﻿// JScript File
function ShowFilterList(p_stockSymbolListCSV) {
    var divFilterList = document.getElementById("divFilterList");
    if (divFilterList != null) {
        if (divFilterList.innerHTML == "") {
            if (p_stockSymbolListCSV == null) return;
            var stockList = p_stockSymbolListCSV.split(',');
            if ((stockList == null) || (stockList.length < 1)) return;

            var strCheckBoxes = new StringBuilder();
            strCheckBoxes.append("<table width='100%' border='0' cellpadding='0' cellspacing='0'>");
            var i = 0;
            while (i < stockList.length) {
                strCheckBoxes.append("<tr>");
                for (var col = 0; col < 18; col++) {
                    if (i < stockList.length) {
                        if (stockList[i] != "") {
                            strCheckBoxes.append("<td class='tdFilter' width='4%'>");
                            strCheckBoxes.append("<input id='chkStkSbl_" + stockList[i] + "' type='checkbox' name='chkStkFilter' value='" + stockList[i] + "' onclick=\"rebuildUserList()\" />");
                            strCheckBoxes.append(stockList[i]); // Stock symbol
                            strCheckBoxes.append("</td>");
                        }
                        else {
                            strCheckBoxes.append("<td class='tdFilter' width='4%'></td>");
                        }
                    }
                    else {
                        strCheckBoxes.append("<td class='tdFilter' width='4%'></td>");
                    }
                    i++;
                }
                strCheckBoxes.append("</tr>");
            }
            strCheckBoxes.append("</table>");
            divFilterList.innerHTML = strCheckBoxes;
            initUserFilter();
        }
    }
}

function lnkFilterShowHideClicked()
{
    if (document.getElementById("lnkOption").innerHTML == langTxt.Txt_FilterShowBtn)
    {
        doShow();
    }
    else
    {
        doHide();
    }
}

function doHide()
{
    document.getElementById("divFilter").style.display = "none";
    document.getElementById("lnkOption").innerHTML = langTxt.Txt_FilterShowBtn;
}

function doShow()
{
    document.getElementById("divFilter").style.display = "inline";
    document.getElementById("lnkOption").innerHTML = langTxt.Txt_FilterHideBtn;
}

function setFilterCheck(checked) {
    setAllCheckBoxes("chkStkFilter", checked);
    rebuildUserList();
}

function reverseFilterSelection() {
    var arrChk = document.getElementsByName("chkStkFilter");
    for (i = 0; i < arrChk.length; i++) {
        arrChk[i].checked = !arrChk[i].checked;
    }
    rebuildUserList();
}

function reselectFilterList(checkList) {
    if ((checkList == null) || (checkList.length <= 0)) return;
    setAllCheckBoxes("chkStkFilter", false);

    for (i = 0; i < checkList.length; i++) {
        var chkID = "chkStkSbl_" + checkList[i];
        var obj = document.getElementById(chkID);
        if (obj != null) obj.checked = true;
    }
    rebuildUserList();
}
