// 函数round_decimals()功能: 将价格数字保留N位小数,不够的补"0";

// begin ++++++++++++++++++++++++++++++++++

function round_decimals(original_number,decimals){

 var result1 = original_number * Math.pow(10,decimals);

 var result2 = Math.round(result1);

 var result3 = result2 / Math.pow(10,decimals);

 return pad_with_zeros(result3,decimals);

}

function pad_with_zeros(rounded_value,decimal_places){

 var value_string = rounded_value.toString();

 var decimal_location = value_string.indexOf(".");

 if (decimal_location == -1){

  decimal_part_length = 0;

  value_string += decimal_places > 0 ? "." :"";

 }else{

  decimal_part_length = value_string.length - decimal_location - 1;

 }

 var pad_total = decimal_places - decimal_part_length;

 if(pad_total > 0){

  for (var counter = 1;counter <= pad_total;counter++){

   value_string += "0";

  }

 }

 return value_string;

}

//end  +++++++++++++++++++++++



//判断是否出现"buy now"按钮

// begin ++++++++++++++++++++++

function show_buynow(p_psecode,imagepath){

	var proportion = 1.00; //价格的比率，相对于标准价

	var now_price;	    //此为提交购物车后的显示价格

	var now_price  = Math.round(price[p_psecode][0] * proportion * 100)/100;

	var now_price  = round_decimals( now_price ,2);

	if (price[p_psecode][0] > "0"){


		
		          document.write("<input type=\"image\" src=\"https://www.paypal.com/en_GB/i/btn/btn_cart_LG.gif\" border=\"0\" name=\"submit\" alt=\"PayPal - The safer, easier way to pay online.\">");
		          document.write("<img alt=\"\" border=\"0\" src=\"https://www.paypal.com/zh_XC/i/scr/pixel.gif\" width=\"1\" height=\"1\">");
				  document.write("<input type=\"hidden\" name=\"add\" value=\"1\" />");
				  document.write("<input type=\"hidden\" name=\"cmd\" value=\"_cart\" />");
				  document.write("<input type=\"hidden\" name=\"business\" value=\"shopbattery@hotmail.com\" />");
				  document.write("<input type=\"hidden\" name=\"item_number\" value=\"" + p_psecode + "\" />");
				  document.write("<input type=\"hidden\" name=\"amount\" value=\"" + now_price + "\" />");
				  document.write("<input type=\"hidden\" name=\"shipping\" value=\"9.99\" />");
				  document.write("<input type=\"hidden\" name=\"no_shipping\" value=\"0\" />");
				  document.write(" <input type=\"hidden\" name=\"no_note\" value=\"1\" />");
				  document.write("<input type=\"hidden\" name=\"currency_code\" value=\"AUD\" />");
				  document.write("<input type=\"hidden\" name=\"lc\" value=\"US\" />");
				  document.write("<input type=\"hidden\" name=\"bn\" value=\"PP-ShopCartBF\" />");
				  document.write("<input type=\"hidden\" name=\"cancel_return\" value=\"http://www.aubattery.com.au\">");  
				  document.write("<input type=\"hidden\" name=\"return\" value=\"http://www.aubattery.com.au/aucart/paypal_ok.php\"> ");
				  document.write("<input type=\"hidden\" name=\"rm\" value=\"2\">");  
				  document.write("<input type=\"hidden\" name=\"cbt\" value=\"view your order details\">");  
				  document.write("<input type=\"hidden\" name=\"notify_url\" value=\"http://www.order-battery.com/aucart/dealorder.php?webname=aubattery.com.au\">");

	}

	else{

		document.write("<br><b>Coming Soon!</b>");

		//document.write("<span class=\"style3\">Coming Soon</span>");

	}

}

// end ++++++++++++++++++++++++++
function show_per_price(psecode){
	
	var psecode_price  = eval (price[psecode][0]);
	
	document.write("<font color='red' style='font-size:12px; font-family:Arial;font-weight:bold;'>A$" + psecode_price + "</font>");
	
	}


// 根据type参数选择显示的价格类型

function show_price(p_psecode,type){//显示价格，如果要搞促销，可以做这样的修改，也就是修改一下promotion这个常量的值为1以及修改一下proportion的比例即可。

	var promotion = 1;   //促销时为"1"，日常销售为"0"

	var proportion = 1.00;  //价格的比率，相对于标准价

	var rise = 1.5;     //用于显示促销前后价格的变化，是嘘头.

	var rise_price = price[p_psecode][0] * rise ;

	var now_price  = price[p_psecode][0] * proportion;

//mobile phone *2 end
	if(price[p_psecode][2] =="M"){
		rise_price = now_price * 2 ;
	}
//mobile phone *2 end
	
	var save_price = rise_price - now_price;

	var rise_price = round_decimals( rise_price ,2);

	var now_price  = round_decimals( now_price  ,2);

	var save_price = round_decimals( save_price ,2);

	
	if(now_price ==0){
		
		document.write("No price!");
	
	}else{	
	
		if (promotion != 0){

			if (type != 0){

				document.write("<br><font color='#000000' style='font-size:12px; font-family:Arial'>Org. Price: A$" + rise_price + "</font><br>");
	
				document.write("<span style='font-size:12px; font-family:Arial'><font color='#000000'>Special Price:</font> <font color='red' style='font-weight:bold;font-size:14px;'>A$"  + now_price + "(inc. GST)</font></span><br>");
	
				document.write("<font color='#000000' style='font-size:12px; font-family:Arial'>You Save: A$" + save_price + "</font>");
				
			}else{
	
				document.write("Special price: <span style='font-weight:bold;font-size:14px;'>A$" + now_price + "</span>");
	
			}

		}else{

		//document.write("<span class=\"style3\">US A$" + now_price + "</span>");

		document.write("<b>Special price:</b> <span style='font-weight:bold;font-size:14px;'>A$" + now_price + "</span><br>");

		}
	}

}


////////////////////////////////
function show_both_price(psecode1,psecode2){
	var psecode1_price  = eval (price[psecode1][0]);
	var psecode2_price  = eval (price[psecode2][0]);
	var total_price_old = round_decimals((psecode1_price + psecode2_price)*1,2);	
	var total_price = round_decimals((psecode1_price + psecode2_price)-1,2);
	document.write("Sale Price:<font color='red' style='font-size:14px; font-family:Arial;font-weight:bold;'>A$" + total_price + " (inc. GST)</font><br>");
	document.write("Org. Price:<font style='font-size:12px; font-family:Arial' color='#000000' class='midline'>[ A$" + total_price_old + " ]</font>");	

}

function show_both_buynow(psecode1,psecode2){
	var psecode1_price  = eval (price[psecode1][0]);
	var psecode2_price  = eval (price[psecode2][0]);
	var total_price = round_decimals((psecode1_price + psecode2_price)-1,2);
	var total_psecode = psecode1 + "+" + psecode2;
	
	if((price[psecode1][1]==1) && (price[psecode2][1]==1)){
		
		document.write("<input name=\"Submit\" type=\"image\" value=\"Submit\" src=\"http://www.aubattery.com.au/images/add_to_cart.gif\">");

		document.write("<input type=\"hidden\" name=\"psecode\" value=\"" + total_psecode + "\">");

		document.write("<input type=\"hidden\" name=\"pseprice\" value=\"" + total_price + "\">");

		document.write("<input type=\"hidden\" name=\"sitename\" value=\"aubattery.com.au\">");
		
	}else{

		document.write("<br><b>Coming Soon!</b>");

	}

}

// end ++++++++++++++++++++++++++++++++++++


