function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}

function checkEmail(emailStr) {
var emailSyntax = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var matchArray = emailStr.match(emailSyntax);
if (matchArray == null) {
alert("That 'Email address' is in the wrong format. Please check it to continue.");
return false;
}
return true;
}

function checkForm(theForm){
	if (trim(theForm.contactname.value) == ""){
		alert("You must enter your 'Name' to continue.");
		theForm.contactname.focus();
		return false;
	}
	else if (trim(theForm.email.value) == ""){
		alert("You must enter an 'Email address' to continue.");
		theForm.email.focus();
		return false;
	}
	else if (checkEmail(theForm.email.value)==false){
		theForm.email.focus();
		return false;
	}
	else if (trim(theForm.telephone.value) == ""){
		alert("You must enter a 'Telephone number' to continue.");
		theForm.telephone.focus();
		return false;
	}
	else if (trim(theForm.telephone.value)==false){
		theForm.telephone.focus();
		return false;
	}
	else if (trim(theForm.enquiry.value) == ""){
		alert("You must 'Specify your enquiry' to continue.");
		theForm.enquiry.focus();
		return false;
	}
	return true;
}