//Email, zipcode US only, and age validation 13 and over

function FrontPage_Form1_Validator(theForm)
{

  if (theForm.email.value == "")
  {
    alert("Please enter a valid email address.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.email.value.length < 7)
  {
    alert("Please enter a valid email address.");
    theForm.email.focus();
    return (false);
  }

  if (theForm.email.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"email\" field.");
    theForm.email.focus();
    return (false);
  }

if (theForm.email.value.indexOf("@", 0) < 0)
 {
    alert("Please enter a valid email address.");
    theForm.email.focus();
    return (false);
 }

if (theForm.email.value.indexOf(".", 0) < 0)
 {
    alert("Please enter a valid email address.");
    theForm.email.focus();
    return false;
 }

  if (theForm.Age.value == "")
  {
    alert("Please enter your age.");
    theForm.Age.focus();
    return (false);
  }

  if (theForm.Age.value.length < 1)
  {
    alert("Please enter your age.");
    theForm.Age.focus();
    return (false);
  }

  if (theForm.Age.value.length > 2)
  {
    alert("Please enter at most 2 numbers in the \"Age\" field.");
    theForm.Age.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = theForm.Age.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only numbers in the \"Age\" field.");
    theForm.Age.focus();
    return (false);
  }

 if (theForm.Age.value < 13)
  {
    window.location = "http://www.teenfreeway.com/pg/beinggirl1005/hcunderaged.htm";
return (false);
  }

 if (theForm.Age.value > 17)
  {
    window.location = "http://www.teenfreeway.com/pg/beinggirl1005/hcoveraged.htm";
return (false);
  }

 if (theForm.zipcode.value == "")
  {
    alert("Please your zip code.");
    theForm.zipcode.focus();
    return (false);
  }

  if (theForm.zipcode.value.length < 5)
  {
    alert("Please enter at least 5 numbers in the \"zip code\" field.");
    theForm.zipcode.focus();
    return (false);
  }

  if (theForm.zipcode.value.length > 5)
  {
    alert("Please enter at most 5 numbers in the \"zip code\" field.");
    theForm.zipcode.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = theForm.zipcode.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only 5 numbers in the \"zip code\" field.  Sorry, US residents only");
    theForm.zipcode.focus();
    return (false);
  }
  
  if (theForm.emailfriend.value == "")
  {
    alert("Please enter the email address of the friend who told you about this offer. Thanks!");
    theForm.emailfriend.focus();
    return (false);
  }

  if (theForm.emailfriend.value.length < 7)
  {
    alert("Please enter a valid email address.");
    theForm.emailfriend.focus();
    return (false);
  }

  if (theForm.emailfriend.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"email\" field.");
    theForm.emailfriend.focus();
    return (false);
  }

if (theForm.emailfriend.value.indexOf("@", 0) < 0)
 {
    alert("Please enter a valid email address.");
    theForm.emailfriend.focus();
    return (false);
 }

if (theForm.emailfriend.value.indexOf(".", 0) < 0)
 {
    alert("Please enter a valid email address.");
    theForm.emailfriend.focus();
    return false;
 }
  
  return (true);
}
