


//formcheck

// To fix errors change [0] to [1] if using more than one form.



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("realname")) {

	alert("Could we have your name please.");

	setFocus("realname");

	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 Tel field is valued

if (isEmpty("tel")) {

	alert("Please fill in the Telephone field, we may need to call you.");

	setFocus("tel");

	return false;

}

// check that the Message field is valued

if (isEmpty("textarea-quote")) {

	alert("Please complete the message field.");

	setFocus("textarea-quote");

	return false;

}

// if  everthing is ok submit the form

return true;

}