    var openRoleList = new Array();
    var downloadedRoles = new Array();
    var downloadedAll = false;

    function addToOpenRoles (item) {
        for (var i = 0; i < openRoleList.length; i++) {
            if (openRoleList[i] == null || openRoleList[i] == '') {
                openRoleList[i] = item;    
                updateCookiesRole();
                return;     
            }
        }
        openRoleList[openRoleList.length] = item;
        updateCookiesRole();
    }
    
    function isInDownloadedRoles (item) {
        if (item == '000000000000000') {
            return true;
        }
        
        for (var i = 0; i < downloadedRoles.length; i++) {
            if (downloadedRoles[i] == item) {
                return true;
            }
        }
        return false;
    }    
    
    function removeFromOpenRoles (item) {   
        for (var i = 0; i < openRoleList.length; i++) {
            if (openRoleList[i] == item) {
                openRoleList[i] = null;            
            }
        }
        updateCookiesRole();
    }
    
    function updateCookiesRole() {
        var stringlist = "";
        for (var i = 0; i < openRoleList.length; i++) {
            if (openRoleList[i] != null && openRoleList[i] != '') {
                stringlist = stringlist + openRoleList[i] + ":";
            }
        }

        SetCookieRoles("roleopen", stringlist, null, "/");     
    }
    
    function SetCookieRoles (name, value) {  
        var argv = SetCookieRoles.arguments;  
        var argc = SetCookieRoles.arguments.length;  
        var expires = (argc > 2) ? argv[2] : null;  
        var path = (argc > 3) ? argv[3] : null;  
        var domain = (argc > 4) ? argv[4] : null;  
        var secure = (argc > 5) ? argv[5] : false;  

        document.cookie = name + "=" + value + 
            ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
            ((path == null) ? "" : ("; path=" + path)) +  
            ((domain == null) ? "" : ("; domain=" + domain)) +    
            ((secure == true) ? "; secure" : "");
        }
    
    function toggleRoles(img, blockNum, roleId) {
       var obj=document.getElementById(blockNum);
       if (obj != null) {
           visible=(obj.style.display != "none")
           if (visible) {  //Toggle to invisible
             obj.style.display="none";
             img.src = getCollapsedWidgetState(img.src);
             removeFromOpenRoles (roleId);
           }
           else {
              addToOpenRoles (roleId);  
              if (downloadedAll || isInDownloadedRoles (roleId)) {
                  obj.style.display="block";
                  img.src =  getExpandedWidgetState(img.src);
              }
              else {
                  window.location.replace(window.location.href);
              }
           }
       }
    }

    function collapseAllRoles() {
        SetCookieRoles("roleopen", "", null, "/");     
        window.location.replace(window.location.href);
    }
    
    function expandAllRoles() {
        SetCookieRoles("roleopen", "EXPANDALL", null, "/");     
        window.location.replace(window.location.href);
    }
    
    function DeleteCookieRoles () {  
        var cval = GetCookieRoles("roleopen");
        if (cval == null) {
            return;
        }
    
        var exp = new Date(); 
        exp.setTime(exp.getTime() - 1);

        SetCookieRoles("roleopen", "", exp, "/");
    }
    
    function getCookieValRoles(offset) {
        var endstr = document.cookie.indexOf (";", offset);
        if (endstr == -1)
            endstr = document.cookie.length;
        return unescape(document.cookie.substring(offset, endstr));
    }

    function GetCookieRoles (name) {  

        var arg = name + "=";  
        var alen = arg.length;  
        var clen = document.cookie.length;  
        var i = 0;  

        while (i < clen) {    
            var j = i + alen;    
            if (document.cookie.substring(i, j) == arg)      
                return getCookieValRoles (j);    
            i = document.cookie.indexOf(" ", i) + 1;    
            if (i == 0) break;   
        }  
        return null;
    }
    
    
