// JavaScript Document

function validateEmail(email) {
/*	new version by Laurence 2004 Nov 26
	revised 2005 Nov 04 by Laurence: allow hyphens before @ symbol; rename 'verifyEmail' to 'validateEmail'

	RegExp is a Javascript1.2 feature; tested successfully in WinIE 5.0+, MacIE 5.1, Safari 1.0, WinNN 4.7, WinNN 6.2, WinMoz 1.7
	The pattern matches: 
	- at least one word character ( a-zA-Z0-9_ )
	- followed by any number more including periods and hyphens
	- then a single @
	- then at least one alphanumeric character plus any number more including hyphens and periods
	- plus an ending of an alphanumeric char, a single period, and at least 2 more letters. 
	There can be nothing before or after the pattern; all whitespace, punctuation, etc. not explicitly allowed is forbidden.
*/
	var myRegExp = /^[\w][\w\.\-]*@[a-zA-Z0-9]+[\w\.\-]*[a-zA-Z0-9]\.[a-zA-Z]{2,}$/;
	var sPos = email.search(myRegExp);
	if (sPos >= 0) {
		return true;
	} else {
		return false;
	}
}

function validateCustomer(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";

	if (theForm.firstName.value == ""){
		emptyFields += "The First Name cannot be blank." + "\n" ;
	} 
	
	 if (theForm.lastName.value == ""){
		emptyFields += "The Last Name cannot be blank." + "\n" ;
	} 
	
	 if (theForm.emailAddress.value == ""){
		emptyFields += "The Email Address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.emailAddress.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
		
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}