//This script runs email, age (13 and over) and zipcode validations

function formVal()
{

  if (document.theForm.First_Name.value == "")
  {
    alert("Please enter your First Name.");
    document.theForm.First_Name.focus();
    return (false);
  }

  if (document.theForm.First_Name.value.length < 1)
  {
    alert("Please enter your First Name.");
    document.theForm.First_Name.focus();
    return (false);
  }

  if (document.theForm.First_Name.value.length > 24)
  {
    alert("Please enter at most 24 characters in the \"First Name\" field.");
    document.theForm.First_Name.focus();
    return (false);
  }

  if (document.theForm.Last_Name.value == "")
  {
    alert("Please enter your Last Name.");
    document.theForm.Last_Name.focus();
    return (false);
  }

  if (document.theForm.Last_Name.value.length < 1)
  {
    alert("Please enter your Last Name.");
    document.theForm.Last_Name.focus();
    return (false);
  }

  if (document.theForm.Last_Name.value.length > 24)
  {
    alert("Please enter at most 24 characters in the \"Last Name\" field.");
    document.theForm.Last_Name.focus();
    return (false);
  }

  if (document.theForm.email.value == "")
  {
    alert("Please enter your email address.");
    document.theForm.email.focus();
    return (false);
  }

  if (document.theForm.email.value.length < 7)
  {
    alert("Please enter at least 7 characters in the \"email\" field.");
    document.theForm.email.focus();
    return (false);
  }

  if (document.theForm.email.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"email\" field.");
    document.theForm.email.focus();
    return (false);
  }

if (document.theForm.email.value.indexOf("@", 0) < 0)
 {
    alert("Please enter a valid email address.");
    document.theForm.email.focus();
    return (false);
 }

if (document.theForm.email.value.indexOf(".", 0) < 0)
 {
    alert("Please enter a valid email address.");
    document.theForm.email.focus();
    return false;
 }
  
  if (document.theForm.Address1.value == "")
  {
    alert("Please enter your Address.");
    document.theForm.Address1.focus();
    return (false);
  }

  if (document.theForm.Address1.value.length < 1)
  {
    alert("Please enter your Address.");
    document.theForm.Address1.focus();
    return (false);
  }

  if (document.theForm.Address1.value.length > 24)
  {
    alert("Please enter at most 24 characters in the Address field.");
    document.theForm.Address1.focus();
    return (false);
  }
  
  if (document.theForm.Address2.value.length > 24)
  {
    alert("Please enter at most 24 characters in the Address field.");
    document.theForm.Address2.focus();
    return (false);
  }

  if (document.theForm.City1.value == "")
  {
    alert("Please enter your City.");
    document.theForm.City1.focus();
    return (false);
  }

  if (document.theForm.City1.value.length < 1)
  {
    alert("Please enter your City.");
    document.theForm.City1.focus();
    return (false);
  }

  if (document.theForm.City1.value.length > 24)
  {
    alert("Please enter at most 24 characters in the City field.");
    document.theForm.City1.focus();
    return (false);
  }

  if (document.theForm.state1.selectedIndex < 0)
  {
    alert("Please select your State.");
    document.theForm.state1.focus();
    return (false);
  }

  if (document.theForm.state1.selectedIndex == 0)
  {
    alert("Please select your State.");
    document.theForm.state1.focus();
    return (false);
  }

  if (document.theForm.Zip1.value == "")
  {
    alert("Please enter your Zip Code.");
    document.theForm.Zip1.focus();
    return (false);
  }

  if (document.theForm.Zip1.value.length < 5)
  {
    alert("Please enter your Zip Code.");
    document.theForm.Zip1.focus();
    return (false);
  }

  if (document.theForm.Zip1.value.length > 5)
  {
    alert("Please enter at most 5 characters in the Zip Code field.");
    document.theForm.Zip1.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = document.theForm.Zip1.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 Zip Code field.  Sorry, U.S. residents only.");
    document.theForm.Zip1.focus();
    return (false);
  }

/*
if (document.theForm.Age.value == "")
  {
    alert("Please enter your Age.");
    document.theForm.Age.focus();
    return (false);
  }

  if (document.theForm.Age.value.length < 1)
  {
    alert("Please enter at least 1 characters in the \"Age\" field.");
    document.theForm.Age.focus();
    return (false);
  }

  if (document.theForm.Age.value.length > 2)
  {
    alert("Please enter at most 2 characters in the \"Age\" field.");
    document.theForm.Age.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = document.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.");
    document.theForm.Age.focus();
    return (false);
  }

if (document.theForm.Age.value < 13)
  {
    window.location = "http://www.teenfreeway.com/hcunderaged.htm";
return (false);
  }
*/
    var em = document.theForm.email.value;
//alert("em = " + em);
document.theForm.email.value = em
document.cookie = "emcookie" + "=" + escape(document.theForm.email.value) + "; path=/"

  return (true);
}
