var good_addr;
var attempts;
attempts = 0;

function validateEmailAddress(eAddress){
         attempts++;
         if (attempts >= 3 & eAddress == ""){return false;}
		 good_addr = true;
	 	 isEmail(eAddress);
	 	 if (good_addr == false){
		 	alert("The entered email address format is incorrect!\nPlease re-enter");
			document.getElementById("email").focus();
		 	return false;
			}
         return true;
		 }
	 
function isEmail(str) {
  		if (window.RegExp){
			var tempStr = "a";
    	 	var tempReg = new RegExp(tempStr);
    	 	if (tempReg.test(tempStr))
				{var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  				 var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  				 good_addr = !r1.test(str) && r2.test(str);
				 return;
				}
			}
		var at = 0;
		var dot = false;
		var x = 0;
  		for (var i = 0; i < str.length; i++) 
			{ch = str.substring(i, i + 1)
        	 if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == "@") || (ch == ".") || (ch == "_") || (ch == "-") || (ch >= "0" && ch <= "9"))
				{if (ch == "@") {at = at + 1}
                 if (ch == ".") {dot = true}
				 x++;
        		} 
			}
 		if (dot == false || at != 1) {good_addr = false; return}
		if (str.indexOf("@.") != -1) {good_addr = false; return}
		if (str.indexOf("..",str.indexOf("@")) > str.indexOf("@")) {good_addr = false; return}
		if (x != str.length){good_addr =  false; return}
		}
