/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

// centraliza container vertical

(function ($) {

    $.fn.Vcentralize = function () {
        var h_div = this.outerHeight();
        var h_screen = window.innerHeight;
        var h_atual = (h_screen / 2) - (h_div / 2);
        this.offset({top: h_atual});
    };

}(jQuery));

// Abre janela centralizada

(function ($) {

    $.fn.janelaCentro = function (options) {

        // Establish our default settings
        var settings = $.extend({
            w: null,
            h: null,
            confirma: null
        }, options);


        return this.each(function () {// pra cada elemento aplica o plugin
            
            $(this).click(function () {

                var status = true;

                if ($.isFunction(settings.confirma)) {
                    status = settings.confirma.call(this);
                }
                
                if (status === false) {
                    return false;
                }

                var url = $(this).prop('href');
                var left = (screen.width / 2) - (settings.w / 2);
                var tops = (screen.height / 2) - (settings.h / 2);
                
                var janela = window.open(url, "", "width=" + settings.w + ", height=" + settings.h + ", top=" + tops + ", left=" + left);
               
                var id_int_login = setInterval(function () {
                    
                    if (janela.closed === true) {
                        window.location.reload();
                        clearInterval(id_int_login);
                    }
                    
                }, 1000);
                
                return false;
                
            });

        });

    };



}(jQuery));
