﻿function list_style(Num,form){
	document.getElementById("list_display10").src="/images/list02.jpg";
	document.getElementById("list_display11").src="/images/list12.jpg";
	document.getElementById("list_display12").src="/images/list22.jpg";
	document.getElementById("list_display20").src="/images/list02.jpg";
	document.getElementById("list_display21").src="/images/list12.jpg";
	document.getElementById("list_display22").src="/images/list22.jpg";
	
	document.getElementById("list_display1"+Num).src="/images/list"+Num+"1.jpg";
	document.getElementById("list_display2"+Num).src="/images/list"+Num+"1.jpg";
	
	document.getElementById("product_list").className="product_list"+Num;
	setCookies("product_list",Num);
}

function Show_product_list(){
	var Num;
	Num=getCookieVal("product_list");
	
	if (Num==''){
		Num=0;
	}

	document.getElementById("list_display10").src="/images/list02.jpg";
	document.getElementById("list_display11").src="/images/list12.jpg";
	document.getElementById("list_display12").src="/images/list22.jpg";
	document.getElementById("list_display20").src="/images/list02.jpg";
	document.getElementById("list_display21").src="/images/list12.jpg";
	document.getElementById("list_display22").src="/images/list22.jpg";
	
	document.getElementById("list_display1"+Num).src="/images/list"+Num+"1.jpg";
	document.getElementById("list_display2"+Num).src="/images/list"+Num+"1.jpg";
	
	document.getElementById("product_list").className="product_list"+Num;
}


function show(flag,url){
var my_tips=document.all.mytips;
if(flag){
     my_tips.style.display="";
     if (url!=null){my_tips.innerHTML="<img src='"+url+"' align='left' width='250' style='border:1 #cccccc solid;'>";}
     else{ my_tips.innerHTML='';}
     my_tips.style.left=event.clientX-50+document.documentElement.scrollLeft;
     my_tips.style.top=event.clientY+20+document.documentElement.scrollTop;
    // my_tips.style.left=event.clientX-20;
     //my_tips.style.top=event.clientY+20;
    }
else 
   {
    my_tips.style.display="none";
    }
}  


function ForDight(Dight,How)   
{   
  Dight=Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);   
  return Dight;   
}   


function ShippingSelect(FirstPrice,SecondPrice,ShippingTxt,InsurancePrice,InsuranceTxt,Total,int_all){
	
	var InsurancePriceAll=ForDight(InsurancePrice*int_all,2);
	
	Total=FormatNumber(Total,2);
	
	document.getElementById("ShippingTxt").innerHTML=ShippingTxt;
	document.getElementById("InsuranceTxt").innerHTML="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+InsuranceTxt;
	//document.getElementById("InsurancePrice").innerHTML=" $"+InsurancePriceAll;
	document.getElementById("InsurancePrice").innerHTML=" $"+InsurancePrice+" each item.";
	
	document.getElementById("ShippingTotal").innerHTML=" $"+FormatNumber((parseFloat(FirstPrice)+(parseFloat(int_all)-1)*parseFloat(SecondPrice)),2);
	document.getElementById("AllTotal").innerHTML=" $"+FormatNumber((parseFloat(Total)+parseFloat(FirstPrice)+(parseFloat(int_all)-1)*parseFloat(SecondPrice)),2);
	
	document.getElementById("insurance").checked=false;
	document.getElementById("insurance").value=InsurancePriceAll;
	document.getElementById("order_Shipping_Price").value=FirstPrice+(int_all-1)*SecondPrice;
	document.getElementById("order_All_Price").value=parseFloat(Total)+FirstPrice+(int_all-1)*SecondPrice;
	
}


function InsuranceSelect(num,Total){
	
	Total=FormatNumber(Total,2);
	
	if (document.getElementById("insurance").checked==true){
		document.getElementById("ShippingTotal").innerHTML=" $"+FormatNumber((parseFloat(document.getElementById("order_Shipping_Price").value)+parseFloat(num)),2);
		document.getElementById("AllTotal").innerHTML=" $"+FormatNumber((parseFloat(document.getElementById("order_Shipping_Price").value)+parseFloat(Total)+parseFloat(num)),2);
		document.getElementById("order_All_Price").value=parseFloat(document.getElementById("order_Shipping_Price").value)+parseFloat(Total)+parseFloat(num);
	}else{
		document.getElementById("ShippingTotal").innerHTML=" $"+FormatNumber((parseFloat(document.getElementById("order_Shipping_Price").value)),2);
		document.getElementById("AllTotal").innerHTML=" $"+FormatNumber((parseFloat(document.getElementById("order_Shipping_Price").value)+parseFloat(Total)),2);
		document.getElementById("order_All_Price").value=parseFloat(document.getElementById("order_Shipping_Price").value)+parseFloat(Total);
	}
}


function FormatNumber(srcStr,nAfterDot)        //nAfterDot小数位数
{
　　        var srcStr,nAfterDot;
　　        var resultStr,nTen;
　　        srcStr = ""+srcStr+"";
　　        strLen = srcStr.length;
　　        dotPos = srcStr.indexOf(".",0);
　　        if (dotPos == -1){
　　　　        resultStr = srcStr+".";
　　　　        for (i=0;i<nAfterDot;i++){
　　　　　　        resultStr = resultStr+"0";
　　　　        }
　　　　        return resultStr;
　　        }
　　        else{
　　　　        if ((strLen - dotPos - 1) >= nAfterDot){
　　　　　　        nAfter = dotPos + nAfterDot + 1;
　　　　　　        nTen =1;
　　　　　　        for(j=0;j<nAfterDot;j++){
　　　　　　　　        nTen = nTen*10;
　　　　　　        }
　　　　　　        resultStr = Math.round(parseFloat(srcStr)*nTen)/nTen;
　　　　　　        return resultStr;
　　　　        }
　　　　        else{
　　　　　　        resultStr = srcStr;
　　　　　　        for (i=0;i<(nAfterDot - strLen + dotPos + 1);i++){
　　　　　　　　        resultStr = resultStr+"0";
　　　　　　        }
　　　　　　        return resultStr;
　　　　        }
　　        }
}



function getCookieVal(name)
    {
    var firstCharPos,lastCharPos;
    var theBigCookie = document.cookie;
    firstCharPos = theBigCookie.indexOf(name);
    if(firstCharPos != -1)
    {//skip 'name' and '='.
    firstCharPos +=name.length + 1;
    //Find the end of the value string (i.e. the next';').
    lastCharPos = theBigCookie.indexOf(';', firstCharPos);
    if(lastCharPos == -1) lastCharPos = theBigCookie.length;
    //Return thevalue.
    return theBigCookie.substring(firstCharPos, lastCharPos);
    }
    else
    { return false;}
} 
function setCookies(name,value)
{
   var Days = 30; //此 cookie 将被保存 30 天
   var exp   = new Date();     //new Date("December 31, 9998");
   exp.setTime(exp.getTime() + Days*24*60*60*1000);
   document.cookie =name+"="+value;
}


function left_menu(meval,img,j)
{
  if (document.getElementById(meval).style.display=="none")
  {
	img.src='/images/Minus.jpg';
  	document.getElementById(meval).style.display="";
	setCookies("left_menu_"+j,"1");
	//alert(getCookieVal("left_menu"));
  }else{
	img.src='/images/Plus.jpg';
  	document.getElementById(meval).style.display="none";
	setCookies("left_menu_"+j,"0");
	//alert(getCookieVal("left_menu"));
  }

}

function Show_left_menu(j){
	for(var i=1;i<j+1;i++) {
		if(getCookieVal("left_menu_"+i)=="1"){
			document.getElementById("left_menu_"+i+"_img").src='/images/Minus.jpg';
  			document.getElementById("left_menu_"+i).style.display="";
		}else{
			document.getElementById("left_menu_"+i+"_img").src='/images/Plus.jpg';
  			document.getElementById("left_menu_"+i).style.display="none";
		}
	}
}

function ShippingAddressSelect(obj){
	var inputs=document.getElementById("shipping_info").getElementsByTagName("input");
	var inputLength=document.getElementById("shipping_info").getElementsByTagName("input").length;
	
	var selects=document.getElementById("shipping_info").getElementsByTagName("select");
	var selectLength=document.getElementById("shipping_info").getElementsByTagName("select").length;
	
	if (obj.checked){
		document.getElementById("shipping_info").className="shipping_info_hide";
		for(i=0;i<inputLength;i++){
			inputs[i].disabled="disabled";
		}
		for(j=0;j<selectLength;j++){
			selects[j].disabled="disabled";
		}
	}else{
		document.getElementById("shipping_info").className="shipping_info_show";
		for(i=0;i<inputLength;i++){
			inputs[i].disabled="";
		}
		for(j=0;j<selectLength;j++){
			selects[j].disabled="";
		}
	}
	ShippingType('');
}

function CheckOutLoad(){
	ShippingAddressSelect(document.getElementById("card_address_select"));
}

