// Global JavaScript file

function CalculateShippingCost() {
   /*id='totalWeight'
   id='shippingCost'
   id='totalCost'*/
   var shipping = 0;
   var airmail = 0;
   var weight = parseInt(document.getElementById('totalWeight').innerHTML * 1);
   var total = document.getElementById('BaseTotal').value;
   var region = document.shoppingCartForm.country.value;
   region = region.substring(region.indexOf('#') + 1);
   
   /*if (total > 150) {
		document.getElementById('shippingCost').innerHTML = '0 Eur';
		document.getElementById('totalCost').innerHTML = total;
		document.getElementById('shipping').value = 0;
		return;
   } */  
   
   if ((weight > 0) && (weight < 500)) {
      weight = weight + 150;
      } else if (weight < 1300) {
      weight = weight + 600;
      } else if (weight < 2600) {
      weight = weight + 1000;
      } else {
      weight = weight + 1500;
      }

   if (weight == 0) {
     document.getElementById('shippingCost').innerHTML = '0 Eur';
     document.getElementById('totalCost').innerHTML = '0';
     return;
     }
    if (weight <= 2000) {
     if (weight <= 50) {
       shipping = 26;
       } else if (weight <= 100) {
       shipping = 33;
       } else if (weight <= 250) {
       shipping = 45;
       } else if (weight <= 500) {
       shipping = 67;
       } else if (weight <= 1000) {
       shipping = 98;
       } else {
       shipping = 138;
       }
     if (document.getElementById('airmail').checked == true) {
       if (region == '1') {
         airmail = 4;
         } else if (region == '2') {
         airmail = 3;
         }
       shipping = shipping + Math.floor(weight / 20) * airmail;
       if ((weight % 20) > 0) {
         shipping = shipping + airmail;
         }
       }
     if (region == '5') {
       shipping = 30;
       }
     } else {
     if (region == '1') {
       shipping = 164;
       airmail = 42;
       if (weight > 1000) {
         shipping = shipping + Math.floor((weight - 1000) / 1000 ) * 34;
         if (((weight - 1000) % 1000) > 0) {
           shipping = shipping + 34;
           }
         }
       } else if (region == '2') {
       shipping = 143;
       airmail = 28;
       if (weight > 1000) {
         shipping = shipping + Math.floor((weight - 1000) / 1000 ) * 28;
         if (((weight - 1000) % 1000) > 0) {
           shipping = shipping + 28;
           }
         }
       } else if (region == '3') {
       shipping = 115.5;
       airmail = 0;
       if (weight > 1000) {
         shipping = shipping + Math.floor((weight - 1000) / 1000 ) * 12.5;
         if (((weight - 1000) % 1000) > 0) {
           shipping = shipping + 12.5;
           }
         }
       } else if (region == '5') {
       shipping = 40;
       airmail = 0;
       } else {
       shipping = 102.5;
       airmail = 0;
       if (weight > 1000) {
         shipping = shipping + Math.floor((weight - 1000) / 1000 ) * 8.5;
         if (((weight - 1000) % 1000) > 0) {
           shipping = shipping + 8.5;
           }
         }
       }
     if (document.getElementById('airmail').checked == true) {
       shipping = shipping + Math.floor(weight / 500) * airmail;
       if ((weight % 500) > 0) {
         shipping = shipping + airmail;
         }
       }
     }
   if (shipping > 0) {
     shipping = (shipping / 7) * 100;
     shipping = Math.round(shipping);
     shipping = shipping / 100;
     }
     
   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;
   }
