$(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 toName = $("input#toName").val();
		if (toName == "") {
      $("label#toName_error").show();
      $("input#toName").focus();
      return false;
    }
	
	var fromName = $("input#fromName").val();
		if (fromName == "") {
      $("label#fromName_error").show();
      $("input#fromName").focus();
      return false;
    }
	
		var fromEmail = $("input#fromEmail").val();
		if (fromEmail == "") {
      $("label#email_error").show();
      $("input#fromEmail").focus();
      return false;
    }
	
		var message = $("textarea#message").val();
		if (message == "") {
      $("label#message_error").show();
      $("textarea#message").focus();
      return false;
    }
	
	var subject = $("input#subject").val();
	
	var toEmail = $("input#toEmail").val();
		
		
		var dataString = 'toName=' + toName + '&fromName=' + fromName + '&fromEmail=' + fromEmail + '&message=' + message + '&subject=' + subject + '&toEmail=' + toEmail;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/data/modules/emailForm/bin/process.php",
      data: dataString,
      success: function() {
        $('#emailFormBody').html("<div id='thankYou'></div>");
        $('#thankYou').html(thanks)
        .hide()
        .fadeIn(1500, function() {
          $('#thankYou').append("<img id='checkmark' src='/data/modules/emailForm/img/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#fromName").select().focus();
});
