var chks;
var len;
var continuous = true;
function chk(obj) {
    chks = document.getElementsByName("P");
    len = chks.length;
    if (continuous == true) {
        Previous(obj);
        Next(obj);
    }
}
function Previous(obj) {
    for (var i = 0; i < len; i++) {
        if (obj.getAttribute("parentid") == chks[i].value) {
            if (Count(obj) == 0) {
                chks[i].checked = obj.checked;
            } else {
                chks[i].checked = true;
            }
            Previous(chks[i]);
        }
    }
}
function Count(obj) {
    var num = 0;
    for (var i = 0; i < len; i++) {
        if (obj.getAttribute("parentid") == chks[i].getAttribute("parentid")) {
            if (chks[i].checked) num++;
        }
    }
    return num;
}
function Next(obj) {
    for (var i = 0; i < len; i++) {
        if (obj.value == chks[i].getAttribute("parentid")) {
            chks[i].checked = obj.checked;
            Next(chks[i]);
        }
    }
}
function Field(id) {
    var obj = uiGet("ul" + id + "");
    if (obj != null) {
        if (obj.style.visibility == "visible") {
            obj.style.visibility = 'hidden';
            obj.style.height = '0px';
        } else {
            obj.style.visibility = 'visible';
            obj.style.height = 'auto';
        }
    }
}
function ktd(obj) {
    var p = uiGetTag(obj.parentElement, "b")[0]
    var value = obj.getAttribute("value");
    var td = uiGet("K" + value);
    if (td.style.display == "block" || td.style.display == "") {
        td.style.display = "none";
        p.innerHTML = "[+]";
    } else {
        td.style.display = "block";
        p.innerHTML = "[-]";
    }
}
function ChkALLSelRef(id) {
    var chk = uiGetTag(uiGet(id), "input");
    if (chk != null) {
        for (i = 0; i < chk.length; i++) {
            if (chk[i].getAttribute("type") == "checkbox") {
                if (chk[i].getAttribute("name") != "IsAdmin") {
                    if (chk[i].checked) {
                        chk[i].checked = false;
                    } else {
                        chk[i].checked = true;
                    }
                }
            }
        }
    }
}
function ChkALLCancel(id) {
    var chk = uiGetTag(uiGet(id), "input");
    if (chk != null) {
        for (i = 0; i < chk.length; i++) {
            if (chk[i].getAttribute("type") == "checkbox") {
                if (chk[i].getAttribute("name") != "IsAdmin") {
                    chk[i].checked = false;
                }
            }
        }
    }
}
function ChkALLOpen(id) {
    var td = uiGetTag(uiGet(id), "td");
    if (td != null) {
        for (i = 0; i < td.length; i++) {
            if (td[i].id.indexOf("K") != -1) {
                td[i].style.display = "block";
                var p = uiGetTag(uiGet("P" + td[i].id.substring(1)).parentElement, "b")[0];
                p.innerHTML = "[-]";
            }

        }
    }
}
function ChkALLClose(id) {
    var td = uiGetTag(uiGet(id), "td");
    if (td != null) {
        for (i = 0; i < td.length; i++) {
            if (td[i].id.indexOf("K") != -1) {
                td[i].style.display = "none";
                var p = uiGetTag(uiGet("P" + td[i].id.substring(1)).parentElement, "b")[0];
                p.innerHTML = "[+]";
            }
        }
    }
}
function isAdminClick(obj) {
    var div = obj.parentElement;
    if (obj.checked) {
        with(div.style) {
            border = "1px red solid";
            background = "#FFF0F0";
        }
    } else {
        with(div.style) {
            border = "1px solid #CCCCCC";
            background = "#DDDDDD";
        }
    }
    var chk = uiGetTag(div, "input");
    for (i = 0; i < chk.length; i++) {
        if (chk[i] != obj) chk[i].checked = obj.checked;
    }
}
function _continuous_(obj) {
    var flag = obj.checked;
    continuous = flag;
}