//-----------------------------------------------------------
// 文件名称: Web25175_Hotel2.treeview.v1.1.js
// 页面名称: Web25175_Hotel2.treeview.v1.1
//　
// 描    述: .Net树型控件 联动复选辅助
// 版　　本: 1.1
// 兼容情况: IE6+,Chrome,Mozilla, Netscape, Firefox,Maxthon3+,
// 创建标识: Add By 吴希 2011-10-26
//---------------------------------------------
function InitCheckTree(ElementId, flag) {
    var div = uiGet(ElementId);
    if (div != null) {
        var input = uiGetTag(div, "input");
        if (input != null && input.length > 0) {
            for (i = 0; i < input.length; i++) {
                if (input[i].type.toLowerCase() == "checkbox") {
                    input[i].onclick = function() {
                        var div_2_id = this.id.substring(0, this.id.indexOf("CheckBox")) + "Nodes";
                        var div_2 = uiGet(div_2_id);
                        if (div_2 != null) {
                            SelectCheckNext(div_2, this);
                        }
                        if (flag != null && flag == true) {
                            SelectCheckPrev(this)　
                        }
                    }　　
                }　　
            }　　
        }
    }
}
function SelectCheckNext(Element, ElementChk) {
    var input = uiGetTag(Element, "input");
    if (input != null && input.length > 0) {
        for (i = 0; i < input.length; i++) {
            if (input[i].type.toLowerCase() == "checkbox") {
                input[i].checked = ElementChk.checked;
            }
        }
    }
}
function SelectCheckPrev(Element) {
    var div = Element.parentElement.parentElement.parentElement.parentElement.parentElement;
    var table = Element.parentElement.parentElement.parentElement.parentElement;
    var count = SelectCheckCount(table);
    var chk_2_id = div.id.substring(0, div.id.indexOf("Nodes")) + "CheckBox";
    var chk_2 = uiGet(chk_2_id);
    if (chk_2 != null) {
        if (count == 0) {
            chk_2.checked = Element.checked;
        } else {
            chk_2.checked = true;
        }
        SelectCheckPrev(chk_2);
    }
} 
//nextSibling // previousSibling
function SelectCheckCount(Element) {
    var Next = Element.nextSibling;
    var Prev = Element;
    var array = new Array();
    var Count = 0
    while (Next != null) {
        if (Next.nodeName.toLowerCase() == "table") {
            array.push(Next);
        }
        Next = Next.nextSibling;
    }
    while (Prev != null) {
        if (Prev.nodeName.toLowerCase() == "table") {
            array.push(Prev);
        }
        Prev = Prev.previousSibling;
    }
    for (i = 0; i < array.length; i++) {
        var input = uiGetTag(array[i], "input");
        if (input != null && input.length > 0) {
            for (j = 0; j < input.length; j++) {
                if (input[j].type.toLowerCase() == "checkbox" && input[j].checked) {
                    Count++;
                }
            }
        }
    }
    return Count;
}
