<%@ Page Language="C#" AutoEventWireup="true" Title="风格添加/修改" ValidateRequest="false"
  MasterPageFile="~/Admin/MasterPage.master" CodeBehind="StyleSheets.aspx.cs" Inherits="PowerEasy.Module.General.WebSite.Admin.Template.StyleSheets" %>

<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="3" 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='请使用正确的扩展名.css或.js，不能包含\/:*?"<>|.和空格等字符！'></asp:RegularExpressionValidator><asp:Label
            ID="savefilename" Style="color: Red" runat="server"></asp:Label>
      </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="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="400px" Width="99%" TextMode="MultiLine"
          Wrap="False" CssClass="txt_main inputtext"></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>
  <br />
  <center>
  <asp:Button ID="BtnUse" runat="server" Text="应用" OnClick="BtnUse_Click" />&nbsp;
    <asp:Button ID="BtnSubmit" runat="server" Text="保存" OnClick="BtnSubmit_Click" />&nbsp;
    <input name="Cancel" type="button" class="inputbutton" id="Cancel" value="取消" onclick="Redirect('<%= ViewState["UrlReferrer"].ToString() %>')" />
  </center>

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

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

    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>
