
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function ShowHideAccountNumer()
{
	if(document.getElementById('input_shipping').value.indexOf("Przelew") != -1 )
	{
		document.getElementById('account_number').style.display = "table-row";
	}
	else
	{
		document.getElementById('account_number').style.display = "none";
	}
}


//dodano 07.2011
function ComputeOrderPrice()
{
	
	var weightListDeposit = new Array(0, 1, 2, 5, 10, 15, 20);
	var shippingPriceDepositList = new Array(9.5, 11, 13, 18, 21, 30, 36);
	
	var weightListCod = new Array(0, 0.5, 1, 2, 5, 10, 15, 20);
	var shippingPriceCodList = new Array(10.5, 12.5, 14, 16, 22.5, 27, 36, 42);
	
	var sResult = document.getElementById('total_price');
	var sShippingPrice = document.getElementById('shipping_price');
	var iShippingType = document.getElementById('input_shipping').value;
	
	//ceny ksiazek
	var book1Price = 65;
	var book2Price = 14.5;
	
	//waga ksiazek
	var book1Weight = 0.8;//w kg
	var book2Weight = 0.25;
	
	//il ksiazek
	var quantity1 = parseInt(document.getElementById('input_quantity1').value);//ilosc ksiazki nr 1 (narazie tylko to)
	var quantity2 = parseInt(document.getElementById('input_quantity2').value);//ilosc ksiazki nr 1 (narazie tylko to)
	
	//waga ksiazek
	var totalWeight = quantity1 * book1Weight + quantity2 * book2Weight;
	
	//koszt przeslyki
	if (iShippingType == "Przelew")
	{
		var i=0;
		for (i=0;i<weightListDeposit.length-1;i++)
		{
			if (totalWeight >= weightListDeposit[i] && totalWeight < weightListDeposit[i+1])
				break;
		}
		var shippingCost = shippingPriceDepositList[i];
	}
	else
	{
		var i=0;
		for (i=0;i<weightListCod.length-1;i++)
		{
			if (totalWeight >= weightListCod[i] && totalWeight < weightListCod[i+1])
				break;
		}
		var shippingCost = shippingPriceCodList[i];
	}
	
	var totalPrice = (shippingCost + (quantity1 * book1Price + quantity2 * book2Price)).toFixed(2);

	
	if (!isNaN(totalPrice) && (quantity1 != 0 || quantity2 != 0))
	{
		sResult.innerHTML = "Suma: "+totalPrice+"zł";
		sShippingPrice.innerHTML = "Cena za przesyłkę: "+shippingCost+"zł";
	}
	else
	{
		sResult.innerHTML = "Suma: 0zł";
		sShippingPrice.innerHTML = "Cena za przesyłkę: 0zł";
	}
	
	
}

function ComputeOrderAmount()
{
	/*
	do przerobienia:
	na system wagowy a dodatkowo trzeba uzwględniac drgą książkę
	czyli kosz przesyłki będzie dobierany dopiero po zsumowaniu wagi książek
	*/
	
	ShowHideAccountNumer();

	var result = document.getElementById('orderAmount');
	
	var price = 65;
	var quantity = parseInt(document.getElementById('input_quantity').value);
	
	var deposit = document.getElementById('input_shipping_deposit');
	var cod = document.getElementById('input_shipping_cod');
	
	var depositCost = 0;
	
	if(quantity == 1)
	{
		depositCost = 9.5;
	}
	else if(quantity == 2)
	{
		depositCost = 11;
	}
	else
	{
		depositCost = 13;
	}

	var codCost = depositCost + 5;
	
	depositCost = depositCost.toFixed(2).toString().replace(".",",");
	codCost = codCost.toFixed(2).toString().replace(".",",");
	
	deposit.innerHTML = "Przelew - " + depositCost + "zł";
	deposit.value = "Przelew (" + depositCost + "zł)";
	cod.innerHTML = "Pobranie - " + codCost + "zł";	
	cod.value = "Pobranie (" + codCost + "zł)";
	
	var shippingStr = document.getElementById('input_shipping').value.replace(",",".");
	var shipping = parseFloat(shippingStr.substring(shippingStr.indexOf("(")+1,shippingStr.indexOf(")")-2));

	var total =  (price*quantity + shipping).toFixed(2);
	
	if(isNaN(total))
	{
		result.innerHTML = "";
	}  
	else
	{
		result.innerHTML = total.toString().replace(".",",") + ' zł';
	}
}
