
function dismiss(id){
	$(id).slideUp(500);	
	
}

function insertSpinner(id){	
	$(id).text('').append('<img class="loadingSpinner" src="css_and_images/loadingSpinnerMedium.gif" height="24" width="24" alt="loading">');	
}

function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name){
	if (document.cookie.length>0){
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1){
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}


$(document).ready(function(){
		// Effects for notice dialogs
	$("p.warning").fadeTo(800, 0.70).fadeTo(700, 1).fadeTo(2000, 0.70).delay(500).slideUp();
	$("p.notice").fadeTo(800, 0.70).fadeTo(700, 1).fadeTo(2000, 0.70).delay(500).slideUp();
	// Navigation
	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled - Adds empty span tag after ul.subnav
	
	$("ul.topnav li span").click(function() { //When trigger is clicked...
		
		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click

		$(this).parent().hover(function() {
		}, function(){	
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() { 
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});
	
	
	$('.gapList').click(function(){
		$(this).children('span').slideToggle();
		$(this).children('div').slideToggle();
	});
	
	$('#gapExpander').click(function(){
		if($(this).hasClass('expanded')){
			$(this).html('expand all').removeClass('expanded');
		}
		else {
			$(this).html('collapse all').addClass('expanded');
		}
	
		$('.gapList span').each(function(){
			$(this).slideToggle();
		});
		$('.gapList div').each(function(){
			$(this).slideToggle();
		});
	});
	
	$('.expander').click(function(){
		group_id = 'group' + $(this).attr('id');
		if($(this).hasClass('expanded')){
			$(this).removeClass('expanded')
			$(this).children('span').html('Expand Group');
			$('#' + group_id).slideUp();	
			setCookie(group_id, 'collapsed', 14);
		}
		else {
			$(this).addClass('expanded');
			$(this).children('span').html('Collapse Group');
			$('#' + group_id).slideDown();		
			setCookie(group_id, 'expanded', 14);
		}
	});
	
	$('.expander').each(function(){
		group_id = 'group' + $(this).attr('id');
		if(getCookie(group_id) == 'collapsed'){
			$(this).children('span').html('Expand Group');
			$('#' + group_id).hide();	
		}	
		else {
			$(this).addClass('expanded');
		}
	});
	
	
	// styling for form buttons
	
	
	if($.browser.msie && ($.browser.version == 7))
	{
		$(":radio").addClass('radio_ie');
		$(":submit").addClass('button_ie');
	}
	else {
		$(":radio").addClass('radio');
		$(":submit").addClass('button');
	}

	$(".answer").focus(function(){
		$(this).addClass("fullanswer").slideDown("slow");
	});
	
	$(".answer").blur(function(){
		$(this).removeClass("fullanswer").addClass("answer");
	});
	
	// styling for tables
	$(".resultsList tr:nth-child(odd)").addClass("odd");
	
	//
	$( "#start_date_picker" ).datepicker({ dateFormat: 'yy-mm-dd' });
	$( "#start_date_picker" ).datepicker({ maxDate: '+0' });
	$( "#start_date_picker" ).datepicker({ maxDate: '-30' });
	$( "#end_date_picker" ).datepicker({ dateFormat: 'yy-mm-dd' });
	$( "#end_date_picker" ).datepicker({ maxDate: '+0' });
	$( "#end_date_picker" ).datepicker({ minDate: '-60' });
	
	$( "#account_expiry_date_picker" ).datepicker({ dateFormat: 'yy-mm-dd' });
	$( "#account_expiry_date_picker" ).datepicker({ minDate: '-0' });

});


