function jsConditionSetting() {

};
/*条件类型*/
jsConditionSetting.sqlType = null;
/*SQL类型的SQL语句*/
jsConditionSetting.sqlContent = null;
/*sql类型的参数数组*/
jsConditionSetting.sqlArray = null;
/*存储过程的参数*/
jsConditionSetting.processParam = null;
/*当前数据视图数据对象ID*/
jsConditionSetting.CurrentDataViewID = null;
/*关系*/
jsConditionSetting.LinkString = "<select style='width:98%' class='selLinkString'><option value='and'>并且</option><option value='or'>或者</option></select>";
/*字段*/
//jsConditionSetting.FieldString="<span>查询字段：</span><input type='text' style='width:80%'/>";
//jsConditionSetting.FieldString = function(id) { return "<span>查询字段：</span><select style='width:80%' id='sel" + id + "'  class='selQueryField'></select>"; }
/*比较方式*/
jsConditionSetting.TypeString = "<select style='width:97%'><option value='='>等于</option><option value='<>'>不等于</option><option value='>'>大于</option><option value='>='>大于等于</option><option value='<'>小于</option><option value='<='>小于等于</option><option value='in'>包含在</option><option value='not in'>不包含在</option><option value='like'>含有</option></select>";
/*值*/
jsConditionSetting.ValueString = "<span>值：</span><input type='text' style='width:80%'/>";
/*组操作串*/
jsConditionSetting.GroupOperateString = "<input type='button' class='btn' value='加条件' onclick='jsConditionSetting.addCondition(this);'/>&nbsp;&nbsp;<input type='button' class='btn' value='子分组' onclick='jsConditionSetting.addItemGroup(this);'/>&nbsp;&nbsp;<input type='button' class='btn' value='删组' onclick='jsConditionSetting.DeleteGroup(this)'/>";
/*条件操作串*/
jsConditionSetting.ConditionOperateString = "<input type='button' class='btn' value='删除' onclick='jsConditionSetting.deleteCondition(this);'/>";

jsConditionSetting.MaxGroupNum = 0;

jsConditionSetting.PageLoad = function() {
    try {
        document.getElementById("div-main-container").style.height = document.body.clientHeight - document.getElementById("divToolBar").clientHeight - document.getElementById("divCode").clientHeight;
        jsConditionSetting.AddGroup();
    }
    catch (e) {

    }
};
/*增加分组*/
//jsConditionSetting.AddGroup = function(indexValue) {
jsConditionSetting.AddGroup = function() {
    try {
        var newRowObj = null;
//        if (typeof (indexValue) != "undefined") {
//            newRowObj = document.getElementById("tdContent").insertRow(rowIndex);
//        }
//        else {
            newRowObj = document.getElementById("tdContent").insertRow(document.getElementById("tdContent").rows.length);
//        }
        /*本组条件个数*/
        newRowObj.ItemCount = 0;
        /*本组分组个数*/
        newRowObj.ItemGroupCount = 0;
        newRowObj.GroupIndex = jsConditionSetting.MaxGroupNum;
        newRowObj.Path = "0_" + (newRowObj.GroupIndex + 1);
        newRowObj.id = 'Group_' + newRowObj.Path;
        newRowObj.ParentID = "Group_-1";
        newRowObj.Level = 0;
        newRowObj.expended = true;
        newRowObj.style.backgroundColor = '#D6D3CE';

        var newCellObj = newRowObj.insertCell(0);
        newCellObj.innerHTML = jsConditionSetting.LinkString;
        newCellObj = null;
        newCellObj = newRowObj.insertCell(1);
        newCellObj.colSpan = 3;
        newCellObj.innerHTML = "<img style='cursor:hand;' src='../../AppFrame/APICss/default/images/tree/elbow-end-minus-nl.gif' border='0' alt='点击收起所有下级' actionType='expend' onclick='jsConditionSetting.expendItemGroup(this);'/><span style='color:#FF9900'>[第 " + (jsConditionSetting.MaxGroupNum + 1) + " 组]</span>";

        newCellObj = null;
        newCellObj = newRowObj.insertCell(2);
        newCellObj.colSpan = 2;
        newCellObj.align = 'right';
        newCellObj.innerHTML = jsConditionSetting.GroupOperateString;

        jsConditionSetting.MaxGroupNum = parseInt(jsConditionSetting.MaxGroupNum) + 1;
        jsConditionSetting.setFirstGroup("Group");
        /*加组后自动增加一个条件*/
        var actionObj = newRowObj.cells(2).childNodes[0];
        jsConditionSetting.addCondition(actionObj);
        actionObj = null;
        newRowObj = null;

    }
    catch (e) {
        alert(e.message);
    }
    CollectGarbage();
};
/*删除当前组*/
jsConditionSetting.DeleteGroup = function(obj) {
    try {
        var rowObj = obj.parentElement.parentElement;
        var ParentRowObj = document.getElementById(rowObj.ParentID);
        var currentIndex = rowObj.rowIndex;
        /*删除自己*/
        document.getElementById("tdContent").deleteRow(currentIndex);
        /*删除子级*/
        var len = rowObj.Path.length;
        var SumLen = document.getElementById("tdContent").rows.length;
        for (var i = SumLen - 1; i >= currentIndex; i--) {
            var ItemRowObj = document.getElementById("tdContent").rows(i);
            if (ItemRowObj != null) {
                if (ItemRowObj.Path.substring(0, len) == rowObj.Path) {
                    document.getElementById("tdContent").deleteRow(i);
                }
            }
            ItemRowObj = null;
        }
        SumLen = null;
        len = null;
        /*改变同级*/
        if (ParentRowObj != null) {
            ParentRowObj.ItemGroupCount = ParentRowObj.ItemGroupCount - 1;
        }
        for (var i = currentIndex; i < document.getElementById("tdContent").rows.length; i++) {
            var ItemRowObj = document.getElementById("tdContent").rows(i);
            if (ItemRowObj.ParentID == rowObj.ParentID) {
                var OldPath = ItemRowObj.Path;
                if (ParentRowObj != null) {
                    if (ItemRowObj.id.indexOf("ItemGroup") != -1) {
                        ItemRowObj.GroupIndex = ItemRowObj.GroupIndex - 1;
                        ItemRowObj.Path = ParentRowObj.Path + "_" + (ItemRowObj.GroupIndex + 1);
                        ItemRowObj.id = 'ItemGroup_' + ItemRowObj.Path;
                    }
                    else if (ItemRowObj.id.indexOf("ItemCondition") != -1) {
                        ItemRowObj.ItemIndex = ItemRowObj.ItemIndex - 1;
                        ItemRowObj.Path = ParentRowObj.Path + "_" + (ItemRowObj.ItemIndex + 1);
                        ItemRowObj.id = 'ItemCondition_' + ItemRowObj.Path;
                    }
                }
                else {
                    ItemRowObj.GroupIndex = ItemRowObj.GroupIndex - 1;
                    ItemRowObj.Path = "0_" + (ItemRowObj.GroupIndex + 1);
                    ItemRowObj.id = 'Group_' + ItemRowObj.Path;
                }
                if (ParentRowObj != null && ItemRowObj.id.indexOf("ItemGroup") != -1) {
                    ItemRowObj.cells(1).childNodes(2).innerText = "[第 " + ItemRowObj.Path.substring(2, ItemRowObj.Path.length) + " 组]";
                }
                else {
                    ItemRowObj.cells(1).childNodes(1).innerText = "[第 " + (ItemRowObj.GroupIndex + 1) + " 组]";
                }
                /*改变下级路径*/
                var len = OldPath.length;
                for (var ii = (i + 1); ii < document.getElementById("tdContent").rows.length; ii++) {
                    var ItemRowObj2 = document.getElementById("tdContent").rows(ii);
                    if (ItemRowObj2 != null) {
                        if (ItemRowObj2.Path.substring(0, len) == OldPath) {
                            ItemRowObj2.Path = ItemRowObj.Path + ItemRowObj2.Path.substring(len, ItemRowObj2.Path.length);

                            if (ItemRowObj2.id.indexOf("ItemGroup") != -1) {
                                ItemRowObj2.id = "ItemGroup_" + ItemRowObj2.Path;
                            }
                            else if (ItemRowObj2.id.indexOf("ItemCondition") != -1) {
                                ItemRowObj2.id = "ItemCondition_" + ItemRowObj2.Path;
                            }
                            if (ItemRowObj2.ParentID.indexOf("ItemGroup") != -1) {
                                ItemRowObj2.ParentID = "ItemGroup_" + ItemRowObj.Path + ItemRowObj2.ParentID.substring(("ItemGroup_" + ItemRowObj.Path).length, ItemRowObj2.ParentID.length);
                            }
                            else {
                                ItemRowObj2.ParentID = "Group_" + ItemRowObj.Path + ItemRowObj2.ParentID.substring(("Group_" + ItemRowObj.Path).length, ItemRowObj2.ParentID.length);
                            }
                            if (ItemRowObj2.id.indexOf("ItemGroup") != -1) {
                                ItemRowObj2.cells(1).childNodes(2).innerHTML = "[第 " + ItemRowObj2.Path.substring(2, ItemRowObj2.Path.length) + " 组]";
                            }
                        }
                        else {
                            ItemRowObj2 = null;
                            break;
                        }
                    }
                    ItemRowObj2 = null;
                }
                OldPath = null;
                len = null;
            }
            ItemRowObj = null;
        }
        if (rowObj.id.indexOf("ItemGroup") != -1) {
            jsConditionSetting.setFirstGroup("ItemGroup");
        }
        else if (ParentRowObj == null) {
            jsConditionSetting.setFirstGroup("Group");
            jsConditionSetting.MaxGroupNum = jsConditionSetting.MaxGroupNum - 1;
        }
        currentIndex = null;
        rowObj = null;
        //jsConditionSetting.changRowSelect();
    }
    catch (e) {
        alert(e.message);
    }
    CollectGarbage();
};
/*设置第一组或条件的关系列为空*/
jsConditionSetting.setFirstGroup = function(typeName) {
    try {
        for (var i = 0; i < document.getElementById("tdContent").rows.length; i++) {
            var rowObj = document.getElementById("tdContent").rows(i);
            if (rowObj.id.indexOf(typeName) != -1) {
                var tempValue = rowObj.Path.split('_');
                if (tempValue[tempValue.length - 1] == '1') {
                    if (typeName == "Group" && rowObj.id.indexOf("ItemGroup") == -1) {
                        rowObj.cells(0).innerHTML = '';
                    }
                    else if (typeName == "ItemGroup") {
                        var ParentRowObj = document.getElementById(rowObj.ParentID);
                        if (ParentRowObj != null && ParentRowObj.ItemCount > 0) {
                            rowObj.cells(0).innerHTML = jsConditionSetting.LinkString;
                        }
                        else {
                            rowObj.cells(0).innerHTML = '';
                        }
                    }
                    else if (typeName == "ItemCondition") {
                        rowObj.cells(1).innerHTML = '';
                    }
                }
            }
            rowObj = null;
        }
    }
    catch (e) {
        alert(e.message);
    }
    CollectGarbage();
};
/*添加条件*/
jsConditionSetting.addCondition = function(obj) {
    rowObj = null;
    if (obj == null) {
        rowObj = document.getElementById("tdContent").rows(2);
    }
    else {
        rowObj = obj.parentElement.parentElement;
    }
    try {
        var newRowObj = null;
        var insertIndex = parseInt(parseInt(rowObj.rowIndex) + parseInt(rowObj.ItemCount) + 1);
        newRowObj = document.getElementById("tdContent").insertRow(insertIndex);

        /*本组条件个数*/
        rowObj.ItemCount = parseInt(rowObj.ItemCount) + 1;
        var newItemIndex = rowObj.ItemCount - 1;
        newRowObj.ItemIndex = newItemIndex;
        newRowObj.id = "ItemCondition_" + rowObj.Path + "_" + newRowObj.ItemIndex;
        newRowObj.ParentID = rowObj.id;
        newRowObj.Path = rowObj.Path + "_" + (newRowObj.ItemIndex + 1);
        var ParentPath = rowObj.Path;

        var newCellObj = newRowObj.insertCell(0);
        newCellObj.innerHTML = "";
        newCellObj = null;
        newCellObj = newRowObj.insertCell(1);
        newCellObj.innerHTML = jsConditionSetting.LinkString;
        /*如果条件序号不是第2个，那么就直接灰掉关系选择*/
        if (newItemIndex > 1) {
            newCellObj.childNodes[0].disabled = true;
            /*设置默认值为第一个条件的值*/
            for (var i = insertIndex - 1; i > 0; i--) {
                var oldrowObj = document.getElementById("tdContent").rows(i);
                if (oldrowObj != null) {
                    /*找到同级中的条件作为取默认值对象*/
                    if (oldrowObj.Path.substring(0, ParentPath.length) == ParentPath && oldrowObj.id.indexOf('ItemCondition') != -1) {
                        newCellObj.childNodes[0].value = oldrowObj.cells(1).childNodes[0].value;
                        oldrowObj = null;
                        break;
                    }
                }
                rowObj = null;
            }
        }
        else if (newItemIndex == 1) {
            /*如果是第2个条件的时候，那么改变关系的时候会自动改变后面条件的关系*/
            var arr = new Array();
            arr.push("newCellObj.childNodes[0].onchange=function()");
            arr.push("{");
            arr.push("jsConditionSetting.setConditionLink(this);");
            arr.push("};");
            var method = arr.join('');
            newCellObj.childNodes[0].Method = escape(method.substring(method.indexOf("="), method.length));
            method = null;
            eval(arr.join(''));
            arr.length = 0;
            arr = null;
        }
        newCellObj = null;
        newCellObj = newRowObj.insertCell(2);
        newCellObj.innerHTML = jsConditionSetting.FieldString(newRowObj.id);
        //document.getElementById("sel" + newRowObj.id).onchange = function() { jsConditionSetting.changeSelect(document.getElementById("sel" + newRowObj.id)); }
        /*设置字段选择下拉时动作*/
        var arr = new Array();
        arr.push("newCellObj.childNodes[1].onchange=function()");
        arr.push("{");
        arr.push("jsConditionSetting.changedFieldAddCondition(this);");
        arr.push("};");
        var method = arr.join('');
        newCellObj.childNodes[1].Method = escape(method.substring(method.indexOf("="), method.length));
        method = null;
        eval(arr.join(''));
        arr.length = 0;
        arr = null;
        newCellObj = null;
        newCellObj = newRowObj.insertCell(3);
        newCellObj.innerHTML = jsConditionSetting.TypeString;
        newCellObj = null;
        newCellObj = newRowObj.insertCell(4);
        newCellObj.innerHTML = jsConditionSetting.ValueString;
        newCellObj = null;
        newCellObj = newRowObj.insertCell(5);
        newCellObj.innerHTML = jsConditionSetting.ConditionOperateString;
        newCellObj = null;
        jsConditionSetting.changedFieldAddCondition(newRowObj.cells[2].children[1], 0);
        newRowObj = null;
        newItemIndex = null;
        insertIndex = null;
        ParentPath = null;
        jsConditionSetting.setFirstGroup("ItemCondition"); /*项目条件*/
        jsConditionSetting.setFirstGroup("ItemGroup"); /*项目组*/
    }
    catch (e) {
        if (e == "Invalid JSON: undefined") {
            jsConditionSetting.DeleteGroup(obj);
            alert("加组失败，请在系统设置设置资料！");
        } else {
            alert(e.message);
        }
    }
    rowObj = null;
    CollectGarbage();
}
/*改变后面同级条件的关系和当前条件的关系一样*/
jsConditionSetting.setConditionLink = function(obj) {
    try {
        var GrouprowObj = obj.parentElement.parentElement;
        var objRowIndex=GrouprowObj.rowIndex;
        var parentPath=GrouprowObj.Path;
        var parentID=GrouprowObj.ParentID;
        
        var len = parentPath.length;
        for (var i = (parseInt(objRowIndex) + 1); i < document.getElementById("tdContent").rows.length; i++) {
            var rowObj = document.getElementById("tdContent").rows(i);
            if (rowObj != null) {
                if (rowObj.ParentID == parentID && rowObj.id.indexOf('ItemCondition') != -1) {
                    rowObj.cells(1).childNodes[0].value = obj.value;
                }
                else {
                    rowObj = null;
                    break;
                }
            }
            rowObj = null;
        }
        len = null;
    }
    catch (e) {
        alert("jsConditionSetting.setConditionLink:" + e.message);
    }
    obj = null;
    objRowIndex = null;
    parentPath = null;

    CollectGarbage();
};
/*字段选择改变时自动添加一行条件*/
jsConditionSetting.changedFieldAddCondition = function(obj, pat) {
    try {
        var rowObj = obj.parentElement.parentElement;
        var objRowIndex = rowObj.rowIndex;
        var parentPath = rowObj.Path;
        var parentID = rowObj.ParentID;
        /*获取组的行对象*/
        /*如果本行接下来一行不是条件或者本行是最后一行，那么就自动添加条件*/
//        if (pat == undefined && (objRowIndex == document.getElementById("tdContent").rows.length - 1
//        || document.getElementById("tdContent").rows(parseInt(objRowIndex) + 1).id.indexOf("Group") != -1)) {
//            for (var i = objRowIndex - 1; i > 0; i--) {
//                var oldrowObj = document.getElementById("tdContent").rows(i);
//                if (oldrowObj != null) {
//                    /*找到本条件所属的组对象*/
//                    if (oldrowObj.id == parentID) {
//                        var actionObj = oldrowObj.cells(2).childNodes[0];
//                        jsConditionSetting.addCondition(actionObj);
//                        oldrowObj = null;
//                        actionObj = null;
//                        break;
//                    }
//                }
//                oldrowObj = null;
//            }
//        }
        if (obj[obj.selectedIndex].process == "") {
            var htmlContent = unescape(obj[obj.selectedIndex].content);
            if (htmlContent.toLowerCase().indexOf("</textarea>") != -1) {
                obj.parentElement.parentElement.childNodes[4].innerHTML = "<SPAN>值：</SPAN>" + "<input type='text' class ='ipt' style='width:80%;'>";
            } else {
                obj.parentElement.parentElement.childNodes[4].innerHTML = "<SPAN>值：</SPAN>" + htmlContent;
            }

            htmlContent = null;
        } else {
            obj.parentElement.parentElement.childNodes[4].innerHTML = unescape(obj[obj.selectedIndex].content);
            var _dom = obj.parentElement.parentElement.childNodes[4].childNodes[0];
            obj.parentElement.parentElement.childNodes[4].innerHTML = "<SPAN>值：</SPAN>" + jsConditionSetting.createProcessDom(_dom, obj[obj.selectedIndex].process);
        }
    }
    catch (e) {
        alert("jsConditionSetting.changedFieldAddCondition:" + e.message);
    }
    CollectGarbage();
};

/*读取数据库生成控件*/
jsConditionSetting.createProcessDom = function(obj, process) {
    var strSql = unescape(process); /*解密存储过程字段*/
    var selectObj = $.parseJSON("{" + DBReader.selectSqlForJson(strSql) + "}"); /*读取数据库*/
    var strInsertHtml = "";
    strSql = null;
    if (selectObj.table != undefined && selectObj.table.length > 0) {
        if (obj.type == "select") {/*解析下拉框*/
            var selected = "";
            for (var i = 0; i < selectObj.table.length; i++) {
                if (selectObj.table[i][obj.processValue] == obj.value) {
                    selected = "selected";
                }
                strInsertHtml += "<option " + selected + " value='" + (selectObj.table[i][obj.processValue] == undefined ? "" : selectObj.table[i][obj.processValue]) + "'>" + (selectObj.table[i][obj.processName] == undefined ? "" : selectObj.table[i][obj.processName]) + "</option>";
            }
            strInsertHtml = "<select type='select' Field='" + obj.Field + "' format='varchar(50)' dataType='" + obj.dataType + "' process='" + process + "' SelValueMode='Text'>" + strInsertHtml + "</select>";
            selected = null;

        } else if (obj.type == "checkbox") {/*解析复选框*/
            var arrayChk = [];
            var chkObj = document.getElementsByName(obj.name);
            for (var p = 0; p < chkObj.length; p++) {
                if (chkObj[p].checked) {
                    arrayChk.push(chkObj[p].value);
                }
            }
            for (var i = 0; i < selectObj.table.length; i++) {
                var checked = "";
                if (arrayChk.length > 0) {
                    for (var k = 0; k < arrayChk.length; k++) {
                        if (selectObj.table[i][obj.processValue] == arrayChk[k]) {
                            checked = "checked='checked'";
                            break;
                        }
                    }
                }
                if (strInsertHtml == "") {
                    strInsertHtml += "<input  name='" + obj.name + "' " + checked + " Field='" + obj.Field + "' format='varchar(50)' type='checkbox'  value='" + (selectObj.table[i][obj.processValue] == undefined ? "" : selectObj.table[i][obj.processValue]) + "' dataType='" + obj.dataType + "' process='" + process + "' SelValueMode='Text'/><span>" + (selectObj.table[i][obj.processName] == undefined ? "" : selectObj.table[i][obj.processName]) + "</span>";
                }
                else {
                    strInsertHtml += "<input name='" + obj.name + "' Field='" + obj.Field + "' " + checked + "  type='checkbox'  value='" + (selectObj.table[i][obj.processValue] == undefined ? "" : selectObj.table[i][obj.processValue]) + "' SelValueMode='Text'/><span>" + (selectObj.table[i][obj.processName] == undefined ? "" : selectObj.table[i][obj.processName]) + "</span>";
                }
                checked = null;
            }
        } else if (obj.type == "radio") {/*解析单选框*/
            var checkValue = "";
            var chkObj = document.getElementsByName(obj.name);
            for (var p = 0; p < chkObj.length; p++) {
                if (chkObj[p].checked) {
                    checkValue = chkObj[p].value;
                    break;
                }
            }
            for (var i = 0; i < selectObj.table.length; i++) {
                var checked = "";
                if (selectObj.table[i][obj.processValue] == checkValue) {
                    checked = "checked='checked'";
                }
                if (strInsertHtml == "") {
                    strInsertHtml += "<input  name='" + obj.name + "' Field='" + obj.Field + "' format='varchar(50)' " + checked + " type='radio' value='" + (selectObj.table[i][obj.processValue] == undefined ? "" : selectObj.table[i][obj.processValue]) + "' dataType='" + obj.dataType + "' process='" + process + "' SelValueMode='Text'/><span>" + (selectObj.table[i][obj.processName] == undefined ? "" : selectObj.table[i][obj.processName]) + "</span>";
                }
                else {
                    strInsertHtml += "<input  name='" + obj.name + "' Field='" + obj.Field + "' " + checked + " type='radio' value='" + (selectObj.table[i][obj.processValue] == undefined ? "" : selectObj.table[i][obj.processValue]) + "' SelValueMode='Text'/><span>" + (selectObj.table[i][obj.processName] == undefined ? "" : selectObj.table[i][obj.processName]) + "</span>";
                }
                checked = null;
            }
        }
    }
    return strInsertHtml;
}

/*删除条件*/
jsConditionSetting.deleteCondition = function(obj) {
    var rowObj = obj.parentElement.parentElement;
    try {
        var currentIndex = rowObj.rowIndex;
        var currentItemIndex = rowObj.ItemIndex;
        var currentId = rowObj.id;
        document.getElementById("tdContent").deleteRow(currentIndex);

        /*本组条件个数*/
        var GroupIndex = currentId.split('_')[1];
        var GroupRowObj = document.getElementById(rowObj.ParentID);
        GroupRowObj.ItemCount = parseInt(GroupRowObj.ItemCount) - 1;
        for (var i = parseInt(currentIndex); i < (parseInt(currentIndex) + parseInt(GroupRowObj.ItemCount)); i++) {
            var ItemRowObj = document.getElementById("tdContent").rows(i);
            if (ItemRowObj != null) {
                if (ItemRowObj.id.indexOf("ItemCondition_" + GroupRowObj.Path + "_") != -1 && ItemRowObj.ItemIndex >= currentItemIndex) {
                    ItemRowObj.ItemIndex = ItemRowObj.ItemIndex - 1;
                    ItemRowObj.Path = GroupRowObj.Path + "_" + (ItemRowObj.ItemIndex + 1);
                    ItemRowObj.id = 'ItemCondition_' + GroupRowObj.Path + "_" + ItemRowObj.ItemIndex;
                }
            }
            ItemRowObj = null;
        }
        currentIndex = null;
        GroupRowObj = null;
        currentIndex = null;
        currentItemIndex = null;
        currentId = null;
        GroupIndex = null;
        jsConditionSetting.setFirstGroup("ItemCondition");
        jsConditionSetting.setFirstGroup("ItemGroup");
    }
    catch (e) {
        alert(e.message);
    }
    rowObj = null;
    //jsConditionSetting.changRowSelect();
    CollectGarbage();
};
/*添加分组*/
jsConditionSetting.addItemGroup = function(obj) {
    try {
        var GroupRowObj = obj.parentElement.parentElement; /*获取分组按钮的行对象*/
        var currentIndex = GroupRowObj.rowIndex; /*行对象的行序号*/

        var ItemCount = GroupRowObj.ItemCount; /*条件个数*/
        var ItemGroupCount = GroupRowObj.ItemGroupCount;
        var addPosition = 0;
        var pathValue = GroupRowObj.Path;

        for (var i = (currentIndex + 1); i < document.getElementById("tdContent").rows.length; i++) {
            var rowObj = document.getElementById("tdContent").rows(i);
            if (rowObj.ParentID == GroupRowObj.id) {
                addPosition = i;
            }
            else if (rowObj.Level == GroupRowObj.Level) {
                rowObj = null;
                break;
            }
            rowObj = null;
        }
        var newRowObj = null;
        var ItemNodeCount = 0;
        if (addPosition == 0) {
            addPosition = currentIndex;
        }
        else {
            var tempRowObj = document.getElementById("tdContent").rows(addPosition);
            var len = tempRowObj.Path.length;
            for (var i = (addPosition + 1); i < document.getElementById("tdContent").rows.length; i++) {
                var rowObj = document.getElementById("tdContent").rows(i);
                if (rowObj != null) {
                    if (rowObj.Path.substring(0, len) == tempRowObj.Path) {
                        ItemNodeCount++;
                    }
                    else {
                        rowObj = null;
                        break;
                    }
                }
                rowObj = null;
            }
            len = null;
            tempRowObj = null;
        }
        var InsertIndex = (addPosition + ItemNodeCount + 1);
        ItemNodeCount = null;
        newRowObj = document.getElementById("tdContent").insertRow(InsertIndex);
        InsertIndex = null;
        /*本组条件个数*/
        newRowObj.ItemCount = 0;
        /*分组个数*/
        newRowObj.ItemGroupCount = 0;
        newRowObj.GroupIndex = GroupRowObj.ItemGroupCount;
        newRowObj.ParentID = GroupRowObj.id;
        newRowObj.Path = GroupRowObj.Path + "_" + (parseInt(newRowObj.GroupIndex) + 1);
        newRowObj.Level = (parseInt(GroupRowObj.Level) + 1);
        GroupRowObj.ItemGroupCount = parseInt(GroupRowObj.ItemGroupCount) + 1;

        newRowObj.id = 'ItemGroup_' + newRowObj.Path;
        newRowObj.style.backgroundColor = '#999966';
        newRowObj.expended = true;

        var newCellObj = newRowObj.insertCell(0);
        newCellObj.innerHTML = jsConditionSetting.LinkString;
        newCellObj = null;
        newCellObj = newRowObj.insertCell(1);
        newCellObj.colSpan = 3;
        var spaceLen = "";
        var arr = newRowObj.Path.split('_');
        for (var i = 0; i < arr.length - 1; i++) {
            spaceLen += "&nbsp;&nbsp;&nbsp;";
        }
        arr = null;

        newCellObj.innerHTML = spaceLen + "<img style='cursor:hand;' src='../../AppFrame/APICss/default/images/tree/elbow-end-minus-nl.gif' border='0' alt='点击收起所有下级' actionType='expend' onclick='jsConditionSetting.expendItemGroup(this);'/><span style='color:#FF9900'>[第 " + (newRowObj.Path.substring(2, newRowObj.Path.length)) + " 组]</span>";
        spaceLen = null;
        newCellObj = null;
        newCellObj = newRowObj.insertCell(2);
        newCellObj.colSpan = 2;
        newCellObj.align = 'right';
        newCellObj.innerHTML = jsConditionSetting.GroupOperateString;
        newCellObj = null;

        jsConditionSetting.setFirstGroup("ItemGroup");
        /*加组后自动增加一个条件*/
        var actionObj = newRowObj.cells(2).childNodes[0];
        jsConditionSetting.addCondition(actionObj);
        actionObj = null;

        newRowObj = null;
        ItemCount = null;
        ItemGroupCount = null;

        currentIndex = null;
        GroupRowObj = null;
    }
    catch (e) {
        alert(e.message);
    }
    CollectGarbage();
};
/*展开下级组*/
jsConditionSetting.expendItemGroup = function(obj) {
    var rowObj = obj.parentElement.parentElement;
    try {
        var len = rowObj.Path.length;
        for (var i = (rowObj.rowIndex + 1); i < document.getElementById("tdContent").rows.length; i++) {
            var ItemRowObj = document.getElementById("tdContent").rows(i);
            if (ItemRowObj != null) {
                if (ItemRowObj.id.indexOf("Group") != -1) {
                    if (ItemRowObj.Path.substring(0, len) == rowObj.Path) {
                        if (obj.actionType == "unexpend") {
                            if (ItemRowObj.cells(0).childNodes.length > 0) {
                                ItemRowObj.cells(0).childNodes(0).style.display = '';
                            }
                            if (ItemRowObj.id.indexOf('Group') != -1) {
                                ItemRowObj.expended = true;
                                if (ItemRowObj.cells(1).childNodes.length > 1) {
                                    ItemRowObj.cells(1).childNodes(1).actionType = "expend";
                                    ItemRowObj.cells(1).childNodes(1).src = '../../AppFrame/APICss/default/images/tree/elbow-end-minus-nl.gif';
                                }
                            }
                            ItemRowObj.style.display = '';
                        }
                        else {
                            if (ItemRowObj.cells(0).childNodes.length > 0) {
                                ItemRowObj.cells(0).childNodes(0).style.display = 'none';
                            }
                            if (ItemRowObj.id.indexOf('Group') != -1) {
                                ItemRowObj.expended = false;
                                if (ItemRowObj.cells(1).childNodes.length > 1) {
                                    ItemRowObj.cells(1).childNodes(1).actionType = "unexpend";
                                    ItemRowObj.cells(1).childNodes(1).src = '../../AppFrame/APICss/default/images/tree/elbow-plus-nl.gif';
                                }
                            }
                            ItemRowObj.style.display = 'none';
                        }
                    }
                    else {
                        ItemRowObj = null;
                        break;
                    }
                }
                else {
                    if (obj.actionType == "unexpend") {
                        if (ItemRowObj.cells(1).childNodes.length > 0) {
                            ItemRowObj.cells(1).childNodes(0).style.display = '';
                        }
                        if (ItemRowObj.cells(2).childNodes.length > 1) {
                            ItemRowObj.cells(2).childNodes(0).style.display = '';
                            ItemRowObj.cells(2).childNodes(1).style.display = '';
                        }
                        ItemRowObj.cells(3).childNodes(0).style.display = '';
                        if (ItemRowObj.cells(4).childNodes.length > 1) {
                            ItemRowObj.cells(4).childNodes(0).style.display = '';
                            ItemRowObj.cells(4).childNodes(1).style.display = '';
                        }
                        ItemRowObj.style.display = '';
                    }
                    else {
                        if (ItemRowObj.cells(1).childNodes.length > 0) {
                            ItemRowObj.cells(1).childNodes(0).style.display = 'none';
                        }
                        if (ItemRowObj.cells(2).childNodes.length > 1) {
                            ItemRowObj.cells(2).childNodes(0).style.display = 'none';
                            ItemRowObj.cells(2).childNodes(1).style.display = 'none';
                        }
                        ItemRowObj.cells(3).childNodes(0).style.display = 'none';
                        if (ItemRowObj.cells(4).childNodes.length >1) {
                            ItemRowObj.cells(4).childNodes(0).style.display = 'none';
                            ItemRowObj.cells(4).childNodes(1).style.display = 'none';
                        }
                        ItemRowObj.style.display = 'none';
                    }
                }
            }
            ItemRowObj = null;
        }
        len = null;

        if (obj.actionType == "unexpend") {
            /*展开*/
            rowObj.expended = true;
            obj.actionType = "expend";
            obj.alt = "点击所有收起下级";
            obj.src = '../../AppFrame/APICss/default/images/tree/elbow-end-minus-nl.gif';
        }
        else {
            /*收起*/
            rowObj.expended = false;
            obj.actionType = "unexpend";
            obj.alt = "点击所有展开下级";
            obj.src = '../../AppFrame/APICss/default/images/tree/elbow-plus-nl.gif';
        }
    }
    catch (e) {
        alert(e.message);
    }
    rowObj = null;
    CollectGarbage();
};
window.onload = function() {
    App.SetNullHref(0);
    jsConditionSetting.PageLoad();
    jsConditionSetting.settingTableContent();
    jsConditionSetting.settingInSelect();
};

jsConditionSetting.loadProcess = function() {
//jsConditionSetting.loadProcess = function(processName, dataViewId) {
    try {
        //        var sqlTxt = "exec eOA_Sys_Select 'eOA_cmbDataSource','SQLContent,SqlType,ProcessParam','AND ID=" + dataViewId + "'";
        var sqlTxt = "";
        //        if (jsConditionSetting.sqlType == null) { sqlTxt = "exec eOA_Sys_Select 'eOA_cmbDataSource','SQLContent,SqlType,ProcessParam','AND ID=" + dataViewId + "'"; } else { sqlTxt = "exec eOA_Sys_Select 'eOA_cmbDataSource','SQLContent,SqlType,ProcessParam','AND ID=32'"; }
        if (jsConditionSetting.sqlType == null) { sqlTxt = "exec eOA_CMB_GetDataSoureParameter 29"; } else { sqlTxt = "exec eOA_CMB_GetDataSoureParameter 32"; }

        var obj = DBReader.selectSql(sqlTxt);
        if (DBReader.DObjectIsNull(obj) == false) {
            if (obj.Fields.count == 2) {
                jsConditionSetting.sqlContent = unescape(obj.Fields("SQLContent").Value);
                jsConditionSetting.sqlType = unescape(obj.Fields("SqlType").Value);
            } else {
                jsConditionSetting.sqlType = 'process';
                jsConditionSetting.sqlContent = null;
                var params = [];
                var rowCount = parseInt(obj.RecordCount);
                if (typeof (rowCount) == "number" && rowCount > 0) {
                    obj.MoveFirst();
                    var i = rowCount - 1;
                    params.push("[");
                    for (i; i >= 0; i--) {
                        if (params.length > 1) {
                            params.push(',{"ID":' + obj.Fields("ID").Value + ',"Title":"' + obj.Fields("Title").Value + '","Parameter":"' + obj.Fields("Parameter").Value + '","Defaults":"' + obj.Fields("Defaults").Value + '","IsQuery":' + obj.Fields("IsQuery").Value + ',"IsPageIndex":' + obj.Fields("IsPageIndex").Value + ',"IsPageSize":' + obj.Fields("IsPageSize").Value + ',"IsOrder":' + obj.Fields("IsOrder").Value + '}');
                        } else {
                            params.push('{"ID":' + obj.Fields("ID").Value + ',"Title":"' + obj.Fields("Title").Value + '","Parameter":"' + obj.Fields("Parameter").Value + '","Defaults":"' + obj.Fields("Defaults").Value + '","IsQuery":' + obj.Fields("IsQuery").Value + ',"IsPageIndex":' + obj.Fields("IsPageIndex").Value + ',"IsPageSize":' + obj.Fields("IsPageSize").Value + ',"IsOrder":' + obj.Fields("IsOrder").Value + '}');
                        }
                        obj.MoveNext();
                    }
                    i = null;
                    params.push("]");
                    params = params.join("");
                    jsConditionSetting.processParam = $.parseJSON(params);
                    params = null;
                }
                //                jsConditionSetting.processParam = unescape(obj.Fields("ProcessParam").Value);

            }
        }
        var selQuery = $(".selQueryField");
        var _length = selQuery.length - 1;
        for (_length; _length >= 0; _length--) {
            var sel = selQuery[_length];
            var i = sel.options.length - 1;
            for (i; i > 0; i--) {
                sel[i] = null;
            }
        }
        _length = selQuery.length - 1;
        if (_length > -1) {/*防止没有分组时加载数据*/
            jsConditionSetting.addRowSelect();
        }
        DBReader.Dispose(obj);
    }
    catch (e) {
        alert("Error for jsConditionSetting.loadProcess" + e.message);
    }
    CollectGarbage();
}

/*过程类型时下拉框的唯一数据*/
jsConditionSetting.changRowSelect = function() {
    try {
        var selQuery = $(".selQueryField");
        var _length = selQuery.length - 1;
        var processParam = jsConditionSetting.processParam;
        var selectArray = [];
        for (_length; _length >= 0; _length--) {
            if (selQuery[_length].value != "") {
                selectArray.push(selQuery[_length].value);
            }
        }
        var arrayLength = selectArray.length - 1;
        if (arrayLength > -1) {
            _length = selQuery.length - 1;
            for (_length; _length >= 0; _length--) {
                var selectValue = selQuery[_length].value;
                selQuery[_length].options.length = 1;
                arrayLength = selectArray.length - 1;
                if (processParam != null) {
                    for (var i = 0; i < processParam.length; i++) {
                        if (processParam[i].IsQuery) {
                            var newItem = new Option(processParam[i].Title, processParam[i].Parameter);
                            newItem.className = processParam[i].Defaults;
                            selQuery[_length].options.add(newItem);
                            newItem = null;
                        }
                    }
                }
                for (arrayLength; arrayLength >= 0; arrayLength--) {
                    var optLength = selQuery[_length].options.length - 1;
                    var opt = selQuery[_length].options;
                    for (optLength; optLength >= 0; optLength--) {
                        if ((opt[optLength].value == selectArray[arrayLength]) && (selectValue != opt[optLength].value)) {
                            opt.remove(opt[optLength].index);
                        }
                    }
                }
                var opt = selQuery[_length].options;
                if (opt != null) {
                    var optLength = opt.length - 1;
                    if (selectValue != "") {
                        for (optLength; optLength >= 0; optLength--) {
                            if (selectValue == opt[optLength].value || selectValue == opt[optLength].innerText) {
                                selQuery[_length].options[optLength].selected = true;
                                var rowObj = selQuery[_length].parentElement.parentElement;
                                if ($.trim(rowObj.childNodes[4].childNodes[1].value) == "" && rowObj.childNodes[4].childNodes[1].tagName == "INPUT") {
                                    rowObj.childNodes[4].childNodes[1].value = opt[optLength].className;
                                }
                                break;
                            }
                        }
                    }
                }
                selQuery[_length].onchange = jsConditionSetting.changRowSelect;
                optLength = null;
                opt = null;
            }
        }
    } catch (e) {
        alert("Error for jsConditionSetting.changRowSelect " + e.message);
    }
}

/*绑定表字段在下拉框*/
jsConditionSetting.FieldString = function(id) {
    //    var tableNameList = ["T_EMPLOYEE", "T_COMPANY"];/*源数组用来存储表名*/
    //    var selectData = "<span>查询字段：</span><select select style='width:60%' id='sel" + id + "'  class='selQueryField'>";
    //    if (tableNameList.length > 0) {
    //        for (var j = 0; j < tableNameList.length; j++) {
    //            var strJson = eval("[{" + DBReader.selectSqlForJson("select * from " + tableNameList[0] + " where 1=2") + "}]"); /*获取表字段生成数组*/
    //            var arrayList = strJson[0].col.length;
    //            if (arrayList > 0) {
    //                selectData += "<OPTGROUP LABEL='" + tableNameList[j] + "' style='background-color:#c8d9f6;'>";
    //                for (var i = 0; i < arrayList; i++) {
    //                    selectData += "<OPTION value='" + strJson[0].col[i].FieldName + "'style='background-color:white;'>" + strJson[0].col[i].FieldName + "</OPTION>";
    //                }
    //                selectData += "</OPTGROUP>";
    //            }
    //            arrayList = null;
    //            strJson = null;
    //        }
    //    }
    //    selectData += "</select>";

    var selectData = "<span>查询字段：</span><select select style='width:60%' id='sel" + id + "'  class='selQueryField' >" + jsConditionSetting.gettingTableData(); +"</select>";
    tableNameList = null;
    selectDom = null;
    CollectGarbage();
    return selectData;
};

/*获取表数据*/
jsConditionSetting.gettingTableData = function() {
    /*源数组用来存储表名*/
    var tableNameList = [{ GroupName: "T_EMPLOYEE", GruopText: "个人资料", jsName: "jsPersonalInformation" }, { GroupName: "T_COMPANY", GruopText: "单位资料", jsName: "jsDepartmentInformation"}];
    var selectData = "";
    if (tableNameList.length > 0) {
        for (var j = 0; j < tableNameList.length; j++) {
            if (!(document.getElementById(tableNameList[j].jsName))) {
                var inputJs = document.createElement("script");
                var _head = document.getElementsByTagName("head");
                inputJs.src = "../js/" + tableNameList[j].jsName + ".js";
                inputJs.type = "text/javascript";
                inputJs.id = tableNameList[j].jsName;
                _head[0].appendChild(inputJs);
                inputJs = null;
                _head = null;
            }
            selectData += "<OPTGROUP LABEL='" + tableNameList[j].GruopText + "' style='background-color:#c8d9f6;'>";
            if (tableNameList[j].GroupName == "T_COMPANY") {
                selectData += "<option value='T_COMPANY.SIMPLE_NAME' style='background-color:white;' content='%3CINPUT%20class%3Dipt%20Field%3D%22SIMPLE_NAME%22%20format%3D%22varchar%2850%29%22%3E' process=''>单位名称</option>";
            }
            var arrayList = $.parseJSON(unescape(eval(tableNameList[j].jsName + ".dataJSON")));
            for (var i = 0; i < arrayList.length; i++) {
                for (var p = 0; p < arrayList[i].length; p++) {
                    if (arrayList[i][p].IsOrNotSel == "true") {
                        selectData += "<OPTION value='" + (arrayList[i][p].Field == "null" ? arrayList[i][p].Field : (tableNameList[j].GroupName + "." + arrayList[i][p].Field)) + "'style='background-color:white;' content='" + arrayList[i][p].content + "' process='" + (arrayList[i][p].process == undefined ? "" : arrayList[i][p].process) + "'>" + arrayList[i][p].title + "</OPTION>";
                    }
                }
            }
            arrayList = null;
            selectData += "<OPTGROUP LABEL='" + tableNameList[j].GruopText.substring(0, 2) + "往来记录' style='background-color:#c8d9f6;'><option value='" + tableNameList[j].GroupName + "|T_OTHERINFO.Title' style='background-color:white;' content='%3CINPUT%20class%3Dipt%20Field%3D%22Title%22%20format%3D%22varchar%2850%29%22%3E' process=''>" + tableNameList[j].GruopText + "往来记录：标题</option><option value='" + tableNameList[j].GroupName + "|T_OTHERINFO.Content' style='background-color:white;' content='%3CINPUT%20class%3Dipt%20Field%3D%22Content%22%20format%3D%22varchar%2850%29%22%3E' process=''>" + tableNameList[j].GruopText + "往来记录：内容</option></OPTGROUP>";
        }
        //        selectData += "<OPTGROUP LABEL='" + tableNameList[j].GruopText + "其他资料' style='background-color:#c8d9f6;'><option value='" + tableNameList[j].GroupName + "|T_OTHERINFO.Title' style='background-color:white;' content='%3CINPUT%20class%3Dipt%20Field%3D%22Title%22%20format%3D%22varchar%2850%29%22%3E' process=''>" + tableNameList[j].GruopText + "标题</option><option value='" + tableNameList[j].GroupName + "|T_OTHERINFO.Content' style='background-color:white;' content='%3CINPUT%20class%3Dipt%20Field%3D%22Content%22%20format%3D%22varchar%2850%29%22%3E' process=''>" + tableNameList[j].GruopText + "备注</option></OPTGROUP>"
    }
    return selectData;
}


/*下拉框重新放值*/
jsConditionSetting.settingInSelect = function() {
    var selectTab = $(".selQueryField");
    var conditionTab = $(".selLinkString");
    for (var i = 0; i < selectTab.length; i++) {
        var _val = selectTab[i].value;
        var method = selectTab[i].Method;
        var _id = selectTab[i].id;
        var parentDom = selectTab[i].parentElement;
        parentDom.innerHTML = "<span>查询字段：</span><select select style='width:60%' id='" + _id + "' Method = '" + method + "'  class='selQueryField' >" + jsConditionSetting.gettingTableData() + "</select>";
        parentDom.childNodes[1].value = _val;
        var arr = new Array();
        arr.push("parentDom.childNodes[1].onchange");
        arr.push(unescape(method));
        eval(arr.join(''));
        arr.length = 0;
        method = null;
        arr = null;
        _val = null;
    }
    for (var j = 0; j < conditionTab.length; j++) {
        var method = conditionTab[j].Method;
        var arr = new Array();
        arr.push("conditionTab[j].onchange");
        arr.push(unescape(method));
        eval(arr.join(''));
        arr.length = 0;
        method = null;
        arr = null;
        _val = null;
    }
}

/*读取查询条件*/
jsConditionSetting.getQueryString = function() {
    try {
        /*从上往下读取条件*/
        var arrQuery = new Array();
        /*最后一次记录组路径*/
        var LastGroupPath = "";
        /*当前记录的组路径*/
        var CurrentPath = "";
        /*上一级级别号*/
        var lastLevel = -1;
        /*当前级别号*/
        var currentLevel = -1;

        /*去掉标题和工具，所以从2开始*/
        for (var i = 2; i < document.getElementById("tdContent").rows.length; i++) {
            var rowObj = document.getElementById("tdContent").rows(i);
            if (rowObj != null) {
                if (rowObj.id.indexOf("Group") != -1 && rowObj.id.indexOf("ItemGroup") == -1) {
                    /*组*/
                    LastGroupPath = rowObj.Path;

                    lastLevel = currentLevel;
                    currentLevel = rowObj.Level;

                    /*计算当前级别号号和刚才记录的级别号进行对比，如果级别发生改变就说明组合发生改变
                    然后计算之间的差值，填补欠缺的结束括号
                    */
                    if (lastLevel > currentLevel) {
                        /*根据路径获取节点深度*/
                        for (var n = 0; n < lastLevel - currentLevel; n++) {
                            arrQuery.push(")");
                        }
                    }
                    else if (lastLevel > 0 && currentLevel > lastLevel) {
                        for (var n = 0; n <= currentLevel - lastLevel; n++) {
                            arrQuery.push(")");
                        }
                    }
                    else if (lastLevel > 0 && lastLevel == currentLevel) {
                        arrQuery.push(")");
                    }
                    if (rowObj.GroupIndex > 0) {
                        arrQuery.push(")");
                    }
                    lastLevel = -1;
                    if (rowObj.cells(0).childNodes.length > 0) {
                        /*接上连接本组的关系*/
                        arrQuery.push(" ");
                        arrQuery.push(rowObj.cells(0).childNodes[0].value);
                        arrQuery.push(" ");
                    }
                    arrQuery.push("(");
                }
                else if (rowObj.id.indexOf("ItemGroup") != -1) {
                    /*分组*/
                    CurrentPath = rowObj.Path;
                    lastLevel = currentLevel;
                    currentLevel = rowObj.Level;

                    /*计算当前级别号号和刚才记录的级别号进行对比，如果级别发生改变就说明组合发生改变
                    然后计算之间的差值，填补欠缺的结束括号
                    */
                    if (lastLevel > currentLevel) {
                        /*根据路径获取节点深度*/
                        for (var n = 0; n <= lastLevel - currentLevel; n++) {
                            arrQuery.push(")");
                        }
                    }
                    else if (lastLevel > 0 && lastLevel == currentLevel) {
                        arrQuery.push(")");
                    }
                    if (rowObj.cells(0).childNodes.length > 0) {
                        /*接上连接本组的关系*/
                        arrQuery.push(" ");
                        arrQuery.push(rowObj.cells(0).childNodes[0].value);
                        arrQuery.push(" ");
                    }
                    arrQuery.push("(");

                }
                else if (rowObj.id.indexOf("ItemCondition") != -1) {
                    /*当前行是条件*/
                    if (rowObj.cells(1).childNodes.length > 0) {
                        /*如果不是第一个条件那么就需要加上关系*/
                        arrQuery.push(rowObj.cells(1).childNodes[0].value);
                    }
                    /*查询字段*/
                    arrQuery.push(" (");
                    var tableNameItem = rowObj.cells(2).childNodes[1].value.split("|");
                    if (rowObj.cells[2].children[1].value.indexOf("T_OTHERINFO") == -1) {
                        arrQuery.push(rowObj.cells(2).childNodes[1].value);
                    }
                    /*比较关系*/
                    if (rowObj.cells[4].children[1].className != "Wdate" && rowObj.cells(4).childNodes[1].value != undefined) {
                        if (rowObj.cells[2].children[1].value.indexOf("T_OTHERINFO") != -1) {
                            if (tableNameItem[0] == "T_EMPLOYEE") {
                                arrQuery.push("T_EMPLOYEE.EMPLOYEE_ID in (select EMPLOYEE_ID from T_OTHERINFO where ");
                            } else if (tableNameItem[0] == "T_COMPANY") {
                                arrQuery.push("T_COMPANY.COMPANY_ID in (select COMPANY_ID from T_OTHERINFO where ");
                            }
                            arrQuery.push(tableNameItem[1]);
                            arrQuery.push(" ");
                            arrQuery.push(rowObj.cells(3).childNodes[0].value);
                        } else {
                            arrQuery.push(" ");
                            arrQuery.push(rowObj.cells(3).childNodes[0].value);
                        }
                    }
                    /*比较值*/
                    arrQuery.push(" ");
                    if (rowObj.cells(3).childNodes[0].value == "like" && rowObj.cells[4].children[1].className != "Wdate" && rowObj.cells(4).childNodes[1].value != undefined) {/*含有*/
                        var field = rowObj.cells[2].childNodes[1].value;
                        if (field != "null") {
                            field = field.substring(field.indexOf(".") + 1, field.length);
                        }
                        //if ((rowObj.cells(4).childNodes[1].tagName == "INPUT" || rowObj.cells(4).childNodes[1].tagName == "TEXTAERA") && field == "REMARK")
                        var tempObj = document.createElement(unescape(rowObj.cells(2).childNodes[1].options[rowObj.cells(2).childNodes[1].selectedIndex].content));
                        if (tempObj.tagName == "TEXTAREA") {
                            arrQuery.push("'%" + escape(rowObj.cells(4).childNodes[1].value) + "%' OR " + rowObj.cells(2).childNodes[1].value + " LIKE '%" + rowObj.cells(4).childNodes[1].value + "%'");
                        }
                        else {
                            if (rowObj.cells[2].children[1].value.indexOf("T_OTHERINFO") != -1) {
                                arrQuery.push("'%" + rowObj.cells(4).childNodes[1].value + "%' )");

                            } else {
                                arrQuery.push("'%" + rowObj.cells(4).childNodes[1].value + "%'");
                            }
                        }
                        tempObj.outerHTML = "";
                        tempObj = null;

                    } else if (rowObj.cells[4].children[1].className == "Wdate" && rowObj.cells(4).childNodes[1].value != undefined) {/*查询时间*/
                        arrQuery.push(" = #" + rowObj.cells(4).childNodes[1].value + "#");
                    } else if (rowObj.cells(4).childNodes[1].value == undefined && rowObj.cells[4].childNodes[1].className == "tbTime") {
                        var dateString = "";
                        if (rowObj.cells[4].children[1].children[0].children[0].children[0].children[0].value != "") {
                            dateString = ">= #" + rowObj.cells[4].children[1].children[0].children[0].children[0].children[0].value + "# ";
                        }
                        if (rowObj.cells[4].children[1].children[0].children[1].children[0].children[0].value != "") {
                            if (dateString.length > 0) {
                                dateString += "and " + rowObj.cells(2).childNodes[1].value + " <= #" + rowObj.cells[4].children[1].children[0].children[1].children[0].children[0].value + "# ";
                            } else {
                                dateString = " <= #" + rowObj.cells[4].children[1].children[0].children[1].children[0].children[0].value + "# ";
                            }
                        }
                        if (dateString.length == 0) {
                            dateString = " = ##";
                        }
                        arrQuery.push(dateString);
                        dateString = null;
                    } else if (rowObj.cells(4).childNodes[0].process != undefined && rowObj.cells(4).childNodes[0].type != "select") {
                        var arrDom = rowObj.cells(4).getElementsByTagName("INPUT");
                        for (var j = 0; j < arrDom.length; j++) {
                            if (arrDom[j].checked) {
                                if (rowObj.cells(3).childNodes[0].value == "like") {
                                    arrQuery.push(rowObj.cells[4].childNodes[1].Field + " " + rowObj.cells(3).childNodes[0].value + " '%" + arrDom[j].value + "%'");
                                } else {
                                    arrQuery.push(rowObj.cells[4].childNodes[1].Field + " " + rowObj.cells(3).childNodes[0].value + " '" + arrDom[j].value + "'");
                                }
                                break;
                            }
                        }
                        arrDom.length = 0;
                        arrDom = null;
                    } else if (rowObj.cells(4).children[1] != null && rowObj.cells(4).children[1].format == "datetime") {
                        var dateType = rowObj.cells(4).children[1].datetype;
                        var dateDiv = rowObj.cells(4).children[1];
                        var strDate = "";
                        if (rowObj.cells(3).children[0].value == "like") {
                            strDate = "%";
                        } else {
                            strDate = rowObj.cells(3).children[0].value;
                        }
                        switch (dateType) {
                            case "yyyy-MM":
                                {
                                    strDate += " #";
                                    for (var j = 0; j < dateDiv.children.length; j++) {
                                        if (strDate.length > 4) {
                                            strDate += (" - " + (dateDiv.children[j].value == "" ? "01" : dateDiv.children[j].value));
                                        } else {
                                            strDate += (dateDiv.children[j].value == "" ? "2000" : dateDiv.children[j].value);
                                        }
                                    }
                                    strDate += "#";
                                    //                                    arrQuery.push(strDate);
                                } break;
                            case "MM-dd":
                                {
                                    strDate += " #";
                                    for (var j = 0; j < dateDiv.children.length; j++) {
                                        if (strDate.length > 4) {
                                            strDate += " - ";
                                        }
                                        strDate += (dateDiv.children[j].value == "" ? "01" : dateDiv.children[j].value);
                                    }
                                    strDate += "#";
                                    //                                    arrQuery.push(strDate);
                                } break;
                            //                            case "MM-dd":                                             
                            //                                {                                             

                            //                                } break;                                           
                            case "hh:mm":
                            case "hh:mm:ss":
                                {
                                    strDate += " #";
                                    for (var j = 0; j < dateDiv.children.length; j++) {
                                        if (strDate.length > 3) {
                                            strDate += " : ";
                                        }
                                        strDate += (dateDiv.children[j].value == "" ? "00" : dateDiv.children[j].value);
                                    }
                                    strDate += "#";
                                    //                                    arrQuery.push(strDate);
                                } break;
                            case "dd hh:mm:ss":
                                {
                                    strDate += " #";
                                    for (var j = 0; j < dateDiv.children.length; j++) {
                                        if (j == 0) {
                                            strDate += "";
                                        } else if (j == 1) {
                                            strDate += " ";
                                        } else {
                                            strDate += ":";
                                        }
                                        if (j > 0) {
                                            strDate += (dateDiv.children[j].value == "" ? "00" : dateDiv.children[j].value);
                                        } else {
                                            strDate += (dateDiv.children[j].value == "" ? "01" : dateDiv.children[j].value);
                                        }
                                    }
                                    strDate += "#";
                                    //                                    arrQuery.push(strDate);
                                } break;
                            //                            case "hh:mm:ss":                                           
                            //                                {                                           
                            //                                                                               
                            //                                } break;                                           
                            //                            case "hh":                                           
                            //                                {                                           

                            //                                } break;                                           
                            //                            case "mm":                                           
                            //                                {                                           

                            //                                } break;                                           
                            //                            case "dd":                                           
                            //                                {                                           

                            //                                } break;                                       
                        }
                        if (rowObj.cells(3).childNodes[0].value == "like") {
                            strDate += "%";
                        }
                        arrQuery.push(strDate);
                        strDate = null;
                    } else {
                        arrQuery.push("'" + rowObj.cells(4).childNodes[1].value + "'");
                    }
                    if (rowObj.cells[2].children[1].value.indexOf("T_OTHERINFO") != -1 && rowObj.cells(3).childNodes[0].value != "like") {
                        arrQuery.push(") ");
                    }
                    arrQuery.push(") ");
                }
            }
            rowObj = null;
        }

        if (CurrentPath.substring(0, LastGroupPath.length) == LastGroupPath) {
            /*如果当前路径和刚才记录路径相同，那说明是在同一组，所以只需要按照级别号补充结束括号*/
            for (var n = 0; n <= currentLevel; n++) {
                arrQuery.push(")");
            }
        }
        else {
            /*计算当前级别号号和刚才记录的级别号进行对比，如果级别发生改变就说明组合发生改变
            然后计算之间的差值，填补欠缺的结束括号
            */
            if (lastLevel > currentLevel) {
                /*根据路径获取节点深度*/
                for (var n = 0; n < lastLevel - currentLevel; n++) {
                    arrQuery.push(")");
                }
            }
            else if (lastLevel > 0 && currentLevel > lastLevel) {
                for (var n = 0; n <= currentLevel - lastLevel; n++) {
                    arrQuery.push(")");
                }
            }
            else if (lastLevel > 0 && lastLevel == currentLevel) {
                arrQuery.push(")");
            }
            arrQuery.push(")");
        }
        //        document.getElementById("txtSqlCode").value = arrQuery.join('');
        if (arrQuery.length > 2) {
            if (App.query("action") != undefined) {
                if (App.query("jsPath") == "" || App.query("jsPath") == null) {
                    ShowWindow.opener.execScript(App.query("formIdx"), App.query("action").replace("@str", escape(arrQuery.join(''))));
                    jsConditionSetting.savePagePath(escape(arrQuery.join('')));
                } else {
                    var jsconten = escape(jsConditionSetting.savePagePath(escape(arrQuery.join(''))));
                    var tableHTML = escape(document.getElementById("div-main-container").innerHTML);
                    ShowWindow.opener.execScript(App.query("formIdx"), App.query("action").replace("@str", escape(arrQuery.join(''))).replace("@str1", jsconten).replace("@str2", tableHTML));
                    jsconten = null;
                    tableHTML = null;
                }
            }
        } else {
            alert("查询条件为空！");
        }
        CurrentPath = null;
        LastGroupPath = null;
        CollectGarbage();
        if (arrQuery.length > 2) {
            arrQuery.length = 0;
            arrQuery = null;
            ShowWindow.close();
        }
    }
    catch (e) {
        alert("jsConditionSetting.getQueryString:" + e.message);
    }
    CollectGarbage();
};
/*保存表数据*/
jsConditionSetting.savePagePath = function(str) {
    try {
        var jsFile = [];
        var tableHTML = document.getElementById("div-main-container").innerHTML;
        var id = "jsAdvancedQuery";
        if (App.query("jsPath") != "" && App.query("jsPath") != null) {
            id = App.query("jsPath");
        }
        jsFile.push("function " + id + "()");
        jsFile.push("{};");
        jsFile.push(id + ".tableContent =");
        jsFile.push("'" + escape(tableHTML) + "';");
        jsFile.push(id + ".searchContent =");
        jsFile.push("'" + str + "';");
        var jsSource = jsFile.join("");
        var a = App.query("jsPath");
        if (App.query("jsPath") == "" || App.query("jsPath") == null) {/*在主页面保存不在这里保存*/
            if (App.FileIsExist(escape(App.ApplicationPath()+"Application\\TeleSecretary\\js\\"+id+".js"))) {
                App.FileDelete("Application/TeleSecretary/js/" + id + ".js");   /*删除原有的本地文件*/
            }
            App.CreateFile("Application/TeleSecretary/js/", id + ".js", jsSource); /*创建JS文件*/
        }
        jsFile, tableHTML, JSFileInfoObj = null;
    } catch (e) {
        alert("保存失败！" + e.message);
    }
    CollectGarbage();
    if (App.query("jsPath") != "" && App.query("jsPath") != null) {
        return jsSource;
    }
}

/*加载表数据*/
jsConditionSetting.settingTableContent = function() {
    var inputJs = document.createElement("script");
    var _head = document.getElementsByTagName("head");
    var tbContent = document.getElementById("div-main-container");
    try {
        var id = "jsAdvancedQuery";
        var searchSource = null;
        if (App.query("insertSource") != "" && App.query("insertSource") != null) {
            searchSource = unescape(eval(unescape(App.query("insertSource"))).searchTable);
        }
        if (searchSource != "" && searchSource != null && searchSource != "undefined") {
            tbContent.innerHTML = searchSource;
        } else {
            if (App.query("jsPath") != "" && App.query("jsPath") != null) {
                id = App.query("jsPath");
            }
            if (!(document.getElementById(id))) {
                if (App.FileIsExist(escape(App.ApplicationPath()+"Application\\TeleSecretary\\js\\"+id+".js"))) {
                    inputJs.src = "../js/" + id + ".js";
                    inputJs.type = "text/javascript";
                    inputJs.id = id;
                    _head[0].appendChild(inputJs);
                    var tbSource = unescape(eval(id + ".tableContent"));
                    if (tbSource != "") {
                        tbContent.innerHTML = tbSource;
                    }
                }
            }
        }
    } catch (e) {
        alert("ERROR FOR jsSystemSettings.settingTableContent" + e.message);
    }
}