// JavaScript Document
<!--
function Form_Validator(theForm)
{

  var alertsay = ""; // define for long lines
  // alertsay is not necessary for your code,
  // but I need to break my lines in multiple lines
  // so the code won't extend off the edge of the page
  
  
    // check to see if the name field is blank
  if (theForm.YourName.value == "")
  {
    alert("Please enter your \"Full Name\".");
    theForm.YourName.focus();
    return (false);
  }

  // require at least 3 characters be entered
  if (theForm.YourName.value.length < 6)
  {
    alert("Please enter at least 6 characters in the \"Name\" field.");
    theForm.YourName.focus();
    return (false);
  }

  // allow ONLY alphanumeric keys, no symbols or punctuation
  // this can be altered for any "checkOK" string you desire
  var checkOK = "A .'BCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  var checkStr = theForm.YourName.value;
  var allValid = 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 letters in the \"Name\" field.");
    theForm.YourName.focus();
    return (false);
  }
  
  // check if email field is blank
 if (theForm.EmailAddress.value == "")
  {
    alert("Please enter your \"Email Address\".");
    theForm.EmailAddress.focus();
    return (false);
  }

  // test if valid email address, must have @ and .
  var checkemail = "@.";
  var checkStr = theForm.EmailAddress.value;
  var emailValid = false;
  var emailAt = false;
  var emailPeriod = false;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkemail.length;  j++)
    {
      if (ch == checkemail.charAt(j) && ch == "@")
        emailAt = true;
      if (ch == checkemail.charAt(j) && ch == ".")
        emailPeriod = true;
	  if (emailAt && emailPeriod)
		break;
	  if (j == checkemail.length)
		break;
	}
	// if both the @ and . were in the string
    if (emailAt && emailPeriod)
    {
		emailValid = true
		break;
	}
  }
  if (!emailValid)
  {
    alert("Your \"Email Address\" must contain an \"@\" and a \".\" ");
    theForm.EmailAddress.focus();
    return (false);
  }


   // check if TelephoneDay field is blank
 if (theForm.TelephoneDay.value == "")
  {
    alert("Please enter your Day Time contact \"Telephone\" number.");
    theForm.TelephoneDay.focus();
    return (false);
  }

  // only allow numbers to be entered
  var checkOK = "0 +123456789";
  var checkStr = theForm.TelephoneDay.value;
  var allValid = true;
  var allNum = "";
  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 (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digits and \"+\" in the \"Telephone\" field.");
    theForm.TelephoneDay.focus();
    return (false);
  }


   // check if TelephoneEvening field is blank
 if (theForm.TelephoneEvening.value == "")
  {
    alert("Please enter your Evening Time contact \"Telephone\" number.");
    theForm.TelephoneEvening.focus();
    return (false);
  }

  // only allow numbers to be entered
  var checkOK = "0 +123456789";
  var checkStr = theForm.TelephoneEvening.value;
  var allValid = true;
  var allNum = "";
  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 (ch != ",")
      allNum += ch;
  }
  if (!allValid)
  {
    alert("Please enter only digits and \"+\" in the \"Telephone\" field.");
    theForm.TelephoneEvening.focus();
    return (false);
  }
  
 
    // check if PostalAddressLn1v field is blank 
    if (theForm.PostalAddressLn1.value == "")
  {
    alert("Please enter your \"Postal Address box 1\".");
    theForm.PostalAddressLn1.focus();
    return (false);
  }
  // allow only 500 characters maximum in the briefenquiry field
  if (theForm.PostalAddressLn1.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"Postal Address box 1\" field.");
    theForm.PostalAddressLn1.focus();
    return (false);
  }


   // check to see if the PostCode field is blank
  if (theForm.PostCode.value == "")
  {
    alert("Please enter your \"Post Code\".");
    theForm.PostCode.focus();
    return (false);
  }

  // require at least 6 characters be entered
  if (theForm.PostCode.value.length < 6)
  {
    alert("Please enter your \"Full Post Code\".");
    theForm.PostCode.focus();
    return (false);
  }

  // allow ONLY upper case alphanumeric keys, space and numbers, no symbols or punctuation
  // this can be altered for any "checkOK" string you desire
  var checkOK = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  var checkStr = theForm.PostCode.value;
  var allValid = 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 UPPER CASE Letters in the \"Post Code\" field.");
    theForm.PostCode.focus();
    return (false);
  }


   // check if no Course has been selected
  if (theForm.Course.selectedIndex < 0)
  {
    alert("Please select a \"Course\".");
    theForm.Course.focus();
    return (false);
  }

  // check if the first drop down is selected, if so, invalid selection
  if (theForm.Course.selectedIndex == 0)
  {
    alert("Please select a \"Course\".");
    theForm.Course.focus();
    return (false);
  }


 // require that at least one SelectGear be checked
  var checkSelected = false;
  for (i = 0;  i < theForm.SelectGear.length;  i++)
  {
    if (theForm.SelectGear[i].checked)
        checkSelected = true;
  }
  if (!checkSelected)
  {
    alert("Please select a \"Gear Type\".");
    return (false);
  }
  
  // only allow up to 1 checkboxes be checked
  var checkCounter = 0;
  for (i = 0;  i < theForm.SelectGear.length;  i++)
  {
    if (theForm.SelectGear[i].checked)
        checkCounter = checkCounter + 1;
  }
  if (checkCounter > 1)
  {
    alert("Please select only one of the \"Gear Type\" options.");
    return (false);
  }
  

    // check if EnquiryInfo field is blank 
    if (theForm.EnquiryInfo.value == "")
  {
    alert("Please enter a brief description of your \"Enquiry Information\".");
    theForm.EnquiryInfo.focus();
    return (false);
  }
  // allow only 500 characters maximum in the briefenquiry field
  if (theForm.EnquiryInfo.value.length > 350)
  {
    alert("Please enter at most 350 characters in the \"Enquiry Information\" field.");
    theForm.EnquiryInfo.focus();
    return (false);
  }


   // check if no AboutUs has been selected
  if (theForm.AboutUs.selectedIndex < 0)
  {
    alert("Where did you hear \"About Us\" ?");
    theForm.AboutUs.focus();
    return (false);
  }

  // check if the first drop down is selected, if so, invalid selection
  if (theForm.AboutUs.selectedIndex == 0)
  {
    alert("Please tell us where you heard \"About Us\" or select \"Others\"");
    theForm.AboutUs.focus();
    return (false);
  }






    
    // because this is a sample page, don't allow to exit to the post action
  // comes in handy when you are testing the form validations and don't
  // wish to exit the page
  alertsay = "\"done.\""
  alert(alertsay);
  return (true);
  // replace the above with return(true); if you have a valid form to submit to
}
//-->