$(function() {

  $('.error').hide();
  $('.error_captcha').hide();
  $(".getInTouchBtn").click(function() {
	
  
		// validate and process form
		// first hide any error messages
    $('.error').hide();
	
		
	    var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var company = $("input#company").val();
		if (company == "") {
      $("label#company_error").show();
      $("input#company").focus();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		

		challengeField = $("input#recaptcha_challenge_field").val();
		responseField = $("input#recaptcha_response_field").val();
	
	var dataString = 'name='+ name + '&company=' + company + '&phone=' + phone + '&email=' + email + '&recaptcha_challenge_field=' + challengeField + '&recaptcha_response_field=' + responseField;
		
	var html = $.ajax({
      type: "POST",
      url: "process.php",
      data: dataString,
    async: false
    }).responseText;
    
    if(html == "success")
    {
        $('#getInTouch').html("<h1 class='grey'>Get in touch!</h1><h2>Thanks for contacting us.</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1000, function() {
        });
    }
    else
    {
		$("label#captcha_error").show();
        Recaptcha.reload();
        return false;
    }

});
});

