treeAutoSubmit = false;
setCallbackMethod = '';
inactiveText = '';
form = 'mainForm';

function Node(id, text, grouptype, groupcategory, categoryname, inactive, icon) {
    this.id = id;
    this.text = text;
    this.grouptype = grouptype;
    this.groupcategory = groupcategory;
    this.categoryname = categoryname;
    this.icon = icon;
    this.inactive = inactive;
    this.toString = nodeAsString;
    this.add = addNode;
    this.children = new Array();
    this.hasChildren = hasChildNodes;
    this.write = writeNode;
    this.select = selectNode;
    this.parent = 0;
    this.expand = expandNode;
    this.collapse = collapseNode;
    this.view = viewNode;
}
function hasChildNodes() {
    return this.children.length>0;
}
function expandNode() {
    if (this.hasChildren()) {
        document.getElementById(this.id).style.display='block';
        document.getElementById('I' + this.id).src='images/minus.gif';
    }
}
function collapseNode() {
    if (this.hasChildren()) {
        document.getElementById(this.id).style.display='none';
        document.getElementById('I' + this.id).src='images/plus.gif';
    }
}
function viewNode() {
    try {
        this.expand();
        this.parent.view();
    }
    catch (e) {}
}
function toggleNode(nodeId) {
    var nodeSpan =
    document.getElementById(nodeId);
    var img =
    document.getElementById('I' + nodeId);
    if (nodeSpan.style.display!='block') {
        nodeSpan.style.display='block';
        img.src='images/minus.gif';
    }
    else {
        nodeSpan.style.display='none';
        img.src='images/plus.gif';
    }
}
function nodeAsString(){
    var nodeString = '<span style="white-space:nowrap">';
    if (this.hasChildren()) {
        nodeString += '<span onClick="toggleNode(\'' + this.id +
        '\')"><img class="nodehub" src="images/plus.gif" border="0" id="I' +
        this.id + '"></span>';
    }
    else {
        nodeString += '<img src="images/blank.gif" width="16" border="0">';
    }
    nodeString += '<a ' + (this.inactive ? 'class="inactive" ' : '') +
    'style="white-space:nowrap" href="javascript:root.select(' + this.id + ')" title="';
    if (this.groupcategory != "null") {
        nodeString += this.categoryname;
        if (this.inactive) nodeString += ' / ';
    }
    if (this.inactive) {
        nodeString += inactiveText;
    }
    nodeString += '">' +
    '<img class="silk" border="0" id="GI' + this.id + '" ' + (this.inactive ? 'id="inactive" ' : '') + 'src="images/fatcow/16/' + (this.icon ? this.icon : 'group' + this.grouptype) +
    '.png">&nbsp;<span class="node-text" id="S' +
    this.id + '">' + this.text + '<br/></span></a>' +
    '<span class="node" id="' + this.id + '">';
    for (var i=0; i<this.children.length; i++) {
        nodeString += this.children[i].toString();
    }
    nodeString += '</span></span>';
    return nodeString;
}
function addNode(node){
    this.children[this.children.length] = node;
    node.parent=this;
}
function writeNode() {
    document.write(this.toString());
}
function selectNode(nodeId) {
    var textStyle = document.getElementById('S' + this.id).style;
    if (nodeId==this.id) {
        updateComboTopView(nodeId);
        textStyle.fontWeight='bold';
        try {
            eval('document.' + form + '.groupId.value=this.id');
        } catch (e) { }
        try {
            eval('document.' + form + '.group.value=this.text');
        } catch (e) { }
        try {
            document.getElementById('hideOnChange').style.display='none';
        } catch (e) { }
        if (treeAutoSubmit) {
            eval('document.' + form + '.submit()');
        } else {
            this.expand();
        }
        if (setCallbackMethod!='') {
            eval(setCallbackMethod);
        }
    }
    else {
        textStyle.fontWeight='normal';
    }
    for (var i=0; i<this.children.length; i++) {
        this.children[i].select(nodeId);
    }
}
function updateComboTopView(nodeId) {
    if (document.getElementById('idTreeComboTopIcon') != undefined) {
        document.getElementById('idTreeComboTopIcon').src = document.getElementById('GI' + nodeId).src;
        document.getElementById('idTreeComboTopLabel').innerHTML = document.getElementById('S' + nodeId).innerHTML;
        document.getElementById('idTreeComboDropdown').style.display = 'none';
    }
}
function toggleTreeCombo() {
    if (document.getElementById('idTreeComboDropdown').style.display == 'none') {
        document.getElementById('idTreeComboDropdown').style.display = displayBlock;
    } else {
        document.getElementById('idTreeComboDropdown').style.display = 'none';
    }
}

