// Initialize today's date info
Now = new Date();
NowDay = Now.getDate();
NowMonth = Now.getMonth() + 1;
NowYear = Now.getFullYear();

// Initialize variables for user selections
SelectedDay = NowDay;
SelectedMonth = NowMonth;
SelectedYear = NowYear;

// Month name strings
monthname=new Array("blank","January","February","March","April","May","June", "July","August","September","October","November","December");
// monthname=new Array("blank","Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep","Oct","Nov","Dec");

//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear) {
var DaysInMonth = 31;
if (WhichMonth == "4" || WhichMonth == "6" || WhichMonth == "9" || WhichMonth == "11") DaysInMonth = 30;
if (WhichMonth == "2" && (WhichYear/4) != Math.floor(WhichYear/4)) DaysInMonth = 28;
if (WhichMonth == "2" && (WhichYear/4) == Math.floor(WhichYear/4)) DaysInMonth = 29;
return DaysInMonth;
}

// function for displaying days of month
function printDays(obj) {
	$("#Form1 :input#day").empty();
	for (i=1; i<=obj; i++) {
	$("#Form1 :input#day").append('<option value="' + i + '">' + i + '</option>');
	}
	//DaysObject[0].selected = true;
}

$(document).ready(function() {

DaysObject = document.Form1.zday;
MonthObject = document.Form1.zmonth;

DayCount = DaysInMonth(NowMonth, NowYear);
printDays(DayCount);
	
$("#Form1 :input#year").change( function() { 
	SelectedYear = this[this.selectedIndex].value;
	DayCount = DaysInMonth(SelectedMonth, SelectedYear);
	printDays(DayCount);
});

$("#Form1 :input#month").change( function() { 
	SelectedMonth = this[this.selectedIndex].value;
	DayCount = DaysInMonth(SelectedMonth, SelectedYear);
	printDays(DayCount);
});
	

for (i=1; i<=12; i++) {
	$("#Form1 :input#month").append('<option value="' + i + '">' + monthname[i] + '</option>');
}
	
maxYear = NowYear + 1;
thisYear = SelectedYear;
for (i=SelectedYear; i<=maxYear; i++) {
	//if (thisYear == NowYear) { var yearON = ' selected="selected"'; } else { var yearON = ''; }
	$("#Form1 :input#year").append('<option value="'+ thisYear +'">' + thisYear + '</option>');

	thisYear = SelectedYear + 1;
}
// Set initial selected indexes
//$("select#year option:first").attr("selected", "selected");

document.Form1.zyear[0].selected = true;
document.Form1.zday.selectedIndex = (NowDay - 1);
document.Form1.zmonth.selectedIndex = (SelectedMonth - 1);


});

