function isUndefined(a) 
{
  return typeof a == 'undefined';
} 

// get today's date
function getCurrentDate()
{
  var today = new Date();
  var month = today.getMonth() + 1;
  if (month < 10)
  {
    month = "0" + month;
  }
  var day = today.getDate();
  if (day < 10)
  {
    day = "0" + day;
  }
  var year = today.getYear();
  if (year < 2000)
  {
    year = (today.getYear() + 1900);
  }

  
  var currentDate = month + "/" + day + "/" + year;
  return(currentDate);
}

// validate email address
function validateEmail(email)
{
  // and email address must have one '@' followed by at least one '.'
  var valid = true;
  var atIdx = email.indexOf("@");
  var atLastIdx = email.lastIndexOf("@");
  if ((atIdx <= 0) || (atIdx != atLastIdx))
  { 
    valid = false;
  }

  // there must be at least one '.' after the '@'
  var dotIdx = email.lastIndexOf(".");
  if (dotIdx <= (atIdx + 1))
  { 
    valid = false;
  }

  if (!valid)
  {
    alert("Email addresses must contain a single '@' symbol and at least one '.' after the '@' (similar to: jsmith@yahoo.com).")
  }
  return(valid);
}


// validate phone format
function validatePhone(phone)
{
  // and phone be in (999) 999-9999 format
  var valid = true;
  if (phone.length < 14)
  {
    valid = false;
  }
  else
  {
    var validFormat = "";
    validFormat = /^(\(\d{3}\)\s\d{3}-\d{4})$/i;
    valid = validFormat.test(phone);
  }

  if (!valid)
  {
    alert("Phone Numbers must be in the following format: (999) 999-9999")
  }
  return(valid);
}

