function calculate()
{
	var rate = 6.30;
	var comission_percent = 10;
	var min_comission = 2;
	var price = document.getElementById('item_price').value;
	var amount = document.getElementById('item_amount').value; 
	var delivery = document.getElementById('item_china_delivery').value; 
	var total = 0, totalusd = 0.00;
	if (parseInt(price) > 0 && parseInt(amount) >= 1 && parseInt(delivery) >= 0)
	{
		total = parseFloat(price) * parseInt(amount);
		var comission = convertToUsd(total * (comission_percent / 100), rate);
		if (comission < min_comission) {
			comission = min_comission;
		}
		totalusd = convertToUsd(total, rate) + comission + convertToUsd(parseInt(delivery), rate);
	}
	document.getElementById('usdTotal').innerHTML = roundNumber(totalusd, 2);
}

function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}

function convertToUsd(value, rate, id)
{
	value = Number(value);
	var result = 0;
	if (value > 0)
	{
		result = value / rate;
	}
	return roundNumber(result, 2);
}

function calculateShipping()
{
	var amount = {'ems':
					{'by': [0, 192, 278, 366, 453, 540, 628, 710, 803, 884, 972],
					 'ru': [0, 192, 278, 366, 453, 540, 628, 710, 803, 884, 972],
					 'ua': [0, 192, 278, 366, 453, 540, 628, 710, 803, 884, 972]
					},
				  'chinapost':
					{'by': [0, 135, 192, 248, 304, 360, 417, 473, 529, 586, 642],
					 'ru': [0, 171, 230, 289, 349, 408, 467, 526, 586, 646, 704],
					 'ua': [0, 162, 216, 270, 324, 378, 432, 486, 540, 594, 648]
					}		
				};
	var weight = parseInt(document.getElementById('weight').value);
	if (weight != 0) 
	{
		var method = document.getElementById('shipping').value;
		var country = document.getElementById('country').value;
		var total = amount[method][country][weight];
		document.getElementById('result4').innerHTML = total;
		document.getElementById('result5').innerHTML = Math.round(total*0.15625*100)/100;
	}	
}
