// isEmail 1.0 
// Use this function in a javascript validation to ensure proper formatting of an email address text input...
// Created 4/2002, by MQ (c) Charter Oak State College
function isEmail(s){
	
	// declare the working variables
	var emailLength, notFound, atSign, firstPeriod, lastPeriod, whereAtSign, space;
	
	// pull in the values for the variables
	notFound 	= -1;								// set notFound to -1, equals the result of indexOf if the character is not found
	atSign		= s.indexOf("@"); 					// Get where the @ sign is
	emailLength = s.length; 						// what is the length
	firstPeriod = s.indexOf("."); 					// get where the '.' is
	lastPeriod 	= s.lastIndexOf(".", emailLength-1) // get where the end '.' is.  If there is one at the end.
	space 		= s.indexOf(" "); 					// are there any spaces (should return -1 for none)
	whereAtSign = (emailLength-1) - atSign; 		// figure out where in the address the @ sign is.
	
	// use the next line for debugging.
	//alert(firstPeriod +" - "+lastPeriod +" - "+whereAtSign);
	
	// If any of the following are true, this will return false, otherwise, it is a well formed email address.
	// @ and '.' are not found
	// the last '.' in the address is before the '@'
	// the @ sign is too close to the end of the string
	// there are any spaces in the address.
	if(atSign == notFound || firstPeriod == notFound || lastPeriod < atSign || whereAtSign < 2 || space != notFound || lastPeriod == (emailLength-1))
		return false;
	else
		return true;
}
