<%@ 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="Order" Object="Order" InnerID="Request.QueryString['ID']" />
<base target="_self" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Expires" content="Mon,1 Fab 1979 23:36:05 GMT" />
<title>生成退款单</title>
<link rel="stylesheet" type="text/css" href="<%=CommonPath%>jquery/themes/lightness/all.css" />
<ilghar:Comment><link rel="stylesheet" type="text/css" href="../../S01/CHS/css/common.css" /></ilghar:Comment>
<link rel="stylesheet" href="<%=CssPath%>common.css" />
<ilgharUC:Ime Ime="true" Eot="true" runat="server" />
<style type="text/css">
TD TABLE{background:#FFF}
TD TABLE TH{width:100px}
</style>
<script type="text/javascript">
var _page = "make_refund";
var _lang = "<%=ContentLang%>";
var _webPath = "<%=WebPath%>";
var _imagePath = "<%=ImagePath%>";
var _id = "<%=Request.QueryString["ID"]%>";
var _orderID = "<%=Order[ID]%>";
var _hasPayed = <%=Order[HasPayed]%>;
var _currency = "<%=Order[Currency]%>";
var _data;
var _lang_working = "正在操作...";
var _lang_operation_fail = "操作失败！";
var _lang_operation_success = "操作成功！";
var _lang_amount_incorrect = "退款金额格式不正确！";
var _lang_amount_less_than_zero = "退款金额必须大于零！";
var _lang_amount_greater_than_sum = "退款金额不能大于已付金额！";
var _lang_time_incorrect = "退款时间格式不正确！";
var _lang_making_refund = "正在生成退款单...";

//---
var _action = null;
var _data;
function XmlHttpCallBack(xmlHttp)
{
	if (xmlHttp.status == 200)
	{
		if (_action == "Submit")
		{
			window.status = "退款完成！";
			
			_action = "MakeRefund";
			window.status = "正在生成退款单...";
			_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Refund&Operation=Add", _data, XmlHttpCallBack);
		}
		else if (_action == "MakeRefund")
		{
			alert("退款成功！");
			document.getElementById("Submit").disabled = false;
			window.status = "";
			
			if (g_browser == "IE")
				window.dialogArguments.OnSearch();
			else
				window.opener.OnSearch();
			window.close();			
		}
	}
	else
	{
		if (_action == "Submit")
			alert("退款失败！请查看日志！");
		else if (_action == "MakePayment")
			alert("生成退款单失败！请查看日志！");
		else
			alert("失败！请查看日志！");
		document.getElementById("Submit").disabled = false;
		window.status = "";
	}
}

function OnSubmit(form)
{
	if (!form.Amount.value.match(/^\d+(\.\d+)?$/))
	{
		alert("退款金额格式不正确！");
		form.Amount.select();
		return false;
	}
	
	if (parseFloat(form.Amount.value) <= 0)
	{
		alert("退款金额必须大于零！");
		form.Amount.select();
		return false;
	}
	
	if (parseFloat(form.Amount.value) > <%=Order[HasPayed]%>)
	{
		alert("退款金额不能大于已付金额！");
		form.Amount.select();
		return false;
	}
	
	var dateTime = /^(\d{1,4})(-|\/)(\d{1,2})(-|\/)(\d{1,2})( (\d{1,2}):(\d{1,2}):(\d{1,2}))?$/;
	if (!dateTime.test(form.Time.value))
	{
		alert("退款时间格式不正确！");
		form.Time.select();
		return false;
	}
	
	var refundNumber = (form.Number.value == "" ? FormatDate(new Date(), "YYYYMMDDhhmmssSSS") : form.Number.value);

	_data = "OrderID=<%=Order[ID]%>&Currency=<%=Order[Currency]%>";
	_data += "&Number=" + refundNumber;
	_data += "&Name=" + encodeURIComponent(form.Name.value);
	_data += "&Phone=" + form.Phone.value;
	_data += "&Mobile=" + form.Mobile.value;
	_data += "&Email=" + form.Email.value;
	_data += "&QQ=" + form.QQ.value;
	_data += "&WW=" + form.WW.value;
	_data += "&MSN=" + form.MSN.value;
	_data += "&AccountInfo=" + encodeURIComponent(form.AccountInfo.value);
	_data += "&Amount=" + form.Amount.value;
	_data += "&Time=" + form.Time.value;
	_data += "&Memo=" + encodeURIComponent(form.Memo.value);
	
	document.getElementById("Submit").disabled = true;
	window.status = "正在操作...";
	_action = "Submit";
	_ajax.Post("<%=WebPath%>ilghar.aspx?Lang=<%=ContentLang%>&Object=Order&Operation=Refund&ID=<%=Request.QueryString["ID"]%>", "Amount=" + form.Amount.value + "&RefundNumber=" + refundNumber, XmlHttpCallBack);
	return false;
}
</script>
</head>
<body>
<div class="Block">
	<ul class="Title">
		<li class="Left"></li>
		<li class="Middle">生成退款单</li>
		<li class="Right"></li>
	</ul>
	<form>
		<table border="0" cellpadding="4" cellspacing="1">
			<tfoot>
				<tr><td colspan="2"><input type="submit" value="退款" /></td></tr>
			</tfoot>
			<tbody>
				<tr>
					<th width="120">订单号：</th>
					<td><%=Order[Number]%></td>
				</tr>
				<tr>
					<th>退款单号：</th>
					<td><input type="text" name="Number" size="30" maxlength="50" class="Text" />如果留空，则会自动生成</td>
				</tr>
				<tr>
					<th>收款人：</th>
					<td>
						<table border="0" cellpadding="4" cellspacing="1">
							<tr>
								<th>姓名：</th>
								<td><input type="text" name="Name" value="<%=Order[OrdererName]%>" maxlength="50" class="Text <%=ContentLang%>Font" /></td>
							</tr>
							<tr>
								<th>电话：</th>
								<td><input type="text" name="Phone" value="<%=Order[OrdererPhone]%>" maxlength="20" class="Text" /></td>
							</tr>
							<tr>
								<th>手机：</th>
								<td><input type="text" name="Mobile" value="<%=Order[OrdererMobile]%>" maxlength="20" class="Text" /></td>
							</tr>
							<tr>
								<th>Email：</th>
								<td><input type="text" name="Email" value="<%=Order[OrdererEmail]%>" maxlength="50" class="Text" /></td>
							</tr>
							<tr>
								<th>QQ：</th>
								<td><input type="text" name="QQ" value="<%=Order[OrdererQQ]%>" maxlength="20" class="Text" /></td>
							</tr>
							<tr>
								<th>WW：</th>
								<td><input type="text" name="WW" value="<%=Order[OrdererWW]%>" maxlength="50" class="Text" /></td>
							</tr>
							<tr>
								<th>MSN：</th>
								<td><input type="text" name="MSN" value="<%=Order[OrdererMSN]%>" maxlength="50" class="Text" /></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<th>货币：</th>
					<td><%=Order[Currency]%></td>
				</tr>
				<tr>
					<th>帐号信息：</th>
					<td><textarea name="AccountInfo" cols="70" rows="4" wrap="off" class="Text <%=ContentLang%>Font"></textarea></td>
				</tr>
				<tr>
					<th>退款金额：</th>
					<td><input type="text" name="Amount" value="0" size="5" maxlength="10" class="Text" /></td>
				</tr>
				<tr>
					<th>退款时间：</th>
					<td><input type="text" name="Time" value="<%=DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")%>" maxlength="20" class="Text" /></td>
				</tr>
				<tr>
					<th>备注：</th>
					<td><textarea name="Memo" cols="70" rows="4" wrap="off" class="Text <%=ContentLang%>Font"></textarea></td>
				</tr>
				<tr>
					<th>可退金额：</th>
					<td><%=Order[HasPayed]%></td>
				</tr>
			</tbody>
		</table>
	</form>
	<div class="Footer"></div>
</div>
<script type="text/javascript" src="<%=CommonPath%>jquery/core.js"></script>
<script type="text/javascript" src="<%=CommonPath%>jquery/ui.js"></script>
<script type="text/javascript" src="<%=CommonPath%>utility.js"></script>
<script type="text/javascript" src="<%=JsPath%>global.js"></script>
<script type="text/javascript" src="<%=JsPath%>shop.js"></script>
</body>
</html>