/* 	FIXES THE DAYS IN A SELECT 
		WHERE THERE ARE 3 SELECTS
		NAMED MONTH, DAY AND YEAR.
		
		PASS THE NAME OF THE FORM IN QUOTES, IE. setDays('formName');	*/

function setDays(frmName, monFldName, dayFldName, yearFldName) {
	obj = eval("document."+frmName);
	monObj = eval("document."+frmName+"."+monFldName);
	dayObj = eval("document."+frmName+"."+dayFldName);
	yearObj = eval("document."+frmName+"."+yearFldName);
  c = 1;
  var y = yearObj.options[yearObj.selectedIndex].value;
  var m = monObj.selectedIndex;
	var d;
	
	if(frmName=='qd')	m=m+4;

  // 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 > dayObj.length) {
    for (i = dayObj.length; i < days; i++) {
      dayObj.length = days;
      dayObj.options[i].text = i + 1;
      dayObj.options[i].value = i + 1;
    }
  }

  // if (days in new month < current days) then we must delete the extra days
  if (days < dayObj.length) {
    dayObj.length = days;
    if (dayObj.selectedIndex == -1) 
      dayObj.selectedIndex = days - 1;
  }  
}
