function calSubtotal(itemPrice) {
   var quantity = document.getElementById('qty').value;
   
   if(!isNaN(quantity)) {
   
		   //become a integer
		   quantity = Math.round(quantity);
		   document.getElementById('qty').value = quantity;
		   
		   //check lower range
		   if (quantity < 5) {
		      document.getElementById('quantity_alert').innerHTML = "<br /><font size=1 color=red>Min. quantity is 5</>";  
		      document.getElementById('qty').value = "5";  
		      quantity = 5;  
		   }
		   
		   //check upper range
		   else if (quantity > 1000000) {
		   		document.getElementById('quantity_alert').innerHTML = "<br /><font size=1 color=red>Max. quantity is 1,000,000</>";      
		      document.getElementById('qty').value = "1000000";
		      quantity = 1000000;
		   } 
		   
		   //clear warning if it is normal
		   else {
		   		document.getElementById('quantity_alert').innerHTML = "";
		   }
	 }
	 else {
 		   document.getElementById('quantity_alert').innerHTML = "<br /><font size=1 color=red>Number Only</>";  
		   document.getElementById('qty').value = "5";  
		   quantity = 5; 
	 }
  
   var subtotal = quantity * itemPrice;
   calShipping();
   var shipping = document.getElementById('charge').value;
	 var total = parseInt(shipping) + parseInt(subtotal);
   document.getElementById('sub_total').value = subtotal;
	 document.getElementById('amount').value = total;
}

function calShipping() {
   var shipping = 0;
   var zone = document.getElementById('country').value;
   zone = zoneArray[zone];
   var quantity = document.getElementById('qty').value;
   var subtotal = document.getElementById('sub_total').value;
   switch (zone) {
      case 'A0':
      shipping = 14 + ((quantity-1) * 3);
      break;
      case '10':
      shipping = 27 + ((quantity-1) * 5);
      break;
      case '20':
      shipping = 27 + ((quantity-1) * 5);
      break;
      case 'B0':
      shipping = 18 + ((quantity-1) * 5);
      break;           
      case 'C0':
      shipping = 21 + ((quantity-1) * 5);
      break;      
      case 'D0':
      shipping = 24 + ((quantity-1) * 5);
      break;      
      case 'E1':
      shipping = 43 + ((quantity-1) * 6);
      break;
      case 'E0':
      shipping = 37 + ((quantity-1) * 5);
      break;            
      case 'F1':
      shipping = 53 + ((quantity-1) * 9);
      break;       
      case 'H1':
      shipping = 74 + ((quantity-1) * 17);
      break;     
      case 'G1':
      shipping = 74 + ((quantity-1) * 14);
      break;     
      case 'F0':
      shipping = 44 + ((quantity-1) * 8);
      break; 
      case 'G0':
      shipping = 61 + ((quantity-1) * 12);
      break;  
      case 'HK':
      shipping = 25 + Math.round((quantity-1) * (25/8));
      break;   
      default:
      shipping = 0;
                   
   }
   var total = shipping + parseInt(subtotal);
   document.getElementById('charge').value = shipping;
   document.getElementById('amount').value = total;
}
