$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFffff"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
		var terminos = $("input#terminos").val()
		if (!document.contact.terminos.checked) {
			alert("Debe aceptar la politica de privacidad");
			return false;
	}
			
	
		var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(email)) {
	  $("label#email_error").show();
      $("input#email").focus();
      return false;
		}
		
		var dataString = 'name='+ name + '&email=' + email;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Gracias por suscribirse.</h2>")
        .append("<p>Lo mantendremos al tanto de nuestras novedades y promociones.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<!--p><img id='checkmark' src='images/check.png' align='center' /></p-->");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
 $("input#name").select().focus();
});
