var Popup = function Popup(Adresse_de_la_page, Nom_de_la_fenetre) {
    window.open(Adresse_de_la_page, Nom_de_la_fenetre, 'height=350px,width=400px,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,directories=no,status=no');
    window.location = window.location;
}

function isAuthorized() {
    if (getCookie('ISAUTHORIZED') != "") {
        return true;
    }

    return false;
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function showhide(list) {
    var listElementStyle = document.getElementById(list).style;
    if (listElementStyle.display == "none") {
        listElementStyle.display = "block";
    }
    else {
        listElementStyle.display = "none";
    }
}


function load() {

    if (document.getElementById('selected') != null) {
        var catId = document.getElementById('selected').value;


        var listElementStyle = document.getElementById(catId);
        var currentClass = null;
        var elemToSet;
        if (listElementStyle.hasChildNodes()) {
            for (i = 0; i < listElementStyle.childNodes.length; i++) {
                m = listElementStyle.childNodes[i];

                if (m.nodeType == 1) {
                    currentClass = m.getAttribute("class");

                    if (currentClass == null) {
                        currentClass = m.getAttribute("className");
                    }
                    elemToSet = m;
                }
            }
        }
        else {
            elemToSet = listElementStyle;
        }

        elemToSet.setAttribute("class", currentClass + "_active");
        elemToSet.setAttribute("className", currentClass + "_active");

        if (listElementStyle != null) {
            listElementStyle.style.display = "block";
            var parent = listElementStyle.parentNode;

            parent.style.display = "block";

            if (parent.parentNode != null) {
                parent.parentNode.style.display = "block";
                parent.parentNode.parentNode.style.display = "block";
            }
        }
    }

    //HANDLE CONNEXION PART
    var lnk = document.getElementById('lnkLogin');

    if (lnk != null) {
        if (isAuthorized()) {
            if (lnk.href.indexOf("../") != -1)
            {
                lnk.href = '../Logout.aspx';
            }
            else
            {
                lnk.href = 'Logout.aspx';
            }
            
            lnk.innerHTML = 'D&eacute;connexion';
        }
        else {
            if (lnk.href.indexOf("../") != -1)
            {
                lnk.href = '../Login.aspx';
            }
            else
            {
                lnk.href = 'Login.aspx';
            }
            lnk.innerHTML = 'Connexion';
        }
    }
}
