$().ready(function () {

    // validate signup form on keyup and submit
    $("#newsleter_form").validate({
        rules: {
            email_news: {
                required: true,
                email: true
            }
        },
        errorLabelContainer: $("#newsleter_form p.aviso"),
        invalidHandler: function (form, validator) {
            var errors = validator.numberOfInvalids();
            $('.aviso').html('');
        },
        submitHandler: function (form) {
            //alert('valid form');
            $.ajax({
                type: "POST",
                url: $(form).attr('action'),
                data: $(form).serialize(),
                success: function (data) {
                    var timer;
                    $('.aviso').html('Pronto recibirás nuestras novedades!');
                    $('.aviso').css('display', 'visible');
                    $('#email_news').val('');
                    timer = setInterval(function () {
                        $('.aviso').hide().html('');
                    }, 5000);
                    timer = null;
                    //$('.aviso').hide(10000).html('');

                }
            });
            return false;
        }

    });
});	