<%@ 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="<%=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%>xmldom.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 _xmlDoc = CreateXmlDom();
function XmlHttpCallBack(xmlHttp)
{
	if (xmlHttp.status == 200)
	{
		if (_action == "Replace")
		{
			alert("替换成功！");
			document.getElementById("Submit").disabled = false;
			window.status = "";
		}
		else if (_action == "CategoryList")
		{
			_xmlDoc.loadXML(xmlHttp.responseText);
			var childNodes = _xmlDoc.documentElement.childNodes;
			
			var from = "<select name=\"From\" class=\"<%=ContentLang%>Font\">";
			var to = "<select name=\"To\" class=\"<%=ContentLang%>Font\">";
			for (var i = 0; i < childNodes.length; i++)
			{
				if (typeof (childNodes[i].selectSingleNode) == "undefined")
					continue;
				
				var option = "<option value=\"" + childNodes[i].selectSingleNode(IlgharCMS.ShopModule.ProductCategory.ID).text + "\">" + childNodes[i].selectSingleNode(IlgharCMS.PictureModule.ProductCategory.Name).text + "</option>";
				from += option;
				to += option;
			}
			from += "</select>";
			to += "</select>";
			
			document.getElementById("FromTd").innerHTML = from;
			document.getElementById("ToTd").innerHTML = to;
			window.status = "";
		}
	}
	else
	{
		if (_action == "Replace")
			alert("替换失败！请查看日志！");
		else if (_action == "CategoryList")
			alert("获取类别列表失败！请查看日志！");
		else
			alert("失败！请查看日志！");
		
		document.getElementById("Submit").disabled = false;
		window.status = "";
	}
}

function OnSubmit(form)
{
	if (form.From.type == "text" && form.From.value == "")
	{
		alert("原值不能空！");
		form.From.select();
		return false;
	}
	
	var data = "Property=" + form.Property.value;
	data += "&From=" + encodeURIComponent(form.From.value);
	data += "&To=" + encodeURIComponent(form.To.value);
	
	document.getElementById("Submit").disabled = true;
	_action = "Replace";
	window.status = "正在替换...";
	_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Product&Operation=Replace", data, XmlHttpCallBack);
	return false;
}

function Property_OnChange(value)
{
	switch (value)
	{
		case "CategoryID":
			_action = "CategoryList";
			window.status = "正在获取类别...";
			_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=ProductCategory&Operation=List", null, XmlHttpCallBack);
			break;
		case "Name":
		case "Description":
			document.getElementById("FromTd").innerHTML = "<input type=\"text\" name=\"From\" class=\"Text <%=ContentLang%>Font\" />";
			document.getElementById("ToTd").innerHTML = "<input type=\"text\" name=\"To\" class=\"Text <%=ContentLang%>Font\" />";
			break;
		default:
			document.getElementById("FromTd").innerHTML = "<input type=\"text\" name=\"From\" size=\"40\" class=\"Text\" />";
			document.getElementById("ToTd").innerHTML = "<input type=\"text\" name=\"To\" size=\"40\" class=\"Text\" />";
			break;
	}
}
</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"></li>
		<li class="Middle"><a href="add.aspx?Lang=<%=ContentLang%>">添加产品</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>
	<form method="post" onsubmit="return OnSubmit(this)">
		<table border="0" cellpadding="4" cellspacing="1">
			<tbody>
				<tr>
					<th width="100">目标：</th>
					<td>
						<select name="Property" onchange="Property_OnChange(this.value)">
							<option value="Name">名称</option>
							<option value="Description">简介</option>
							<option value="Picture">大图</option>
							<option value="Thumbnail">小图</option>
							<option value="CategoryID">类别</option>
						</select>
					</td>
				</tr>
				<tr>
					<th>原值：</th>
					<td id="FromTd"><input type="text" name="From" class="Text <%=ContentLang%>Font" /></td>
				</tr>
				<tr>
					<th>新值：</th>
					<td id="ToTd"><input type="text" name="To" 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">
HandleFake404();
</script>
</body>
</html>