	var alertmessage = "";

//calling functions



function RunValidEmail (currentfield) {

		var textemail = document.getElementById(currentfield).value;
//alert(textemail);
		//remove all spaces
		textemail = textemail.replace(/\s+/g,"");

		//update form element
		document.getElementById(currentfield).value = textemail;

		//blank field check
		if (textemail == "") {
			alertmessage = 'Please enter email address.';
			return false;
		}

		//alert message
		alertmessage = '"' + textemail + '"  is not a valid email. Please enter another value.';

		//check for email format
		var numPat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		var matchString = textemail.match(numPat);
		if (matchString == null) {
			return false;
		}
		
}



function ValidEmail (currentfield) {
				currentfield = currentfield.id;
				if (RunValidEmail(currentfield)==false) {
					document.getElementById(currentfield).value = "";
					document.getElementById(currentfield).focus();
					alert(alertmessage);
					return false;
				 }
		
}