



function isNum(passedVal) {					// Is this a number?
	if (passedVal == "") {
		return false;
	}
	for (var i=0; i<passedVal.length; i++) {
		if (passedVal.charAt(i) < "0") {
			return false;
		}
		if (passedVal.charAt(i) > "9") {
			return false;
		}
	}
	return true;
}

function validZip(inZip) {					// Is this a valid Zip code?
	if (inZip == "") {
		return true;
	}
//	if (isNum(inZip)) {						// Check if Zip is numeric
//		return true
//	}
//	return false
    return true;
}


function Form1_Validator(theForm)
{
		// remove the next var lines for direct mail
		//var codestr = location.search.substring(1, location.search.length);
		//alert("The content of code is " + codestr)
		
		//alert(codestr.indexOf('='));
		//alert(codestr.length);
		//var code = codestr.substring(codestr.indexOf('=')+1, codestr.length);
		//alert(code);
	
  		if (theForm.fname.value == "")
  		{
    		alert("Please enter a value for the \"First Name\" field.");
    		theForm.fname.focus();
    		return (false);
  		}
  	
	

	
  		if (theForm.lname.value == "")
  		{
    		alert("Please enter a value for the \"Last Name\" field.");
    		theForm.lname.focus();
    		return (false);
  		}
  		


 
  		if (theForm.address.value == "")
  		{
    		alert("Please enter a value for the \"Address\" field.");
    		theForm.address.focus();
    		return (false);
  		}

 

  		if (theForm.city.value == "")
  		{
    		alert("Please enter a value for the \"City\" field.");
    		theForm.city.focus();
    		return (false);
  		}



		stateChoice = theForm.state.selectedIndex;
		if (theForm.state.options[stateChoice].value == "")
  		{
    		alert("Please select a value for the \"State\" field.");
    		theForm.state.focus();
    		return (false);
  		}


  		if (theForm.zip.value == "")
  		{
    		alert("Please enter a valid code in the \"postcode\" field.");
    		theForm.zip.focus();
    		return (false);
  		}
  		
		if (!validZip(theForm.zip.value)) {
			alert("That is an invalid Zip code");
			theForm.zip.focus();
			theForm.zip.select();
			return false;
		}

		
	

		if (theForm.phone.value == "")
  		{
    		alert("Please enter a valid number for the \"Phone\" field.");
    		theForm.phone.focus();
    		return (false);
  		}

  		var checkOK = "0123456789-() +";
		var checkStr = theForm.phone.value;
		var allValid = true;
		var allNum = "";
		for (var i = 0;  i < checkStr.length;  i++)
		{
		  ch = checkStr.charAt(i);
		  for (var 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 a valid number in the \"phone\" field.");
		  theForm.phone.focus();
		  return (false);
		}
  		
 

		if (theForm.emailid.value == "")
  		{
    		alert("Please enter a valid email for the \"Email\" field.");
    		theForm.emailid.focus();
    		return (false);
  		}

		var checkEmail = "@.";
		checkStr = theForm.emailid.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("The \"email\" field is invalid, please try again. It must contain an \"@\" and a \".\".");
		  theForm.emailid.focus();
		  return (false);
		}
 
 
	return (true);
	
}




	

 
