jQuery(function() {
  jQuery('.error').hide();
  jQuery('input.text-input').css({backgroundColor:"#FFFFFF"});
  jQuery('input.text-input').focus(function(){
    jQuery(this).css({backgroundColor:"#c9daee"});
  });
  jQuery('input.text-input').blur(function(){
    jQuery(this).css({backgroundColor:"#FFFFFF"});
  });
  
  // highlights the textarea when selected
  jQuery('.error').hide();
  jQuery('textarea').css({backgroundColor:"#FFFFFF"});
  jQuery('textarea').focus(function(){
    jQuery(this).css({backgroundColor:"#c9daee"});
  });
  jQuery('textarea').blur(function(){
    jQuery(this).css({backgroundColor:"#FFFFFF"});
  });

  jQuery(".button").click(function() {
		// validate and process form
		// first hide any error messages
    jQuery('.error').hide();
		
	var name = jQuery("input#name").val();
	if (name == "") {
      jQuery("label#name_error").show();
      jQuery("input#name").focus();
      return false;
    }
	var company = jQuery("input#company").val();
	if (company == "") {
      jQuery("label#company_error").show();
      jQuery("input#company").focus();
      return false;
    }
	var email = jQuery("input#email").val();
	if (email == "") {
      jQuery("label#email_error").show();
      jQuery("input#email").focus();
      return false;
    }
		var phone = jQuery("input#phone").val();
		if (phone == "") {
		  jQuery("label#phone_error").show();
		  jQuery("input#phone").focus();
		  return false;
		}
	
	var comments = jQuery("textarea#comments").val();
	if (comments == "") {
      jQuery("label#comments_error").show();
      jQuery("textarea#comments").focus();
      return false;
    }
	
		
		var dataString = 'name='+ name + '&company=' + company + '&email=' + email + '&phone=' + phone + '&comments=' + comments;
		//alert (dataString);return false;
		
		jQuery.ajax({
      type: "POST",
      url: "php/_formprocesser.php",
      data: dataString,
      success: function() {
        jQuery('#contact_form').html("<div id='message'></div>");
        jQuery('#message').html("<h3></h3>")
        .append("<p>Thank you, your request has been submitted, we will be in touch soon</p>")
       .hide()
        .fadeIn(1500, function() {
           jQuery('#message')/*.append("<img id='checkmark' src='images/check.png' />")*/;
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  jQuery("input#name").select().focus();
});
