$(document).ready(function(){
	$("#emailsubmit").click(function(){
		errors = 0;
		email = $("#emailSignUp #address").val();
		errorString = "";
		if (email==""){
			errorString="You must enter your Email address.\n";errors++;
		}else if(email.indexOf(".") < 2 || email.indexOf("@") < 1 || email.indexOf(".") == email.length-1){ 
			errorString = "Please enter a valid Email address\n"; errors++; 
		}
		
		if(errors>0){
			$("#alertBox").html(errorString);
			$("#alertBox").effect('highlight', {color:"#FF0000"}, 1000);
		}else{
			$.ajax({
			  type: "POST",
			  url: "/scripts/addToNewsletter.php",
			  data: "email="+email,
			  dataType: 'json',
			  success: function(data){
				  if(data.error.length>0){
					$("#alertBox").html(data.error);
					$("#alertBox").effect('highlight', {color:"#FF0000"}, 1000);
				  }else{
					$("#alertBox").html(data.msg);
					$("#alertBox").effect('highlight', {color:"#FFF000"}, 1000);
				  }
			  },
			  error: function (msg, status, e){
				alert("errors: "+msg.error+" "+e+" "+status);
			  }
			});
		}
		return false;								 
	});
});