// portions of this script taken from (http://www.digitalroom.net)

function setDays() {

    var y = document.dateForm.sf_birth_year.options[document.dateForm.sf_birth_year.selectedIndex].value;
    var m = document.dateForm.sf_birth_month.selectedIndex-2;
	
    document.dateForm.sf_bday.length = 0;
    // find number of days in current month
	if ( (m == 3) || (m == 5) || (m == 8) || (m == 10) ) {
		days = 30;
	} 
	else if (m == 1) {
	// check for leapyear - Any year divisible by 4, except those divisible by 100 (but NOT 400)
		if ( (Math.floor(y/4) == (y/4)) && ((Math.floor(y/100) != (y/100)) || (Math.floor(y/400) == (y/400))) )
			days = 29
		else
			days = 28
		} else {
			days = 31;
	}
	
	// if (days in new month > current days) then we must add the extra days
	if (days > document.dateForm.sf_bday.length) {
		for (i = document.dateForm.sf_bday.length; i < days; i++) {
			document.dateForm.sf_bday.length = days;
			document.dateForm.sf_bday.options[i].text = i + 1;
			document.dateForm.sf_bday.options[0].value = "01";
			document.dateForm.sf_bday.options[1].value = "02";
			document.dateForm.sf_bday.options[2].value = "03";
			document.dateForm.sf_bday.options[3].value = "04";
			document.dateForm.sf_bday.options[4].value = "05";
			document.dateForm.sf_bday.options[5].value = "06";
			document.dateForm.sf_bday.options[6].value = "07";
			document.dateForm.sf_bday.options[7].value = "08";
			document.dateForm.sf_bday.options[8].value = "09";
			document.dateForm.sf_bday.options[i].value = i + 1;
		}
	}
	

	// if (days in new month < current days) then we must delete the extra days
	if (days < document.dateForm.sf_bday.length) {
		document.dateForm.sf_bday.length = days;
	if (document.dateForm.sf_bday.selectedIndex == -1) 
		document.dateForm.sf_bday.selectedIndex = days - 1;
	}
}