$(document).ready(function(){
	/*
	 JQuery Date boxes - Jamie Thompson - F1 Design - 2007
	 This script will adjust the available optionsfor 'day' based on the month and correctly deals with february on leap years

	 The code deals with three select boxes classed with 'day', 'month' and 'year' respectively
	contained within a single div. The script supports multiple instances but each set of selects 
	must live within a sepearte div or bad things will happen.
	*/		
			$("select.month").change(function(){
			// change the date day options on month change
				var month = $(this).val();				
				if(month=='2'){
					var year = $(this).siblings(".year").val(); 
					if(year % 400 == 0){ // if year divisable by 400 then it's a leap year
						month_end = 29;
					}else if(year % 4 == 0  && year % 100 > 0){
					// if year is divisible by four but not 100 then it's also a leap year. apparently.
						month_end = 29;
					}else{
						month_end = 28;}
				}
				else if(month=='4'||month=='6'||month=='9'||month=='11'){month_end='30'}
				else{month_end=31}
				
				daybox = $(this).siblings("span.day").children("select");
				var daybox_id = $(daybox).attr('id');
				var daybox_date = $(daybox).val();
				
				html = '<select name="'+daybox.attr("name")+'" id="'+daybox_id+'" class="day">'; 
				is_selected="";
				
				for (var i = 1; i <= month_end; i++){
					if(i < 10){day='0'+i;}else{day=i;} //pad a zero for days 1-9
					if(i == daybox_date){is_selected=' selected="selected"';}
					html=html+'<option value="'+day+'"'+is_selected+'>'+day+'</option>';
					is_selected="";
				} 
				html = html+'</select>'; 
				$(this).siblings(".day").html(html);
			
			});
			//re-trigger the month change function whenever the year select box is changed
			$("select.year").change(function(){$(this).siblings("select.month").change();});

});