$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var enc_name = $("input#enc_name").val();
		if (enc_name == "") {
      $("label#enc_name_error").show();
      $("input#enc_name").focus();
      return false;
    }
		var enc_mail = $("input#enc_mail").val();
		if (enc_mail == "") {
      $("label#enc_mail_error").show();
      $("input#enc_mail").focus();
      return false;
    }
		var enc_detail = $("textarea#enc_detail").val();
		if (enc_detail == "") {
      $("label#enc_detail_error").show();
      $("textarea#enc_detail").focus();
      return false;
    }
		
		var enc_subject = $("input#enc_subject").val();
		if (enc_subject == "") {
      $("label#enc_subject_error").show();
      $("input#enc_subject").focus();
      return false;
    }
		
		
		var dataString = 'name='+ enc_name + '&email=' + enc_mail + '&details=' + enc_detail + '&subject=' + enc_subject;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "_classes/enc_process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2 class='fancy white'>Encouragement Submitted!</h2>")
        .append("<p class='footer_link white'>Once we moderate your note, it will be available to view @ <a href='http://encourage.branandjuli.com' class='noicon footer_link white'>Encourage &bull; BranAndJuli</a></p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#enc_name").select().focus();
});

