$(function() {
  $('.error').hide();
  $(".loading").hide();
  $(".loadingOk").hide();
  $(".loadingError").hide();
  $('.text-input').css({backgroundColor:"#fff"});
  $('.text-input').focus(function(){
    $(this).css({backgroundColor:"#f4f9fd", borderColor:"#999"});
  });
  $('.text-input').blur(function(){
    $(this).css({backgroundColor:"#fff", borderColor:"#ccc"});
  });

  $(".buttonActive").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();

		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }

		$(".buttonActive").hide();
		$(".loading").show();
		
		var dataString = '&email=' + email;
		//alert (dataString);return false;
		
	$.ajax({
      type: "POST",
      url: "processNewsletter.php",
      data: dataString,
	  timeout:4000,
      success: function() {
		$(".loading").hide();
		$(".loadingOk").show();
		$('.text-input').attr("disabled", true);
		$('.text-input').val("");
      },
	  error: function() {
	  	$(".loading").hide();
		$(".loadingError").show();
	  }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
  $('.text-input').attr("disabled", false); 
});
