function isLeapYear(yr)
{
  if (yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0))
    return true;
  else
    return false;
}

function onMonthChange(mnth, dy, yr)
{
  switch (mnth.options[mnth.selectedIndex].value)
  {
    case "4":
    case "6":
    case "9":
    case "11":
      if (dy.selectedIndex == 30) dy.selectedIndex = 29;
      break;
    case "2":
      if (isLeapYear(yr.options[yr.selectedIndex].value))
      {
        if (dy.selectedIndex >= 29) dy.selectedIndex = 28;
      }
      else
      {
        if (dy.selectedIndex >= 28) dy.selectedIndex = 27;
      }
      break;
  }
  return true;
}

function onDayChange(mnth, dy, yr)
{
  switch (mnth.options[mnth.selectedIndex].value)
  {
    case "4":
    case "6":
    case "9":
    case "11":
      if (dy.selectedIndex == 30) dy.selectedIndex = 29;
      break;
    case "2":
      if (isLeapYear(yr.options[yr.selectedIndex].value))
      {
        if (dy.selectedIndex >= 29) dy.selectedIndex = 28;
      }
      else
      {
        if (dy.selectedIndex >= 28) dy.selectedIndex = 27;
      }
      break;
  }
  return true;
}

function onYearChange(mnth, dy, yr)
{
  switch (mnth.options[mnth.selectedIndex].value)
  {
    case "2":
      if (isLeapYear(yr.options[yr.selectedIndex].value))
      {
        if (dy.selectedIndex >= 29) dy.selectedIndex = 28;
      }
      else
      {
        if (dy.selectedIndex >= 28) dy.selectedIndex = 27;
      }
      break;
  }
  return true;
}
