//If adding new fields to the basic form page, all
//that needs to be changed on this page is the validate
//function with the new field names.

function validate() {
// Check that required fields are
// filled in - if not, send an alert
// with the name of the field that isn't.
// Set the cursor back to the field
// that needs to be filled in

// Name Field
if (isEmpty("name")) {
	alert("Oops, you forgot to enter your name.");
	setFocus("name");
	return false;
}
// Email Field
if (isEmpty("email")) {
	alert("Oops, you forgot to enter your email address.");
	setFocus("email");
	return false;
}

// Now that we have determined that all the 
// required fields are filled in, we need to
// determine that the email is in the proper
// format. Call the isAnEmailAddress function.
// If the email address isn't valid, alert the user, 
// put the cursor back to the email field
// and don't submit the form.
if (!isAnEmailAddress("email")) {
	alert("The email address you entered is invalid. Please enter a valid email address.");
	setFocus("email");
	return false;
}

// If we make it this far in the code, all
// required fields have been filled in and
// we have a properly formatted email, so
// now we return true to submit the form.
return true;

}

// This function takes the name of the field that was just
// alerted and put the cursor focus back on that field
function setFocus(aField) {
document.forms[0][aField].focus();
}

//This function takes the users input data for email address
//and determines if it is in proper format
function isAnEmailAddress(aTextField) {

	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; }
	}

//This function is passed the value of the input name and
//determines if the field is empty and returns a value of true
//to let the calling if statement know to send an alert
function isEmpty(aTextField) {
	if ((document.forms[0][aTextField].value.length==0) ||
 	(document.forms[0][aTextField].value==null)) {
	return true;
	}
	else { return false; }
}