<%@ page language="C#" autoeventwireup="true" inherits="V5Shop.Admin.Template_Page_Operate, V5Shop.Shop.Template" enableviewstatemac="false" enableEventValidation="false" viewStateEncryptionMode="Never" %>
<%@ Register Src="control/PageBottom.ascx" TagName="PageBottom" TagPrefix="uc1" %>
<%@ Register Assembly="V5Shop.Control" Namespace="V5Shop.Control" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>页面详细</title>
<link href="css/css.css" rel="stylesheet" type="text/css">
<link href="css/css_list.css" rel="stylesheet" type="text/css">
<link href="css/control.css" rel="stylesheet" type="text/css">
<script type="text/javascript" language="javascript" src="js/Common.js"></script>
<script type="text/javascript" src="editor/fckeditor.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="Review" onmousedown="init(this)" onmousemove="moveit(this)" onmouseup="stopdrag(this)" style="z-index:10000; border:solid 1px black; display:none; position:absolute; top:50px; left:450px; background-color:White;"></div>
    <div id="AlphaField" style="background-color:#EEE;filter:alpha(opacity=50); position:absolute; left:0px; height:0px; width:100%; height:600px; z-index:9999; display:none;"></div>
        <div class="OperateTitle">
            <div>
                <asp:Label ID="lblTitleAdd" runat="server" Text="【 模板页面添加 】"></asp:Label> 
                <asp:Label ID="lblTitleEdit" runat="server" Text="【 模板页面编辑 】" Visible="false"></asp:Label> 
                <a href="Template_Page_Manage.aspx" title="返回页面列表">返回列表</a>
            </div>
        </div>
        
        <div>
        <table id="OperateTable" width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td width="20%" height="30" align="right">
                    <asp:Label ID="Label1" runat="server" Text="模板名称："></asp:Label> 
                </td>
                <td align=left>
                    <%=tplname %>
                </td>
            </tr>
            <tr id="PageType" runat="server">
                <td width="20%" height="30" align="right">
                    <asp:Label ID="Label2" runat="server" Text="页面类型："></asp:Label> 
                </td>
                <td align=left>
                    <input type="radio" name="PageType" value="0" checked="checked" class="radio" onclick="HiddenField(this)" id="PageType_0"/><label for="PageType_0" >默认页面</label>
                    <input type="radio" name="PageType" value="1" class="radio" onclick="HiddenField(this)" id="PageType_1" /><label for="PageType_1" >自定义页面</label>
                </td>
            </tr>
            <tr id="SelectPage" runat="server">
                <td width="10%" height="30" align="right">
                    <asp:Label ID="lblPage" runat="server" Text="选择页面："></asp:Label> 
                </td>
                <td align=left>
                    <asp:DropDownList ID="ddlPage" runat="server" Width="150px">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr id="SelfPage" style="display:none;" runat="server">
                <td width="10%" height="30" align="right">
                    <asp:Label ID="lblTitle" runat="server" Text="页面名称："></asp:Label> 
                </td>
                <td align=left>
                    <asp:TextBox ID="txtTitle" runat="server" Width="300px" MaxLength="100"></asp:TextBox><span class="NeedMsg">*</span>  
                    (请输入文件名即可，所有模板页面文件都为.html格式)
                </td>
            </tr>
            <script>
                function HiddenField(obj){
                    var value = obj.value;
                    document.getElementById("SelectPage").style.display = value == "0" ? "" : "none";
                    document.getElementById("SelfPage").style.display = value == "1" ? "" : "none";
                    InitTrClass();
                }
            </script>
            <tr>
                <td width="20%" height="30" align="right">
                    <asp:Label ID="lblInsertLable" runat="server" Text="插入图片："></asp:Label> 
                </td>
                <td align=left>
                     <!--<input value="选择自定义标签" type="button" class="button" onClick="OpenDialogLable('Template_Lable_Manage_Dialog.aspx',500,500);" />
                    &nbsp;&nbsp;&nbsp;&nbsp;
                   <asp:Label ID="lblInsertCss" runat="server" Text="插入CSS调用："></asp:Label> 
                    <input value="选择CSS" type="button" class="button" onClick="OpenDialogLable('Template_CSS_Manage_Dialog.aspx',500,500);" />
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Label ID="lblInsertPicture" runat="server" Text="插入图片："></asp:Label> -->
                    <input value="选择图片" type="button" class="button" onClick="OpenDialogPage();" />
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <input value="编辑选中标签" type="button" class="button" onClick="EditSelectLabel();" />
                </td>
            </tr>
            <tr>
                <td height="30" align="right" colspan="2">
                    <cc1:FCKeditor ID="fckcontent" runat="server" width="1000px" Height="400px"></cc1:FCKeditor>
                </td>
            </tr>
            <tr>
                <td height="36" align="right"></td>
                <td align=left>
                    <asp:Button ID="btnAdd" runat="server" Text="确定" OnClick="btnAdd_Click" class="button"/>
                    <asp:Button ID="btnEdit" runat="server" Text="更新" OnClick="btnEdit_Click" Visible="False" class="button"/>
                    <input id="iptReset" runat="server" type="reset" value="重置" class="button"/>    
                    <input id="Button1" runat="server" type="button" value="返回列表" onclick="window.location.href='Template_Page_Manage.aspx'" class="button"/>    
                    <input id="Button2" runat="server" type="button" value="预览效果" onclick="ViewEffect()" class="button"/>    
                </td>
            </tr>
        </table>  
        <script type="text/javascript">
            //加TABLE样式
            InitTrClass();
            
            function EditSelectLabel(){
                var oEditor = FCKeditorAPI.GetInstance('fckcontent'); 
                if(oEditor.EditMode == 1){
                    alert('必须在设计模式下使用此功能');
                    return;
                }
                
                if (navigator.appVersion.indexOf("MSIE") != -1){
                    var EditHtml = oEditor.EditorDocument.selection.createRange().text.replace("{","").replace("}","");
                    if(EditHtml.indexOf("web_") != -1){
                        window.location.href= 'Template_Lable_Operate.aspx?id=' + escape(EditHtml.replace("web_","").replace(/(^\s*)|(\s*$)/g, ""));
                    }else{
                        alert("请选择一个有效的标签 " + EditHtml);
                    }
                }else{                        
                    var EditHtml = oEditor.EditorDocument.getSelection().replace("{","").replace("}","");
                    if(EditHtml.indexOf("web_") != -1){
                        window.location.href= 'Template_Lable_Operate.aspx?id=' + escape(EditHtml.replace("web_","").replace(/(^\s*)|(\s*$)/g, ""));
                    }else{
                        alert("请选择一个有效的标签 " + EditHtml);
                    }
                }
            }

            //打开标签选择对话框
            function OpenDialogLable(url, w, h){
                if (navigator.appVersion.indexOf("MSIE") == -1){
                    this.returnAction=function(strResult){
                        if(strResult!=null){
                            var oEditor = FCKeditorAPI.GetInstance('fckcontent'); 
                            oEditor.InsertHtml(GetValue) 
                        }
                    }
                    window.open(url + '?d=' + Date(),'newWin','modal=yes,width='+w+',height='+h+',top=200,left=300,resizable=no,scrollbars=no');
                    return;
                }else{
                    var GetValue = showModalDialog(url + '?d=' + Date(), null, 'dialogWidth:'+w+'px; dialogHeight:'+h+'px;')
                    if (GetValue != null) {
                        var oEditor = FCKeditorAPI.GetInstance('fckcontent'); 
                        oEditor.InsertHtml("{web_" + GetValue + "}"); 
                    } 
                }
            }
            
            //打开模式对话框（图片选择）
            function OpenDialogPage(){
                if (navigator.appVersion.indexOf("MSIE") == -1){
                    this.returnAction=function(strResult){
                        if(strResult!=null){
                            var oEditor = FCKeditorAPI.GetInstance('fckcontent'); 
                            oEditor.InsertHtml(GetValue) 
                        }
                    }
                    window.open('Template_Picture_Manage_Dialog.aspx?d=' + Date(),'newWin','modal=yes,width=550,height=550,top=200,left=300,resizable=no,scrollbars=no');
                    return;
                }else{
                    var GetValue = showModalDialog('Template_Picture_Manage_Dialog.aspx?d=' + Date(),'','dialogWidth:550px;dialogHeight:550px;')
                    if (GetValue != null) {
                        var oEditor = FCKeditorAPI.GetInstance('fckcontent'); 
                            oEditor.InsertHtml("<img src='<%=BaseConfigPath %>" + GetValue + "'>");
                    } 
                }
            }
            
             
            //定义即时获取全局变量
            var isnow = 0;
            //预览样式
            function ViewEffect(){
                var obj = document.getElementById("Review");
                obj.style.display = "block";
                //document.getElementById("AlphaField").style.display = "";
                isnow = 1;
                GetHtmlNow();
            }
            
            //显示预览
            function ShowView(){
                var obj = document.getElementById("Review");
                var oEditor = FCKeditorAPI.GetInstance('fckcontent'); 
                var EditorHtml = ConvertTag(oEditor.GetXHTML(true));
                obj.innerHTML = EditorHtml + "<div align=\"center\"><input type=\"button\" value=\"隐藏\" class=\"button\" onclick=\"Resume()\" /></div>";
            }
            
            //即时浏览效果
            function GetHtmlNow(){
                ShowView();
                if(isnow == 1){
                    setTimeout('GetHtmlNow()', 1000);
                }
            }
            
            //预览样式返回
            function Resume(){
                var obj = document.getElementById("Review");
                obj.style.display = "none";
                document.getElementById("AlphaField").style.display = "none";
                isnow = 0;
            }
            
            //替换图片中的标签
            function ConvertTag(str){
                var reg = new RegExp("\{web_index_part\}","gi");
                str = str.replace(reg, "<a href=\"Template_Lable_Operate.aspx?id=index_part\">{web_index_part}</a>");
                reg = new RegExp("\{web_index_part_1\}","gi");
                str = str.replace(reg, "<a href=\"Template_Lable_Operate.aspx?id=index_part_1\">{web_index_part_1}</a>");
                return str;
            }
            
            //替换源码中的CSS路径
            function ReplaceCssPath(){
                var oEditor = FCKeditorAPI.GetInstance('fckcontent');
                var content = oEditor.GetXHTML(true);
                
                var reg = new RegExp("<title>","gi");
                content = content.replace(reg,"<base href='<%=TrueUrl %><%=BaseConfigPath %>template/<%=path %>/'><title>");
                
                oEditor.SetHTML(content) ; 
            }
            
            //fck加载完毕事件
            function FCKeditor_OnComplete(oFCKeditor)   {
                ReplaceCssPath();
            } 
            
        </script>
    </div>
    <uc1:PageBottom ID="PageBottom1" runat="server" />
    </form>
</body>
</html>
