



function currencyOnchange(id){
	var currencyObj=document.getElementById(id);
	if(priceCalculaterCurrency!=currencyObj.options[currencyObj.options.selectedIndex].value){
		priceCalculaterCurrency=currencyObj.options[currencyObj.options.selectedIndex].value;
		try{priceCalculaterOnchange();}catch(e){}
		try{priceListTableUpdate();}catch(e){}
		return true;
	}
	try{document.getElementById("chooseCurrency").options.selectedIndex = currencyObj.options.selectedIndex;}catch(e){}
	try{document.getElementById("chooseCurrency2").options.selectedIndex = currencyObj.options.selectedIndex;}catch(e){}
	return false;
}
function priceListTableUpdate(){
	for(var index in pricesObj["li0001"])try{
		switch(index){
			case "1":
			  document.getElementById("tdli0001quantity1to1").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li0001"][index][priceCalculaterCurrency]);
  			document.getElementById("tdli0001quantityprocent1to1").innerHTML=Math.ceil( 100-((parseInt(pricesObj["li0001"][index][priceCalculaterCurrency])/parseInt(pricesObj["li0001"][1][priceCalculaterCurrency]))*100) )+"%";
  			document.getElementById("tdli0001quantitysavings1to1").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][1][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
  			break;
			case "4":
			  if (document.getElementById("tdli0001quantity1to4")){
          document.getElementById("tdli0001quantity1to4").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li0001"][index][priceCalculaterCurrency]);
  				document.getElementById("tdli0001quantityprocent1to4").innerHTML=Math.ceil( 100-((parseInt(pricesObj["li0001"][index][priceCalculaterCurrency])/parseInt(pricesObj["li0001"][1][priceCalculaterCurrency]))*100) )+"%";
  				document.getElementById("tdli0001quantitysavings1to4").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][1][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
        }
        else if (document.getElementById("tdli0001quantity2to4")){
          document.getElementById("tdli0001quantity2to4").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li0001"][index][priceCalculaterCurrency]);
  				document.getElementById("tdli0001quantityprocent2to4").innerHTML=Math.ceil( 100-((parseInt(pricesObj["li0001"][index][priceCalculaterCurrency])/parseInt(pricesObj["li0001"][1][priceCalculaterCurrency]))*100) )+"%";
  				document.getElementById("tdli0001quantitysavings2to4").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][1][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
        }
				break;
			case "9":
				document.getElementById("tdli0001quantity5to9").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li0001"][index][priceCalculaterCurrency]);
				document.getElementById("tdli0001quantityprocent5to9").innerHTML=Math.ceil( 100-((parseInt(pricesObj["li0001"][index][priceCalculaterCurrency])/parseInt(pricesObj["li0001"][1][priceCalculaterCurrency]))*100) )+"%";
				document.getElementById("tdli0001quantitysavings5to9").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][1][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
				break;
			case "24":
				document.getElementById("tdli0001quantity10to24").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li0001"][index][priceCalculaterCurrency]);
				document.getElementById("tdli0001quantityprocent10to24").innerHTML=Math.ceil( 100-((parseInt(pricesObj["li0001"][index][priceCalculaterCurrency])/parseInt(pricesObj["li0001"][1][priceCalculaterCurrency]))*100) )+"%";
				document.getElementById("tdli0001quantitysavings10to24").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][1][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
				break;
			case "49":
				document.getElementById("tdli0001quantity25to49").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li0001"][index][priceCalculaterCurrency]);
				document.getElementById("tdli0001quantityprocent25to49").innerHTML=Math.ceil( 100-((parseInt(pricesObj["li0001"][index][priceCalculaterCurrency])/parseInt(pricesObj["li0001"][1][priceCalculaterCurrency]))*100) )+"%";
				document.getElementById("tdli0001quantitysavings25to49").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][1][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
				break;
			case "99":
				document.getElementById("tdli0001quantity50to99").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li0001"][index][priceCalculaterCurrency]);
				document.getElementById("tdli0001quantityprocent50to99").innerHTML=Math.ceil( 100-((parseInt(pricesObj["li0001"][index][priceCalculaterCurrency])/parseInt(pricesObj["li0001"][1][priceCalculaterCurrency]))*100) )+"%";
				document.getElementById("tdli0001quantitysavings50to99").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][1][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
				break;
			case "1000000":
				if(document.getElementById("tdli0001quantity50plus"))document.getElementById("tdli0001quantity50plus").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li0001"][index][priceCalculaterCurrency]);
				if(document.getElementById("tdli0001quantityprocent50plus"))document.getElementById("tdli0001quantityprocent50plus").innerHTML=Math.ceil( 100-((parseInt(pricesObj["li0001"][index][priceCalculaterCurrency])/parseInt(pricesObj["li0001"][1][priceCalculaterCurrency]))*100) )+"%";
				if(document.getElementById("tdli0001quantitysavings50plus"))document.getElementById("tdli0001quantitysavings50plus").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][1][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
				if(document.getElementById("tdli0001quantity100plus"))document.getElementById("tdli0001quantity100plus").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li0001"][index][priceCalculaterCurrency]);
				if(document.getElementById("tdli0001quantityprocent100plus"))document.getElementById("tdli0001quantityprocent100plus").innerHTML=Math.ceil( 100-((parseInt(pricesObj["li0001"][index][priceCalculaterCurrency])/parseInt(pricesObj["li0001"][1][priceCalculaterCurrency]))*100) )+"%";
				if(document.getElementById("tdli0001quantitysavings100plus"))document.getElementById("tdli0001quantitysavings100plus").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][1][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
				break;
		}}catch(e){}
		if (document.getElementById("tdreuploadprice"))document.getElementById("tdreuploadprice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["change"]["1000000"][priceCalculaterCurrency]);
		if (document.getElementById("tdrenewalprice"))document.getElementById("tdrenewalprice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["renewal"]["1000000"][priceCalculaterCurrency]);
		if (document.getElementById("tdvideoprice"))document.getElementById("tdvideoprice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["video"]["10"][priceCalculaterCurrency]);
		if (document.getElementById("tdlioemprice"))document.getElementById("tdlioemprice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["li-OEM"]["1000000"][priceCalculaterCurrency]);
		if (document.getElementById("tdteaserprice"))document.getElementById("tdteaserprice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["teaser"]["1000000"][priceCalculaterCurrency]);
		if (document.getElementById("tdLicensesUnlimitedPrice"))document.getElementById("tdLicensesUnlimitedPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(pricesObj["unlimited"]["1000000"][priceCalculaterCurrency]);
		priceCalculaterOnchange(event);
}
function priceCalculaterOnchange(e){
	var keycode;
	if(window.event)keycode=window.event.keyCode;
	else if(e)keycode=e.which;
  try{
    var li0001Quantity=priceCalculaterToInt("0"+document.getElementById("li0001quantity").value);
    var li0001CartPrice=priceCalculaterGetPrice("li0001",1*li0001Quantity);
    if(li0001CartPrice==0 && arguments.length==0){
  		document.getElementById("li0001quantity").value="";
  		return priceCalculaterOnchange(1);
  	}
  	else if(li0001Quantity>9999 && arguments.length==0){
  		document.getElementById("li0001quantity").value=(""+li0001Quantity).substr(0,4);
  		return priceCalculaterOnchange(2);
  	}
    var li0001ListPrice=priceCalculaterGetPrice("li0001",1);
    var li0001NextDiscountLevel=1+(1*priceCalculaterGetNextDiscountLevel("li0001",1*li0001Quantity));
  }
  catch(e){}
  try{
  	var reuploadQuantity=priceCalculaterToInt("0"+document.getElementById("reuploadquantity").value);
  	var reuploadCartPrice=priceCalculaterGetPrice("change",1*reuploadQuantity);
  	if(reuploadCartPrice==0 && arguments.length==0){
  		document.getElementById("reuploadquantity").value="";
  		return priceCalculaterOnchange(3);
  	}
  	else if(reuploadQuantity>9999 && arguments.length==0){
  		document.getElementById("reuploadquantity").value=(""+reuploadQuantity).substr(0,4);
  		return priceCalculaterOnchange(4);
  	}
  }
  catch(e){}
  try{
    var teaserQuantity=priceCalculaterToInt("0"+document.getElementById("teaserquantity").value);
  	var teaserCartPrice=priceCalculaterGetPrice("teaser",1*teaserQuantity);
  	if(teaserCartPrice==0 && arguments.length==0){
  		document.getElementById("teaserquantity").value="";
  		return priceCalculaterOnchange(5);
  	}
  	else if(teaserQuantity>9999 && arguments.length==0){
  		document.getElementById("teaserquantity").value=(""+teaserQuantity).substr(0,4);
  		return priceCalculaterOnchange(6);
  	}
  }
  catch(e){}
  try{
  	var renewalQuantity=priceCalculaterToInt("0"+document.getElementById("renewalquantity").value);
  	var renewalCartPrice=priceCalculaterGetPrice("renewal",1*renewalQuantity);
  	if(renewalCartPrice==0 && arguments.length==0){
  		document.getElementById("renewalquantity").value="";
  		return priceCalculaterOnchange(7);
  	}
  	else if(renewalQuantity>9999 && arguments.length==0){
  		document.getElementById("renewalquantity").value=(""+renewalQuantity).substr(0,4);
  		return priceCalculaterOnchange(8);
  	}
  }
  catch(e){}
  try{
  	var oemCartPrice=priceCalculaterGetPrice("li-OEM",1);
  	var videoCartPrice=priceCalculaterGetPrice("video",1);
  	var unlimitedCartPrice=priceCalculaterGetPrice("unlimited",1);
  	var totalDiscount=(li0001Quantity*li0001ListPrice)-(li0001Quantity*li0001CartPrice);
  	var totalCartPrice=li0001Quantity*li0001CartPrice;
  	totalCartPrice+=reuploadQuantity*parseInt(reuploadCartPrice);
  	totalCartPrice+=teaserQuantity*parseInt(teaserCartPrice);
  	totalCartPrice+=renewalQuantity*parseInt(renewalCartPrice);
  	if(document.getElementById("liOEM").checked)
  		totalCartPrice+=1*oemCartPrice;
  	if(document.getElementById("livideo").checked)
  		totalCartPrice+=1*videoCartPrice;
  	if(document.getElementById("unlimited") && document.getElementById("unlimited").checked)
  		totalCartPrice+=1*unlimitedCartPrice;
  	priceCalculaterTotalPrice=parseInt(totalCartPrice);
  	priceCalculaterSetInput("li0001quantity",1*li0001Quantity);
  	priceCalculaterSetInput("reuploadquantity",1*reuploadQuantity);
  	priceCalculaterSetInput("teaserquantity",1*teaserQuantity);
  	priceCalculaterSetInput("renewalquantity",1*renewalQuantity);
  	document.getElementById("licensesCartPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(li0001CartPrice);
  	document.getElementById("reuploadListPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(reuploadCartPrice);
  	document.getElementById("teaserListPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(teaserCartPrice);
  }
  catch(e){}
  try{
    if (document.getElementById("licensesUnlimitedPrice")){
      document.getElementById("licensesUnlimitedPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(unlimitedCartPrice);
    }
    document.getElementById("licensesOEMPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(oemCartPrice);
  	document.getElementById("licensesVideoPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(videoCartPrice);
  	if (document.getElementById("licensesUnlimitedPrice"))
      document.getElementById("licensesUnlimitedPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(unlimitedCartPrice);
  	document.getElementById("renewalListPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(renewalCartPrice);
  	document.getElementById("licensesTotalCurrency").innerHTML=priceCalculaterCurrency;
  	document.getElementById("licensesTotalPrice").innerHTML=priceCalculaterFormatNumber(totalCartPrice);
  	document.getElementById("liDiscount1").innerHTML="&nbsp;";//Math.ceil( 100-((parseInt(li0001CartPrice)/parseInt(li0001ListPrice))*100) )+"%";
  	document.getElementById("liDiscount2").innerHTML=priceCalculaterCurrency;
  	document.getElementById("liDiscount3").innerHTML="<nobr>-"+priceCalculaterFormatNumber(totalDiscount)+"</nobr>";
  	document.getElementById("liDiscount4").innerHTML=li0001NextDiscountLevel;
  	if((li0001NextDiscountLevel<1000001)&&(li0001NextDiscountLevel<=(li0001Quantity+4)))
  		document.getElementById("liDiscount5").style.display="inline";
  	else
  		document.getElementById("liDiscount5").style.display="none";
  	if(keycode==13)
  		priceCalculaterSubmit();
  }
  catch(e){}
}
function priceCalculaterToInt(value){
	value=value.replace(/[^0-9]*/gim,"");
	return 1*value;
}
function priceCalculaterGetPrice(productid,quantity){
  if(productid in pricesObj)
		for(var index in pricesObj[productid])
			if(parseInt(index)>=parseInt(quantity))
				return pricesObj[productid][index][priceCalculaterCurrency];
	return 0;
}
function priceCalculaterGetNextDiscountLevel(productid,quantity){
	if(productid in pricesObj)
		for(var index in pricesObj[productid])
			if(parseInt(index)>=parseInt(quantity))
				return index;
	return 0;
}
function priceCalculaterSetInput(id,value){
	if(""+document.getElementById(id).value!=""+value)
		document.getElementById(id).value=value>0?value:"";
}
function priceCalculaterFormatNumber(no){
	var noStr=""+no,
		no=parseInt(no),
		digs="00",
		tmp=null,
		returnStr=""+no;
	if(noStr.indexOf(".")>-1){
		tmp=noStr.split(/\./gim);
		no=parseInt(tmp[0]);
		digs=parseInt(tmp[1]);
		digs=(digs<10?"0":"")+digs;
	}
	if(no>999){
		tmp=""+no;
		returnStr=tmp.substr(0,tmp.length-3);
		returnStr+=","+tmp.substr(returnStr.length);
	}
	return returnStr+"."+digs;
}
function priceCalculaterSubmit(){
	if(parseInt(priceCalculaterTotalPrice)==0){
		document.getElementById("li0001quantity").focus();
		return false;
	}
	var url="/cart/add2.php?currency="+priceCalculaterCurrency+"&emptycart=1&fastcheckout=1";
	var cartid="",cartquantity="",i=0;
	if(parseInt(document.getElementById("li0001quantity").value)>0){
		cartid+=(++i>1?",":"")+"li0001";
		cartquantity+=(i>1?",":"")+document.getElementById("li0001quantity").value;
	}
	if(parseInt(document.getElementById("reuploadquantity").value)>0){
		cartid+=(++i>1?",":"")+"change";
		cartquantity+=(i>1?",":"")+document.getElementById("reuploadquantity").value;
	}
	if(parseInt(document.getElementById("teaserquantity").value)>0){
		cartid+=(++i>1?",":"")+"teaser";
		cartquantity+=(i>1?",":"")+document.getElementById("teaserquantity").value;
	}
	if(parseInt(document.getElementById("renewalquantity").value)>0){
		cartid+=(++i>1?",":"")+"renewal";
		cartquantity+=(i>1?",":"")+document.getElementById("renewalquantity").value;
	}
	if(document.getElementById("liOEM").checked){
		cartid+=(++i>1?",":"")+"li-OEM";
		cartquantity+=(i>1?",":"")+"1";
	}
	if(document.getElementById("livideo").checked){
		cartid+=(++i>1?",":"")+"video";
		cartquantity+=(i>1?",":"")+"1";
	}
	if(document.getElementById("unlimited") && document.getElementById("unlimited").checked){
		cartid+=(++i>1?",":"")+"unlimited";
		cartquantity+=(i>1?",":"")+"1";
	}
	if(document.getElementById("promocode")){
		url+="&promocode="+escape(document.getElementById("promocode").value);
	}
	url+="&id="+cartid+"&quantity="+cartquantity;
	//alert(url);
	window.location=url;
}




