g_errorPID = null;

validateForm = function(evt){	
	evt = (document.all) ? event : evt;
	
	var email = $("#optinName");
	var name  = $("#optinEmail");
	
	evt.returnValue = false;
	
	if (jQuery.trim(email.val()).length > 0 &&
		jQuery.trim(name.val()).length > 0){
		validateEmail();
	} else {
		setErrorMessage("Missing fields!");
	}
	
	return false;
};

setErrorMessage = function(aMsg){
	$(".optinErrorClass").html(aMsg);
	$(".optinErrorClass").css("display","block");
	
	if (g_errorPID){
		clearInterval(g_errorPID);
	}
	
	g_errorPID = setTimeout("clearErrorMessage();",10*1000);		
};

clearErrorMessage = function(){
	$(".optinErrorClass").html("");
	$(".optinErrorClass").css("display","none");
};

validateEmail = function(){
	$.ajax({
		type: "POST",
		url: "emailvalidation.php",
		data:{
			email:jQuery.trim($("#optinEmail").val())
		},
		dataType: "text",
		success: function(resp){			
			if (resp == "NOTOK"){
				setErrorMessage("Email address invalid!");
				return;
			}
			
			clearErrorMessage();
			document.forms["optin"].submit();
		}
	});
};