/**
 *
 */
jQuery(document).ready(function(){
    jQuery("#response_contacto").hide();
    jQuery("#loading_contacto").css("display", "none");
    jQuery("#response").css("display", "none");
    
    jQuery('#limpiar_contacto').click(function(){
        jQuery('.error').css("display", "none");
    });
    
    jQuery("#formContacto").validate({
        rules: {
            nombre: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            apellidos: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            email: {
                required: true,
                email: true,
                minlength: 3,
                maxlength: 50
            },
            mensaje: {
                required: true,
                minlength: 10,
                maxlength: 1000
            }
        },
        messages: {
            nombre: "Introduce tu nombre por favor",
            apellidos: "Introduce tus apellidos por favor",
            email: "Introduce un email válido por favor",
            mensaje: "Introduce un mensaje por favor ( 10 - 1000 caractéres)"
        },
        submitHandler: function(){
            jQuery("#formContacto").ajaxSubmit({
                beforeSubmit: showRequest, // pre-submit callback 
                success: showResponse // post-submit callback
            });
            
        },
        highlight: function(element, errorClass){
            //jQuery(element).addClass('error');
        },
        unhighlight: function(element, errorClass){
            //jQuery(element).removeClass('error');
        }
    });
    
    function showRequest(formData, jqForm, options){
        jQuery("#loading_contacto").show("slow");
    }
    
    // post-submit callback 
    function showResponse(responseText, statusText){
        jQuery("#loading_contacto").hide("slow");
        jQuery("#response_contacto").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery("#response").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery('form')[1].reset();
    }
    
    
    jQuery("#formContact").validate({
        rules: {
            nombre: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            apellidos: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            email: {
                required: true,
                email: true,
                minlength: 3,
                maxlength: 50
            },
            mensaje: {
                required: true,
                minlength: 10,
                maxlength: 1000
            }
        },
        messages: {
            nombre: "Type your name please",
            apellidos: "Type your last name please",
            email: "Type your email please",
            mensaje: "Type a message please ( 10 - 1000 characters )"
        },
        submitHandler: function(){
            jQuery("#formContact").ajaxSubmit({
                beforeSubmit: showRequest, // pre-submit callback 
                success: showResponse // post-submit callback
            });
            
        },
        highlight: function(element, errorClass){
            //jQuery(element).addClass('error');
        },
        unhighlight: function(element, errorClass){
            //jQuery(element).removeClass('error');
        }
    });
    
    function showRequest(formData, jqForm, options){
        jQuery("#loading_contacto").show("slow");
    }
    
    // post-submit callback 
    function showResponse(responseText, statusText){
        jQuery("#loading_contacto").hide("slow");
        jQuery("#response_contacto").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery("#response").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery('form')[1].reset();
    }
    
    jQuery("#formRegistro").validate({
        rules: {
            nombre: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            apellidos: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            email: {
                required: true,
                email: true,
                minlength: 3,
                maxlength: 50
            },
            mensaje: {
                required: true,
                minlength: 10,
                maxlength: 1000
            }
        },
        messages: {
            nombre: "Introduce tu nombre por favor",
            apellidos: "Introduce tus apellidos por favor",
            email: "Introduce tu email por favor",
            mensaje: "Introduce un mensaje ( 10 - 1000 caracteres )"
        },
        submitHandler: function(){
            jQuery("#formRegistro").ajaxSubmit({
                beforeSubmit: showRequest, // pre-submit callback 
                success: showResponse // post-submit callback
            });
            
        },
        highlight: function(element, errorClass){
            //jQuery(element).addClass('error');
        },
        unhighlight: function(element, errorClass){
            //jQuery(element).removeClass('error');
        }
    });
    
    function showRequest(formData, jqForm, options){
        jQuery("#loading_contacto").show("slow");
    }
    
    // post-submit callback 
    function showResponse(responseText, statusText){
        jQuery("#loading_contacto").hide("slow");
        jQuery("#response_contacto").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery("#response").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery('form')[1].reset();
    }
    
    jQuery("#formRegister").validate({
        rules: {
            nombre: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            apellidos: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            email: {
                required: true,
                email: true,
                minlength: 3,
                maxlength: 50
            },
            mensaje: {
                required: true,
                minlength: 10,
                maxlength: 1000
            }
        },
        messages: {
            nombre: "Type your name please",
            apellidos: "Type your last name please",
            email: "Type your email please",
            mensaje: "Type a message please ( 10 - 1000 characters )"
        },
        submitHandler: function(){
            jQuery("#formRegister").ajaxSubmit({
                beforeSubmit: showRequest, // pre-submit callback 
                success: showResponse // post-submit callback
            });
            
        },
        highlight: function(element, errorClass){
            //jQuery(element).addClass('error');
        },
        unhighlight: function(element, errorClass){
            //jQuery(element).removeClass('error');
        }
    });
    
    function showRequest(formData, jqForm, options){
        jQuery("#loading_contacto").show("slow");
    }
    
    // post-submit callback 
    function showResponse(responseText, statusText){
        jQuery("#loading_contacto").hide("slow");
        jQuery("#response_contacto").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery("#response").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery('form')[1].reset();
    }
    
    jQuery("#formEmpleo").validate({
        rules: {
            nombre: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            apellidos: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            email: {
                required: true,
                email: true,
                minlength: 3,
                maxlength: 50
            },
            mensaje: {
                required: true,
                minlength: 10,
                maxlength: 1000
            }
        },
        messages: {
            nombre: "Introduce tu nombre por favor",
            apellidos: "Introduce tus apellidos por favor",
            email: "Introduce tu email por favor",
            mensaje: "Introduce un mensaje ( 10 - 1000 caracteres )"
        },
        submitHandler: function(){
            jQuery("#formEmpleo").ajaxSubmit({
                beforeSubmit: showRequest, // pre-submit callback 
                success: showResponse // post-submit callback
            });
            
        },
        highlight: function(element, errorClass){
            //jQuery(element).addClass('error');
        },
        unhighlight: function(element, errorClass){
            //jQuery(element).removeClass('error');
        }
    });
    
    function showRequest(formData, jqForm, options){
        jQuery("#loading_contacto").show("slow");
    }
    
    // post-submit callback 
    function showResponse(responseText, statusText){
        jQuery("#loading_contacto").hide("slow");
        jQuery("#response_contacto").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery("#response").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery('form')[1].reset();
    }
    
    jQuery("#formJob").validate({
        rules: {
            nombre: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            apellidos: {
                required: true,
                minlength: 3,
                maxlength: 50
            },
            email: {
                required: true,
                email: true,
                minlength: 3,
                maxlength: 50
            },
            mensaje: {
                required: true,
                minlength: 10,
                maxlength: 1000
            }
        },
        messages: {
            nombre: "Type your name please",
            apellidos: "Type your last name please",
            email: "Type your email please",
            mensaje: "Type a message please ( 10 - 1000 characters )"
        },
        submitHandler: function(){
            jQuery("#formJob").ajaxSubmit({
                beforeSubmit: showRequest, // pre-submit callback 
                success: showResponse // post-submit callback
            });
            
        },
        highlight: function(element, errorClass){
            //jQuery(element).addClass('error');
        },
        unhighlight: function(element, errorClass){
            //jQuery(element).removeClass('error');
        }
    });
    
    function showRequest(formData, jqForm, options){
        jQuery("#loading_contacto").show("slow");
    }
    
    // post-submit callback 
    function showResponse(responseText, statusText){
        jQuery("#loading_contacto").hide("slow");
        jQuery("#response_contacto").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery("#response").show("slow").append(responseText).fadeTo(3000, 1).fadeOut(2000);
        jQuery('form')[1].reset();
    }
});
