<%@Page Language="C#" Inherits="IWMS.Admin.LinkAdd" EnableViewState="false" EnableEventValidation="false" MasterPageFile="admin_pop.master"%>
<asp:Content ContentPlaceHolderId="cphHead" runat="server">
	<%
		RegisterOnSubmitStatement("postForm","return "+ (!Submit.Enabled ? "false" : "postForm($i('"+ Submit.ClientID +"'));") );
		linkName.Attributes["onblur"]="validName();";
		linkUrl.Attributes["onblur"]="validUrl();";
	%>
	<script type="text/javascript">
		function postForm(ele)
		{
			var add=$i("<%=lid.ClientID%>").value=="0";
			if (!validForm()){
				return false;
			}
			
			iwms.ajSrc=null;
			var v=iwms.ajForm(document.forms[0]);
			v.act='ajax',
			v.cmd='add';
			$.post('admin_popLinkAdd.aspx',v,function(r){
				if(r.success){
					Boxy.alert("保存成功！",null,{title:"操作结果"});
					if (add){
						document.forms[0].reset();
						<%if(!CurUser.HavePower("manageLink")){
						// 非管理员只提交一次
						%>
						document.forms[0].onsubmit=function(){return false;};
						document.getElementById("<%=Submit.ClientID%>").disabled=true;
						<%}%>
					}
				}else{
					Boxy.alert("保存失败！<br/>"+r.msg,null,{title:"操作结果"});
				}
			},'json');
			return false;
		}
		
		function validForm()
		{
			if(!validName()){
				return false;
			}
			if (!validUrl()){
				return false;
			}
			return true;
		}
		
		function validName()
		{
			var o_name=$i("<%=linkName.ClientID%>");
			var msg_name=$i("vld_name");
			o_name.value=o_name.value.replace(/['"]/g,"");
			if (o_name.value.length==0){
				msg_name.innerHTML="网站名必须填写";
				msg_name.style.display="inline";
				return false;
			}else{
				msg_name.style.display="none";
				return true;
			}
		}
		
		function validUrl()
		{
			var o_url=$i("<%=linkUrl.ClientID%>");
			var msg_url=$i("vld_url");
			o_url.value=o_url.value.replace(/['"]/g,"");
			if (o_url.value.length==0){
				msg_url.innerHTML="网址必须填写";
				msg_url.style.display="inline";
				return false;
			}else{
				var re=new RegExp("^https?://.{4,}$","ig");
				if (!re.test(o_url.value)){
					msg_url.innerHTML="网址填写错误";
					msg_url.style.display="inline";
					return false;
				}else{
					msg_url.style.display="none";
				}
			}
			return true;
		}
	</script>
</asp:Content>
<asp:Content ContentPlaceHolderId="cphMain" runat="server">

	<form id="MyForm" runat="server">
	<div class="mframe">
	<div class="tl"></div>
	<div class="rt"></div>
	<div class="tm">
		<span class="tt"><asp:Literal id="ltAction" runat="server"/>友情链接</span>
	</div>
	<div class="wrapper">
	<div class="ml"></div>
	<div class="mr"></div>
	<div class="mm">
		<asp:Label id="myLabel" class="msgBar" EnableViewState="false" runat="server"/>
		<table cellpadding="3" width="95%" align="center">
		<%if(!CurUser.HavePower("manageLink")){%>
			<tr><td colspan="2" style="padding:10px 30px" class="tdbg-dark">
			申请要求：<%=config.LinkRequest%>
			</td></tr>
		<%}%>
		<tr><th width="100">
			网站名称：
			<input type="hidden" id="lid" value="0" runat="server"/>
		</th><td>
			<asp:TextBox Columns="20" MaxLength="50" id="linkName" runat="server"/>
			<div class="vldMsg" id="vld_name"></div>
		</td></tr>
		<tr><th>
			网站分类：
		</th><td>
			<asp:DropDownList id="linkSort"
				runat="server"/>
			&nbsp;
			<asp:CheckBox id="linkInIndex" runat="server"/>
		</td></tr>
		<tr><th>
			网站地址：
		</th><td>
			<asp:TextBox Columns="40" MaxLength="255" id="linkUrl" runat="server"/>
			<div class="vldMsg" id="vld_url"></div>
		</td></tr>
		<tr><th>
			网站图标：
		</th><td>
			<asp:TextBox Columns="40" MaxLength="255" id="linkLogo" runat="server"/>
			(<%=config.LinkLogoWidth%>x<%=config.LinkLogoHeight%>)
		</td></tr>
		<tr><th valign="top">
			网站简介：<br/>
			<span class="explain">最多255字</span>
		</th><td>
			<asp:TextBox Columns="40" MaxLength="255" id="linkRemark" TextMode="MultiLine" Rows="3" runat="server"/>
		</td></tr>
		<tr><td align="center" colspan="2">
		  <asp:Button id="Submit" text=" 添 加 " runat="server"/>
		</td></tr>
		</table>
		
	</div>
	</div>
	<div class="bl"></div>
	<div class="br"></div>
	<div class="bm"></div>
	</div>
	</form>
</asp:Content>