function ValidateEmail(email)
{
	var count=0; var atPos=0; var invalidChars = "\/'\\ \";:?!()[]\{\}^|";

	email = Trim(email);

	// Check for invalid charactors
	for (count=0; count<invalidChars.length; count++) {
		if (email.indexOf(invalidChars.charAt(count),0) > -1) {
			return false;
		}
	}
	
	// Check for non-ascii charactors
	for (count=0; count<email.length; count++) {
		if (email.charCodeAt(count)>127) {
			return false;
		}
	}

	// Check for @ symbol - if exists, position, no more than one 
	atPos = email.indexOf("@",0);
	if ((atPos<1)||(email.indexOf("@", atPos+1)>-1)) {
		return false;
	}

	// Check for period in domain portion & make sure period placement is correct.
	if ((email.indexOf(".", atPos)==-1)||(email.indexOf('@.',0)!=-1)||(email.indexOf('.@',0)!=-1)||(email.indexOf('..',0)!=-1)) {
		return false;
	}
	
	// Make sure domain is a vaild length.
	if (email.substring(email.lastIndexOf(".")+1).length<2) {
		return false;
	}

	return true;
}

function Trim(tempString) {
	while (tempString.charAt(0)==" ") {
		tempString=tempString.substring(1);
	} 
	
	while (tempString.charAt(tempString.length-1)==" ") {
	    tempString=tempString.substring(0, tempString.length - 1);
	}

	return tempString;
}
