var today = new Date(new Date().valueOf());

function setDates()
{
  // This will populate the date dropdowns with today and tomarrow's values.
  theForm = document.searchform;
  var yearOffset = parseInt(theForm.inyear.options[0].value,10);
  // getDate
  var tomorrow = new Date(new Date().valueOf() + (24*60*60*1000));
  var inMonth=tomorrow.getMonth();
  var inDay=tomorrow.getDate();
  var inYear=y2k(tomorrow.getYear());

  if(isLeapYear(inYear)) { var days = new Array(31,29,31,30,31,30,31,31,30,31,30,31); }
  else { var days = new Array(31,28,31,30,31,30,31,31,30,31,30,31); }


  // Now set the select boxes to the appropriate dates:
  theForm.inmonth.options[inMonth].selected=true;
  theForm.inday.options[(inDay-1)].selected=true;
  theForm.inyear.options[(inYear-yearOffset)].selected=true;
}
// quadYear
function y2k(number){return (number < 1000) ? number + 1900 : number;}

function isLeapYear(yr)
{
  if (((yr % 4 == 0) && (yr % 100 != 0)) || (yr % 400 == 0)) { return true; }
  else { return false; } 
}

function changeDates()
{
  theForm = document.searchform;
  var yearOffset = parseInt(theForm.inyear.options[0].value,10);
  var inMonth=parseInt(theForm.inmonth.options[theForm.inmonth.selectedIndex].value,10)-1;
  var inYear=parseInt(theForm.inyear.options[theForm.inyear.selectedIndex].value,10);
  var baseMonth=today.getMonth();
  var baseDay=today.getDate();
  var baseYear=y2k(today.getYear());
  
  if(isLeapYear(inYear)) { var days = new Array(31,29,31,30,31,30,31,31,30,31,30,31); }
  else { var days = new Array(31,28,31,30,31,30,31,31,30,31,30,31); }

  var inDay=parseInt(theForm.inday.options[theForm.inday.selectedIndex].value,10);
  
  if(inDay >= days[inMonth]) { inDay = days[inMonth]; }
  else { inDay = inDay%days[inMonth]; }
  theForm.inday.options[inDay-1].selected=true;

}