function isValidEmail(passedVal) { //Is this a valid email?
  if(passedVal == "") {
     return (false);
  }
  for (i=0; i<passedVal.length; i++) {
     if (passedVal.charAt(i) == "@") {
		return (true);
     }
  }
  return (false);
}

function error_check(theForm) {

if (theForm.selCustTitle.value == 0) {
    alert("Please select customer title.");
    theForm.selCustTitle.focus();
    return (false);
  }
  
if (theForm.txtCustName.value == "") {
    alert("Please enter your name.");
    theForm.txtCustName.focus();
    return (false);
  }    

if (theForm.txtCustEmail.value == "") {
    alert("Please enter your e-mail address.");
    theForm.txtCustEmail.focus();
    return (false);
  }
   
if(theForm.txtCustEmail.value != "") {
	if (isValidEmail(theForm.txtCustEmail.value) == false)
	{
	  alert("Please enter a valid e-mail address.");
	  theForm.txtCustEmail.value = "";
	  theForm.txtCustEmail.focus();
	  return (false);
	}
  }
  
if (theForm.selRecTitle.value == 0) {
    alert("Please select Recipient title.");
    theForm.selRecTitle.focus();
    return (false);
  }  
  
if (theForm.txtRecName.value == "") {
    alert("Please enter Recipient name.");
    theForm.txtRecName.focus();
    return (false);
  }    
  
if (theForm.txtCustPostCode.value.length > 10) {
    alert("the Postcode is too long, the maximum allowed characters are 10");
    theForm.txtCustPostCode.focus();
    return (false);
  }

if (theForm.txtCustAddress.value.length > 200) {
    alert("the Address is too long, the maximum allowed characters are 200");
    theForm.txtCustAddress.focus();
    return (false);
  }   


return(true);

}
