



function isNum(passedVal) {					// Is this a number?
	if (passedVal == "") {
		return false
	}
	for (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.First_name.value == "")
  		{
    		alert("Please enter a value for the \"First Name\" field.");
    		theForm.First_name.focus();
    		return (false);
  		}
  	
	

	
  		if (theForm.Last_name.value == "")
  		{
    		alert("Please enter a value for the \"Last Name\" field.");
    		theForm.Last_name.focus();
    		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 (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 a valid phone 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 = "@.";
		var 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);
		}
		

 
  		if (theForm.Address.value == "")
  		{
    		alert("Please enter a value for the \"Address\" field.");
    		theForm.Address.focus();
    		return (false);
  		}

 

  		if (theForm.Suburb.value == "")
  		{
    		alert("Please enter a value for the \"Suburb\" field.");
    		theForm.Suburb.focus();
    		return (false);
  		}
		
		
		
		

  		if (theForm.Postcode.value == "")
  		{
    		alert("Please enter a valid code in the \"Postcode\" field.");
    		theForm.Postcode.focus();
    		return (false);
  		}
  		
		if (!validZip(theForm.Postcode.value)) {
			alert("That is an invalid Postcode")
			theForm.Postcode.focus();
			theForm.Postcode.select();
			return false;
		}


 

  		if (theForm.Description.value == "")
  		{
    		alert("Please enter a value for the \"Description\" field.");
    		theForm.Description.focus();
    		return (false);
  		}
		
		
		
		



 
 
	return (true);
	
}




	


