var Comunidad = {
    actionUrl: '/app_reg/php/user_check_session.php',
    idMenu: 'menu-reg',

    urlencode: function (str) {
        str = (str+'').toString();
        return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
                                                                        replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
    },

    checkSession: function () {
        $.ajaxSetup({
            error: function() {
                $('#' + Comunidad.idMenu).find('ul li').show();
            },
            cache: false
        });
        $.getJSON(Comunidad.actionUrl + '&jsoncallback=?&referer=' + Comunidad.urlencode(window.location.href), function (data) {
            if (data.res !== '') {
                if (data.res == 'error') {
                    alert(data.msg);
                    $('#' + Comunidad.idMenu).find('ul li').show();
                }
                if (typeof data.menu !== 'undefined') {
                    $('#' + Comunidad.idMenu).html(data.menu).find('ul').show();
                }
                if (typeof data.redirUrl !== 'undefined') {
                    window.location.href = data.redirUrl;
                }
                if (typeof data.reload !== 'undefined') {
                    window.location.href = window.location.href;
                }
            } else {
                $('#' + Comunidad.idMenu).find('ul li').show();
            }
        });
    },
    
    showLoginBox: function () {
        if ($('#menu-loginbox').is(':hidden')) {
            $('#menu-loginbox').show();
        } else {
            $('#menu-loginbox').hide();
        }
    }
};

