// Global JavaScript file

function CalculateShippingCost() {
	var shipping = 0;
	var airmail = 0;
	if (document.getElementById('totalWeight')) {
		var weight = parseInt(document.getElementById('totalWeight').innerHTML);
	} else {
		return;
	}
	if (document.getElementById('BaseTotal')) {
		var total = document.getElementById('BaseTotal').value;
	} else {
		return;
	}
	if (document.getElementById('country')) { 
		var regionChar = document.shoppingCartForm.country.value;
		regionChar = regionChar.substring(regionChar.indexOf('#') + 1);
		var region = parseInt(regionChar);
	} else {
		return;
	}   
	
	var	cost = new Array(5);
	/*ostalo*/
	cost[0] = new Array(10);
	cost[0][0] = 7;
	cost[0][1] = 13;
	cost[0][2] = 21;
	cost[0][3] = 29;
	cost[0][4] = 62;
	cost[0][5] = 92;
	cost[0][6] = 120;
	cost[0][7] = 150;
	cost[0][8] = 170;
	cost[0][9] = 190;
	/*SAD*/
	cost[1] = new Array(10);
	cost[1][0] = 7;
	cost[1][1] = 13;
	cost[1][2] = 21;
	cost[1][3] = 29;
	cost[1][4] = 51;
	cost[1][5] = 76;
	cost[1][6] = 102;
	cost[1][7] = 120;
	cost[1][8] = 140;
	cost[1][9] = 160;
	/*europa*/	
	cost[2] = new Array(10);
	cost[2][0] = 7;
	cost[2][1] = 13;
	cost[2][2] = 21;
	cost[2][3] = 29;
	cost[2][4] = 46;
	cost[2][5] = 56;
	cost[2][6] = 71;
	cost[2][7] = 80;
	cost[2][8] = 100;
	cost[2][9] = 120;
	/*ostalo zrak*/
	cost[3] = new Array(10);
	cost[3][0] = 10;
	cost[3][1] = 29;
	cost[3][2] = 37;
	cost[3][3] = 57;
	cost[3][4] = 75;
	cost[3][5] = 110;
	cost[3][6] = 140;
	cost[3][7] = 160;
	cost[3][8] = 180;
	cost[3][9] = 200;	
	/*SAD zrak*/
	cost[4] = new Array(10);
	cost[4][0] = 9;
	cost[4][1] = 25;
        cost[4][2] = 37;
	cost[4][3] = 52;
	cost[4][4] = 62;
	cost[4][5] = 92;
	cost[4][6] = 120;
	cost[4][7] = 140;
	cost[4][8] = 160;
	cost[4][9] = 180;
   
	if (weight == 0) {
		document.getElementById('shippingCost').innerHTML = '0 Eur';
		document.getElementById('totalCost').innerHTML = '0';
		return;
	}
	 
	if (document.getElementById('airmail').checked == true) {
		if ((region == 3) /*|| ((region == 2) && (weight > 500))*/) {
			document.getElementById('airmail').checked = false;
		} else {
			region = region + 3;
		}
	}
	region = region - 1;
   
	if (weight <= 100) {
		weight = 0;
	} else if (weight <= 500) {
		weight = 1;
	} else if (weight <= 1000) {
		weight = 2;
	} else if (weight <= 2000) {
		weight = 3;
	} else if (weight <= 5000) {
		weight = 4;
	} else if (weight <= 10000) {
		weight = 5;
	} else if (weight <= 15000) {
		weight = 6;
	} else if (weight <= 20000) {
		weight = 7;
	} else if (weight <= 25000) {
		weight = 8;
	} else if (weight <= 30000) {
		weight = 9;
	} else {
		document.getElementById('shippingCost').innerHTML = '0 Eur';
		return;
	}
   
	shipping = cost[region][weight];     
	total = parseFloat(total) * 100;
	total = Math.round(total);
	total = total / 100;
	var finalTotal = total+shipping;
	/*finalTotal = finalTotal * 100;
	finalTotal = Math.round(finalTotal);
	finalTotal = finalTotal / 100;*/
	document.getElementById('shippingCost').innerHTML = shipping+' Eur';
	document.getElementById('totalCost').innerHTML = finalTotal;
	document.getElementById('shipping').value = shipping;
	return;
}

