var deliverable = false;

function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	var mdiv = document.getElementById("Email_AddrMsg");
	mdiv.innerHTML = "<span class='error'>A valid <b>Email Address</b> is required</span>";
					
	if (matchArray==null) {
		return deliverable;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
		mdiv.innerHTML =  "<span class='error'>The name is not valid</span>";	
	     return deliverable;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
	    // this is an IP address
	  	for (var i=1;i<=4;i++) {
	    		if (IPArray[i]>255) {
				return deliverable;
		    }
    		}
 	}
	// Domain is symbolic name
	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
    		return deliverable;
	}
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || 
    		domArr[domArr.length-1].length>3) {
   		// the address must end in a two letter or three letter word.
		mdiv.innerHTML =  "<span class='error'>The address must end in a two letter or three letter word</span>";	
	   	return deliverable;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) {
		mdiv.innerHTML =  "<span class='error'>This address is missing a hostname</span>";	
   		return deliverable;
	}
	return true;
}
function pausecomp(millis){
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); }
	while(curDate-date < millis);
}
function checkValidNumber(val){
	var result = null;

	// For only positive whole numbers, including zero, uncomment the following:  
	result = val.match(/^\d+$/);

	// For only positive decimal numbers, including zero, uncomment the following:  
	// result = val.match(/^\d+(\.\d+)?$/);

	// For positive and negative decimal numbers, including zero, uncomment the following:  
	// result = val.match(/^-?\d+(\.\d+)?$/);

	// For positive and negative numbers, including zero, uncomment the following:  
	// result = val.match(/^-?\d+$/);

	return (result != null);
}
