﻿
function ActiveThreads() {
    var panel = document.getElementById("ThreadPanel");
    
    // REMOVE buttons
    var kids = panel.childNodes;
    for (i = 0; i < kids.length; i++) {
        if (typeof kids[i].id != "undefined") {
            if (kids[i].id.indexOf("ThreadLabel") == -1)
                panel.removeChild(kids[i]);
        }
    }
    
    // ADD buttons
    var button, title, command;
    var maxLen = 30;
    for (i = 0; i < threads.length; i++) {
        if (typeof threads[i][0] != "undefined" && threads[i][0] != "") {
            panel.appendChild(document.createTextNode(" "));
            button = document.createElement("input");
            button.setAttribute("type", "button");
            title = threads[i][1];
            if (title.length > maxLen)
                title = title.substring(0, maxLen - 3) + "...";
            button.setAttribute("value", title);
            command = "setFrame('thread.aspx?th=" + threads[i][0] + "');";
            button.setAttribute("onClick", command);
            panel.appendChild(button);
        }
    }
}

// (adds Thread to client list; server list managed by iframe page)
function OpenThread(id, title) {
    var match = false;
    for (i = 0; i < threads.length; i++) {
        if (typeof threads[i][0] != "undefined" && threads[i][0] == id) {
            match = true;
            break;
        }
    }
    if (!match) {
        threads[threads.length] = [id, title];
        ActiveThreads();
    }
    setFrame("thread.aspx?th=" + id);
}

// (removes Thread from client list; server list managed by iframe page)
function RemoveThread(id) {
    for (i = 0; i < threads.length; i++) {
        if (typeof threads[i][0] != "undefined" && threads[i][0] == id) {
            threads[i] = "";
            break;
        }
    }
    ActiveThreads();
}

