$(document).ready(function() 
{
	$("#response").hide();
	$("#ajax-loader").hide();
	$("#submit").click(postToDB);
	
	$("#userEmail").click(function() 
	{
		$("#userEmail").val("");
	});
	
	$("#userEmail").blur(function() 
	{
		if($("#userEmail").attr('value') == "")
		{
			$("#userEmail").val("email address")
		}
	});	
});

function postToDB()
{	
	$("#ajax-loader").show();
	
	$.ajax({
		type: "GET",
		url: "/capture.aspx",
		data: "email=" + $("#userEmail").attr('value'),
		success: function(data) 
		{
			console.log(data);
			if(data == "FAIL") 
			{
				alert('Please enter a valid email adress!');
				$("#response").hide();
			} 
			else 
			{
				$("#response").html = "Thanks! We'll be in touch";
				$("#response").show();
				$("#subscribe").hide();
				$("#response").hide();
			}
			
		}
	});
}
