<%@ Page CodeFileBaseClass="IlgharCMS.Lib.AdminPageBase" %>
<%@ Register TagPrefix="IlgharUC" TagName="Ime" Src="../../ime.dwt.ascx"%>
<%@ Register TagPrefix="IlgharUC" TagName="LanguageMenu" Src="../../language_menu.dwt.ascx"%>
<!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>
<!-- TemplateInfo codeOutsideHTMLIsLocked="true" -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加类别</title>
<ilghar:Comment><link rel="stylesheet" type="text/css" href="../../S01/CHS/css/common.css" /></ilghar:Comment>
<link rel="stylesheet" href="<%=CssPath%>common.css" />
<script type="text/javascript" src="<%=CommonPath%>ajax.js"></script>
<script type="text/javascript" src="<%=CommonPath%>uploader.js"></script>
<script type="text/javascript" src="<%=JsPath%>common.js"></script>
<ilgharUC:Ime Ime="true" Eot="true" runat="server" />
<script type="text/javascript">
var _action = null;
var _uploadPicture = false;
function XmlHttpCallBack(xmlHttp)
{
	if (xmlHttp == null || xmlHttp.status == 200)
	{
		if (_action == "Add")
		{
			window.status = "添加类别完成！";
			
			if (_uploadPicture)
			{
				_action = "GetInnerIDFromGuid";
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=ProductCategory&Operation=" + _action + "&ID=" + xmlHttp.responseText, null, XmlHttpCallBack);
			}
			else
			{
				alert("添加成功！");
				document.getElementById("Submit").disabled = false;
				window.status = "";
			}
		}
		else if (_action == "GetInnerIDFromGuid")
		{
			_action = "UploadPicture";
			window.status = "开始上传图片...";
			_uploader.Init({Status:"正在上传图片...",Params:"Lang=<%=ContentLang%>&Object=ProductCategory&Operation=" + _action + "&ID=" + xmlHttp.responseText});
			_uploader.Upload("Picture");
		}
		else if (_action == "UploadPicture")
		{
			if (arguments.length == 2)
				alert(arguments[1]);
			else
				alert("添加成功！");
			document.getElementById("Submit").disabled = false;
			window.status = "";
		}
	}
	else
	{
		if (_action == "Add")
			alert("添加失败！请查看日志！");
		else if (_action == "GetInnerIDFromGuid")
			alert("获取InnerID失败！请查看日志！");
		else if (_action == "UploadPicture")
			alert("上传图片失败！请查看日志！");
		else
			alert("添加失败！请查看日志！");
		document.getElementById("Submit").disabled = false;
		window.status = "";
	}
}

function OnSubmit(form)
{
	if (form.Name.value == "")
	{
		alert("名称不能空！");
		form.Name.select();
		return false;
	}
	
	if (!IsAllowedType(form.Picture.value, form.PictureAllowedType.value))
	{
		alert("图片类型应为：" + form.PictureAllowedType.value);
		form.Picture.select();
		return false;
	}

	var data = "Kind=<%=Request.QueryString["Kind"]%>&Name=" + encodeURIComponent(form.Name.value);
	data += "&ParentID=" + form.ParentID.value;
	data += "&MetaKeywords=" + encodeURIComponent(form.MetaKeywords.value);
	data += "&MetaDescription=" + encodeURIComponent(form.MetaDescription.value);
	_uploadPicture = _uploader.NeedUpload("Picture");
	if (!_uploadPicture)
		data += "&Picture=" + encodeURIComponent(form.Picture.value);
	data += "&IsRecommended=" + document.getElementById("IsRecommendedYes").checked;
	data += "&IsHeld=" + document.getElementById("IsHeldYes").checked;
	
	document.getElementById("Submit").disabled = true;
	window.status = "正在添加类别...";
	_action = "Add";
	_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=ProductCategory&Operation=Add", data, XmlHttpCallBack);
	return false;
}

function Kind_OnClick()
{
	var kind;
	var inputs = document.getElementsByTagName("INPUT");
	for (var i = 0; i < inputs.length; i++)
	{
		if (inputs[i].name == "Kind" && inputs[i].checked)
		{
			kind = inputs[i].value;
			break;
		}
	}
	window.location.href = HandleFake404("add.aspx?Kind=" + kind);
}
</script>
</head>
<body>
<div class="WhiteHeader">
	<div class="Left"><img src="<%=ImagePath%>close_frame.gif" onclick="OpenCloseLeftFrame()" /></div>
	<div class="Title">添加类别</div>
	<div class="Right">
		<ilgharUC:LanguageMenu runat="server" />
		<img height="15" src="<%=ImagePath%>dropdown.gif" onmouseover="this.src='<%=ImagePath%>dropdown_over.gif';ShowLanguageMenu(this);" onmouseout="this.src='<%=ImagePath%>dropdown.gif'" />
		语言：<%=CurrentLanguage%>
	</div>
</div>
<div class="Block">
	<ul class="TabMenu">
		<li class="Left"></li>
		<li class="Middle"><a href="list.aspx?Lang=<%=ContentLang%>&amp;Kind=<%=Request.QueryString["Kind"]%>">类别列表</a></li>
		<li class="Right"></li>
		<li class="Left Selected"></li>
		<li class="Middle Selected">添加类别</li>
		<li class="Right Selected"></li>
	</ul>
	<ul class="Title">
		<li class="Left"></li>
		<li class="Middle"></li>
		<li class="Right"></li>
	</ul>
	<div class="ToolBar">
		<%If Request.QueryString["Kind"] == "AutoSite"%>
			<input type="radio" name="Kind" id="AutoSite" value="AutoSite" checked="checked" onclick="Kind_OnClick()" /><label for="AutoSite">智能建站</label>
		<%Else%>
			<input type="radio" name="Kind" id="AutoSite" value="AutoSite" onclick="Kind_OnClick()" /><label for="AutoSite">智能建站</label>
		<%EndIf%>
		<%If Request.QueryString["Kind"] == "Host"%>
			<input type="radio" name="Kind" id="Host" value="Host" checked="checked" onclick="Kind_OnClick()" /><label for="Host">虚拟主机</label>
		<%Else%>
			<input type="radio" name="Kind" id="Host" value="Host" onclick="Kind_OnClick()" /><label for="Host">虚拟主机</label>
		<%EndIf%>
		<%If Request.QueryString["Kind"] == "WebSite"%>
			<input type="radio" name="Kind" id="WebSite" value="WebSite" checked="checked" onclick="Kind_OnClick()" /><label for="WebSite">网站</label>
		<%Else%>
			<input type="radio" name="Kind" id="WebSite" value="WebSite" onclick="Kind_OnClick()" /><label for="WebSite">网站</label>
		<%EndIf%>
		<%If Request.QueryString["Kind"] == "Set"%>
			<input type="radio" name="Kind" id="Set" value="Set" checked="checked" onclick="Kind_OnClick()" /><label for="Set">套餐</label>
		<%Else%>
			<input type="radio" name="Kind" id="Set" value="Set" onclick="Kind_OnClick()" /><label for="Set">套餐</label>
		<%EndIf%>
		<%If String.IsNullOrEmpty(Request.QueryString["Kind"])%>
			<input type="radio" name="Kind" id="Other" value="" checked="checked" onclick="Kind_OnClick()" /><label for="Other">其他</label>
		<%Else%>
			<input type="radio" name="Kind" id="Other" value="" onclick="Kind_OnClick()" /><label for="Other">其他</label>
		<%EndIf%>
	</div>
	<form method="post" onsubmit="return OnSubmit(this)">
		<table border="0" cellpadding="4" cellspacing="1">
			<tbody>
				<tr>
					<th width="120">所属类别：</th>
					<td>
						<select name="ParentID" class="<%=ContentLang%>Font">
							<option value="">未指定</option>
							<ilghar:Tree Object="ProductCategory" Condition="Kind=Request.QueryString['Kind']">
								<ilghar:Control>
									<ilghar:Space>&nbsp;&nbsp;</ilghar:Space>
									<ilghar:Line>│</ilghar:Line>
									<ilghar:TopOpen>┌</ilghar:TopOpen>
									<ilghar:Top>┌</ilghar:Top>
									<ilghar:MiddleOpen>├</ilghar:MiddleOpen>
									<ilghar:Middle>├</ilghar:Middle>
									<ilghar:BottomOpen>└</ilghar:BottomOpen>
									<ilghar:Bottom>└</ilghar:Bottom>
								</ilghar:Control>
								<ilghar:Record>
									<option value="<%=ID%>"><%=Control%><%=Name%></option>
									<%=ChildRecords%>
								</ilghar:Record>
							</ilghar:Tree>		
						</select>
					</td>
				</tr>
				<tr>
					<th>名称：</th>
					<td><input type="text" name="Name" maxlength="50" class="Text <%=ContentLang%>Font" /></td>
				</tr>
				<tr>
					<th>图片：</th>
					<td>
						<input id="PictureTextbox" type="text" name="Picture" size="60" class="Text" onchange="document.getElementById('PictureView').src = this.value" />
						<input id="PictureBrowse" type="button" value="浏览..." />
						<input type="hidden" name="PictureAllowedType" value="gif|jpg|jpeg|png|bmp" />
						<img height="22" id="PictureView" alt="预览" style="vertical-align:bottom" />
					</td>
				</tr>
				<tr>
					<th>是否推荐：</th>
					<td>
						<input type="radio" name="IsRecommended" id="IsRecommendedYes" /><label for="IsRecommendedYes">是</label>
						<input type="radio" name="IsRecommended" id="IsRecommendedNo" checked="checked" /><label for="IsRecommendedNo">否</label>
					</td>
				</tr>
				<tr>
					<th>是否置顶：</th>
					<td>
						<input type="radio" name="IsHeld" id="IsHeldYes" /><label for="IsHeldYes">是</label>
						<input type="radio" name="IsHeld" id="IsHeldNo" checked="checked" /><label for="IsHeldNo">否</label>
					</td>
				</tr>
				<tr>
					<th>Meta：</th>
					<td>
						Keywords：<input type="text" name="MetaKeywords" size="20" maxlength="255" class="Text <%=ContentLang%>Font" />
						Description：<input type="text" name="MetaDescription" size="20" maxlength="255" class="Text <%=ContentLang%>Font" />
					</td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="2">
						<input type="submit" id="Submit" value="添加" />
						<input type="reset" value="清空" />
					</td>
				</tr>
			</tfoot>
		</table>
	</form>
	<div class="Footer"></div>
</div>
<script type="text/javascript">
_uploader.Init({WebPath:"<%=WebPath%>",OnComplete:XmlHttpCallBack});
_uploader.Add("Picture", "PictureTextbox", "PictureBrowse");

HandleFake404();
</script>
</body>
</html>