// portions of this script taken from (http://www.digitalroom.net)

function setDays() {    

    var y = document.Innovation.birthYear.options[document.Innovation.birthYear.selectedIndex].value;
    var m = document.Innovation.birthMonth.selectedIndex-2;
	
    document.Innovation.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.Innovation.bday.length) {
		for (i = document.Innovation.bday.length; i < days; i++) {
			document.Innovation.bday.length = days;
			document.Innovation.bday.options[i].text = i + 1;
			document.Innovation.bday.options[0].value = "01";
			document.Innovation.bday.options[1].value = "02";
			document.Innovation.bday.options[2].value = "03";
			document.Innovation.bday.options[3].value = "04";
			document.Innovation.bday.options[4].value = "05";
			document.Innovation.bday.options[5].value = "06";
			document.Innovation.bday.options[6].value = "07";
			document.Innovation.bday.options[7].value = "08";
			document.Innovation.bday.options[8].value = "09";
			document.Innovation.bday.options[i].value = i + 1;
		}
	}
	

	// if (days in new month < current days) then we must delete the extra days
	if (days < document.Innovation.bday.length) {
		document.Innovation.bday.length = days;
	if (document.Innovation.bday.selectedIndex == -1) 
		document.Innovation.bday.selectedIndex = days - 1;
	}
      
      selectDay();
}

function selectDay(){
   //select previously chosen option
   var selectedDay = document.Innovation.day_hidden.value;
   for (i=0; i<document.Innovation.bday.length; i++){ 
      if(selectedDay == document.Innovation.bday.options[i].value){
         document.Innovation.bday.selectedIndex = i;
         break;
      }
   }
}