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.name.value) == ""){
		alert("You must enter your 'Name' to continue.");
		theForm.name.focus();
		return false;
	}
	else if (trim(theForm.emailaddress.value) == ""){
		alert("You must enter an 'Email address' to continue.");
		theForm.emailaddress.focus();
		return false;
	}
	else if (checkEmail(theForm.emailaddress.value)==false){
		theForm.emailaddress.focus();
		return false;
	}
	else if (trim(theForm.telnumber.value)== ""){
		alert("You must enter a 'Telephone Number' to continue.");
		theForm.telnumber.focus();
		return false;
	}
	else if (trim(theForm.enquiry.value) == ""){
		alert("You must 'Specify your enquiry' to continue.");
		theForm.enquiry.focus();
		return false;
	}
	return true;
}