// JavaScript Form Validation

function setFocus(aField) {
document.contactForm[aField].focus();
}

function isAnEmailAddress(aTextField) {
// 1+@3+ [or x@x.x] is as close as we will test

if (document.contactForm[aTextField].value.length<5) {
return false;
}
else if (document.contactForm[aTextField].value.indexOf("@") < 1) {
return false;
}
else if (document.contactForm[aTextField].value.length -
 document.contactForm[aTextField].value.indexOf("@") < 4) {
return false;
}
else { return true; }
}

function isEmpty(aTextField) {
if ((document.contactForm[aTextField].value.length==0) ||
 (document.contactForm[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 first name field is valued
if (isEmpty("omsna")) {
	alert("Please fill in all required fields. Name is missing.");
	setFocus("omsna");
	return false;
}
// check that the email field is valued
if (isEmpty("omsph")) {
	alert("Please fill in all required fields. Phone is missing.");
	setFocus("omsph");
	return false;
}
// check that the email field is valued
if (isEmpty("omsem")) {
	alert("Please fill in all required fields. Email is missing.");
	setFocus("omsem");
	return false;
}
if (isEmpty("day")) {
	alert("Please select a day.");
	setFocus("day");
	return false;
}
if (isEmpty("time")) {
	alert("Please select a time.");
	setFocus("time");
	return false;
}




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

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

}