$(document).ready(function() {

// Test if the email container is on the page
if ( $("#email_signup_container").length ) {

	// bind to the email form
	$("#email_signup").submit(function(){
		//check if the name and email are filled in
		if ($("#email_name").val() == 0)
		{
			alert ("Name required.");
			return false;
		}

		if ($("#email_email").val() == 0)
		{
			alert ("Email address required.");
			return false;
		}


		// call ajax_email.php
		response = $.ajax({
			url:"ajax_email.php",
			global: false,
			type: "POST",
			beforeSend: function(x,msg) {
				$("#submit_email").hide();
				$("#email_signup_loading").show();
			},
			complete: function(x,msg) {
				$("#email_signup_loading").hide();
			},
			data: ({
				email_name:$("#email_name").val(),
				email_email:$("#email_email").val(),
				general:"true",
				book_info:"true"
			}),
			dataType: "html",
			success: function(msg){
				$("#email_signup_container").html("<p>Thank you for subscribing. You will be sent a confirmation email shortly with instructions on finalizing your subscription.</p>");	
			},
			error: function(msg){
				$("#email_signup_container").html("<p>There was an error with your subscription. Please try again later or contact <a href='mailto:webmaster@lindagalindo.com'>webmaster@lindagalindo.com</a>.</p>");	
			}
		}).responseText;
		return false;
	})
	
/*
	
	sign_up_form_html  = $.ajax({
	      url: sign_up_form_url,
	      global: false,
	      type: "POST",
	      data: ({
		name : "Joe Harkins",
		email : "jharkins@gmail.com",
		emailconfirm : email,
		subscribe : "Subscribe",
		htmlemail: "1"
		}),
	      dataType: "html",
	      success: function(msg){
		$("#email_signup_container").html(msg);
		//alert(msg);
	      }
	   }
	).responseText;
*/	
}

});
