$(function() {
  $('.error').hide();
  $('.text-input').css({backgroundColor:"#FFFFFF"});
  $('.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".submit-button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
	
	var first_name = $("input#first_name").val();
	if (first_name == "") {
      	$("label#first_name_error").show();
		$("input#first_name").css({backgroundColor:"#ee4036"});
      	$("input#first_name").focus();
      	return false;
    }
	
	var last_name = $("input#last_name").val();
	if (last_name == "") {
      	$("label#last_name_error").show();
		$("input#last_name").css({backgroundColor:"#ee4036"});
      	$("input#last_name").focus();
      	return false;
    }

	var email = $("input#email").val();
	if (email == "") {
      	$("label#email_error").show();
		$("input#email").css({backgroundColor:"#ee4036"});
      	$("input#email").focus();
      	return false;
    }

	var needs_summary = $("#needs_summary").val();
	if (needs_summary == "") {
      	$("label#needs_summary_error").show();
		$("#needs_summary").css({border:"1px solid #ee4036"});
      	$("#needs_summary").focus();
      	return false;
    }
	
	var phone = $("#phone").val();
	var company = $("#company").val();
	
	
	  $('#contact_form').html("<div id=\"AJAXLOADER\" class=\"ajaxLoaderContent\"><div style=\"text-align: center; padding: 50px 0px 0px 0px; font-size: 11pt; color: #b03a00;\">En traitement...</div><div style=\"text-align: center; padding: 20px 0px 50px 0px;\"><img src=\"images/ajax-loader.gif\" alt=\"ajax loader\" /></div></div>");
		
	  var dataString = 'first_name='+ first_name + '&last_name=' + last_name + '&email=' + email + '&phone=' + phone + '&company=' + company + '&needs_summary=' + needs_summary;
	  //alert (dataString);return false;
		
	  $.ajax({
      type: "POST",
      url: "includes/nous-joindre/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Message envoyé.</h2>")
        .append("<p>Un membre de notre équipe entrera en contact avec vous très bientôt.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("");
        });
      }
     });
    return false;
	});
});
/* runOnLoad(function(){
  $("input#name").select().focus();
}); */
