/*!
 * TGK Page JS
 * http://jquery.com/
 */

$(function () {

    $(".error").hide();

    $(".enviar").click(function () {

        //
        //form validation
        //

        $('.error').hide();
        var name = $("input#email").val();
        if (name == "") {
            $("label#email_error").show();
            $("input#email").focus();
            return false;
        }

        $('.error').hide();
        var pregunta = $("textarea#pregunta").val();
        if (pregunta == "") {
            $("label#pregunta_error").show();
            $("textarea#pregunta").focus();
            return false;
        }

        //
        //send form via ajax
        //

        var dataString = 'email=' + name + '&pregunta=' + pregunta;
        //alert(dataString); return false;

        $.ajax({
            type: "POST",
            url: "bin/process.php",
            data: dataString,
            success: function ()
            {
                //replace form with success message
                $('#contact_form').html("<div id='contact_message'></div>");
                $('#contact_message').html("<h2>Tu consulta ha sido recibida</h2>")
                .append("<p>Nos pondremos en contacto contigo muy pronto, a traves de la direccion de correo electronico que nos has facilitado. Gracias.</p>")
                .hide()
                .fadeIn(1500, function () {
                    $('#contact_message').append("<img id='checkmark' src='images/check.png' />");
                });
            }
        });

        return false;

    });
});
