/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: wsabstract.com | http://www.wsabstract.com */
/* fields whose name is preceded by "required" are checked */
function checkrequired(which) {
  var pass=true;
  for (i=0;i<which.length;i++) {
    var tempobj=which.elements[i];
    if (tempobj.name.substring(0,8)=="required") {
      if (((tempobj.type=="text"||tempobj.type=="textarea")&&
          tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
          tempobj.selectedIndex==0)) {
        pass=false;
        break;
      }
    }
  }
/* code in each field's index (in the HTML form) */
statefield=7;
zipcodefield=8;
emailaddress=12;
secondemailaddress=13;
captchafield=47;
txt=which.elements[emailaddress].value;
if ((txt=="")||(txt==null)) {
alert("Please enter a valid email address!");
return false;
}
txt1=which.elements[secondemailaddress].value;
if (!(txt1==txt)) {
alert("The email address fields do not match.");
return false;
}
txt=which.elements[emailaddress].value;
if (txt.indexOf("@")<3){
alert("Your email address seems wrong. Please"
+" check the email ID and '@' sign.");
return false;
}
if (txt.indexOf(".")<3){
alert("Your email address seems wrong. It should include "
+"a period symbol.")
return false;
}
txt=which.elements[captchafield].value;
if(!txt.match(/^\d{5}$/)) {
alert('Please enter the correct five digits in the box provided at the bottom of the form.');
which.elements[captchafield].focus();
return false; }
 var checkOK = "0123456789-";
var checkStr = which.elements[zipcodefield].value;
var allValid = true;
var decPoints = 0;
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;
  }
  allNum += ch;
}
if (!allValid)
{
  alert("Please enter only digit characters in the \"Zip Code\" field.");
  return false;
}

  if (!pass) {
    shortFieldName=tempobj.name.substring(8,30).toUpperCase();
    alert("The "+shortFieldName+" field is a required field.");
    return false;
  } else {
return true;
  }

}
