
function checkForm(theForm){
  var error="";
	
	if (theForm.name){
  	 error = isEmptyBox(theForm.name.value);
	}
	if (theForm.surname){
  	if (error==""){
  		error = isEmptyBox(theForm.surname.value);
  	}  
	}
	if (theForm.company){
  	if (error==""){
  		error = isEmptyBox(theForm.company.value);
  	}  
	}
	if (theForm.email){
  	if (error==""){
  		error = isEmptyBox(theForm.email.value);
  	}  
	}
	if (theForm.telno){
  	if (error==""){
  		error = isEmptyBox(theForm.telno.value);
  	}  	
	}
	if (theForm.postcode){
  	if (error==""){
  		error = isEmptyBox(theForm.postcode.value);
  	}  
	}
	if (theForm.profilename){
  	if (error==""){
  		error = isEmptyBox(theForm.profilename.value);
  	}  
	}
	if (theForm.profilepassword){	  
  	if (error==""){
  		error = isEmptyBox(theForm.profilepassword.value);
  	}  
  	if (error==""){
  		error = isEmptyBox(theForm.profilepasswordcheck.value);
  	}
	}
	if (theForm.pprofiler){
   	if (error==""){
  		error = isEmptyBox(theForm.pprofiler.value);
  	}  
	}
	if (theForm.tprofiler){
  	if (error==""){
  		error = isEmptyBox(theForm.tprofiler.value);
  	}  
	}
	if (theForm.FSANumber){
  	if (error==""){
  		error = isEmptyBox(theForm.FSANumber.value);
  	}  
	}
	if (theForm.ifacode){
  	if (error==""){
  		error = isEmptyBox(theForm.ifacode.value);
  	}  
  	if (error==""){
  		error = isEmptyBox(theForm.ifapassword.value);
  	}  
	}	
	if (theForm.postcode){
		 error += checkPostCode(theForm.postcode.value);
	}
  if (theForm.telno){
		 error += checkPhone(theForm.telno.value);
	}
	if (theForm.email){
		 if (!isEmptyBox(theForm.email.value)){
     		error += checkEmail(theForm.email.value);
		 }
	}
  if (error != "") {
    // write out the errors on the screen
		document.getElementById("jserrors").innerHTML=error;
		//alert(error);
    return false;
  }else{
  	return true;
	}
}

// email

function checkEmail (strng) {
  var error="";
  if (strng == "") {
     error = "Please enter an email address.<br />";
  }
  else{
    var emailFilter=/^.+@.+\..{2,4}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.<br />";
    }
    else {
  		 //test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.<br />";
       }
    }
  }
  return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
  var error = "";
  if (strng.length < 10&&strng!="") {
  	 error = "Please enter the full phone number including area code.<br />";
  } 
return error;
}

// postcode - 6 chars or more

function checkPostCode (strng) {
  var error = "";
  if (strng.length < 5&&strng!="") {
     error = "Please enter your correct postcode.<br />";
  }
return error;
}       


// non-empty textbox
function isEmptyBox(strng) {
  var error = "";
    if ((strng.length == 0)) {
       error = "Please fill in all boxes<br />"
    }
  return error;	  
}