/// 购物车操作方法


// 封装下 Propertyt 的 AJAX 召唤方法
function callAjax(url, method, postBody, callBack)
{
	new Ajax.Request(url, {
	  encoding: "UTF-8", 
	  method: method,
	  postBody: postBody,
	  onSuccess: function(transport) {
		callBack(transport.responseXML);
	  }
	});
}

/// 列表添加购物车
function add2Cart(id)
{
	if (id == ""||id == null) return;
	try
	{
		$(id+"_add").update("正在添加...");
		$(id+"_add").title = "正在添加到购物车";
		add2CartWithCount(id, 1, -1, -1);
	}
	catch (e){};
}

/// 获取详细页上用户选择了哪个标签的ID
function getTagIdFromPage()
{
	var oRadios = document.getElementsByName("tagId");
	if (oRadios.length == 0) return;
	for (var i=0; i<oRadios.length; i++) if (oRadios[i].checked) return oRadios[i].value;
}
/// 详细页添加购物车
function add2CartWithCount(id, count, source)
{
	if (id == ""||id == null) return;
	if (count == ""||count == null) return;
	if (isNaN(count))
	{
		alert("购买数量请填写数值！");
		return;
	}
	else
	{
		if (count < 1)
		{
			alert("购买数量请填写大于等于 1 的数值！");
			return;
		}
	}
	if (source == ""||source == null) source = 1;
	var tid = getTagIdFromPage();
	if (tid == ""||tid == null) tid = -1;
	try
	{
		$(id+"_add").update("正在添加...");
		$(id+"_add").title = "正在添加到购物车";
	}
	catch (e){};
	var sXml = "<root cmd='{D96391E8-285B-4A6E-A908-F823DFE7B703}' id='"+id+"' count='"+count+"' source='"+source+"' tid='"+tid+"'/>";
	callAjax("ServerProcess.asp", "POST", sXml, doneAdd2CartWithCount);
}
//列表页/详细页点击后动作
function doneAdd2CartWithCount(o)
{
	if(o == null) return;
	var oRoot = o.documentElement;
	if (oRoot == null) return;
	var id = oRoot.firstChild.getAttribute("id");
	if (oRoot.firstChild.getAttribute("status") == "-1"||oRoot.firstChild.getAttribute("status") == -1)
	{
		alert(oRoot.firstChild.getAttribute("reason"));
		return;
	}
	try
	{
		$(id+"_add").update("已在购物车");
		$(id+"_add").title = "此产品已经加入购物车";
		if (oRoot.firstChild.getAttribute("source") == "-1"||oRoot.firstChild.getAttribute("source") == -1)
		{
			$(id+"_add").className = "inCartDiv";
		}
		else
		{
			$(id+"_add").className = "inCartDivs";
		}
	}
	catch (e){};
	if (oRoot.firstChild.getAttribute("log") == "-1"||oRoot.firstChild.getAttribute("log") == -1) document.location.href = "cart.asp";
	getCartSum();
}


// 被动获取当前购物车中的产品数量和总金额
function getCartSum()
{
	var sXml = "<root cmd='{C3F7A9EA-FBB1-4EE5-BBE0-767CF8F2CCAD}'/>";
	//alert(sXml);
	callAjax("ServerProcess.asp", "POST", sXml, doneGetCartSum);
}
function doneGetCartSum(o)
{
	if(o == null) return;
	var oNode = o.documentElement.firstChild;
	if (oNode == null) return;
	try
	{
		if (oNode.getAttribute("count") == 0||oNode.getAttribute("count") == "0")
		{
			$("myCartCount").update("您的购物车是空的");
		}
		else
		{
			$("myCartCount").update(oNode.getAttribute("count")+"枚&nbsp;(￥"+oNode.getAttribute("money")+")");
		}
	}
	catch (e){}
}


// 购物车删除操作
function delCart(id)
{
	if (id == ""||id == null) return;
	// remote delete files
	var sMsg = "删除数据后将不能恢复，您确定要执行删除操作？　　　";
	if(!confirm(sMsg)) return;
	callAjax("ServerProcess.asp", "POST", "<root cmd='{D56F1E25-F3B8-40A4-A8C7-B8E67BF33971}' id='"+id+"'/>", function (x){
		if (x == null) return;
		if (x.documentElement == null) return;
		if (x.documentElement.firstChild.getAttribute("status")==-1||x.documentElement.firstChild.getAttribute("status")=="-1") alert(x.documentElement.firstChild.getAttribute("reason"));
	});
	document.location.reload();
}


// 购物车删除操作（个人登录）
function delCart2(id)
{
	if (id == ""||id == null) return;
	// remote delete files
	var sMsg = "删除数据后将不能恢复，您确定要执行删除操作？　　　";
	if(!confirm(sMsg)) return;
	callAjax("ServerProcess.asp", "POST", "<root cmd='{166C9E53-8DA5-43CB-8852-269938027F4F}' id='"+id+"'/>", function (x){
		if (x == null) return;
		if (x.documentElement == null) return;
		if (x.documentElement.firstChild.getAttribute("status")==-1||x.documentElement.firstChild.getAttribute("status")=="-1") alert(x.documentElement.firstChild.getAttribute("reason"));
	});
	document.location.reload();
}


// 购物车清空操作
function delCartAll()
{
	var temp = event.srcElement;
	try{temp.disabled=true;}catch(e){};
	// remote delete files
	var sMsg = "此操作将删除您在购物车中的全部商品，删除数据后将不能恢复，您确定要执行删除操作？　　　";
	if(!confirm(sMsg))
	{
		try{temp.disabled=false;}catch(e){};
		return;
	}
	callAjax("ServerProcess.asp", "POST", "<root cmd='{A5789488-E9AF-46B8-9DCA-E26ADA30A023}'/>", function (x){
		if (x == null) return;
		if (x.documentElement == null) return;
		if (x.documentElement.firstChild.getAttribute("status")==-1||x.documentElement.firstChild.getAttribute("status")=="-1") alert(x.documentElement.firstChild.getAttribute("reason"));
	});
	document.location.reload();
}

// 获取当前页面上的全部产品数据成为 xml 
var rXml;
var alllllprice;
function getProductInfo2Xml(method)
{
	try
	{
		if (method == ""||method == null) method = -1;//默认不提交
		var o = document.getElementsByName("proId");
		var d = document.getElementsByName("opId");
		var p = document.getElementsByName("proPrice");
		var m = document.getElementsByName("proMoney");
		var t = document.getElementsByName("tag_id");
		var c = document.getElementsByName("tag_count");
		if (o.length != p.length || o.length != d.length || o.length != m.length)
		{
			alert("数据加载错误！");
			return;
		}
		//alert("proId"+o.length+"个\nproPrice"+p.length+"个\nproMoney"+m.length+"个");
		if (t.length != c.length)
		{
			alert("数据加载错误！");
			return;
		}
		var tCount = [0, 0];//一维数组 [0]=数量合计 [1]=快键贴数量合计
		var tArr = [];// 二维数组 [0]=标签ID [1]=标签订购数量 [2]=pid
		for (var i=0; i<t.length; i++)
		{
			if (c[i].value == "")
			{
				c[i].value = 1;
			}
			else
			{
				if (isNaN(c[i].value))
				{
					c[i].value = 1;
				}
				else
				{
					if (c[i].value < 0) c[i].value = 1;
				}
			}
			tArr[i] = [t[i].value, c[i].value, t[i].getAttribute("pid")];
			tCount[c[i].getAttribute("t")] = tCount[c[i].getAttribute("t")]+parseInt(c[i].value);
		}
		var oInnerXml = new ActiveXObject("Microsoft.XMLDOM");
		oInnerXml.async = false;	//同步传输
		oInnerXml.loadXML("<root/>");
		var oRoot = oInnerXml.documentElement;
		oRoot.setAttribute("cmd", "{E7C65A38-F3BC-4AED-9D51-6DB055D188C7}");
		var s_count = 0;
		var s_value = 0;
		for (var i=0; i<o.length; i++)
		{
			var oNode = oInnerXml.createElement("product");
			var count = 0;
			for (var j=0; j<tArr.length; j++)
			{
				if (tArr[j][2] == o[i].value)
				{
					var oTag = oInnerXml.createElement("tag");
					oTag.setAttribute("id", tArr[j][0]);
					oTag.setAttribute("count", tArr[j][1]);
					oNode.appendChild(oTag);
					count = count + parseInt(tArr[j][1]);
				}
			}
			oNode.setAttribute("id", o[i].value);
			oNode.setAttribute("order", d[i].value);
			oNode.setAttribute("price", p[i].value);
			oNode.setAttribute("money", count*parseFloat(p[i].value));
			m[i].value = oNode.getAttribute("money");
			m[i].previousSibling.innerText = "￥"+(count*parseFloat(p[i].value)).toFixed(2).toString();
			oRoot.appendChild(oNode);
			s_count += count;
			s_value += parseFloat(m[i].value);
		}
		$("btnReady2Check").disabled=true;
		if (s_value>0) $("btnReady2Check").disabled=false;
		oRoot.setAttribute("total", s_value.toFixed(2));
		$("sum_count").value = s_count;
		$("sum_money").value = s_value;
		$("sum_count_text").update(s_count);
		$("sum_money_text").update("￥"+s_value.toFixed(2));
		alllllprice=s_value
		rXml = oInnerXml;
		if (method == -1) return true;
		callAjax("ServerProcess.asp", "POST", oRoot.xml, function (x){
			if (x == null) return false;
			if (x.documentElement == null) return false;
			switch (x.documentElement.firstChild.getAttribute("status"))
			{
				case -1:
				case "-1":
					alert(x.documentElement.firstChild.getAttribute("reason"));
					return false;
				case 1:
				case "1":
					//document.location.reload();
					return true;
			}
		});
	}
	catch (e){}
}


/// 确认下单（第一次下单）
var defaultTransMoney=0;//推荐运费金额，也是减免的数字
var currentTransMoney=0;//当前用户选择的货运方式后得到的运费
var currentMoney=0;
function confirmOrder1st()
{
	/// 先提交下当前计算的总金额
	if (rXml == null)
	{
		alert("错误：更新总金额错误！您必须首先更新总金额！");
		return;
	}

	var err = [];
	var total = rXml.documentElement.getAttribute("total");
	if (total == ""||total == null)
	{
		err.push(1);
	}
	else
	{
		if (isNaN(total))
		{
			err.push(2);
		}
		else
		{
			if (parseFloat(total)<=0) err.push(3);
		}
	}
	if ($F("nm") == ""||$F("nm") == null) err.push(4);
	if ($F("add") == ""||$F("add") == null) err.push(5);
	if ($F("tel") == ""||$F("tel") == null) err.push(6);
	if (O_iMethod == 1)
	{
		if ($F("co") == ""||$F("co") == null)
		{
			err.push(7);
		}
		else
		{
			if (!checkEmail($F("co"))) err.push(8);
		}
	}
	if (err.length > 0)
	{
		var errDes = [""];
		errDes.push("未能获取订单总金额！　　　　　");
		errDes.push("订单总金额不是数值！　　　　　");
		errDes.push("订单总金额为零！　　　　　　　");
		errDes.push("请填写姓名！　　　　　　　　　");
		errDes.push("请填写地址！　　　　　　　　　");
		errDes.push("请填写电话！　　　　　　　　　");
		errDes.push("请填写Email！　　　　　　　　　");
		errDes.push("请填写合法的邮件地址！　　　　");

		var errDescription = "";
		for (var i=0; i<err.length; i++) errDescription += errDes[err[i]]+"\n";
		alert("错误：\n\n"+errDescription);
	}
	else
	{
		// 检测通过后提交数据到服务器上计算并返回正确总额和运费数据等待确认
		rXml.documentElement.setAttribute("cmd", "{BB750F3E-DBCC-4454-BB5F-C2B3C5DDBDCD}");
		//alert(rXml.xml);
		callAjax("ServerProcess.asp", "POST", rXml.documentElement.xml, function (x){
			if (x == null) return;
			if (x.documentElement == null) return;
			var m = x.documentElement.firstChild.getAttribute("money");
			if (m == ""||m == null)
			{
				alert("错误：未能获取产品总金额！");
				return;
			}
			switch (x.documentElement.firstChild.getAttribute("status"))
			{
				case -1:
				case "-1":
					alert(x.documentElement.firstChild.getAttribute("reason"));
					return;
					break;
				case 1:
				case "1":
					var count1 = x.documentElement.firstChild.getAttribute("count1");
					var count2 = x.documentElement.firstChild.getAttribute("count2");
					var money = x.documentElement.firstChild.getAttribute("money");
					count1 = parseInt(count1);
					count2 = parseInt(count2);
					money = parseFloat(money);
					currentMoney = money;
					var oPolicy = x.documentElement.firstChild.firstChild;
					if (oPolicy == null)
					{
						alert("错误：未能获取运费配置！");
						return;
					}
					var oTransports = oPolicy.lastChild;
					if (oTransports == null)
					{
						alert("错误：运费配置为空！");
						return;
					}
					$("ConfirmTransportInfo_method").update("");
					//计算减免运费
					//defaultTransMoney = calcTransport(oTransports.childNodes[0], count1, count2);
					//defaultTransMoney = parseFloat(defaultTransMoney);
					//defaultTransMoney = defaultTransMoney.toFixed(2);
					$("finalTransPriceCut").update("￥0.00");
					//登陆了才可能有减免
					//if (money > 1000) if (O_iMethod == 2) $("finalTransPriceCut").update("￥-"+defaultTransMoney);
//					for (var i=0; i<oTransports.childNodes.length; i++)
//					{
//						var oNode = oTransports.childNodes[i];
//						var oRow = document.createElement("tr");
//						var oCol1 = document.createElement("<td nowrap></td>");
//						var oCol2 = document.createElement("td");
//						var transPrice = calcTransport(oNode, count1, count2);
//						var AllPrice = parseFloat(transPrice)+parseFloat(money);
//						transPrice = transPrice.toFixed(2);
//						oCol2.innerHTML = "￥"+transPrice;
//						var oLabel = document.createElement("label");
//						oLabel.htmlFor = "transMethod"+i;
//						oLabel.onclick = clickTrans;
//						var oRadio = document.createElement("<input type='radio' id='transMethod"+i+"' name='transMethod'/>");
//						oRadio.value = oNode.getAttribute("number");
//						oRadio.setAttribute("m", transPrice);
//						var oSpan = document.createElement("span");
//						oSpan.innerHTML = "&nbsp;"+oNode.getAttribute("name");
//						oLabel.appendChild(oRadio);
//						oLabel.appendChild(oSpan);
//						oCol1.appendChild(oLabel);
//						oRow.appendChild(oCol1);
//						oRow.appendChild(oCol2);
//						oRow.title = "点击选择 "+oNode.getAttribute("name")+" 运输您订购的货品";
//						$("ConfirmTransportInfo_method").appendChild(oRow);
//						if (oNode.getAttribute("select") == 1)
//						{
//							oRadio.checked = true;
//							currentTransMoney = transPrice;
//							$("finalTransPrice").update("￥"+transPrice);
//							$("finalAllPrice").update("￥"+AllPrice.toFixed(2));
//							$("finalAllPrice_p").update("￥"+(parseFloat(money)+parseInt(personTransportFee)).toFixed(2));
//							if (money > 1000) if (O_iMethod == 2) $("finalAllPrice").update("￥"+(AllPrice-defaultTransMoney).toFixed(2));
//						}
//					}
					$("finalCount").update(parseInt(count1)+parseInt(count2));
					$("finalCount_p").update(parseInt(count1)+parseInt(count2));
					$("finalPrice").update("￥"+parseFloat(money).toFixed(2));
					$("finalPrice_p").update("￥"+parseFloat(money).toFixed(2));
					// 显示层提示
					if (O_iMethod == 2)
					{
						var iContextmenuWidth  = parseFloat($("ConfirmTransportInfo").offsetWidth);
						var iContextmenuHeight = parseFloat($("ConfirmTransportInfo").offsetHeight);
						var iBodyWidth		= parseFloat(document.body.clientWidth);
						var iBodyHeight		= parseFloat(document.body.clientHeight);
						$("ConfirmTransportInfo").style.left	= (iBodyWidth-iContextmenuWidth)/2;
						$("ConfirmTransportInfo").style.top		= (iBodyHeight-iContextmenuHeight)/2+document.body.scrollTop-80;
						$("ConfirmTransportInfo").style.visibility = "visible";
					}
					else
					{
						var iContextmenuWidth  = parseFloat($("ConfirmTransportInfo_p").offsetWidth);
						var iContextmenuHeight = parseFloat($("ConfirmTransportInfo_p").offsetHeight);
						var iBodyWidth		= parseFloat(document.body.clientWidth);
						var iBodyHeight		= parseFloat(document.body.clientHeight);
						$("ConfirmTransportInfo_p").style.left	= (iBodyWidth-iContextmenuWidth)/2;
						$("ConfirmTransportInfo_p").style.top		= (iBodyHeight-iContextmenuHeight)/2+document.body.scrollTop-80;
						$("ConfirmTransportInfo_p").style.visibility = "visible";
					}
					$("ConfirmTransportInfo_shadow").style.width	= document.body.scrollWidth;
					$("ConfirmTransportInfo_shadow").style.height	= document.body.scrollHeight;
					$("ConfirmTransportInfo_shadow").style.visibility = "visible";
					break;
			}
		});
	}
}

/// 传递运费参数节点，指定个数，返回运费价格
/// 错误返回 -1
/// count1 和 count2 不能同时为空
function calcTransport(node, count1, count2)
{
	if (node == null) return -1;
	if ((count1 == ""||count1 == null)&&(count2 == ""||count2 == null)) return -1;
	var finalWeight = 0;
	if (!(count1 == ""||count1 == null)&&(count2 == ""||count2 == null)) finalWeight = parseInt(count1)/10;//总重量
	if ((count1 == ""||count1 == null)&&!(count2 == ""||count2 == null)) finalWeight = parseInt(count2)/20;//总重量
	if (!(count1 == ""||count1 == null)&&!(count2 == ""||count2 == null)) finalWeight = parseInt(count1)/10+parseInt(count2)/20;//总重量
	var finalCount = parseInt(count1)+parseInt(count2);//总个数
	if (finalWeight > parseInt(finalWeight)) finalWeight = (finalWeight+0.5).toFixed(0);// 不足 1kg 的一律按 1kg 算

	var _baseWeight, _basePrice, _price;
	_baseWeight		= node.getAttribute("baseWeight");//基准重量
	_basePrice		= node.getAttribute("basePrice");//基准价格
	_price			= node.getAttribute("price");//超出基准重量后每单位价格
	//先计算基准金额
	var basePrice = parseInt(_basePrice);
	var overPrice = 0;
	if (parseInt(finalWeight) > parseInt(_baseWeight)) overPrice = (parseInt(finalWeight)-parseInt(_baseWeight))*parseInt(_price);
	return basePrice+overPrice;
}

/// 选择运费
function clickTrans()
{
	if (event.srcElement.tagName.toLowerCase() != "input") return;
	var o = event.srcElement;
	if (o.checked)
	{
		var v = parseFloat(o.getAttribute("m"));
		currentTransMoney = v;
		var m = $("finalPrice").innerText;
		m = parseFloat(m.replace("￥", ""));
		$("finalTransPrice").update("￥"+v.toFixed(2));
		$("finalAllPrice").update("￥"+(m+v).toFixed(2));
		if (currentMoney > 1000) if (O_iMethod == 2) $("finalAllPrice").update("￥"+(m+v-defaultTransMoney).toFixed(2));
	}
}

/// 确认下单（最终下单操作）
/// 要求至少有一个标签数量 > 0 才可以
/// 其他商品要求数量 > 0 才可以
var toAccount;
function confirmOrder(b, c)
{
	/// 先提交下当前计算的总金额
	///getProductInfo2Xml(1);
	try
	{
		b.disabled = true;
		c.disabled = true;
		b.style.backgroundColor = "silver";
		c.style.backgroundColor = "silver";
		$("confirmResult").cells[0].innerHTML = "正在提交数据，请稍候......";
		$("confirmResult_p").cells[0].innerHTML = "正在提交数据，请稍候......";
		$("confirmResult").style.display = "block";
		$("confirmResult_p").style.display = "block";
		if (rXml == null)
		{
			alert("错误：更新总金额错误！您必须首先更新总金额！");
			return;
		}
		if (O_iMethod == 1)
		{
			currentTransMoney = 15;//personTransportFee;
			defaultTransMoney = 0;
		}
		else
		{
			if (currentTransMoney == ""||currentTransMoney == null||defaultTransMoney == ""||defaultTransMoney == null)
			{
				alert("错误：无法获取当前运费金额！"+defaultTransMoney);
				return;
			}
		}
		currentTransMoney = parseFloat(currentTransMoney);
		defaultTransMoney = parseFloat(defaultTransMoney);
		var err = [];
		var total = rXml.documentElement.getAttribute("total");
		if (total == ""||total == null)
		{
			err.push(1);
		}
		else
		{
			if (isNaN(total))
			{
				err.push(2);
			}
			else
			{
				if (parseFloat(total)<=0) err.push(3);
			}
		}
		if ($F("nm") == ""||$F("nm") == null) err.push(4);
		if ($F("add") == ""||$F("add") == null) err.push(5);
		if ($F("tel") == ""||$F("tel") == null) err.push(6);
		if (O_iMethod == 1)
		{
			if ($F("co") == ""||$F("co") == null)
			{
				err.push(7);
			}
			else
			{
				if (!checkEmail($F("co"))) err.push(8);
			}
		}
		if (err.length > 0)
		{
			var errDes = [""];
			errDes.push("未能获取订单总金额！　　　　　");
			errDes.push("订单总金额不是数值！　　　　　");
			errDes.push("订单总金额为零！　　　　　　　");
			errDes.push("请填写姓名！　　　　　　　　　");
			errDes.push("请填写地址！　　　　　　　　　");
			errDes.push("请填写电话！　　　　　　　　　");
			errDes.push("请填写Email！　　　　　　　　　");
			errDes.push("请填写合法的邮件地址！　　　　");

			var errDescription = "";
			for (var i=0; i<err.length; i++) errDescription += errDes[err[i]]+"\n";
			alert("错误：\n\n"+errDescription);
		}
		else
		{
			if (O_iMethod == 2)
			{
				var c = document.getElementsByName("transMethod");//运费
				for(var i=0; i<c.length; i++) if (c[i].checked) rXml.documentElement.setAttribute("tr", c[i].value);
				rXml.documentElement.setAttribute("dft", $("transMethod0").value);
				if (rXml.documentElement.getAttribute("tr") == ""||rXml.documentElement.getAttribute("tr") == null)
				{
					alert("请选择货运方式！");
					return;
				}
			}
			rXml.documentElement.setAttribute("currentTransMoney", currentTransMoney);
			rXml.documentElement.setAttribute("defaultTransMoney", defaultTransMoney);
			rXml.documentElement.setAttribute("cmd", "{A946CA19-972A-42C8-A831-5FC9153BC343}");
			rXml.documentElement.setAttribute("co", $F("co"));
			rXml.documentElement.setAttribute("nm", $F("nm"));
			rXml.documentElement.setAttribute("add", $F("add"));
			rXml.documentElement.setAttribute("tel", $F("tel"));
			rXml.documentElement.setAttribute("mp", $F("mp"));
			rXml.documentElement.setAttribute("memo", $F("memo"));
			//alert(rXml.documentElement.xml);
			//return;
			callAjax("ServerProcess.asp", "POST", rXml.documentElement.xml, function (x){
				if (x == null) return;
				if (x.documentElement == null) return;
				switch (x.documentElement.firstChild.getAttribute("status"))
				{
					case -1:
					case "-1":
						$("confirmResult").cells[0].innerHTML = x.documentElement.firstChild.getAttribute("reason");
						$("confirmResult_p").cells[0].innerHTML = x.documentElement.firstChild.getAttribute("reason");
						break;
					case 1:
					case "1":
						$("confirmResult").cells[0].innerHTML = "下单成功！<br>您的订单编号为： "+x.documentElement.firstChild.getAttribute("n")+"<br>请记录本编号，稍后您可以在“我的账户”中按照该编号查询订单的处理状态。<br>本页面将在 10 秒后自动跳转到“<a href='account.asp'>我的账户</a>”页面。<span onclick='window.clearTimeout(toAccount)' title='点击停止自动跳转动作'>[停止自动跳转]</span>";
						$("confirmResult_p").cells[0].innerHTML = "下单成功！<br>您的订单编号为： "+x.documentElement.firstChild.getAttribute("n")+"<br>请记录本编号，稍后您可以在“我的账户”中按照该编号查询订单的处理状态。<br>本页面将在 10 秒后自动跳转到“<a href='account.asp'>我的账户</a>”页面。<span onclick='window.clearTimeout(toAccount)' title='点击停止自动跳转动作'>[停止自动跳转]</span>";
						toAccount = window.setTimeout("document.location.href='account.asp'", 10000);
						break;
				}
			});
		}
	}
	catch (e){}
}


/// 获取当前设置的货运方式数据(xml格式)
/// 直接从服务器端请求数据
var oTransparentXml;
function getTransportConfig()
{
	callAjax("ServerProcess.asp", "POST", "<root cmd='{BBAF9BA7-97FA-47B8-A2F7-46480D7D4688}'/>", function (x){
		if (x == null) return;
		if (x.documentElement == null) return;
		switch (x.documentElement.firstChild.getAttribute("status"))
		{
			case -1:
			case "-1":
				alert(x.documentElement.firstChild.getAttribute("reason"));
				return;
				break;
			case 1:
			case "1":
				var oTransparentXml = x.documentElement.selectSingleNode("result/policy/transportors");
				break;
		}
	});
	oTransparentXml = new ActiveXObject("Microsoft.XMLDOM");
	oTransparentXml.async = false;	//同步传输
	oTransparentXml.loadXML("<root/>");
}


/// 执行登陆动作
function doLogin()
{
	login();
	return;
	getProductInfo2Xml(1);
	if (rXml == null)
	{
		alert("错误：更新总金额错误！您必须首先更新总金额！");
		return;
	}
	else
	{
		login();
	}
}

/// 处理回车键
function ProcessKeyCode()
{
	var o = event.srcElement;
	if (o == null) return;
	switch (o.name.toLowerCase())
	{
		case "jname":
		case "jpwd":
			if (event.keyCode == 13) login();
			break;
		default:
			break;
	}
}

///检测邮件地址
function checkEmail(email)
{
	if (email == ""||email == null) return false;
	var oRex1 = /@/g;
	var oRex2 = /\./g;
	if (email.search(oRex1) == -1||email.search(oRex2) == -1) return false;
	if (email.search(oRex1) == 0||email.search(oRex2) == 0) return false;
	return true;
}


/// 申请撤消订单
function cancelOrder(id)
{
	if (id == ""||id == null) return;
	var sMsg = "只有处于未处理或订单无效状态下的订单可以被撤消，您确定要执行删除操作？　　　";
	if(!confirm(sMsg)) return;
	callAjax("ServerProcess.asp", "POST", "<root cmd='{C63BC3D5-7106-403D-A751-7C37A99D0EAA}' id='"+id+"'/>", function (x){
		if (x == null) return;
		if (x.documentElement == null) return;
		switch (x.documentElement.firstChild.getAttribute("status"))
		{
			case -1:
			case "-1":
				alert(x.documentElement.firstChild.getAttribute("reason"));
				return;
				break;
			case 1:
			case "1":
				alert("撤消成功！");
				document.location.reload("account.asp");
				break;
		}
	});
}


/// 将指定产品放入收藏夹
function addFav(id)
{
	if (id == ""||id == null) return;
	callAjax("ServerProcess.asp", "POST", "<root cmd='{87330E05-8CB4-43B8-A8A7-C271472ABB24}' id='"+id+"'/>", function (x){
		if(x == null) return;
		var oRoot = x.documentElement;
		if (oRoot == null) return;
		if (oRoot.firstChild.getAttribute("status") == "-1"||oRoot.firstChild.getAttribute("status") == -1)
		{
			alert(oRoot.firstChild.getAttribute("reason"));
		}
		else
		{
			$("add2FavText").update("已在收藏夹");
		}
	});
}


/// 将指定产品从收藏夹删除
function delFav(id)
{
	if (id == ""||id == null) return;
	// remote delete files
	var sMsg = "删除数据后将不能恢复，您确定要执行删除操作？　　　";
	if(!confirm(sMsg)) return;
	callAjax("ServerProcess.asp", "POST", "<root cmd='{9AD8F20C-5427-4633-9ECC-5496A4800B61}' id='"+id+"'/>", function (x){
		if (x == null) return;
		if (x.documentElement == null) return;
		if (x.documentElement.firstChild.getAttribute("status")==-1||x.documentElement.firstChild.getAttribute("status")=="-1") alert(x.documentElement.firstChild.getAttribute("reason"));
	});
	document.location.reload();
}


/// 清空收藏夹
function clearFav()
{
	// remote delete files
	var sMsg = "此操作将删除您在收藏夹中的全部商品，删除数据后将不能恢复，您确定要执行删除操作？　　　";
	if(!confirm(sMsg)) return;
	callAjax("ServerProcess.asp", "POST", "<root cmd='{9C5C6395-F6E6-4CED-A482-D0CBA65AE900}'/>", function (x){
		if (x == null) return;
		if (x.documentElement == null) return;
		if (x.documentElement.firstChild.getAttribute("status")==-1||x.documentElement.firstChild.getAttribute("status")=="-1") alert(x.documentElement.firstChild.getAttribute("reason"));
	});
	document.location.reload();
}


/// 购买单个收藏
function pro2Cart(id, sid)
{
	if (id == ""||id == null||sid == ""||sid == null) return;
	callAjax("ServerProcess.asp", "POST", "<root cmd='{D96391E8-285B-4A6E-A908-F823DFE7B703}' id='"+id+"' count='1'/>", function (o){
		if(o == null) return;
		var oRoot = o.documentElement;
		if (oRoot == null) return;
		if (oRoot.firstChild.getAttribute("status") == "-1"||oRoot.firstChild.getAttribute("status") == -1)
		{
			alert(oRoot.firstChild.getAttribute("reason"));
			return;
		}
		callAjax("ServerProcess.asp", "POST", "<root cmd='{9AD8F20C-5427-4633-9ECC-5496A4800B61}' id='"+sid+"'/>", function (x){
			if (x == null) return;
			if (x.documentElement == null) return;
			switch (x.documentElement.firstChild.getAttribute("status"))
			{
				case -1:
				case "-1":
					alert(x.documentElement.firstChild.getAttribute("reason"));
					break;
				case 1:
				case "1":
					document.location.reload();
					break;
			}
		});
	});
}


/// 收藏夹全部移动到购物车
function fav2Cart()
{
	var p = document.getElementsByName("proId");
	if (p.length == 0) return;
	for (var i=0; i<p.length; i++)
	{
		callAjax("ServerProcess.asp", "POST", "<root cmd='{D96391E8-285B-4A6E-A908-F823DFE7B703}' id='"+p[i].value+"' count='1'/>", function (o){
			if(o == null) return;
			var oRoot = o.documentElement;
			if (oRoot == null) return;
			if (oRoot.firstChild.getAttribute("status") == "-1"||oRoot.firstChild.getAttribute("status") == -1)
			{
				alert(oRoot.firstChild.getAttribute("reason"));
				return;
			}
		});
	}
	callAjax("ServerProcess.asp", "POST", "<root cmd='{9C5C6395-F6E6-4CED-A482-D0CBA65AE900}'/>", function (x){
		if (x == null) return;
		if (x.documentElement == null) return;
		if (x.documentElement.firstChild.getAttribute("status")==-1||x.documentElement.firstChild.getAttribute("status")=="-1") alert(x.documentElement.firstChild.getAttribute("reason"));
	});
	document.location.href="cart.asp";
}

