$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:""});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:""});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:""});
  });

  $(".button_c").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 ciudad = $("input#ciudad").val();
		if (ciudad == "") {
      $("label#ciudad_error").show();
      $("input#ciudad").focus();
      return false;
    }
	
		var texto = $("textarea#texto").val();
		if (texto == "") {
      $("label#texto_error").show();
      $("textarea#texto").focus();
      return false;
    }
		
		var dataString = '&nombre=' + nombre + '&email=' + email + '&ciudad=' + ciudad + '&texto=' + texto;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "../form.php",
      data: dataString,
      success: function() {
        $('#form_box').html("<div id='message'></div>");
        $('#message').html("<h2>Gracias ! Su Mensaje ha sido enviado!</h2>")
        .append("<p>En breve nos pondremos en Contacto con usted. Es posible que reciba la respuesta en su bandeja de <strong>CORREOS NO DESEADOS</strong> o <strong>SPAM</strong>.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='../design/check2.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#nombre").select().focus();
});
