//##### ======================================= #####
//#####          DEVELOPER: W.Q.F Peter         #####
//#####           EMPOLDER: 2004-10-25          #####
//##### ======================================= #####
//

// 
// 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  +++++++++++++++++++++++

//
// 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" && price[p_psecode][1] == "1"){
		document.write("<span class=\"price\"><font color=red><strong>"+ "US $" + now_price + " &nbsp;&nbsp;</strong></font></span>");
		document.write("<input name=\"Submit\" type=\"image\" value=\"Submit\" src=\"/images/buy.gif\">");
		document.write("<br><font color=blue><a href='http://www.laptop-battery.org/'>Happy new year, Save up to 35%, huge discounts! The same day shipping, 30 days money back.</a></font>");
		document.write("<input type=\"hidden\" name=\"psecode\" value=\"" + p_psecode + "\">");
		document.write("<input type=\"hidden\" name=\"pseprice\" value=\"" + now_price + "\">");
		document.write("<input type=\"hidden\" name=\"sitename\" value=\"www.laptop-battery.org\">");
		}
	else{
		document.write("<span class=\"price\">"+"Sorry, out of stock now!" + "</span>");
		//document.write("<span class=\"style3\">Out of stock</span>");
	}
}
// end ++++++++++++++++++++++++++

// 
// begin +++++++++++++++++++++++++++++++++++++

function show_price(p_psecode,type){//
	var promotion = 1;   //
	var proportion = 1.00;  //
	var rise = 1.10;     //
	var rise_price = price[p_psecode][0] * proportion * rise;
	var now_price  = price[p_psecode][0] * proportion;
	var save_price = rise_price - now_price;
	rise_price = round_decimals( rise_price ,2);
	now_price  = round_decimals( now_price  ,2);
	save_price = round_decimals( save_price ,2);

	if (promotion != 0){
		if (type != 0){
			//document.write("Reg .price: <strike>US $" + rise_price + "</strike><br>");
			document.write("US $" + now_price + "");
			//document.write("You save: <span class=\"style3\">$" + save_price + "</span><br>");
		}else{
			document.write("US $" + now_price + "");
		}
	}
	else{
		//
		document.write("US $" + now_price + "");
	}
}

// end ++++++++++++++++++++++++++++++++++++
// add by stone.wang ++++++++++++++++++++++++
 // BATTERY AND CHARGER
// +++++++++++++++++++++++++++++++++++++++++++
function show_price2(p_psecode,p_psecode2,type){//
	var promotion = 1;   //
	var proportion = 1.00;  //
	var rise = 1.10;     //
	var rise_price = price[p_psecode][0] * proportion * rise;
	var now_price  = (eval(price[p_psecode][0])+eval(price[p_psecode2][0])) * proportion;
	var save_price = rise_price - now_price;
	rise_price = round_decimals( rise_price ,2);
	now_price  = round_decimals( now_price  ,2);
	save_price = round_decimals( save_price ,2);
	
	if (promotion != 0){
		if (type != 0){
			//document.write("Reg .price: <strike>US $" + rise_price + "</strike><br>");
			document.write("US $" + now_price + "");
			//document.write("You save: <span class=\"style3\">$" + save_price + "</span><br>");
		}else{
			document.write("US $" + now_price + "");
		}
	}
	else{
		//
		document.write("US $" + now_price + "");
	}
}
///-net add to sum----------------------add "battery + charger" or "battery + adapter"========sum

function show_buynow2(p_psecode,p_psecode2,imagepath){
	var proportion = 1.00; //
	var now_price;	    //
	var now_price  = Math.round(price[p_psecode][0] * proportion * 100)/100;
	var now_price2 = Math.round(price[p_psecode2][0] * proportion * 100)/100;
	var now_price = eval(now_price) + eval(now_price2);
	var now_price  = round_decimals( now_price ,2);
    var now_price2  = now_price*0.98;
    var now_price2  = round_decimals( now_price2 ,2);
 if ((price[p_psecode] != "0" && price[p_psecode][1] == "1") && (price[p_psecode2] != "0" && price[p_psecode2][1] == "1")) {
  document.write("<font size=\"1\"><b>Total List Price: </b></font><s>$" + now_price + "</s><b><br><font size=\"1\">Buy Together Today: </font><font color=\"#FF0000\">$" + now_price2 + "</font></b> ");
  document.write("<input name=\"Submit\" type=\"image\" value=\"Submit\" src=\"/images/buy2.gif\">");
    document.write("<input type=\"hidden\" name=\"psecode\" value=\"" + p_psecode + "+" + p_psecode2 + "\">");
  document.write("<input type=\"hidden\" name=\"pseprice\" value=\"" + now_price2 + "\">");
  document.write("<input type=\"hidden\" name=\"sitename\" value=\"www.laptop-battery.org\">");
	}
	else{
		document.write("Sorry, out of stock now!");
		}
}
function show_buynow3(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);
	var rise_price = round_decimals( now_price*1.2 ,2);
	if (price[p_psecode][0] != "0" && price[p_psecode][1] == "1"){
		document.write("<p><em><b>Original Price:<font color=\"#000000\"><S>" + "$" + rise_price + " </b></S></em></p>");
		document.write("<p><b><font color=\"#FF0000\">Special Price:" + "$" + now_price + " </b></p>");
		document.write("<input name=\"Submit\" type=\"image\" value=\"Submit\" src=\"/images/buy.gif\">");
		document.write("<input type=\"hidden\" name=\"psecode\" value=\"" + p_psecode + "\">");
		document.write("<input type=\"hidden\" name=\"pseprice\" value=\"" + now_price + "\">");
		document.write("<input type=\"hidden\" name=\"sitename\" value=\"www.laptop-battery.org\">");
		
	}
	else{
		document.write("<p><b><font color=\"#FF0000\">"+"Sorry, out of stock now!" + "</font></b></p>");
		//document.write("<span class=\"style3\">Out of stock</span>");
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function JustSoPicWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
       if (bgcolor=="") {
              bgcolor="#FFFFFF";
       }
       var adj=10
       var w = screen.width;
       var h = screen.height;
       var byFactor=1;

       if(w<740){
         var lift=0.90;
       }
       if(w>=740 & w<835){
         var lift=0.91;
       }
       if(w>=835){
         var lift=0.93;
       }
       if (imageWidth>w){       
         byFactor = w / imageWidth;                     
         imageWidth = w;
         imageHeight = imageHeight * byFactor;
       }
       if (imageHeight>h-adj){
         byFactor = h / imageHeight;
         imageWidth = (imageWidth * byFactor);
         imageHeight = h; 
       }
          
       var scrWidth = w-adj;
       var scrHeight = (h*lift)-adj;

       if (imageHeight>scrHeight){
           imageHeight=imageHeight*lift;
         imageWidth=imageWidth*lift;
       }

       var posLeft=0;
       var posTop=0;

       if (hugger == "hug image"){
         if (hugMargin == ""){
           hugMargin = 0;
         }
         var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
         if (scrHeightTemp < scrHeight) {
              scrHeight = scrHeightTemp;
         } 
         var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
         if (scrWidthTemp < scrWidth) {
              scrWidth = scrWidthTemp;
         }
         
         if (scrHeight<100){scrHeight=100;}
         if (scrWidth<100){scrWidth=100;}

         posTop =  ((h-(scrHeight/lift)-adj)/2);
         posLeft = ((w-(scrWidth)-adj)/2);
       }

       if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
              imageHeight=imageHeight-adj;
              imageWidth=imageWidth-adj;
       }

       var agt=navigator.userAgent.toLowerCase(); 
       var is_opera = (agt.indexOf("opera") != -1); 

       if (is_opera == true){
         var args= new Array();
         args[0]='parent';
         args[1]=imageName;
         var i ; document.MM_returnValue = false;
         for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
       } else {

       newWindow = window.open("vwd_justso.htm","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
       newWindow.document.open();
       newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onBlur="self.close()" onClick="self.close()">');  
       newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
       newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+'height='+imageHeight+' alt="Click screen to close" >'); 
       newWindow.document.write('</td></tr></table></body></html>');
       newWindow.document.close();
       newWindow.focus();
       }
}

