



function currencyOnchange(id){
	var currencyObj=document.getElementById(id);
	if(priceCalculaterCurrency!=currencyObj.options[currencyObj.options.selectedIndex].value){
		priceCalculaterCurrency=currencyObj.options[currencyObj.options.selectedIndex].value;
		priceCalculaterOnchange();
		priceListTableUpdate();
		return true;
	}
	document.getElementById("chooseCurrency").options.selectedIndex = currencyObj.options.selectedIndex;
	document.getElementById("chooseCurrency2").options.selectedIndex = currencyObj.options.selectedIndex;
	return false;
}
function priceListTableUpdate(){
	for(var index in pricesObj["li0001"])
		switch(index){
			case "4":
				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"][4][priceCalculaterCurrency]))*100) )+"%";
				document.getElementById("tdli0001quantitysavings1to4").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][4][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"][4][priceCalculaterCurrency]))*100) )+"%";
				document.getElementById("tdli0001quantitysavings5to9").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][4][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"][4][priceCalculaterCurrency]))*100) )+"%";
				document.getElementById("tdli0001quantitysavings10to24").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][4][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"][4][priceCalculaterCurrency]))*100) )+"%";
				document.getElementById("tdli0001quantitysavings25to49").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][4][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"][4][priceCalculaterCurrency]))*100) )+"%";
				if(document.getElementById("tdli0001quantitysavings50plus"))document.getElementById("tdli0001quantitysavings50plus").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(Math.ceil(parseInt(pricesObj["li0001"][4][priceCalculaterCurrency])-parseInt(pricesObj["li0001"][index][priceCalculaterCurrency]))) + "";
				break;
		}
}
function priceCalculaterOnchange(e){
	var keycode;
	if(window.event)keycode=window.event.keyCode;
	else if(e)keycode=e.which;
	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));
	
	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);
	}
	
	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);
	}
	
	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);
	}
	
	var oemCartPrice=priceCalculaterGetPrice("li-OEM",1);
	var videoCartPrice=priceCalculaterGetPrice("video",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;
	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);
	document.getElementById("licensesOEMPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(oemCartPrice);
	document.getElementById("licensesVideoPrice").innerHTML=priceCalculaterCurrency+" "+priceCalculaterFormatNumber(videoCartPrice);
	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();
}
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("promocode")){
		url+="&promocode="+escape(document.getElementById("promocode").value);
	}
	url+="&id="+cartid+"&quantity="+cartquantity;
	window.location=url;
}



