function jsServiceRegister(){

};

jsServiceRegister.LoadServiceRegisterUI=function(){
    var arrString=[];
    arrString.push('<div id="div-CallNoteSearch" class="div-search div-multi-search" style="height:30px;">');
    arrString.push('<table cellpadding="0" cellspacing="0" border="0">');
    arrString.push("<tr>");
    arrString.push('<td >类型：</td>');
    arrString.push('<td class="td130"><input id="dlInputType"  readonly="readonly" /><input  style="display:none" type="hidden" id="hhidInputType" /></td>');
    arrString.push('<td><input type="button"  value="保存"  onclick="" id="btnSaveCallNote" class="button" /></td>');
    arrString.push("</tr>");
    arrString.push("</table>");
    arrString.push("</div>");
    arrString.push('<div id="div-ServiceRecordContent">' );   /*<!--服务登记内容--> */              
    arrString.push('<div id="div_DetailStyle" style="display:none;vertical-align:top;">');
    arrString.push('<div id="div_fixedToolbar" class="toolBotton">');
    arrString.push('<a id="AddNewRow" class="imgbtn" onclick="jsCallBookList.DetailTypeAddRow();" ><span class="Edit"  title="新增行">新增行</span></a> '  );                 
    arrString.push("</div>");
    arrString.push('<table id="tbDetailStyleGride" style="display:none;"></table>');
    arrString.push("</div>");
    arrString.push('<div id="divTextType" style="display:none;">');
    arrString.push("<div>内容：</div>");
    arrString.push("<div>");
    arrString.push('<textarea id="txtServiceRecordContent" cols="80" rows="10"></textarea></div>');
    arrString.push("</div>");
    arrString.push('<div id="tbServiceRecordContainer" style="overflow-y:scroll; height:290px; margin:0px; display:none;"></div>');
    arrString.push("</div>");
    document.getElementById("divServiceRecord").innerHTML=arrString.join("");
};

/*服务登记类型下拉选择框*/
 jsServiceRegister.ServiceRecordTypeDrop=function(){
    var typeItemArray = [];
    typeItemArray.push({text:"明细模式",value:"DetailType"});
    typeItemArray.push({text:"文本模式",value:"TextType"});
    
    var txtSql="SELECT Lable as ID,CNName as Name FROM eOA_fip_CallInputSheet";
    var  obj= DBReader.selectSqlForJson(txtSql);
    if(obj!=null)
    { 
        var result=eval("[{"+obj+"}]");          
        if(result[0].result=="1" && result[0].table!=undefined)
        {      
            for (var index = 0; index < result[0].table.length; index++) {
                typeItemArray.push({ text:result[0].table[index].Name, value:result[0].table[index].ID});
            } 
        }
        result=null;
   }   
   var drop = $("#dlInputType").dropdown({
        dropwidth: 100,
        vinputid: "hhidInputType",
        selectedIndex: 0,
        items: typeItemArray,
        isNoItems:true,
        selectedchange:jsServiceRegister.dlInputTypeOnSelChanged
    });
    txtSql=null;
    obj=null;
    CollectGarbage();
}

/*服务登记选择类型操作*/
jsServiceRegister.dlInputTypeOnSelChanged=function(){
    document.getElementById('tbServiceRecordContainer').innerHTML='';
    if($("#hhidInputType").val()=="DetailType")
    {/*明细模式*/
      $("#div_DetailStyle").show();
      $("#divTextType").hide();
      $("#tbServiceRecordContainer").hide(); 
      jsServiceRegister.initDetailTypeGrid();    /*服务登记明细模式列表*/
    }
    else if($("#hhidInputType").val()=="TextType")
    {/*文本模式*/
      $("#div_DetailStyle").hide();
      $("#divTextType").show();
      $("#tbServiceRecordContainer").hide(); 
    }
    else
    {/*自定义模式*/
       $("#div_DetailStyle").hide();
       $("#divTextType").hide();
       $("#tbServiceRecordContainer").show(); 
        var txtSql="SELECT Lable,JSFileName,JSFilePath FROM eOA_fip_CallInputSheet WHERE Lable='"+$("#hhidInputType").val()+"'";
        var obj=DBReader.selectSqlForJson(txtSql);
        var result=eval("[{"+obj+"}]");          
        if(result[0].result=="1" && result[0].table!=undefined){                   
            if(result[0].table[0].JSFilePath!="" && result[0].table[0].JSFilePath!=null)
            {   
               if(App.FileIsExist(escape(App.ApplicationPath()+"Application\\TeleSecretary\\js\\"+result[0].table[0].JSFileName)))
               {
                    App.SetNullHref(0);
                    var divObj=document.getElementsByTagName("HEAD");
                    var scriptObj=document.createElement("script");
                    scriptObj.src="js/"+result[0].table[0].JSFileName;
                    scriptObj.id="js_"+$("#hhidInputType").val();
                    divObj[0].appendChild(scriptObj);
                    scriptObj=null;
                    divObj=null;
                    setTimeout("js"+$("#hhidInputType").val()+".reLoadCallNote()",100);/*加载模板设计内容*/
                    jsFile=null;
//                    App.SetNullHref(1);
                }
            }
        } 
    }
};

/*服务登记明细模式列表*/
jsServiceRegister.DetailTypeTemplateGrid=null;
jsServiceRegister.initDetailTypeGrid=function(){
  try {
         var w =  $("#middleContanier").width()-2;
         var gh = 156;
         var option = {
             height: gh,
             width: w,
             colModel:[
                { display: '标题', name: 'Title', width: (w * 0.15), sortable: true, align: 'left',process:jsServiceRegister.FormatDetailTypeTitle,processType:'select'},
                { display: '内容', name: 'Content', width: (w * 0.3), sortable: true, align: 'left',process:jsServiceRegister.FormatDetailTypeContent,processType:'text'},
	            { display: '删除', name: 'ID', width: (w * 0.08), sortable: true,process: jsServiceRegister.delDetailTypeButton}
		     ],
             customFunction: jsServiceRegister.ShowDetailTypeTemplate,
             rp: 10000,
             usepager:false,
             rowHeight:24,
             rowbinddata:true
         };
        jsServiceRegister.DetailTypeTemplateGrid = $("#tbDetailStyleGride").ikegrid(option);
    }
    catch (e) {
        alert("jsServiceRegister.initDetailTypeGrid:" + e.message);
    }
};

/*服务登记明细模式列表获得数据源*/
jsServiceRegister.ShowDetailTypeTemplate=function(){
       var result=$.parseJSON('[{"result" :"0","returnval" :"暂时没有结果"}]');
       return result[0];
};
/*标题*/
jsServiceRegister.FormatDetailTypeTitle=function(value,pid,rows){
        return '<select id="txtFixedTitle_'+pid+'" ><option>标题选项</option></select>';
};
/*内容*/
jsServiceRegister.FormatDetailTypeContent=function(value,pid,rows){
        return '<input id="txtFixedContent_'+pid+'"  type="text" style="width:300px;"/>';
};

/*通话笔记固定模板新增行*/
jsServiceRegister.DetailTypeAddRow=function(){
        var newRowObj=jsServiceRegister.DetailTypeTemplateGrid.addRow(0);
        var initValue = [{ 'Title': '', 'Content': ''}];
        jsServiceRegister.DetailTypeTemplateGrid.setRowData(newRowObj,initValue);
        CollectGarbage();
};
/*通话笔记固定模板删除行*/
jsServiceRegister.delDetailTypeButton=function(value,pid,rows){
    return '<div onclick="jsServiceRegister.delDetailTypeMethod(\''+pid+'\');" style="cursor:pointer;"><img src="../AppFrame/APICss/default/ico/user_delete.gif" />删除</div>';
}
/*删除行方法*/
jsServiceRegister.delDetailTypeMethod = function(rowID) {
    var rowObj=jsServiceRegister.DetailTypeTemplateGrid.getRowByID(rowID);
    var isDel = window.confirm("确定删除吗？");
    if (isDel) 
    {
      jsServiceRegister.DetailTypeTemplateGrid.deleteRow(rowObj.rowIndex);
    }
}

/*保存服务登记*/
jsServiceRegister.SaveServiceRegister=function(){
    if($("#hhidInputType").val()=="DetailType"){
    /*明细模式*/
        var store =jsServiceRegister.DetailTypeTemplateGrid.getRowData();
        if(store!=null && store.length>0)
        {
            var strContact="";
            var entity=jsEntity.CreateEntityByTableName_access("T_TemporaryTable");
            for (var i = 0; i < store.length; i++) {
                var entityFixedBill=jsEntity.CreateEntityByTableName_access("eOA_fip_CallInputFixedBill"); 
                entityFixedBill.Fields.Title= unescape(store[i].Title);
                entityFixedBill.Fields.Content= unescape(store[i].Content);
                entityFixedBill.Fields.CreatorID=window.parent.jsTitle.UserID;
                entityFixedBill.Fields.Creator=window.parent.jsTitle.UserName;
                entityFixedBill.Fields.CreateTime="@Time";                
                entity.appendEntity(entityFixedBill,App.SqlAction.Insert);   
                
//                if(strContact!="")
//                {
//                    strContact+=";";
//                }  
//                strContact+=unescape(store[i].Title)+":"+unescape(store[i].Content);
            }         
            entity.Fields.DataID=1;
            var result=jsCommonLogic.rcTemporary_Update(entity);
            if(result)
            {
//                jsFastInputHomePage.SaveContractInfo(strContact);/*保存一条往来记录*/
                alert("保存成功！");
            }
            else
            {
                alert("保存失败！");
            }

            DBReader.DisposeEntity(entity);
        }
    }
    else if($("#hhidInputType").val()=="TextType"){
    }
    else{
       var strTableName=jsCommonLogic.selColumnData("TableName","eOA_fip_CallInputSheet","WHERE Lable='"+$("#hhidInputType").val()+"'");
       var entity=jsEntity.CreateEntityByTableName_access(strTableName);  
       jsDataResolution.GetControlData(document.getElementById("tdContent"),entity);/*通过控件填充实体*/
       var result=entity.Insert(entity);
       if(result)
       {
                /*需要保存一条往来记录*/
//            var strContact = jsFastInputHomePage.GetContactContentOnBill();
//            jsFastInputHomePage.SaveContractInfo(strContact);
            alert("保存成功！");            
       }
       else
       {
            alert("保存失败！");
       }
       DBReader.DisposeEntity(entity);
       strTableName,trCount=null;
       CollectGarbage();
    }
};

/*单击服务登记便签时操作*/
jsServiceRegister.LoadServiceRegisterTab=function()
{   
    jsCallMiddlePanel.listNo="ServiceRegister";     
}

/*保存通话笔记的同时保存一条往来记录*/
jsServiceRegister.SaveContractInfo=function(strContact){
//        strContact=sysKit.strToString(strContact);
//        var nowTime=DBReader.ServerTime();
//        nowTime =nowTime.Format("yyyy-MM-dd");
//        var strSql="exec eOA_fip_InsertContract "+jsFastInputHomePage.CurTelInfoObj.CompanyID+",'"+nowTime+"通话笔记','"+$("#curTelLinkManName").html()+"','"+$("#curTelLinkManBusiness").html()+"','"+App.CurrentUser(App.Virsion.main).UserName+"','电话联系','"+strContact+"','"+$("#dlInputType").val()+"'";
//        DBReader.execSql(strSql);
//        strSql=null;
};