//##### ======================================= #####
//#####             UKbattery.net            #####
//#####           EMPOLDER: 2006-11-22          #####
//##### ======================================= #####

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;
}

function show_buy(T_code,imagepath){
	var proportion = 1.00; //	
	var ori2;
	var ori3;
	var ori4;
	var ori5;
	var ori6;
	var ori7;
	var ori;
	var org;
	var save;
	var sale_price;	    //
	var ori2_price  = Math.round(price[T_code][0] * proportion * 100)/100 + 19;
	var ori3_price  = Math.round(price[T_code][0] * proportion * 100)/100 + 39;
	var ori4_price  = Math.round(price[T_code][0] * proportion * 100)/100 + 59;
	var ori5_price  = Math.round(price[T_code][0] * proportion * 100)/100 + 24;
	var ori6_price  = Math.round(price[T_code][0] * proportion * 100)/100 + 44;
	var ori7_price  = Math.round(price[T_code][0] * proportion * 100)/100 + 64;
	var ori_price  = Math.round(price[T_code][0] * proportion * 100)/100 + 34;
	var org_price  = Math.round(price[T_code][0] * proportion * 100)/100 + 54;
	var sale_price  = Math.round(price[T_code][0] * proportion * 100)/100 ;
	
	var ori2_price  = round_decimals( ori2_price ,2);
	var ori3_price  = round_decimals( ori3_price ,2);
	var ori4_price  = round_decimals( ori4_price ,2);
	var ori5_price  = round_decimals( ori5_price ,2);
	var ori6_price  = round_decimals( ori6_price ,2);
	var ori7_price  = round_decimals( ori7_price ,2);
	
	var ori_price  = round_decimals( ori_price ,2);
	var org_price  = round_decimals( org_price ,2);
	var sale_price  = round_decimals( sale_price ,2);
	var save_price  = round_decimals( save_price ,2);
	if (price[T_code] != "0" && price[T_code][1] == "1"){

document.write("<p>"+"<b>"+"sale : "+"</b>"+"<span class=\"savePrice\">&pound; " + sale_price + "</span>" +"</P>");

		document.write("<input type=\"hidden\" name=\"item_number\" value=\"" + T_code + "\">");
		document.write("<select name=\"amount\">");
		document.write("<option value=\"" + sale_price + "\">No Lenses, Frames Only</option>");
		document.write("<option value=\"" + ori2_price + "\">Plastic Thin Lens(1.56) + &pound; 19</option>");
		document.write("<option value=\"" + ori3_price + "\">Plastic Thin Lens(1.61) + &pound; 39</option>");
		document.write("<option value=\"" + ori4_price + "\">Plastic Super Thin Lens(1.67) + &pound; 59</option>");
		document.write("<option value=\"" + ori5_price + "\">Glasse Thin Lens(1.5) + &pound; 24</option>");
		document.write("<option value=\"" + ori6_price + "\">Glass Thin Lens(1.7) + &pound; 44</option>");
		document.write("<option value=\"" + ori7_price + "\">Glass Super Thin Lens(1.8) + &pound; 64</option>");
		document.write("</select>");
		
		document.write("<input type=\"hidden\" name=\"business\" value=\"payment@ukglasses.net\">");

		document.write("<input name=\"Submit\" type=\"image\" value=\"Submit\" src=\"http://www.ukglasses.net/images/add_to_cart.gif\" hspace=\"5\">");
		document.write("<input type=\"hidden\" name=\"no_shipping\" value=\"0\">");
		document.write("<input type=\"hidden\" name=\"page_style\" value=\"PayPal\">");
		document.write("<input type=\"hidden\" name=\"currency_code\" value=\"GBP\">");
		document.write("<input type=\"hidden\" name=\"lc\" value=\"GB\">");
		document.write("<input type=\"hidden\" name=\"bn\" value=\"PP-ShopCartBF\">");
		document.write("<input type=\"hidden\" name=\"add\" value=\"1\">");
		document.write("<input type=\"hidden\" name=\"cmd\" value=\"_cart\">");
	}
	else{
		document.write("<span class=\"light\">Out of stock</span>");
	}
}

function show_buy1(T_code,imagepath){
	var sale_price = 1.0	    //
	var sale_price  = Math.round(price[T_code][0] * sale_price * 100)/100;
	var sale_price  = round_decimals( sale_price ,2);
	if (price[T_code] != "0" && price[T_code][1] == "1"){
	document.write("<span class=\"priceText\">&pound; " + sale_price + "</span>");
	}
	else{
		document.write("<span class=\"light\">Out of stock</span>");
	}
}

function show_buy2(T_code,T_code2,imagepath){
	var proportion = 1.00; //
	var uk = 7.9;
	var eur = 11.9;
	var sav = 2.0;
	var ori_price;	    //
	var ori_price  = Math.round(price[T_code][0] * proportion * 100)/100;
	var ori_price2 = Math.round(price[T_code2][0] * proportion * 100)/100;
	var ori_price = eval(ori_price) + eval(ori_price2);
	var sale_price = ori_price - sav;
	var ori_price  = round_decimals( ori_price ,2);
	var sale_price  = round_decimals( sale_price ,2);
	if ((price[T_code] != "0" && price[T_code][1] == "1") && (price[T_code2] != "0" && price[T_code2][1] == "1")) {
		document.write("<input type=\"hidden\" name=\"item_number\" value=\"" + T_code + "+" + T_code2 + "\">");
		document.write("<input type=\"hidden\" name=\"amount\" value=\"" + sale_price + "\">");
		document.write("<input type=\"hidden\" name=\"business\" value=\"payment@ukbattery.net\">");
		document.write("<select name=\"shipping\">");
		document.write("<option value=\"" + uk + "\">Ship to England</option>");
		document.write("<option value=\"" + eur + "\">Other European countries</option>");
		document.write("</select>");
		document.write("<br>");
		document.write("<input name=\"Submit\" type=\"image\" value=\"Submit\" src=\"http://www.ukglasses.net/images/add_to_cart.gif\"  vspace=\"5\">");
		document.write("<input type=\"hidden\" name=\"page_style\" value=\"PayPal\">");
		document.write("<input type=\"hidden\" name=\"currency_code\" value=\"GBP\">");
		document.write("<input type=\"hidden\" name=\"lc\" value=\"GB\">");
		document.write("<input type=\"hidden\" name=\"bn\" value=\"PP-ShopCartBF\">");
		document.write("<input type=\"hidden\" name=\"add\" value=\"1\">");
		document.write("<input type=\"hidden\" name=\"cmd\" value=\"_cart\">");
	}
	else{
		document.write("<span class=\"light\">Out of stock</span>");
	}
}
