$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFE1E2"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFE1E2"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFE1E2"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("input#email").focus();
      return false;
    }
		var phone = $("input#phone").val();
		if (phone == "") {
      $("input#phone").focus();
      return false;
    }
		var telefone = $("input#telefone").val();
		if (telefone == "") {
      $("input#telefone").focus();
      return false;
    }
		var mensagem = $("textarea#mensagem").val();

		var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&telefone=' + telefone + '&mensagem=' + mensagem;
		//(dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<img id='checkmark' style='float:left; margin: 50px 10px 0 40px; width:48px;' src='images/check.png' alt='Checkmark' /><h3 style='line-height: 48px; margin-top: 55px;'>We will be in touch soon.</h3>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append(" ");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

