function jsCallInputSheetList(){

};
jsCallInputSheetList.userID=App.CurrentUser().UserID;
jsCallInputSheetList.userName=App.CurrentUser().UserName;
jsCallInputSheetList.CurrentTypeID=null;/*类型树中选中的类型ID*/
jsCallInputSheetList.CurrentTypeName=null;/*类型中选中节点的名称*/
jsCallInputSheetList.CurSelMainRow=null;/*当前主列表中选择的行*/
jsCallInputSheetList.CurContentDesignCell=null;/*当前表单内容选择设计的列*/
 
var pageState="New";
/*控件状态*/
var arrAttrbute = new Array();
arrAttrbute["New"]="Addbtn,unvisible|s_Addbtn,unvisible|Savebtn,visible|s_Savebtn,unvisible|Editbtn,unvisible| s_Editbtn,unvisible|Deletebtn,unvisible|s_Deletebtn,unvisible|Cancelbtn,unvisible|selectFileType,visible,|resetDicType,visible|frmCallInputSheetDetail input,visible,enabled";
arrAttrbute["Update"]="Addbtn,unvisible|s_Addbtn,unvisible|Savebtn,visible|s_Savebtn,visible|Editbtn,unvisible| s_Editbtn,unvisible|Deletebtn,unvisible|s_Deletebtn,unvisible|Cancelbtn,visible|selectFileType,visible,|resetDicType,visible|frmCallInputSheetDetail input,visible,enabled";
arrAttrbute["View"]="Addbtn,visible|s_Addbtn,visible|Savebtn,unvisible|s_Savebtn,unvisible|Editbtn,visible| s_Editbtn,visible|Deletebtn,visible|s_Deletebtn,unvisible|Cancelbtn,unvisible|selectFileType,unvisible,|resetDicType,unvisible|frmCallInputSheetDetail input,visible,disabled";
 
jsCallInputSheetList.CallInputSheetGrid = null;
/*主列表*/
jsCallInputSheetList.GetCallInputSheetGrid=function() {
    var w = $(document.documentElement).width();//document.body.scrollWidth;
    var gh = 220;
    var Option = {
        height: gh,
         width: w,
         colModel:
         [
            { display: '标识', name: 'Lable', width: (w * 0.1), sortable: true}, 
            { display: '表单类型', name: 'typeName', width: (w * 0.1), sortable: true}, 
            { display: '中文名称', name: 'CNName', width: (w * 0.1), sortable: true}, 
            { display: '状态', name: 'EndFlag', width: (w * 0.06), sortable: true,align: 'center',process:jsCallInputSheetList.onEndFlag}, 
            { display: '编号', name: 'ID', width: (w * 0.1), sortable: true,hide:true}
		 ],
         customFunction: jsCallInputSheetList.ShowPage,
          rowhandler: jsCallInputSheetList.doubleClick,
         singleselected: true,
         selectedonclick:true,
         sortname: 'EndFlag',
         sortorder: 'desc',
         rp: 10,
         rowbinddata:true
     };
     jsCallInputSheetList.CallInputSheetGrid=$("#tbCallInputSheetList").ikegrid(Option);
}
/*获取数据源*/
jsCallInputSheetList.ShowPage = function(pageSize, pageIndex, searchStr, extP, order) {
    var result = "";
    var strSql = 'select call.ID,call.Lable,call.CNName as CNName,call.EndFlag,callType.CNName as CNNameType from eOA_fip_CallInputSheet call left join eOA_fip_CallInputSheetType callType on call.TypeID=callType.ID ';


    var strWhere = " where 1=1";
    if (searchStr != "" && searchStr != null) {
        strWhere += '  and  ' + searchStr[0]._strWhere + '';
    }

    if (order != "" && order != null) {
        strOrderBy = "call." + order;
    }
    strSql = strSql + strWhere + " Order By " + strOrderBy;
    //    window.clipboardData.setData("text",strSql);
    /*记录当前查询语句，为获取话务数量查询使用*/
//    jsTelBillCenterContent.CurrentSql = strSql;
    /*分页代码*/
    var countTop = pageSize * (pageIndex - 1);
    if (countTop > 0) {
        strSql = "select TOP " + pageSize + " (select count(ID) from ( " + strSql + ")) as AllCount, * from (" + strSql + ") where ID NOT IN (SELECT TOP " + countTop + " ID from (" + strSql + "))";
    }
    else {
        strSql = "select TOP " + pageSize + " (select count(ID) from ( " + strSql + ")) as AllCount,  * from (" + strSql + ") ";
    }

    var obj = DBReader.selectSqlForJson(strSql);

    var result;
    if (obj != null) {
        result = eval("[{" + obj + "}]");
        result[0].pageIndex = pageIndex;
    }
    return strResult = null ? null : result[0];
}

/*搜索*/
jsCallInputSheetList.searchString = function(tid) {
    jsCallInputSheetList.CurrentTypeID = tid;
    var strWhere = ""
    var txtName = $("#txt_Name").val().split('\"').join('“'); txtName = txtName.split('\'').join('‘');
    var Name = $.trim(txtName);
    var BeginTime = $("#txt_BeginTime").val();
    var EndTime = $("#txt_EndTime").val();

    if (BeginTime != "" && EndTime == "") {
        if (strWhere != "")
            strWhere += " and";
        strWhere += "  call.CreateTime >= #" + BeginTime + " 00:00:00#";
    }
    if (BeginTime == "" && EndTime != "") {
        if (strWhere != "")
            strWhere += " and";
        strWhere += " call.CreateTime <= #" + EndTime + " 23:59:59#";
    }
    if (BeginTime != "" && EndTime != "") {
        if (strWhere != "")
            strWhere += " and";
        strWhere += " call.CreateTime between #" + BeginTime + " 00:00:00# and #" + EndTime + " 23:59:59#";
    }
    var flowIsEndFlag = $("#chbElag").attr("checked") == true ? 1 : 0;
    if (flowIsEndFlag == 0) {
        if (strWhere != "")
            strWhere += " and";
        strWhere += " call.EndFlag=0";
    }

    var flowType = $("#chbAllType").attr("checked") == true ? 0 : jsCallInputSheetList.CurrentTypeID;
    if (flowType > 0) {
        if (strWhere != "")
            strWhere += " and";
        strWhere += " call.TypeID=" + jsCallInputSheetList.CurrentTypeID;
    }

    if (Name != "") {
        if (strWhere != "")
            strWhere += " and ";
        strWhere += " call.CNName like '%" + Name + "%' ";
    }

    var arrWhere = [];
    arrWhere.push({ _strWhere: strWhere });
    if (arrWhere[0]._strWhere != "") {
        jsCallInputSheetList.CallInputSheetGrid.DoSearch(arrWhere);
    }
    strWhere = null;
    txtName, Name, BeginTime, EndTime = null;
    CollectGarbage();
};

/*单击事件*/
jsCallInputSheetList.doubleClick=function(target){
    $(target).click(function(){
        pageState="View";
        jsCommonLogic.LoadStateControls(arrAttrbute,null);
        $("#htxtContent").attr("disabled",true);
        $("#adminPower,#UserInfomation").show();
        jsCallInputSheetList.CurSelMainRow=$(target);
        if(jsCallInputSheetList.CurSelMainRow!=null)
        {
            jsCallInputSheetList.BindCallFastSheetInfoByID(jsCallInputSheetList.CurSelMainRow.attr("ID"));/*文档属性*/
            jsCallInputSheetList.LoadtbContentInfoByJSFile(jsCallInputSheetList.CurSelMainRow.attr("ID"));/*初始化当前模板的设计内容*/
        }
        jsCallInputSheetList.ShowFieldSaveBtn();/*保存设计内容按钮显示与否*/
        document.getElementById("FieldAdd").style.display='';
    });
};

/*是否启用*/
jsCallInputSheetList.onEndFlag = function(value, pid, rows) {
        var strCheck=value.toString().toLowerCase()=="true"?"启用":"未启用";
        return strCheck;
 };
 
 /*清空*/
jsCallInputSheetList.Cancel=function(){
        $("#txt_Name").val("");
        $("#txt_BeginTime").val("");
        $("#txt_EndTime").val("");
        $("#chbAllType").attr("checked",false);
        $("#chbElag").attr("checked",false);
        jsCallInputSheetList.searchString(jsCallInputSheetList.CurrentTypeID);
};

/*根据类型ID获得实体*/
jsCallInputSheetList.GetCallInputSheetById = function(id) {
    var strSql = "select call.*,callType.CNName as typeName  from eOA_fip_CallInputSheet as call left join eOA_fip_CallInputSheetType as callType on call.TypeID=callType.ID where call.ID=" + id;
    var entity = DBReader.selectSqlForJson(strSql);
    var result = null;
    if (entity != null) {
        result = eval("[{" + entity + "}]");
    }
    return result == null ? null : result[0].table[0];
};

/*根据表单ID绑定表单属性*/
jsCallInputSheetList.BindCallFastSheetInfoByID = function(id) {
    var entity = jsCallInputSheetList.GetCallInputSheetById(id);
    if (entity != null) {
        $("#htxtTypeName").val(entity.typeName);
        $("#hhidTypeID").val(entity.TypeID);
        $("#htxtCNName").val(entity.CNName);
        $("#hideCNName").val(entity.CNName);
        $("#txtLable").val(entity.Lable);
        $("#hideLable").val(entity.Lable);

        $("#txtTableName").val(entity.TableName);
        $("#htxtContent").val(entity.Remark != null ? unescape(entity.Remark) : "");

        $("#createUserName").html(entity.Creator);
        $("#createUserID").val(entity.CreatorID);
        $("#createTime").html(entity.CreateTime);
        $("#updateUserName").html(entity.LastModifier);
        $("#updateUserID").val(entity.LastModifierID);
        $("#updateTime").html(entity.LastModifyTime);

        $("#hideID").val(entity.ID);
        if (entity.EndFlag == 1 || entity.EndFlag.toString().toLowerCase() == "true") {
            $("#hrdoIsStop").attr("checked", true);
        }
        else {
            $("#hrdoIsStop").attr("checked", false);
        }
        entity = null;
        currentSelBillType = null;
    }
    CollectGarbage();
};

/*编辑表单属性*/
jsCallInputSheetList.EditCallInputSheet=function(){
        pageState="Update";
        jsCommonLogic.LoadStateControls(arrAttrbute,null);
        $("#htxtContent").attr("disabled",false);
        if($("#txtLable").val()!="")
        {
            $("#txtLable").attr("disabled",true);
        }
         if($("#txtTableName").val()!="")
        {
            $("#txtTableName").attr("disabled",true);
        }
};

jsCallInputSheetList.LableOnblur=function(){
      if( jsCommonLogic.chkLableIsExist($("#txtLable").val(),$("#hideLable").val())>0)
      {
              alert("已存在该标识！");
              $("#txtLable").val("");
      }
};

/*保存表单属性*/
jsCallInputSheetList.SaveCallInputSheet = function() {
    var result = -1;
    var strName = $.trim($("#htxtCNName").val()).split('\"').join('“'); strName = strName.split('\'').join('‘');
    var strLable = $.trim($("#txtLable").val()).split('\"').join('“'); strLable = strLable.split('\'').join('‘');
    var strTableName = $.trim($("#txtTableName").val()).split('\"').join('“'); strTableName = strTableName.split('\'').join('‘');
    if (strName != "" && strLable != "") {
        if (jsCommonLogic.chkLableIsExist(strLable, $("#hideLable").val()) < 1) {
            var entity = jsEntity.CreateEntityByTableName_access("eOA_fip_CallInputSheet");
            entity.Fields.TypeID = $("#hhidTypeID").val() == "" ? 0 : $("#hhidTypeID").val();
            entity.Fields.CNName = strName;
            entity.Fields.Lable = strLable;
            entity.Fields.TableName = strTableName;
            entity.Fields.Remark = $("#htxtContent").val() == "" ? null : escape($("#htxtContent").val());
            entity.Fields.EndFlag = $("#hrdoIsStop").attr("checked") ? 1 : 0;

            if (pageState == "Update") {
                entity.Fields.ID = $("#hideID").val();
                entity.Fields.LastModifier = jsCallInputSheetList.userName;
                entity.Fields.LastModifierID = jsCallInputSheetList.userID;
                entity.Fields.LastModifyTime = "@Time";
                result = entity.Update(entity);
            }
            else {
                entity.Fields.ID = 1;
                entity.Fields.CreatorID = jsCallInputSheetList.userID;
                entity.Fields.Creator = jsCallInputSheetList.userName;
                entity.Fields.CreateTime = "@Time";
                result = entity.Insert(entity);
            }
            DBReader.DisposeEntity(entity);
            if (result == true && typeof (result) == "boolean") {
                alert("操作成功！");
                jsCallInputSheetList.CreateSheetTable();
                if (pageState == "New") {
                    var xmlpro = new xmlProcess(entity.FieldXML);
                    $("#hideID").val(xmlpro.GetValueByFields("ID"));
                    jsCallInputSheetList.CurSelMainRow = null;
                }
                pageState = "View";
                jsCommonLogic.LoadStateControls(arrAttrbute, null);
                $("#htxtContent").attr("disabled", true);
                $("#adminPower,#UserInfomation").show();
                jsCallInputSheetList.searchString(jsCallInputSheetList.CurrentTypeID);
                jsCallInputSheetList.BindCallFastSheetInfoByID($("#hideID").val());
                document.getElementById("FieldAdd").style.display = '';
            }
            else {
                alert("操作失败！");
            }
        }
        else {
            alert("该标识已经存在！");
        }
    }
    else {
        alert("标识和名称不能为空！");
    }
    result, strName = null;
    CollectGarbage();
};

/*新增表单*/
jsCallInputSheetList.AddCallInputSheet=function(){
    try
    {
        pageState="New";
        document.getElementById("FieldAdd").style.display='none';
        jsCommonLogic.LoadStateControls(arrAttrbute,null);
        $("#frmCallInputSheetDetail").resetForm();
        $("#hhidTypeID,#hideID,#hideLable,#hideCNName").val("");
        $("#adminPower,#UserInfomation").hide();
        $("#htxtContent").attr("disabled",false);
        jsCallInputSheetList.ShowFieldSaveBtn();
        jsCallInputSheetList.CurSelMainRow=null;
        jsCallInputSheetList.ClearTableDesignInfo();
    }
    catch(e)
    {
        alert(e.message);
    }
};

/*删除表单相关信息*/
jsCallInputSheetList.DeleteDataByID = function() {
    try {
        var sqlStr = "DROP TABLE " + $("#txtTableName").val();
        DBReader.execSql(sqlStr);
        var divObj = document.getElementsByTagName("HEAD");
        var lable = $("#txtLable").val();
        if (document.getElementById("js" + lable)) {
            var jsObj = document.getElementById("js" + lable);
            divObj[0].removeChild(jsObj);
        }
        var fileName = "js" + $("#txtLable").val() + ".js";
        App.FileDelete(App.ApplicationPath() + "Application/TeleSecretary/js/" + fileName);   /*删除原有的本地文件*/
        divObj = null;
        var EntityObj = jsEntity.CreateEntityByTableName_access("eOA_fip_CallInputSheet", "", "", "","ID");
        EntityObj.Fields.ID = parseInt($("#hideID").val());
        EntityObj.Delete(EntityObj);
    } catch (e) {
        alert("ERROR FOR jsCallInputSheetList.DeleteDataByID" + e.message);
    }
};

/*删除表单按钮*/
jsCallInputSheetList.DeleteCallInputSheet=function(){
        if(confirm("确定删除吗？"))
        {
              // if(jsCommonLogic.selColumnData)
              jsCallInputSheetList.DeleteDataByID();
              jsCallInputSheetList.searchString(jsCallInputSheetList.CurrentTypeID);
              jsCallInputSheetList.AddCallInputSheet();
        }
};

/*取消编辑表单按钮*/
jsCallInputSheetList.CancelCallInputSheet=function(){
     pageState="View";
     jsCommonLogic.LoadStateControls(arrAttrbute,null);
     $("#htxtContent").attr("disabled",true);
     jsCallInputSheetList.BindCallFastSheetInfoByID($("#hideID").val());   
};

/*选择所属类型*/
jsCallInputSheetList.GetFileType=function()
{
//     App.SetNullHref(0);
     var FormIndex=ShowWindow.getFormIdx();
     ShowWindow.ShowMoledDialog("Application/TeleSecretary/CallInputSheetDesign/frmCallInputSheetTypeTree.htm?FormIndex=" + FormIndex + "&action=jsIndexPage.freshItemPage('tab-systemMan','jsSystemSettings.SetValue(@str)')", "类型选择", 250, 500, 0);
//     var dialogFileType = new $.ui.dialog({
//         id:"diaTypeTree_"+new Date().getMilliseconds()+parseInt(10*Math.random()),
//         title: '模板类型',
//         width: 260,
//         height: 500,
//         cover: true,
//         page: "frmCallInputSheetTypeTree.htm"
//    });
//    dialogFileType.ShowDialog();
//    App.SetNullHref(1);
}

/*设置类型值*/
jsCallInputSheetList.SetValue=function(id,text)
{
    $("#htxtTypeName").val(text);
    $("#hhidTypeID").val(id);
};
/*清空类型*/
jsCallInputSheetList.resetDataItem=function(){
        $("#htxtTypeName").val("");
        $("#hhidTypeID").val("");
};

/*标题*/
jsCallInputSheetList.FieldString="<input type='text' class='ipt' style='width:100px'/>";
/*查询*/
jsCallInputSheetList.IsOrNotSelect="<input  type='checkbox' />";
/*条件操作串*/
jsCallInputSheetList.ConditionOperateString = function(id) { return "<input type='button' class='btn' value='设计' onclick='jsCallInputSheetList.designCondition(this,\""+id+"\");'/>&nbsp;<input type='button' class='btn' value='删除' onclick='jsCallInputSheetList.deleteCondition(this);'/>"; }

/*表单内容新建行*/
jsCallInputSheetList.AddRows=function(){
     var rowObj=document.getElementById("trSheetTitle");
     try
     {        
        var newRowObj = null;
        var insertIndex=parseInt(parseInt(rowObj.rowIndex) + parseInt(rowObj.ItemCount) + 1);
        newRowObj = document.getElementById("tdContent").insertRow(insertIndex);
        
        /*本组条件个数*/
        rowObj.ItemCount = parseInt(rowObj.ItemCount) + 1;
        var newItemIndex=rowObj.ItemCount - 1;
        newRowObj.ItemIndex =newItemIndex;
        newRowObj.id = "ItemCondition_" + rowObj.Path + "_" + newRowObj.ItemIndex;
        newRowObj.ParentID = rowObj.id;
        newRowObj.Path = rowObj.Path + "_" + (newRowObj.ItemIndex + 1);
        var ParentPath=rowObj.Path;
        
        var newCellObj=newRowObj.insertCell(0);
        newCellObj.innerHTML=jsCallInputSheetList.FieldString;
        newCellObj=null;        
        newCellObj=newRowObj.insertCell(1);
        newCellObj.innerHTML="&nbsp;";
        newCellObj=null;
        newCellObj=newRowObj.insertCell(2);
        newCellObj.innerHTML=jsCallInputSheetList.IsOrNotSelect;
        newCellObj=null;
        newCellObj=newRowObj.insertCell(3);
        newCellObj.innerHTML = jsCallInputSheetList.ConditionOperateString(rowObj.Path + "_" + newRowObj.ItemIndex);
        newCellObj=null;     
        
        newRowObj=null;
       jsCallInputSheetList.ShowFieldSaveBtn();
  //     window.clipboardData.setData ("text",document.getElementById("tdContent").innerHTML);
    }
    catch(e)
    {
        alert(e.message);
    }
    rowObj=null;
    CollectGarbage();
};

/*显示或隐藏保存表单内容设计按钮*/
jsCallInputSheetList.ShowFieldSaveBtn=function(){
     if($("#trSheetTitle").attr("ItemCount")>0 && $("#txtLable").val()!="" && $("#txtTableName").val()!="")
    {
        $("#FieldSave,#s_FieldSave").show();
    }
    else
    {
        $("#FieldSave,#s_FieldSave").hide();
    }
};

/*设计控件的选择*/
jsCallInputSheetList.designCondition = function(obj,pid) {
    jsCallInputSheetList.CurContentDesignCell = obj;
    var showText = obj.parentElement.parentElement.cells[0].children[0].value;
    var saveData = document.getElementById("transmission");
    saveData.dataSource = obj.dataSource;
    var _data = obj.dataSource;
    //    if(jsCallInputSheetList.CurSelMainRow!=null)
    //    {
    if ($("#txtLable").val() != "" && $("#txtTableName").val() != "") {
        var FormIndex = ShowWindow.getFormIdx();
        if (_data != undefined && _data.length > 0) {
            ShowWindow.ShowMoledDialog("Application/TeleSecretary/eOA_EditControl/eOA_EditInputOrModifyControl.htm?formIdx=" + FormIndex + "&sqlType=access&tableName=" + $("#txtTableName").val() + "&type=EditControl&insertSource=" + escape('ShowWindow.opener.document(App.query("formIdx")).frames["tab_item_frame_tab-systemMan"].frames["tdRegistration"].frames["ifrMainContent"].document.getElementById("transmission")') + "&controlName=Row_" + pid + "&sheetList=CallInputSheet&showText=" + showText + "&action=jsIndexPage.freshItemPage('tab-systemMan','jsSystemSettings.getMessage(\"@str\")')", "取值方式", 600, 650);
        } else {
        ShowWindow.ShowMoledDialog("Application/TeleSecretary/eOA_EditControl/eOA_EditInputOrModifyControl.htm?formIdx=" + FormIndex + "&sqlType=access&tableName=" + $("#txtTableName").val() + "&type=AddControl&sheetList=CallInputSheet&showText=" + showText + "&controlName=Row_" + pid + "&action=jsIndexPage.freshItemPage('tab-systemMan','jsSystemSettings.getMessage(\"@str\")')", "取值方式", 600, 650);
        }
    }
    else {
        alert("表名和标题不能为空！");
    }
};

/*获取设计数据解析内容*/
jsCallInputSheetList.strDateTime="";
jsCallInputSheetList.getSource = function(str) {
    App.SetNullHref(0);
    var strJson = $.parseJSON(unescape(str)); // eval("["+unescape(str)+"]");// alert( strJson[0].selSource);
    var strSelSource = unescape(str).substring(unescape(str).indexOf("["), unescape(str).indexOf("]") + 1);
    var rowObj = jsCallInputSheetList.CurContentDesignCell.parentElement.parentElement;
    rowObj.cells[0].children[0].value = strJson.title;
    var controlType = strJson.type;
    var setControl = rowObj.cells[1];
    var controlID = rowObj.id.replace("ItemCondition", "Control");
    setControl.innerHTML = unescape(strJson.content);
    switch (controlType) {
        case "text":
            setControl.children[0].id = controlID;
            break;

        case "textarea":
            setControl.children[0].id = controlID;
            //            strInsertHtml = "<textarea id='" + controlID + jsSystemSettings.settingCol + "' type='textarea' cols='50' rows='5' Field='" + strJson.identity + "' format='varchar(500)' class='multxt'></textarea>";
            break;

        case "select":
            if (strJson.dataType == "sql")/*手动添加Item*/
            {
                setControl.children[0].id = controlID;
            }
            else if (strJson.dataType == "process")/*根据SQL语句or存储过程添加Item*/
            {
                //                strInsertHtml = "<select id='" + controlID + jsSystemSettings.settingCol + "' type='select' Field='" + strJson.identity + "' format='varchar(50)' dataType='" + strJson.dataType + "' process='" + strJson.process + "' selSource='" + strSelSource + "' SelValueMode='Text'>";
                var strSql = unescape(strJson.process);
                var selectObj = $.parseJSON("{" + DBReader.selectSqlForJson(strSql) + "}");
                var strInsertHtml = "";
                if (selectObj.table != undefined && selectObj.table.length > 0) {
                    for (var i = 0; i < selectObj.table.length; i++) {
                        strInsertHtml += "<option value='" + (selectObj.table[i][strJson.selSource[0].value] == undefined ? "" : selectObj.table[i][strJson.selSource[0].value]) + "'>" + (selectObj.table[i][strJson.selSource[0].name] == undefined ? "" : selectObj.table[i][strJson.selSource[0].name]) + "</option>";
                    }
                }
                strInsertHtml = "<select id='" + controlID + "' processName='" + strJson.selSource[0].name + "' processValue='" + strJson.selSource[0].value + "'  type='select' Field='" + strJson.identity + "' format='varchar(50)' dataType='" + strJson.dataType + "' process='" + strJson.process + "' SelValueMode='Text'>" + strInsertHtml + "</select>";
                setControl.process = strJson.process;
                setControl.innerHTML = strInsertHtml;
                strInsertHtml = null;
                selectObj = null;
                strSql = null;
            }
            break;

        case "radio":
            if (strJson.dataType == "sql") {
                for (var i = 0; i < setControl.children.length; i++) {
                    if (setControl.children[i].tagName == "INPUT") {
                        setControl.children[i].id = controlID + i;
                    }
                }
            }
            else if (strJson.dataType == "process") {
                var strSql = unescape(strJson.process);
                var selectObj = $.parseJSON("{" + DBReader.selectSqlForJson(strSql) + "}");
                var strInsertHtml = "";
                strSql = null;
                if (selectObj.table != undefined && selectObj.table.length > 0) {
                    for (var i = 0; i < selectObj.table.length; i++) {
                        if (strInsertHtml == "") {
                            strInsertHtml += "<input id='" + controlID + "' name='r_" + controlID + "' Field='" + strJson.identity + "' format='varchar(50)' checked='checked' type='radio' value='" + (selectObj.table[i][strJson.selSource[0].value] == undefined ? "" : selectObj.table[i][strJson.selSource[0].value]) + "' dataType='" + strJson.dataType + "' process='" + strJson.process + "' processName='" + strJson.selSource[0].name + "' processValue='" + strJson.selSource[0].value + "'  SelValueMode='Text'/><span>" + (selectObj.table[i][strJson.selSource[0].name] == undefined ? "" : selectObj.table[i][strJson.selSource[0].name]) + "</span>";
                        }
                        else {
                            strInsertHtml += "<input id='" + controlID + "_" + i + "' name='r_" + controlID + "' Field='" + strJson.identity + "' type='radio' value='" + (selectObj.table[i][strJson.selSource[0].value] == undefined ? "" : selectObj.table[i][strJson.selSource[0].value]) + "' SelValueMode='Text'/><span>" + (selectObj.table[i][strJson.selSource[0].name] == undefined ? "" : selectObj.table[i][strJson.selSource[0].name]) + "</span>";
                        }
                    }
                    setControl.process = strJson.process;
                    setControl.innerHTML = strInsertHtml;
                    strInsertHtml = null;
                    selectObj = null;
                    strSql = null;
                }
            }
            break;

        case "checkbox":
            if (strJson.dataType == "sql") {
                for (var i = 0; i < setControl.children.length; i++) {
                    if (setControl.children[i].tagName == "INPUT") {
                        setControl.children[0].id = controlID + i;
                        setControl.children[0].name = controlType + controlID;
                    }
                }
            }
            else if (strJson.dataType == "process") {
                var strSql = unescape(strJson.process);
                var selectObj = $.parseJSON("{" + DBReader.selectSqlForJson(strSql) + "}");
                var strInsertHtml = "";
                strSql = null;
                if (selectObj.table != undefined && selectObj.table.length > 0) {
                    for (var i = 0; i < selectObj.table.length; i++) {
                        if (strInsertHtml == "") {
                            strInsertHtml += "<input id='" + controlID + "' name='chk_" + controlID + "' checked='checked' Field='" + strJson.identity + "' format='varchar(50)' type='checkbox'  value='" + (selectObj.table[i][strJson.selSource[0].value] == undefined ? "" : selectObj.table[i][strJson.selSource[0].value]) + "' dataType='" + strJson.dataType + "' process='" + strJson.process + "' processName='" + strJson.selSource[0].name + "' processValue='" + strJson.selSource[0].value + "' SelValueMode='Text'/><span>" + (selectObj.table[i][strJson.selSource[0].name] == undefined ? "" : selectObj.table[i][strJson.selSource[0].name]) + "</span>";
                        }
                        else {
                            strInsertHtml += "<input id='" + controlID + "_" + i + "' name='chk_" + controlID + "' Field='" + strJson.identity + "'  type='checkbox'  value='" + (selectObj.table[i][strJson.selSource[0].value] == undefined ? "" : selectObj.table[i][strJson.selSource[0].value]) + "' SelValueMode='Text'/><span>" + (selectObj.table[i][strJson.selSource[0].name] == undefined ? "" : selectObj.table[i][strJson.selSource[0].name]) + "</span>";
                        }
                    }
                    setControl.process = strJson.process;
                    setControl.innerHTML = strInsertHtml;
                    strInsertHtml = null;
                    selectObj = null;
                    strSql = null;
                }
            }
            break;

        case "yyyy": case "yyyy-MM-dd": case "yyyy-MM-dd hh:mm:ss": case "MM": case "dd": case "integer": case "decimal":
            setControl.children[0].id = controlID;
            break;
    }
    // var jsFunctionName="js"+$("#txtLable").val();
    //    var strInsertHtml = "";
    //    switch (controlType) {
    //        case "text":
    //            //rowObj.cells[1].appendChild(document.createElement("<input id='"+controlID+"' type='text' Field='"+strJson.identity+"' format='text' class='ipt' />"));
    //            strInsertHtml = "<input id='" + controlID + "' type='text'  Field='" + strJson.identity + "' format='varchar(50)' class='ipt' />";
    //            break;

    //        case "textarea":
    //            strInsertHtml = "<textarea id='" + controlID + "' type='textarea' cols='50' rows='5' Field='" + strJson.identity + "' format='varchar(500)'></textarea>";
    //            break;

    //        case "select":
    //            if (strJson.dataType == "sql")/*手动添加Item*/
    //            {
    //                strInsertHtml = "<select id='" + controlID + "' type='select' Field='" + strJson.identity + "' format='varchar(50)' dataType='" + strJson.dataType + "'   SelValueMode='Text' >";
    //                for (var i = 0; i < strJson.selSource.length; i++) {
    //                    strInsertHtml += "<option value='" + strJson.selSource[i].value + "'>" + strJson.selSource[i].name + "</option>";
    //                }
    //            }
    //            else if (strJson.dataType == "process")/*根据SQL语句or存储过程添加Item*/
    //            {
    //                strInsertHtml = "<select id='" + controlID + "' type='select' Field='" + strJson.identity + "' format='varchar(50)' dataType='" + strJson.dataType + "' process='" + strJson.process + "' selSource='" + strSelSource + "' SelValueMode='Text'>";
    //                var strSql = unescape(strJson.process);
    //                var selectObj = $.parseJSON("[{" + DBReader.selectSqlForJson(strSql) + "}]");
    //                if (DBReader.DObjectIsNull(selectObj) == false && selectObj[0].recordcount > 0) {
    //                    for (var i = 0; i < selectObj[0].recordcount; i++) {
    //                        strInsertHtml += "<option value='" + selectObj[0].table[i][strJson.selSource[0].value] + "'>" + selectObj[0].table[i][strJson.selSource[0].name] + "</option>";
    //                    }
    //                    selectObj = null;
    //                }
    //            }
    //            strInsertHtml += "</select>";
    //            break;

    //        case "radio":
    //            if (strJson.dataType == "sql") {
    //                for (var i = 0; i < strJson.selSource.length; i++) {
    //                    if (strInsertHtml == "") {
    //                        strInsertHtml += "<input id='" + controlID + "' name='r_" + controlID + "' Field='" + strJson.identity + "' format='varchar(50)' type='radio' value='" + strJson.selSource[i].value + "'  dataType='" + strJson.dataType + "' SelValueMode='Text'/><span>" + strJson.selSource[i].name + "</span>";
    //                    }
    //                    else {
    //                        strInsertHtml += "<input id='" + controlID + "_" + i + "' name='r_" + controlID + "' Field='" + strJson.identity + "'  type='radio' value='" + strJson.selSource[i].value + "'  SelValueMode='Text'/><span>" + strJson.selSource[i].name + "</span>";
    //                    }
    //                }
    //            }
    //            else if (strJson.dataType == "process") {
    //                var strSql = unescape(strJson.process);
    //                var selectObj = $.parseJSON("[{" + DBReader.selectSqlForJson(strSql) + "}]");
    //                strSql = null;
    //                if (DBReader.DObjectIsNull(selectObj) == false && selectObj[0].recordcount > 0) {
    //                    for (var i = 0; i < selectObj[0].recordcount; i++) {
    //                        if (strInsertHtml == "") {
    //                            strInsertHtml += "<input id='" + controlID + "' name='r_" + controlID + "' Field='" + strJson.identity + "' format='varchar(50)' type='radio' value='" + selectObj[0].table[i][strJson.selSource[0].value] + "' selSource='" + strSelSource + "' dataType='" + strJson.dataType + "' process='" + strJson.process + "' SelValueMode='Text'/><span>" + selectObj[0].table[i][strJson.selSource[0].name] + "</span>";
    //                        }
    //                        else {
    //                            strInsertHtml += "<input id='" + controlID + "_" + i + "' name='r_" + controlID + "' Field='" + strJson.identity + "'  type='radio' value='" + selectObj[0].table[i][strJson.selSource[0].value] + "' SelValueMode='Text'/><span>" + selectObj[0].table[i][strJson.selSource[0].name] + "</span>";
    //                        }
    //                    }
    //                    selectObj = null;
    //                }
    //            }
    //            break;

    //        case "checkbox":
    //            if (strJson.dataType == "sql") {
    //                for (var i = 0; i < strJson.selSource.length; i++) {
    //                    if (strInsertHtml == "") {
    //                        strInsertHtml += "<input id='" + controlID + "' name='chk_" + controlID + "' Field='" + strJson.identity + "' format='varchar(50)' type='checkbox'  value='" + strJson.selSource[i].value + "'  dataType='" + strJson.dataType + "' SelValueMode='Text'/><span>" + strJson.selSource[i].name + "</span>"
    //                    }
    //                    else {
    //                        strInsertHtml += "<input id='" + controlID + "_" + i + "' name='chk_" + controlID + "' Field='" + strJson.identity + "'  type='checkbox'  value='" + strJson.selSource[i].value + "' SelValueMode='Text'/><span>" + strJson.selSource[i].name + "</span>"
    //                    }
    //                }
    //            }
    //            else if (strJson.dataType == "process") {
    //                var strSql = unescape(strJson.process);
    //                var selectObj = $.parseJSON("[{" + DBReader.selectSqlForJson(strSql) + "}]");
    //                strSql = null;
    //                if (DBReader.DObjectIsNull(selectObj) == false && selectObj[0].recordcount > 0) {
    //                    selectObj.MoveFirst();
    //                    for (var i = 0; i < selectObj[0].recordcount; i++) {
    //                        if (strInsertHtml == "") {
    //                            strInsertHtml += "<input id='" + controlID + "' name='chk_" + controlID + "' Field='" + strJson.identity + "' format='varchar(50)' type='checkbox'  value='" + selectObj[0].table[i][strJson.selSource[0].value] + "' selSource='" + strSelSource + "' dataType='" + strJson.dataType + "' process='" + strJson.process + "' SelValueMode='Text'/><span>" + selectObj[0].table[i][strJson.selSource[0].name] + "</span>";
    //                        }
    //                        else {
    //                            strInsertHtml += "<input id='" + controlID + "_" + i + "' name='chk_" + controlID + "' Field='" + strJson.identity + "'  type='checkbox'  value='" + selectObj[0].table[i][strJson.selSource[0].value] + "' SelValueMode='Text'/><span>" + selectObj[0].table[i][strJson.selSource[0].name] + "</span>";
    //                        }
    //                    }
    //                    selectObj = null;
    //                }
    //            }
    //            break;

    //        case "yyyy-MM-dd": case "yyyy-MM-dd hh:mm:ss":
    //            strInsertHtml = "<input id='" + controlID + "' type='text'  forType='TimeControl' Field='" + strJson.identity + "'  format='datetime' readonly='readonly'  />";

    //            if (controlType == "yyyy-MM-dd") {
    //                jsCallInputSheetList.strDateTime += "showRemindTime(\"" + controlID + "\",false,80);";
    //            }
    //            else if (controlType == "yyyy-MM-dd hh:mm:ss") {
    //                jsCallInputSheetList.strDateTime += "showRemindTime('" + controlID + "');$('#" + controlID + "').val(DBReader.ServerTime().ServerFormat('yyyy-MM-dd hh:mm:ss'));";
    //            }
    //            break;

    //        case "yyyy":
    //            strInsertHtml = "<select id='" + controlID + "' type='select'  Field='" + strJson.identity + "'  format='varchar(50)' readonly='readonly' forType='TimeSelect'>";
    //            for (var i = 1900; i < 2051; i++) {
    //                strInsertHtml += "<option value=" + i + ">" + i + "</option>";
    //            }
    //            strInsertHtml += "</select>";
    //            break;

    //        case "MM":
    //            strInsertHtml = "<select id='" + controlID + "' type='select'  Field='" + strJson.identity + "'  format='varchar(50)' readonly='readonly' forType='TimeSelect'>";
    //            for (var i = 1; i < 13; i++) {
    //                strInsertHtml += "<option value=" + i + ">" + i + "</option>";
    //            }
    //            strInsertHtml += "</select>";
    //            break;

    //        case "dd":
    //            var strInsertHtml = "<select id='" + controlID + "' type='select'  Field='" + strJson.identity + "'  format='varchar(50)' readonly='readonly' forType='TimeSelect'>";
    //            for (var i = 1; i < 32; i++) {
    //                strInsertHtml += "<option value=" + i + ">" + i + "</option>";
    //            }
    //            strInsertHtml += "</select>";
    //            break;

    //        case "integer":
    //            strInsertHtml = "<input id='" + controlID + "' type='text' class='ipt' Field='" + strJson.identity + "' format='integer'  onblur='dataValidate(3,this); '/>";
    //            break;

    //        case "decimal":
    //            strInsertHtml = "<input id='" + controlID + "' type='text' class='ipt' Field='" + strJson.identity + "' format='decimal' onblur='dataValidate(5,this); '/>";
    //            break;

    //    }
//    if (controlType == "yyyy-MM-dd") {
//        showRemindTime(controlID, false, 80);
//    }
//    else if (controlType == "yyyy-MM-dd hh:mm:ss") {
//        showRemindTime(controlID);
//        $("#" + controlID).val(DBReader.ServerTime().ServerFormat('yyyy-MM-dd hh:mm:ss'));
//    }
    rowObj.cells[3].children[0].dataSource = str;

}

/*单击列表中行时显示表单设计内容*/
jsCallInputSheetList.CurHeadJsID=null;
jsCallInputSheetList.OldHeadJsID=null;

jsCallInputSheetList.LoadtbContentInfoByJSFile=function(id){
    var JsFileInfoObj=jsCommonLogic.GetJSFileInfo(id); 
    if(DBReader.DObjectIsNull(JsFileInfoObj)==false )
    {
        if(JsFileInfoObj.Path!="" && JsFileInfoObj.Path!=null)
        {
            App.SetNullHref(0);
            var divObj=document.getElementsByTagName("HEAD");
            if(jsCallInputSheetList.OldHeadJsID!=null)
            {
              divObj[0].removeChild(document.getElementById(jsCallInputSheetList.OldHeadJsID)); 
            }

            var scriptObj=document.createElement("script");
            scriptObj.src = JsFileInfoObj.Path;
            
            scriptObj.id="js_"+JsFileInfoObj.Lable;
            jsCallInputSheetList.OldHeadJsID=jsCallInputSheetList.CurHeadJsID;
            jsCallInputSheetList.CurHeadJsID=scriptObj.id;
            
            divObj[0].appendChild(scriptObj);
            scriptObj=null;
            divObj=null;
            setTimeout("js"+JsFileInfoObj.Lable+".LoadDesignOnClickRow();",100);
            jsFile=null;
//            App.SetNullHref(1);
        }
        else
        {
            jsCallInputSheetList.ClearTableDesignInfo();
        }
    }
     else
     {
          jsCallInputSheetList.ClearTableDesignInfo();
     }//window.clipboardData.setData( "text",document.getElementById("tdContent").innerHTML);
};

jsCallInputSheetList.ClearTableDesignInfo=function(){
    var rowCounts=document.getElementById("trSheetTitle").ItemCount;
    if(rowCounts>0)
    {
        for(var i=0;i<rowCounts;i++)
        {
           var row= document.getElementById("ItemCondition_0_1_"+i);
           var index=row.rowIndex;
           document.getElementById("tdContent").deleteRow(index);
        }
        document.getElementById("trSheetTitle").ItemCount=0;
    }
};

/*表单内容删除行*/
jsCallInputSheetList.deleteCondition=function(obj){
        var rowObj = obj.parentElement.parentElement;
        var itemCount=document.getElementById("trSheetTitle").ItemCount;
        var currentIndex = rowObj.rowIndex;
        document.getElementById("tdContent").deleteRow(currentIndex);
        document.getElementById("trSheetTitle").ItemCount=itemCount-1;
        jsCallInputSheetList.ShowFieldSaveBtn();
};

/*保存表单设计内容*/
jsCallInputSheetList.SaveRows = function() {
    if (jsCallInputSheetList.CreateSheetTable(1)) {   /*创建表结构*/
        var creJSFileResult = jsCallInputSheetList.CreatJSFileRelationInfo(); /*生成JS文件*/
        if (creJSFileResult) {
            alert("保存成功！");
        }
        else {
            alert("保存失败！");
        }
    } else {
        alert("保存失败！");
    }
};

/*根据表单设计内容创建表*/
jsCallInputSheetList.CreateSheetTable = function(operate) {
    var strTableName = jsCommonLogic.selColumnData($("#txtTableName").val());
    if (strTableName == "")/*不存在该表，创建表*/
    {
        try {
            var strCreateTable = "CREATE TABLE " + $("#txtTableName").val() + "( [ID] counter PRIMARY KEY  NOT NULL";
            if (operate != undefined && operate != "") {
                var count = document.getElementById("trSheetTitle").ItemCount;
                for (var i = 0; i < count; i++) {
                    var trObj = document.getElementById("ItemCondition_0_1_" + i);
                    if (trObj.cells[1].children.length > 0) {
                        var controlObj = document.getElementById("Control_0_1_" + i);
                        strCreateTable += "," + controlObj.Field + " " + controlObj.format + " NULL";
                    }
                }
            }
        }
        catch (e) {
            alert("jsCallInputSheetList.CreateSheetTable:" + e.message);
        }
        strCreateTable += ")";
        DBReader.execSql(strCreateTable);
        strCreateTable, count = null;
    }
    else/*已经存在该表，修改表*/
    {
        if (operate != undefined && operate != "") {
            try {
                var obj = $.parseJSON("[{" + strTableName + "}]");
                var _col = obj[0].col;
                var tableNameArray = [];
                var count = document.getElementById("trSheetTitle").ItemCount;
                for (var i = 0; i < count; i++) {
                    var trObj = document.getElementById("ItemCondition_0_1_" + i);
                    if (trObj != null && trObj.cells[1].children.length > 0) {
                        var controlObj = document.getElementById("Control_0_1_" + i);
                        tableNameArray.push({ name: controlObj.Field, format: controlObj.format });
                    }
                }
                for (var j = 0; j < tableNameArray.length; j++) {
                    var fieldName = "";
                    var fieldFormat = "";
                    for (var i = 0; i < _col.length; i++) {
                        if (tableNameArray[j].name == _col[i].FieldName) {
                            break;
                        }
                        if (i == (_col.length - 1)) {
                            fieldName = tableNameArray[j].name;
                            fieldFormat = (tableNameArray[j].format == "decimal" ? "NUMERIC(8,4)" : tableNameArray[j].format == "integer" ? "long" : tableNameArray[j].format);
                            break;
                        }
                    }
                    if (fieldName != "") {
                        var addFieldStr = "ALTER TABLE [" + $("#txtTableName").val() + "] ADD [" + fieldName + "] " + fieldFormat + " NULL";
                        DBReader.execSql(addFieldStr);
                    }
                }
            } catch (e) {
                alert("ERROR FOR jsCallInputSheetList.CreateSheetTable:AddField " + e.message);
                return false;
            }
        }
    }
    strTableName = null;
    CollectGarbage();
    return true;
};

/*将模板设计存储为JS文件*/
jsCallInputSheetList.CreatJSFileRelationInfo=function(){
        var result=-1; 
        var fileName="js"+$("#txtLable").val()+".js";
        var functionName="js"+$("#txtLable").val();
        
        var jsFile=[];
        jsFile.push("function "+functionName+"()");
        jsFile.push("{};");
        jsFile.push(functionName+".reLoadCallNote=function(){");   /*快速录入页面选择模板类型时加载设计内容方法*/
        var count=document.getElementById("trSheetTitle").ItemCount;
        var strContent="";//<div id=\"tbSheetContentContainer\" style=\" overflow-y:scroll;height:100%; \">
        strContent+=("<table id='tdContent' style='width:97%;  background-color:#FFFFFF;border-color:#C0C0C0;' cellpadding='1' cellspacing='1' ItemCount='"+count+"'>");
        var trObj="";
        for(var i=0;i< count;i++)
        {
            trObj=document.getElementById("ItemCondition_0_1_"+i);/*行对象*/
            if(trObj.cells[2].childNodes[0].checked)
            {
                strContent+="<tr id="+trObj.id+" Path="+trObj.Path+" ItemIndex="+trObj.ItemIndex+" IsOrNotSel='true'>";/*加行*/
            }
            else
            {
                strContent+="<tr id="+trObj.id+" Path="+trObj.Path+" ItemIndex="+trObj.ItemIndex+">";/*加行*/
            }
            strContent+="<td style='width:80px;'><span>"+trObj.cells[0].children[0].value+"</span></td>";/*文字列*/
            strContent+=trObj.cells[1].outerHTML;/*内容列*/

         }  
        strContent+=("</table>"); 
        jsFile.push("  var strContent= \"");
        jsFile.push(escape(strContent));
        jsFile.push("\";");
        jsFile.push("document.getElementById('tbServiceRecordContainer').innerHTML=unescape(strContent);");
        jsFile.push("};");

        jsFile.push(functionName+ ".LoadDesignOnClickRow=function(){");/*单击列表时加载设计内容方法*/
        jsFile.push("var strLoadOnClick='"+escape(document.getElementById("tdContent").outerHTML)+"';");
        jsFile.push("$('#tdContent').replaceWith(unescape(strLoadOnClick));");
        jsFile.push("};");
        
        //jsFile.push(functionName+".dataValidate = function(v, p){ jsCommonLogic.dataValidate(v, p); };");
        jsFile.push("function dataValidate(v, p){ jsCommonLogic.dataValidate(v, p); };");
        
        jsFile.push(functionName+".SetTimeInput= function(){");
        if( jsCallInputSheetList.strDateTime!="")
        {
            jsFile.push(jsCallInputSheetList.strDateTime);
        }       
        jsFile.push("};"); 
        var jsSource=jsFile.join("");
        var JSFileInfoObj=jsCommonLogic.GetJSFileInfo($("#hideID").val()); 
        if(JSFileInfoObj!=null)
        {   
           if(JSFileInfoObj.Path!="" && JSFileInfoObj.Path!=null)
           {
               App.FileDelete(App.ApplicationPath() + "Application/TeleSecretary/js/" + fileName);   /*删除原有的本地文件*/
           }
       }
       App.CreateFile(App.ApplicationPath() + "Application/TeleSecretary/js/", fileName, jsSource); /*创建JS文件*/
       var entity=jsEntity.CreateEntityByTableName_access("eOA_fip_CallInputSheet");  
       entity.Fields.JSFileName=fileName;
       entity.Fields.JSFilePath = "../js/" + fileName;
       entity.Fields.ID=$("#hideID").val();
       result= entity.Update(entity);  
        
       DBReader.DisposeEntity(entity);
       fileName,functionName,count,strContent=null;
       jsFile,trObj,jsSource,JSFileInfoObj=null;
       CollectGarbage();
       return result;
};

window.onload = function() {
    showTime("txt_BeginTime", "txt_EndTime", false, 80);
    setTimeout("jsCallInputSheetList.GetCallInputSheetGrid()", 100); /*加载列表*/
    /*选择全部类型*/
    $("#chbAllType").click(function() {
        jsCallInputSheetList.searchString(jsCallInputSheetList.CurrentTypeID);
    });
    /*选择已启用*/
    $("#chbElag").click(function() {
        jsCallInputSheetList.searchString(jsCallInputSheetList.CurrentTypeID);
    });
    /*表单属性按钮显示*/
    jsCommonLogic.LoadStateControls(arrAttrbute, null);
};
//window.onresize=function()
//{
//    var w = $(document.documentElement).width()-1;
//    var gh =230;
//    jsCallInputSheetList.CallInputSheetGrid.flexResize(w, gh);
//};
/*验证*/
function dataValidate(v, p)
{
     jsCommonLogic.dataValidate(v, p); 
};
