// JavaScript Document

function sendEmail(email) 
{
	//alert( "sendEmail" );
	
   http = getHttpRequest();
	
	var url = "email_updates.php"; 
	var myRandom = parseInt(Math.random()*99999999); // cache buster 
	
	http.open("GET", url + "?email=" + escape(email) + "&rand=" + myRandom, true); 
	
	var message = "Thanks for your interest in the Jackson County Brevet!!!";
	
	//alert( message );
	
	http.onreadystatechange = handleHttpResponse( message ); // Call handleMemberHttpResponse if ready state changes
	
	http.send(null); 	
}				

/**
 * DHTML email validation. The following function (echeck, ValidateForm) courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
 
function echeck(str) 
{
	//alert( "echeck" );
	
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Please enter a valid email address")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Please enter a valid email address")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Please enter a valid email address")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Please enter a valid email address")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Please enter a valid email address")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Please enter a valid email address")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Please enter a valid email address")
		    return false
		 }

 		 return true					
	}

function ValidateEmailForm()
{
	//alert( "ValidateEmailForm" );
	
	var emailID=document.email_updates.email
	
	if ((emailID.value==null)||(emailID.value==""))
	{
		alert("Please enter your email address")
		emailID.focus()
		return false
	}
	
	if (echeck(emailID.value)==false)
	{
		emailID.value=""
		emailID.focus()
		return false
	}
	
	//alert( "ValidateEmailForm2" );
	
	sendEmail(emailID.value);
	
	//alert( "ValidateEmailForm3" );
	
	return true
}


