//formcheck
//Added [1] instead of [0] to fix if more than 2 forms are on one page

function setFocus(aField) {
document.forms[0][aField].focus();
}

function isAnEmailAddress(aTextField) {
// 1+@3+ [or x@x.x] is as close as we will test

if (document.forms[0][aTextField].value.length<5) {
return false;
}
else if (document.forms[0][aTextField].value.indexOf("@") <1) {
return false;
}
else if (document.forms[0][aTextField].value.length - document.forms[0][aTextField].value.indexOf("@") <4) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.forms[0][aTextField].value.length==0) || (document.forms[0][aTextField].value==null)) {
return true;
}
else { return false; }
}

function validate() {

// check that the name field is valued
if (isEmpty("name")) {
	alert("Could we have your name please.");
	setFocus("name");
	return false;
}

// check that the email field is valued
if (isEmpty("email")) {
	alert("Please complete the email field with valid email address.");
	setFocus("email");
	return false;
}

// Check that the email address is valid
if (!isAnEmailAddress("email")) {
	alert("The entered email address is invalid. Please check and try again");
	setFocus("email");
	return false;
}

// check that the phone  field is valued
if (isEmpty("tel")) {
	alert("Could we have your telephone number, we may need to contact you.");
	setFocus("tel");
	return false;
}

// check that the message field is valued
if (isEmpty("message")) {
	alert("Please leave a message.");
	setFocus("message");
	return false;
}

// if  everthing is ok submit the form
return true;
}