﻿//This script runs email, age (13 and over) and zipcode validations

function FrontPage_Form1_Validator(theForm)
{

 if (theForm.First_Name.value == "")
  {
    alert("Please enter your First Name.");
    theForm.First_Name.focus();
    return (false);
  }

  if (theForm.First_Name.value.length < 1)
  {
    alert("Please enter your First Name.");
    theForm.First_Name.focus();
    return (false);
  }

  if (theForm.First_Name.value.length > 24)
  {
    alert("Please enter at most 24 characters in the \"First Name\" field.");
    theForm.First_Name.focus();
    return (false);
  }

  if (theForm.First_Name.value.indexOf(".", 0) >= 0)
 {
    alert("Please do not enter a period in the first name field.");
    theForm.First_Name.focus();
    return (false);
 }

  if (theForm.Last_Name.value == "")
  {
    alert("Please enter your Last Name.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Last_Name.value.length < 2)
  {
    alert("Please enter your Last Name.");
    theForm.Last_Name.focus();
    return (false);
  }

  if (theForm.Last_Name.value.length > 24)
  {
    alert("Please enter at most 24 characters in the \"Last Name\" field.");
    theForm.Last_Name.focus();
    return (false);
  }

 if (theForm.Last_Name.value.indexOf(".", 0) >= 0)
 {
    alert("Please do not enter a period in the last name field.");
    theForm.Last_Name.focus();
    return (false);
 }

 if (theForm.Last_Name.value.indexOf(",", 0) >= 0)
 {
    alert("Please do not enter a comma in the last name field.");
    theForm.Last_Name.focus();
    return (false);
 }

  if (theForm.Address1.value == "")
  {
    alert("Please enter your Address.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.Address1.value.length < 1)
  {
    alert("Please enter your Address.");
    theForm.Address1.focus();
    return (false);
  }

  if (theForm.Address1.value.length > 24)
  {
    alert("Please enter at most 24 characters in the Address field.");
    theForm.Address1.focus();
    return (false);
  }

 if (theForm.Address2.value.indexOf(",", 0) >= 0)
 {
    alert("Please do not enter a comma in the Address field.");
    theForm.Address2.focus();
    return (false);
 }

  if (theForm.Address2.value.length > 24)
  {
    alert("Please enter at most 24 characters in the second Address field.");
    theForm.Address2.focus();
    return (false);
  }

  if (theForm.City1.value == "")
  {
    alert("Please enter your City.");
    theForm.City1.focus();
    return (false);
  }

  if (theForm.City1.value.length < 1)
  {
    alert("Please enter your City.");
    theForm.City1.focus();
    return (false);
  }

  if (theForm.City1.value.length > 24)
  {
    alert("Please enter at most 24 characters in the City field.");
    theForm.City1.focus();
    return (false);
  }

  if (theForm.state1.selectedIndex < 0)
  {
    alert("Please select your State.");
    theForm.state1.focus();
    return (false);
  }

  if (theForm.state1.selectedIndex == 0)
  {
    alert("Please select your State.");
    theForm.state1.focus();
    return (false);
  }

  if (theForm.Zip1.value == "")
  {
    alert("Please enter your Zip Code.");
    theForm.Zip1.focus();
    return (false);
  }

  if (theForm.Zip1.value.length < 5)
  {
    alert("Please enter your Zip Code.");
    theForm.Zip1.focus();
    return (false);
  }

  if (theForm.Zip1.value.length > 5)
  {
    alert("Please enter at least 5 numbers in the \"zip code\" field. Sorry, U.S. residents only..");
    theForm.Zip1.focus();
    return (false);
  }

  var checkOK = "0123456789";
  var checkStr = 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.");
    theForm.Zip1.focus();
    return (false);
  }

  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 at least 7 characters in the \"email\" field.");
    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.email.value.indexOf("www.", 0) >= 0)
 {
	alert ("Please enter a valid e-mail address. Valid email addresses do not start with \" www.\"");
	theForm.email.focus();
	return(false);
}

 if (theForm.email.value.indexOf(",", 0) >= 0)
 {
	alert ("Please enter a valid e-mail address. Valid email addresses do not have commas.");
	theForm.email.focus();
	return(false);
}

/*
    var radioSelected = false;
  for (i = 0;  i < theForm.gender.length;  i++)
  {
    if (theForm.gender[i].checked)
        radioSelected = true;
  }
  if (!radioSelected)
  {
    alert("What is your gender?  Please click on the appropriate circle.");
    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 no more than 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.clubs4women.com/cw_underage.htm";
return (false);
  }

    
  return (true);
}
