var whitespace = " \t\n\r";

function isEmpty(s)
{
  var i;
  if((s == null) || (s.length == 0))
  return true;
  for(i = 0; i < s.length; i++)
  {
    var c = s.charAt(i);
    if(whitespace.indexOf(c) == -1)
      return false;
  }
  return true;
}

function validate()
{
  if(isEmpty(document.form1.name.value))
  {
    alert("Must Enter Your Name");
    document.form1.name.focus();
    return false;
  }
  if(isEmpty(document.form1.email.value))
  {
    alert("Must Enter Your Email Address");
    document.form1.email.focus();
    return false;
  }
  if(document.form1.website.value == 0)
  {
    alert("Must Select Type of Website");
    document.form1.website.focus();
    return false;
  }
  /*if(isEmpty(document.form1.hm_phone.value))
  {
    alert("Must Enter Your Home Phone Number");
    document.form1.hm_phone.focus();
    return false;
  }
  if(isEmpty(document.form1.zip.value))
  {
    alert("Must Enter Your Zip Code");
    document.form1.zip.focus();
    return false;
  }
  if(isEmpty(document.form1.ssn.value))
  {
    alert("Must Enter Your Social Security Number");
    document.form1.ssn.focus();
    return false;
  }
  if(isEmpty(document.form1.state.value))
  {
    alert("Must Select A State");
    document.form1.state.focus();
    return false;
  }
  if(isEmpty(document.form1.other_phone.value))
  {
    document.form1.other_phone.value = 'N/A';
  }
  if(isEmpty(document.form1.mi.value))
  {
    document.form1.mi.value = 'N/A';
  }*/
}
function validZip(zip)
{
  if(/\d{5}(-\d{4})?/.test(zip))
  return true;
  alert("Zip Code Entered Incorrectly");
  return false;
}
function validEmail(email)
{
  if(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email))
  return true;
  alert("Email Entered Incorrectly");
  return false;
}

function validSSN(ssn)
{
  if(/\d{3}-\d{2}-\d{4}/.test(ssn))
  return true;
  alert("SSN Entered Incorrectly");
  return false;
}
function validHphone(hm_phone)
{
  if(/\d{3}-\d{3}-\d{4}/.test(hm_phone)) 
  return true;
  alert("Phone Number Entered Incorrectly \n\n Use Format 555-555-5555");
  return false;
}
function validOphone(phone2)
{
  if(/\d{3}-\d{3}-\d{4}?/.test(phone2))
  return true;
  alert("Phone Number Entered Incorrectly \n\n Use Format 555-555-5555");
  return false;
}
function validDate(dob)
{
  if(/\d{2}\/\d{2}\/\d{4}?/.test(dob))
  return true;
  alert("Date Was Entered Incorrectly \n\n Use Format MM/DD/YYYY");
  return false;
}
