
// This function is to be called from any form that allows entry of an email address.
// It checks to see if the text is a properly formed email address.
// To use, simply add onChange="checkEmail(this);" to the html input tag.

function checkEmail(txtEmail)
{
// The regexp below means... start the line with one or more word characters (^\w+), followed by
// zero or more ocurrences of a single period followed by one or more word characters ((\.{1}\w+)*),
// followed by one at symbol (\@), followed by one or more occurances of one or more word characters
// followed by a single period ((\w+\.)+), followed by one or more word characters (\w+) at the end of
// the line ($).
//  var pattern = /^\w+(\.{1}\w+)*\@(\w+\.)+\w+$/;
	var pattern = /^.+@[^\.].*\.[a-z]{2,}$/;
	var result;
	var badMatch = false;
	var working_email = new String(txtEmail.value);
	
	working_email = working_email.replace("; ", ",");
	working_email = working_email.replace(";", ",");
	working_email = working_email.replace(", ", ",");
	
	//If they entered multiple email addresses, they must separate with a comma and space.
	var arrAddrs = working_email.split(",");

	//alert("there are " + arrAddrs.length + " email addresses");
	for (var i = 0; i < arrAddrs.length; i++)
	{
		//alert("this one is:'" + arrAddrs[i] + "'");
		result = arrAddrs[i].match(pattern);
		if (result == null)
			badMatch = true;
	}
	if (badMatch)
	{	
		alert ("You did not enter a proper email address.  Please try again.");
		return false;
	}
	return true;
}
