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() {
// will return true or false
// Step 1: check that required fields are
// filled in, alert and exit without
// submitting if not

// check that the name field is valued
if (isEmpty("name")) {
	alert("Please fill in all required fields.");
	setFocus("name");
	return false;
}



// check that the email field is valued
if (isEmpty("email")) {
	alert("Please fill in your Email address.");
	setFocus("email");
	return false;
}



// Step 2: check that the email address is
// even close, alert and exit without
// submitting if not
if (!isAnEmailAddress("email")) {
	alert("The entered email address is invalid.");
	setFocus("email");
	return false;
}

// if we get this far everthing is ok, so
// let the form submit
return true;

}

