/*Global variables *********************************************************/
var Behaviour = {};
var sb_gCtxMenu = null;
// Semaphore for ignoring bubbling of events using timers
var sb_gIgnore = 0;
// Timer for hiding context menu
var sb_gHideTimer = null;
// Object reference of the right clicked object
var sb_gTargetID = null;
// ID to be copied or moved
var sb_gSourceID = null;
// ID of the dragged object
var sb_gDraggedID = null;
// Object to show tool tip
var sb_gToolTipObj = null;
var sb_gToolTipTop = null;
var sb_gToolTipLeft = null;
var sb_gSourceTypeIsNode = null;
var sb_gInPlaceCommands = [];
//var sb_gPrevParent = null;
var sb_gState = null;
var sb_gFilterActive = false;
var sb_gHighlighted = [];
var sb_gHidden = [];
function addDOMLoadEvent(func) {
    if (!document.getElementById || !document.createTextNode || !document.getElementsByTagName) {
        return;
    }
    var load_events = [],
        load_timer,
        script = document.getElementsByTagName('head')[0].getElementsByTagName('script')[0],
        done = arguments.callee.done,
        exec,
        old_onload,
        init = function () {
            if (done) {
                return;
            }
            clearInterval(load_timer);
            load_timer = null;
            done = true;
            while (exec = load_events.shift()) {
                exec();
            }
        };
    if (func && !load_events[0]) {
        /* for Mozilla/Opera9 */
        if (window.addEventListener) {
            window.addEventListener('DOMContentLoaded', init, true);
        } else if (window.attachEvent && !window.opera) {
            window.attachEvent('onreadystatechange', init);
            load_timer = setInterval(function () {
                if (/loaded|complete/.test(script.readyState)) {
                    init(); /* call the onload handler */
                }
            }, 10);
        } else if (/KHTML|WebKit/i.test(navigator.userAgent)) {/* sniff */
            load_timer = setInterval(function () {
                if (/loaded|complete/.test(script.readyState)) {
                    init(); /* call the onload handler */
                }
            }, 10);
        } else {
            old_onload = window.onload;
            window.onload = function () {
                init();
                if (old_onload) {
                    old_onload();
                }
            };
        }
    }
    load_events.push(func);
}
function sb_getJSData(label) {
    var obj = document.getElementById(label);
    return obj.value;
}
function sb_saveCookie(value) {
    var expires = new Date(new Date().getTime() + 1000 * 60 * 60 * 24 * 7).toGMTString();
    document.cookie = 'SB3NODES=' + value + '; expires=' + expires;
}
function sb_saveState(id, state) {
    sb_gState = (state ? 'Y' : 'N') + id.substr(1) + ':' + sb_gState;
    sb_saveCookie(sb_gState);
}
function sb_getCookie(name, defaultValue) {
    var index = document.cookie.indexOf(name + '=');
    if (index === -1) {
        return defaultValue;
    }
    index = document.cookie.indexOf('=', index) + 1;/* first character*/
    var endstr = document.cookie.indexOf(';', index);
    if (endstr === -1) {
        endstr = document.cookie.length;/* last character*/
    }
    return this.unescape(document.cookie.substr(index, endstr));/* unescape is deprecated*/
}
function sb_storeSearch() {
    var searchText = document.getElementById('fldSearch').value;
    document.cookie = 'SB3SEARCH=' + encodeURIComponent(searchText);
}
function sb_hasClass(obj, className) {
    return obj.className.indexOf(className) !== -1;
}
function sb_class(obj, className, add) {
    var startPos = obj.className.indexOf(className);
    if (add) {
        if (startPos !== -1) {
            return;
        }
        obj.className += ' ' + className;
    } else {
        if (startPos === -1) {
            return;
        }
        var oldClass = obj.className;
        obj.className = obj.className.substr(0, startPos);
        if (obj.className.length > (startPos + className.length)) {
            obj.className += oldClass.substr(startPos + className.length);
        }
    }
}
function sb_appendPersistentParams() {
    var url = '', sParam = location.search, persistentParams = ['target', 'mode', 'w'];
    if (sParam && sParam.length && sParam.split) {
        var aParam = sParam.substr(1).split('&'), i = 0, ap = aParam.length;
        for (i = 0; i < ap; i += 1) {
            var aPair = aParam[i].split('=');
            if (aPair[0] === 'reload') {
                continue;
            }
            if (aPair[0] === 'uniq') {
                continue;
            }
            var j = 0, pp = persistentParams.length;
            for (j = 0; j < pp; j += 1) {
                if (persistentParams[j] === aPair[0]) {
                    url += '&' + aParam[i];
                }
            }
        }
    }
    return url;
}
function sb_reloadPageWorker(cancelled, all) {
    var url = 'index.php?reload=' + (all ? 'all' : 'yes') + (!cancelled ? '&uniq=' + new Date().valueOf() : '') + sb_appendPersistentParams();
    location.replace(url);
}
function sb_reloadPage() {
    //sb_storePosition();
    sb_reloadPageWorker();
}
function sb_reloadAll() {
    sb_reloadPageWorker(false, true);
}
function sb_renewIt() {
    sb_gIgnore = 0;
}
function sb_stopIt(event) {
    if (!event) {
        return false;
    }
    sb_gIgnore += 1;
    if (sb_gIgnore > 1) {
        return true;
    }
    setTimeout(sb_renewIt, 10);
    return false;
}
function sb_initCommander() {
    document.cookie = 'SB3COOKIE=1';
    if (document.getElementById('focused')) {
        setTimeout(function () {var focused = document.getElementById('focused'); return focused.focus(); }, 10);
    }
    if (window && !window.closed) {
        window.focus();
    }
}
function sb_isOpera() {
    return window.opera && window.print;
}
function sb_restorePosition() {
    var iTop = parseInt(sb_getCookie('SB3TOP', -1), 10);
    var iLeft = parseInt(sb_getCookie('SB3LEFT', -1), 10);
    if (iTop !== -1) {
        window.scroll(iTop, iLeft);
    }
}
function sb_initPage(inPlaceCommands) {
    sb_gInPlaceCommands = inPlaceCommands;
}
function sb_isGecko() {
    return window.content && window.sidebar && window.sidebar.addPanel;
}
function sb_stopMenuHider() {
    if (sb_gHideTimer) {
        window.clearTimeout(sb_gHideTimer);
        sb_gHideTimer = null;
    }
}
function sb_hideMenus(ignore) {
    var menus = ['node', 'link'];
    var i = 0, ml = menus.length;
    for (i = 0; i < ml; i += 1) {
        var menu = document.getElementById(menus[i] + 'CtxMenu');
        if (menu !== ignore) {
            menu.style.display = 'none';
        }
    }
}
function sb_menuOff() {
    sb_gCtxMenu = null;
    sb_hideMenus(null);
    sb_stopMenuHider();
}
function sb_cancelDragging() {
    if (sb_gDraggedID !== null) {
        sb_gDraggedID = null;
        //sb_changeStyleForDragging(false);
    }
}
function sb_node(event, obj, show, noSaveState) {
    var children = document.getElementById('c' + obj.id);
    var deleted = (children.previousSibling.lastChild.getAttribute('rel').indexOf('*') === -1);
    var links = children.getElementsByTagName('h3');
    var root = document.getElementById('r' + obj.id);
    if (sb_stopIt(event)) {
        return false;
    }
    sb_menuOff();
    sb_cancelDragging();
    children.className = (children.className === 'childrenExpanded' ? 'childrenCollapsed' : 'childrenExpanded');
    if (root) {
        obj.className = (obj.className === 'root' + (deleted ? '_deleted' : '') ? 'root_plus' : 'root' + (deleted ? '_deleted' : ''));
    } else {
        obj.className = (obj.className === 'node_open' ? 'node' : 'node_open');
    }
    show = (children.className && obj.className) || !links.length;
    if (!noSaveState) {
        sb_saveState(obj.id, show);
    }
    return true;
}
function sb_xmlHttpGet() {
    var nhttp = null;
    if (window.ActiveXObject && typeof ActiveXObject !== 'undefined') {
        var activeXObjects = ['Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP'];
        var i = 0, ao = activeXObjects.length;
        for (i = 0; i < ao; i += 1) {
            try {
                nhttp = new ActiveXObject(activeXObjects[i]);
            } catch (e) {
                //e = event || window.event;
            }
        }
    } else if (window.XMLHttpRequest && typeof XMLHttpRequest !== 'undefined') {
        nhttp = new XMLHttpRequest();
    }
    return nhttp;
}
function sb_xmlHttpReady(ohttp) {
    return (ohttp.readyState === 4 && (ohttp.status === 304 || ohttp.status === 302 || ohttp.status === 200));
}
function sb_xmlHttpSend(ohttp, url) {
    ohttp.open('GET', url, true);
    if (window.XMLHttpRequest && typeof XMLHttpRequest !== 'undefined') {
        ohttp.send(null || '');
    } else if (window.ActiveXObject && typeof ActiveXObject !== 'undefined') {
        ohttp.send();
    }
}
function sb_nodeReload(event, obj) {
    var children = document.getElementById('c' + obj.id);
    var ohttp = sb_xmlHttpGet();
    var acl = children.previousSibling.lastChild.getAttribute('rel');
    var url = 'index.php?w=sitebar_ajax' + '&nid=' + obj.id.substr(1) + '&acl=' + acl + sb_appendPersistentParams();
    if (sb_node(event, obj)) {
        var childClass = children.firstChild.getAttribute('class');
        if (childClass === null) {
        if (!ohttp) {
            sb_reloadPageWorker();
            return;
        }
        ohttp.onreadystatechange = function () {
            if (sb_xmlHttpReady(ohttp)) {
                var hdrIdx = ohttp.responseText.indexOf("\n");
                var nid = ohttp.responseText.substr(1, hdrIdx);
                children.innerHTML = ohttp.responseText.substr('cn' + nid);
            }
        };
        sb_xmlHttpSend(ohttp, url);
        ohttp.close(); 
        }
    }
}
function sb_getCoordTop(event, ycoord) {
    var e = event || window.event;
    var de = document.documentElement;
    var db = document.body;
    var sb_gCoordUnit = '' || 'px';
    if (!e || (typeof e.pageY !== 'number' && typeof e.clientY !== 'number')) {
        return [0];
    }
    if (typeof e.pageY === 'number') {
        sb_gCoordUnit = 'px';
        ycoord = e.pageY;
    } else if (typeof e.clientY === 'number') {
        sb_gCoordUnit = '';
        ycoord = e.clientY;
    }
    if (db && db.scrollTop) {
        ycoord += db.scrollTop;
    } else if (de && de.scrollTop) {
        ycoord += de.scrollTop;
    }
    return ycoord - 1;
}
function sb_getCoordLeft(event, xcoord) {
    var e = event || window.event;
    var de = document.documentElement;
    var db = document.body;
    var sb_gCoordUnit = '' || 'px';
    if (!e || (typeof e.pageX !== 'number' && typeof e.clientX !== 'number')) {
        return [0];
    }
    if (typeof e.pageX === 'number') {
        sb_gCoordUnit = 'px';
        xcoord = e.pageX;
    } else if (typeof e.clientX === 'number') {
        sb_gCoordUnit = '';
        xcoord = e.clientX;
    }
    if (db && db.scrollLeft) {
        xcoord += db.scrollLeft;
    } else if (de && de.scrollLeft) {
        xcoord += de.scrollLeft;
    }
    return xcoord - 1;
}
function sb_toolTipHide() {
    var toolTipObj = document.getElementById('toolTip');
    //var sb_gToolTipTimer = null; unused variable, so it's useless
    if (sb_gToolTipObj.getAttribute('title') !== null) {
        sb_gToolTipObj.setAttribute('title', toolTipObj.innerHTML);
    }
    toolTipObj.innerHTML = '';
    sb_gToolTipObj = null;
    if (toolTipObj) {
        toolTipObj.style.display = 'none';
    }
}
function sb_menuOn(event, obj) {
    var e = event || window.event;
    var sbarBody = document.getElementById('sbarBody');
    var images = sbarBody.getElementsByTagName('b');
    var links = sbarBody.getElementsByTagName('a');
    var sb_gCoordUnit = '' || 'px';
    if (sb_stopIt(e)) {
        return false;
    }
    sb_cancelDragging();
    sb_stopMenuHider();
    obj = links || images;
    obj.id = this.parentNode.parentNode.getAttribute('id');
    sb_gTargetID = obj.id;
    var menuDIV = (sb_gTargetID.charAt(0) === 'n' ? 'node' : 'link');
    sb_gCtxMenu = document.getElementById(menuDIV + 'CtxMenu');
    if (menuDIV === 'node') {
        document.cookie = 'SB3CTXROOT=' + sb_gTargetID.substr(1);
        sb_saveState(sb_gTargetID, true);
    }
    if (sb_gToolTipObj) {
        sb_toolTipHide();
    }
    sb_hideMenus(sb_gCtxMenu);
    sb_gCtxMenu.style.top = sb_getCoordTop(e) + 20 + sb_gCoordUnit;
    sb_gCtxMenu.style.left = sb_getCoordLeft(e) + sb_gCoordUnit;
    sb_gCtxMenu.style.display = ('none' ? 'list-item' : 'none');
    var  i = 0, nodeACL = links[i].getAttribute('rel');
    for (i = 0;; i += 1) {
        var menuItem = document.getElementById(menuDIV + 'menuItem' + i);
        if (!menuItem) {
            break;
        }
        if (sb_hasClass(menuItem, 'separator')) {
            continue;
        }
        var commandACL = menuItem.firstChild.getAttribute('rel');
        var commandSPEC = menuItem.getAttribute('title');
        if (!commandACL) {
            continue;
        }
        var arr = commandACL.split('_');
        var disabled = false;
        if (arr.length > 1) {
            commandACL = arr[0];
            commandSPEC = arr[1];
        }
        var j = 0, ca = commandACL.length;
        for (j = 0; j < ca; j += 1) {
            if (nodeACL.indexOf(commandACL.charAt(j)) === -1) {
                disabled = true;
                break;
            }
        }
        if (!disabled && commandSPEC) {
            switch (commandSPEC) {
            case 'c':
                disabled = !sb_gTargetID;
                break;
            default:
                disabled = false;
                break;
            }
        }
        sb_class(menuItem, 'disabled', disabled);
    }
    return false;
}
function sb_showOptional(menuItem, menuDIV) {
    var i = 0;
    for (i = 0;; i += 1) {
        menuItem = document.getElementById(menuDIV + 'menuItem' + i);
        if (!menuItem) {
            break;
        }
        menuItem.style.display = 'list-item';
        menuItem.parentNode.style.display = 'list-item';
    }
}
function sb_itemOn(menuItem) {
    sb_stopMenuHider();
    // Display menu
    menuItem.parentNode.style.display = 'list-item';
    if (sb_hasClass(menuItem, 'disabled')) {
        return;
    }
}
function sb_itemOff(menuItem) {
    sb_stopMenuHider();
    sb_gHideTimer = setTimeout(sb_menuOff, 1000);
    if (sb_hasClass(menuItem, 'disabled')) {
        return;
    }
}
function sb_toolTipShow() {
    var sbarBody = document.getElementById('sbarBody');
    var sb_gCoordUnit = '' || 'px';
    if (sb_gCtxMenu) {
        sb_toolTipHide();
        return;
    }
    if (sb_gToolTipObj) {
        var toolTipObj = document.getElementById('toolTip');
        if (!toolTipObj || toolTipObj.style.display === 'block') {
            return;
        }
        var text = sb_gToolTipObj.getAttribute('title');
        if (!text || !text.length) {
            return;
        }
        var maxLen = 20, curLen = 0, i = 0, tl = text.length;
        if (text.indexOf(' ') === -1) {
            maxLen = tl;
        } else {
            for (i = 0; i < tl; i += 1) {
                curLen = text.indexOf(' ', i);
                if ((curLen - i) > maxLen) {
                    maxLen = (curLen - i);
                }
            }
        }
        var  iTop = 0, iLeft = 0, save  = '', width = maxLen * 7; // Magic number
        var punct = ['.', '(', ')', ':', ';', '#'];
        var images = ['&#46;', '&#40;', '&#41;', '&#58;', '&#59;', '&#35;'];
        for (i = 0; i < tl; i += 1) {
            var j = 0, pl = punct.length, skip = false;
            /*for (j = 0; j < pl && !skip; j += 1) {
                if (text.charAt(i) === punct[j]) {
                    save += images[j];
                    skip = true;
                }
            }*/
            if (!skip) {
                save += text.charAt(i);
            }
        }
        if (iTop === 0 && (sb_gToolTipObj.className === 'raised' || sb_gToolTipObj.className === 'check')) {
            if (sb_isGecko() && sb_gToolTipObj.offsetParent) {
                iTop = sb_gToolTipObj.offsetTop + 30;
                iLeft = sb_gToolTipLeft - width + 5;
            } else {
                iTop = sb_gToolTipTop + 15;
                iLeft = sb_gToolTipLeft - width;
            }
            if (iLeft < 0) {
                iLeft = 0;
            }
        } else {
            if (sb_isGecko() && sb_gToolTipObj.offsetParent) {
                iTop = sb_gToolTipObj.offsetTop - sbarBody.scrollTop + 30;
                iLeft = Math.floor(sb_gToolTipLeft / 20) + 5;
            } else {
                iTop = sb_gToolTipTop + 22;
                iLeft = Math.floor(sb_gToolTipLeft / 20);
            }
        }
        toolTipObj.innerHTML = save;
        if (text) {
            sb_gToolTipObj.setAttribute('title', '');
        }
        toolTipObj.style.display = 'block';
        toolTipObj.style.top = iTop + sb_gCoordUnit;
        toolTipObj.style.left = iLeft + sb_gCoordUnit;
        toolTipObj.style.width = width + sb_gCoordUnit;
        if (sb_isOpera()) {
            toolTipObj.parentNode.onmouseover = 'return false';//for Opera <9.0
        }
    }
}
function sb_toolTip(source, event) {
    var e = event || window.event;
    sb_gToolTipObj = source;
    sb_gToolTipTop = sb_getCoordTop(e);
    sb_gToolTipLeft = sb_getCoordLeft(e);
    sb_toolTipShow();//window.setTimeout(sb_toolTipShow, 1000);
}
function sb_markDefault(nid) {
    var ohttp = sb_xmlHttpGet();
    if (!ohttp) {
        window.alert('Sorry, your browser does not support AJAX!');
        return;
    }
    var url = 'command.php?command=Mark%20as%20Default&do=1&nid_acl=' + nid + sb_appendPersistentParams();
    sb_xmlHttpSend(ohttp, url);
}
function sb_nodeCopy(nid) {
    sb_gSourceID = nid;
    sb_gSourceTypeIsNode = true;
}
function sb_commandWindow(command, nid, lid) {
    var url = 'command.php?command=' + encodeURIComponent(command) + (nid ? '&nid_acl=' + nid : '') + (lid ? '&lid_acl=' + lid : '') + (sb_gSourceID ? '&sid=' + sb_gSourceID + '&stype=' + (sb_gSourceTypeIsNode ? '1' : '0') : '');
    url += sb_appendPersistentParams();
    var inPlaceCommands = false, i = 0, ic = sb_gInPlaceCommands.length;
    for (i = 0; i < ic; i += 1) {
        if (command === sb_gInPlaceCommands[i]) {
            inPlaceCommands = true;
            break;
        }
    }
    if (sb_getJSData('sb_externCommander') === '1' && !inPlaceCommands) {
        var sb_gCmdWin = null, w = window, d = document, de = d.documentElement, db = d.body, cp = d.characterSet || d.charset, sX, sY, sW, sH, opW, pW, opH, pH, nwO, nwW, nwH, nwX, nwY;
        sW = w.screen.availWidth;
        sH = w.screen.availHeight;
        opW = w.outerWidth || de.offsetWidth || db.offsetWidth;
        opH = w.outerHeight || de.offsetHeight || db.offsetHeight;
        pW = w.innerWidth || de.clientWidth || db.clientWidth;
        pH = w.innerHeight || de.clientHeight || db.clientHeight;
        sX = sW - opW + 4 + w.screenX;
        sY = opH - pH - 3 + w.screenY;
        nwW = 192;
        nwH = pH;
        if (sb_isOpera()) {
            nwX = (sW - nwW) / 2 + nwW;
            nwY = w.screen.height - sH + 4;
        } else {
            nwX = sW - nwW - 22;
            nwY = (sY || w.screenTop + 3);
        }
        nwO = 'width=' + nwW + ', height=' + nwH + ', left=' + nwX + ', top=' + nwY + ', toolbar = 1, location = 1, resizable = 1, scrollbars = 1, status = 1, dependent = 1';
        url += (cp ? '&cp=' + cp:'');
        if (!sb_gCmdWin || sb_gCmdWin.closed) {
            if (sb_isGecko()) {
                sb_gCmdWin = window.open(url, 'sitebar_gCmdWin', nwO);
                sb_gCmdWin.blur();
                sb_gCmdWin.resizeTo(nwW, nwH);
                sb_gCmdWin.moveTo(nwX, nwY - 26);
                sb_gCmdWin.focus();
            } else {
                sb_gCmdWin = w.open(url, 'sitebar_gCmdWin', nwO);
                sb_gCmdWin.blur();
                sb_gCmdWin.resizeTo(nwW, nwH);
                sb_gCmdWin.moveTo(nwX, nwY);
                sb_gCmdWin.focus();
            }
        } else {
            sb_gCmdWin.location.href = url;
            sb_gCmdWin.focus();
        }
    } else {
        location.href = url;
    }
}
function sb_nodeHide(nid) {
    var nodeObj = document.getElementById('n' + nid);
    nodeObj.style.display = 'none';
    sb_commandWindow('Hide Folder', nid, null);
}
function sb_linkCopy(lid) {
    sb_gSourceID = lid;
    sb_gSourceTypeIsNode = false;
}
function sb_expandAll() {
    var sbarBody = document.getElementById('sbarBody');
    var i = 0, obj = sbarBody.getElementsByTagName('h2')[i];
    for (i = 0; (obj = sbarBody.getElementsByTagName('h2')[i]); i += 1) {
        sb_node(null, obj.parentNode, true);
    }
    location.hash = '#';
}
function sb_collapseAll() {
    var sbarBody = document.getElementById('sbarBody');
    var i = 0, obj = sbarBody.getElementsByTagName('h2')[i];
    sb_gState = '!';
    if (sb_gState.length === 0 || sb_gState === '!') {
        sb_expandAll();
        return;
    }
    for (i = 0; (obj = sbarBody.getElementsByTagName('h2')[i]); i += 1) {
        sb_node(null, obj.parentNode, false, true);
    }
    sb_saveCookie(sb_gState);
    location.hash = '#';
}
function sb_nodeDrag(event, obj, nid) {
    var e = event || window.event;
    obj = this.parentNode.parentNode;
    if (obj.className.indexOf('node') !== -1 || obj.className.indexOf('root') !== -1) {
        nid = obj.getAttribute('id').substr(1);
    }
    if (e && (e.button === 2 || e.which === 2 || sb_gDraggedID !== null)) {
        return false;
    }
    sb_gSourceID = nid;
    sb_gSourceTypeIsNode = true;
    sb_gDraggedID = sb_gSourceID;
    return false;
}
function sb_linkDrag(event, obj, lid) {
    var e = event || window.event;
    obj = this.parentNode.parentNode;
    if (obj.className.indexOf('link') !== -1) {
        lid = obj.getAttribute('id').substr(1);
    }
    if (e && (e.button === 2 || e.which === 2 || sb_gDraggedID !== null)) {
        return false;
    }
    sb_gSourceID = lid;
    sb_gSourceTypeIsNode = false;
    sb_gDraggedID = sb_gSourceID;
    return false;
}
function sb_nodeDrop(event, obj, nid, lid) {
    var e = event || window.event;
    obj = this.parentNode.parentNode;
    if (obj.className.indexOf('node') !== -1 || obj.className.indexOf('root') !== -1) {
        nid = obj.getAttribute('id').substr(1);
    } else {
        lid = obj.getAttribute('id').substr(1);
    }
    if (sb_gDraggedID === nid || (!sb_gSourceTypeIsNode && lid && sb_gDraggedID === lid)) {
        return true;
    }
    if (e && (e.button === 2 || e.which === 2 || sb_gDraggedID === null)) {
        return false;
    }
    //if (sb_isOpera()) {return '';}
    sb_stopIt(e);
    sb_gDraggedID = sb_gSourceID;
    //sb_gSourceID = sb_gDraggedID;
    sb_commandWindow('Paste', (nid ? nid : lid));
    sb_cancelDragging();
    return false;
}
function sb_highlight(linkObj, highlight) {
    var className = 'highlight';
    if (!sb_hasClass(linkObj, className) && highlight) {
        sb_gHighlighted[sb_gHighlighted.length] = linkObj;
        linkObj.onmouseover = function () {
            if (linkObj.className === 'acl highlight') {
                linkObj.className = 'acl';
            }
            if (linkObj.className === 'al highlight') {
                linkObj.className = 'al';
            }
            if (linkObj.className === 'an highlight') {
                linkObj.className = 'an';
            }
            sb_toolTip(linkObj);
        };
        linkObj.onmouseout = function () {
            if (linkObj.className === 'acl') {
                linkObj.className = 'acl highlight';
            }
            if (linkObj.className === 'al') {
                linkObj.className = 'al highlight';
            }
            if (linkObj.className === 'an') {
                linkObj.className = 'an highlight';
            }
        };
    }
    sb_class(linkObj, className, highlight);
}
function sb_unfilter() {
    sb_gFilterActive = false;
    var i = 0, hd = sb_gHidden.length;
    for (i = 0; i < hd; i += 1) {
        sb_class(sb_gHidden[i], 'hidden', false);
    }
    sb_gHidden = [];
    document.getElementById('fldSearch').focus();
}
function sb_getLinkName(linkTag) {
    if (linkTag.innerHTML.match('/.*>(.*)/')) {
        return RegExp.$1;
    } else {
        return linkTag.innerHTML;
    }
}
function sb_filter() {
    var sbarBody = document.getElementById('sbarBody');
    if (sb_gFilterActive) {
        sb_unfilter();
        if (icon) {
            //return;
        }
    }
    var i = 0, hl = sb_gHighlighted.length;
    for (i = 0; i < hl; i += 1) {
        sb_highlight(sb_gHighlighted[i], false);
    }
    sb_gHighlighted = [];
    var fld  = document.getElementById('fldSearch');
    var text = fld.value;
    if (text.length === 0) {
        return;
    }
    sb_gFilterActive = true;
    var type = sb_getJSData('sb_defaultSearch');
    //sb_gPrevParent = null;
    var reST = new RegExp('/^(url|desc|name|all):(.*)$/');
    if (text.match(reST)) {
        type = RegExp.$1;
        if (type === 'url' || type === 'desc' || type === 'name' || type === 'all') {
            text = RegExp.$2;
        }
    }
    var re = new RegExp(text, 'i');
    var parents = sbarBody.getElementsByTagName('h3');
    var links = sbarBody.getElementsByTagName('a'), ll = links.length;
    var parentDIV = parents[i].parentNode;
    for (i = 0; i < ll; i += 1) {
        var name = sb_getLinkName(links[i]);
        var url = links[i].getAttribute('href');
        var desc = links[i].getAttribute('title');
        var subject = '';
        if (type === 'url' || type === 'all') {
            subject += url;
        }
        if (type === 'name' || type === 'all') {
            subject += name;
        }
        if (type === 'desc' || type === 'all') {
            subject += desc;
        }
        if (subject.search(re) !== -1) {
            sb_highlight(links[i], true);
            while (parents[i] === 'loader') {
                sb_node(false, parentDIV);
            }
        } else {
            if (links[i].className === 'al') {
                sb_class(links[i].parentNode.parentNode, 'hidden', true);
                sb_gHidden[sb_gHidden.length] = links[i].parentNode.parentNode;
            }
        }
    }
    fld.select();
    fld.focus();
}
function sb_defaultSearch(tool) {
    if (tool === 'filter') {
        sb_filter();
        return;
    }
    sb_storeSearch();
}
function sb_itemDo(menuItem, func) {
    var nid = null, lid = null, id = null;
    if (sb_hasClass(menuItem, 'disabled') || !menuItem.getAttribute('title')) {
        return;
    }
    sb_menuOff();
    if (sb_gTargetID) {
        id = sb_gTargetID.substr(1);
        if (sb_gTargetID.charAt(0) === 'n') {
            nid = id;
        } else {
            lid = id;
        }
        sb_gTargetID = null;
    }
    if (func) {
        eval(func + '(id)');
    } else {
        sb_commandWindow(menuItem.getAttribute('title'), nid, lid);
    }
}
function sb_itemDoAlt(menuItem, func) {
    var nid = null, lid = null, id = null;
    if (sb_hasClass(menuItem, 'disabled') || !menuItem.getAttribute('title')) {
        return;
    }
    sb_menuOff();
    if (sb_gTargetID) {
        id = sb_gTargetID.id.substr(1);
        if (sb_gTargetID.id.charAt(0) === 'n') {
            nid = id;
        } else {
            lid = id;
        }
        sb_gTargetID = null;
    }
    if (func) {
        eval(func + '(id)');
    } else {
        sb_commandWindow(menuItem.getAttribute('title'), nid, lid);
    }
}
function sb_openHelp(url) {
    var nwO = 'resizable, location, toolbar, scrollbars, status';
    var sb_gHelpWin = window.open(url, 'sitebar_gHelpWin', nwO);
    sb_gHelpWin.focus();
}
function sb_showMore() {
    document.getElementById('showMore').style.display = 'block';
    document.getElementById('showLess').style.display = 'none';
    document.getElementById('optionalFields').style.display = 'none';
}
function sb_showLess() {
    document.getElementById('showMore').style.display = 'none';
    document.getElementById('showLess').style.display = 'block';
    document.getElementById('optionalFields').style.display = 'block';
}
function sb_showShareGroup(gid) {
    var i = 0;
    for (i = 0; i < 2; i += 1) {
        var ch = (i === 0 ? 'a' : 'b');
        var el = document.getElementById('group' + gid + ch);
        if (el) {
            el.style.visibility = 'visible';
        }
    }
}
function sb_memberSelector(id, show) {
    document.getElementById(id + '_l').style.display = (show ? 'none' : 'block');
    document.getElementById(id + '_s').style.display = (!show ? 'none' : 'block');
    if (show) {
        document.getElementById(id + '_v').focus();
        document.getElementById(id + '_v').className = document.getElementById(id + '_v').value;
    }
}
function sb_onMemberSelectorChange(id) {
    document.getElementById(id + '_r').className = document.getElementById(id + '_v').value;
    document.getElementById(id + '_v').className = document.getElementById(id + '_v').value;
}

function sb_onMemberSelectorBlur(id) {
    sb_memberSelector(id, false);
}
addDOMLoadEvent(function () {
    function attachEH(obj, e, func) {
        if (obj.attachEvent) {
            obj.attachEvent('on' + e, func);
        } else {
            obj.addEventListener(e, func, true);
        }
    }

    function detachEH(obj, e, func) {
        if (obj.detachEvent) {
            obj.detachEvent('on' + e, func);
        } else {
            obj.removeEventListener(e, func, true);
        }
    }
    Behaviour = {
        list : {},
        handle : function (e) {
            if (!e) {
                e = window.event;
            }
            var n = e.srcElement || e.target;
            while (n) {
                try {
                    Behaviour.list[e.type + '__' + n.className](n);
                } catch (er) {}
                try {
                    Behaviour.list[e.type + '_' + n.id](n);
                } catch (err) {}
                if (n.last) {
                    n.last = null;
                    break;
                }
                n = n.parentNode;
            }
        },
        start : function () {
            var de = document.documentElement;
            var db = document.body;
            var d = db || de || window;
            attachEH(d, 'DOMContentLoaded', Behaviour.handle);
            attachEH(d, 'readystatechange', Behaviour.handle);
            attachEH(d, 'load', Behaviour.handle);
            attachEH(d, 'scroll', Behaviour.handle);
            attachEH(d, 'error', Behaviour.handle);
            attachEH(d, 'mousemove', Behaviour.handle);
            attachEH(d, 'mouseover', Behaviour.handle);
            attachEH(d, 'mouseout', Behaviour.handle);
            attachEH(d, 'mousedown', Behaviour.handle);
            attachEH(d, 'mouseup', Behaviour.handle);
            attachEH(d, 'click', Behaviour.handle);
            attachEH(d, 'submit', Behaviour.handle);
            attachEH(d, 'keydown', Behaviour.handle);
            attachEH(d, 'keypress', Behaviour.handle);
            attachEH(d, 'keyup', Behaviour.handle);
            attachEH(d, 'contextmenu', Behaviour.handle);
            attachEH(d, 'focus', Behaviour.handle);
            attachEH(d, 'blur', Behaviour.handle);
            attachEH(d, 'dragstart', Behaviour.handle);
            attachEH(d, 'dragend', Behaviour.handle);
            attachEH(d, 'drop', Behaviour.handle);
            attachEH(d, 'beforeunload', Behaviour.handle);
        },
        end : function () {
            var de = document.documentElement;
            var db = document.body;
            var d = db || de || window;
            detachEH(d, 'DOMContentLoaded', Behaviour.handle);
            detachEH(d, 'readystatechange', Behaviour.handle);
            detachEH(d, 'load', Behaviour.handle);
            detachEH(d, 'scroll', Behaviour.handle);
            detachEH(d, 'error', Behaviour.handle);
            detachEH(d, 'mousemove', Behaviour.handle);
            detachEH(d, 'mouseover', Behaviour.handle);
            detachEH(d, 'mouseout', Behaviour.handle);
            detachEH(d, 'mousedown', Behaviour.handle);
            detachEH(d, 'mouseup', Behaviour.handle);
            detachEH(d, 'click', Behaviour.handle);
            detachEH(d, 'submit', Behaviour.handle);
            detachEH(d, 'keydown', Behaviour.handle);
            detachEH(d, 'keypress', Behaviour.handle);
            detachEH(d, 'keyup', Behaviour.handle);
            detachEH(d, 'contextmenu', Behaviour.handle);
            detachEH(d, 'focus', Behaviour.handle);
            detachEH(d, 'blur', Behaviour.handle);
            detachEH(d, 'dragstart', Behaviour.handle);
            detachEH(d, 'dragend', Behaviour.handle);
            detachEH(d, 'drop', Behaviour.handle);
            detachEH(d, 'beforeunload', Behaviour.handle);
        }
    };
    Behaviour.start();

    Behaviour.list = {
        mouseover__logo : function (n) {
            sb_toolTip(n);
            n.last = true;
        },
        mouseout__logo : function (n) {
            sb_toolTipHide(n);
            n.last = true;
        },
        mouseover__acl : function (n) {
            sb_toolTip(n);
            n.last = true;
        },
        mouseout__acl : function (n) {
            sb_toolTipHide(n);
            n.last = true;
        },
        mouseover__al : function (n) {
            sb_toolTip(n);
            n.last = true;
        },
        mouseout__al : function (n) {
            sb_toolTipHide(n);
            n.last = true;
        },
        mouseover__an : function (n) {
            sb_toolTip(n);
            n.last = true;
        },
        mouseout__an : function (n) {
            sb_toolTipHide(n);
            n.last = true;
        },
        mouseover__dead : function (n) {
            sb_toolTip(n);
            n.last = true;
        },
        mouseout__dead : function (n) {
            sb_toolTipHide(n);
            n.last = true;
        },
        mouseover__private : function (n) {
            sb_toolTip(n);
            n.last = true;
        },
        mouseout__private : function (n) {
            sb_toolTipHide(n);
            n.last = true;
        },
        mousedown__acl : function (n) {
            if (!sb_isOpera()) {
                n.focus();
                n.oncontextmenu = sb_menuOn;
                n.ondragstart ? n.ondragstart : n.onmousedown = sb_nodeDrag;
            }
            n.last = true;
        },
        mousedown__an : function (n) {
            if (!sb_isOpera()) {
                n.focus();
                n.oncontextmenu = sb_menuOn;
                n.ondragstart ? n.ondragstart : n.onmousedown = sb_nodeDrag;
            }
            n.last = true;
        },
        mousedown__al : function (n) {
            if (!sb_isOpera()) {
                n.focus();
                n.oncontextmenu = sb_menuOn;
                n.ondragstart ? n.ondragstart : n.onmousedown = sb_linkDrag;
            }
            n.last = true;
        },
        mousedown__dead : function (n) {
            if (!sb_isOpera()) {
                n.oncontextmenu = sb_menuOn;
                n.ondragstart ? n.ondragstart : n.onmousedown = sb_linkDrag;
            }
            n.last = true;
        },
        mousedown__private : function (n) {
            if (!sb_isOpera()) {
                n.oncontextmenu = sb_menuOn;
                n.ondragstart ? n.ondragstart : n.onmousedown = sb_linkDrag;
            }
            n.last = true;
        },
        keypress__acl : function (n) {
            var e = window.event;
            if (e && e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_menuOn;
            }
            n.last = true;
        },
        keyup__acl : function (n) {
            var e = window.event;
            if (e && !e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_renewIt;
            }
            n.last = true;
        },
        keypress__an : function (n) {
            var e = window.event;
            if (e && e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_menuOn;
            }
            n.last = true;
        },
        keyup__an : function (n) {
            var e = window.event;
            if (e && !e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_renewIt;
            }
            n.last = true;
        },
        keypress__al : function (n) {
            var e = window.event;
            if (e && e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_menuOn;
            }
            n.last = true;
        },
        keyup__al : function (n) {
            var e = window.event;
            if (e && !e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_renewIt;
            }
            n.last = true;
        },
        keypress__dead : function (n) {
            var e = window.event;
            if (e && e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_menuOn;
            }
            n.last = true;
        },
        keyup__dead : function (n) {
            var e = window.event;
            if (e && !e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_renewIt;
            }
            n.last = true;
        },
        keypress__private : function (n) {
            var e = window.event;
            if (e && e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_menuOn;
            }
            n.last = true;
        },
        keyup__private : function (n) {
            var e = window.event;
            if (e && !e.ctrlKey && sb_isOpera()) {
                n.onclick = sb_renewIt;
            }
            n.last = true;
        },
        mouseover__item : function (n) {
            n.className = 'activeItem';
            sb_itemOn(n);
            n.last = true;
        },
        mouseout__activeItem : function (n) {
            n.className = 'item';
            sb_itemOff(n);
            n.last = true;
        },
        mouseover__optional : function (n) {
            n.className = 'actopt';
            sb_itemOn(n);
            n.last = true;
        },
        mouseout__actopt : function (n) {
            n.className = 'optional';
            sb_itemOff(n);
            n.last = true;
        },
        mouseup__actopt : function (n) {
            if (n.parentNode.id === 'nodeCtxMenu') {
                if (n.getAttribute('title') === 'Mark as Default') {
                    sb_itemDo(n, 'sb_markDefault');
                } else {
                    sb_itemDo(n);
                }
            }
            n.last = true;
        },
        mouseup__activeItem : function (n) {
            if (n.parentNode.id === 'linkCtxMenu') {
                if (n.getAttribute('title') === 'Copy Bookmark') {
                    sb_itemDo(n, 'sb_linkCopy');
                } else {
                    sb_itemDo(n);
                }
            }
            if (n.parentNode.id === 'nodeCtxMenu') {
                if (n.getAttribute('title') === 'Copy') {
                    sb_itemDo(n, 'sb_nodeCopy');
                } else {
                    sb_itemDo(n);
                }
            }
            if (n.parentNode.id === 'userCtxMenu') {
                if (n.getAttribute('title')) {
                    sb_itemDo(n);
                }
            }
            n.last = true;
        },
        mouseover__more : function (n) {
            n.className = 'less';
            sb_showOptional(n, 'node');
            n.last = true;
        },
        mousedown__nmenu : function (n) {
            n.parentNode.className = '';
            n.onmouseup = sb_menuOn;
            n.last = true;
        },
        click__nmenu : function (n) {
            n.parentNode.className = 'loader';
            n.last = true;
        },
        mousedown__lmenu : function (n) {
            n.onmouseup = sb_menuOn;
            n.last = true;
        },
        mouseover__btn : function (n) {
            n.className = 'raised';
            sb_toolTip(n);
            n.last = true;
        },
        mousedown__raised : function (n) {
            n.className = 'pressed';
            sb_toolTipHide(n);
            n.last = true;
        },
        mouseup__pressed : function (n) {
            n.className = 'btn';
            sb_toolTipHide(n);
            n.last = true;
        },
        mouseout__pressed : function (n) {
            n.className = 'btn';
            sb_toolTipHide(n);
            n.last = true;
        },
        mouseout__raised : function (n) {
            n.className = 'btn';
            sb_toolTipHide(n);
            n.last = true;
        },
        mouseover__check : function (n) {
            sb_toolTip(n);
            n.last = true;
        },
        mouseout__check : function (n) {
            sb_toolTipHide(n);
            n.last = true;
        },
        keyup__fldSearch : function (n) {
            sb_storeSearch(this);
            sb_defaultSearch(n);
            n.last = true;
        },
        click__loader : function (n) {
            location.hash = '#an' + n.parentNode.id.substr(1);
            sb_nodeReload(n, n.parentNode) || sb_getJSData('sb_loader');
            if (sb_gToolTipObj) {
                sb_toolTipHide(n);
            }
            n.last = true;
        },
        click_reloader : function (n) {
            if (window.opener) {
                window.opener.location.reload(true);
                window.close();
            }
            n.last = true;
        },
        click_closer : function (n) {
            window.close();
            n.last = true;
        },
        click_history : function (n) {
            window.history.go(-1);
            n.last = true;
        },
        click_btnFilter : function (n) {
            sb_filter();
            n.last = true;
        },
        click_btnSearch : function (n) {
            sb_storeSearch(this);
            sb_defaultSearch(n);
            n.last = true;
        },
        click_btnSearchWeb : function (n) {
            sb_storeSearch(this);
            sb_defaultSearch(n);
            n.last = true;
        },
        click_btnBack : function (n) {
            window.history.go(-1);
            n.last = true;
        },
        click_btnForward : function (n) {
            window.history.go(1);
            n.last = true;
        },
        click_showMore : function (n) {
            n.className = 'showLess';
            sb_showLess(n);
            n.last = true;
        },
        click_showLess : function (n) {
            n.className = 'showMore';
            sb_showMore(n);
            n.last = true;
        },
        click_btnCollapse : function (n) {
            sb_collapseAll();
            n.last = true;
        },
        click_btnReloadAll : function (n) {
            sb_reloadPageWorker(false, true);
            n.last = true;
        },
        click_btnReload : function (n) {
            sb_reloadPageWorker();
            n.last = true;
        },
        click_userInfo : function (n) {
            var footer = n.parentNode.parentNode;
            footer.className = (footer.className === 'expanded' ? 'collapsed' : 'expanded');
            if (footer.className === 'expanded') {
                sb_hideMenus(sb_gCtxMenu);
            }
            n.last = true;
        }
    };
    if (sb_isOpera() && this.innerWidth < 300) { 
        var base = document.getElementsByTagName('base')[0];
        base.setAttribute('target', '_main');
    }
    sb_gState = sb_getCookie('SB3NODES', '!');
    sb_gInPlaceCommands = ['Accept Membership', 'Email Verified', 'Invalid Token', 'Log In', 'Log Out', 'Reject Membership', 'Set Up', 'Sign Up'];
    sb_initPage(sb_gInPlaceCommands);
    sb_initCommander();
    window.onbeforeunload = function () {
        Behaviour.end();
    };
});

