$(function() {
  $('.form-error').hide();
  $('input.hometextbox').css({backgroundColor:"#FFF"});
  $('input.hometextbox').focus(function(){
    $(this).css({backgroundColor:"#FFFFDF"});
  });
  $('input.hometextbox').blur(function(){
    $(this).css({backgroundColor:"#FFF"});
  });

  $(".homesubmitbtn").click(function() {
    $('.form-error').hide();		
		
	  var fullname = $("#fullname").val();
		if (fullname == "") {
      $("#fullname_error").show();
      $("#fullname").focus();
      return false;
    }    
		var company = $("#company").val();
		if (company == "") {
      $("#company_error").show();
      $("#company").focus();
      return false;
    }    
		var email = $("#email").val();
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (email == "") {
      $("#email_error").show();
      $("#email").focus();
      return false;
    } else {
    	if(!filter.test(email)) {
    		$("#email_error").show();
    		$("#email").focus();
    		return false;
    	}
    }
    //var dataString = 'fullname='+ fullname + '&company=' + company;
	var dataString = $("#b3 form").serialize();
	//alert(dataString);
		
	$.ajax({
      type: "POST",
      url: "ajax.php",
      data: dataString+"&action=homeEnquiry",
      cache: false,
      beforeSend: function(){
	     $('#home-enquiry-form').html("<div id='thnx-msg'><img id='loading' src='/img/tm/loading.gif' alt='Loading...' /></div>");
	    },
      success: function() {
        $('#home-enquiry-form').html("<div id='thnx-msg'></div>");
        $('#thnx-msg').html("<img id='checkmark' src='/img/icons/128x128-check.png' alt='' />")
        .append("<h2 class='thnk'>Thank you for your enquiry!</h2>")
        .hide()
        .fadeIn(1500, function() {
          $('#thnx-msg').append("<p class='thnk'>A member of our team will be in touch shortly!</p>");
        });
      }
     });
		
    return false;
	});
});
