//formcheck
//Added [1] instead of [0] to fix if more than 2 forms are on one page

function setFocus(aField) {
document.forms[1][aField].focus();
}

function isAnEmailAddress(aTextField) {
// 1+@3+ [or x@x.x] is as close as we will test

if (document.forms[1][aTextField].value.length<5) {
return false;
}
else if (document.forms[1][aTextField].value.indexOf("@") <1) {
return false;
}
else if (document.forms[1][aTextField].value.length - document.forms[1][aTextField].value.indexOf("@") <4) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.forms[1][aTextField].value.length==0) || (document.forms[1][aTextField].value==null)) {
return true;
}
else { return false; }
}

function validate() {

// check that the date field is valued
if (isEmpty("date")) {
	alert("Please enter todays date.");
	setFocus("date");
	return false;
}


// check that the name field is valued
if (isEmpty("name")) {
	alert("Could we have your name please.");
	setFocus("name");
	return false;
}

// check that the name field is valued
if (isEmpty("age")) {
	alert("Could we have your age please.");
	setFocus("age");
	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("address")) {
	alert("Please fill in the Address field, we may need to write to you..");
	setFocus("address");
	return false;
}

// if  everthing is ok submit the form
return true;
}