//This script runs email, age (13 and over) and zipcode validations

function otxval()
{

 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.First_Name.value.indexOf(".", 0) >= 0)
 {
    alert("Please do not enter a period 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 < 2)
  {
    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.Last_Name.value.indexOf(".", 0) >= 0)
 {
    alert("Please do not enter a period in the last name field.");
    document.theForm.Last_Name.focus();
    return (false);
 }

 if (document.theForm.Last_Name.value.indexOf(",", 0) >= 0)
 {
    alert("Please do not enter a comma in the last name field.");
    document.theForm.Last_Name.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.Address1.value.indexOf(",", 0) >= 0)
 {
    alert("Please do not enter a comma in the Address field.");
    document.theForm.Address1.focus();
    return (false);
 }

 if (document.theForm.Address2.value.indexOf(",", 0) >= 0)
 {
    alert("Please do not enter a comma in the Address field.");
    document.theForm.Address2.focus();
    return (false);
 }

  if (document.theForm.Address2.value.length > 24)
  {
    alert("Please enter at most 24 characters in the second Address field.");
    document.theForm.Address2.focus();
    return (false);
  }

if (document.theForm.City1.value.indexOf(",", 0) >= 0)
 {
    alert("Please only enter your city in the City field. No commas please!");
    document.theForm.City1.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 least 5 numbers in the \"zip code\" field. Sorry, U.S. residents only..");
    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.email.value == "")
  {
    alert("Please enter a valid 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;
 }

 
     var radioSelected = false;
  for (i = 0;  i < document.theForm.gender.length;  i++)
  {
    if (document.theForm.gender[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("What is your gender?  Please click on the appropriate circle.");
    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 your age.");
    document.theForm.Age.focus();
    return (false);
  }

  if (document.theForm.Age.value.length > 2)
  {
    alert("Please enter no more than 2 numbers 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);
  }
  
/*
 if (document.theForm.Age.value > 25)
  {
    window.location = "http://www.teenfreeway.com/hcoveraged.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);
}
