function jsBookListModle(){

};
jsBookListModle.AddressBookGrid=null;  /*通讯簿列表模式中的列表*/
jsBookListModle.CurSeletedBookListGridRow=null;/*主列表选中的行*/
jsBookListModle.IsHaveColSetFile=null;/*是否有列设置文件*/
jsBookListModle.CurEmpGridAllCount=0;/*当前联系人列表中的记录总数*/
jsBookListModle.GridStrWhere=null;/*当前列表查询条件*/
/*加载页面内容*/
jsBookListModle.LoadListModleDom=function(){
        var arrString=new  Array();
        /*<!--通讯簿列表操作按钮-->*/
        arrString.push('<div id="custom-toolbar">');
        arrString.push("</div>");
        /*<!--通讯簿列表-->*/
        arrString.push('<div id="divAdrressBook"><table id="tbAdrressBook">');
        arrString.push("</table></div>");
        document.getElementById("callListModle").innerHTML=arrString.join("");
        
        jsBookListModle.LoadColSetJsFile();/*加载列设置内容*/
        jsBookListModle.LoadToolBarBtn();/*通讯簿操作按钮*/
        jsBookListModle.LoadCallBookGrid();/*通讯簿主列表*/

        /*注册响铃动作，让响铃的时候获取到来电号码，然后查询出对应的资料*/
        var ringActionString="jsIndexPage.freshItemPage('tab-addressBook','jsBookListModle.getRingNumberInfor(\\\"@number\\\")')";
        window.parent.execScript("jsTitle.regPhoneRingAction(\""+ringActionString+"\");");
        ringActionString=null;   
          
        /*注册去电动作，让去电的时候获取到拨打号码，然后查询出对应的资料*/
        var actionString="jsIndexPage.freshItemPage('tab-addressBook','jsBookListModle.getRingNumberInfor(\\\"@number\\\")')";
        window.parent.execScript("jsTitle.regPhoneGoDialAction(\""+actionString+"\");");
        actionString=null;  
        
      
};

/*加载列设置结果*/
jsBookListModle.LoadColSetJsFile = function() {
    if (App.FileIsExist(escape(App.ApplicationPath()+"Application\\TeleSecretary\\js\\jsColSetFile.js"))) {
        App.SetNullHref(0);
        if (document.getElementById("js_ColSetFile")) {
            var obj = document.getElementById("js_ColSetFile").parentElement;
            obj.removeChild(document.getElementById("js_ColSetFile"));
            var scriptObj = document.createElement("script");
            scriptObj.src = "js/jsColSetFile.js";
            scriptObj.id = "js_ColSetFile";
            obj.appendChild(scriptObj);
            jsBookListModle.IsHaveColSetFile = 1;
        } else {
            var obj = document.getElementsByTagName("HEAD");
            var scriptObj = document.createElement("script");
            scriptObj.src = "js/jsColSetFile.js";
            scriptObj.id = "js_ColSetFile";
            obj[0].appendChild(scriptObj);
            jsBookListModle.IsHaveColSetFile = 1;
        }
        scriptObj = null;
        obj = null;
        App.SetNullHref(1);
    }

};
/*通讯簿操作按钮*/
jsBookListModle.LoadToolBarBtn = function() {
    customOption = { items: [
        { type: 'button', text: '新建档案', useable: 'T', className: 'tableAdd', handler: function() {
            jsBookListModle.CurSeletedBookListGridRow=null;
            jsBookCardModle.ChangeToAddInfo();
            jsCallBookList.IsListOrCardModle('List');
        } 
        },
        { type: 'button', text: '修改', useable: 'T', className: 'tableEdit', handler: function() {
            jsBookListModle.ChangeListOrCardModle();
        } 
        },
        { type: 'button', text: '删除选中', useable: 'T', className: 'tableClose', handler: function() {
            if (jsBookListModle.AddressBookGrid.getSelectedRows().length > 0) {
                if (confirm("确定要删除吗？")) {
                    $(jsBookListModle.AddressBookGrid.getSelectedRows()).each(function() {
                          jsBookListModle.DeleteAllSelData($(this).attr("EMPLOYEE_ID"), $(this).attr("COMPANY_ID")); /*删除选择的*/
                    });
                   jsBookListModle.AddressBookGrid.flexReload();
                }
            }
            else {
                alert("请选择要删除的行！");
            }
        }},
       { type: 'button', text: '更改分组', useable: 'T', className: 'tableEdit',handler:  function(){
             if (jsBookListModle.AddressBookGrid.getSelectedRows().length > 0) {
                 var FormIndex=ShowWindow.getFormIdx();
                 ShowWindow.ShowMoledDialog("Application/TeleSecretary/frmCommunication/frmGroupTree.htm?FormIndex="+FormIndex+"&LoadAction=jsIndexPage.freshItemPage(\"tab-addressBook\",\"jsBookListModle.EditCurGroupID(@str)\")","更改分组",260,500);  
             }else{
                alert("请先选择要更改分组的联系人！");
             }
        }},   
        { type: 'separate' },
        { type: 'button', text: '列设置', useable: 'T', className: 'tableSet', handler: function() { jsBookListModle.OpenColSetWindow(); } },
        { type: 'separate' }, 
        { type: 'button', text: '导入', useable: 'T', className: 'tableSave',handler: function() {
               var groupID =0; 
               var groupText="";
               if(jsCommunicationQueryCondition.curSelNode!=null){
                    if(jsCommunicationQueryCondition.curSelNode.id>0){
                        groupID=jsCommunicationQueryCondition.curSelNode.id;
                        groupText=jsCommunicationQueryCondition.curSelNode.text;
                    }
               }
               var FormIndex=ShowWindow.getFormIdx();
               ShowWindow.ShowMoledDialog("Application/TeleSecretary/InportExcel/frmInportExcel.htm?GroupID="+groupID+"&GroupText="+groupText+"&FormIndex="+FormIndex+"&LoadAction=jsIndexPage.freshItemPage(\"tab-addressBook\",\"jsBookListModle.AddressBookGrid.DoSearch()\")","导入数据",400,500);  
               groupID=null;
               groupText=null;
               FormIndex=null;
               CollectGarbage();
         } },    
         { type: 'button', text: '导出', useable: 'T', className: 'tableSet',handler:  function(){
                   jsBookListModle.ExportEmployeeGridInfo();
          }},   
        //        { type: 'button', text: '转到拨号台', useable: 'T', className: 'tableView',handler:  function(){
        //             jsBookListModle.AddToTxtDialTelNo();
        //        }},             
        {type: 'button', text: '档案卡', useable: 'T', className: 'tableView', handler: function() {
            jsBookListModle.CurSeletedBookListGridRow=null;
            jsBookListModle.ChangeListOrCardModle();
            var Sys = {};
            var ua = navigator.userAgent.toLowerCase();
            if (window.ActiveXObject) {
                Sys.ie = ua.match(/msie ([\d.]+)/)[1]
            }
            if (Sys.ie == "6.0") {
                jsCallBookList.ShowOrHideTabPanel(0);
            }
        } 
    }
     ]
};
$("#custom-toolbar").toolbar(customOption);
}

/*更改选中联系人的分组*/
jsBookListModle.EditCurGroupID=function(id,name){
    if(id>0){
        if (jsBookListModle.AddressBookGrid.getSelectedRows().length > 0) {
            var strComIDList="";
            var strEmpIDList="";
            $(jsBookListModle.AddressBookGrid.getSelectedRows()).each(function() {
                var comID=jsCommonLogic.selColumnData("COMPANY_ID","T_EMPLOYEE","WHERE EMPLOYEE_ID="+ $(this).attr("EMPLOYEE_ID"));
                if(comID>0){
                     if (strComIDList != "") {
                        strComIDList += ",";
                    }
                    strComIDList += comID;
                }
                else{
                    if (strEmpIDList != "") {
                        strEmpIDList += ",";
                    }
                    strEmpIDList += $(this).attr("EMPLOYEE_ID");
                }
            });
            /*更改所属公司及其包含的联系人的分组*/
            if(strComIDList!=""){
                var strSql1="UPDATE T_COMPANY SET GROUP_ID="+id+" WHERE COMPANY_ID IN("+strComIDList+")";
                DBReader.execSql(strSql1);
                var strSql2="UPDATE T_EMPLOYEE SET GROUP_ID="+id+" WHERE COMPANY_ID IN("+strComIDList+")";
                DBReader.execSql(strSql2);
            }
            /*没有所属公司的联系人*/
            if(strEmpIDList!=""){
                var strSql="UPDATE T_EMPLOYEE SET GROUP_ID="+id+" WHERE EMPLOYEE_ID IN("+strEmpIDList+")";
                DBReader.execSql(strSql);
            }
            alert("更改分组成功！");
            jsBookListModle.BookListSearchString();
  
            strEmpIDList=null;
            strSql=null;
            CollectGarbage();
        }
    }
};

/*打开列设置窗口*/
jsBookListModle.OpenColSetWindow=function(){
    var FormIndex=ShowWindow.getFormIdx();
    ShowWindow.ShowMoledDialog("Application/TeleSecretary/AddressBookColSet/frmAddressBookColSet.htm?FormIndex="+FormIndex+"&LoadAction=jsIndexPage.freshItemPage('tab-addressBook','jsBookListModle.ShowOrHideGridColumn(\"@hideStr\",\"@showStr\")')","列设置",500,500);
};


jsBookListModle.ShowOrHideGridColumn = function(hideCol, showCol) {
    var tbParent = document.getElementById("divAdrressBook");
    tbParent.innerHTML = "";
    var tabObj = document.createElement("TABLE");
    tabObj.id = "tbAdrressBook";
    tbParent.appendChild(tabObj);
    var objHideColSet = hideCol.split(",");
    for (var i = 0; i < objHideColSet.length; i++) {
        $("#tbAdrressBook").hiddentColumnByName(objHideColSet[i]);
    }
    var objShowColSet = showCol.split(",");
    for (var j = 0; j < objShowColSet.length; j++) {
        $("#tbAdrressBook").showColumnByName(objShowColSet[j]);
    }
    jsBookListModle.LoadColSetJsFile();
    jsBookListModle.AddressBookGrid = null;
    jsBookListModle.LoadCallBookGrid();
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    if (window.ActiveXObject) {
        Sys.ie = ua.match(/msie ([\d.]+)/)[1]
    }
    if (Sys.ie == "6.0") {
        jsCallBookList.ChangeToEmpOrComDivModel(document.getElementById("radCallBookList"));
    }
    jsBookListModle.AddressBookGrid.DoSearch();
    tabObj = null;
    tbParent = null;
    objHideColSet = null;
    objShowColSet = null;
    hideCol = null;
    showCol = null;
    CollectGarbage();
};

/*绑定档案卡模式数据*/
jsBookListModle.ChangeListOrCardModle = function() {
    App.SetNullHref(0);
    var strEmpIDList = "";
    if (jsBookListModle.AddressBookGrid.getSelectedRows().length > 0) {
        $(jsBookListModle.AddressBookGrid.getSelectedRows()).each(function() {
            if (strEmpIDList != "") {
                strEmpIDList += ",";
            }
            strEmpIDList += $(this).attr("EMPLOYEE_ID");
        });
    }
    else {
        if (jsBookListModle.CurSeletedBookListGridRow != null) {
            $(jsBookListModle.CurSeletedBookListGridRow).each(function() {
                if (strEmpIDList != "") {
                    strEmpIDList += ",";
                }
                strEmpIDList += $(this).attr("EMPLOYEE_ID");
            });
        } else {
            var store = jsBookListModle.AddressBookGrid.getRowData();
            for (var i = 0; i < store.length; i++) {
                if (strEmpIDList != "") {
                    strEmpIDList += ",";
                }
                strEmpIDList += store[i].EMPLOYEE_ID;
            }
        }
    }
    jsBookCardModle.curSelectedEmpIDList = escape(strEmpIDList);
    jsBookCardModle.curInfoID = 0; /*重置当前数据集下标*/
    jsBookCardModle.BindData();
    jsCallBookList.IsListOrCardModle('List');
};

/*导出列表中的数据*/
jsBookListModle.ExportEmployeeGridInfo=function(){
    $(document.body).mask("数据导出中,请稍后...");
    var FieldObj=new Object();
    var arrDataName=new Array();
    var arrDataField=new Array();
    var strSelColumn="";
    if(jsBookListModle.IsHaveColSetFile==1){
        var objColSet = eval("[" + jsColSetFile.ColSetString + "]");
        for (var i = 0; i < objColSet.length; i++) {
            if (objColSet[i].IsDisplay.toString() == "1") {
                arrDataName.push(unescape(objColSet[i].Title));
                arrDataField.push(objColSet[i].DataField);
                strSelColumn+=(objColSet[i].TbName+"."+ objColSet[i].DataField+",");
            }
        }     
        strSelColumn=strSelColumn.substring(0,strSelColumn.length-1);   
        objColSet=null;
    }else{
        var strDataName="姓名,性别,单位,地址,手机号码,固话号码";
        var strDataField="NAME,MANORWOMAN,CmpName,ADDRESS,MOBILE,TEL1";
        arrDataName=strDataName.split(",");
        arrDataField=strDataField.split(",");
        strDataName=null;
        strDataField=null;
    }
    FieldObj.Count=arrDataName.length;
    FieldObj.Caption=arrDataName;
    FieldObj.FieldName=arrDataField;
    var strSql="SELECT ";
    if(strSelColumn!=""){
        strSql+=strSelColumn;
    }else{
        strSql+="T_EMPLOYEE.NAME, T_EMPLOYEE.MANORWOMAN,iif(IsNull( T_COMPANY.SIMPLE_NAME ), T_COMPANY.FULL_NAME, T_COMPANY.SIMPLE_NAME ) AS CmpName, T_COMPANY.ADDRESS, T_EMPLOYEE.MOBILE, T_EMPLOYEE.TEL1";
    }
    strSql+=" FROM T_EMPLOYEE LEFT JOIN T_COMPANY ON T_EMPLOYEE.COMPANY_ID=T_COMPANY.COMPANY_ID"+jsBookListModle.GridStrWhere;    
    var obj = DBReader.selectSql(strSql, "T_INFO");
    if(DBReader.DObjectIsNull(obj)==false)
    {
        if(parseInt(obj.RecordCount)>0)
        {
             App.ExportExcel(FieldObj,obj);
        }
        else
        {
            alert("没有要导出的数据！");
        }
    }
    else
    {
        alert("获取数据出错！");
    }
    FieldObj=null;
    arrDataName=null;arrDataField=null;
    strSelColumn=null;
    strSql=null; obj=null;
    CollectGarbage();
   $(document.body).unmask();   
};

/*通讯簿主列表*/
jsBookListModle.LoadCallBookGrid = function() {
    var w = $("#middleContanier").width();
    var gh = $("#middleContanier").height() - 370;
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    if (window.ActiveXObject) {
        Sys.ie = ua.match(/msie ([\d.]+)/)[1]
    }
    if (Sys.ie == "6.0") {
        gh = gh - 100;
    }
    var arrColumn = new Array();
    if (jsBookListModle.IsHaveColSetFile == 1) {
        arrColumn.push("{display: '联系人ID', name: 'EMPLOYEE_ID', width: (w * 0.1), sortable: false, align: 'left',hide:true }");
        arrColumn.push("{ display: '单位ID', name: 'COMPANY_ID', width: (w * 0.15), sortable: false, align: 'left' ,hide:true}");
        var objColSet = eval("[" + jsColSetFile.ColSetString + "]");
        for (var i = 0; i < objColSet.length; i++) {
            if (objColSet[i].DataField == "MOBILE" || objColSet[i].DataField == "S2" || objColSet[i].DataField == "TEL" || objColSet[i].DataField == "TEL1" || objColSet[i].DataField == "TEL2") {
                arrColumn.push("{display: '" + unescape(objColSet[i].Title) + "', name: '" + objColSet[i].DataField + "', width: (w * 0.18),hide:" + (objColSet[i].IsDisplay.toString() == "0" ? "true" : "false") + ", sortable: " + (objColSet[i].IsOrder.toString() == "1" ? "true" : "false") + ", align: 'left',process:jsBookListModle.FormatTELNumbr}");
            }
            else if (objColSet[i].DataField == "REMARK") {
                arrColumn.push("{display: '" + unescape(objColSet[i].Title) + "', name: '" + objColSet[i].DataField + "', width: (w * 0.09),hide:" + (objColSet[i].IsDisplay.toString() == "0" ? "true" : "false") + ", sortable: " + (objColSet[i].IsOrder.toString() == "1" ? "true" : "false") + ", align: 'left',process:jsBookListModle.FormatRemark}");
            }
            else {
                arrColumn.push("{display: '" + unescape(objColSet[i].Title) + "', name: '" + objColSet[i].DataField + "', width: (w * 0.09),hide:" + (objColSet[i].IsDisplay.toString() == "0" ? "true" : "false") + ", sortable: " + (objColSet[i].IsOrder.toString() == "1" ? "true" : "false") + ", align: 'left'}");
            }
        }
    }
    else {
        arrColumn.push("{display: '联系人ID', name: 'EMPLOYEE_ID', width: (w * 0.1), sortable: false, align: 'left',hide:true }");
        arrColumn.push("{display: '姓名', name: 'NAME', width: (w * 0.1), sortable: false, align: 'left' }");
        arrColumn.push("{ display: '性别', name: 'MANORWOMAN', width: (w * 0.03), sortable: false, align: 'left' }");
        arrColumn.push("{ display: '单位ID', name: 'COMPANY_ID', width: (w * 0.15), sortable: false, align: 'left' ,hide:true}");
        arrColumn.push("{ display: '单位', name: 'CmpName', width: (w * 0.15), sortable: false, align: 'left' }");
        arrColumn.push("{ display: '地址', name: 'ADDRESS', width: (w * 0.2), sortable: false, align: 'left' }");
        arrColumn.push("{ display: '手机号码', name: 'MOBILE', width: (w * 0.18), sortable: false, align: 'left',process:jsBookListModle.FormatTELNumbr }");
        arrColumn.push("{ display: '固话号码', name: 'TEL1', width: (w * 0.18), sortable: false, align: 'left',process:jsBookListModle.FormatTELNumbr }");
    }
    var tableGridOption =
    {
        height: gh,
        //        width: w,
        colModel: eval("[" + arrColumn.join(",") + "]"),
        customFunction: jsBookListModle.ShowBookListPage,
        showcheckbox: true,
        selectedonclick: true,
        rowcheckboxselect: false,
        rowbinddata: true,
        sortname: 'EMPLOYEE_ID',
        sortorder: 'asc',
        rowhandler: jsBookListModle.doubleClickToCardModle,
        rp: 20
    };
    jsBookListModle.AddressBookGrid = $("#tbAdrressBook").ikegrid(tableGridOption);
    tableGridOption = null;
};

jsBookListModle.FormatRemark=function(value,pid,rows){
    if(value.toString()!="")
    {
        var strValue=unescape(value.toString()).length>10?unescape(value.toString()).substring(0,10)+"...":unescape(value.toString());
        return '<a href="#" title='+unescape(value.toString())+'>'+strValue+'</a>';
    }
};

/*列表点击事件*/
jsBookListModle.doubleClickToCardModle = function(target) {
    $(target).dblclick(function() {
        $("#tbAdrressBook").mask("数据加载中,请稍后...");
        jsBookListModle.CurSeletedBookListGridRow = $(target);
        jsBookListModle.ChangeListOrCardModle();
        jsBookListModle.CurSeletedBookListGridRow = null;
        $("#tbAdrressBook").unmask();
    });
    $(target).click(function() {
    
    
        jsBookListModle.CurSeletedBookListGridRow = $(target);
        switch (jsCallMiddlePanel.listNo) {
            case "HistoryRecord":
                jsHistoryRecord.HistoryRecordSearchString();
            break;
            case "OtherInfo":
                jsOtherInfo.OtherInfoSearchString();
            break;
            case "webSearch":
               window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strTelNum=$(target).attr("MOBILE");
               window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strComName=$(target).attr("NAME");
               window.frames["tab_item_frame_tab-webSearch"].document.getElementById("fontPhone").style.display="";
               window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strPhone=$(target).attr("TEL1");
               window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.searchInfo();
            break;
            default:
            break;
        }
        var obj = event.srcElement;
        if (obj.childNodes[0] != null && (obj.childNodes[0].className != "itemchk" && obj.className != "chboxtd") || obj.tagName == "IMG") {
            /*单选行改行样式*/
            $("tr", target.parentElement.parentElement).each(function() {
                this.childNodes[0].childNodes[0].children[0].checked = false;
                $(this).removeClass("trSelected");
            });
        }
        $(target).addClass("trSelected");
        target.childNodes[0].childNodes[0].children[0].checked = true;
        /*===============*/
    });
}
/*电话号码*/
jsBookListModle.FormatTELNumbr = function(value, pid, rows) {
    if($.trim(value.toString())!="" && value.toString()!="&nbsp;")
    {
        var strContent=value.toString();
        var PhoneTypeName=window.parent.jsTitle.TelephoneTypeName;
        var strShowContent="";
        
        if(PhoneTypeName=="E6" || PhoneTypeName=="E7")
        {
            strShowContent = '<img alt="拨打" src="images/Tel.Gif" onclick="jsBookListModle.PeopleDialImageClick(\'' + value.toString() + '\')" width="13px" height="13px" title="拨打电话"/>';
        }
        strShowContent+='<img alt="添加到拨号台" src="../AppFrame/APICss/default/images/icons/Item.Add.gif" onclick="jsBookListModle.TurnToTxtDialTelNo(\'' + value.toString() + '\',\'' + rows.NICKNAME + '\')" width="13px" height="13px" title="添加到拨号台"/>&nbsp;' + value.toString() + '';
        return strShowContent;
    } else {
    return "&nbsp;";
    }
};

/*添加到拨号台*/
jsBookListModle.TurnToTxtDialTelNo = function(telNum, userName) {
    var strInnerHTML = "";
    var editorbody =window.parent.jsRightMessage.GetTxtWaitCallItem();
    /*创建号码集合载体*/
    var itemList = editorbody.getElementsByTagName("P");
    if (itemList.length == 0 && editorbody.innerText !="") {
        strInnerHTML += "<p>" + editorbody.innerText + "</p>";
    }
    else {
        for (var i = 0; i < itemList.length; i++) {
            if(itemList[i].innerText !=""){
                 strInnerHTML += "<p>" + itemList[i].innerText + "</p>";
            }
        }
    }
    if ($.trim(telNum) != "" && telNum != undefined && strInnerHTML.indexOf(telNum) == -1) {
        if (userName != "" && userName.toString() != "undefined") {
            strInnerHTML += "<p>" + telNum + "|" + userName + "</p>";
        } else {
            strInnerHTML += "<p>" + telNum + "</p>";
        }
        window.parent.jsRightMessage.LoadInfoToTxtWaitCall(strInnerHTML);
        strInnerHTML = null;
        CollectGarbage();
    }
}
/*拨打电话*/
jsBookListModle.PeopleDialImageClick=function(telNum){
  try
    {
        if(window.parent.PhoneHelper.Telphone_IsConnection()){
            /*只有不是在拨打电话的状态下才能促发拨号事件*/
            if(window.parent.jsRightMessage.isPhoning==false)
            {
                window.parent.jsRightMessage.isPhoning=true;
                if(telNum!="")
                {
                    window.parent.execScript("jsTitle.Dial('"+telNum+"');");
                }
                telNum=null;
            }
        }else{
            alert("话机未连接！");
        }
    }
    catch(e)
    {
        alert("jsBookListModle.PeopleDialImageClick:"+e.message);
    }
    CollectGarbage();
};
 
/*通讯簿列表获取数据*/
jsBookListModle.ShowBookListPage = function(pageSize, pageIndex, searchStr, extpara, order) {
    var countTop = pageSize * pageIndex;
    var strSql = "SELECT top " + countTop + " T_EMPLOYEE.EMPLOYEE_ID, T_EMPLOYEE.NAME, T_EMPLOYEE.MANORWOMAN,T_EMPLOYEE.COMPANY_ID, iif(IsNull( T_COMPANY.SIMPLE_NAME ), T_COMPANY.FULL_NAME, T_COMPANY.SIMPLE_NAME ) AS CmpName, T_COMPANY.ADDRESS, T_EMPLOYEE.MOBILE, T_EMPLOYEE.TEL1 FROM T_EMPLOYEE LEFT JOIN T_COMPANY ON T_EMPLOYEE.COMPANY_ID=T_COMPANY.COMPANY_ID";
    var sort = " desc";
    if (order != undefined && order.toUpperCase().indexOf("ASC") != -1) {
        sort = " asc";
    }
    if (jsBookListModle.IsHaveColSetFile == 1) {
        var objColSet = eval("[" + jsColSetFile.ColSetString + "]");
        var strSearchColumn = "";
        for (var i = 0; i < objColSet.length; i++) {
            if (objColSet[i].IsDisplay.toString() == "1") {
                if (strSearchColumn != "") {
                    strSearchColumn += ",";
                }
                strSearchColumn += objColSet[i].TbName + "." + objColSet[i].DataField;
            }
        }
        if (strSearchColumn != "") {
            strSql = "SELECT top " + countTop + " T_EMPLOYEE.EMPLOYEE_ID,T_EMPLOYEE.COMPANY_ID," + strSearchColumn + " FROM T_EMPLOYEE LEFT JOIN T_COMPANY ON T_EMPLOYEE.COMPANY_ID=T_COMPANY.COMPANY_ID";
        }
        objColSet = null;
        strSearchColumn = null;
    }

    var strWhere = " where 1=1 ";
    if (searchStr != "" && searchStr != undefined) {
        if (searchStr[0]._Type == 0) {/*熟悉度查询*/
            if (searchStr[0]._BeginTime != "" || searchStr[0]._EndTime != "") {
                var shortWhere = "select EMPLOYEEID from T_CALLBILL where 1=1 ";
                if (searchStr[0]._BeginTime != "" && searchStr[0]._BeginTime != null) {
                    shortWhere = shortWhere + " and T_CALLBILL.CALLTIME >= " + searchStr[0]._BeginTime;
                }
                if (searchStr[0]._EndTime != "" && searchStr[0]._EndTime != null) {
                    shortWhere = shortWhere + " and T_CALLBILL.CALLTIME <= " + searchStr[0]._EndTime;
                }
                strWhere = strWhere + " and T_EMPLOYEE.EMPLOYEE_ID in (" + shortWhere + ")";
                shortWhere = null;
            }
        }
        else if (searchStr[0]._Type == 1) {/*陌生度查询*/
            if (searchStr[0]._BeginTime != "" || searchStr[0]._EndTime != "") {
                var shortWhere = "select EMPLOYEEID from T_CALLBILL where 1=1 ";
                if (searchStr[0]._BeginTime != "" && searchStr[0]._BeginTime != null) {
                    shortWhere = shortWhere + " and T_CALLBILL.CALLTIME >= " + searchStr[0]._BeginTime;
                }
                if (searchStr[0]._EndTime != "" && searchStr[0]._EndTime != null) {
                    shortWhere = shortWhere + " and T_CALLBILL.CALLTIME <= " + searchStr[0]._EndTime;
                }
                strWhere = strWhere + " and T_EMPLOYEE.EMPLOYEE_ID not in (" + shortWhere + ")";
                shortWhere = null;
            }
        }
        /*else if(searchStr[0]._Type==2)
        {快速查询*/
        if (searchStr[0]._strQuickSearch != "" && searchStr[0]._strQuickSearch != null) {
            strWhere += searchStr[0]._strQuickSearch;
        }
        //    }
        /* else if(searchStr[0]._Type==3)
        {高级搜索查询条件*/
        if (searchStr[0]._AdvancedSearch != "" && searchStr[0]._AdvancedSearch != null) {
            strWhere += " and" + searchStr[0]._AdvancedSearch;
        }
        //        }
        else if (searchStr[0]._Type == 4) {/*来电查询*/
            if (searchStr[0]._curTelNum != "" && searchStr[0]._curTelNum != null) {
                strWhere += " and (T_EMPLOYEE.MOBILE ='" + searchStr[0]._curTelNum + "' or T_EMPLOYEE.TEL1 = '" + searchStr[0]._curTelNum + "' or T_EMPLOYEE.TEL2='" + searchStr[0]._curTelNum + "' or T_COMPANY.TEL ='" + searchStr[0]._curTelNum + "')";
            }
        }
        if (searchStr[0]._EmpName != "" && searchStr[0]._EmpName != null) {  /*姓名*/
            strWhere = strWhere + " and T_EMPLOYEE.NAME like '%" + searchStr[0]._EmpName + "%'";
        }
        if (searchStr[0]._Sex != "" && searchStr[0]._Sex != null) { /*性别(男or女)*/
            strWhere = strWhere + " and T_EMPLOYEE.MANORWOMAN ='" + searchStr[0]._Sex + "'";
        }
        if (searchStr[0]._Customer != "" && searchStr[0]._Customer != null) { /*单位*/
            strWhere = strWhere + " and (T_COMPANY.FULL_NAME like '%" + searchStr[0]._Customer + "%' OR T_COMPANY.SIMPLE_NAME like '%" + searchStr[0]._Customer + "%')";
        }
        if (searchStr[0]._Address != "" && searchStr[0]._Address != null) { /*地址*/
            strWhere = strWhere + " and T_COMPANY.ADDRESS like '%" + searchStr[0]._Address + "%'";
        }
    }
    /*if( jsCommunicationQueryCondition.allTypeChk!=1)
    {*/
    if (jsCommunicationQueryCondition.curSelNode != null) {/*所属分组*/
        if (jsCommunicationQueryCondition.curSelNode.id == -1) {
            strWhere += " and (T_EMPLOYEE.GROUP_ID=0 or T_EMPLOYEE.GROUP_ID is null)";
        } else {
            strWhere += " and T_EMPLOYEE.GROUP_ID=" + jsCommunicationQueryCondition.curSelNode.id;
        }
    }
    /* }*/
    //    var strOrderBy="";
    //    if(order !="" && order != null)
    //    {
    //        var str=order.toUpperCase().replace(/ASC/i,"").replace(/DESC/i,"").replace(/\s/g, "");
    //        if(str !="T_EMPLOYEE.EMPLOYEE_ID")
    //         {
    //            strOrderBy="T_EMPLOYEE."+order.toUpperCase().replace("DESC","").replace("ASC","")+" DESC";
    //         }
    //        else
    //         {
    //            strOrderBy="T_EMPLOYEE."+order;
    //         }   
    //    }
    strSql = strSql + strWhere + " Order By " + order;//window.clipboardData.setData("text",strSql);
    jsBookListModle.GridStrWhere=strWhere+ " Order By " + order+",T_EMPLOYEE.EMPLOYEE_ID asc";
    /*分页代码*/
    if (countTop > 0) {
        //           strSql="select TOP "+ pageSize +" (select count(T_EMPLOYEE.EMPLOYEE_ID) from ( " + strSql +")) as AllCount, * from (" + strSql +") where T_EMPLOYEE.EMPLOYEE_ID NOT IN (SELECT TOP "+ countTop +" T_EMPLOYEE.EMPLOYEE_ID from (" + strSql + "))";

        strSql = "    select( select count(*)  from ( SELECT T_EMPLOYEE.EMPLOYEE_ID FROM T_EMPLOYEE LEFT JOIN T_COMPANY ON T_EMPLOYEE.COMPANY_ID=T_COMPANY.COMPANY_ID   " + strWhere + " )) as AllCount,* from (select top " + pageSize + " * from ( " + strSql + "  ,T_EMPLOYEE.EMPLOYEE_ID asc)   order by " + order.toUpperCase().replace("DESC", "").replace("ASC", "") + (sort == " asc" ? " desc" : " asc") + "   ,T_EMPLOYEE.EMPLOYEE_ID asc)order by " + order.toUpperCase().replace("DESC", "").replace("ASC", "") + sort;
    }
    else {
        strSql = "select TOP " + pageSize + " (select count(T_EMPLOYEE.EMPLOYEE_ID) from ( " + strSql + ")) as AllCount, * from (" + strSql + ") ";
    } 

    var strResult = DBReader.selectSqlForJson(strSql); //window.clipboardData.setData("text",strResult);
    var result;
    if (strResult != null) {
        result = eval("[{" + strResult + "}]");
        result[0].pageIndex = pageIndex;
        if (result[0].table != undefined) {
            jsBookListModle.CurEmpGridAllCount = result[0].table[0].AllCount;
        } else {
            jsBookListModle.CurEmpGridAllCount = 0;
        }
    }
    countTop = null; strSql = null;
    strWhere = null; strOrderBy = null;
    CollectGarbage();
    return strResult == null ? null : result[0];
}

/*通讯簿列表搜索*/
jsBookListModle.BookListSearchString=function(strType)
{
    try
    {
        jsBookListModle.CurSeletedBookListGridRow=null;
        /*获取查询区域返回的查询条件*/
        jsCommunicationQueryCondition.GetQueryPara(strType);
//        if(strType=="quick")
//        {/*快速查询*/
//            jsCommunicationQueryCondition.queryObj[0]._Type=2;
//        }
        if(strType=="familiar")
        {/*熟悉度查询*/
            jsCommunicationQueryCondition.queryObj[0]._Type=0;
        }
        else if(strType=="strange")
        {/*陌生度查询*/
           jsCommunicationQueryCondition.queryObj[0]._Type=1;
        }
        else if(strType=="advanced")
        {/*高级搜索*/
           jsCommunicationQueryCondition.queryObj[0]._Type=3;
        }
        else if(strType=="InComCall")
        {/*来电查询*/ 
            jsCommunicationQueryCondition.queryObj[0]._Type=4;   
        }
        else 
        {/*全部中查询*/
           jsCommunicationQueryCondition.queryObj[0]._Type=-1;
        }
//        if(strType=="quick")
//        {
//            if(!(jsCommunicationQueryCondition.queryObj[0]._EmpName=="" &&  jsCommunicationQueryCondition.queryObj[0]._Sex=="全部" &&  jsCommunicationQueryCondition.queryObj[0]._Customer=="" && jsCommunicationQueryCondition.queryObj[0]._Address==""))
//            {
                $("#tbAdrressBook").DoSearch(jsCommunicationQueryCondition.queryObj);
//            }
//        }
//        else if(strType!="quick"){
//         $("#tbAdrressBook").DoSearch(jsCommunicationQueryCondition.queryObj);
//        }
        if(jsHistoryRecord.HistoryCallGrid!=null){
             jsHistoryRecord.HistoryCallGrid.clearRow();/*刷新主列表时清空历史记录*/
        }
         jsCallMiddlePanel.FreashTabDetailInfo();/*刷新主表时，清空明细表*/
    }
    catch(e)
    {
        alert("jsBookListModle.BookListSearchString:" + e.message);
    }
    CollectGarbage();
}

 jsBookListModle.DeleteAllSelData=function(empID,comID){
    var strSql="DELETE * FROM T_EMPLOYEE WHERE EMPLOYEE_ID ="+empID;
    var result = DBReader.execSql(strSql);
    var count=jsCommonLogic.selColumnData("count(*)","T_EMPLOYEE","WHERE COMPANY_ID="+comID);
    if(count==1)
    {
        var txtSql="DELETE * FROM T_COMPANY WHERE COMPANY_ID="+comID;
        DBReader.execSql(txtSql);
        txtSql=null;
    }
    /*删除该联系人的其它资料*/
    jsOtherInfo.DeleteOtherInfoByEmpID(empID);
    strSql=null;
    count=null;
    CollectGarbage();
    return result;
 };
 
 /*将选中的号码加到拨号台*/
 jsBookListModle.AddToTxtDialTelNo=function(){
    if( jsBookListModle.AddressBookGrid.getSelectedRows().length>0)
    {
        var strInnerHTML="";
        var editorbody=window.parent.jsRightMessage.GetTxtWaitCallItem();
        /*创建号码集合载体*/
        var itemList = editorbody.getElementsByTagName("P");          
        if(itemList.length==0){
                 strInnerHTML+=  "<p>"+editorbody.innerText+"</p>";
        }
        else
        {
            for(var i=0;i<itemList.length;i++){
                strInnerHTML+= "<p>"+itemList[i].innerText+"</p>";
            }
        }                
        $(jsBookListModle.AddressBookGrid.getSelectedRows()).each(function(){
            /*公司电话*/
            if($(this).attr("TEL")!=undefined && $(this).attr("TEL")!="")
            {
                if(strInnerHTML.indexOf($(this).attr("TEL"))==-1)
                {
                    if($(this).attr("NICKNAME")!=undefined && $(this).attr("NICKNAME")!="")
                    {
                        strInnerHTML+="<p>"+$(this).attr("TEL")+"|"+$(this).attr("NICKNAME")+"</p>"
                    }
                    else
                    {
                        strInnerHTML+="<p>"+$(this).attr("TEL")+"</p>";
                    }
                }
            }
            /*联系人手机*/
           if($(this).attr("MOBILE")!=undefined && $(this).attr("MOBILE")!="")
            {
                if(strInnerHTML.indexOf($(this).attr("MOBILE"))==-1)
                {
                    if($(this).attr("NICKNAME")!=undefined && $(this).attr("NICKNAME")!="")
                    {
                        strInnerHTML+="<p>"+$(this).attr("MOBILE")+"|"+$(this).attr("NICKNAME")+"</p>"
                    }
                    else
                    {
                        strInnerHTML+="<p>"+$(this).attr("MOBILE")+"</p>";
                    }
                }
            }
            /*联系人电话1*/
            if($(this).attr("TEL1")!=undefined && $(this).attr("TEL1")!="")
            {
                if(strInnerHTML.indexOf($(this).attr("TEL1"))==-1)
                {
                    if($(this).attr("NICKNAME")!=undefined && $(this).attr("NICKNAME")!="")
                    {
                        strInnerHTML+="<p>"+$(this).attr("TEL1")+"|"+$(this).attr("NICKNAME")+"</p>"
                    }
                    else
                    {
                        strInnerHTML+="<p>"+$(this).attr("TEL1")+"</p>";
                    }
                }
            }
            /*联系人电话2*/
            if($(this).attr("TEL2")!=undefined && $(this).attr("TEL2")!="")
            {
                if(strInnerHTML.indexOf($(this).attr("TEL2"))==-1)
                {
                    if($(this).attr("NICKNAME")!=undefined && $(this).attr("NICKNAME")!="")
                    {
                        strInnerHTML+="<p>"+$(this).attr("TEL2")+"|"+$(this).attr("NICKNAME")+"</p>"
                    }
                    else
                    {
                        strInnerHTML+="<p>"+$(this).attr("TEL2")+"</p>";
                    }
                }
            }
        });    
        window.parent.jsRightMessage.LoadInfoToTxtWaitCall(strInnerHTML);
        editorbody=null;
        itemList=null;
        strInnerHTML="";
        CollectGarbage();
    }
    else
    {
        alert("请先选择要转的号码！");
    }
 };
 
 /*根据响铃号码获取号码资料*/
 jsBookListModle.getRingNumberInfor=function(_number)
 {
    try
    {   
        /*提机的时候停止播放录音*/
       window.parent.jsRightAudio.StopPlay(true);
        
        /*主窗体切换到通讯簿窗口*/
        window.parent.execScript('$("#div-other-Info").opentabitem({ id: "tab-addressBook"});');
        
        /*加载号码资料*/    
        if(jsCallBookList.GetCurComOrEmpModel()=="Emp" &&  window.parent.jsTitle.IsPopWinOrNot==0){/*联系人模式*/
              if(document.getElementById("callCardModle").style.display==""){
                 window.parent.jsTitle.IsPopWinOrNot=1;
                ShowWindow.ShowModeLessDialog("Application/TeleSecretary/frmShowConfirmWin.htm?formIndex="+ShowWindow.getFormIdx()+"&loadAction=jsIndexPage.freshItemPage('tab-addressBook','jsBookListModle.ChangePageWhenCallRing(\""+_number+"\")')","来电提示",200,150);
                 
//        window.parent.execScript("jsTitle.regPhoneRingAction(\"\");");
//                 if(window.confirm("是否显示电话弹屏\r\n点击【确定】界面将跳转\r\n点击【取消】保留当前页面！")){
//                     jsBookListModle.ChangePageWhenCallRing(_number);
//                     jsBookListModle.IsPopWinOrNot=0;
//                 }else{
//                     jsBookListModle.IsPopWinOrNot=0;
//                 }
              }else{
                   jsBookListModle.ChangePageWhenCallRing(_number);
              }
        }else if(jsCallBookList.GetCurComOrEmpModel()=="Com"){/*公司模式*/
            if(document.getElementById("ComCardModle").style.display=="" || document.getElementById("EmpCardModle").style.display==""){
               if(window.parent.jsTitle.IsPopWinOrNot==0){
                     window.parent.jsTitle.IsPopWinOrNot=1;
                     ShowWindow.ShowModeLessDialog("Application/TeleSecretary/frmShowConfirmWin.htm?formIndex="+ShowWindow.getFormIdx()+"&loadAction=jsIndexPage.freshItemPage('tab-addressBook','jsBookListModle.ChangePageWhenCallRing(\""+_number+"\")')","来电提示",200,150);
//                   if(window.confirm("是否显示电话弹屏\r\n点击【确定】界面将跳转\r\n点击【取消】保留当前页面！")){
//                        jsBookListModle.IsPopWinOrNot=0;
//                        $("#radCallBookList").attr("checked",true);
//                        jsCallBookList.ChangeToEmpOrComDivModel(document.getElementById("radCallBookList"));
//                        jsBookListModle.ChangePageWhenCallRing(_number);
//                    }else{
//                         jsBookListModle.IsPopWinOrNot=0;
//                    }
                }else{
                    $("#radCallBookList").attr("checked",true);
                    jsCallBookList.ChangeToEmpOrComDivModel(document.getElementById("radCallBookList"));
                    jsBookListModle.ChangePageWhenCallRing(_number);
                }
            }else{
                $("#radCallBookList").attr("checked",true);
                jsCallBookList.ChangeToEmpOrComDivModel(document.getElementById("radCallBookList"));
                jsBookListModle.ChangePageWhenCallRing(_number);
            }
        }  
    }
    catch(e)
    {
        alert(" jsBookListModle.getRingNumberInfor:"+e.message);
    }
    CollectGarbage();
 };
 
 /*跳转页面*/
 jsBookListModle.ChangePageWhenCallRing=function(_number){
    if(window.parent.jsTitle.GetCallBillNameByCallNum(_number)!="无"){
        jsCommunicationQueryCondition.queryObj[0]._curTelNum=_number;      
        jsCommunicationQueryCondition.LeftSearchBtnClick("InComCall");/*通讯簿—联系人模式*/        
        jsHistoryRecord.HistoryRecordSearchString("InComCall");/*历史通话记录*/
    }else{        
        jsBookListModle.CurSeletedBookListGridRow=null;
        jsCallBookList.IsListOrCardModle('List');              
        jsBookCardModle.ChangeToAddInfo();                      
        jsBookCardModle.SetTelNumDefInfo(_number);
    }
//    if(window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strTelNum!=undefined && window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strTelNum!=""){
//       window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strTelNum=_number;
//       window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strComName="";
//    }
 };
 
 /*记录来去电时是否已打开ShowWindow*/
 jsBookListModle.ChangeIsPopWinOrNot=function(){
    window.parent.jsTitle.IsPopWinOrNot=0;
    window.parent.jsRightMessage.OpenItemLoadAction=null;
 };
 
/*挂机时关闭ShowWindow*/
jsBookListModle.LoadOpenItemWin=function(strIndex){
  window.parent.jsRightMessage.OpenItemLoadAction="ShowWindow.opener.execScript("+strIndex+",'ShowWindow.close()')";    
};
 
/*点击通讯簿便签时执行刷新*/
jsBookListModle.LoadRefreshBookPage=function(){
    window.parent.parent.parent.execScript("jsIndexPage.loadWithMask();");
   if(window.parent.jsTitle.IsAddNewRelationInfo){
        if(jsCallBookList.GetCurComOrEmpModel()=="Com"){
            $("#radCallBookList").attr("checked",true);
            jsCallBookList.ChangeToEmpOrComDivModel(document.getElementById("radCallBookList"));
        }   
        jsBookListModle.CurSeletedBookListGridRow=null;
        jsCallBookList.IsListOrCardModle('List');              
        jsBookCardModle.ChangeToAddInfo();                      
        jsBookCardModle.SetTelNumDefInfo(window.parent.jsTitle.NewRelationNumber);
       window.parent.jsTitle.IsAddNewRelationInfo=false;
       window.parent.jsTitle.NewRelationNumber=null;
   }else{
         jsCommunicationQueryCondition.LeftSearchBtnClick();/*刷新通讯簿列表*/
   }
    window.parent.parent.parent.execScript("jsIndexPage.loadWithUnMask();");
};