    function ValidEMail(Id) {

		var EMail = document.getElementById(Id);
		if (!EMail) {alert("Cannot find " + Id); return false;}
		
		var Err = document.getElementById(Id + "Error");
		if (!Err) {alert("Cannot find " + Id + "Error"); return false;}
		

		var regexp = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
		//var regexp = /^[a-z0-9][a-z0-9_\.-]{0,}[a-z0-9]@[a-z0-9][a-z0-9_\.-]{0,}[a-z0-9][\.][a-z0-9]{2,4}$/;
		
		var email = Trim(EMail.value);
		//alert(email);
        if (!regexp.test(email)) {
			Err.style.display = "inline";
			return false;
		}
		Err.style.display = "none";
		EMail.value = Trim(email);
        return true;
		
    }

	function Required(Id) {
		
		var Field = document.getElementById(Id);
		if (!Field) {alert("Cannot find " + Id); return false;}
		
		var Err = document.getElementById(Id + "Error");
		if (!Err) {alert("Cannot find " + Id + "Error"); return false;}

		var input = Trim(Field.value);
		if (input == "") {
			Err.style.display = "inline";
			return false; 
		}
		Err.style.display = "none";
		return true; 
		
	}

	function MinChars(Id, nchars) {
		
		var Field = document.getElementById(Id);
		if (!Field) {alert("Cannot find " + Id); return false;}
		
		var Err = document.getElementById(Id + "Error");
		if (!Err) {alert("Cannot find " + Id + "Error"); return false;}

		input = Field.value.replace(/\s/, '');				// Remove all white space
		if (input.length < nchars) {
			Err.style.display = "inline";
			return false; 
		}
		Err.style.display = "none";
		return true; 
		
	}
	
	function Trim(str) {
		// http://blog.stevenlevithan.com/archives/faster-trim-javascript
		var r = str.replace(/^\s\s*/, '');
		r = r.replace(/\s\s*$/, '');
		return r;
	}


