$(function() {
	$("#SubscribeForm").submit(function() {
		
		// validate and process form
		// first hide any error messages
		$('.errorBox').text("");
		$('.errorBox').hide();
		$('.messageBox').hide();
		$('.positiveBox').hide();
		
		var Name = $("input#Name").val();
		
		if (Name == "") {
			$('.errorBox').text("You must provide your name!");
			$('.errorBox').show();
			$("input#Name").focus();
			return false;
		}
		
		var email = $("input#Email").val();
		
		if (email == "") {
			$('.errorBox').text("You must provide an e-mail address!");
			$('.errorBox').show();
			$("input#Email").focus();
			return false;
		}
		
		$('.messageBox').text("Please wait while we process your request...");
		$('.messageBox').show();
		
		setTimeout(function(){ self.SubmitForm() }, 750);
		
	return false;

	});

});

function SubmitForm() {

	var dataString = 'name=' + $("input#Name").val() + '&email=' + $("input#Email").val();
	//alert (dataString);return false;
	
	$.ajax({
		type: "POST",
		url: "/home/library/ajax_SubscribeSend.cfm",
		data: dataString,
		success: function() {
			$('.messageBox').hide();
			$('.positiveBox').html("Subscription request submitted!<br>Thank you!");
			$('.positiveBox').show();
			$(':input').val("");
			$('input.submit').val("Subscribe");
		}
	});
	
}
