function jsTelBillCenterContent() {
};
/*记录列表*/
jsTelBillCenterContent.CurrentColumnGrid = null;
/*查询数据sql语句*/
jsTelBillCenterContent.CurrentSql="";
/*列表中当前选中的行*/
jsTelBillCenterContent.CurBillListSelectedMainRow=null;
/*是否修改统计——全部*/
jsTelBillCenterContent.IsEditAllCount=true;

jsTelBillCenterContent.showPage = function() {
    jsTelBillCenterContent.inputDom();
    jsTelBillCenterContent.initColumnGrid();
    jsTelBillCenterContent.GetCallRecordCount();
};

/*加载dom*/
jsTelBillCenterContent.inputDom = function() {
    var dom = document.getElementById("centerContent");
    var allString = [];
    allString.push('<div id="div-left-menu-content" class="div-left-menu-content" style="line-height:25px;background-color:#fff;">');  
    allString.push('<div  class="div-title"><div class="div-title-name">通话记录表</div></div>');
    allString.push('<div id="CallTypeTitelContanier" style="color:#15428B;font-weight:bold;"><label><input type="checkbox" value="-1" onclick="jsTelBillCenterContent.CallRecordSearchString(\'chk\',-1)"/>全部[&nbsp;<span id="allCount">0</span>&nbsp;]</label>');
    allString.push('<label><input type="checkbox" value="1" onclick="jsTelBillCenterContent.CallRecordSearchString(\'chk\',1)"/>来电[&nbsp;<span id="comeCount">0</span>&nbsp;]</label>');
    allString.push('<label><input type="checkbox" value="2" onclick="jsTelBillCenterContent.CallRecordSearchString(\'chk\',2)"/>去电[&nbsp;<span id="goCount">0</span>&nbsp;]</label>');
    allString.push('<label><input type="checkbox" value="0" onclick="jsTelBillCenterContent.CallRecordSearchString(\'chk\',0)"/>未接[&nbsp;<span id="otherCount">0</span>&nbsp;]</label>&nbsp;&nbsp;');
    allString.push("<div>");
    allString.push('<input id="btnExport" type="button" value="删除选中话单" class="button" onclick="jsTelBillCenterContent.DeleteSelCallBillRecord()" style="width:90px;"/>');
    allString.push('&nbsp;<input id="btnExport" type="button" value="导出列表话单" class="button" onclick="jsTelBillCenterContent.ExportCallBillRecordData()" style="width:90px;"/>');
    allString.push('&nbsp;<input id="btnExportSel" type="button" value="导出选中话单" class="button" onclick="jsTelBillCenterContent.ExportSelectCallBillRecord()" style="width:90px;"/>');
    allString.push('&nbsp;<input id="btnExport" type="button" value="导出列表录音" class="button" onclick="jsTelBillCenterContent.ExportCurAllAudio()" style="width:90px;"/>');
    allString.push('&nbsp;<input id="btnExport" type="button" value="导出选中录音" class="button" onclick="jsTelBillCenterContent.ExportSelectedAudio()" style="width:90px;"/>');
    allString.push("</div>");
    allString.push("</div>");
    allString.push('<table id="tbCenterContentColumn"></table>');
    allString.push('</div>');
    dom.innerHTML = allString.join("");
    dom=null;
    allString.length=0;
    allString=null;
    CollectGarbage();
    
    if(window.parent.jsIndexPage.IsCallReOrBookReg){
        jsTelBillCenterContent.RegCallAction();
    }
}

jsTelBillCenterContent.RegCallAction=function(){

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

/*生成表头及字段*/
jsTelBillCenterContent.SetExcelTableTitle=function()
{
    var FieldObj=new Object();
    FieldObj.Count=7;
    FieldObj.Caption=new Array();
    FieldObj.FieldName=new Array();
//    var excelHeaderName="电话号码,类型,归属地,名字,通话时长,通话时间,通话状态,通话备注";
//    var excelHeadField="TELNUM,CALLTYP,AREATXT,CUSTOMER,TALKLENGTH,CALLTIME,Type,REMARK";
    var excelHeaderName="电话号码,类型,归属地,通话时长,通话时间,通话状态,通话备注";
    var excelHeadField="TELNUM,CALLTYP,AREATXT,TALKLENGTH,CALLTIME,Type,REMARK";
    FieldObj.Caption=[];
    FieldObj.Caption=excelHeaderName.split(",");
    excelHeaderName=null;
    FieldObj.FieldName=[];
    FieldObj.FieldName=excelHeadField.split(",");
    excelHeadField=null;
    
    var strList=FieldObj;    
    FieldObj=null;
    CollectGarbage();
    return strList;
}

/*导出选中话单*/
jsTelBillCenterContent.ExportSelectCallBillRecord=function(){
   if( jsTelBillCenterContent.CurrentColumnGrid.getSelectedRows().length>0)
    {     
       $(document.body).mask("数据导出中,请稍后...");
        var strBillIDList="";
        $(jsTelBillCenterContent.CurrentColumnGrid.getSelectedRows()).each(function(){
            if(strBillIDList!="")
            {
                strBillIDList+=",";
            }
            strBillIDList+=$(this).attr("BILLID");           
        });     
        var strSql = "SELECT T_CALLBILL.BILLID,T_CALLBILL.TELNUM,iif(T_CALLBILL.CALLTYP=0,'未接',iif(T_CALLBILL.CALLTYP=1,'来电',iif(T_CALLBILL.CALLTYP=2,'去电'))) as CALLTYP,T_CALLBILL.AREATXT,iif(ISNULL(T_CALLBILL.CUSTOMER),'无',T_CALLBILL.CUSTOMER) as CUSTOMER,T_CALLBILL.TALKLENGTH,Format(T_CALLBILL.CALLTIME,'yyyy-MM-dd hh:mm:ss') as CALLTIME,iif(T_MP3RECORD.MP3ID is null,0) AS MP3ID,T_CALLBILL.Type,T_CALLBILL.REMARK FROM T_Callbill left join T_MP3RECORD ON T_CALLBILL.BILLID=T_MP3RECORD.BILLID WHERE T_CALLBILL.BILLID IN("+strBillIDList+")";
        var obj = DBReader.selectSql(strSql, "T_CALLBILL"); 
        if(DBReader.DObjectIsNull(obj)==false)
        {
            if(parseInt(obj.RecordCount)>0)
            {
                 var _FieldData=jsTelBillCenterContent.SetExcelTableTitle(); //表头、字段、列数
                 App.ExportExcel(_FieldData,obj);
                 _FieldData=null;
            }
        }
        else
        {
            alert("获取数据出错！");
        }
        strBillIDList=null;
        strSql=null;
        obj=null;
        CollectGarbage(); 
        $(document.body).unmask();
    } 
    else 
    {
        alert("请先选择要导出的话单！");
    }
};

/*将当前数据导出到Excel*/
jsTelBillCenterContent.ExportCallBillRecordData=function(){
     $(document.body).mask("数据导出中,请稍后...");
     try {
        var obj = DBReader.selectSql(jsTelBillCenterContent.CurrentSql, "T_CALLBILL");
        if(DBReader.DObjectIsNull(obj)==false)
        {
            if(parseInt(obj.RecordCount)>0)
            {
                 var _FieldData=jsTelBillCenterContent.SetExcelTableTitle(); //表头、字段、列数
                 App.ExportExcel(_FieldData,obj);
            }
            else
            {
                alert("没有要导出的数据！");
            }
        }
        else
        {
            alert("获取数据出错！");
        }
     }
     catch(e)
     {
        alert("jsTelBillCenterContent.ExportCallBillRecordData"+e.message);
     }
     obj=null;
     CollectGarbage();
     $(document.body).unmask();    
};

/* 通话记录列表 */
jsTelBillCenterContent.initColumnGrid = function() {
    try {
        var marginValue = App.ieMargin();
        var gh = document.body.clientHeight - marginValue - 130;
        var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        if (window.ActiveXObject) {
            Sys.ie = ua.match(/msie ([\d.]+)/)[1]
        }
        if (Sys.ie == "6.0") {
            gh = document.body.clientHeight - marginValue - 125;
        }
        var w = $("#centerContent").width();
        var tableGridOption =
        {
            height: gh,
            colModel:
            [
                {display: '通话记录ID', name: 'BILLID', width: (w * 0.1), sortable: false, align: 'left', hide: true },
                {display: '电话号码', name: 'TELNUM', width: (w * 0.15), sortable: true, align: 'left', process: jsTelBillCenterContent.FormatTELNUM },
                {display: '类型', name: 'CALLTYP', width: (w * 0.05), sortable: true, align: 'left' }, /*,process:jsTelBillCenterContent.FormCallType},*/
                {display: '归属地', name: 'AREATXT', width: (w * 0.05), sortable: true, align: 'left' },
                {display: '名字', name: 'CUSTOMER', width: (w * 0.08), sortable: true, align: 'center',hide:window.parent.jsIndexPage.IsCallReOrBookReg,process:jsTelBillCenterContent.FormatCustomer},
                {display: '通话时长', name: 'TALKLENGTH', width: (w * 0.05), sortable: true, align: 'left' },
                {display: '通话时间', name: 'CALLTIME', width: (w * 0.13), sortable: true, align: 'left' },
                {display: '录音ID', name: 'MP3ID', width: (w * 0.1), sortable: true, align: 'center', hide: true },
                {display: '录音', name: 'MP3ID', width: (w * 0.08), sortable: true, align: 'center', process: jsTelBillCenterContent.PlayAudio },
                {display: '通话状态', name: 'Type', width: (w * 0.1), sortable: true, align: 'left',process:jsTelBillCenterContent.FormatCallState,processType:'select'},
                {display: '通话备注', name: 'REMARK', width: (w * 0.16), sortable: true, align: 'left', process: jsTelBillCenterContent.FormtRemark },
               // {display: '黑名单ID', name: 'BLACKID', width: (w * 0.1), sortable: true, align: 'left', hide: true },
                {display: '操作', name: 'BILLID', width: (w * 0.08), sortable: false, align: 'center', process: jsTelBillCenterContent.FormtCallBillBtn,hide:true}
            ],
            customFunction: jsTelBillCenterContent.ShowTelBillPage,
            rowhandler: jsTelBillCenterContent.CallBillListRowClick,
            showcheckbox: true,
            rowcheckboxselect: false,
            selectedonclick: true,
            rp: 15,
            rowbinddata: true,
            sortname: 'BILLID',
            sortorder: 'desc'
        };
        jsTelBillCenterContent.CurrentColumnGrid = $("#tbCenterContentColumn").ikegrid(tableGridOption);
        tableGridOption = null;
    }
    catch (e) {
        alert("jsTelBillCenterContent.initColumnGrid:" + e.message);
    }
    CollectGarbage();
};
/*绑定显示数据*/
jsTelBillCenterContent.ShowTelBillPage = function(pageSize, pageIndex, searchStr,extpara,order) {
    var strPara="";
    if(searchStr!="" && searchStr!=undefined)
    {   
        strPara=searchStr[0]._BeginTime+"|"+searchStr[0]._EndTime+"|"+searchStr[0]._TelNum+"|"+searchStr[0]._statusType+"|"+searchStr[0]._Name +"|"+searchStr[0]._Remark+"|"+searchStr[0]._callType+"|"+searchStr[0]._IsHaveAudio+"|"+pageSize+"|"+pageIndex+"|"+order;
    }
    else
    {
        strPara =""+"|"+""+"|"+""+"|"+""+"|"+""+"|"+""+"|"+"-1"+"|"+""+"|"+pageSize+"|"+pageIndex+"|"+order;
    }
    var strResult=jsTelBillCenterContent.GetRecordCallJson(strPara);
    var result;
    /*设置全部话务默认值
    $("#allCount").text("0");*/
    if(strResult!=null)
    {
        result=eval("[{"+strResult+"}]");
        /*设置全部数量*/     
        if(jsTelBillCenterContent.IsEditAllCount)
        {
            if(result[0].result=="1" && result[0].table!=undefined)
            {
                $("#allCount").text(result[0].table[0].AllCount);
            }   
            else
            {
                $("#allCount").text("0");
            }
        }
        result[0].pageIndex=pageIndex;    
    }
 
    strPara=null;
    strResult=null;
    CollectGarbage();
    return strResult=null?null:result[0];
}

jsTelBillCenterContent.GetRecordCallJson = function(strPara) {
    var startTime = strPara.split('|')[0];        /*开始时间*/
    var endTime = strPara.split('|')[1];          /*结束时间*/
    var TelNum = strPara.split('|')[2];          /*电话号码*/
    var CallStatus = strPara.split('|')[3];         /*通话状态*/
    var EmpName = strPara.split('|')[4];        /*名字*/
    var Remark = strPara.split('|')[5];          /*通话备注*/
    var callType = strPara.split('|')[6];         /*值为-1时全部，0去电，1来电，2未接*/
    var isHaveAdio = strPara.split('|')[7];   /*是否有录音*/
    var pageSize = strPara.split('|')[8];        /*一页多少条记录*/
    var pageCount = strPara.split('|')[9];        /*第几页*/
    var orderBy = strPara.split('|')[10];          /*排序*/

    var countTop = pageSize * pageCount;
    var strSql = "SELECT top " + countTop + "  T_CALLBILL.BILLID,T_CALLBILL.TELNUM,iif(T_CALLBILL.CALLTYP=0,'未接',iif(T_CALLBILL.CALLTYP=1,'来电',iif(T_CALLBILL.CALLTYP=2,'去电'))) as CALLTYP,T_CALLBILL.AREATXT,iif(ISNULL(T_CALLBILL.CUSTOMER),'无',T_CALLBILL.CUSTOMER) as CUSTOMER,T_CALLBILL.TALKLENGTH,Format(T_CALLBILL.CALLTIME,'yyyy-MM-dd hh:mm:ss') as CALLTIME,T_MP3RECORD.MP3ID,T_CALLBILL.Type,T_CALLBILL.REMARK FROM T_Callbill left join T_MP3RECORD ON T_CALLBILL.BILLID=T_MP3RECORD.BILLID ";
    var sort = " desc";
    if (orderBy != undefined && orderBy.toUpperCase().indexOf("ASC") != -1) {
        sort = " asc";
    }
    var strWhere = " where 1=1 ";

    if (startTime != "" && startTime != null) {
        strWhere = strWhere + " and T_CALLBILL.CALLTIME >= " + startTime;
    }
    if (endTime != "" && endTime != null) {
        strWhere = strWhere + " and T_CALLBILL.CALLTIME <= " + endTime;
    }
    if (TelNum != "" && TelNum != null) {
        strWhere = strWhere + " and T_CALLBILL.TELNUM like '%" + TelNum + "%'";
    }
    if (CallStatus != "" && CallStatus != null) {
        strWhere += " and T_CALLBILL.Type='" + CallStatus + "'";
    }
    if (EmpName != "" && EmpName != null) {
        if (EmpName == "无") {
            strWhere = strWhere + " and T_CALLBILL.CUSTOMER is null ";
        }
        else {
            strWhere = strWhere + " and T_CALLBILL.CUSTOMER like '%" + EmpName + "%'";
        }
    }
    if (Remark != "" && Remark != null) {
        strWhere = strWhere + " and T_CALLBILL.REMARK like '%" + Remark + "%'";
    }
    if (isHaveAdio != "" && isHaveAdio != null) {
        if (isHaveAdio == 1) {
            strWhere += " and T_MP3RECORD.MP3ID>0";
        }
        else if (isHaveAdio == 2) {
            strWhere += " and T_MP3RECORD.MP3ID is null";
        }
    }
    if (callType != "" && callType.indexOf("-1") == -1) {
        var arrType = callType.split(":");
        if (arrType.length > 0) {
            for (var i = 0; i < arrType.length; i++) {
                if (arrType[i] != -1) {
                    if (strWhere.indexOf("T_CALLBILL.CALLTYP") != -1) {
                        strWhere = strWhere + " or T_CALLBILL.CALLTYP = " + arrType[i];
                    }
                    else {
                        strWhere = strWhere + " and (T_CALLBILL.CALLTYP = " + arrType[i];
                    }
                }
            }
            strWhere += ")";
        }
        arrType.length = 0;
        arrType = null;
    }
    if (orderBy != "" && orderBy != null) {
        if (orderBy.indexOf("MP3ID") != -1) {
            strOrderBy = "T_MP3RECORD." + orderBy;
        }
        else {
            strOrderBy = "T_CALLBILL." + orderBy;
        }
    }
    strSql = strSql + strWhere + " Order By " + strOrderBy;
    // window.clipboardData.setData("text",strSql);
    /*记录当前查询语句，为获取话务数量查询使用*/
    jsTelBillCenterContent.CurrentSql = strSql;
    /*分页代码*/
    if (countTop > 0) {
        //        strSql = "select TOP " + pageSize + " (select count(BILLID) from ( " + strSql + ")) as AllCount, * from (" + strSql + ") where BILLID NOT IN (SELECT TOP " + countTop + " BILLID from (" + strSql + "))";
        strSql = "select TOP " + pageSize + " (select count(BILLID) from (  SELECT T_CALLBILL.BILLID FROM T_Callbill LEFT JOIN T_MP3RECORD ON T_CALLBILL.BILLID=T_MP3RECORD.BILLID   " + strWhere + " )) as AllCount, * from (select top " + pageSize + " * from ( " + strSql + " ,T_CALLBILL.BILLID asc)    order by " + strOrderBy.toUpperCase().replace("DESC", "").replace("ASC", "").substring(strOrderBy.indexOf(".") + 1, strOrderBy.length) + (sort == " asc" ? " desc" : " asc") + " ,T_CALLBILL.BILLID asc)order by " + strOrderBy.toUpperCase().replace("DESC", "").replace("ASC", "").substring(strOrderBy.indexOf(".") + 1, strOrderBy.length) + sort;
    }
    else {
        strSql = "select TOP " + pageSize + " (select count(BILLID) from ( " + strSql + ")) as AllCount,  * from (" + strSql + ") ";
    }
    //window.clipboardData.setData("text", strSql);
    var obj = DBReader.selectSqlForJson(strSql);

    /*清空变量释放内存*/
    strSql = null;
    startTime = null;
    endTime = null;
    TelNum = null;
    EmpName = null;
    Remark = null;
    callType = null;
    pageSize = null;
    pageCount = null;
    countTop = null;
    strWhere = null;
    CollectGarbage();
    return obj;
}

 /*通话记录列表搜索*/
jsTelBillCenterContent.CallRecordSearchString = function(strType, val) {
    try {
        /*获取查询区域返回的查询条件*/
        jsTelBillQueryCondition.queryString();

        var strCallType = "";
        var parObj = document.getElementById("CallTypeTitelContanier");
        var chkItem = parObj.getElementsByTagName("input");
        if (val == -1) {
            strCallType = val;
        }
        for (var i = 0; i < chkItem.length; i++) {
            if (chkItem[i].type == "checkbox") {
                if (val != undefined) {
                    if (val == -1 && chkItem[i].value != -1) {
                        chkItem[i].checked = false;
                    } else if (val != -1) {
                        if (chkItem[i].value == -1) {
                            chkItem[i].checked = false;
                        } else {
                            if (chkItem[i].checked == true) {
                                if (strCallType != "") {
                                    strCallType += ":";
                                }
                                strCallType += chkItem[i].value;
                            }
                        }
                    }
                } else {
                    if (chkItem[i].checked == true) {
                        if (strCallType != "") {
                            strCallType += ":";
                        }
                        strCallType += chkItem[i].value;
                    }
                }
            }
        }
        parObj = null;
        chkItem = null;
        jsTelBillQueryCondition.queryObj[0]._callType = strCallType;

        if (strType != "chk") {
            jsTelBillCenterContent.IsEditAllCount = true;
        }
        else {/*单击统计复选框时不再统计数目*/
            jsTelBillCenterContent.IsEditAllCount = false;
        }
        $("#tbCenterContentColumn").DoSearch(jsTelBillQueryCondition.queryObj);

        if (strType != "chk") {/*单击统计复选框时不再统计数目*/
            jsTelBillCenterContent.GetCallRecordCount();
        }

        strCallType = null;
        jsTelBillQueryCondition.DayType = "today"; /*选中今日时：避免其它相关查询操作依然执行前一天或后一天的动作*/

        jsTelBillCenterContent.CurBillListSelectedMainRow = null; /*去掉当前选择行*/
        window.parent.jsRightMessage.LoadRemarkWhenClickCallBillRow(''); /*清空通话备注*/
    }
    catch (e) {
        alert("jsTelBillCenterContent.CallRecordSearchString:" + e.message);
    }
    CollectGarbage();
}

/*单击通话记录列表事情*/
jsTelBillCenterContent.CallBillListRowClick = function(target) {
    $(target).click(function() {
        if (!window.parent.jsTitle.IsHoldOn) {/*非通话状态下查看通话备注*/
            jsTelBillCenterContent.CurBillListSelectedMainRow = $(target);
            var strRemark = jsTelBillCenterContent.CurBillListSelectedMainRow.attr("REMARK");
            window.parent.jsRightMessage.LoadRemarkWhenClickCallBillRow(strRemark);
        }
        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;
        /*===============*/
    });
}

/*名字*/
jsTelBillCenterContent.FormatCustomer=function(value,pid,rows){
    if($.trim(value.toString())=="无"){
        return '<button class="button" style="width:65px;" onclick="jsTelBillCenterContent.AddNewRelationInfo(\''+rows["TELNUM"]+'\');">新建档案</button>';
    }else{
        return value;
    }
};

/*跳转到新建档案*/
jsTelBillCenterContent.AddNewRelationInfo=function(telNum){
    /*主窗体切换到通讯簿窗口*/
     window.parent.jsTitle.IsAddNewRelationInfo=true;
     window.parent.jsTitle.NewRelationNumber=telNum;
     window.parent.execScript('$("#div-other-Info").opentabitem({ id: "tab-addressBook"});');
};

/*电话号码*/
jsTelBillCenterContent.FormatTELNUM = function(value, pid, rows) {
    if($.trim(value.toString())!="")
    {
        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="jsTelBillCenterContent.PeopleDialImageClick(\'' + rows["TELNUM"] + '\')" width="13px" height="13px" title="拨打电话"/>';
        }
        strShowContent+='<img alt="添加到拨号台" src="../AppFrame/APICss/default/images/icons/Item.Add.gif" onclick="jsTelBillCenterContent.TurnToTxtDialTelNo(\'' + rows["TELNUM"] + '\',\'\')" width="13px" height="13px" title="添加到拨号台"/>&nbsp;' + value.toString();

        return strShowContent;
    }
};
/*添加到拨号台*/
jsTelBillCenterContent.TurnToTxtDialTelNo = function(telNum, userName) {
    var strInnerHTML = "";
    var editorbody = window.parent.jsRightMessage.GetTxtWaitCallItem();
    /*创建号码集合载体*/
    var itemList = editorbody.getElementsByTagName("P");
    if (itemList.length == 0) 
    {
        strInnerHTML += "<p>" + editorbody.innerText + "</p>";
    }
    else 
    {
        for (var i = 0; i < itemList.length; i++) 
        {
            strInnerHTML += "<p>" + itemList[i].innerText + "</p>";
        }
    }
    if (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();
    }
}

/*手工拨号*/
jsTelBillCenterContent.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+"');");
    //                jsRightMessage.changeOffOrUp();/*更改拨号台状态*/
    //                jsRightMessage.DeleteWaitNumFromTable(telNum);/*删除待拨号码表中的记录*/
                }
                telNum=null;
            }
        }else{
            alert("话机未连接！");
        }
    }
    catch(e)
    {
        alert("jsTelBillCenterContent.PeopleDialImageClick:"+e.message);
    }
    CollectGarbage();
};

/*打入黑名单*/
jsTelBillCenterContent.MoveToBlackList=function(telNum){   
    if(jsCommonLogic.selColumnData("count(*)","T_BlackList","")>48)
    {
        alert("超出设置范围，黑名单只能设置48个号码！");
    }
    else
    {
        var entity=jsEntity.CreateEntityByTableName_access("T_BlackList");   
        entity.Fields.CallNum=telNum;
        entity.Fields.Creator=window.parent.jsTitle.UserName;
        entity.Fields.CreatorID=window.parent.jsTitle.UserId;
        entity.Fields.CreateTime="@Time";
        var result = entity.Insert(entity);
        if(result)
        {
            alert("已将该号码打入黑名单！"); 
            window.parent.execScript("jsTitle.AddToBlackList('"+telNum+"','');");/*将号码设置到话机黑名单中*/
            jsTelBillCenterContent.CallRecordSearchString();/*刷新列表*/
        }
        else
        {
            alert("打入黑名单没有成功！");
        }
        DBReader.DisposeEntity(entity);                
        CallID=null;         
        CollectGarbage();
    }
};

/*移出黑名单*/
jsTelBillCenterContent.MoveOutBlackList=function(telNum,blackID){
    var entity=jsEntity.CreateEntityByTableName_access("T_BlackList");   
    entity.Fields.ID=blackID;
    var result = entity.Delete(entity);
    if(result)
    {
        alert("已将该号码移出黑名单！"); 
        window.parent.execScript("jsTitle.ClearAllBlackList();");/*清空话机黑名单*/
        jsTelBillCenterContent.ReSetBlackListForCall();/*重新写入黑名单*/
        jsTelBillCenterContent.CallRecordSearchString();/*刷新列表*/
    }
    DBReader.Dispose(entity);
    result=null;
    CollectGarbage();
};

/*重新将所有黑名单表中的号码设置到话机*/
jsTelBillCenterContent.ReSetBlackListForCall=function(){
    var strSql="SELECT ID,CallNum,Remark FROM T_BlackList ORDER BY ID";
    var obj=DBReader.selectSqlForJson(strSql);
    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++)
            {
                /*将号码设置到话机黑名单中*/
                window.parent.execScript("jsTitle.AddToBlackList('"+result[0].table[i].CallNum+"','"+unescape(result[0].table[i].Remark)+"');");
            }
        }
    }
};

/*电话类型*/
jsTelBillCenterContent.FormCallType=function(value,pid,rows){
    var strResult="";
    switch(value){
        case "0":
            strResult= "末接";
        break;
        case "1":
            strResult= "来电";
        break;
        case "2":
            strResult= "去电";
        break;
        default:
        break;
    }
    return strResult;
}

/*通话状态*/
jsTelBillCenterContent.FormatCallState=function(value,pid,rows){
    var valueArr;
    if(rows["CALLTYP"].toString()=="去电")
    {
         valueArr=[{Value:"无"},{Value:"对方已接"},{Value:"对方拒接"},{Value:"对方没空"},{Value:"非本人接听"},{Value:"无人接听"},{Value:"号码不对"},{Value:"对方回拨"},{Value:"稍候再拨"},{Value:"对方通话中"}];
    }
    else
    {
        valueArr=[{Value:"无"},{Value:"咨询"},{Value:"投诉"},{Value:"报修"},{Value:"推销"}];
    }       
     var strSelect='<select style="width:98%;" id="selCallType_'+pid+'" onchange="jsTelBillCenterContent.WhenChangCallState(this,\''+rows["BILLID"]+'\')">';
       for(var i=0;i< valueArr.length;i++)
       {
            if(valueArr[i].Value==value.toString())
            {
               strSelect+=" <option selected='selected'>"+valueArr[i].Value+"</option>";
            }
            else
            {
                strSelect+=" <option>"+valueArr[i].Value+"</option>";
            }
       }
        strSelect+= "</select>";
        valueArr.length=0;
        valueArr=null;
        CollectGarbage();
        return strSelect;
};

/*改变通话状态*/
jsTelBillCenterContent.WhenChangCallState=function(obj,billID){
    var curSelType=obj.options[obj.selectedIndex].text; 
    var entity=jsEntity.CreateEntityByTableName_access("T_CALLBILL","","","","BILLID");   
    entity.Fields.BILLID=billID;
    entity.Fields.Type=curSelType;
    entity.Update(entity); 
    curSelType=null;
    DBReader.DisposeEntity(entity);
    CollectGarbage();
};

/*解密通话备注*/
jsTelBillCenterContent.FormtRemark=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>';
    }
};

/*主列表操作-删除*/
jsTelBillCenterContent.FormtCallBillBtn=function(value,pid,rows){
     return '<button class="button" onclick="jsTelBillCenterContent.DeleteCallBillInfo('+rows["BILLID"]+',\''+rows["MP3ID"]+'\');">删除</button>';
};

/*删除话单，同时删除录音*/
jsTelBillCenterContent.DeleteCallBillInfo=function(billId,MP3Id){
    if(confirm("确定删除吗？"))
    {
        var txtSql="DELETE * FROM T_CALLBILL WHERE BILLID="+billId;
        DBReader.execSql(txtSql);
        if(MP3Id>0)
        {
          jsTelBillCenterContent.DeleteLocalAudio(MP3Id);
        }        
        jsTelBillCenterContent.CurrentColumnGrid.flexReload();
        /*jsRightMessage.TodayContactTable.flexReload();刷新今日拨打号码列表*/        
        txtSql=null;
        CollectGarbage();
    }
};

/*删除选中话单*/
jsTelBillCenterContent.DeleteSelCallBillRecord=function(){
 if(confirm("确定要删除当前选中的话单吗？"))
 {
   if( jsTelBillCenterContent.CurrentColumnGrid.getSelectedRows().length>0)
    {
        var BillIDList="";
        $(jsTelBillCenterContent.CurrentColumnGrid.getSelectedRows()).each(function(){
            if(BillIDList!="")
            {
                BillIDList+=",";
            }
            BillIDList+=$(this).attr("BILLID");
            if($(this).attr("MP3ID")>0)
            {
                 jsTelBillCenterContent.DeleteLocalAudio($(this).attr("MP3ID"));
            }
        });   
        if(BillIDList!="")
        {
            var txtSql="DELETE * FROM T_CALLBILL WHERE BILLID in ("+BillIDList+")";
            DBReader.execSql(txtSql);
//            alert("删除成功！");
             jsTelBillCenterContent.CurrentColumnGrid.flexReload();
            /* jsRightMessage.TodayContactTable.flexReload();刷新今日拨打号码列表*/       
             txtSql=null;
        }
        BillIDList=null;
        CollectGarbage();
     }
     else
      {
        alert("请先选择要删除的话单！");
      }
  }
};

/*删除本地录音文件*/
jsTelBillCenterContent.DeleteLocalAudio=function(MP3Id){
    var getMp3Sql="SELECT FNAME FROM T_MP3RECORD WHERE MP3ID="+MP3Id;
    var DataString=DBReader.selectSqlForJson(getMp3Sql);
    if(DataString!=null)
    {
        var dataObj=eval("[{"+DataString+"}]");
        if(dataObj[0].result==1 && dataObj[0].table!=undefined)
        {
             var FileName=dataObj[0].table[0].FNAME;           
             var filePath=App.ApplicationPath()+"\\Records\\"+FileName;                          
             App.FileDelete(filePath);/*删除录音*/
             FileName=null;
             filePath=null;
         }
         dataObj=null;
      }       
    DataString=null;
    getMp3Sql=null;
};

/*列表中播放按钮*/
jsTelBillCenterContent.PlayAudio=function(value,pid,rows){
    var resultStr="";
    if(rows["MP3ID"]==0)
    {
        resultStr='无';
    }
    else
    { 
        resultStr='<button class="button" onclick="jsTelBillCenterContent.BindPlayEvent(this,'+rows["MP3ID"]+',\''+value+'\');">播放</button>';
    }
    return resultStr;
};
/*记录播放按钮对象*/
jsTelBillCenterContent.PlayActionButton=null;
/*播放操作*/
jsTelBillCenterContent.BindPlayEvent=function(obj,MP3ID,value)
{
    if($(obj).text()=="播放")
    {
        /*只有在不提机状态才能播放*/
        if(parent.jsTitle.IsHoldOn==false)
        {
            if(jsTelBillCenterContent.PlayActionButton!=null)
            {
                $(jsTelBillCenterContent.PlayActionButton).text("播放");
            }
            /*因为现在播放完录音的时候无法让播放按钮恢复成停止状态，所以需要先注释*/
            /*$(obj).text("停止");*/
            /*---------------------------------------------------------------------*/
            /*播放录音，传入录音文件名"."表示程序当前目录*/
            var getMp3Sql="SELECT FNAME FROM T_MP3RECORD WHERE MP3ID="+MP3ID;
            var DataString=DBReader.selectSqlForJson(getMp3Sql);
            if(DataString!=null)
            {
                var dataObj=eval("[{"+DataString+"}]");
                if(dataObj[0].result==1)
                {
                    var FileName=dataObj[0].table[0].FNAME;
                    var path=App.ApplicationPath()+"\Records\\"+FileName;
                    window.parent.jsRightAudio.Play(path.split('\\').join('\\\\'));//"./Records/梦里水乡.MP3");
                    path=null;
                    FileName=null;
                }
                dataObj.length=0;
                dataObj=null;
            }
            DataString=null;
            jsTelBillCenterContent.PlayActionButton=obj;
            /*显示播放器*/
            window.parent.jsRightMessage.RightUIShow("audioCondition");
        }
    }
    else
    {
         $(obj).text("播放");
        /*传入参数，是否为播放本地文件，本次是播放本地文件*/
         window.parent.jsRightAudio.StopPlay(true);
         jsTelBillCenterContent.PlayActionButton=null;
    }
    CollectGarbage();
}

/*获取话务数量*/
jsTelBillCenterContent.GetCallRecordCount=function(){
    try
    {
        /*设置话务默认值*/
        /*去电数量*/
        $("#goCount").text("0");
        /*来电数量*/
        $("#comeCount").text("0"); 
        /*未接数量*/
        $("#otherCount").text("0");
        /*从当前查询语句中抽取出对应类型的数据量*/
        if(jsTelBillCenterContent.CurrentSql!="")
        {
            var strSql='select Count(CALLTYP) as CALLTYPCount,CALLTYP from('+jsTelBillCenterContent.CurrentSql+')_AllDataBill group by CALLTYP';
            var dataString=DBReader.selectSqlForJson(strSql);
            if(dataString!=null)
            {
                var dataObj=eval("[{"+dataString+"}]");
                if(dataObj[0].result=="1")
                {
                    var itemLen=dataObj[0].table.length;
                    for(var i=0;i<itemLen;i++)
                    {
                        if(dataObj[0].table[i].CALLTYP=="去电")
                        {
                            /*去电数量*/
                            $("#goCount").text(dataObj[0].table[i].CALLTYPCount);
                        }
                        else if(dataObj[0].table[i].CALLTYP=="来电")
                        {
                            /*来电数量*/
                            $("#comeCount").text(dataObj[0].table[i].CALLTYPCount); 
                        }
                        else if(dataObj[0].table[i].CALLTYP=="未接")
                        {
                            /*未接数量*/
                            $("#otherCount").text(dataObj[0].table[i].CALLTYPCount);
                        }
                    }
                    itemLen=null;
                }
                dataObj=null;
            }
            strSql=null;
            dataString=null;
        }
    }
    catch(e)
    {
        alert("jsTelBillCenterContent.GetCallRecordCount Eorr:"+e.message);
    }
    CollectGarbage();
}

/*导出当前列表录音*/
jsTelBillCenterContent.ExportCurAllAudio=function(){
    $(document.body).mask("录音导出中,请稍后...");
    /*var store = jsTelBillCenterContent.CurrentColumnGrid.getRowData();
    for(var i=0;i<store.length;i++)
    {
        if(unescape(store[i].MP3ID)>0)
        { 
             jsTelBillCenterContent.ExportAudioEvent(unescape(store[i].MP3ID),unescape(store[i].TELNUM),unescape(store[i].CALLTIME));
        }
    }*/
    var obj=DBReader.selectSqlForJson(jsTelBillCenterContent.CurrentSql);
    if(obj!=null)
    {
        var  result=eval("[{"+obj+"}]");
        if(result[0].result=="1" && result[0].table!=undefined)
        {
            var filePath=App.Direct_Load("");
            if(filePath!="")
            {
                filePath=filePath.split('\\').join('\\\\');
                filePath=filePath+"\\\\";
                for(var i=0;i<result[0].table.length;i++)
                {
                    jsTelBillCenterContent.ExportAudioEvent(result[0].table[i].MP3ID,result[0].table[i].TELNUM,result[0].table[i].CALLTIME,filePath);
                }           
                alert("导出成功！"); 
            }
            filePath=null;
        }
        else
        {
            alert("当前没有可导出的录音！");
        }
        result=null;
    }
    else
    {
        alert("获取数据失败！");
    }
    obj=null;
    CollectGarbage();
    $(document.body).unmask();
};

/*导出选中录音*/
jsTelBillCenterContent.ExportSelectedAudio=function(){
   $(document.body).mask("录音导出中,请稍后...");
   if( jsTelBillCenterContent.CurrentColumnGrid.getSelectedRows().length>0)
    {
        var filePath=App.Direct_Load("");
        if(filePath!="")
        {
            filePath=filePath.split('\\').join('\\\\');
            filePath=filePath+"\\\\";
            $(jsTelBillCenterContent.CurrentColumnGrid.getSelectedRows()).each(function(){
                if($(this).attr("MP3ID")>0)
                {
                     jsTelBillCenterContent.ExportAudioEvent($(this).attr("MP3ID"),$(this).attr("TELNUM"),$(this).attr("CALLTIME"),filePath);
                }
            });       
            alert("导出成功！"); 
         }
         filePath=null;
        CollectGarbage();
    } 
    else
    {
        alert("请先选择要导出的录音！");
    }
   $(document.body).unmask();
};

/*导出录音*/
jsTelBillCenterContent.ExportAudioEvent=function(MP3ID,callNum,callTime,toFilePath){
    var getMp3Sql="SELECT FNAME FROM T_MP3RECORD WHERE MP3ID="+MP3ID;
    var DataString=DBReader.selectSqlForJson(getMp3Sql);
    if(DataString!=null)
    {
        var dataObj=eval("[{"+DataString+"}]");
        if(dataObj[0].result==1 && dataObj[0].table!=undefined)
        {
             var FileName=dataObj[0].table[0].FNAME;
             var fName=sysKit.strToString(toFilePath+callNum+"_"+callTime.replace(/\-/g,'').replace(/\:/g,'').replace(" ",''))+".Mp3"; 
             var filePath=App.ApplicationPath()+"\Records\\"+FileName; 
             App.FileCopy_Nodialog(filePath,fName);
             FileName=null;
             fName=null;
             filePath=null;
        }
        dataObj=null;
    }    
    DataString=null;
    getMp3Sql=null;
    CollectGarbage();    
};

/*点击通话记录便签时执行刷新*/
jsTelBillCenterContent.LoadRefreshRecordPage = function() {
    window.parent.parent.parent.execScript("jsIndexPage.loadWithMask()");
    jsTelBillCenterContent.CallRecordSearchString(); /*刷新通话记录列表*/
    window.parent.jsRightMessage.OnLoadWaitCallNumber("Call"); /*重新加载待通话号码*/
    window.parent.parent.parent.execScript("jsIndexPage.loadWithUnMask()");
};

 /*根据响铃号码获取号码资料*/
 jsTelBillCenterContent.getRingNumberInfor=function(_number)
 {
    try
    {   
        /*提机的时候停止播放录音*/
        window.parent.jsRightAudio.StopPlay(true);  
        
        /*加载号码资料*/
//        jsTelBillQueryCondition.queryObj[0]._TelNum=_number;   
        jsTelBillQueryCondition.setTelNumValue(_number);
        jsTelBillCenterContent.CallRecordSearchString();
    }
    catch(e)
    {
        alert(" jsBookListModle.getRingNumberInfor:"+e.message);
    }
    CollectGarbage();
 };