// JavaScript Document

function isValidEmail(strEmail) {
	
	var msg;
	var i;
	var len=strEmail.length;
	if(strEmail=="") {
			msg="";
	} else {
		if((strEmail.charAt(0)=="@") || (strEmail.charAt(0)==".")) {
			msg="Invalid Email Address.";
		} else {
	//	checking the number of the @ and dots in the email add	
			var countAt=0;
			var countDot=0;
			for (i=0; i<len; i++) {
				if(strEmail.charAt(i)=="@") {
					countAt=countAt+1;
				}	
				if(strEmail.charAt(i)==".") {
					countDot=countDot+1;
				}
			} //end of for (i=0; i<strEmail.length; i++) {...	
			if((countAt!=1) || (countDot<1)) {
				msg="Invalid Email Address.";
			} else {
		//	checking the position of the @ with respect to the dot 
				var posDot=0;
				var posAt=0;
				posDot=strEmail.lastIndexOf(".");
				posAt=strEmail.indexOf("@");
				if((posAt>posDot) || (posDot==(posAt+1))) {
					msg="Invalid Email Address.";
				} else {
			//	checking the dot position and the @ postion at the end
					if((strEmail.charAt(len)=="@") || (strEmail.charAt(len)==".")) {
						msg="Invalid Email Address.";
					} else {
						/* 	checking for the invalid characters
						 if(ereg('[^A-Za-z0-9_]', strEmail)) {
					msg="Only letters, numbers and underscores(_).";		*/
						msg = "";
					} //end of if((strEmail.charAt(len)=="@") || (strEmail.charAt(len)==".")) {...
				} //end of if((posAt>posDot) || (posDot==(posDot+1))) {...
			} //end of if((countAt!=1) ||(countDot<1)) {...		
		} //end  if((strEmail.charAt(i)=="@") || (strEmail.charAt(i)==".")) {...
	} //end of if(strEmail=="") {...
	return msg;	
}//end function		