
		//计算手续费
		function getHandling(product) {
			if (product.handlingInfo == null) {
				var handling = 0;
				var rmbHandling = 0;
				var orgHandling = null;
				var orgRmbHandling = null;
				var handlingInfo = {
						"price" : product.price,
						"pid" : product.pid,
						"sortid" : product.sort.id,
						"handling_rate" : handling_rate
					};
				var asyncFlag = dwr.engine._async;
				if(asyncFlag){
					dwr.engine.setAsync(false);
				}
				Buy.calculateHandling(handlingInfo, function(data) {
					handling = Math.ceil(Number(data.handling).toFixed(6));
					rmbHandling = Math.ceil(Number(data.rmbHandling).toFixed(6));
					if (data.orgHandlingValue != "") {
						orgHandling = Math.ceil(Number(data.orgHandlingValue).toFixed(6));
					}
					if (data.orgRmbHandlingValue != "") {
						orgRmbHandling = Math.ceil(Number(data.orgRmbHandlingValue).toFixed(6));
					}
				});
				if(asyncFlag) {
					dwr.engine.setAsync(true);
				}
				product.handlingInfo = {
						"handling" : handling,
						"rmbHandling" : rmbHandling,
						"orgHandling" : orgHandling,
						"orgRmbHandling" : orgRmbHandling
					};
			}
			return product.handlingInfo;
		}
		
		//计算多个商品的手续费
		function calculateHandlingFromList(productsList) {
			var handlingList = new Array();
			var rmbHandlingList = new Array();
			var orgHandlingList = new Array();
			var orgRmbHandlingList = new Array();
			var handlingInfoList = new Array();
			var resultList = new Array();
			for ( var i = 0; i < productsList.length; i++) {
				var product = productsList[i];
				handlingList[i] = 0;
				rmbHandlingList[i] = 0;
				var handlingInfo = {
						"price" : product.price,
						"pid" : product.pid,
						"sortid" : product.sort.id,
						"handling_rate" : handling_rate
					};
				handlingInfoList[i] = handlingInfo;
			}
			var asyncFlag = dwr.engine._async;
			if(asyncFlag){
				dwr.engine.setAsync(false);
			}
			Buy.calculateHandlingFromList(handlingInfoList, function(data) {
				for ( var i = 0; i < data.length; i++) {
					handlingList[i] = Math.ceil(Number(data[i].handling).toFixed(6));
					rmbHandlingList[i] = Math.ceil(Number(data[i].rmbHandling).toFixed(6));
					if (data[i].orgHandlingValue != "") {
						orgHandlingList[i] = Math.ceil(Number(data[i].orgHandlingValue).toFixed(6));
					}
					if (data[i].orgRmbHandlingValue != "") {
						orgRmbHandlingList[i] = Math.ceil(Number(data[i].orgRmbHandlingValue).toFixed(6));
					}
					resultList[i] = {
							"handling" : handlingList[i],
							"rmbHandling" : rmbHandlingList[i],
							"orgHandling" : orgHandlingList[i],
							"orgRmbHandling" : orgRmbHandlingList[i]
						};
				}
			});
			if(asyncFlag) {
				dwr.engine.setAsync(true);
			}
			
			return resultList;
		}

		//获取预设的商品重量以及每50克运费
		function getPresetWeight(product) {
			if (product.presetWeight == null) {
				var weightResult = null;
				var weightInfo = {
						"price" : product.price,
						"pid" : product.pid,
						"sortid" : product.sort.id,
						"discnum" : product.discnum
				};
				//若为二手商品，则使用其参考价格
				if (product.refPrice != undefined && !isNaN(parseInt(product.refPrice))) {
					weightInfo.price = product.refPrice;
				}

				var asyncFlag = dwr.engine._async;
				if(asyncFlag){
					dwr.engine.setAsync(false);
				}
				Buy.getPresetWeight(weightInfo, function(data) {
					weightResult = data;
					if (weightResult.weight_price == "") {
						weightResult.weight_price = weight_price_default;
					}
				});
				if(asyncFlag) {
					dwr.engine.setAsync(true);
				}
				product.presetWeight = weightResult;
			}
			return product.presetWeight;
		}
		
		//获取多个商品的预设重量以及每50克运费
		function getPresetWeightFromList(productsList) {
			var weightResultList = new Array();
			var weightInfoList = new Array();
			for ( var i = 0; i < productsList.length; i++) {
				var product = productsList[i];
				var weightInfo = {
						"price" : product.price,
						"pid" : product.pid,
						"sortid" : product.sort.id,
						"discnum" : product.discnum
				};
				//若为二手商品，则使用其参考价格
				if (product.refPrice != undefined && !isNaN(parseInt(product.refPrice))) {
					weightInfo.price = product.refPrice;
				}
				weightInfoList[i] = weightInfo;
			}
			
			var asyncFlag = dwr.engine._async;
			if(asyncFlag){
				dwr.engine.setAsync(false);
			}
			Buy.getPresetWeightFromList(weightInfoList, function(data) {
				weightResultList = data;
				for ( var i = 0; i < weightResultList.length; i++) {
					if (weightResultList[i].weight_price == "") {
						weightResultList[i].weight_price = weight_price_default;
					}
				}
			});
			if(asyncFlag) {
				dwr.engine.setAsync(true);
			}
			
			return weightResultList;
		}
		
		//计算一种商品的价格、快递、手续费、小计
		function getPrice(product) {
			var handling = 0;
			var rmbHandling = 0;
			var orgHandling = null;
			var orgRmbHandling = null;
			var totalPrice = 0;
			var productPrice = 0;
			var shipcharge = 0;
			var weight = "";
			var weightPrice = 0;
			var orgWeight = "";
			var discountWeight = -1;
			var rmbIntfreight = 0;
			var discountRmbIntfreight = -1;
			
			shipcharge = product.shipcharge;
			productPrice = product.price;
			var handlingResult = getHandling(product);
			handling = handlingResult.handling;
			rmbHandling = handlingResult.rmbHandling;
			orgHandling = handlingResult.orgHandling;
			orgRmbHandling = handlingResult.orgRmbHandling;
			var weightResult = getPresetWeight(product);
			weight = weightResult.weight;
			weightPrice = Number(weightResult.weight_price).toFixed(2);
			discountWeight = Number(weightResult.discountWeight);
			if (weight != "") {
				rmbIntfreight = Math.ceil((Math.ceil((Number(weight) / 50)) * weightPrice).toFixed(6));
			}
			if (discountWeight >= 0) {
				discountRmbIntfreight = Math.ceil((Math.ceil((discountWeight / 50)) * weightPrice).toFixed(6));
			}
			totalPrice = productPrice * product.number + shipcharge + handling * product.number;
			
			var price = {
				"weight" : weight,
				"discountWeight" : discountWeight,
				"weightPrice" : weightPrice,
				"rmbIntfreight" : rmbIntfreight,
				"discountRmbIntfreight" : discountRmbIntfreight,
				"jpyShipping" : shipcharge,
				"rmbShipping" : Math.ceil((shipcharge * exchange_rate).toFixed(6)),
				"jpyTotalPrice" : totalPrice,
				"rmbTotalPrice" : 0,
				"jpyProductPrice" : productPrice,
				"rmbProductPrice" : Math.ceil((productPrice * exchange_rate).toFixed(6)),
				"jpyHandlingCharge" : handling,
				"rmbHandlingCharge" : rmbHandling,
				"orgHandling" : orgHandling,
				"orgRmbHandling" : orgRmbHandling
			};
			price.rmbTotalPrice = price.rmbProductPrice * product.number + price.rmbShipping + price.rmbHandlingCharge * product.number;
			
			return price;
		}
		
		//计算多个商品的价格、快递、手续费、小计
		function getPriceFromList(productsList) {
			var handlingResultList = calculateHandlingFromList(productsList);
			var weightResultList = getPresetWeightFromList(productsList);
			var priceList = new Array();
			for ( var i = 0; i < productsList.length; i++) {
				var product = productsList[i];
				var handling = 0;
				var rmbHandling = 0;
				var orgHandling = null;
				var orgRmbHandling = null;
				var totalPrice = 0;
				var productPrice = 0;
				var shipcharge = 0;
				var weight = "";
				var weightPrice = 0;
				var orgWeight = "";
				var discountWeight = -1;
				var rmbIntfreight = 0;
				var discountRmbIntfreight = -1;
				
				shipcharge = product.shipcharge;
				productPrice = product.price;
				var handlingResult = handlingResultList[i];
				handling = handlingResult.handling;
				rmbHandling = handlingResult.rmbHandling;
				orgHandling = handlingResult.orgHandling;
				orgRmbHandling = handlingResult.orgRmbHandling;
				var weightResult = weightResultList[i];
				weight = weightResult.weight;
				weightPrice = Number(weightResult.weight_price).toFixed(2);
				discountWeight = Number(weightResult.discountWeight);
				if (weight != "") {
					rmbIntfreight = Math.ceil((Math.ceil((Number(weight) / 50)) * weightPrice).toFixed(6));
				}
				if (discountWeight >= 0) {
					discountRmbIntfreight = Math.ceil((Math.ceil((discountWeight / 50)) * weightPrice).toFixed(6));
				}
				totalPrice = productPrice * product.number + shipcharge + handling * product.number;
				
				var price = {
					"weight" : weight,
					"discountWeight" : discountWeight,
					"weightPrice" : weightPrice,
					"rmbIntfreight" : rmbIntfreight,
					"discountRmbIntfreight" : discountRmbIntfreight,
					"jpyShipping" : shipcharge,
					"rmbShipping" : Math.ceil((shipcharge * exchange_rate).toFixed(6)),
					"jpyTotalPrice" : totalPrice,
					"rmbTotalPrice" : 0,
					"jpyProductPrice" : productPrice,
					"rmbProductPrice" : Math.ceil((productPrice * exchange_rate).toFixed(6)),
					"jpyHandlingCharge" : handling,
					"rmbHandlingCharge" : rmbHandling,
					"orgHandling" : orgHandling,
					"orgRmbHandling" : orgRmbHandling
				};
				price.rmbTotalPrice = price.rmbProductPrice * product.number + price.rmbShipping + price.rmbHandlingCharge * product.number;
				priceList[i] = price;
			}
			return priceList;
		}
		
		//计算所有商品的价格、快递、手续费、支付总额
		function getTotalPrice() {
			var jpyShipping = 0;
			var rmbShipping = 0;
			var jpyTotalPrice = 0;
			var rmbTotalPrice = 0;
			var jpyProductPrice = 0;
			var rmbProductPrice = 0;
			var jpyHandlingCharge = 0;
			var rmbHandlingCharge = 0;
			var rmbIntfreight = 0;
			var rmbIntfreightMerged = 0;
			var priceinfoMerged = new Array();
			for (var i=0; i < productList.length ; i++) {
				var priceinfo = getPrice(productList[i]);
				jpyShipping = jpyShipping + priceinfo.jpyShipping;
				rmbShipping = rmbShipping + priceinfo.rmbShipping;
				jpyTotalPrice = jpyTotalPrice + priceinfo.jpyTotalPrice;
				rmbTotalPrice = rmbTotalPrice + priceinfo.rmbTotalPrice;
				jpyProductPrice = jpyProductPrice + priceinfo.jpyProductPrice * productList[i].number;
				rmbProductPrice = rmbProductPrice + priceinfo.rmbProductPrice * productList[i].number;
				jpyHandlingCharge = jpyHandlingCharge + priceinfo.jpyHandlingCharge * productList[i].number;
				rmbHandlingCharge = rmbHandlingCharge + priceinfo.rmbHandlingCharge * productList[i].number;
				rmbIntfreight = rmbIntfreight + (priceinfo.discountRmbIntfreight < 0 ? priceinfo.rmbIntfreight : priceinfo.discountRmbIntfreight) * productList[i].number;
				if (priceinfo.weight != "") {
					var matchFlag = false;
					var productWeight = priceinfo.discountWeight < 0 ? Number(priceinfo.weight) : priceinfo.discountWeight;
					for (var j=0; j < priceinfoMerged.length; j++) {
						if(priceinfoMerged[j].weightPrice == priceinfo.weightPrice){
							priceinfoMerged[j].weight = priceinfoMerged[j].weight + productWeight * productList[i].number;
							matchFlag = true;
							break;
						}
					}
					if(!matchFlag){
						var priceinfoItem = {
								"weight" : productWeight * productList[i].number,
								"weightPrice" : priceinfo.weightPrice
						};
						priceinfoMerged.push(priceinfoItem);
					}
				}
			}
			for ( var i = 0; i < priceinfoMerged.length; i++) {
				rmbIntfreightMerged = rmbIntfreightMerged + Math.ceil((Math.ceil((priceinfoMerged[i].weight / 50)) * priceinfoMerged[i].weightPrice).toFixed(6));
			}
			var price = {
				"jpyShipping" : jpyShipping,
				"rmbShipping" : rmbShipping,
				"jpyTotalPrice" : jpyTotalPrice,
				"rmbTotalPrice" : rmbTotalPrice,
				"jpyProductPrice" : jpyProductPrice,
				"rmbProductPrice" : rmbProductPrice,
				"jpyHandlingCharge" : jpyHandlingCharge,
				"rmbHandlingCharge" : rmbHandlingCharge,
				"rmbIntfreight" : rmbIntfreight,
				"rmbIntfreightMerged" : rmbIntfreightMerged
			};
			return price;
		}
		
		//拼装form内容
		function createMallInput(list) {
			var input = "";
			for (var i=0; i < list.length ; i++) {
				var handlingResult = getHandling(list[i]);
				var weightResult = getPresetWeight(list[i]);
				if (weightResult.weight == "") {
					weightResult.weight = 0;
				}
				input = input + "<input type='hidden' name='name' value=\"" + list[i].name.replace(/\"/g, "''") + "\">";
				input = input + "<input type='hidden' name='price' value=\"" + list[i].price + "\">";
				input = input + "<input type='hidden' name='shipcharge' value=\"" + list[i].shipcharge + "\">";
				input = input + "<input type='hidden' name='number' value=\"" + list[i].number + "\">";
				input = input + "<input type='hidden' name='seller' value=\"" + list[i].seller.replace(/\"/g, "''") + "\">";
				input = input + "<input type='hidden' name='remark' value=\"" + list[i].remark.replace(/\"/g, "''") + "\">";
				input = input + "<input type='hidden' name='type' value=\"" + list[i].type.value + "\">";
				input = input + "<input type='hidden' name='condition' value=\"" + list[i].condition.replace(/\"/g, "''") + "\">";
				input = input + "<input type='hidden' name='link' value=\"" + list[i].link + "\">";
				input = input + "<input type='hidden' name='isbn' value=\"" + list[i].isbn + "\">";
				input = input + "<input type='hidden' name='pid' value=\"" + list[i].pid + "\">";
				input = input + "<input type='hidden' name='sortid' value=\"" + list[i].sort.id + "\">";
				input = input + "<input type='hidden' name='discount' value=\"" + list[i].discount.value + "\">";
				input = input + "<input type='hidden' name='discnum' value=\"" + list[i].discnum + "\">";
				input = input + "<input type='hidden' name='contentRating' value=\"" + list[i].contentRating + "\">";
				input = input + "<input type='hidden' name='merchantID' value=\"" + (list[i].merchantID == null ? "" : list[i].merchantID) + "\">";
				input = input + "<input type='hidden' name='quantityLimit' value=\"" + list[i].quantityLimit + "\">";
				input = input + "<input type='hidden' name='handling' value=\"" + handlingResult.handling + "\">";
				input = input + "<input type='hidden' name='rmbHandling' value=\"" + handlingResult.rmbHandling + "\">";
				input = input + "<input type='hidden' name='weight' value=\"" + weightResult.weight + "\">";
				input = input + "<input type='hidden' name='discountWeight' value=\"" + weightResult.discountWeight + "\">";
				input = input + "<input type='hidden' name='weightprice' value=\"" + weightResult.weight_price + "\">";
			}
			return input;
		}