function jsAdrBookForCompany(){

};
jsAdrBookForCompany.CompanyGrid =null;/*主列表*/
jsAdrBookForCompany.EmployeeGrid=null;/*联系人列表*/

jsAdrBookForCompany.IsHaveComSetFile=null;
jsAdrBookForCompany.IsHavePerSetFile=null;

jsAdrBookForCompany.CurCompanyGridSelRow=null;/*当前主列表选中的行*/
jsAdrBookForCompany.strComIDList=null;/*当前公司档案中公司ID集合*/
jsAdrBookForCompany.ComInfoList=null;/*当前公司档案卡数据集合*/
jsAdrBookForCompany.CurComID=0;/*当前公司档案显示公司的ID*/
jsAdrBookForCompany.CurComGridAllCount=0/*当前公司列表中的总记录数*/
jsAdrBookForCompany.ComGridStrWhere=null;/*主列表的查询条件*/
                
jsAdrBookForCompany.EmpInfoList=null;/*当前联系人卡数据集合*/
jsAdrBookForCompany.CurEmpID = 0; /*当前联系人数据集下标*/
jsAdrBookForCompany.CurEmployeeSql=null;/*当前联系人SQL语句*/

$(function(){

});

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

/*注入公司及个人的系统设置js文件*/
jsAdrBookForCompany.LoadComAndEmpDesign= function(){ 
  if(App.FileIsExist(escape(App.ApplicationPath()+"Application\\TeleSecretary\\js\\jsDepartmentInformation.js")))   
   {
        App.SetNullHref(0);
        var comObj=document.getElementsByTagName("HEAD");
        var comScriptObj=document.createElement("script");
        comScriptObj.src="js/jsDepartmentInformation.js";
        comScriptObj.id="js_DepartmentInformation";
        comObj[0].appendChild(comScriptObj);
     
        setTimeout("jsAdrBookForCompany.PersionalOrCompanyDesignInfo('com')",150);
        
        comObj[0].removeChild(document.getElementById(comScriptObj.id)); 
        comScriptObj=null;
        comObj=null;
//        App.SetNullHref(1);
   }
  if(App.FileIsExist(escape(App.ApplicationPath()+"Application\\TeleSecretary\\js\\jsPersonalInformation.js")))
   {
        App.SetNullHref(0);
        var divObj=document.getElementsByTagName("HEAD");
        var scriptObj=document.createElement("script");
        scriptObj.src="js/jsPersonalInformation.js";
        scriptObj.id="js_PersonalInformation";
        divObj[0].appendChild(scriptObj);
      
        setTimeout("jsAdrBookForCompany.PersionalOrCompanyDesignInfo('per')",100);
        
       divObj[0].removeChild(document.getElementById(scriptObj.id)); 
        scriptObj=null;
        divObj=null;
//        App.SetNullHref(1);
    }
}

/*加载公司及个人的系统设置结果*/
jsAdrBookForCompany.PersionalOrCompanyDesignInfo=function(strType) {
    var arrTable = new Array();
    var obj = null;
    if (strType == "per") {
        arrTable.push('<form id="frPersionalContC" ><input id="hhideEmployeeIDC" type="hidden" /><table id="tbDesignPersionalInfoC" cellpadding="0" cellspacing="0"  style="width:98%;" class="formtable">');    
         arrTable.push('<tr><td colspan="4"><h2 align="left"><a id="changeComGoupType"  title="更改公司" onclick="jsAdrBookForCompany.OpenSelCompanyWin();"><span class="select_info">更改公司</span></a></span></h2></td></tr>');      
        obj = eval(unescape(jsPersonalInformation.dataJSON));
    }
    else if (strType == "com") {
        arrTable.push('<form id="frCompanyContC" ><input id="hhideCompanyIDC" type="hidden" /><table id="tbDesignCompanyInfoC" cellpadding="0" cellspacing="0"  style="width:98%" class="formtable">'); 
        arrTable.push('<tr><td colspan="4"><h2 align="left">公司信息<span id="divComGroupInfo" style="color:#06A291;">——所属分组：<span id="curComGroup_ID"></span><input id="hideComCurGroupID" type="hidden" />&nbsp;<a id="changeComGoupType"  title="更改分组" onclick="jsAdrBookForCompany.ChangeGroupType();"><span class="select_info">更改分组</span></a></span></h2></td></tr>');
        arrTable.push('<tr><td>单位名称</td><td colspan="3"><INPUT id="hhideCompanyNameC" type="hidden" Field="SIMPLE_NAME"/><INPUT type="text" class="ipt" id="txtCompanyNameC" Field="SIMPLE_NAME" style="width:' + document.body.clientWidth * 0.6 + 'px;"/> <input id="btnViewComC" type="button" class="buttonList" value="更改公司" onclick="jsBookCardModle.OpenSelCompanyWin()" style="width:60px; display:none;" /></td></tr>');
        obj = eval(unescape(jsDepartmentInformation.dataJSON));
    }
    for (var i = 0; i < obj.length; i++) {
        arrTable.push("<tr>");
        for (var j = 0; j < obj[i].length; j++) {
            arrTable.push("<td>" + unescape(obj[i][j].title) + "</td>");
            if (obj[i].length == 1) {           
                arrTable.push("<td colspan='3' style='width:90%;'>" + unescape(obj[i][j].content) + "</td>");
            } else {
                arrTable.push("<td>" + unescape(obj[i][j].content) + "</td>"); //alert(unescape(obj[i][j].content));
            }
        }
        arrTable.push("</tr>");
    }
    arrTable.push("<table/></form>");
    if (strType == "per") {
        document.getElementById("divEmpCardContanier").innerHTML = arrTable.join("");
        var tdArray = document.getElementById("divEmpCardContanier").getElementsByTagName("TD");
        for (var p = 0; p < tdArray.length; p++) {
            if (tdArray[p].colSpan == 3) {
                var _child = tdArray[p].childNodes[0];
                if (_child != null && (_child.type == "text" || _child.tagName == "TEXTAREA")) {
                    _child.style.width = document.body.clientWidth  * 0.6;
                }
                _child = null;
            }
        }
        tdArray = null;
        jsPersonalInformation.initControl();
    }
    else if (strType == "com") {
        document.getElementById("divComCardContanier").innerHTML = arrTable.join("");
        var tdArray = document.getElementById("divComCardContanier").getElementsByTagName("TD");
        for (var p = 0; p < tdArray.length; p++) {
            if (tdArray[p].colSpan == 3) {
                var _child = tdArray[p].childNodes[0];
                if (_child != null && (_child.type == "text" || _child.tagName == "TEXTAREA")) {
                    _child.style.width = document.body.clientWidth  * 0.6;
                }
                _child = null;
            }
        }
        tdArray = null;
    }
    jsAdrBookForCompany.ChangePhoneValueIsClick("divComCardContanier","com");
    jsAdrBookForCompany.ChangePhoneValueIsClick("divEmpCardContanier","per");
    arrTable.length = 0;
    arrTable = null;
    obj = null;
    CollectGarbage();
};

/*更改公司模式下电话控件的相关属性值—避免与联系人模式冲突*/
jsAdrBookForCompany.ChangePhoneValueIsClick=function(strDiv,strType){
    var divObj=document.getElementById(strDiv); 
    var inputObj=divObj.getElementsByTagName("INPUT");
    for(var j=0;j<inputObj.length;j++){
        if (inputObj[j].contorlType == "phone" || inputObj[j].contorlType == "web") {
          if (strType == "per") {
            inputObj[j].isClick="P_"+inputObj[j].isClick;
            }
            else if(strType=="com"){
              inputObj[j].isClick="C_"+inputObj[j].isClick;
            }      
        }
    }
    
    var imgObj=divObj.getElementsByTagName("IMG");
    for(var k=0;k<imgObj.length;k++){
        if(imgObj[k].isClick!=undefined){
          if (strType == "per") {
            imgObj[k].isClick="P_"+imgObj[k].isClick;
            }
            else if(strType=="com"){
              imgObj[k].isClick="C_"+imgObj[k].isClick;
            }
        }
    }
    divObj=null;
    inputObj=null;
    imgObj=null;
    CollectGarbage();
}
/*打开更改公司窗口*/
jsAdrBookForCompany.OpenSelCompanyWin=function(){
     var formIndex=ShowWindow.getFormIdx();
     ShowWindow.ShowMoledDialog("Application/TeleSecretary/frmSelectCompany.htm?comName="+escape($("#txtCompanyNameC").val())+"&formIndex="+formIndex+"&action=jsIndexPage.freshItemPage('tab-addressBook','jsAdrBookForCompany.ChangeComIDValue(\"@ComID\",\"@ComName\",\"@GroupID\")')","更改公司",600,440);
};

/*更改公司*/
jsAdrBookForCompany.ChangeComIDValue=function(ComID,ComName,GroupID){
    var curSelComID=0;
    if(jsAdrBookForCompany.CurCompanyGridSelRow!=null)
    {
        curSelComID=jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID")==-2?0:jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID");
    }
    else if($("#hhideCompanyIDC").val()>0)
    {
        curSelComID=$("#hhideCompanyIDC").val()
    }
    if(curSelComID!=ComID && $("#hhideEmployeeIDC").val()>0)
    {
          var empGroupID=jsCommonLogic.selColumnData("GROUP_ID","T_EMPLOYEE","WHERE EMPLOYEE_ID="+$("#hhideEmployeeIDC").val());          
         var entity=jsEntity.CreateEntityByTableName_access("T_EMPLOYEE","","","","EMPLOYEE_ID");   
         entity.Fields.EMPLOYEE_ID=$("#hhideEmployeeIDC").val();
         entity.Fields.COMPANY_ID=ComID;
         if(empGroupID!=GroupID){
            entity.Fields.GROUP_ID=GroupID;
         }
         var result = entity.Update(entity);
         DBReader.DisposeEntity(entity);
         if(result){
            /*刷新联系人列表*/
             if(jsAdrBookForCompany.CurCompanyGridSelRow!=null){
                jsAdrBookForCompany.EmployeeGridSearchString(jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID"),"","clickRow");
             }
             else if($("#hhideCompanyIDC").val()>0){
                 jsAdrBookForCompany.EmployeeGridSearchString($("#hhideCompanyIDC").val(),"","clickRow");
             }
            /*重新绑定联系人数据*/
            var strEmpIDList = jsAdrBookForCompany.GetEmployeeIDListByComID(curSelComID);
            jsAdrBookForCompany.GetEmployeeList(escape(strEmpIDList));
            jsAdrBookForCompany.BindEmployeeData();

            jsAdrBookForCompany.UpdateCallBillInfoWhenChageData(ComID,$("#hhideEmployeeIDC").val());
            strEmpIDList=null;
        }        
        CollectGarbage();
    }
};


/*保存档案时更改通话记录中关联号码的档案相关值*/
jsAdrBookForCompany.UpdateCallBillInfoWhenChageData=function(comID,empID){
    var selSql="select TEL from T_COMPANY where COMPANY_ID="+comID+" union select MOBILE as TEL  from T_EMPLOYEE where EMPLOYEE_ID="+empID+" union select TEL1 as TEL from T_EMPLOYEE where EMPLOYEE_ID="+empID+" union select TEL2 as TEL from T_EMPLOYEE where EMPLOYEE_ID="+empID+" union select S2 as TEL from T_EMPLOYEE where EMPLOYEE_ID="+empID;
    var strResult=DBReader.selectSqlForJson(selSql);
    if(strResult!=null){
        var result=eval("[{"+strResult+"}]");
        if(result[0].result==1 && result[0].table!=undefined){
            for(var i=0;i<result[0].table.length;i++){
                if(result[0].table[i].TEL!=""){
                     jsAdrBookForCompany.ChangeCallBillData(comID,empID,result[0].table[i].TEL);
                }
            }
           result=null;
        }
    }
    strResult=null;          
    comID=null;
    empID=null;
    CollectGarbage();   
};

jsAdrBookForCompany.ChangeCallBillData=function(comID,empID,telNum){
    var txtSql="UPDATE T_CALLBILL SET COMPANYID="+comID+",EMPLOYEEID="+empID+" WHERE TELNUM='"+telNum+"'";
    if(comID==0){
         txtSql="UPDATE T_CALLBILL SET EMPLOYEEID="+empID+" WHERE TELNUM='"+telNum+"'";
    }
    if(empID==0){
         txtSql="UPDATE T_CALLBILL SET COMPANYID="+comID+" WHERE TELNUM='"+telNum+"'";
    }
    DBReader.execSql(txtSql);
     var strName=window.parent.jsTitle.GetCallBillNameByCallNum(telNum);
    if(strName!="" && strName!='无'){
        var txtChange="UPDATE T_CALLBILL SET CUSTOMER='"+strName+"' WHERE TELNUM='"+telNum+"' and CUSTOMER='无'";
        DBReader.execSql(txtChange);
        txtChange=null;
    }    
    strName=null;    
    txtSql=null;
    CollectGarbage();
};

/*单位操作按钮*/
jsAdrBookForCompany.LoadCompanyToolBarBtn = function() {
    $("#ComList-toolbar").html('');
    $("#EmpList_toolbar").html('');
    var comOption = { items: [
        { type: 'button', text: '新建单位', useable: 'T', className: 'tableAdd', handler: function() {
            jsAdrBookForCompany.ChangeToAddComInfo();
            jsAdrBookForCompany.IsListOrCardModle("com", "list");
        } 
        },
        { type: 'button', text: '修改单位', useable: 'T', className: 'tableEdit', handler: function() {
            $("#btnCancelComAdd").show();
            $("#btnDeleteComInfo").hide();
            jsAdrBookForCompany.ChangeListToCompanyCardModle();
        } },
        { type: 'button', text: '删除选中', useable: 'T', className: 'tableClose', handler: function() {
              if (jsAdrBookForCompany.CompanyGrid.getSelectedRows().length > 0) {
                  if (confirm("将删除所选单位及联系人信息,确定要删除吗？")) {
                      $(jsAdrBookForCompany.CompanyGrid.getSelectedRows()).each(function() {
                          jsAdrBookForCompany.DeleteAllSelCompanyData($(this).attr("COMPANY_ID")); /*删除选择的*/
                      });
                      jsAdrBookForCompany.CompanyGrid.flexReload();                     
                      if (document.getElementById("divEmployeeCrid").style.display == "") {
                          jsAdrBookForCompany.EmployeeGrid.clearRow();
                      }
                      else {
                          jsAdrBookForCompany.EmpInfoList = null;
                          jsAdrBookForCompany.BindEmployeeData();
                      }
                  }
              }
              else {
                  alert("请选择要删除的行！");
              }
          } },
          { type: 'button', text: '更改分组', useable: 'T', className: 'tableEdit',handler:  function(){
             if (jsAdrBookForCompany.CompanyGrid.getSelectedRows().length > 0) {
                 var FormIndex=ShowWindow.getFormIdx();
                 ShowWindow.ShowMoledDialog("Application/TeleSecretary/frmCommunication/frmGroupTree.htm?FormIndex="+FormIndex+"&LoadAction=jsIndexPage.freshItemPage(\"tab-addressBook\",\"jsAdrBookForCompany.EditCurGroupID(@str)\")","更改分组",260,500);  
             }else{
                alert("请先选择要更改分组的公司！");
             }
        }},   
        { type: 'separate' },
        { type: 'button', text: '列设置', useable: 'T', className: 'tableSet', handler: function() {
            jsAdrBookForCompany.OpenComColSetWindow("com");
        }},
        { type: 'button', text: '导入', useable: 'T', className: 'tableSave',handler: function() {
               var FormIndex=ShowWindow.getFormIdx();
               var groupID =0; 
               var groupText="";
               if(jsCommunicationQueryCondition.curSelNode!=null){
                    if(jsCommunicationQueryCondition.curSelNode.id>0){
                        groupID=jsCommunicationQueryCondition.curSelNode.id;
                        groupText=jsCommunicationQueryCondition.curSelNode.text;
                    }
               }
               ShowWindow.ShowMoledDialog("Application/TeleSecretary/InportExcel/frmInportExcel.htm?GroupID="+groupID+"&GroupText="+groupText+"&FormIndex="+FormIndex+"&LoadAction=jsIndexPage.freshItemPage(\"tab-addressBook\",\"jsAdrBookForCompany.CompanyGrid.DoSearch()\")","导入数据",400,500);           
               groupID=null;
               groupText=null;
               FormIndex=null;
               CollectGarbage();     
         }}, 
        { type: 'button', text: '导出', useable: 'T', className: 'tableSet',handler:  function(){
                   jsAdrBookForCompany.ExportCompanyInfo();
        }},   
        { type: 'button', text: '单位档案卡', useable: 'T', className: 'tableView', handler: function() {
            App.SetNullHref(0);
            jsAdrBookForCompany.ChangeListToCompanyCardModle();
            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);
            }
        } 
        }
     ]
    };
    $("#ComList-toolbar").toolbar(comOption);

    /*联系人操作按钮*/
    var empOption = { items: [
       { id: 'btnAddEmpT', type: 'button', text: '新建联系人', useable: 'T', className: 'tableAdd', handler: function() {
           jsAdrBookForCompany.ChangeToAddEmpInfo();
           jsAdrBookForCompany.IsListOrCardModle("emp", "list");
       } 
       },
       { id: 'btnEditEmpT', type: 'button', text: '修改联系人', useable: 'T', className: 'tableEdit', handler: function() {
           $("#btnCancelEmp").show();
           $("#btnDelEmp").hide();
           jsAdrBookForCompany.ChangeListToEmployeeCardModle();
       } 
       },
          { id: 'btnDelEmpT', type: 'button', text: '删除选中', useable: 'T', className: 'tableClose', handler: function() {
              jsAdrBookForCompany.DeleteSelEmployeInfo();
          } 
          },
        //        {id:'btnSeparateC', type: 'separate' }, 
        {type: 'button', text: '列设置', useable: 'T', className: 'tableSet', handler: function() {
            jsAdrBookForCompany.OpenComColSetWindow("per");
        } 
    },
        { type: 'button', text: '联系人档案卡', useable: 'T', className: 'tableView', handler: function() {
            jsAdrBookForCompany.ChangeListToEmployeeCardModle();
        } 
        }
     ]
};
$("#EmpList_toolbar").toolbar(empOption);
}

/*公司列表中——更改分组*/
jsAdrBookForCompany.EditCurGroupID=function(id,name){
       if(id>0){
        if (jsAdrBookForCompany.CompanyGrid.getSelectedRows().length > 0) {
            var strComIDList="";
            $(jsAdrBookForCompany.CompanyGrid.getSelectedRows()).each(function() {
                if (strComIDList != "") {
                    strComIDList += ",";
                }
                strComIDList += $(this).attr("COMPANY_ID");
            });
            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);
            alert("更改分组成功！");
            
            strComIDList=null;
            strSql1=null;
            strSql2=null;
            CollectGarbage();
        }
    }
};

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

/*显示或隐藏列*/
jsAdrBookForCompany.ShowOrHideGridColumn = function(hideCol, showCol, strType) {
    if (strType == "com") {
        var tbParent = document.getElementById("divCompanyList");
        tbParent.innerHTML = "";
        var tabObj = document.createElement("TABLE");
        tabObj.id = "tdCompanyList";
        tbParent.appendChild(tabObj);
    }
    else if (strType == "per") {
        var tbParent = document.getElementById("divEmployeeList");
        tbParent.innerHTML = "";
        var tabObj = document.createElement("TABLE");
        tabObj.id = "tdEmployeeList";
        tbParent.appendChild(tabObj);
    }
    /*隐藏*/
    var objHideColSet = hideCol.split(",");
    for (var i = 0; i < objHideColSet.length; i++) {
        if (strType == "com") {
            $("#tdCompanyList").hiddentColumnByName(objHideColSet[i]);
        }
        else if (strType == "per") {
            $("#tdEmployeeList").hiddentColumnByName(objHideColSet[i]);
        }
    }
    /*显示*/
    var objShowColSet = showCol.split(",");
    for (var j = 0; j < objShowColSet.length; j++) {
        if (strType == "com") {
            $("#tdCompanyList").showColumnByName(objShowColSet[j]);
        }
        else if (strType == "per") {
            $("#tdEmployeeList").showColumnByName(objShowColSet[j]);
        }
    }
    jsAdrBookForCompany.LoadColSetJsFile();
    if (strType == "com") {
        jsAdrBookForCompany.CompanyGrid = null;
        jsAdrBookForCompany.LoadCompanyGrid();
        jsCallBookList.ChangeToEmpOrComDivModel(document.getElementById("radCallBookComList"));
        jsAdrBookForCompany.CompanyGrid.DoSearch();
    } else if (strType == "per") {
        jsAdrBookForCompany.EmployeeGrid = null;
        jsAdrBookForCompany.LoadEmployeeGrid();
        jsAdrBookForCompany.EmployeeGrid.DoSearch();
        if (jsAdrBookForCompany.CurCompanyGridSelRow != null) {
            var target = jsAdrBookForCompany.CurCompanyGridSelRow[0];
            switch (jsCallMiddlePanel.listNo) {
                case "HistoryRecord":
                    jsHistoryRecord.HistoryRecordSearchString();
                    break;
                case "EmployeeInfo":
                    if (jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID") > 0) {
                        $("#btnAddEmpT").show();
                        $("#btnEditEmpT").show();
                        $("#btnDelEmpT").show();
                        $("#btnSeparateC").show();

                        $("#btnAddEmp").show();
                        $("#btnDelEmp").show();
                        $("#btn_DelEmps").show();
                        $("#btnSaveEmp").show();
                    }
                    if (document.getElementById("divEmployeeCrid").style.display == "") {
                        jsAdrBookForCompany.EmployeeGridSearchString($(target).attr("COMPANY_ID"), "", "clickRow"); /*显示当前公司的联系人*/
                    }
                    else {
                        jsAdrBookForCompany.CurEmpID = 0;
                        var curComID = $(target).attr("COMPANY_ID") == -2 ? 0 : $(target).attr("COMPANY_ID");
                        var strEmpIDList = jsAdrBookForCompany.GetEmployeeIDListByComID(curComID);
                        jsAdrBookForCompany.GetEmployeeList(escape(strEmpIDList));
                        jsAdrBookForCompany.BindEmployeeData();
                        curComID = null;
                        strEmpIDList = null;
                        CollectGarbage();
                    }
                    break;
                case "OtherInfo":
                    jsOtherInfo.OtherInfoSearchString();
                    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;
        }
    }
    tabObj = null;
    tbParent = null;
    objHideColSet = null;
    objShowColSet = null;
    hideCol = null;
    showCol = null;
    CollectGarbage();
};

/*联系人档案卡删除当前联系人*/
jsAdrBookForCompany.DelelteCurEmployeeInformation=function(){
    if($("#hhideEmployeeIDC").val()>0)
    {
        if(confirm("确定要删除吗？"))
        {
            var txtSql="DELETE * FROM T_EMPLOYEE WHERE EMPLOYEE_ID="+$("#hhideEmployeeIDC").val();
            DBReader.execSql(txtSql);
           /*删除该联系人的其它资料*/
            jsOtherInfo.DeleteOtherInfoByEmpID($("#hhideEmployeeIDC").val());
            jsAdrBookForCompany.CurEmpID=0;
//            if(document.getElementById("divCompanyGrid").style.display==""){
//                 jsAdrBookForCompany.EmployeeGridSearchString(jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID"),"","clickRow");
//            }
//            else{
//                jsAdrBookForCompany.EmployeeGridSearchString($("#hhideCompanyIDC").val(),"","clickRow");
//            }         
            jsAdrBookForCompany.EmployeeGrid.flexReload();
            jsAdrBookForCompany.IsListOrCardModle("emp","card");
            strEmpIDList=Number;
            txtSql=null;
            CollectGarbage();
        }
    }
};

/*删除联系人列表中选中的联系人*/
jsAdrBookForCompany.DeleteSelEmployeInfo=function(){
  if(jsAdrBookForCompany.EmployeeGrid.getSelectedRows().length>0){
    if(confirm("确定要删除吗？")){
            var strEmpIDList="";
            $(jsAdrBookForCompany.EmployeeGrid.getSelectedRows()).each(function(){
                if(strEmpIDList!=""){
                    strEmpIDList+=",";
                }
                strEmpIDList+=$(this).attr("EMPLOYEE_ID");
            });    
            var txtSql="DELETE * FROM T_EMPLOYEE WHERE EMPLOYEE_ID IN("+strEmpIDList+")"
            DBReader.execSql(txtSql);
           /*删除该联系人的其它资料*/
            jsOtherInfo.DeleteOtherInfoByEmpID(strEmpIDList);
            strEmpIDList=null;
            txtSql=null;
            CollectGarbage();
            jsAdrBookForCompany.EmployeeGrid.flexReload();
//             if(document.getElementById("divCompanyGrid").style.display==""){
//                 jsAdrBookForCompany.EmployeeGridSearchString();
//            }
//            else{
//                jsAdrBookForCompany.EmployeeGridSearchString($("#hhideCompanyIDC").val());
//            }
        }
    }
    else
    {
        alert("请选择要删除的行！");
    }
};

/*保存联系人*/
jsAdrBookForCompany.SaveEmployeeInformation=function(){
      var result=-1;
      var entity = jsEntity.CreateEntityByTableName_access("T_EMPLOYEE", "", "", "", "EMPLOYEE_ID");
      var employeeObj=document.getElementById("tbDesignPersionalInfoC");
      var comID=0;
      jsDataResolution.GetControlData(employeeObj, entity); /*通过页面控件获得实体*/
      if(entity.Fields.NAME!="")
      {
          if(document.getElementById("divCompanyGrid").style.display==""){
                if(jsAdrBookForCompany.CurCompanyGridSelRow!=null)
                {
                    comID=jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID");
                }
          }
          else{
               comID=$("#hhideCompanyIDC").val()==""?0:$("#hhideCompanyIDC").val();
          }    
          if(comID==-2){comID=0;}
          entity.Fields.COMPANY_ID=comID;
          if($("#hideComCurGroupID").val()>0){
                entity.Fields.GROUP_ID=$("#hideComCurGroupID").val();
          }
          if($("#hhideEmployeeIDC").val()>0){
                entity.Fields.EMPLOYEE_ID=$("#hhideEmployeeIDC").val();
                result=entity.Update(entity);
          }
          else{
                result=entity.Insert(entity);
          }
          if(result)
          {
                $("#hhideEmployeeIDC").val(entity.Fields.EMPLOYEE_ID);            
                if(jsAdrBookForCompany.CurCompanyGridSelRow!=null){
                    jsAdrBookForCompany.EmployeeGridSearchString(jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID"),"","clickRow");               
                 }
                else if($("#hhideCompanyIDC").val()>0){
                    jsAdrBookForCompany.EmployeeGridSearchString($("#hhideCompanyIDC").val(),"","clickRow");
                }
                else{
                    jsAdrBookForCompany.EmployeeGridSearchString(0,"","clickRow");
                }          
                var strEmpIDList = jsAdrBookForCompany.GetEmployeeIDListByComID(comID);
                jsAdrBookForCompany.GetEmployeeList(escape(strEmpIDList));
                jsAdrBookForCompany.BindEmployeeData();
                strEmpIDList=null;

                jsAdrBookForCompany.UpdateCallBillInfoWhenChageData(comID,$("#hhideEmployeeIDC").val());
                $("#btnCancelEmp").hide();
                $("#btnDelEmp").show();
                alert("保存成功！");
          }
          else
          {
                alert("保存失败！");
          }   
      }  
      else
      {
        alert("联系人姓名不能为空！");
      }     
      result=null;
      employeeObj=null;
      comID=null;
      DBReader.DisposeEntity(entity);
      CollectGarbage();
};

/*新建联系人*/
jsAdrBookForCompany.ChangeToAddEmpInfo=function(){
    $("#hhideEmployeeIDC").val('');
    $("#frPersionalContC").resetForm();/*清空联系人信息*/
    
    if(jsAdrBookForCompany.EmpInfoList==null){
          $("#btnEmpPrevious").hide();
          $("#btnEmpNext").hide();
    }
    $("#btnCancelEmp").show();
    $("#btnDelEmp").hide();    
    $("#btnEmpPrevious").hide();
    $("#btnEmpNext").hide();
    
    if($("#hhideCompanyIDC").val()==""){
          $("#curComGroup_ID").text("暂无");
         $("#hideComCurGroupID").val('');    
    }
};

/*单位档案卡删除当前单位信息*/
jsAdrBookForCompany.DelelteCurCompanyInformation=function(){
    if($("#hhideCompanyIDC").val()>0){
        if(confirm("将删除该公司及其联系人信息，确定删除？"))
        {
           jsAdrBookForCompany.DeleteAllSelCompanyData($("#hhideCompanyIDC").val());           
           jsAdrBookForCompany.CompanyGrid.flexReload();
           jsAdrBookForCompany.IsListOrCardModle("com","card");
                /*-------------------------------------*/
           if(document.getElementById("divEmployeeCrid").style.display==""){
                jsAdrBookForCompany.EmployeeGrid.clearRow();
           }
           else{
                  jsAdrBookForCompany.EmpInfoList=null;
                  jsAdrBookForCompany.BindEmployeeData();
           }
          
        }
    }
};

/*删除选择单位信息*/
jsAdrBookForCompany.DeleteAllSelCompanyData=function(comID){
    if(comID>0){
        /*根据公司ID删除其它资料*/
        jsOtherInfo.DeleteOtherInfoByComID(comID);
        var empIDList=jsAdrBookForCompany.GetEmployeeIDListByComID(comID); 
        if(empIDList!="")
        {
            var txtSql="DELETE * FROM T_EMPLOYEE WHERE EMPLOYEE_ID IN("+empIDList+")";
            DBReader.execSql(txtSql);
            txtSql=null;
        }
        var txtDelSql="DELETE * FROM T_COMPANY WHERE COMPANY_ID="+comID;
        DBReader.execSql(txtDelSql);
        txtDelSql=null;
        CollectGarbage();
    }
};

/*新建单位*/
jsAdrBookForCompany.ChangeToAddComInfo=function(){
    $("#hhideCompanyIDC").val('');
    $("#hhideCompanyNameC").val('');
    $("#frCompanyContC").resetForm();/*清空公司信息*/

    $("#btnCancelComAdd").show();
    $("#btnDeleteComInfo").hide();
    $("#btnComPrevious").hide();
    $("#btnComNext").hide();
    $("#btnComs_Next").hide();
    
    if(document.getElementById("divCompanyGrid").style.display=="")
    {/*当前公司信息是列表*/
        jsAdrBookForCompany.CurCompanyGridSelRow=null;
    }
    /*清空联系人信息*/
    //jsAdrBookForCompany.EmployeeGridSearchString(-1,"","clickRow");
    jsAdrBookForCompany.EmployeeGrid.clearRow();
    jsAdrBookForCompany.EmpInfoList=null;
    jsAdrBookForCompany.BindEmployeeData();
    strEmpIDList=null;
    CollectGarbage();

     if(jsCommunicationQueryCondition.curSelNode!=null){
        if(jsCommunicationQueryCondition.curSelNode.id>0){
            $("#curComGroup_ID").text(jsCommunicationQueryCondition.curSelNode.text);
            $("#hideComCurGroupID").val(jsCommunicationQueryCondition.curSelNode.id);
        }else{
            /*清空所属分组*/
            $("#curComGroup_ID").text("暂无");
            $("#hideComCurGroupID").val('');
        }
    }else{
        /*清空所属分组*/
        $("#curComGroup_ID").text("暂无");
        $("#hideComCurGroupID").val('');
    }
    
     /*隐藏新建联系人*/
    $("#btnAddEmpT").hide();
    $("#btnEditEmpT").hide();
    $("#btnDelEmpT").hide();
    $("#btnSeparateC").hide();
    
     $("#btnAddEmp").hide();
     $("#btnDelEmp").hide();
     $("#btn_DelEmps").hide();
     $("#btnSaveEmp").hide();
     
     jsCallMiddlePanel.FreashTabDetailInfo();/*刷新主表时，清空明细表*/
};

/*保存单位*/
jsAdrBookForCompany.SaveCompanyInformation=function(){   
     var comSimpleName = $("#txtCompanyNameC").val().split('\"').join('“').split('\'').join('‘');
     if(comSimpleName!=""){
         var companyID = jsCommonLogic.selColumnData("COMPANY_ID", "T_COMPANY", "WHERE SIMPLE_NAME='" + comSimpleName + "' and SIMPLE_NAME<>'" + $("#hhideCompanyNameC").val() + "'");
         if(companyID==0){    
            var entity = jsEntity.CreateEntityByTableName_access("T_COMPANY", "", "", "", "COMPANY_ID");
            var comObj = document.getElementById("tbDesignCompanyInfoC");
            jsDataResolution.GetControlData(comObj, entity);/*为实体赋值*/
            if($("#hideComCurGroupID").val()>0){
                 entity.Fields.GROUP_ID=$("#hideComCurGroupID").val();
            }
            var result=-1;
            if($("#hhideCompanyIDC").val()>0){/*修改*/
                entity.Fields.COMPANY_ID=$("#hhideCompanyIDC").val();
                result= entity.Update(entity);
            }    
            else{/*添加*/
               result =entity.Insert(entity);
            }
            if(result) {
                alert("保存成功！");
                $("#hhideCompanyIDC").val(entity.Fields.COMPANY_ID);//alert( $("#hhideCompanyIDC").val());
                $("#hhideCompanyNameC").val(entity.Fields.SIMPLE_NAME);//alert($("#hhideCompanyNameC").val());
                jsAdrBookForCompany.CompanyGrid .flexReload();
//                 jsAdrBookForCompany.IsListOrCardModle("com","card");
                if($("#hhideCompanyIDC").val()>0){
                      /*新建公司才更改通话记录关联信息*/
                      jsAdrBookForCompany.UpdateCallBillInfoWhenChageData($("#hhideCompanyIDC").val(),0);
                }
                $("#btnCancelComAdd").hide();
                $("#btnDeleteComInfo").show();
                /*可以新建联系人*/
                $("#btnAddEmpT").show();
                $("#btnEditEmpT").show();
                $("#btnDelEmpT").show();
                $("#btnSeparateC").show();
                
                $("#btnAddEmp").show();
                $("#btnDelEmp").show();
                $("#btn_DelEmps").show();
                $("#btnSaveEmp").show();
            }
            else{
                alert("保存失败！");
            }
            DBReader.DisposeEntity(entity);
            comObj=null;
            result=null;
        }
        else{
             alert("已存在该单位简称！");
             $("#txtCompanyNameC").val($("#hhideCompanyNameC").val());
             $("#txtCompanyNameC").focus();
        }
        companyID=null;
    }
    else
    {
        alert("单位简称不能为空！");
    }
    comSimpleName=null;
    CollectGarbage();
}

/*取消新增单位*/
jsAdrBookForCompany.CancelAddCompanyInfo=function(){
    $("#btnCancelComAdd").hide();
    $("#btnDeleteComInfo").show();    
    jsAdrBookForCompany.BindCompanyData();
}

/*取消新增联系人*/
jsAdrBookForCompany.CancelAddEmployeeInfo=function(){
    $("#btnCancelEmp").hide();
    $("#btnDelEmp").show();  
    $("#btnEmpPrevious").show();
    $("#btnEmpNext").show();
    jsAdrBookForCompany.BindEmployeeData();
};

/*公司列表转公司档案卡*/
jsAdrBookForCompany.ChangeListToCompanyCardModle=function(rowId){
    jsAdrBookForCompany.CurCompanyGridSelRow=null;
    var strComIDList = "";
    if(rowId !=undefined){
    $(jsAdrBookForCompany.CompanyGrid.getRowByIndex(rowId)).each(function() {
            if (strComIDList != "") {
                strComIDList += ",";
            }
            strComIDList += $(this).attr("COMPANY_ID");
        });
    }else if (jsAdrBookForCompany.CompanyGrid.getSelectedRows().length > 0) {
        $(jsAdrBookForCompany.CompanyGrid.getSelectedRows()).each(function() {
            if (strComIDList != "") {
                strComIDList += ",";
            }
            strComIDList += $(this).attr("COMPANY_ID");
        });
    }
    else {
        var store =  jsAdrBookForCompany.CompanyGrid.getRowData();
        for (var i = 0; i < store.length; i++) {
            if (strComIDList != "") {
                strComIDList += ",";
            }
            strComIDList += store[i].COMPANY_ID;
        }
        store=null;
    }
    if(strComIDList!="-2"){
        jsAdrBookForCompany.CurComID = 0; /*重置当前数据集下标*/
        jsAdrBookForCompany.strComIDList=escape(strComIDList);
        jsAdrBookForCompany.GetComInfoList(); 
        jsAdrBookForCompany.BindCompanyData();
        jsAdrBookForCompany.IsListOrCardModle("com","list");
    }
    var textareaItem = document.getElementById("divComCardContanier").getElementsByTagName("TEXTAREA");
    for (var i = 0; i < textareaItem.length; i++) {
        eval("textareaItem[i].onkeydown = function() {jsTextEare.setEnterKey(this); }");
    }
    strComIDList=null;
    App.SetNullHref(0);
    CollectGarbage();
};

/*公司档案卡转公司列表*/
jsAdrBookForCompany.BtnCompanyListClick=function(){   
    jsAdrBookForCompany.CompanyGrid.flexReload();
    jsAdrBookForCompany.EmployeeGrid.clearRow();
    jsAdrBookForCompany.IsListOrCardModle("com","card");  
    
    jsAdrBookForCompany.ComInfoList=null;/*清空档案卡数据集合*/ 
    $("#hhideCompanyIDC").val('');
    $("#hhideCompanyNameC").val('');
    
    $("#btnCancelComAdd").hide();
    $("#btnDeleteComInfo").show();  
    
    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);
    }
    CollectGarbage();
};

/*联系人列表转联系人档案卡*/
jsAdrBookForCompany.ChangeListToEmployeeCardModle = function() {
    App.SetNullHref(0);
    var strEmpIDList = "";
    if (jsAdrBookForCompany.EmployeeGrid.getSelectedRows().length > 0) {
        $(jsAdrBookForCompany.EmployeeGrid.getSelectedRows()).each(function() {
            if (strEmpIDList != "") {
                strEmpIDList += ",";
            }
            strEmpIDList += $(this).attr("EMPLOYEE_ID");
        });
    }
    else {
        var store = jsAdrBookForCompany.EmployeeGrid.getRowData();
        for (var i = 0; i < store.length; i++) {
            if (strEmpIDList != "") {
                strEmpIDList += ",";
            }
            strEmpIDList += store[i].EMPLOYEE_ID;
        }
        store = null;
    }
    jsAdrBookForCompany.CurEmpID = 0; /*重置当前数据集下标*/
    jsAdrBookForCompany.GetEmployeeList(escape(strEmpIDList));
    jsAdrBookForCompany.BindEmployeeData();
    jsAdrBookForCompany.IsListOrCardModle("emp", "list");
    var textareaItem = document.getElementById("divEmpCardContanier").getElementsByTagName("TEXTAREA");
    for (var i = 0; i < textareaItem.length; i++) {
        eval("textareaItem[i].onkeydown = function() {jsTextEare.setEnterKey(this); }");
    }
    strEmpIDList = null;
    CollectGarbage();
};

/*联系人档案卡转联系人列表*/
jsAdrBookForCompany.BtnEmployeeListClick=function(){
    jsAdrBookForCompany.EmpInfoList=null;
    $("#hhideEmployeeIDC").val('');
    jsAdrBookForCompany.EmployeeGrid.flexReload();
    jsAdrBookForCompany.IsListOrCardModle("emp","card");
    $("#btnCancelEmp").hide();
    $("#btnDelEmp").show();  
};
/*档案卡与列表的切换*/
jsAdrBookForCompany.IsListOrCardModle = function(type, listOrCard) {
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    if (window.ActiveXObject) {
        Sys.ie = ua.match(/msie ([\d.]+)/)[1]
    }
    if (type == "com") {
        if (listOrCard == "list") {
            document.getElementById("divCompanyGrid").style.display = "none";
            document.getElementById("ComDataRecordCount").style.display = "";
            document.getElementById("ComCardModle").style.display = "";
            if (Sys.ie == "6.0") {
                var cardInfo = document.getElementById("divComCardContanier");
                if (cardInfo.style.height == "100%") {
                    var gh = parseInt($("#ComCardModle").height()) - 25;
                    $("#ComCardModle").height(gh);
                    cardInfo.style.height = gh;
                }
            }
        }
        else if (listOrCard == "card") {
            document.getElementById("divCompanyGrid").style.display = "";
            document.getElementById("ComDataRecordCount").style.display = "none";
            document.getElementById("ComCardModle").style.display = "none";
        }
    }
    else if (type == "emp") {
        if (listOrCard == "list") {
            document.getElementById("divEmployeeCrid").style.display = "none";
            document.getElementById("EmpDataRecordCount").style.display = "";
            document.getElementById("EmpCardModle").style.display = "";
        }
        else if (listOrCard == "card") {
            document.getElementById("divEmployeeCrid").style.display = "";
            document.getElementById("EmpDataRecordCount").style.display = "none";
            document.getElementById("EmpCardModle").style.display = "none";
        }
    }
};

/*导出列表中的数据*/
jsAdrBookForCompany.ExportCompanyInfo=function(){
    $(document.body).mask("数据导出中,请稍后...");
    var FieldObj=new Object();
    var arrDataName=new Array();
    var arrDataField=new Array();
    var strSelColumn="";
    if (jsAdrBookForCompany.IsHaveComSetFile == 1) {
        var objColSet = eval("[" + jsColSetForComFile.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="CmpName,TEL,ADDRESS";
        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_COMPANY.ADDRESS,iif(IsNull( T_COMPANY.SIMPLE_NAME ), T_COMPANY.FULL_NAME, T_COMPANY.SIMPLE_NAME ) AS CmpName,T_COMPANY.TEL";
    }
    strSql+=" FROM T_COMPANY LEFT JOIN T_EMPLOYEE ON T_COMPANY.COMPANY_ID=T_EMPLOYEE.COMPANY_ID"+jsAdrBookForCompany.ComGridStrWhere;    
    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();   
};


/*公司列表*/
jsAdrBookForCompany.LoadCompanyGrid=function(){
    var w = $("#middleContanier").width();
    var gh = $("#middleContanier").height() - 405;
    var arrColumn=new  Array();
    if(jsAdrBookForCompany.IsHaveComSetFile==1)
    {
        arrColumn.push("{ display: '单位ID', name: 'COMPANY_ID', width: (w * 0.1), sortable: false, align: 'left' ,hide:true}");
        var objColSet = eval("["+ jsColSetForComFile.ColSetString+"]");
        for(var i=0;i<objColSet.length;i++)
        {
            if(objColSet[i].DataField=="TEL"){
                   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:jsAdrBookForCompany.FormatTelNum}");
            }
            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:jsAdrBookForCompany.FormatRemark}");
            }
            else{            
                     arrColumn.push("{display: '"+unescape(objColSet[i].Title)+"', name: '"+objColSet[i].DataField+"', width: (w * 0.08),hide:"+(objColSet[i].IsDisplay.toString()=="0"?"true":"false")+", sortable: "+(objColSet[i].IsOrder.toString()=="1"?"true":"false")+", align: 'left'}");        
           }
        }
     }
     else
     {
         arrColumn.push("{ display: '编号', name: 'COMPANY_ID', width: (w * 0.1), sortable: false, align: 'left',hide:true}");
         arrColumn.push("{ display: '单位名称', name: 'CmpName', width: (w * 0.2), sortable: true, align: 'left' }");
         arrColumn.push("{ display: '公司电话', name: 'TEL', width: (w * 0.18), sortable: true, align: 'left' ,process:jsAdrBookForCompany.FormatTelNum}");
         arrColumn.push("{ display: '地址', name: 'ADDRESS', width: (w * 0.3), sortable: true, align: 'left' } ");
     }
     var option = {
         height: gh,
//         width: w,
         colModel:eval( "["+arrColumn.join(",")+"]"),         
         customFunction: jsAdrBookForCompany.ShowCompanyGridPage,
         rowhandler:jsAdrBookForCompany.ClickCompanyGridRow,
         rp: 20,
         showcheckbox: true,
         rowcheckboxselect: false,
         selectedonclick: true, 
         rowbinddata:true,
         sortname: 'COMPANY_ID',
         sortorder: 'desc'
     };
     jsAdrBookForCompany.CompanyGrid = $("#tdCompanyList").ikegrid(option);
};

/*获取公司数据*/
jsAdrBookForCompany.ShowCompanyGridPage = function(pageSize, pageIndex, searchStr, extpara, order) {
    var countTop = pageSize * pageIndex;
    var strSearchColumn = "";
    var strSql = "SELECT top " + countTop + "  T_COMPANY.COMPANY_ID,T_COMPANY.ADDRESS,iif(IsNull( T_COMPANY.SIMPLE_NAME ), T_COMPANY.FULL_NAME, T_COMPANY.SIMPLE_NAME ) AS CmpName,T_COMPANY.TEL FROM T_COMPANY LEFT JOIN T_EMPLOYEE ON T_COMPANY.COMPANY_ID=T_EMPLOYEE.COMPANY_ID";
    var strUnion = " union SELECT -2 as COMPANY_ID";
    var sort = " desc";
    if (order != undefined && order.toUpperCase().indexOf("ASC") != -1) {
        sort = " asc";
    }
    if (jsAdrBookForCompany.IsHaveComSetFile == 1) {
        var objColSet = eval("[" + jsColSetForComFile.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 (objColSet[i].DataField != "COMPANY_ID" && objColSet[i].DataField != "SIMPLE_NAME" && objColSet[i].DataField != "FULL_NAME") {
                    strUnion += ",'' as " + objColSet[i].DataField;
                }
                else if (objColSet[i].DataField == "SIMPLE_NAME" || objColSet[i].DataField == "FULL_NAME") {
                    strUnion += ",'无公司的联系人' as " + objColSet[i].DataField;
                }
            }
        }
        if (strSearchColumn != "") {
            strSql = "SELECT top " + countTop + " T_COMPANY.COMPANY_ID," + strSearchColumn + " FROM T_COMPANY LEFT JOIN T_EMPLOYEE ON T_COMPANY.COMPANY_ID=T_EMPLOYEE.COMPANY_ID";
        }
        objColSet = null;
        //        strSearchColumn = null;
    }
    var strWhere = " WHERE 1=1";

    if (searchStr != "" && searchStr != undefined) {
        if (searchStr[0]._ComIDList != "" && searchStr[0]._ComIDList != null) {
            strWhere += " and T_COMPANY.COMPANY_ID IN(" + searchStr[0]._ComIDList + ")";
        }
        /*单位名称*/
        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 (searchStr[0]._StrType == 0) { /*陌生度查询*/
            if (searchStr[0]._BeginTime != "" || searchStr[0]._EndTime != "") {
                var shortWhere = "select COMPANYID 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_COMPANY.COMPANY_ID in (" + shortWhere + ")";
            }
        }
        else if (searchStr[0]._StrType == 1) {/*熟悉度查询*/
            if (searchStr[0]._BeginTime != "" || searchStr[0]._EndTime != "") {
                var shortWhere = "select COMPANYID 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_COMPANY.COMPANY_ID not in (" + shortWhere + ")";
            }
        }
    }
    /*else if(searchStr[0]._StrType ==3){高级搜索*/
    if (jsCommunicationQueryCondition.queryObj[0]._AdvancedSearch != "" && jsCommunicationQueryCondition.queryObj[0]._AdvancedSearch != null) {
        strWhere += " and" + jsCommunicationQueryCondition.queryObj[0]._AdvancedSearch; //searchStr[0]._AdvanceSearch ;
    }
    // }
    /*所属分组*/
    if (jsCommunicationQueryCondition.curSelNode != null) {
        if (jsCommunicationQueryCondition.curSelNode.id == -1) {
            strWhere += " and (T_COMPANY.GROUP_ID=0 or T_COMPANY.GROUP_ID is null)";
        } else {
            strWhere += " and T_COMPANY.GROUP_ID=" + jsCommunicationQueryCondition.curSelNode.id;
        }
    }
    strSql = strSql + strWhere + " Order By T_COMPANY." + order + " ,T_COMPANY.COMPANY_ID asc";      //window.clipboardData.setData("text",strSql);
     jsAdrBookForCompany.ComGridStrWhere=strWhere+ " Order By T_COMPANY." + order+",T_COMPANY.COMPANY_ID asc";
     
    if (jsAdrBookForCompany.IsHaveComSetFile == 1) {
            strSql += strUnion + " FROM T_COMPANY";
    }
    else {
        strSql += " union SELECT -2 as COMPANY_ID,'' as ADDRESS,'无公司的联系人' as CmpName, '' as TEL FROM T_COMPANY   ";
    }

    /*分页代码*/
    if (countTop > 0) {      
       strSql = "select * from (SELECT ( select count(*)  from ( SELECT T_COMPANY.COMPANY_ID FROM T_COMPANY LEFT JOIN T_EMPLOYEE ON T_COMPANY.COMPANY_ID=T_EMPLOYEE.COMPANY_ID   " + strWhere + " )) as AllCount,* from (select top " + pageSize + " * from ( " + strSql + ")   order by " + order.toUpperCase().replace("DESC", "").replace("ASC", "") + (sort == " asc" ? " desc" : " asc") + "   ,T_COMPANY.COMPANY_ID asc)order by " + order.toUpperCase().replace("DESC", "").replace("ASC", "") + sort + ")order by COMPANY_ID asc";
    }
    else {
        strSql = "select TOP " + pageSize + " (select count(COMPANY_ID) from ( " + strSql + ")) as AllCount, * from (" + strSql + ") ";
    }//window.clipboardData.setData("text", strSql);
    var strResult = DBReader.selectSqlForJson(strSql);
    var result;
    if (strResult != null) {
        result = eval("[{" + strResult + "}]");
        result[0].pageIndex = pageIndex;
        if (result[0].table != undefined) {
            jsAdrBookForCompany.CurComGridAllCount = result[0].table[0].AllCount - 1;
        } else {
            jsAdrBookForCompany.CurComGridAllCount = 0;
        }
    }
    countTop = null;
    strSql = null;
    strWhere = null;
    strSearchColumn = null;

    CollectGarbage();
    return strResult == null ? null : result[0];
};

/*搜索公司*/
jsAdrBookForCompany.CompanyListSearchString=function(strComIDList,strType){
    var strWhere=[];
    /*获取查询区域返回的查询条件*/
    jsCommunicationQueryCondition.GetQueryPara(strType);
    var beginTime=jsCommunicationQueryCondition.queryObj[0]._BeginTime;
    var endTime=jsCommunicationQueryCondition.queryObj[0]._EndTime;
    var customer=jsCommunicationQueryCondition.queryObj[0]._Customer;
    var address=jsCommunicationQueryCondition.queryObj[0]._Address;
   // var advanceSearch=jsCommunicationQueryCondition.queryObj[0]._AdvancedSearch;
    var searchType=-1;
    if(strType!=undefined && strType=="familiar")
    {/*熟悉度查询*/
        searchType=0;
    }
    else if(strType!=undefined && strType=="strange")
    {/*陌生度查询*/
      searchType=1;
    }
    else if(strType!=undefined && strType=="advanced")
    {/*高级搜索*/
       searchType=3;
    }
    else if(strType!=undefined && strType=="InComCall")
    {/*来电查询*/ 
        searchType=4;   
    }

    strWhere.push({_StrType:searchType,_ComIDList:strComIDList,_BeginTime:beginTime,_EndTime:endTime,_Customer:customer,_Address:address});//,_AdvanceSearch:advanceSearch
    $("#tdCompanyList").DoSearch(strWhere); 
    
    if(document.getElementById("divCompanyGrid").style.display=="none"){
         jsAdrBookForCompany.IsListOrCardModle("com","card");
    }

    //jsAdrBookForCompany.EmployeeGridSearchString(-1,"","clickRow");

//    jsCallMiddlePanel.FreashTabDetailInfo();/*刷新主表时，清空明细表*/
//    if(jsAdrBookForCompany.EmployeeGrid!=null){
//         jsAdrBookForCompany.EmployeeGrid.clearRow();
//     }
    jsAdrBookForCompany.CurCompanyGridSelRow=null;

    if(document.getElementById("divEmployeeCrid").style.display=="none"){
        jsAdrBookForCompany.IsListOrCardModle("emp","card");
     } 
     beginTime=null;
     endTime=null;
     customer=null;
     address=null;
     CollectGarbage();
};

/*单击主列表行事件*/
jsAdrBookForCompany.ClickCompanyGridRow = function(target) {
    /*单击*/
    $(target).click(function() {
        jsAdrBookForCompany.CurCompanyGridSelRow = $(target);
        switch (jsCallMiddlePanel.listNo) {
            case "HistoryRecord":
                jsHistoryRecord.HistoryRecordSearchString();
            break;
            case "EmployeeInfo":
                if (jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID") > 0) {
                    $("#btnAddEmpT").show();
                    $("#btnEditEmpT").show();
                    $("#btnDelEmpT").show();
                    $("#btnSeparateC").show();

                    $("#btnAddEmp").show();
                    $("#btnDelEmp").show();
                    $("#btn_DelEmps").show();
                    $("#btnSaveEmp").show();
                }
                if (document.getElementById("divEmployeeCrid").style.display == "") {
                    jsAdrBookForCompany.EmployeeGridSearchString($(target).attr("COMPANY_ID"), "", "clickRow"); /*显示当前公司的联系人*/
                }
                else {
                    jsAdrBookForCompany.CurEmpID = 0;
                    var curComID = $(target).attr("COMPANY_ID") == -2 ? 0 : $(target).attr("COMPANY_ID");
                    var strEmpIDList = jsAdrBookForCompany.GetEmployeeIDListByComID(curComID);
                    jsAdrBookForCompany.GetEmployeeList(escape(strEmpIDList));
                    jsAdrBookForCompany.BindEmployeeData();
                    curComID = null;
                    strEmpIDList = null;
                    CollectGarbage();
                }
            break;
            case "OtherInfo":
                jsOtherInfo.OtherInfoSearchString();
                break;
            case "webSearch":
               if(!window.frames["tab_item_frame_tab-webSearch"].document.getElementById("rdPhone").checked && !window.frames["tab_item_frame_tab-webSearch"].document.getElementById("rdCompanyName").checked){
                  window.frames["tab_item_frame_tab-webSearch"].document.getElementById("rdPhone").checked="checked";
               }
              window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strPhone=$(target).attr("TEL");
              window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strComName=$(target).attr("SIMPLE_NAME");
              window.frames["tab_item_frame_tab-webSearch"].document.getElementById("fontPhone").style.display="none";
              window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strTelNum="";
              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;
        /*===============*/
    });
    /*双击*/
    $(target).dblclick(function() {
        $("#tdCompanyList").mask("数据加载中,请稍后...");
        if ($(target).attr("COMPANY_ID") != -2) {
            jsAdrBookForCompany.ChangeListToCompanyCardModle(this.rowIndex);
        }
        $("#tdCompanyList").unmask();
    });
};

/*根据公司ID获得联系人ID字符串*/
jsAdrBookForCompany.GetEmployeeIDListByComID=function(comID){
    var returnResult="";
   var strSql="SELECT EMPLOYEE_ID FROM T_EMPLOYEE WHERE COMPANY_ID="+comID;
   var obj= DBReader.selectSqlForJson(strSql);//alert(obj);
    if(obj!=null)
    {
        var result=eval("[{"+obj+"}]");
        if(result[0].result==1 && result[0].table!=undefined)
        {
            for(var i=0;i<result[0].table.length;i++)
            {
                if(returnResult!="")
                {
                    returnResult+=",";
                }
                returnResult+=result[0].table[i].EMPLOYEE_ID;
            }
        }
        result=null;
    }    
    strSql=null;
    obj=null;
    CollectGarbage();
    return returnResult;
}

/*联系人列表*/
jsAdrBookForCompany.LoadEmployeeGrid = function() {
    var w = $("#middleContanier").width() - 5;
    var gh = 156;
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    if (window.ActiveXObject) {
        Sys.ie = ua.match(/msie ([\d.]+)/)[1]
    }
    if (Sys.ie == "6.0") {
        gh = 122;
    }
    var arrColumn = new Array();
    if (jsAdrBookForCompany.IsHavePerSetFile == 1) {
        arrColumn.push("{display: '联系人ID', name: 'EMPLOYEE_ID', width: (w * 0.1), sortable: false, align: 'left',hide:true }");
        var objColSet = eval("[" + jsColSetForPerFile.ColSetString + "]");
        for (var i = 0; i < objColSet.length; i++) {
            if (objColSet[i].DataField == "MOBILE" || 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:jsAdrBookForCompany.FormatTelPersonalNum}");
            }
            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:jsAdrBookForCompany.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: '联系人编号', name: 'EMPLOYEE_ID', width: (w * 0.1), sortable: false, align: 'left',hide:true}");
        arrColumn.push("{display: '公司编号', name: 'COMPANY_ID', width: (w * 0.1), sortable: false, align: 'left',hide:true}");
        arrColumn.push("{display: '姓名', name: 'NAME', width: (w * 0.08), sortable: true, align: 'left' }");
        arrColumn.push("{display: '昵称', name: 'NICKNAME', width: (w * 0.08), sortable: true, align: 'left' }");
        arrColumn.push("{display: '职位', name: 'BUSINESS', width: (w * 0.08), sortable: true, align: 'left' }");
        arrColumn.push("{display: '性别', name: 'MANORWOMAN', width: (w * 0.05), sortable: true, align: 'left' }");
        arrColumn.push("{display: '手机', name: 'MOBILE', width: (w * 0.18), sortable: true, align: 'left' ,process:jsAdrBookForCompany.FormatTelPersonalNum} ");
        arrColumn.push("{display: '电话1', name: 'TEL1', width: (w * 0.18), sortable: true, align: 'left',process:jsAdrBookForCompany.FormatTelPersonalNum} ");
        arrColumn.push("{display: '电话2', name: 'TEL2', width: (w * 0.18), sortable: true, align: 'left' ,process:jsAdrBookForCompany.FormatTelPersonalNum} ");
        arrColumn.push("{display: 'Email', name: 'EMAIL', width: (w * 0.08), sortable: true, align: 'left' } ");
    }
    var option = {
        height: gh,
        //         width: w,
        colModel: eval("[" + arrColumn.join(",") + "]"),
        customFunction: jsAdrBookForCompany.ShowEmployeeGridPage,
        rowhandler: jsAdrBookForCompany.ClickEmployeeGridRow,
        rp: 20,
        sortname: 'EMPLOYEE_ID',
        showcheckbox: true,
        rowcheckboxselect: false,
        selectedonclick: true,
        rowbinddata: true,
        sortorder: 'desc'
    };
    jsAdrBookForCompany.EmployeeGrid = $("#tdEmployeeList").ikegrid(option);
    arrColumn.length = 0;
    arrColumn = null;
    option = null;
    CollectGarbage();
};

jsAdrBookForCompany.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>';
    }
};

/*获取联系人数据*/
jsAdrBookForCompany.ShowEmployeeGridPage = function(pageSize, pageIndex, searchStr, extpara, order) {
    var countTop = pageSize * pageIndex;
    var strSql = "SELECT top " + countTop + " T_EMPLOYEE.EMPLOYEE_ID, T_EMPLOYEE.COMPANY_ID, T_EMPLOYEE.NAME, T_EMPLOYEE.NICKNAME,T_EMPLOYEE.BUSINESS, T_EMPLOYEE.MANORWOMAN, T_EMPLOYEE.MOBILE, T_EMPLOYEE.TEL1, T_EMPLOYEE.TEL2, T_EMPLOYEE.EMAIL  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 (jsAdrBookForCompany.IsHavePerSetFile == 1) {
        var objColSet = eval("[" + jsColSetForPerFile.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) {
        /*公司ID*/
        if (searchStr[0]._comID != "" && searchStr[0]._comID != null) {
            if (searchStr[0]._comID == -2) {
                strWhere += " AND T_EMPLOYEE.COMPANY_ID=0";
            }
            else {
                strWhere += " AND T_EMPLOYEE.COMPANY_ID=" + searchStr[0]._comID;
            }
        }
        if (searchStr[0]._searchType == 0) { /*熟悉度查询*/
            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 + ")";
        }
        else if (searchStr[0]._searchType == 1) {/*陌生度查询*/
            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 + ")";
        }
        /* else if(searchStr[0]._searchType ==3){高级搜索*/
        if (searchStr[0]._advanceSearch != "" && searchStr[0]._advanceSearch != null) {
            strWhere += " and" + searchStr[0]._advanceSearch;
        }
        //        }
        else if (searchStr[0]._searchType == 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) {
            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 (searchStr[0]._strQuickSearch != "" && searchStr[0]._strQuickSearch != null) {
            strWhere += searchStr[0]._strQuickSearch;
        }
    }
    else {
        strWhere += " AND T_EMPLOYEE.COMPANY_ID=-1";
    }

    strSql = strSql + strWhere + " Order By T_EMPLOYEE." + order;
    jsAdrBookForCompany.CurEmployeeSql = strSql;
    //    window.clipboardData.setData("text",strSql);
    /*分页代码*/
    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 + ") ";
    }
    //    window.clipboardData.setData("text",strSql);
    var strResult = DBReader.selectSqlForJson(strSql);
    var result;
    if (strResult != null) {
        result = eval("[{" + strResult + "}]");
        result[0].pageIndex = pageIndex;
    }
    countTop = null;
    strSql = null;
    strWhere = null;

    CollectGarbage();
    return strResult == null ? null : result[0];

};

/*搜索联系人*/
jsAdrBookForCompany.EmployeeGridSearchString=function(curComID,strType,IsClickRow){
    var strWhere=[];
    if(IsClickRow!="clickRow"){
       jsAdrBookForCompany.CurCompanyGridSelRow=null;
    }
    /*当前公司ID*/
    var comID=-1;
    if(curComID!=undefined && curComID!="")
    {/*公司档案*/
        comID=curComID;
    }
    else if(jsAdrBookForCompany.CurCompanyGridSelRow!=null)
    {/*公司列表*/
        comID=jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID");       
    }  

    /*获取查询区域返回的查询条件*/
    jsCommunicationQueryCondition.GetQueryPara(strType);
    var beginTime=jsCommunicationQueryCondition.queryObj[0]._BeginTime;
    var endTime=jsCommunicationQueryCondition.queryObj[0]._EndTime;
    var empName=jsCommunicationQueryCondition.queryObj[0]._EmpName;
    var sex=jsCommunicationQueryCondition.queryObj[0]._Sex;
    var customer=jsCommunicationQueryCondition.queryObj[0]._Customer;
    var address=jsCommunicationQueryCondition.queryObj[0]._Address;
    var strQuickSearch=jsCommunicationQueryCondition.queryObj[0]._strQuickSearch;
    var advanceSearch=jsCommunicationQueryCondition.queryObj[0]._AdvancedSearch;
    var curTelNum=jsCommunicationQueryCondition.queryObj[0]._curTelNum;
    var searchType=-1;
    if(strType!=undefined && strType=="familiar")
    {/*熟悉度查询*/
        searchType=0;
    }
    else if(strType!=undefined && strType=="strange")
    {/*陌生度查询*/
      searchType=1;
    }
    else if(strType!=undefined && strType=="advanced")
    {/*高级搜索*/
       searchType=3;
    }
    else if(strType!=undefined && strType=="InComCall")
    {/*来电查询*/ 
        searchType=4;   
    }
    strWhere.push({_comID:comID,_beginTime:beginTime,_endTime:endTime,_empName:empName,_sex:sex,_customer:customer,_address:address,_strQuickSearch:strQuickSearch,_advanceSearch:advanceSearch,_curTelNum:curTelNum,_searchType:searchType});
     if(IsClickRow=="clickRow"){
        $("#tdEmployeeList").DoSearch(strWhere); 
    }
    else{
        jsAdrBookForCompany.ShowEmployeeGridPage(10,1,strWhere,"","EMPLOYEE_ID");        
    }        
    if(IsClickRow!="clickRow"){
        var strResult=DBReader.selectSqlForJson(jsAdrBookForCompany.CurEmployeeSql);
        if (strResult != null) {
               var  result = eval("[{" + strResult + "}]");
                if(result[0].result==1 && result[0].table!=undefined){
                    var strComIDList="";
                    for(var i=0;i<result[0].table.length;i++){
                        if(strComIDList!=""){
                            strComIDList+=",";
                        }
                        strComIDList+=result[0].table[i].COMPANY_ID;
                    }
                     jsAdrBookForCompany.CompanyListSearchString(strComIDList);/*刷新公司列表*/
                     jsAdrBookForCompany.ComInfoList=null;                
                    if(document.getElementById("divCompanyGrid").style.display=="none"){
                             jsAdrBookForCompany.IsListOrCardModle("com","card");
                    }
                    strComIDList=null;
                }
                else{
                      jsAdrBookForCompany.CompanyListSearchString("0");/*刷新公司列表*/
                      if(document.getElementById("divCompanyGrid").style.display==""){
                             jsAdrBookForCompany.IsListOrCardModle("com","card");
                       }                   
                }
                result=null;
         }
         strResult=null;
     }
    comID=null;beginTime=null;
    endTime=null;empName=null;
    sex=null;customer=null;
    address=null;strQuickSearch=null;
    advanceSearch=null;
    curTelNum=null;searchType=null;
    CollectGarbage();
};

/*联系人列表单击事件*/
jsAdrBookForCompany.ClickEmployeeGridRow = function(target) {
    /*单击*/
    $(target).click(function() {
        /*单选行改行样式*/
        $("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;
        /*===============*/
    });
    /*双击*/
    $(target).dblclick(function() {
        jsAdrBookForCompany.ChangeListToEmployeeCardModle();
    });
};

/*获取公司档案卡数据集*/
jsAdrBookForCompany.GetComInfoList=function(){
    if(jsAdrBookForCompany.strComIDList!="")
    {        
          var strSql="SELECT com.*,T_GROUPDEF.GROUPNAME FROM T_COMPANY as com left join T_GROUPDEF on com.GROUP_ID=T_GROUPDEF.ID WHERE com.COMPANY_ID in("+unescape(jsAdrBookForCompany.strComIDList)+")";              
         var comObj=DBReader.selectSqlForJson(strSql);
         if(comObj!=null){
            jsAdrBookForCompany.ComInfoList=eval("[{"+comObj+"}]");
         }
        strComIDList=null;
        strSql=null;
        comObj=null;
        CollectGarbage();
    }
    else
    {
        jsAdrBookForCompany.ComInfoList=null;
    }
};

/*绑定公司档案数据*/
jsAdrBookForCompany.BindCompanyData=function(){
    if(jsAdrBookForCompany.ComInfoList!=null)
    {             
           if(jsAdrBookForCompany.ComInfoList[0].result==1 && jsAdrBookForCompany.ComInfoList[0].table!=undefined)
            { 
               if(jsAdrBookForCompany.CurComID<0)
                {
                    alert("已经是第一条记录！");
                    jsAdrBookForCompany.CurComID=0;
                }
                else if(jsAdrBookForCompany.CurComID>=jsAdrBookForCompany.ComInfoList[0].table.length)
                {
                    alert("已经是最后一条记录！");
                    jsAdrBookForCompany.CurComID=jsAdrBookForCompany.ComInfoList[0].table.length-1;
                }  
                else
                {
                    if(jsAdrBookForCompany.ComInfoList[0].table.length==1){
                        $("#btnComs_Del").hide();
                        $("#btnComPrevious").hide();
                        $("#btnComNext").hide();
                    }
                    else{
                        $("#btnComs_Del").show();
                        $("#btnComPrevious").show();
                        $("#btnComNext").show();
                    }
                    $("#hhideCompanyIDC").val(jsAdrBookForCompany.ComInfoList[0].table[jsAdrBookForCompany.CurComID].COMPANY_ID);
                    $("#AllComDataCount").text(jsAdrBookForCompany.ComInfoList[0].table.length);
                    $("#CurComDataCount").text(jsAdrBookForCompany.CurComID+1);
                    jsDataResolution.SetControlDataByJsonData(document.getElementById( "divComCardContanier"),jsAdrBookForCompany.ComInfoList,jsAdrBookForCompany.CurComID);/*绑定公司控件*/
                   jsAdrBookForCompany.BindTelNumberToCallControl();/*为电话控件的电话图标添加单击事情*/

                }
                switch(jsCallMiddlePanel.listNo){
                    case "HistoryRecord":
                        jsHistoryRecord.HistoryRecordSearchString();     
                    break;
                    case "EmployeeInfo":
                        if($("#hhideCompanyIDC").val()>0){
                            $("#btnAddEmpT").show();
                            $("#btnEditEmpT").show();
                            $("#btnDelEmpT").show();
                            $("#btnSeparateC").show();
                            
                            $("#btnDelEmp").show();
                            $("#btn_DelEmps").show();
                            $("#btnAddEmp").show();
                            $("#btnSaveEmp").show();
                        }
                        if(document.getElementById("divEmployeeCrid").style.display=="")
                        {/*当前联系人信息是列表*/
                            jsAdrBookForCompany.EmployeeGridSearchString($("#hhideCompanyIDC").val(),"","clickRow");
                        }
                        else if(document.getElementById("divEmployeeCrid").style.display=="none")
                        {/*当前联系人信息是档案卡*/
                            jsAdrBookForCompany.CurEmpID=0;
                            var strEmpIDList = jsAdrBookForCompany.GetEmployeeIDListByComID($("#hhideCompanyIDC").val());
                            jsAdrBookForCompany.GetEmployeeList(escape(strEmpIDList));
                            jsAdrBookForCompany.BindEmployeeData();
                            strEmpIDList=null;
                            CollectGarbage();
                        }
                    break;
                    case "OtherInfo":
                        jsOtherInfo.OtherInfoSearchString();
                    break;    
                    default:
                    break;
                }
          
               /*处理所属分组*/
               var curComGroup_ID=jsAdrBookForCompany.ComInfoList[0].table[jsAdrBookForCompany.CurComID].GROUP_ID;
               if(curComGroup_ID>0)
               {
                    $("#curComGroup_ID").text(jsAdrBookForCompany.ComInfoList[0].table[jsAdrBookForCompany.CurComID].GROUPNAME);
                    $("#hideComCurGroupID").val(curComGroup_ID);
               }
               else
               {           
                    $("#curComGroup_ID").text("暂无");
                    $("#hideComCurGroupID").val('');
               }
               curComGroup_ID=null;
          }    
    }
    else{
        $("#hhideCompanyIDC").val('');
        $("#hhideCompanyNameC").val('');
        $("#AllComDataCount").text("0");
        $("#CurComDataCount").text("0");
        $("#frCompanyContC").resetForm();
        
        if(document.getElementById("divEmployeeCrid").style.display==""){
             jsAdrBookForCompany.EmployeeGridSearchString(0,"","clickRow");
        }
        else{
           $("#hhideEmployeeIDC").val('');
           $("#AllEmpDataCount").text("0");
           $("#CurEmpDataCount").text("0");
           $("#frPersionalContC"). resetForm();
      }
      CollectGarbage();  
    }    
};

/*上一个公司*/
jsAdrBookForCompany.BtnComPreviousClick=function(){
    $(document.body).mask("数据加载中,请稍后...");
    jsAdrBookForCompany.CurComID--; 
    jsAdrBookForCompany.BindCompanyData();
    $(document.body).unmask();
};

/*下一个公司*/
jsAdrBookForCompany.BtnComNextClick=function(){
   $(document.body).mask("数据加载中,请稍后...");
   jsAdrBookForCompany.CurComID++;
   jsAdrBookForCompany.BindCompanyData();
   $(document.body).unmask();
};

/*获取联系人档案卡数据集*/
jsAdrBookForCompany.GetEmployeeList=function(strEmpIDList){
    if(strEmpIDList!="")
    {        
         var strSql="SELECT T_EMPLOYEE.*,T_GROUPDEF.GROUPNAME FROM T_EMPLOYEE left join T_GROUPDEF on T_EMPLOYEE.GROUP_ID=T_GROUPDEF.ID WHERE T_EMPLOYEE.EMPLOYEE_ID in("+unescape(strEmpIDList)+")";          
         var empObj=DBReader.selectSqlForJson(strSql);
         if(empObj!=null){
            jsAdrBookForCompany.EmpInfoList=eval("[{"+empObj+"}]");
         }
        strEmpIDList=null;
        strSql=null;
        empObj=null;
        CollectGarbage();
    }    
    else{
            jsAdrBookForCompany.EmpInfoList=null;
    }
};

/*绑定联系人档案*/
jsAdrBookForCompany.BindEmployeeData=function(){
    if(jsAdrBookForCompany.EmpInfoList!=null)
    {
         $("#btnEmpPrevious").show();
         $("#btnEmpNext").show();
          if(jsAdrBookForCompany.EmpInfoList[0].result==1 && jsAdrBookForCompany.EmpInfoList[0].table!=undefined)
            { 
               if(jsAdrBookForCompany.CurEmpID<0)
                {
                    alert("已经是第一条记录！");
                    jsAdrBookForCompany.CurEmpID=0;
                }
                else if(jsAdrBookForCompany.CurEmpID>=jsAdrBookForCompany.EmpInfoList[0].table.length)
                {
                    alert("已经是最后一条记录！");
                    jsAdrBookForCompany.CurEmpID=jsAdrBookForCompany.EmpInfoList[0].table.length-1;
                }  
                else
                {
                   if(jsAdrBookForCompany.EmpInfoList[0].table.length==1){
                        $("#btnEmpPrevious").hide();
                        $("#btnEmpNext").hide();
                    }
                    else{
                        $("#btnEmpPrevious").show();
                        $("#btnEmpNext").show();
                    }
                    $("#hhideEmployeeIDC").val(jsAdrBookForCompany.EmpInfoList[0].table[jsAdrBookForCompany.CurEmpID].EMPLOYEE_ID);
                    $("#AllEmpDataCount").text(jsAdrBookForCompany.EmpInfoList[0].table.length);
                    $("#CurEmpDataCount").text(jsAdrBookForCompany.CurEmpID+1);
                    jsDataResolution.SetControlDataByJsonData(document.getElementById( "divEmpCardContanier"),jsAdrBookForCompany.EmpInfoList,jsAdrBookForCompany.CurEmpID);/*绑定联系人控件*/
                    jsAdrBookForCompany.BindTelNumberToCallControl();/*为电话控件的电话图标添加单击事情*/
                }
               /*处理所属分组*/
               var curEmpGroup_ID=jsAdrBookForCompany.EmpInfoList[0].table[jsAdrBookForCompany.CurEmpID].GROUP_ID;
               if(curEmpGroup_ID>0 && $("#hideComCurGroupID").val()<=0)
               {
                    $("#curComGroup_ID").text(jsAdrBookForCompany.EmpInfoList[0].table[jsAdrBookForCompany.CurEmpID].GROUPNAME);
                    $("#hideComCurGroupID").val(curEmpGroup_ID);
               }
               else{
                 if($("#hhideCompanyIDC").val()=="")
                 {
                      /*清空所属分组*/
                     $("#curComGroup_ID").text("暂无");
                     $("#hideComCurGroupID").val('');
                 }
               }
               curEmpGroup_ID=null;
          }    
    }
    else
    {
            $("#btnEmpPrevious").hide();
            $("#btnEmpNext").hide();
           $("#hhideEmployeeIDC").val("");
           $("#AllEmpDataCount").text("0");
           $("#CurEmpDataCount").text("0");
           $("#frPersionalContC").resetForm();
    }
};

/*上一个联系人*/
jsAdrBookForCompany.BtnEmpPreviousClick=function(){
    $(document.body).mask("数据加载中,请稍后...");
    jsAdrBookForCompany.CurEmpID--;
    jsAdrBookForCompany.BindEmployeeData();
    $(document.body).unmask();
};
/*下一个联系人*/
jsAdrBookForCompany.BtnEmpNextClick=function(){
    $(document.body).mask("数据加载中,请稍后...");
    jsAdrBookForCompany.CurEmpID++;
    jsAdrBookForCompany.BindEmployeeData();
    $(document.body).unmask();
};

/*为电话控件的电话图标添加单击事情*/
jsAdrBookForCompany.BindTelNumberToCallControl = function() {
    var phoneArray = $("input[contorlType='phone']");
    for (var k = 0; k < phoneArray.length; k++) {
        var isClick = phoneArray[k].isClick;
        var _img = $("img[isClick='" + isClick + "']");
        var PhoneTypeName = window.parent.jsTitle.TelephoneTypeName;
        if (PhoneTypeName == "E6" || PhoneTypeName == "E7") {
            if (_img[0].imgType == "telphone") {
                _img[0].src = "images/Tel.Gif";
                eval("_img[0].onclick=function(){jsAdrBookForCompany.TelHoldOnClickComImg(this)};");
            } else if (_img[0].imgType == "web") {
                _img[0].src = "images/htm.bmp";
                eval("_img[0].onclick=function(){jsAdrBookForCompany.WebHoldOnClickComImg(this)};");
            }
        }
        else {
            _img[0].style.display = "none";
        }
    }
};
/*打开网站*/
jsAdrBookForCompany.WebHoldOnClickComImg = function(obj) {
    var str = $.trim(obj.parentElement.children[0].value);
    if (str != "") {
        App.OpenIE(str);
    }
}

/*拨打电话控件号码*/
jsAdrBookForCompany.TelHoldOnClickComImg = function(obj) {
    var strNum = $.trim(obj.parentElement.children[0].value);
    if (strNum != "") {
        try {
            if (window.parent.PhoneHelper.Telphone_IsConnection()) {
                /*只有不是在拨打电话的状态下才能促发拨号事件*/
                if (window.parent.jsRightMessage.isPhoning == false) {
                    window.parent.jsRightMessage.isPhoning = true;
                    if (strNum != "") {
                        window.parent.execScript("jsTitle.Dial('" + strNum + "');");
                    }
                    telNum = null;
                }
            } else {
                alert("话机未连接！");
            }
        }
        catch (e) {
            alert("jsAdrBookForCompany.TelHoldOnClickImg:" + e.message);
        }
    }
};

/*列表中添加拨号图标*/
jsAdrBookForCompany.FormatTelNum = function(value, pid, rows) {
    if (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="jsAdrBookForCompany.PeopleDialImageClick(\'' + value.toString() + '\')" width="13px" height="13px" title="拨打电话"/>&nbsp;';
        }
        strShowContent+='<img alt="添加到拨号台" src="../AppFrame/APICss/default/images/icons/Item.Add.gif" onclick="jsAdrBookForCompany.TurnToTxtDialTelNo(\'' + value.toString() + '\',\'' + rows.FULL_NAME + '\')" width="13px" height="13px" title="添加到拨号台"/>&nbsp;' + value.toString() + '';
        return strShowContent;
    } else {
        return "&nbsp;";
    }
}

/*列表中添加拨号图标*/
jsAdrBookForCompany.FormatTelPersonalNum = function(value, pid, rows) {
    if (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="jsAdrBookForCompany.PeopleDialImageClick(\'' + value.toString() + '\')" width="13px" height="13px" title="拨打电话"/>';
        }
        strShowContent+='<img alt="添加到拨号台" src="../AppFrame/APICss/default/images/icons/Item.Add.gif" onclick="jsAdrBookForCompany.TurnToTxtDialTelNo(\'' + value.toString() + '\',\'' + rows.NICKNAME + '\')" width="13px" height="13px" title="添加到拨号台"/>&nbsp;' + value.toString() + '';
        return strShowContent;
    } else {
        return "&nbsp;";
    }
}
/*拨打电话*/
jsAdrBookForCompany.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("jsAdrBookForCompany.PeopleDialImageClick:"+e.message);
    }
    CollectGarbage();
};

/*添加到拨号台*/
jsAdrBookForCompany.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();
    }
};

jsAdrBookForCompany.ChangeGroupType=function(){
     var FormIndex=ShowWindow.getFormIdx();//"+$("#hideComCurGroupID").val()+"
    ShowWindow.ShowMoledDialog("Application/TeleSecretary/frmCommunication/frmGroupTree.htm?hideID=&FormIndex="+FormIndex+"&LoadAction=jsIndexPage.freshItemPage(\"tab-addressBook\",\"jsAdrBookForCompany.EditCurGroup(@str)\")","更改分组",260,500);  
    FormIndex=null;
    CollectGarbage();
};


/*更改分组*/
jsAdrBookForCompany.EditCurGroup=function(id,name){
    if(id!="")
    {
        var curComID=0;
        if($("#hhideCompanyIDC").val()>0){
            curComID=$("#hhideCompanyIDC").val();
        }
        else if(jsAdrBookForCompany.CurCompanyGridSelRow!=null){
            curComID=jsAdrBookForCompany.CurCompanyGridSelRow.attr("COMPANY_ID");
        }
        if(curComID>0)
        {
             var entity=jsEntity.CreateEntityByTableName_access("T_COMPANY","","","","COMPANY_ID");   
             entity.Fields.COMPANY_ID=curComID;
             entity.Fields.GROUP_ID=id;
             entity.Update(entity);
             DBReader.DisposeEntity(entity);   
             /*更改该公司下所有联系人的分组*/
             var txtSql="UPDATE T_EMPLOYEE SET GROUP_ID="+id+" WHERE COMPANY_ID ="+curComID;
             DBReader.execSql(txtSql);  
             txtSql=null;     
        }    
        
        /*无公司的联系人*/
        if($("#hhideEmployeeIDC").val()>0 && curComID<=0)
        {
             var empEntity=jsEntity.CreateEntityByTableName_access("T_EMPLOYEE","","","","EMPLOYEE_ID");   
             empEntity.Fields.EMPLOYEE_ID=$("#hhideEmployeeIDC").val();
             empEntity.Fields.GROUP_ID=id;
             empEntity.Update(empEntity);
             DBReader.DisposeEntity(empEntity);    
        }    
       $("#curComGroup_ID").text(name);
       $("#hideComCurGroupID").val(id); 
       jsAdrBookForCompany.GetComInfoList(); 
        jsAdrBookForCompany.BindCompanyData();
       curComID=null;  
       CollectGarbage();    
    }    
};   

jsAdrBookForCompany.LoadEmployeeInfoListTab=function(){
    jsCallMiddlePanel.listNo="EmployeeInfo";   
     jsAdrBookForCompany.LoadCompanyToolBarBtn();/*公司、联系人列表操作按钮*/
      
    jsAdrBookForCompany.LoadEmployeeGrid();/*联系人列表*/      
    jsAdrBookForCompany.LoadComAndEmpDesign();/*加载公司模式：档案卡*/
    if(jsOtherInfo.GetComID()>0){  
        jsAdrBookForCompany.EmployeeGridSearchString(jsOtherInfo.GetComID(), "", "clickRow");
        if(document.getElementById("divEmployeeCrid").style.display == "none"){
            jsAdrBookForCompany.BtnEmployeeListClick();
        }
    }
};