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

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	  var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }
	
	  var ap = $("input#ap").val();
		if (ap == "") {
      $("label#ap_error").show();
      $("input#ap").focus();
      return false;
    }
		var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
		
		var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
		var dia = $("input#dia_res").val();
		if (dia == "") {
      $("label#dia_error").show();
      $("input#dia").focus();
      return false;
    }
		var e2 = $("input#e2").val();
		var e3 = $("input#e3").val();
		var e4 = $("input#e4").val();
		var e5 = $("input#e5").val();
		var horario = $("input#horario").val();
		
		var dataString = 'name='+ name + '&ap='+ ap + '&email=' + email + '&phone=' + phone + '&dia_res=' + dia + '&e2=' + e2 + '&e3=' + e3 + '&e4=' + e4 + '&e5=' + e5 + '&horario=' + horario;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      //url: "bin/process.php",
	  url: "http://www.pixelsiete.com/clientes/web/reserva_delbosque.php",
      data: dataString,
      complete: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Datos Enviados!</h2>")
        .append("<p>En breve nos pondremos en contacto, gracias.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#name").select().focus();
});

