function CheckEmail(Email) {
  var Value = Email;
  if (Value.length == 0) {
    return "";
  } else {
    var ValidEmail = true;
    if (Value.indexOf("@") == -1) { ValidEmail = false; }
    if (Value.indexOf(".") == -1) { ValidEmail = false; }
    if (Value.indexOf(" ") != -1) { ValidEmail = false; }
    if (Value.indexOf(",") != -1) { ValidEmail = false; }
    if (ValidEmail == false) {
      alert("'" + Email + "' is not a valid email address.");
      return "";
    } else {
      return Email;
    }
  }
}

// -------------------------------------------------------------------------------------

function CheckDate(ThisDate) {
  // Do nothing if the string is blank
  if (ThisDate == "") { return ""; }

  // Identify the delimiter
  var ThisDelimiter = "";
  for (var i = 0; i < ThisDate.length; i++) {
    var OneChar = ThisDate.charAt(i);
    if (ThisDelimiter == "") {
      if (OneChar < "0" || OneChar > "9") { ThisDelimiter = OneChar; }
    }
  }
  if (ThisDelimiter == "") {
    alert ("'" + ThisDate + "' is not a valid date");
    return "";
  }

  // Split into Month, Day, and Year
  var aryThisDate = ThisDate.split(ThisDelimiter);
  var ThisMonth = aryThisDate[0];
  var ThisDay   = aryThisDate[1];
  var ThisYear  = aryThisDate[2];

  // Make sure they're all numbers
  if (isNaN(ThisMonth) || isNaN(ThisDay) || isNaN(ThisYear)) {
    alert ("'" + ThisDate + "' is not a valid date");
    return "";
  }

  // Check month
  if (ThisMonth < 0 || ThisMonth > 12) {
    alert ("'" + ThisDate + "' is not a valid date");
    return "";
  }

  // Check year
  if (ThisYear < 1950 || ThisYear > 2050) {
    if (ThisYear != 9999) {
      alert ("'" + ThisDate + "' is not a valid date");
      return "";
    }
  }

  var LeapYear;
  var MonthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31,30,31);
  // Determine if year is a leap year
  if (ThisYear % 4 == 0) { LeapYear = true; } else { LeapYear = false; }
  // Allow for leap year
  if (LeapYear && ThisMonth == 2 && ThisDay == 29) {
    return ThisMonth + "/" + ThisDay + "/" + ThisYear;
  } else {
    if (ThisDay > MonthDays[ThisMonth - 1]) {
      alert("'" + ThisDate + "' is not a valid date.");
      return "";
    }
  }
  return ThisMonth + "/" + ThisDay + "/" + ThisYear;
}

// -------------------------------------------------------------------------------------

function toggleDisplay(objID) {
  var DisplayStyle = document.getElementById(objID).style.display;
  if (DisplayStyle == "block") {
    document.getElementById(objID).style.display = "none";
  } else {
    document.getElementById(objID).style.display = "block";
  }
}
