<%@ Page Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true"
  ValidateRequest="false" Inherits="PowerEasy.Module.General.WebSite.Admin.Template.LabelTemplateStatic"
  Title="静态标签内容编辑" CodeBehind="LabelTemplateStatic.aspx.cs" %>

<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" EnablePartialRendering="true" runat="server" />
  <table style="width: 100%; margin: 0 auto;" cellpadding="2" cellspacing="0" class="border">
    <tr>
      <td class="spacingtitle" style="height: 22px;" colspan="5" align="center">
        <b>标签内容编辑</b>
      </td>
    </tr>
    <tr class="tdbg">
      <td style="text-align: left; vertical-align: top; width: 200px;" 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/butc.gif" alt="关闭" style="border: 0px;
          width: 12px;" />
      </td>
      <td style="text-align: left; vertical-align: top; width: 100%">
        <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="430px" Width="99%" TextMode="MultiLine"
          Wrap="False" />
        <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: 1px;" id="ft2">
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">
          <ContentTemplate>
            <pe:ExtendedLabel HtmlEncode="false" ID="itemlist" runat="server" Width="200px"></pe:ExtendedLabel>
            </div>
          </ContentTemplate>
        </asp:UpdatePanel>
      </td>
    </tr>
    <tr class="tdbg">
      <td align="center" colspan="5">
        <asp:Button ID="BtnPrv" runat="server" Text="上一步" OnClick="BtnPrv_Click" Style="cursor: pointer;
          cursor: hand; width: 88px;" />&nbsp;&nbsp;<asp:Button ID="BtnFinal" runat="server"
            Text="保　存" OnClick="BtnFinal_Click" Style="cursor: pointer; cursor: hand; width: 88px;" />&nbsp;&nbsp;<input
              id="BtnCancel" type="button" class="inputbutton" value="取　消" onclick="Redirect('LabelManage.aspx?type=-3')"
              style="cursor: pointer; cursor: hand; width: 88px;" />&nbsp; &nbsp;<pe:OneClickButton ID="OpenShowTemplate" IsOneClick="false"
                runat="server" Text="查看效果" />
      </td>
    </tr>
  </table>
  <br />
  <table style="width: 100%; margin: 0 auto;" cellpadding="2" cellspacing="1" class="border">
    <tr>
      <td class="spacingtitle" style="height: 22px;" colspan="2" align="center">
        <b>操作说明</b>
      </td>
    </tr>
    <tr class="tdbg">
      <td class="tdbg" align="left">
        <ajaxToolkit:TabContainer runat="server" ID="Tabs" Height="150px">
          <ajaxToolkit:TabPanel runat="Server" ID="TabPanel1" HeaderText="模板编辑">
            <ContentTemplate>
              <p>
                请直接在文本输入框中输入您需要显示的文字或html代码，也可以输入其他的动易系统标签，本标签支持签套使用。</p>
            </ContentTemplate>
          </ajaxToolkit:TabPanel>
          <ajaxToolkit:TabPanel runat="Server" ID="TabPanel2" HeaderText="参数调用">
            <ContentTemplate>
              <p>
                您可以在模板中使用标签参数，调用模式为&lt;xsl:value-of select=&quot;标签名&quot;/&gt;。</p>
            </ContentTemplate>
          </ajaxToolkit:TabPanel>
        </ajaxToolkit:TabContainer>
      </td>
    </tr>
  </table>
  <asp:Panel ID="Panel1" runat="server" Style="display: none" ScrollBars="Auto" CssClass="modalPopup">
    <asp:Panel ID="Panel3" runat="server" Style="cursor: move; background-color: #CCCCDD;
      border: solid 1px Gray; color: Black; text-align: center">
      <b>标签测试窗口</b>
    </asp:Panel>
    测试标签：<asp:TextBox ID="TxtTemplateTest" runat="server" Width="480px"></asp:TextBox>
    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
      <ContentTemplate>
        &nbsp;<asp:Button ID="BtnShowTemplate" runat="server" OnClick="BtnShowTemplate_Click"
          Text="刷新" Style="cursor: pointer; cursor: hand; width: 88px;" />
        &nbsp;&nbsp;<input id="tohtml" type="button" value="源码" onclick="sizeshowmode()"
          style="cursor: pointer; cursor: hand; width: 88px;" />
        <div style="overflow: auto; width: 550px; height: 390px; background-color: #EEEEEE;
          border: solid 1px Gray; color: Black;">
          <pe:ExtendedLabel ID="LabShow" HtmlEncode="False" runat="server" Text="标签结果显示区"></pe:ExtendedLabel>
          <textarea id="ShowHtml" rows="" cols="50" style="width: 540px; height: 380px; display: none"></textarea>
        </div>
      </ContentTemplate>
    </asp:UpdatePanel>
    <pe:OneClickButton ID="CloseButton" runat="server" IsOneClick="false" Text="关闭" Style="cursor: pointer; cursor: hand" />
  </asp:Panel>
  <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender" runat="server" TargetControlID="OpenShowTemplate"
    PopupControlID="Panel1" BackgroundCssClass="modalBackground" CancelControlID="CloseButton"
    DropShadow="true" PopupDragHandleControlID="Panel3" />

    <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 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("InsideLabelTemplateStatic" + 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("InsideLabelTemplateStatic" + 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("InsideLabelTemplateStatic" + 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';
      }
    }

    function sizeshowmode() {
      var obj = $get("<% = LabShow.ClientID %>");
      if ($get("tohtml").value != "源码") {
        $get("tohtml").value = "源码";
        $get("ShowHtml").style.display = "none";
        obj.style.display = "";
      }
      else {
        $get("tohtml").value = "内容";
        $get("ShowHtml").style.display = "";
        $get("ShowHtml").value = obj.innerHTML;
        obj.style.display = "none";
      }
    }

    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>
