function setCurrentDateStart($year, $month, $day) {
  /* changes the date selector menus to the current date or the specified date */
  var currentDate = new Date();

  var todaysYear = getYear(currentDate);

  if ($year && $month && $day) {
    currentDate.setFullYear($year,$month,$day);
  }

  if (getYear(currentDate) == todaysYear) {
    document.dateform.year_start.selectedIndex = 0;
  }
  else {
    document.dateform.year_start.selectedIndex = 1;
  }
  
  document.dateform.month_start.selectedIndex = currentDate.getMonth();

  setDaysStart();  
  
  document.dateform.day_start.selectedIndex = currentDate.getDate() - 1;
}

function setDaysStart() {
  var y = 2000;
  try {
    y = document.dateform.year_start.options[document.dateform.year_start.selectedIndex].value;
  } catch(e) {
    y = document.dateform.year_start.value;  
  }
  var m = document.dateform.month_start.selectedIndex;
  var d;

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

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

}

function setCurrentDateEnd($year, $month, $day) {
  /* changes the date selector menus to the current date or the specified date */
  var currentDate = new Date();

  var todaysYear = getYear(currentDate)

  if ($year && $month && $day) {
    currentDate.setFullYear($year,$month,$day);
  }

  if (getYear(currentDate) == todaysYear) {
    document.dateform.year_end.selectedIndex = 0;
  }
  else {
    document.dateform.year_end.selectedIndex = 1;
  }
  
  document.dateform.month_end.selectedIndex = currentDate.getMonth();

  setDaysEnd();  
  document.dateform.day_end.selectedIndex = currentDate.getDate() - 1;
}

function setDaysEnd() {
  var y = 2000;
  try {
    y = document.dateform.year_end.options[document.dateform.year_end.selectedIndex].value;
  } catch(e) {
    y = document.dateform.year_end.value;  
  }
  var m = document.dateform.month_end.selectedIndex;
  var d;

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

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

// gets the full year i.e. 2007 and is browser independant
function getYear(theDate) {
  x = theDate.getYear();
  var y = x % 100;
  y += (y < 38) ? 2000 : 1900;
  return y;
}