$(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 tema = $("select#tema").val();
		if (tema == "") {
      $("label#tema_error").show();
      $("input#tema").focus();
      return false;
    }


	var name = $("input#name").val();
		if (name == "") {
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }

	  var apellidos = $("input#apellidos").val();
		if (apellidos == "") {
      $("label#apellidos_error").show();
      $("input#apellidos").focus();
      return false;
    }

	var mail = $("input#mail").val();
		if (mail == "") {
      $("label#mail_error").show();
      $("input#mail").focus();
      return false;
    }

	var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }


	var msje = $("textarea#msje").val();
		if (msje == "") {
      $("label#msje_error").show();
      $("textarea#msje").focus();
      return false;
    }

	var txt_mail_to = $("input#txt_mail_to").val();

		//var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone;

		var dataString = 'tema='+ tema + '&name='+ name + '&apellidos='+ apellidos + '&mail=' + mail + '&phone=' + phone + '&msje=' + msje + '&txt_mail_to=' + txt_mail_to;

//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "../includes/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Su mensaje fu&eacute; enviado exitosamente!</h2>")
        .append("<p>Muy pronto le estar&eacute; contactando.</p><p>Soy Kike de Heredia, Un Siervo de Dios</p>")
        .hide()
        .fadeIn(1000, function() {
          $('#message').append("<img id='checkmark' src='../images/check.png' />");
        });
      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("select#tema").select().focus();
});

