function checkNewsletterEmail(str) {
	var at = "@";
	var dot = ".";
	var len_str = str.length;
	var len_at = str.indexOf(at);
	var len_dot = str.indexOf(dot);

	// Test if "@" exists and that it is not at the beginning and/or end of the email address
	if ((str.indexOf(at) == -1) || (str.indexOf(at) == 0) || (str.indexOf(at) == len_str)) {
		alert("Please enter a valid email address.");
		return false;
	}

	// Test if "." exists and that it is not at the beginning and/or end of the email address entered
	if ((str.indexOf(dot) == -1) || (str.indexOf(dot) == 0) || (str.indexOf(dot) == len_str)) {
		alert("Please enter a valid email address.");
		return false;
	}

	// Test more than one "@"
	if (str.indexOf(at,(len_at + 1)) != -1) {
		alert("Please enter a valid email address.");
		return false;
	}

	// Test relative positions of "@" and "." to each other
	if (str.substring(len_at - 1,len_at) == dot || str.substring(len_at + 1,len_at + 2) == dot) {
		alert("Please enter a valid email address.");
		return false;
	}

	// Test if there is at least one "." after the "@"
	if (str.indexOf(dot,(len_at + 2)) == -1) {
		alert("Please enter a valid email address.");
		return false;
	}

	// Test if there are spaces in the email address
	if (str.indexOf(" ") != -1) {
		alert("Please enter a valid email address.");
		return false;
	}
	return true					
}

function validateNewsletterEmail(){
	var newsletterEmail = document.getElementById("newsletterEmail");
	
	if ((newsletterEmail.value == null) || (newsletterEmail.value == "")) {
		alert("Please Enter your email Address.")
		newsletterEmail.focus()
		return false
	}
	if (checkNewsletterEmail(newsletterEmail.value) == false){
		newsletterEmail.value = ""
		newsletterEmail.focus()
		return false
	}
	return true
 }

