$(function() {
  $('.error').hide();
  $('.text-input').css({backgroundColor:"#E5EDF2"});
  $('.text-input').focus(function(){
    $(this).css({backgroundColor:"#F9F2C7"});
  });
  $('.text-input').blur(function(){
    $(this).css({backgroundColor:"#E5EDF2"});
  });


  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var nombre = $("input#nombre").val();
		if (nombre == "") {
      $("label#nombre_error").show();
      $("input#nombre").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var telefono = $("input#telefono").val();
		if (telefono == "") {
      $("label#telefono_error").show();
      $("input#telefono").focus();
      return false;
    }

	var mensaje = $("textarea#mensaje").val();
	
		
		var dataString = 'nombre='+ nombre + '&email=' + email + '&telefono=' + telefono + '&mensaje=' + mensaje;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contacto_form').html("<div id='contacto_ok'></div>");
        $('#contacto_ok').html("<img id='checkmark' src='img/mensaje.png' />")
        .hide()
        .fadeIn(0, function() {
          $('#contacto_ok').append("<img id='checkmark' src='img/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#nombre").select().focus();
});

