// email validation script for the Golds Gym Sydney website for the newsletter sign up page.
// Written by Dale Fyfe for Quoth Design, May 2007


function validateEmail()
{
	var email = document.newsletter.email.value;
	var errorMsg = "";
	
	if(email == "")
		{
			errorMsg = "You must specify an email address for us to send the newsletter to.";	
		}
		//if there is an email address then we need to make sure it is of a valid syntax of text@moretext.moretext
		else
		{
			var first = email.charAt(0);//first char of the email address
			var last = email.charAt(email.length -1);//Last char of the email address
			var foundSymbol = email.indexOf('@');// Where abouts the @ symbol is in the email address, returns -1 if not there
			var foundDot = email.indexOf('.');// Where the dot is in the email address.
			
			//if the @ symbol is not there, is at the start, or at the end, then the email is not valid
			if ((foundSymbol == -1) || (foundSymbol == 0) || (foundSymbol == email.length -1))
			{
				errorMsg = errorMsg + "The @ symbol in your email address is either missing, or in the wrong place.\n";
				document.newsletter.email.value="";	
			}
			//if the dot is not there, is at the start, or at the end, then the email is not valid
			if ((foundDot == -1) || (foundDot == 0) || (foundDot == email.length -1))
			{
				errorMsg = errorMsg + "the . (dot) in your email address is either missing, or in the wrong place.\n";
				document.newsletter.email.value="";	
			}
		}
		if( errorMsg == "")
		{
			return true;	
		}
		else
		{
			alert(""+errorMsg);
			return false;
		}
}
	