function jsBookCardModle(){

};
jsBookCardModle.curInfoID=0;/*当前档案卡显示数据在记录集中的下标*/
jsBookCardModle.curSelectedEmpIDList=null;/*当前列表中选中行的EmployeeID集合*/

jsBookCardModle.LoadCardModleDom=function(){
    var arrString=new  Array(); 
    var Sys = {};
    var ua = navigator.userAgent.toLowerCase();
    if (window.ActiveXObject) {
        Sys.ie = ua.match(/msie ([\d.]+)/)[1]
    }
    arrString.push("<!--通讯簿卡片操作按钮-->");
    arrString.push('<div id="card-toolbar" class="toolBotton">');
    arrString.push('  <a id="btnNewInfo" class="imgbtn"  onclick="jsBookCardModle.ChangeToAddInfo()"><span class="addComment"  title="新建档案">新建档案</span></a>');
//    arrString.push('  <a id="btnNewPreInfo" class="imgbtn"  onclick="jsBookCardModle.ChangeToAddPerInfo()"><span class="addComment"  title="新建联系人资料">新建联系人资料</span></a>');
    arrString.push('<a id="btns_Save" class="imgbtns"><span class="span-sperate" >&nbsp;</span></a>');
    arrString.push('<a id="btnSaveInfo" class="imgbtn" onclick="jsBookCardModle.SaveCallInformation()"><span class="Save"  title="保存">保存</span></a>');
    arrString.push('<a id="btnCancelAdd" class="imgbtn"  onclick="jsBookCardModle.CancelAddInfo()" style="display:none;"><span class="Cancel" title="取消" >取消</span></a>');
    arrString.push(' <a id="btnDeleteInfo" class="imgbtn" onclick="jsBookCardModle.DelelteCurInformation()"><span class="Delete" title="删除">删除</span></a>');
    arrString.push(' <a id="btnRelationNum" class="imgbtn" onclick="jsBookCardModle.OpenRelationNumWin()"><span class="Edit" title="关联档案">关联档案</span></a>');
    arrString.push('<a id="btns_Delete" class="imgbtns"><span class="span-sperate" >&nbsp;</span></a>');
    arrString.push(' <a id="btnPrevious" class="imgbtn"  onclick="jsBookCardModle.BtnPreviousClick()"><span class="arrow_up" title="上一个" >上一个</span></a>');
    arrString.push('<a id="btnNext" class="imgbtn"  onclick="jsBookCardModle.BtnNextClick()"><span class="arrow_down" title="下一个" >下一个</span></a>');
       arrString.push('<a id="btns_Next" class="imgbtns"><span class="span-sperate" >&nbsp;</span></a>');
//       arrString.push('<a id="btnImportInfo" class="imgbtn"  onclick=""><span class="Export" title="导入" >导入</span></a>');
       arrString.push('<a id="btnBookList" class="imgbtn"  onclick="jsBookCardModle.BtnBookListClick()"><span class="Export" title="列表" >列表</span></a>');
       arrString.push('<div style="float:right;"><font id="DataRecordCount" style="display:none;color:#15428B;font-weight:bold;">记录数[<span id="AllDataCount">0</span>]&nbsp;当前第[<span id="CurDataCount">0</span>]条</font></div>');
    arrString.push('</div>');
    arrString.push("<!--通讯簿卡片信息-->");
     if (Sys.ie == "6.0") {     
    arrString.push('<div style="overflow-y:auto; height:100%"><table id="tbCardInfo" cellpadding="0" cellspacing="0" style="background: #fff; width: 98%; " class="formtable">');
    }else{
    arrString.push('<div style="overflow-y:auto; height:82%"><table id="tbCardInfo" cellpadding="0" cellspacing="0" style="background: #fff; width: 98%; " class="formtable">');
    }
    arrString.push('<tr><td>');
    arrString.push('<h2 align="left">联系人资料<span id="divGroupInfo" style="color:#06A291;">——所属分组：<span id="curGroup_ID"></span><input id="hideCurGroupID" type="hidden" />&nbsp;<a id="changeGoupType"  title="更改分组" onclick="jsBookCardModle.ChangeGroupType();"><span class="select_info">更改</span></a></span></h2>');
    arrString.push('</td></tr>');
    arrString.push('<tr><td id="tdPersonalInfo"></td></tr>');
    arrString.push('<tr id="trCompanyInfo"><td><h2 align="left">单位资料&nbsp;&nbsp;<input id="btnViewCom" type="button" class="buttonList" value="更改公司" onclick="jsBookCardModle.OpenSelCompanyWin()" style="width:60px; " /></h2> </td></tr>');
        arrString.push('<tr><td id="tdCompanyInfo"></td></tr>');
    arrString.push('</table></div>');
    document.getElementById("callCardModle").innerHTML=arrString.join("");
    
    jsBookCardModle.LoadPersionalInfoDom();
};

/*关联号码弹出框*/
jsBookCardModle.OpenRelationNumWin=function(){
     var formIndex=ShowWindow.getFormIdx();
     var objArr = $("input[Field='TEL1']");
     var strNum=objArr[0].value;
     if(strNum!=null && strNum!=""){
     ShowWindow.ShowMoledDialog("Application/TeleSecretary/frmRelationTelNumber.htm?strNum="+escape(strNum)+"&formIndex="+formIndex+"&action=jsIndexPage.freshItemPage('tab-addressBook','jsBookCardModle.AssociationTelNum(\"@comID\",\"@empID\")')","关联档案",800,500);
     }else{
        alert("没有可供关联的号码，以固话1为准！");
     }
    formIndex=null;
    objArr.length=0;
    objArr=null;
    strNum=null;
    CollectGarbage();     
};

/*关联号码*/
jsBookCardModle.AssociationTelNum=function(ComID,EmpID){
   if(EmpID>0){
     alert("关联档案成功！");
     jsBookCardModle.EditSelectedRowData(ComID,EmpID);
     jsBookListModle.BookListSearchString();
   }else{
    alert("关联档案失败！");
   }
};

/*加载档案设计界面*/
jsBookCardModle.LoadPersionalInfoDom=function(){
  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("jsBookCardModle.PersionalOrCompanyInfo('per')",100); 
       divObj[0].removeChild(document.getElementById(scriptObj.id)); 
        scriptObj=null;
        divObj=null;
//        App.SetNullHref(1);
   }
   if(App.FileIsExist(escape(App.ApplicationPath()+"Application\\TeleSecretary\\js\\jsDepartmentInformation.js"))){    
        App.SetNullHref(0);
        $("#trCompanyInfo").show();
        var comObj=document.getElementsByTagName("HEAD");
        var comScriptObj=document.createElement("script");
        comScriptObj.src="js/jsDepartmentInformation.js";
        comScriptObj.id="js_DepartmentInformation";
        comObj[0].appendChild(comScriptObj);
        setTimeout("jsBookCardModle.PersionalOrCompanyInfo('com')",150);  
        comObj[0].removeChild(document.getElementById(comScriptObj.id)); 
        comScriptObj=null;
        comObj=null;
        //App.SetNullHref(1);
   }else{
         $("#trCompanyInfo").hide();
   }
};

/*显示用户设置的个人及单位资料界面*/
jsBookCardModle.PersionalOrCompanyInfo = function(strType) {
    var arrTable = new Array();
    var obj = null;
    if (strType == "per") {
        arrTable.push('<form id="frPersionalCont" ><input id="hhideEmployeeID" type="hidden" /><table id="tbDesignPersionalInfo" cellpadding="0" cellspacing="0"  style="width:100%;">');
        obj = eval(unescape(jsPersonalInformation.dataJSON));
    }
    else if (strType == "com") {
        arrTable.push('<form id="frCompanyCont" ><input id="hhideCompanyID" type="hidden" /><table id="tbDesignCompanyInfo" cellpadding="0" cellspacing="0"  style="width:100%">');
        arrTable.push('<tr><td>单位名称</td><td colspan="3"><INPUT id="hhideCompanyName" type="hidden" Field="SIMPLE_NAME"/><INPUT type="text" class="ipt" id="txtCompanyName" Field="SIMPLE_NAME" style="width:' + document.body.clientWidth * 0.5 + 'px;"/></td></tr>');
        obj = eval(unescape(jsDepartmentInformation.dataJSON));
        if (obj[0].length == 0) {
            document.getElementById("trCompanyInfo").style.display = "none";
            document.getElementById("tdCompanyInfo").style.display = "none";
        }
    }
    for (var i = 0; i < obj.length; i++) {
        arrTable.push("<tr>");
        for (var j = 0; j < obj[i].length; j++) {
            arrTable.push("<td style='width:100px;'>" + unescape(obj[i][j].title) + "</td>");
            if (obj[i].length == 1) {
                arrTable.push("<td colspan='3'>" + unescape(obj[i][j].content) + "</td>");
            } else {
                arrTable.push("<td>" + unescape(obj[i][j].content) + "</td>");
            }
        }
        arrTable.push("</tr>");
    }
    arrTable.push("<table/></form>");
    if (strType == "per") {
        document.getElementById("tdPersonalInfo").innerHTML = arrTable.join("");
        jsPersonalInformation.initControl();
        var tdArray = document.getElementById("tdPersonalInfo").getElementsByTagName("TD");
        App.SetNullHref(0);
        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.id = _child.id + "_" + Math.random();
                    if (_child.tagName == "TEXTAREA") {
                        eval("_child.onkeydown=function(){jsTextEare.setEnterKey(this);};");
                    }
                }
                _child = null;
            }
            else if (tdArray[p].childNodes[0] != null && tdArray[p].childNodes[0].tagName == "TEXTAREA") {
                eval("tdArray[p].childNodes[0].onkeydown=function(){jsTextEare.setEnterKey(this);};");
            }
        }
        tdArray = null;
    }
    else if (strType == "com") {
        document.getElementById("tdCompanyInfo").innerHTML = arrTable.join("");
        var tdArray = document.getElementById("tdCompanyInfo").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.5 - 10;
                    if (_child.tagName == "TEXTAREA") {
                        eval("_child.onkeydown=function(){jsTextEare.setEnterKey(this);};");
                    }
                }
                _child = null;
            }
            else if (tdArray[p].childNodes[0] != null && tdArray[p].childNodes[0].tagName == "TEXTAREA") {
                eval("tdArray[p].childNodes[0].onkeydown=function(){jsTextEare.setEnterKey(this);};");
            }
        }
        tdArray = null;
    }
    arrTable.length = 0;
    arrTable = null;
    obj = null;
    CollectGarbage();
};

/*打开更改公司弹出框*/
jsBookCardModle.OpenSelCompanyWin=function(){
     var formIndex=ShowWindow.getFormIdx();
     ShowWindow.ShowMoledDialog("Application/TeleSecretary/frmSelectCompany.htm?comName="+escape($("#txtCompanyName").val())+"&formIndex="+formIndex+"&action=jsIndexPage.freshItemPage('tab-addressBook','jsBookCardModle.ChangeComIDValue(\"@ComID\",\"@ComName\",\"@GroupID\")')","更改公司",600,440);
};

/*更改公司*/
jsBookCardModle.ChangeComIDValue=function(ComID,ComName,GroupID){
    if($("#hhideCompanyID").val()!=ComID)
    {
        if($("#hhideEmployeeID").val()>0){
            var empGroupID=jsCommonLogic.selColumnData("GROUP_ID","T_EMPLOYEE","WHERE EMPLOYEE_ID="+$("#hhideEmployeeID").val());          
             var entity=jsEntity.CreateEntityByTableName_access("T_EMPLOYEE","","","","EMPLOYEE_ID");   
             entity.Fields.EMPLOYEE_ID=$("#hhideEmployeeID").val();
             entity.Fields.COMPANY_ID=ComID;      
             if(empGroupID!=GroupID){
                entity.Fields.GROUP_ID=GroupID;
            }
            var result = entity.Update(entity);
            if(result){
                jsBookCardModle.UpdateCallBillInfoWhenChageData();
             }    
             DBReader.DisposeEntity(entity);
             result=null;
         }
         jsBookCardModle.EditSelectedRowData(ComID,$("#hhideEmployeeID").val());                      
         CollectGarbage();
    }
};

/*列表*/
jsBookCardModle.BtnBookListClick=function(){
//    var strType="";
//    if(jsCommunicationQueryCondition.queryObj[0]._Type==0){/*熟悉度查询*/
//        strType="familiar";
//    }
//    else if(jsCommunicationQueryCondition.queryObj[0]._Type==1){/*陌生度查询*/
//       strType="strange";
//    }
//    else if(jsCommunicationQueryCondition.queryObj[0]._Type==3){/*高级搜索*/
//       strType="advanced";
//    }
//    else if(jsCommunicationQueryCondition.queryObj[0]._Type==4){/*来电查询*/ 
//        strType="InComCall";   
//    }
//     jsBookListModle.BookListSearchString(strType);
     jsBookListModle.AddressBookGrid.flexReload();
     jsHistoryRecord.HistoryCallGrid.clearRow();/*刷新主列表时清空历史记录*/
     jsCallBookList.IsListOrCardModle('Card');
     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);
     }
     
    $("#btnCancelAdd").hide();
    $("#btnDeleteInfo").show();
};
/*上一个*/
jsBookCardModle.BtnPreviousClick=function(){
    $(document.body).mask("数据加载中,请稍后...");
    jsBookCardModle.curInfoID= jsBookCardModle.curInfoID-1;
    jsBookCardModle.BindData();
    $(document.body).unmask();    
};
/*下一个*/
jsBookCardModle.BtnNextClick=function(){     
    $(document.body).mask("数据加载中,请稍后...");          
    jsBookCardModle.curInfoID= jsBookCardModle.curInfoID+1;
    jsBookCardModle.BindData();  
   $(document.body).unmask();
};

/*取消*/
jsBookCardModle.CancelAddInfo=function(){
    $("#btnCancelAdd").hide();
    $("#btnDeleteInfo").show();
    jsBookCardModle.BindData();
};
/*新建联系人档案*/
jsBookCardModle.ChangeToAddPerInfo=function(){
    $("#btnCancelAdd").show();
    $("#btnDeleteInfo").hide();
    
    $("#hhideEmployeeID").val('');
    $("#frPersionalCont").resetForm();
    var dateObj = $(".Wdate");
    for(var i=0;i<dateObj.length;i++){
        dateObj[i].value="";
    }
};
/*新建档案*/
jsBookCardModle.ChangeToAddInfo = function() {
    App.SetNullHref(0);
    $("#btnCancelAdd").show();
    $("#btnDeleteInfo").hide();
    $("#btnPrevious").hide();
    $("#btnNext").hide();
    $("#btns_Next").hide();
    
    $("#hhideEmployeeID").val('');
    $("#hhideCompanyName").val('');
    $("#hhideCompanyID").val('');
    /*清空个人资料与单位资料*/
    $("#frPersionalCont").resetForm();
    $("#frCompanyCont").resetForm();
    
    if(jsCommunicationQueryCondition.curSelNode!=null){
        if(jsCommunicationQueryCondition.curSelNode.id>0){
            $("#curGroup_ID").text(jsCommunicationQueryCondition.curSelNode.text);
            $("#hideCurGroupID").val(jsCommunicationQueryCondition.curSelNode.id);
        }else{
            /*清空所属分组*/
            $("#curGroup_ID").text("暂无");
            $("#hideCurGroupID").val('');
        }
    }else{
        /*清空所属分组*/
        $("#curGroup_ID").text("暂无");
        $("#hideCurGroupID").val('');
    }
    /*隐藏其它资料的添加行*/
    if(document.getElementById("imgAddOtherInfoRow")!=undefined){
          document.getElementById("imgAddOtherInfoRow").style.display="none";
    }
    var dateObj = $(".Wdate");
    for (var i = 0; i < dateObj.length; i++) {
        dateObj[i].value = "";
    }
    
    jsCallMiddlePanel.FreashTabDetailInfo();/*刷新主表时，清空明细表*/
};
/*删除*/
jsBookCardModle.DelelteCurInformation=function(){
  if(confirm("确定要删除？"))
    {
         var empID=$("#hhideEmployeeID").val();
         var comID=$("#hhideCompanyID").val();
         if(empID>0)
         {           
             var result= jsBookListModle.DeleteAllSelData(empID,comID);
             if(result)
             {
                    var strEmpIDList="";
                    var arrEmpID=unescape(jsBookCardModle.curSelectedEmpIDList).split(",");
                    for(var i=0;i<arrEmpID.length;i++)
                    {
                        if(strEmpIDList!="")
                        {
                            strEmpIDList+=",";
                        }
                        if(arrEmpID[i]!=empID)
                        {
                            strEmpIDList+=arrEmpID[i];
                        }
                    }
                    jsBookCardModle.curSelectedEmpIDList=escape(strEmpIDList);
                    if(jsBookCardModle.curSelectedEmpIDList!="")
                    {
                        jsBookCardModle.BindData();
                    }
                    else
                    {                                    
                          jsBookListModle.AddressBookGrid.flexReload();
                         jsCallBookList.IsListOrCardModle('Card');
                    }
                }
                else
                {
                    alert("删除失败!");
                }
           
         }
   }
};

/*保存用户信息*/
jsBookCardModle.SaveCallInformation = function() {
    $(document.body).mask("数据保存中,请稍后...");
    try {
        var result = -1;
        var comSimpleName = $("#txtCompanyName").val().split('\"').join('“').split('\'').join('‘');
        var entity = jsEntity.CreateEntityByTableName_access("T_COMPANY", "", "", "", "COMPANY_ID");
        var comObj = document.getElementById("tbDesignCompanyInfo");
        jsDataResolution.GetControlData(comObj, entity);

        var employeeObj = document.getElementById("tbDesignPersionalInfo");
        var employeeEntity = jsEntity.CreateEntityByTableName_access("T_EMPLOYEE", "COMPANY_ID", "T_COMPANY", "COMPANY_ID", "EMPLOYEE_ID");
        jsDataResolution.GetControlData(employeeObj, employeeEntity); /*通过页面控件获得实体*/
        if($("#hideCurGroupID").val()>0){
            employeeEntity.Fields.GROUP_ID=$("#hideCurGroupID").val();
        }
        if (comSimpleName != "") {/*联系人与公司都有信息*/
            var companyID = jsCommonLogic.selColumnData("COMPANY_ID", "T_COMPANY", "WHERE SIMPLE_NAME='" + comSimpleName + "' and SIMPLE_NAME<>'" + $("#hhideCompanyName").val() + "'");
            if ($("#hhideCompanyID").val() > 0) {/*修改时*/
                if (companyID > 0) {/*修改公司时新名称重名*/
                    alert("已存在该单位简称！");
                    $("#txtCompanyName").val($("#hhideCompanyName").val());
                    $("#txtCompanyName").focus();
                }
                else {/*修改联系人，修改公司*/
                    if ($("#hhideEmployeeID").val() > 0) {
                        employeeEntity.Fields.EMPLOYEE_ID = $("#hhideEmployeeID").val();
                        entity.appendEntity(employeeEntity, App.SqlAction.Update);
                    }
                    else {/*新建个人档案*/
                        if(employeeEntity.Fields.NAME!=""){
                            employeeEntity.Fields.COMPANY_ID = $("#hhideCompanyID").val();
                            entity.appendEntity(employeeEntity, App.SqlAction.Insert);
                        }
                    }
                    entity.Fields.COMPANY_ID = $("#hhideCompanyID").val();
                    if ($("#hideCurGroupID").val() > 0) {
                        entity.Fields.GROUP_ID = $("#hideCurGroupID").val();
                    }
                    result = entity.Update(entity);
                    if (result) {
                        alert("保存成功！");   
                        DBReader.setItemEntityKeyFieldValue(entity,employeeEntity);
                        $("#hhideEmployeeID").val(employeeEntity.Fields.EMPLOYEE_ID);//alert("1:"+employeeEntity.Fields.EMPLOYEE_ID);  
                        $("#hhideCompanyID").val(entity.Fields.COMPANY_ID);//alert("1:"+entity.Fields.COMPANY_ID);
                        $("#hhideCompanyName").val(entity.Fields.SIMPLE_NAME);
                        $("#btnCancelAdd").hide();
                        $("#btnDeleteInfo").show();
                        jsBookListModle.BookListSearchString();
                        jsBookCardModle.UpdateCallBillInfoWhenChageData();/*更改通话记录信息*/
                    }
                    else {
                        alert("保存失败，请检查填写内容！");
                    }
                }
            }
            else {/*添加时*/
                if (companyID > 0) {
                    entity.Fields.COMPANY_ID = companyID;
                    
                    if ($("#hideCurGroupID").val() > 0) {
                        entity.Fields.GROUP_ID = $("#hideCurGroupID").val();
                    }
                    if ($("#hhideEmployeeID").val() > 0) {/*公司已存在，并且修改联系人*/
                        employeeEntity.Fields.EMPLOYEE_ID = $("#hhideEmployeeID").val();
                        employeeEntity.Fields.COMPANY_ID = companyID;
                        entity.appendEntity(employeeEntity, App.SqlAction.Update);
                    }
                    else {/*公司已存在，并且添加联系人*/
                        if(employeeEntity.Fields.NAME!=""){
                            employeeEntity.Fields.COMPANY_ID = companyID;
                            entity.appendEntity(employeeEntity, App.SqlAction.Insert);
                        }
                    }
                    result = entity.Update(entity);
                }
                else {
                    if ($("#hhideEmployeeID").val() > 0) {/*添加公司，修改联系人*/
                        employeeEntity.Fields.EMPLOYEE_ID = $("#hhideEmployeeID").val();
                        entity.appendEntity(employeeEntity, App.SqlAction.Update);
                    }
                    else {/*添加公司，添加联系人*/
                        if(employeeEntity.Fields.NAME!=""){
                             entity.appendEntity(employeeEntity, App.SqlAction.Insert);
                        }
                    }
                    
                    if ($("#hideCurGroupID").val() > 0) {
                        entity.Fields.GROUP_ID = $("#hideCurGroupID").val();
                    }
                    result = entity.Insert(entity);
                    DBReader.setItemEntityKeyFieldValue(entity, employeeEntity);

                    /*将新增的主表ID更新到明细表*/
                    employeeEntity.Fields.COMPANY_ID = entity.Fields.COMPANY_ID;
                    employeeEntity.Update(employeeEntity);
                }
                if (result) {
                    alert("保存成功！"); //alert("Add:"+employeeEntity.Fields.EMPLOYEE_ID);alert("Add:"+entity.Fields.COMPANY_ID);
                    $("#hhideEmployeeID").val(employeeEntity.Fields.EMPLOYEE_ID); 
                    $("#hhideCompanyID").val(entity.Fields.COMPANY_ID); /*返回的EMPLOYEE_ID*/
                    $("#hhideCompanyName").val(entity.Fields.SIMPLE_NAME); //alert("Add:"+entity.Fields.SIMPLE_NAME);
                    $("#btnCancelAdd").hide();
                    $("#btnDeleteInfo").show();
                    jsBookListModle.BookListSearchString();
                    jsBookCardModle.UpdateCallBillInfoWhenChageData();/*更改通话记录信息*/
                }
                else {
                    alert("保存失败，请检查填写内容！");
                }
            }
        }
        else if (comSimpleName == "") {       
           if(employeeEntity.Fields.NAME!=""){
                if ($("#hhideEmployeeID").val() > 0) {/*只修改联系人*/
                    employeeEntity.Fields.EMPLOYEE_ID = $("#hhideEmployeeID").val();
                    result = employeeEntity.Update(employeeEntity);
                }
                else {/*只添加联系人*/
                        result = employeeEntity.Insert(employeeEntity);
                }
                if (result) {
                    alert("保存成功！");
                    $("#btnCancelAdd").hide();
                    $("#btnDeleteInfo").show();
                    $("#hhideEmployeeID").val(employeeEntity.Fields.EMPLOYEE_ID);
                    jsBookListModle.BookListSearchString();
                    jsBookCardModle.UpdateCallBillInfoWhenChageData();/*更改通话记录信息*/
                }
                else {
                    alert("保存失败，请检查填写内容！");
                }
            }
            else{
                alert("联系人名称不能为空！");
            }
        }
    }
    catch (e) {
        alert("ERROR FOR jsBookCardModle.SaveCallInformation" + e.message);
    }

    $(document.body).unmask();
    result = null;
    comSimpleName = null; companyID = null;
    comObj = null; employeeObj = null;
    DBReader.DisposeEntity(employeeEntity);
    DBReader.DisposeEntity(entity);
    CollectGarbage();
};

jsBookCardModle.BindData=function(){
    if(jsBookCardModle.curSelectedEmpIDList!=null)
    {
        var  strSql="SELECT EMPLOYEE_ID,COMPANY_ID FROM T_EMPLOYEE WHERE EMPLOYEE_ID in("+unescape(jsBookCardModle.curSelectedEmpIDList)+")";
//        alert(strSql);
        var obj= DBReader.selectSqlForJson(strSql);//alert(obj);
        var result;
        if(obj!=null)
        {
            result=eval("[{"+obj+"}]");
            if(result[0].result==1)
            {
                var allCount=result[0].table.length;
                if(jsBookCardModle.curInfoID<0)
                {
                    alert("已经是第一条信息了！");
                    jsBookCardModle.curInfoID=0;
                }
                else if(jsBookCardModle.curInfoID>=allCount)
                {
                    alert("已经是最后一条信息了!");
                    jsBookCardModle.curInfoID=(allCount-1);
                }
                else
                {
                    /*jsDataResolution.SetControlDataByJsonData(document.getElementById( "tbCardInfo"),result,jsBookCardModle.curInfoID);*/
                    var comID=result[0].table[jsBookCardModle.curInfoID].COMPANY_ID;
                    var empID=result[0].table[jsBookCardModle.curInfoID].EMPLOYEE_ID;
                    jsBookCardModle.EditSelectedRowData(comID,empID);
                    jsBookCardModle.BindTelNumToCallControl();/*为电话控件的电话图标添加单击事情*/
                }
                $("#AllDataCount").text(allCount);
                $("#CurDataCount").text(jsBookCardModle.curInfoID+1);
                if(allCount==1){                     
                    $("#btnPrevious").hide();
                    $("#btnNext").hide();
                    $("#btns_Next").hide();
                }  
                else{               
                    $("#btnPrevious").show();
                    $("#btnNext").show();
                    $("#btns_Next").show();
                }
//                window.clipboardData.setData("text",document.getElementById("tbCardInfo").innerHTML);
            }
        }
    }   
};

/*拨打电话控件号码*/
jsBookCardModle.TelHoldOnClickImg=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("jsBookCardModle.TelHoldOnClickImg:"+e.message);
            }
    }
};

/*打开网站*/
jsBookCardModle.WebHoldOnClickImg = function(obj) {
    var str = $.trim(obj.parentElement.children[0].value);
    if (str != "") {
        App.OpenIE(str);
    }
    str = null;
    CollectGarbage();
}
/**/
jsBookCardModle.ChangePhoneValueIsClick = function() {

}
/*为电话控件的电话图标添加单击事情*/
jsBookCardModle.BindTelNumToCallControl = 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(){jsBookCardModle.TelHoldOnClickImg(this)};");
            } else if (_img[0].imgType == "web") {
                _img[0].src = "images/htm.bmp";
                eval("_img[0].onclick=function(){jsBookCardModle.WebHoldOnClickImg(this)};");
            }
        }
        else {
            _img[0].style.display = "none";
        }
    }
};

/*保存档案时更改通话记录中关联号码的档案相关值*/
jsBookCardModle.UpdateCallBillInfoWhenChageData=function(){
//    var phoneArray=$("input[contorlType='phone']");
//    for(var i=0;i<phoneArray.length;i++){
//        if(phoneArray[i].value!=""){
            var comID=$("#hhideCompanyID").val()==""?0:$("#hhideCompanyID").val();
            var empID=$("#hhideEmployeeID").val()==""?0:$("#hhideEmployeeID").val();
            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;

//        }
//    }
//    phoneArray=null;
    CollectGarbage();
};

/*更改通话记录*/
jsBookCardModle.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();
};
  
jsBookCardModle.EditSelectedRowData=function(comID,empID){
    $("#hhideCompanyID").val(comID);
    $("#hhideEmployeeID").val(empID);
    jsBookCardModle.BindDataByComIDAndEmpID(comID,empID);
};

jsBookCardModle.BindDataByComIDAndEmpID=function(comID,empID){
    if(comID>0)
    {
        var strCompany="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="+comID;
        var comObj=DBReader.selectSqlForJson(strCompany);
        if(comObj!=null)
        {
            var comResult=eval("[{"+comObj+"}]");
            if(comResult[0].result==1 && comResult[0].table!=undefined)
            {
                   jsDataResolution.SetControlDataByJsonData(document.getElementById( "tbDesignCompanyInfo"),comResult);
                   /*处理所属分组*/
                   var curGroup_ID=comResult[0].table[0].GROUP_ID;
                   if(curGroup_ID>0)
                   {
                        $("#curGroup_ID").text(comResult[0].table[0].GROUPNAME);
                        $("#hideCurGroupID").val(curGroup_ID);
                   }
                   else
                   {           
                        $("#curGroup_ID").text("暂无");
                        $("#hideCurGroupID").val('');
                   }
                   curGroup_ID=null;
            }
            else
            {
                    $("#frCompanyCont").resetForm();
                    var dateObj = $(".Wdate");
                    for(var i=0;i<dateObj.length;i++){
                        dateObj[i].value="";
                    }
            }
            comResult=null;
        }
        comObj=null;
    }
     else
    {
            $("#frCompanyCont").resetForm();
            var dateObj = $(".Wdate");
            for(var i=0;i<dateObj.length;i++){
                dateObj[i].value="";
            }
    }
    
    if(empID>0){
        var strEmployee="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="+empID;
        var empObj=DBReader.selectSqlForJson(strEmployee);
        if(empObj!=null)
        {
            var empResult=eval("[{"+empObj+"}]");
             if(empResult[0].result==1 && empResult[0].table!=undefined)
             {
                  jsDataResolution.SetControlDataByJsonData(document.getElementById( "tbDesignPersionalInfo"),empResult);
                    /*网络搜索
                 if(jsCallMiddlePanel.listNo=="webSearch"){
                     window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strTelNum=empResult[0].table[0].MOBILE;
                    window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strComName=empResult[0].table[0].NAME;
                    window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.strPhone=empResult[0].table[0].TEL1;
                }*/
                   /*处理所属分组*/
                   var curEmpGroup_ID=empResult[0].table[0].GROUP_ID;
                   if(curEmpGroup_ID>0)
                   {
                        $("#curGroup_ID").text(empResult[0].table[0].GROUPNAME);
                        $("#hideCurGroupID").val(curEmpGroup_ID);
                   }
                   else
                   {       
                        if($("#hhideCompanyID").val()==""){
                            $("#curGroup_ID").text("暂无");
                            $("#hideCurGroupID").val('');
                        }
                   }
                   curEmpGroup_ID=null;
            }
            else
            {
                 $("#frPersionalCont").resetForm();
                    var dateObj = $(".Wdate");
                    for(var i=0;i<dateObj.length;i++){
                        dateObj[i].value="";
                    }
            }
            empResult=null;
        }
        empObj=null;
    }
  else
    {
        if($("#hhideEmployeeID").val()>0){
             $("#frPersionalCont").resetForm();
                var dateObj = $(".Wdate");
                for(var i=0;i<dateObj.length;i++){
                    dateObj[i].value="";
                }
        }
    }

     switch (jsCallMiddlePanel.listNo) {
           case "HistoryRecord":
                jsHistoryRecord.HistoryRecordSearchString();    
           break;
           case "OtherInfo":
                jsOtherInfo.OtherInfoSearchString();
           break;    
//           case "webSearch":          
//               window.frames["tab_item_frame_tab-webSearch"].document.getElementById("fontPhone").style.display="";               
//               window.frames["tab_item_frame_tab-webSearch"].jsWebSearch.searchInfo();
//            break;
           default:
           break;      
     }        
    strCompany="";
    strEmployee="";
    CollectGarbage();
};

/*来电、去电时加载没有档案的号码*/
jsBookCardModle.SetTelNumDefInfo=function(strNum){
    var objArr = $("input[Field='TEL1']");
    if(objArr.length>0){
       objArr[0].value=strNum;
    }
    objArr.length=0;
    objArr=null;
    CollectGarbage();
};

/*更改分组弹出框*/
jsBookCardModle.ChangeGroupType=function(){
    var FormIndex=ShowWindow.getFormIdx();//+$("#hideCurGroupID").val()+
    ShowWindow.ShowMoledDialog("Application/TeleSecretary/frmCommunication/frmGroupTree.htm?hideID=&FormIndex="+FormIndex+"&LoadAction=jsIndexPage.freshItemPage(\"tab-addressBook\",\"jsBookCardModle.EditCurGroup(@str)\")","更改分组",260,500);  
};
/*更改分组*/
jsBookCardModle.EditCurGroup=function(id,name){
    if(id!="")
    {
        if($("#hhideCompanyID").val()>0)
        {
             var entity=jsEntity.CreateEntityByTableName_access("T_COMPANY","","","","COMPANY_ID");   
             entity.Fields.COMPANY_ID=$("#hhideCompanyID").val();
             entity.Fields.GROUP_ID=id;
             entity.Update(entity);
             DBReader.DisposeEntity(entity);
             /*更改公司下所有联系人分组*/
            var txtSql="UPDATE T_EMPLOYEE SET GROUP_ID="+id+" WHERE COMPANY_ID ="+$("#hhideCompanyID").val();
            DBReader.execSql(txtSql);    
            txtSql=null;   
        }     
        /*无公司的联系人更改组*/
        if($("#hhideEmployeeID").val()>0 && $("#hhideCompanyID").val()=="")
        {
             var empEntity=jsEntity.CreateEntityByTableName_access("T_EMPLOYEE","","","","EMPLOYEE_ID");   
             empEntity.Fields.EMPLOYEE_ID=$("#hhideEmployeeID").val();
             empEntity.Fields.GROUP_ID=id;
             empEntity.Update(empEntity);
             DBReader.DisposeEntity(empEntity);    
        }     
       $("#curGroup_ID").text(name);
       $("#hideCurGroupID").val(id);   
       CollectGarbage();   
    }    
};