<%@ Page Language="C#" MasterPageFile="~/Admin/MainPage.Master" AutoEventWireup="true" CodeBehind="FileAdd.aspx.cs" Inherits="PPFOR.Admin.ContentArea.Download.FileAdd" Title="添加下载文件" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PPFOR_mainContent" runat="server">
<script type="text/javascript" src="../../../ckfinder/ckfinder.js"></script>
<script type="text/javascript" src="../../../ckeditor/ckeditor.js"></script>
<script src="../../JS/popup.js" type="text/javascript"></script>  
<script type="text/javascript">
var finder = new CKFinder() ;
finder.BasePath = '/ckfinder/';
finder.RememberLastFolder=true;
finder.PrintWaterImage=false;
finder.ResourceType="Images";
function BrowseFileImage()
{
    finder.SelectFunction = SetFileImage;
	finder.Popup();
}
function BrowseFileSlideImage()
{
    finder.SelectFunction = SetFileSlideImage;
	finder.Popup();
}
function SetFileImage( fileUrl )
{
    var obj=document.getElementById( "<%= PPFOR_filePic.ClientID %>" );
	obj.value = fileUrl ;
    fireEvent(obj,'change');      
}
function SetFileSlideImage( fileUrl )
{
    var obj=document.getElementById( "<%= PPFOR_fileSlideImage.ClientID %>" );
	obj.value = fileUrl ;
    fireEvent(obj,'change');      
}
var linkObject=
{
    FileUrl:'',
    FileFormat:'',
    FileSize:0
};
function showOrhidden()
{
    var obj = document.getElementById("<%=PPFOR_isLink.ClientID %>");  
    var objLink=document.getElementById("<%=PPFOR_link.ClientID %>");
    var objFileUpload=document.getElementById("<%=PPFOR_FileUpload.ClientID %>");
    var objFileFormat=document.getElementById("<%=PPFOR_fileFormat.ClientID %>");
    var objFileSize  =document.getElementById("<%=PPFOR_fileSize.ClientID %>");
    var objFileSizeTypeList  =document.getElementById("<%=PPFOR_fileSizeTypeList.ClientID %>");
    if(obj.checked)
    {
        setControlDisplay("displayLink",'');      
        setControlDisplay("displayUpload",'none');        
        if(document.all){objFileUpload.select();document.execCommand('Delete');}else{objFileUpload.value='';}
        objLink.value=linkObject.FileUrl;
        objFileFormat.value=linkObject.FileFormat;  
        objFileSize.value=linkObject.FileSize;      
        objFileFormat.readOnly=false;  
        objFileSize.readOnly=false;  
        objFileSizeTypeList.disabled=false;
    }
    else
    {
        setControlDisplay("displayLink",'none');      
        setControlDisplay("displayUpload",'');
        
        linkObject.FileUrl=objLink.value;
        linkObject.FileFormat=objFileFormat.value;  
        linkObject.FileSize=objFileSize.value;      
        objFileFormat.readOnly=true;  
        objFileSize.readOnly=true;  
        objFileSizeTypeList.disabled=true;
        if(document.all){objFileUpload.select();document.execCommand('Delete');}else{objFileUpload.value='';}
        objFileFormat.value='';  
        objFileSize.value='0';                        
    }       
}
function setControlDisplay(id,display)
{
    document.getElementById(id).style.display=display;
}
function validateFileUpload(source,args)
{
    var obj=document.getElementById('<%= PPFOR_FileUpload.ClientID %>');
    var objLink=document.getElementById('<%= PPFOR_isLink.ClientID %>');
    if(objLink.checked==false && obj.value=='')
    {
        args.IsValid=false;
    }
    else
    {
        args.IsValid=true;
    }
}
function validateLink(source,args)
{
    var obj=document.getElementById('<%= PPFOR_link.ClientID %>');
    var objLink=document.getElementById('<%= PPFOR_isLink.ClientID %>');
    if(objLink.checked==true && obj.value=='')
    {
        args.IsValid=false;
    }
    else
    {
        args.IsValid=true;
    }
}
function validateFileSize(source,args)
{
    var obj=document.getElementById('<%= PPFOR_fileSize.ClientID %>');
    var objLink=document.getElementById('<%= PPFOR_isLink.ClientID %>');
    var fileSize=parseInt(obj.value);
    var maxSize=parseInt('<%=PPFOR_maxFileSize %>');
    if(fileSize<0 || (objLink.checked==false && fileSize>maxSize))
    {
        args.IsValid=false;
    }
    else if(fileSize)
    {
        args.IsValid=true;
    }
}
function validateFileFormat(source,args)
{
    var obj=document.getElementById('<%= PPFOR_fileFormat.ClientID %>');
    var objLink=document.getElementById('<%= PPFOR_isLink.ClientID %>');
   
    var types="<%=PPFOR_fileFormatList %>";
    if(objLink.checked){
        args.IsValid=true;
        return;
    }else{
        if(args.Value.length>0){
            var format=args.Value.substr(1);        
            var typeArray=types.split('|');
            if(typeArray!=null && typeArray.length>0){
                for(var i=0;i<typeArray.length; i++){
                    if(typeArray[i]==format){
                        args.IsValid=true;
                        return;
                    }
                }
            }        
        }
    }
    args.IsValid=false;
}
function checkFile(filePath)
{
　 var image=new Image();
　 var fileFormat=document.getElementById('<%=PPFOR_fileFormat.ClientID %>');
   var fileSize=document.getElementById('<%=PPFOR_fileSize.ClientID %>');
　
　 if(filePath!=null && filePath!=''){
　     image.src=filePath;　　   
　     fileSize.value=image.fileSize && image.fileSize>=0 ? Math.ceil(image.fileSize/1024) : 0;
　     var i=filePath.lastIndexOf('.');
　     if(i>0){
　          fileFormat.value=filePath.substr(i);
　     }else{
　          fileFormat.value='';
　     }
　 }else{
　    fileSize.value=0;
　    fileFormat.value='';
　 }
　 fireEvent(fileFormat,'change');
　 fireEvent(fileSize,'change');
}
function fireEvent(obj,eventName)
{
    if(document.all)
    {
        obj.fireEvent("on" + eventName);
    }
    else
    {
        var evt = document.createEvent('HTMLEvents');   
        evt.initEvent(eventName,true,true);   
        obj.dispatchEvent(evt);
    } 
}
function show(obj){
    if(obj!=null && obj.type=='checkbox')
    {
        var target1=document.getElementById('divSeo1');
        var target2=document.getElementById('divSeo2');
        target1.style.display=(obj.checked==true)?'':'none';  
        target2.style.display=(obj.checked==true)?'':'none'; 
    }
}
function showSection(checked){
    var obj=document.getElementById("<%=PPFOR_memberDegrees.ClientID %>");
    if(obj && obj.style) obj.style.display=checked ? '' : 'none';
}
function readable(obj,targetid){
    var target=document.getElementById(targetid);
    if(obj!=null && obj.type=='checkbox' && target!=null)
    {
        target.readOnly=obj.checked;
        if(!obj.checked)
        {
            target.select();
        }
    }
}
function openModelFilesForSelect(id)
{
    popup_show("选择模板文件","<iframe id='fileFrame' src='/Admin/CustomView/filemanager.aspx?rid=" + document.getElementById(id).getAttribute("rid") + "' scrolling='yes' width='100%' height='100%' frameborder='0' ></iframe>",520,360);
}
</script>
<form id="form1" action="FileAdd.aspx" method="post" runat="server">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="fortable">
    <thead>   
        <tr>
            <td colspan="2" align="center">添加下载文件</td>
        </tr>    
    </thead>
        <tr>
            <td style="width:15%" align="right">文件名称：</td>
            <td>
                <asp:TextBox ID="PPFOR_fileName" runat="server" Width="300px" MaxLength="200"></asp:TextBox> 
                <asp:Label ID="PPFOR_lastAddName" runat="server"></asp:Label>                            
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" SetFocusOnError="true" ValidationExpression="^.{2,200}$" Display="Dynamic" ControlToValidate="PPFOR_fileName"><br />文件名称长度必须在2至200个字符之间"</asp:RegularExpressionValidator>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" SetFocusOnError="true" Display="Dynamic" ControlToValidate="PPFOR_fileName" ><br />文件名称不能为空</asp:RequiredFieldValidator>
            </td>
        </tr>                   
        <tr>
            <td align="right">所属类型：</td>
            <td>
                <asp:DropDownList ID="PPFOR_fileTypeList" runat="server" Width="300px">
                </asp:DropDownList>
                <asp:Label ID="PPFOR_fileBelongLanguage" runat="server" Enabled="false" Visible="false"></asp:Label>
                <asp:Label ID="PPFOR_fileBelongMenu" runat="server" Enabled="false" Visible="false"></asp:Label>
                <asp:Label ID="PPFOR_returnURL" runat="server" Enabled="false" Visible="false"></asp:Label>
            </td>
        </tr>
        <tr>
            <td align="right">是否外部链接：</td>
            <td>
            <input type="checkbox" id="PPFOR_isLink" runat="server" onclick="showOrhidden();"/>是否外部链接             
            </td>
        </tr>  
        <tr id="displayLink" style="display:none">
            <td align="right">超链接地址：</td>
            <td>
                <asp:TextBox ID="PPFOR_link" runat="server" MaxLength="255" Width="300px"></asp:TextBox>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" SetFocusOnError="true" ValidationExpression="^(http://([\w-]+\.)+[\w-]+(/[\w-./?:%&=]*)?)|(/[\w-./?:%&=]*)$" Display="Dynamic" ControlToValidate="PPFOR_link"><br />超链接格式不符合</asp:RegularExpressionValidator>
                <asp:CustomValidator ID="CustomValidator2" runat="server" ControlToValidate="PPFOR_link" Display="Dynamic" SetFocusOnError="true" ClientValidationFunction="validateLink" ValidateEmptyText="true"><br />超链接不能为空</asp:CustomValidator>
             </td>
        </tr> 
        <tr id="displayUpload">
           <td align="right">选择上传文件：</td>
           <td>
                <asp:FileUpload ID="PPFOR_FileUpload" runat="server" Width="300px"/>
                <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="PPFOR_FileUpload" Display="Dynamic" SetFocusOnError="true" ClientValidationFunction="validateFileUpload" ValidateEmptyText="true"><br />上传文件不能为空</asp:CustomValidator>
           </td>         
        </tr>
        <tr> 
            <td align="right">文件格式：</td>
            <td>
                <asp:TextBox ID="PPFOR_fileFormat" runat="server" MaxLength="8" Text="." Width="100px"></asp:TextBox>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="PPFOR_FileFormat" Display="Dynamic" SetFocusOnError="true"><br />文件格式不能为空</asp:RequiredFieldValidator>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" SetFocusOnError="true" ValidationExpression='^[.][a-zA-Z0-9]{1,7}$' Display="Dynamic" ControlToValidate="PPFOR_FileFormat"><br />下载文件格式必须以“.”号开头，且长度必须在2至8个字符之间，且只能包含英文字母、数字！</asp:RegularExpressionValidator>
                <asp:CustomValidator ID="CustomValidator4" runat="server" ControlToValidate="PPFOR_fileFormat" Display="Dynamic" SetFocusOnError="true" ClientValidationFunction="validateFileFormat"><br />文件格式只能为以下其中之一：“<%=PPFOR_fileFormatList%>”</asp:CustomValidator>               
            </td> 
        </tr>
        <tr> 
            <td align="right">文件大小：</td>  
            <td>
                <asp:TextBox ID="PPFOR_fileSize" runat="server" MaxLength="7" Text="0" Width="100px"></asp:TextBox>
                <asp:DropDownList ID="PPFOR_fileSizeTypeList" runat="server"></asp:DropDownList>                   
                <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="PPFOR_fileSize" Display="Dynamic" SetFocusOnError="true" MinimumValue="0" MaximumValue="9999999" Type="Integer" ><br />文件大小必须为7位以内的整数</asp:RangeValidator>
                <asp:CustomValidator ID="CustomValidator3" runat="server" ControlToValidate="PPFOR_fileSize" Display="Dynamic" SetFocusOnError="true" ClientValidationFunction="validateFileSize"><br />文件大小必须为0至<%=PPFOR_maxFileSize%>之间的整数</asp:CustomValidator>               
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" SetFocusOnError="true" Display="Dynamic" ControlToValidate="PPFOR_fileSize"><br />文件大小不能为空</asp:RequiredFieldValidator>
             </td> 
        </tr>   
        <tr>
            <td align="right">文件简介：</td>
            <td>
                <asp:TextBox ID="PPFOR_fileIntroduction" TextMode="MultiLine" runat="server" Height="80px" Width="98%"></asp:TextBox><br />
                <asp:CheckBox ID="PPFOR_fileIntroductionAuto" runat="server" Text="自动获取" Checked="true"/>
            </td>
        </tr>
        <tr>
            <td align="right">文件介绍：</td>
            <td>
                <asp:TextBox ID="PPFOR_fileDescription" runat="server" TextMode="MultiLine" Height="84px" Width="502px" MaxLength="255"></asp:TextBox>
                <script type="text/javascript">
                    var ckEditor=CKEDITOR.replace("<%=PPFOR_fileDescription.ClientID%>");
                </script>
            </td>
        </tr>  
        <tr>
            <td align="right">文件图片：</td>
            <td>       
                <asp:TextBox ID="PPFOR_filePic" runat="server" Width="300px" MaxLength="255"></asp:TextBox>      
                <input type="button" value="选择图片" class="inputbutton" onmouseover="this.className='inputbutton_hover'" onmouseout="this.className='inputbutton'" onclick="BrowseFileImage();" />
                <asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" SetFocusOnError="true" ValidationExpression='^[/][^\\<>*?:|\"]{3,254}$' Display="Dynamic" ControlToValidate="PPFOR_filePic"><br />图片文件路径必须以“/”开头，且长度必须在4至255个字符之间，且不能包含以下字符之一： \ < > | " ? : *</asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td align="right">幻灯图片：</td>
            <td>
                <asp:TextBox ID="PPFOR_fileSlideImage" runat="server" Width="300px" MaxLength="255"></asp:TextBox>
                <input type="button" class="inputbutton" onmouseover="this.className='inputbutton_hover'" onmouseout="this.className='inputbutton'" value="选择图片" onclick="BrowseFileSlideImage();" />&nbsp;为空值则使用文件图片
                <asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" SetFocusOnError="true" ValidationExpression='^[/][^\\<>*?:|\"]{3,254}$' Display="Dynamic" ControlToValidate="PPFOR_fileSlideImage"><br />图片文件路径必须以“/”开头，且长度必须在4至255个字符之间，且不能包含以下字符之一： \ < > | " ? : *</asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td align="right">文件属性：</td>
            <td>
                <asp:CheckBox ID="PPFOR_isNew" runat="server" Text="最新" />&nbsp;
                <asp:CheckBox ID="PPFOR_recommended" runat="server" Text="推荐" />&nbsp;                
                <asp:CheckBox ID="PPFOR_hot" runat="server" Text="热点" />&nbsp;
                <asp:CheckBox ID="PPFOR_slide" runat="server" Text="幻灯片" />
            </td>
        </tr>
        <tr>
            <td align="right">文件模板：</td>
            <td>
                <asp:TextBox ID="PPFOR_fileTemplate" runat="server" Width="300px" MaxLength="255"></asp:TextBox>
                <input type="button" value="选择模板" class="inputbutton" onmouseover="this.className='inputbutton_hover'" onmouseout="this.className='inputbutton'" onclick="openModelFilesForSelect('<%=PPFOR_fileTemplate.ClientID %>');" />
                <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" SetFocusOnError="true" ValidationExpression='^[/][^\\<>*?:|\"]{3,254}$' Display="Dynamic" ControlToValidate="PPFOR_fileTemplate"><br />模板文件路径必须以“/”开头，且长度必须在4至255个字符之间，且不能包含以下字符之一： \ < > | " ? : *</asp:RegularExpressionValidator>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" SetFocusOnError="true" Display="Dynamic" ControlToValidate="PPFOR_fileTemplate"><br />模板文件路径不能为空</asp:RequiredFieldValidator>
            </td>
        </tr>    
        <tr>
            <td align="right" style="height: 25px">排序：</td>
            <td style="height: 25px">
                <asp:TextBox ID="PPFOR_sort" runat="server" Text="0" MaxLength="4"></asp:TextBox>
                <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="PPFOR_sort" Display="Dynamic" SetFocusOnError="true" Type="Integer" MinimumValue="-999" MaximumValue="9999"><br />排序顺序只能填写-999至9999之间的整数</asp:RangeValidator>
            </td>
        </tr>
        <tr>
            <td align="right">是否显示：</td>
            <td>
                <asp:RadioButton ID="PPFOR_fileShow" runat="server" GroupName="fileShow" Text="是" Checked="true" />&nbsp;&nbsp;&nbsp;
                <asp:RadioButton ID="PPFOR_fileHide" runat="server" GroupName="fileShow" Text="否" />
            </td>
        </tr>
        <tr>
            <td align="right">开放权限：</td>
            <td>
                <asp:RadioButton ID="PPFOR_publicSection" runat="server" GroupName="fileSection" Text="无限制" Checked="true" />&nbsp;&nbsp;&nbsp;
                <asp:RadioButton ID="PPFOR_memberSection" runat="server" GroupName="fileSection" Text="限制会员等级" />&nbsp;&nbsp;&nbsp;
                <asp:CheckBoxList ID="PPFOR_memberDegrees" CssClass="innertable" runat="server" RepeatColumns="2" RepeatDirection="Horizontal"></asp:CheckBoxList>               
            </td>
        </tr>
        <tr>
            <td colspan="2" style="background-color: #f2f2f2" align="left">                
                <input type="checkbox" id="PPFOR_ckeSeo" runat="server" checked="checked" onclick="show(this)" />Seo 优化设置 & 其它
            </td>
        </tr>     
        <tr id="divSeo1">
            <td align="right">Meta关键字：</td>
            <td>
                <asp:TextBox ID="PPFOR_pageKeyWord" runat="server" Width="98%" MaxLength="255"></asp:TextBox><br />
                <input type="checkbox" id="PPFOR_pageKeyWordAuto" runat="server" checked="checked" />自动获取
            </td>
        </tr>
        <tr id="divSeo2">
            <td align="right">Meta描述：</td>
            <td>
                <asp:TextBox ID="PPFOR_pageDescription" runat="server" Width="98%" MaxLength="255"></asp:TextBox><br />                     
                <input type="checkbox" id="PPFOR_pageDescriptionAuto" runat="server" checked="checked" />自动获取
            </td>                  
        </tr>  
        <tr>
            <td colspan="2" style="width:100%; height:50px; display:none" align="center" valign="middle">
                <asp:Button ID="PPFOR_addFileDownload" CssClass="inputbutton" runat="server" Text="添加" OnClick="PPFOR_addFileDownloadClick"/>
                <input name="reset" type="reset" id="reset1" class="inputbutton" onmouseover="this.className='inputbutton_hover'" onmouseout="this.className='inputbutton'" value="重置" />
                <script type="text/javascript">
                    addButtonArray("<%= PPFOR_addFileDownload.ClientID %>","reset1");
                </script>
            </td>
        </tr>          
    </table>
</form> 
</asp:Content>
