$(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 company = $("input#company").val();
		if (company == "") {
      $("label#company_error").show();
      $("input#company").focus();
      return false;
    }
	
	var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if ($('#form2').jVal()) {
      $("label#email_error").show();
      $("input#email").focus();
  
    }
		var phone2 = $("input#phone2").val();
		if (phone2 == "") {
      $("label#phone2_error").show();
      $("input#phone2").focus();
      return false;
    }
		var message = $("textarea#message").val();
		if (message == "") {
      $("label#message_error").show();
      $("textarea#message").focus();
      return false;
    }
		
		var dataString = 'company='+ company + '&name=' + name + '&email=' + email + '&phone2=' + phone2 + '&message=' + message;
		//alert (dataString);return false;
		if ( $('#form2').jVal() ) 
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Enquiry form Sucessfully submitted</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
 // $("input#name").select().focus();
});
