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

function formVal()
{

  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;
 }

 if (document.theForm.email.value.indexOf("www.", 0) >= 0)
 {
	alert ("Please enter a valid e-mail address. Valid email addresses do not start with \" www.\"");
	document.theForm.email.focus();
	return(false);
}

 if (document.theForm.email.value.indexOf(",", 0) >= 0)
 {
	alert ("Please enter a valid e-mail address. Valid email addresses do not have commas.");
	document.theForm.email.focus();
	return(false);
}

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

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

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

  var checkOK = "0123456789";
  var checkStr = document.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 numbers in the \"zip code\" field. Sorry, U.S. residents only.");
    document.theForm.zipcode.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 numbers in the \"Age\" field.");
    document.theForm.Age.focus();
    return (false);
  }

  if (document.theForm.Age.value.length > 2)
  {
    alert("Please enter at most 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 < 17)
  {
    window.location = "http://www.teenfreeway.com/hcunderaged17.htm";
return (false);
  }

  return (true);
}
