// Return an error message for an invalid Email.
function invalidEmailErrorMsg () {
	var invalidEmailErrorMsg =
	"\nPlease enter your \"Email\" in the following format:\n";
	invalidEmailErrorMsg += "login@someplace.com\n";
	return invalidEmailErrorMsg;
}// end subroutine.

// Tests email with a regular expression.
// returns true if email is valid
// else return false.
function isEmailValid ( inEmail ) {
	var ret = true;
	// This is the email regular expression.
	// The minimum accepted is x@x.x
	// where x is any alphanumeric character.
	var emailRegEx = /([\b\w-_]+)@(([\b\w-_]+)(\.+)([\b\w-_]+)+)/
	var email = inEmail;
	var result = email.match( emailRegEx );
	if ( result == null ) {
		ret = false;
	}// end if.
	return ret;
}// end subroutine.

// tests the email after a user changes it.
function testForValidEmail () {
	var email = document.HallOfRecords.sEmail.value;
	var result = isEmailValid( email );
	if ( !result ) {
		var errorMsg = invalidEmailErrorMsg();
		document.HallOfRecords.sEmail.focus();
		alert (errorMsg);
	}// end if.
	return result;
}// end subroutine.

function checkForm () {
	// Regular expression, one or more character.
	var anyChars = /.+/;
	var result = null;
	var ret=true;

	// check the applicants first name
	var FirstName =
	document.HallOfRecords.sFirstName.value;
	result = FirstName.match( anyChars );
	if ( result == null ) {
		ret=false;
		document.HallOfRecords.sFirstName.focus();
		alert("\nPlease enter your \"First Name\".\n");
		return ret;
	}// end if.

	// check the applicants last name
	var LastName =
		document.HallOfRecords.sLastName.value;
	result = LastName.match( anyChars );
	if ( result == null ) {
		ret=false;
		document.HallOfRecords.sLastName.focus();
		alert("\nPlease enter your \"Last Name\".\n");
		return ret;
	}// end if.

	// check the applicants email
	var Email =
	document.HallOfRecords.sEmail.value;
	result = isEmailValid( Email );
	if ( !result ) {
		ret=false;
		document.HallOfRecords.sEmail.focus();
		alert( invalidEmailErrorMsg() );
		return ret;
	}// end if.

	// check the phone
	var Phone =
	document.HallOfRecords.sPhone.value;
	result = Phone.match( anyChars );
	if ( result == null ) {
		ret=false;
		document.HallOfRecords.sPhone.focus();
		alert("\nPlease enter your \"Telephone\" number.\n");
		return ret;
	}// end if.

	return ret;
}// end subroutine.
