<%@ Page Language="C#" AutoEventWireup="true" Inherits="PowerEasy.Module.General.WebSite.Admin.Template.ModelTemplateUI"
  Title="模板管理" ValidateRequest="false" MasterPageFile="~/Admin/MasterPage.master"
  CodeBehind="ModelTemplateEdit.aspx.cs" %>

<asp:Content ID="ContentNavigation" ContentPlaceHolderID="CphNavigation" runat="server">
  <pe:ExtendedSiteMapPath ID="SmpNavigator" SiteMapProvider="AdminMapProvider" runat="server" />
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="CphContent" runat="Server">
  <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
  <table style="width: 100%; margin: 0 auto;" cellpadding="2" cellspacing="1" class="border">
    <tr>
      <td colspan="2" class="tdbgleft">
        <pe:AlternateLiteral ID="AlternateLiteral1" Text="填写文件名：" AlternateText="编辑模板：" runat="Server" /><asp:Label
          ID="LblFileName" runat="server"></asp:Label><asp:TextBox ID="TxtFileName" runat="server"></asp:TextBox><pe:RequiredFieldValidator
            ID="ValrTxtFileName" ControlToValidate="TxtFileName" Display="Dynamic" runat="server"
            ErrorMessage="请填写文件名"></pe:RequiredFieldValidator>
        <asp:RegularExpressionValidator ID="ValeTxtFileName" ControlToValidate="TxtFileName"
          Display="Dynamic" runat="server" ErrorMessage='文件格式应为***.html，不能包含\/:*?"<>|.和空格等字符！'></asp:RegularExpressionValidator><asp:Label
            ID="savefilename" Style="color: Red" runat="server"></asp:Label>
      </td>
    </tr>
    <tr class="tdbg">
      <td align="left" style="height: 430px" valign="top" colspan="2">
        <table style="width: 100%">
          <tr>
            <td style="width: 200px; text-align:left; vertical-align: top;" id="ft">
              <pec:CodeSnippetPanel ID="CodeSnippetPanel1" runat="server" />
            </td>
            <td onclick="switchSysBar('sp','ft','left')" style="width: 12px; cursor: hand; cursor: pointer">
              <img id="sp" src="<% =StyleSheetPath %>Images/butd.gif" alt="关闭" style="border: 0px;
                width: 12px;" />
            </td>
            <td style="vertical-align: top;">
              <div>
                <input type="text" class="inputtext" value="" id="cbox" size="50">
                <input type="button" onclick="findText()" value="查找下一个并选择">
              </div>
              <asp:TextBox ID="TxtTemplate" runat="server" Height="421px" Width="99%" TextMode="MultiLine"
                Rows="7" Wrap="False"></asp:TextBox>
              <div style="text-align: center; vertical-align: top;">
                <img alt="增加高度" src="../../Admin/Images/sizeplus.gif" onclick="sizeChange(50)" />
                <img alt="减少高度" src="../../Admin/Images/sizeminus.gif" onclick="sizeChange(-50)" />
              </div>
            </td>
            <td onclick="switchSysBar('sp2','ft2', 'right')" style="width: 12px; cursor: pointer">
              <img id="sp2" src="<% =StyleSheetPath %>images/butOpen.gif" alt="关闭" style="border: 0px;
                width: 12px;" />
            </td>
            <td style="text-align: left; vertical-align: top; width: 200px" id="ft2">
              <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                <ContentTemplate>
                  <div style="overflow: auto; float: left; width: 100%; height: 410px; text-align: center">
                    <div code="ModelID" onclick="cit()" outype="7" class="spanfixdiv">
                      模型ID</div>
                    <div code="Custom" onclick="cit()" outype="7" class="spanfixdiv">
                      内容页模板自定义字段集</div>
                    <div code="ModelName" onclick="cit()" outype="7" class="spanfixdiv">
                      模型名称</div>
                    <div code="TableName" onclick="cit()" outype="7" class="spanfixdiv">
                      模型表名</div>
                    <div code="ItemName" onclick="cit()" outype="7" class="spanfixdiv">
                      项目名称</div>
                    <div code="ItemUnit" onclick="cit()" outype="7" class="spanfixdiv">
                      项目单位</div>
                  </div>
                </ContentTemplate>
              </asp:UpdatePanel>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
  <br />
  <center>
    <asp:Button ID="BtnSubmit" runat="server" Text="保存" OnClick="BtnSubmit_Click" />&nbsp;
    <input name="Cancel" type="button" class="inputbutton" id="Cancel" value="取消" onclick="Redirect('<%= Request.UrlReferrer.ToString() %>')" />&nbsp;
    <input name="Loadpage" type="button" class="inputbutton" id="loadotherpage" value="导入"
      onclick="loadhtml();" />
  </center>

  <script type="text/javascript" id="searchjs">

    //边侧栏状态记忆，切换实现
    var fpath = '<% =StyleSheetPath %>';
    function setCookie(name, value, expires, path, domain, secure) {
      var today = new Date();
      today.setTime(today.getTime());
      if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
      }
      var expires_date = new Date(today.getTime() + (expires)); document.cookie = name + '=' + escape(value) + ((expires) ? ';expires=' + expires_date.toGMTString() : '') + ((path) ? ';path=' + path : '') + ((domain) ? ';domain=' + domain : '') + ((secure) ? ';secure' : '');
    }

    function getCookie(name) {
      if (document.cookie.length > 0) {
        cookieStart = document.cookie.indexOf(name + "=")
        if (cookieStart != -1) {
          cookieStart = cookieStart + name.length + 1
          cookieEnd = document.cookie.indexOf(";", cookieStart)
          if (cookieEnd == -1) cookieEnd = document.cookie.length
          return unescape(document.cookie.substring(cookieStart, cookieEnd))
        }
      }
      return ""
    }

    function Hashtable() {
      this._hash = new Object();
      this.add = function(key, value) {
        if (typeof (key) != "undefined") {
          if (this.contains(key) == false) {
            this._hash[key] = typeof (value) == "undefined" ? null : value;
            return true;
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
      this.remove = function(key) { delete this._hash[key]; }
      this.count = function() { var i = 0; for (var k in this._hash) { i++; } return i; }
      this.items = function(key) { return this._hash[key]; }
      this.contains = function(key) { return typeof (this._hash[key]) != "undefined"; }
      this.clear = function() { for (var k in this._hash) { delete this._hash[k]; } }
      this.tostring = function() { var output = ""; for (var k in this._hash) { if (output) output += "&"; output += k + ":" + this._hash[k]; } return output; }
    }

    var _hashtable = new Hashtable();
    function ToHashtable(string) {
      var _hashdate = string.split("&");
      for (var _kv in _hashdate) {
        kv = _hashdate[_kv].split(":");
        _hashtable.add(kv[0], kv[1]);
      }
    }

    function appendSideBarState(target, status) {
      var sideBarCookie = getCookie("PE_SideBarCookie");
      if (sideBarCookie) {
        ToHashtable(sideBarCookie);
      }
      _hashtable.remove(target, status);
      _hashtable.add(target, status);
      setCookie("PE_SideBarCookie", _hashtable.tostring(), 300, "/", "", false);
    }

    function initSideBarState(objname, target, dir) {
      var obj = $get(objname);
      var sideBarCooke = getCookie("PE_SideBarCookie");
      if (sideBarCooke) {
        _hashtable.clear;
        ToHashtable(sideBarCooke);
        stateValue = _hashtable.items("InsideModelTemplateEdit" + dir);
        if (stateValue == "none") {
          obj.alt = "打开";
          if (dir == "right")
            obj.src = fpath + "Images/butd.gif";
          else
            obj.src = fpath + "Images/butc.gif";
          $get(target).style.display = "none";
        }
        else {
          obj.alt = "关闭";
          if (dir == "right")
            obj.src = fpath + "Images/butc.gif";
          else
            obj.src = fpath + "Images/butd.gif";
          $get(target).style.display = "block";
        }
      }
    }

    function switchSysBar(objname, target, dir) {
      var obj = $get(objname);
      if (obj.alt == "关闭") {
        obj.alt = "打开";
        if (dir == "right")
          obj.src = fpath + "Images/butd.gif";
        else
          obj.src = fpath + "Images/butc.gif";
        $get(target).style.display = "none";
        appendSideBarState("InsideModelTemplateEdit" + dir, "none");
      }
      else {
        obj.alt = "关闭";
        if (dir == "right")
          obj.src = fpath + "Images/butc.gif";
        else
          obj.src = fpath + "Images/butd.gif";
        $get(target).style.display = "";
        appendSideBarState("InsideModelTemplateEdit" + dir, "block");
      }
    }

    initSideBarState("sp", "ft", "left");
    initSideBarState("sp2", "ft2", "right");

    function sizeChange(size) {
      var obj = $get("<% = TxtTemplate.ClientID %>");
      var height = parseInt(obj.offsetHeight);
      if (height + size >= 100) {
        obj.style.height = height + size + 'px';
      }
    }

    var isff = document.getElementById && !document.all;
    if (!isff) {
      var textRange = document.getElementById("<% = TxtTemplate.ClientID %>").createTextRange();
      var isSelect = false;
      var inputWord = "";
    }

    function findText() {
      if (!isff) {
        if (inputWord != document.getElementById('cbox').value) {
          isSelect = false;
        }
        inputWord = document.getElementById('cbox').value;
        if (inputWord == "") {
          alert("请输入要搜索的内容");
          return;
        }
        var selectedWord = 0;
        if (document.selection) {
          selectedWord = document.selection.createRange().text.length;
        }
        textRange.moveEnd("character", document.getElementById('<% = TxtTemplate.ClientID %>').value.length);
        textRange.moveStart("character", selectedWord);
        if (textRange.findText(inputWord)) {
          textRange.select();
          isSelect = true;
        }
        if (textRange.text != inputWord) {
          if (isSelect) {
            alert("已经搜索到内容末端！搜索将从头开始");
            textRange = document.getElementById('<% = TxtTemplate.ClientID %>').createTextRange()

          }
          else {
            alert("找不到" + inputWord);
          }
        }
        else { return; }

      }
      else {
        alert("抱歉，搜索功能不能适应您的浏览器！");
      }
    }    
  </script>

</asp:Content>
