<%@ 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" -->
<ilghar:Get ID="Config" Object="InstanceConfig" Operation="GetBasicSettings()" />
<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="<%=Manager.GetModulePath(null)%><%=Instance[IlgharCMS.SystemModule.Alias.Module.Namespace]%>/alias.js"></script>
<script type="text/javascript" src="<%=CommonPath%>ajax.js"></script>
<script type="text/javascript" src="<%=CommonPath%>uploader.js"></script>
<script type="text/javascript" src="<%=CommonPath%>xmldom.js"></script>
<script type="text/javascript" src="<%=JsPath%>common.js"></script>
<script type="text/javascript" src="<%=CommonPath%>IlgharHtmlEditor.js"></script>
<ilgharUC:Ime Ime="true" Eot="true" runat="server" />
<style type="text/css">
#PropertyTable,#ParameterTable,#BindingTable,#PresentTable{background:#FFF}
#PropertyTable TH{width:120px}
#BindingTable,#PresentTable{width:400px}
#BindingTable THEAD TH,#BindingTable TD,#PresentTable THEAD TH,#PresentTable TD{text-align:center}
</style>
<script type="text/javascript">
var _action = null;
var _productInnerID = 0;
var _uploadPicture = false;
var _uploadThumbnail = false;
var _uploadWebSite = false;
var _xmlData = null;
var _bindings = new Array();
var _bindingIndex = 0;
var _presents = new Array();
var _presentIndex = 0;
function XmlHttpCallBack(xmlHttp)
{
	if (xmlHttp == null || xmlHttp.status == 200)
	{
		if (_action == "Add")
		{
			_productID = xmlHttp.responseText;
			window.status = "添加产品完成！";

			<%If Request.QueryString["Kind"] == "AutoSite"%>
				if (document.getElementById("BindingHost").hostID != "")
				{
					_action = "BindingHost";
					_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product.Binding&Operation=Add", "ProductID=" + _productID + "&BindingID=" + document.getElementById("BindingHost").hostID + "&Amount=1&IsPresent=false", XmlHttpCallBack);
				}
				else
			<%ElseIf Request.QueryString["Kind"] == "Set"%>
				if (_bindingIndex < _bindings.length)
				{
					_action = "AddBinding";
					window.status = "正在添加捆绑的产品...";
					_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product.Binding&Operation=Add", "ProductID=" + _productID + "&BindingID=" + _bindings[_bindingIndex].BindingID + "&Amount=" + _bindings[_bindingIndex++].Amount + "&IsPresent=false", XmlHttpCallBack);
				}
				else
			<%EndIf%>
			if (_presentIndex < _presents.length)
			{
				_action = "AddPresent";
				window.status = "正在添加赠品...";
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product.Binding&Operation=Add", "ProductID=" + _productID + "&BindingID=" + _presents[_presentIndex].BindingID + "&Amount=" + _presents[_presentIndex++].Amount + "&IsPresent=true", XmlHttpCallBack);
			}
			else if (_uploadPicture || _uploadThumbnail || _uploadWebSite)
			{
				_action = "GetInnerIDFromGuid";
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productID, null, XmlHttpCallBack);
			}
			else
			{
				alert("添加成功！");
				window.status = "";
				document.getElementById("Submit").disabled = false;
			}
		}
		else if (_action == "BindingHost")
		{
			_action = "BindingWebSite";
			_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product.Binding&Operation=Add", "ProductID=" + _productID + "&BindingID=" + document.getElementById("BindingWebSite").webSiteID + "&Amount=1&IsPresent=false", XmlHttpCallBack);
		}
		else if (_action == "BindingWebSite")
		{
			if (_presentIndex < _presents.length)
			{
				_action = "AddPresent";
				window.status = "正在添加赠品...";
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product.Binding&Operation=Add", "ProductID=" + _productID + "&BindingID=" + _presents[_presentIndex].BindingID + "&Amount=" + _presents[_presentIndex++].Amount + "&IsPresent=true", XmlHttpCallBack);
			}
			else if (_uploadPicture || _uploadThumbnail || _uploadWebSite)
			{
				_action = "GetInnerIDFromGuid";
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productID, null, XmlHttpCallBack);
			}
			else
			{
				alert("添加成功！");
				window.status = "";
				document.getElementById("Submit").disabled = false;
			}
		}
		else if (_action == "AddBinding")
		{
			if (_bindingIndex < _bindings.length)
			{
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product.Binding&Operation=Add", "ProductID=" + _productID + "&BindingID=" + _bindings[_bindingIndex].BindingID + "&Amount=" + _bindings[_bindingIndex++].Amount + "&IsPresent=false", XmlHttpCallBack);
			}
			else if (_presentIndex < _presents.length)
			{
				_action = "AddPresent";
				window.status = "正在添加赠品...";
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product.Binding&Operation=Add", "ProductID=" + _productID + "&BindingID=" + _presents[_presentIndex].BindingID + "&Amount=" + _presents[_presentIndex++].Amount + "&IsPresent=true", XmlHttpCallBack);
			}
			else if (_uploadPicture || _uploadThumbnail || _uploadWebSite)
			{
				_action = "GetInnerIDFromGuid";
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productID, null, XmlHttpCallBack);
			}
			else
			{
				alert("添加成功！");
				window.status = "";
				document.getElementById("Submit").disabled = false;
			}
		}
		else if (_action == "AddPresent")
		{
			if (_presentIndex < _presents.length)
			{
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product.Binding&Operation=Add", "ProductID=" + _productID + "&BindingID=" + _presents[_presentIndex].BindingID + "&Amount=" + _presents[_presentIndex++].Amount + "&IsPresent=true", XmlHttpCallBack);
			}
			else if (_uploadPicture || _uploadThumbnail || _uploadWebSite)
			{
				_action = "GetInnerIDFromGuid";
				_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productID, null, XmlHttpCallBack);
			}
			else
			{
				alert("添加成功！");
				window.status = "";
				document.getElementById("Submit").disabled = false;
			}
		}
		else if (_action == "GetInnerIDFromGuid")
		{
			_productInnerID = xmlHttp.responseText;

			if (_uploadPicture)
			{
				_action = "UploadPicture";
				window.status = "开始上传大图...";
				_uploader.Init({Status:"正在上传大图...",Params:"Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productInnerID + "&MakeThumbnail=" + document.getElementById("MakeThumbnail").checked + "&AddWaterMark=" + document.getElementById("AddWaterMark").checked});
				_uploader.Upload("Picture");
			}
			else if (_uploadThumbnail)
			{
				_action = "UploadThumbnail";
				window.status = "开始上传小图...";
				_uploader.Init({Status:"正在上传小图...",Params:"Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productInnerID});
				_uploader.Upload("Thumbnail");
			}
			else if (_uploadWebSite)
			{
				_action = "UploadWebSite";
				window.status = "开始上传网站...";
				_uploader.Init({Status:"正在上传网站...",Params:"Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productInnerID});
				_uploader.Upload("File");
			}
		}
		else if (_action == "UploadPicture")
		{
			if (arguments.length == 2)
			{
				alert(arguments[1]);
				window.status = "";
				document.getElementById("Submit").disabled = false;
				return;
			}
			
			window.status = "大图上传完毕！";	
			
			if (_uploadThumbnail)
			{
				_action = "UploadThumbnail";
				window.status = "开始上传小图...";
				_uploader.Init({Status:"正在上传小图...",Params:"Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productInnerID});
				_uploader.Upload("Thumbnail");
			}
			else if (_uploadWebSite)
			{
				_action = "UploadWebSite";
				window.status = "开始上传网站...";
				_uploader.Init({Status:"正在上传网站...",Params:"Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productInnerID});
				_uploader.Upload("File");
			}
			else
			{
				alert("添加成功！");
				document.getElementById("Submit").disabled = false;
				window.status = "";
			}
		}
		else if (_action == "UploadThumbnail")
		{
			if (arguments.length == 2)
			{
				alert(arguments[1]);
				window.status = "";
				document.getElementById("Submit").disabled = false;
				return;
			}
			
			window.status = "小图上传完毕！";	
			
			if (_uploadWebSite)
			{
				_action = "UploadWebSite";
				window.status = "开始上传网站...";
				_uploader.Init({Status:"正在上传网站...",Params:"Lang=<%=ContentLang%>&Object=Product&Operation=" + _action + "&ID=" + _productInnerID});
				_uploader.Upload("File");
			}
			else
			{
				alert("添加成功！");
				document.getElementById("Submit").disabled = false;
				window.status = "";
			}
		}
		else if (_action == "UploadWebSite")
		{
			if (arguments.length == 2)
				alert(arguments[1]);
			else
				alert("添加成功！");
			document.getElementById("Submit").disabled = false;
			window.status = "";
		}
		else if (_action == "DataList")
		{
			_xmlData = CreateXmlDom();
			_xmlData.loadXML(xmlHttp.responseText);
			CMSID_OnChange();
		}
	}
	else
	{
		if (_action == "Add")
			alert("添加失败！请查看日志！");
		else if (_action == "GetInnerIDFromGuid")
			alert("获取InnerID失败！请查看日志！");
		else if (_action == "UploadPicture")
			alert("上传大图失败！请查看日志！");
		else if (_action == "UploadThumbnail")
			alert("上传小图失败！请查看日志！");
		else if (_action == "UploadWebSite")
			alert("上传网站失败！请查看日志！");
		else if (_action == "DataList")
			alert("获取数据列表失败！请查看日志！");
		else if (_action == "BindingHost")
			alert("添加虚拟主机失败！请查看日志！");
		else if (_action == "BindingWebSite")
			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;
	}
	
	if (!IsAllowedType(form.Thumbnail.value, form.ThumbnailAllowedType.value))
	{
		alert("小图类型应为：" + form.ThumbnailAllowedType.value);
		form.Thumbnail.select();
		return false;
	}
	
	if (!form.HitCount.value.match(/^\d+$/))
	{
		alert("人气不正确！");
		form.HitCount.select();
		return false;
	}

	if (!form.Up.value.match(/^\d+$/))
	{
		alert("顶不正确！");
		form.Up.select();
		return false;
	}

	if (!form.Down.value.match(/^\d+$/))
	{
		alert("踩不正确！");
		form.Down.select();
		return false;
	}
	
	if (!form.Price.value.match(/^\d+(\.\d+)?$/))
	{
		alert("价格格式不正确！");
		form.Price.select();
		return false;
	}	
	
	<%If Request.QueryString["Kind"] == "WebSite"%>
		if (!IsAllowedType(form.File.value, form.FileAllowedType.value))
		{
			alert("网站文件类型应为：" + form.FileAllowedType.value);
			form.File.select();
			return false;
		}
	<%ElseIf Request.QueryString["Kind"] == "Host"%>
		if (!form.SpaceSize.value.match(/^\d+$/))
		{
			alert("空间大小不正确！");
			form.SpaceSize.select();
			return false;
		}
		
		if (!form.MaxConnections.value.match(/^\d+$/))
		{
			alert("最大并发连接数不正确！");
			form.MaxConnections.select();
			return false;
		}
		
		if (!form.MaxBandwidth.value.match(/^\d+$/))
		{
			alert("最大网络带宽不正确！");
			form.MaxBandwidth.select();
			return false;
		}
		
		if (!form.ServerBindingsCount.value.match(/^\d+$/))
		{
			alert("可绑定域名个数不正确！");
			form.ServerBindingsCount.select();
			return false;
		}
		
		if (!form.TrialDay.value.match(/^\d+$/))
		{
			alert("试用天数不正确！");
			form.TrialDay.select();
			return false;
		}
	<%ElseIf Request.QueryString["Kind"] == "AutoSite"%>
		if (document.getElementById("BindingHost").hostID == "")
		{
			alert("请选择虚拟主机！");
			return false;
		}
	
		if (document.getElementById("BindingWebSite").webSiteID == "")
		{
			alert("请选择网站！");
			return false;
		}
	
		if (!form.TrialDay.value.match(/^\d+$/))
		{
			alert("试用天数不正确！");
			form.TrialDay.select();
			return false;
		}
	<%ElseIf Request.QueryString["Kind"] == "Set"%>
		_bindingIndex = 0;
		_bindings.length = 0;
		var inputs = document.getElementById("BindingDiv").getElementsByTagName("INPUT");
		for (var i = 0; i < inputs.length; i += 2)
		{
			if (!inputs[i].checked)
				continue;
			
			if (!inputs[i + 1].value.match(/^\d+$/))
			{
				alert("数量格式不正确！");
				inputs[i + 1].select();
				return false;
			}
			
			var binding = new Object();
			binding.BindingID = inputs[i].value;
			binding.Amount = inputs[i + 1].value;
			_bindings[_bindings.length] = binding;
		}
	<%EndIf%>
	
	_presentIndex = 0;
	_presents.length = 0;
	var inputs = document.getElementById("PresentDiv").getElementsByTagName("INPUT");
	for (var i = 0; i < inputs.length; i += 2)
	{
		if (!inputs[i].checked)
			continue;
		
		if (!inputs[i + 1].value.match(/^\d+$/))
		{
			alert("数量格式不正确！");
			inputs[i + 1].select();
			return false;
		}
		
		var present = new Object();
		present.BindingID = inputs[i].value;
		present.Amount = inputs[i + 1].value;
		_presents[_presents.length] = present;
	}
	
	SetCookie("CategoryID", form.CategoryID.value, 10*360*24*60);	
	SetCookie("UnitID", form.UnitID.value, 10*360*24*60);	

	var category = form.CategoryID.options[form.CategoryID.selectedIndex];
	var unit = form.UnitID.options[form.UnitID.selectedIndex];

	var data = "Kind=<%=Request.QueryString["Kind"]%>&Name=" + encodeURIComponent(form.Name.value);
	if (form.GuidCheckBox.checked)
		data += "&ID=" + form.ID.value;
	data += "&Number=" + encodeURIComponent(form.Number.value == "" ? FormatDate(new Date(), "YYYYMMDDhhmmssSSS") : form.Number.value);
	data += "&CategoryID=" + category.value;
	data += "&CategoryInnerID=" + category.innerID;
	data += "&CategoryName=" + encodeURIComponent(category.name);
	data += "&UnitID=" + unit.value;
	data += "&UnitName=" + encodeURIComponent(unit.name);
	data += "&Price=" + encodeURIComponent(form.Price.value);
	data += "&HitCount=" + form.HitCount.value;
	data += "&Up=" + form.Up.value;
	data += "&Down=" + form.Down.value;
	data += "&IsDisplay=" + document.getElementById("IsDisplayYes").checked;
	data += "&IsRecommended=" + document.getElementById("IsRecommendedYes").checked;
	data += "&IsHeld=" + document.getElementById("IsHeldYes").checked;
	data += "&MetaKeywords=" + encodeURIComponent(form.MetaKeywords.value);
	data += "&MetaDescription=" + encodeURIComponent(form.MetaDescription.value);
	var editor = FCKeditorAPI.GetInstance("HtmlEditor");
	if (editor.IsDirty())
		data += "&Description=" + encodeURIComponent(editor.GetXHTML(false));
	_uploadPicture = _uploader.NeedUpload("Picture");
	if (!_uploadPicture)
		data += "&Picture=" + encodeURIComponent(form.Picture.value);
	if (form.MakeThumbnail.checked)
	{
		_uploadThumbnail = false;
	}
	else
	{
		_uploadThumbnail = _uploader.NeedUpload("Thumbnail");
		if (!_uploadThumbnail)
			data += "&Thumbnail=" + encodeURIComponent(form.Thumbnail.value);
	}
	<%If Request.QueryString["Kind"] == "WebSite"%>
		data += "&CMSID=" + form.CMSID.value;
		data += "&DataID=" + form.DataID.value;
		_uploadWebSite = _uploader.NeedUpload("File");
	<%ElseIf Request.QueryString["Kind"] == "Host"%>
		data += "&OS=" + form.OS.value;
		data += "&SpaceSize=" + form.SpaceSize.value;
		data += "&MaxConnections=" + form.MaxConnections.value;
		data += "&MaxBandwidth=" + form.MaxBandwidth.value;
		data += "&ServerBindingsCount=" + form.ServerBindingsCount.value;
		var script = GetChecked("Script");
		if (script != "")
			data += "&Script=|" + script + "|";
		data += "&CanTry=" + document.getElementById("CanTryYes").checked;
		data += "&TrialDay=" + form.TrialDay.value;
	<%ElseIf Request.QueryString["Kind"] == "AutoSite"%>
		data += "&CanTry=" + document.getElementById("CanTryYes").checked;
		data += "&TrialDay=" + form.TrialDay.value;
	<%EndIf%>
	
	document.getElementById("Submit").disabled = true;
	window.status = "正在操作...";
	_action = "Add";
	_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product&Operation=Add", data, XmlHttpCallBack);
	return false;
}

function SelectFile(type, path)
{
	var form = document.forms[0];
	switch (type)
	{
		case "Picture":
			form.Picture.value = path;
			document.getElementById("PictureView").src = path;
			break;
		case "Thumbnail":
			form.Thumbnail.value = path;
			document.getElementById("ThumbnailView").src = path;
			break;
	}	
}

function ShowSelectFileDialog(type)
{
	var path = "<%=AdminPath%>System/file_manager/select.aspx?Lang=<%=ContentLang%>&Type=" + type + "&ListByPicture=";
	switch (type)
	{
		case "Picture":
			path += "true&Root=<%=Config[ProductPictureFolder]%>";
			break;
		case "Thumbnail":
			path += "true&Root=<%=Config[ProductThumbnailFolder]%>";
			break;
	}
	
	path = HandleFake404(path);
	if (g_browser == "IE")
		window.showModalDialog(path, window, "status=0;dialogWidth=900px;dialogHeight=600px;center=1;help=0;resizable=1;scroll=0");
	else
		window.open(path,null,"width=900,height=600,menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,modal=yes");
}

function ShowSelectDialog(type)
{
	var path;
	if (type == "Binding" || type == "Present" || type == "Host" || type == "WebSite")
		path = "select.aspx?Lang=<%=ContentLang%>&Type=" + type;
		
	path = HandleFake404(path);
	if (g_browser == "IE")
		window.showModalDialog(path, window, "status=0;dialogWidth=500px;dialogHeight=500px;center=1;help=0;resizable=1;scroll=1");
	else
		window.open(path,null,"width=500,height=500,menubar=no,toolbar=no,location=no,scrollbars=yes,status=no,modal=yes");
}

function SelectBinding(control, checked)
{
	var checkbox = document.getElementById("Binding" + control.InnerID);
	if (checkbox != null)
	{
		checkbox.checked = checked;
		return;
	}
	
	var cell1Html = "<input type=\"checkbox\" id=\"Binding" + control.InnerID + "\" value=\"" + control.ID + "\" checked=\"checked\" />";
	var cell2Html = control.Name;
	var cell3Html = "<input type=\"text\" id=\"BindingAmount" + control.InnerID + "\" value=\"" + control.Amount + "\" size=\"5\" />";
	
	var table = document.getElementById("BindingTable");
	if (table == null)
	{
		var html = "<table id=\"BindingTable\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">\
						<thead>\
							<tr>\
								<th width=\"40\">选择</th>\
								<th>名称</th>\
								<th width=\"60\">数量</th>\
							</tr>\
						</thead>\
						<tbody>\
							<tr>\
								<td><!--Cell1--></td>\
								<td><!--Cell2--></td>\
								<td><!--Cell3--></td>\
							</tr>\
						</tbody>\
					</table>";
		html = html.replace("<!--Cell1-->", cell1Html);
		html = html.replace("<!--Cell2-->", cell2Html);
		html = html.replace("<!--Cell3-->", cell3Html);
		document.getElementById("BindingDiv").innerHTML = html;
	}
	else
	{
		var row = table.insertRow();
		var cell1 = row.insertCell();
		cell1.innerHTML = cell1Html;
		var cell2 = row.insertCell();
		cell2.innerHTML = cell2Html;
		var cell3 = row.insertCell();
		cell3.innerHTML = cell3Html;
	}
}

function SelectPresent(control, checked)
{
	var checkbox = document.getElementById("Present" + control.InnerID);
	if (checkbox != null)
	{
		checkbox.checked = checked;
		return;
	}
	
	var cell1Html = "<input type=\"checkbox\" id=\"Present" + control.InnerID + "\" value=\"" + control.ID + "\" checked=\"checked\" />";
	var cell2Html = control.Name;
	var cell3Html = "<input type=\"text\" id=\"PresentAmount" + control.InnerID + "\" value=\"" + control.Amount + "\" size=\"5\" />";
	
	var table = document.getElementById("PresentTable");
	if (table == null)
	{
		var html = "<table id=\"PresentTable\" border=\"0\" cellpadding=\"4\" cellspacing=\"1\">\
						<thead>\
							<tr>\
								<th width=\"40\">选择</th>\
								<th>名称</th>\
								<th width=\"60\">数量</th>\
							</tr>\
						</thead>\
						<tbody>\
							<tr>\
								<td><!--Cell1--></td>\
								<td><!--Cell2--></td>\
								<td><!--Cell3--></td>\
							</tr>\
						</tbody>\
					</table>";
		html = html.replace("<!--Cell1-->", cell1Html);
		html = html.replace("<!--Cell2-->", cell2Html);
		html = html.replace("<!--Cell3-->", cell3Html);
		document.getElementById("PresentDiv").innerHTML = html;
	}
	else
	{
		var row = table.insertRow();
		var cell1 = row.insertCell();
		cell1.innerHTML = cell1Html;
		var cell2 = row.insertCell();
		cell2.innerHTML = cell2Html;
		var cell3 = row.insertCell();
		cell3.innerHTML = cell3Html;
	}
}

function SelectHost(control)
{
	var span = document.getElementById("BindingHost");
	span.innerHTML = control.Name;
	span.hostID = control.ID;
}

function SelectWebSite(control)
{
	var span = document.getElementById("BindingWebSite");
	span.innerHTML = control.Name;
	span.webSiteID = control.ID;
}

function MakeThumbnail_OnClick(checkbox)
{
	if (checkbox.checked)
		document.getElementById("ThumbnailRow").style.display = "none";
	else
		document.getElementById("ThumbnailRow").style.display = "";
}

function GuidCheckBox_OnClick(input)
{
	input.form.ID.disabled = !input.checked;
	if (input.form.ID.disabled)
		input.form.ID.className = "Disabled";
	else
		input.form.ID.className = "Text";
}

function CMSID_OnChange()
{
	var form = document.forms[0];
	form.DataID.length = 0;
	if (form.CMSID.selectedIndex == 0)
	{
		form.DataID.options.add(new Option("未指定", ""));
	}
	else if (_xmlData != null)
	{
		var items = _xmlData.selectNodes("//Item[" + IlgharCMS.HostModule.Data.CMSVersion + "='" + form.CMSID.options[form.CMSID.selectedIndex].version + "']");
		for (var i = 0; i < items.length; i++)
		{
			var id = items[i].selectSingleNode(IlgharCMS.HostModule.Data.ID).text;
			var name = items[i].selectSingleNode(IlgharCMS.HostModule.Data.Name).text;
			form.DataID.options.add(new Option(name, id));
		}
	}
	else
	{
		_action = "DataList";
		_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Data&Operation=List", null, XmlHttpCallBack);
	}
}

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%>">产品列表</a></li>
		<li class="Right"></li>
		<li class="Left Selected"></li>
		<li class="Middle Selected">添加产品</li>
		<li class="Right Selected"></li>
		<li class="Left"></li>
		<li class="Middle"><a href="replace.aspx?Lang=<%=ContentLang%>">批量替换</a></li>
		<li class="Right"></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>
						<input type="text" name="Name" size="30" maxlength="50" class="Text <%=ContentLang%>Font" />
						<input type="checkbox" id="GuidCheckBox" onclick="GuidCheckBox_OnClick(this)" /><label for="GuidCheckBox">Guid：</label><input type="text" name="ID" size="40" maxlength="40" disabled="disabled" class="Disabled" />
					</td>
				</tr>
				<tr>
					<th>编号：</th>
					<td><input type="text" name="Number" size="30" maxlength="50" class="Text" />
						如果留空，则会自动生成
					</td>
				</tr>
				<tr>
					<th>类别：</th>
					<td>
						<select name="CategoryID" class="<%=ContentLang%>Font">
							<option innerID="0" name="">未指定</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%>" innerID="<%=InnerID%>" name="<%=Name%>"><%=Control%><%=Name%></option>
									<%=ChildRecords%>
								</ilghar:Record>
							</ilghar:Tree>
						</select>
					</td>
				</tr>
				<tr>
					<th>计量单位：</th>
					<td>
						<select name="UnitID" class="<%=ContentLang%>Font">
							<option value="">未指定</option>
							<ilghar:List Object="Unit">
								<ilghar:Record>
									<option name="<%=Name%>" value="<%=ID%>"><%=Name%></option>
								</ilghar:Record>
							</ilghar:List>
						</select>
					</td>
				</tr>
				<tr>
					<th>价格：</th>
					<td><input type="text" name="Price" maxlength="20" class="Text" /></td>
				</tr>
				<tr>
					<th>大图：</th>
					<td>
						<input id="PictureTextbox" type="text" name="Picture" size="55" class="Text" onchange="document.getElementById('PictureView').src = this.value" />
						<input id="PictureBrowse" type="button" value="浏览..." />
						<input type="button" value="选择..." onclick="ShowSelectFileDialog('Picture')" />
						<input type="hidden" name="PictureAllowedType" value="gif|jpg|jpeg|png|bmp" />
						<img height="22" id="PictureView" alt="大图" style="vertical-align:bottom" />
						<input type="checkbox" id="MakeThumbnail" onclick="MakeThumbnail_OnClick(this)" /><label for="MakeThumbnail">生成小图</label>
						<input type="checkbox" id="AddWaterMark" /><label for="AddWaterMark">水印</label>
					</td>
				</tr>
				<tr id="ThumbnailRow" style="display:none">
					<th>小图：</th>
					<td>
						<input id="ThumbnailTextbox" type="text" name="Thumbnail" size="55" class="Text" onchange="document.getElementById('ThumbnailView').src = this.value" />
						<input id="ThumbnailBrowse" type="button" value="浏览..." />
						<input type="button" value="选择..." onclick="ShowSelectFileDialog('Thumbnail')" />
						<input type="hidden" name="ThumbnailAllowedType" value="gif|jpg|jpeg|png|bmp" />
						<img height="22" id="ThumbnailView" alt="小图" style="vertical-align:bottom" />
					</td>
				</tr>
				<tr>
					<th>是否显示：</th>
					<td>
						<input type="radio" name="IsDisplay" id="IsDisplayYes" checked="checked" /><label for="IsDisplayYes">是</label>
						<input type="radio" name="IsDisplay" id="IsDisplayNo" /><label for="IsDisplayNo">否</label>
					</td>
				</tr>
				<tr>
					<th>属性：</th>
					<td>
						<table id="PropertyTable" border="0" cellpadding="4" cellspacing="1">
							<%If Request.QueryString["Kind"] == "WebSite"%>
								<tr>
									<th>CMS系统：</th>
									<td>
										<select name="CMSID" onchange="CMSID_OnChange()" class="<%=ContentLang%>Font">
											<option value="">未指定</option>
											<ilghar:List Object="CMS">
												<ilghar:Record>
													<option value="<%=ID%>" version="<%=Version%>"><%=Name%></option>
												</ilghar:Record>
											</ilghar:List>
										</select>
									</td>
								</tr>
								<tr>
									<th>数据：</th>
									<td>
										<select name="DataID" class="<%=ContentLang%>Font">
											<option value="">未指定</option>
										</select>
									</td>
								</tr>
								<tr>
									<th>文件：</th>
									<td>
										<input id="FileTextbox" type="text" name="File" size="60" disabled="disabled" class="Text" />
										<input id="FileBrowse" type="button" value="浏览..." />
										<input type="hidden" name="FileAllowedType" value="zip" />
									</td>
								</tr>
							<%ElseIf Request.QueryString["Kind"] == "Host"%>
								<tr>
									<th>操作系统：</th>
									<td>
										<select name="OS">
											<option value="Windows 2003">Windows 2003</option>
										</select>
									</td>
								</tr>
								<tr>
									<th>空间大小：</th>
									<td><input type="text" name="SpaceSize" size="5" maxlength="20" class="Text" />M</td>
								</tr>
								<tr>
									<th>最大并发连接数：</th>
									<td><input type="text" name="MaxConnections" value="0" size="5" maxlength="20" class="Text" />设置为0，则表示不限制</td>
								</tr>
								<tr>
									<th>最大网络带宽：</th>
									<td><input type="text" name="MaxBandwidth" value="0" size="5" maxlength="20" class="Text" />K，设置为0，则表示不限制</td>
								</tr>
								<tr>
									<th>可绑定域名个数：</th>
									<td><input type="text" name="ServerBindingsCount" size="5" maxlength="20" class="Text" /></td>
								</tr>
								<tr>
									<th>可支持脚本：</th>
									<td>
										<input type="checkbox" name="Script" id="ScriptAsp" value="asp" /><label for="ScriptAsp">Asp</label>
										<input type="checkbox" name="Script" id="ScriptAspNet20" value="aspnet2.0" onclick="if (!this.checked)document.getElementById('ScriptIlgharCMS').checked = false;" /><label for="ScriptAspNet20">Asp.Net2.0</label>
										<input type="checkbox" name="Script" id="ScriptIlgharCMS" value="IlgharCMS" onclick="if (this.checked)document.getElementById('ScriptAspNet20').checked = true;" /><label for="ScriptIlgharCMS">IlgharCMS</label>
									</td>
								</tr>
								<tr>
									<th>可否试用：</th>
									<td>
										<input type="radio" name="CanTry" id="CanTryYes" /><label for="CanTryYes">是</label>
										<input type="radio" name="CanTry" id="CanTryNo" checked="checked" /><label for="CanTryNo">否</label>
									</td>
								</tr>
								<tr>
									<th>试用天数：</th>
									<td><input type="text" name="TrialDay" value="0" size="5" maxlength="20" class="Text" />天</td>
								</tr>
							<%ElseIf Request.QueryString["Kind"] == "AutoSite"%>
								<tr>
									<th>虚拟主机：</th>
									<td><span id="BindingHost" hostID="" class="<%=ContentLang%>Font"></span><input type="button" value="选择" onclick="ShowSelectDialog('Host')" /></td>
								</tr>
								<tr>
									<th>网站：</th>
									<td><span id="BindingWebSite" webSiteID="" class="<%=ContentLang%>Font"></span><input type="button" value="选择" onclick="ShowSelectDialog('WebSite')" /></td>
								</tr>
								<tr>
									<th>可否试用：</th>
									<td>
										<input type="radio" name="CanTry" id="CanTryYes" /><label for="CanTryYes">是</label>
										<input type="radio" name="CanTry" id="CanTryNo" checked="checked" /><label for="CanTryNo">否</label>
									</td>
								</tr>
								<tr>
									<th>试用天数：</th>
									<td><input type="text" name="TrialDay" value="0" size="5" maxlength="20" class="Text" />天</td>
								</tr>
							<%EndIf%>
						</table>
					</td>
				</tr>
				<%If Request.QueryString["Kind"] == "Set"%>
					<tr>
						<th>捆绑：</th>
						<td>
							<input type="button" class="Button" value="选择" onclick="ShowSelectDialog('Binding')" />
							<div id="BindingDiv"></div>
						</td>
					</tr>
				<%EndIf%>
				<tr style="display:none"><!--赠品没有进行测试，所以暂时屏蔽掉-->
					<th>赠品：</th>
					<td>
						<input type="button" class="Button" value="选择" onclick="ShowSelectDialog('Present')" />
						<div id="PresentDiv"></div>
					</td>
				</tr>
				<tr>
					<th>描述：</th>
					<td>
						<textarea id="HtmlEditor" EditorLang="<%=ContentLang%>" EditorInstanceID="<%=Channel[IlgharCMS.SystemModule.Alias.Instance.InnerID]%>" EditorUpload="<%=AdminPath%>" style="display:none;width:600px;height:400px"></textarea>
					</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>指标：</th>
					<td>
						人气：<input type="text" name="HitCount" value="0" size="10" maxlength="255" class="Text" />
						顶：<input type="text" name="Up" value="0" size="10" maxlength="255" class="Text" />
						踩：<input type="text" name="Down" value="0" size="10" maxlength="255" class="Text" />
					</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" class="Button" value="添加" /></td>
				</tr>
			</tfoot>
		</table>
	</form>
	<div class="Footer"></div>
</div>
<script type="text/javascript">
CheckAndSelect(GetCookie("CategoryID"), document.forms[0].UnitID);
CheckAndSelect(GetCookie("UnitID"), document.forms[0].UnitID);

var checkbox = document.getElementById("MakeThumbnail");
if (GetCookie("MakeThumbnail") == "false")
	checkbox.checked = false;
else
	checkbox.checked = true;
MakeThumbnail_OnClick(checkbox);

_uploader.Init({WebPath:"<%=WebPath%>",OnComplete:XmlHttpCallBack});
_uploader.Add("Picture", "PictureTextbox", "PictureBrowse");
_uploader.Add("Thumbnail", "ThumbnailTextbox", "ThumbnailBrowse");
<%If Request.QueryString["Kind"] == "WebSite"%>
	_uploader.Add("File", "FileTextbox", "FileBrowse");
<%EndIf%>

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