<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true"
  CodeBehind="IncludeFile.aspx.cs" ValidateRequest="false" Inherits="PowerEasy.Module.General.WebSite.Admin.Template.IncludeFileUI"
  Title="内嵌代码添加/修改" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CphNavigation" runat="Server">
  <pe:ExtendedSiteMapPath ID="SmpNavigator" SiteMapProvider="AdminMapProvider" runat="server" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CphContent" runat="Server">
  <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true" />
  <table width="100%" border="0" cellpadding="2" cellspacing="1" class="border">
    <tr align="center">
      <td colspan="2" class="spacingtitle">
        <b>
          <pe:AlternateLiteral ID="AltrTitle" Text="添加内嵌代码" AlternateAction="modify" AlternateText="修改内嵌代码"
            runat="Server" />
        </b>
      </td>
    </tr>
    <tr class="tdbg">
      <td align="right" class="tdbgleft" style="width: 10%">
        <b>代码名称：</b>
      </td>
      <td>
        <asp:TextBox ID="TxtName" runat="server"></asp:TextBox><pe:RequiredFieldValidator
          ID="ReqTxtName" ControlToValidate="TxtName" SetFocusOnError="true" runat="server"
          ErrorMessage="名称不能为空" Display="Dynamic"></pe:RequiredFieldValidator>
      </td>
    </tr>
    <tr class="tdbg">
      <td align="right" class="tdbgleft">
        <b>简 介：</b>
      </td>
      <td>
        <asp:TextBox ID="TxtDescription" TextMode="MultiLine" Columns="40" Height="40" runat="server"></asp:TextBox>
      </td>
    </tr>
    <tr class="tdbg">
      <td align="right" class="tdbgleft">
        <b>调用方式：</b>
      </td>
      <td>
        <asp:RadioButtonList ID="RadlCallType" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal" OnSelectedIndexChanged="RadlCallType_OnSelectedIndexChanged" AutoPostBack="true">
          <asp:ListItem Text="静态调用" Selected="True" Value="Static"></asp:ListItem>
          <asp:ListItem Text="动态调用" Value="Dynamic"></asp:ListItem>
        </asp:RadioButtonList>
      </td>
    </tr>
    <tr class="tdbg">
      <td align="right" class="tdbgleft">
        <b>代码类型：</b>
      </td>
      <td>
        <asp:RadioButtonList ID="RadlIncludeType" runat="server" RepeatDirection="Horizontal">
          <asp:ListItem Text="JS输出" Selected="True" Value="JSWriteHtml"></asp:ListItem>
          <asp:ListItem Text="JS" Value="JS"></asp:ListItem>
          <asp:ListItem Text="HTML" Value="Html"></asp:ListItem>
        </asp:RadioButtonList>
      </td>
    </tr>

    <tr class="tdbg" runat="server" id="TrAssociateType">
      <td align="right" class="tdbgleft">
        <b>关联类型：</b>
      </td>
      <td>
        <asp:RadioButtonList ID="RadlAssociateType" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
          <asp:ListItem Text="不关联" Selected="True" Value="None"></asp:ListItem>
          <asp:ListItem Text="关联节点" Value="Node"></asp:ListItem>
          <asp:ListItem Text="关联专题" Value="Special"></asp:ListItem>
        </asp:RadioButtonList>
        <span style="color: Green;">注：关联节点或专题时，对节点或专题的修改将会自动刷新</span>
      </td>
    </tr>
    <tr class="tdbg" runat="server" id="TrFileName">
      <td align="right" class="tdbgleft">
        <b>文 件 名：</b>
      </td>
      <td>
        <asp:TextBox ID="TxtFileName" runat="server"></asp:TextBox><pe:RequiredFieldValidator
          ID="ReqTxtFileName" ControlToValidate="TxtFileName" SetFocusOnError="true" runat="server"
          ErrorMessage="文件名不能为空" Display="Dynamic"></pe:RequiredFieldValidator><asp:RegularExpressionValidator
            ID="RegTxtFileName" SetFocusOnError="true" Display="Dynamic" ControlToValidate="TxtFileName"
            runat="server"></asp:RegularExpressionValidator>
      </td>
    </tr>
    <tr class="tdbg">
      <td align="right" class="tdbgleft">
        <b>模 板：</b>
      </td>
      <td>
        <table style="width: 100%">
          <tr>
            <td style="width: 200px; vertical-align: top;" id="ft">
              <pec:CodeSnippetPanel ID="CodeSnippetPanel1" runat="server" />
            </td>
            <td onclick="switchSysBar('sp','ft','left')" style="width: 12px; cursor: pointer">
              <img id="sp" src="<% =StyleSheetPath %>images/butClose.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" Width="98%" Height="400px" TextMode="MultiLine"></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>
          </tr>
        </table>
      </td>
    </tr>
    <tr class="tdbg">
      <td colspan="2" align="center">
        <asp:Button ID="BtnSaveIncludeFile" runat="server" Text="保存" OnClick="BtnSaveIncludeFile_Click" />
      </td>
    </tr>
  </table>

      <asp:HiddenField ID="HdnKeyword" Value="0" runat="server" />
    <pe:FloatDivDialog ID="FdvShowWindow" runat="server" EnableViewState="false" Width="800"
        Height="430" Enabled="true">
    </pe:FloatDivDialog>

  <script language="JavaScript" type="text/javascript">

    //边侧栏状态记忆，切换实现
    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 ShowWindow(url, title) {
      jQuery('.title').html(title);
      jQuery('#<%=FdvShowWindow.ClientID %>' + '__HdnLoadUrl').prop('value', url);
      jQuery('#<%=FdvShowWindow.ClientID %>' + '__LitID').click();
  }

    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("IncludeFile" + 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("IncludeFile" + 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("IncludeFile" + dir, "block");
      }
    }

    initSideBarState("sp", "ft", "left");


    function sizeChange(size) {

      var obj = document.getElementById("<% = 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>
