// JavaScript Document

function googlecartOnCheckoutClick() {
  var items = googlecart.getItems();

  var internationalShippingShirtandBook = 0; 
  var internationalShippingPoster = 0; 
  var internationalShippingHat = 0;
  //var internationalShippingBook = 0;
  var internationalShippingButton =0;
  var internationalShippingCollection =0;

  
  var domesticShippingShirtandBook = 0; 
  var domesticShippingPoster = 0; 
  var domesticShippingHat = 0; 
  //var domesticShippingBook = 0;
  var domesticShippingButton =0;
  var domesticShippingCollection =0;

  var totalitemQuantityShirt=0;
  var totalitemQuantityPoster=0;
  var totalitemQuantityHat=0;
  var totalitemQuantityBook=0;
  var totalitemQuantityShirtandBook=0;
  var totalitemQuantityButton=0;
  var totalitemQuantityCollection=0;

  
  
 
  
  // loop over each element in the shopping cart
  for (var i = 0; i < items.length; i++) 
  {
    // test if this element is not removed
    if (!items[i].isMarkedForRemoval()) 
	{
		if(items[i].getCategory() == 'shirt')
	  		totalitemQuantityShirt+= items[i].getQuantity();
		else if(items[i].getCategory() == 'hat')
	  		totalitemQuantityHat+= items[i].getQuantity();
		else if(items[i].getCategory() == 'book')
	  		totalitemQuantityBook+= items[i].getQuantity();
		else if(items[i].getCategory() == 'poster')
			totalitemQuantityPoster+= items[i].getQuantity();
		else if(items[i].getCategory() == 'button')
			totalitemQuantityButton+= items[i].getQuantity();
		else if(items[i].getCategory() == 'collection')
			totalitemQuantityCollection+= items[i].getQuantity();
		
	}
  }

//Domestic Collection
   
  if(totalitemQuantityCollection==1) domesticShippingCollection=7;
  else if(totalitemQuantityCollection==2) domesticShippingCollection=14;
  else if(totalitemQuantityCollection==3) domesticShippingCollection=21;
  else if(totalitemQuantityCollection==4) domesticShippingCollection=28;
  else if(totalitemQuantityCollection==5) domesticShippingCollection=35;
  else if(totalitemQuantityCollection>5) domesticShippingCollection=42;

  //International Collection
   
  if(totalitemQuantityCollection==1) internationalShippingCollection=18.5;
  else if(totalitemQuantityCollection==2) internationalShippingCollection=37;
  else if(totalitemQuantityCollection==3) internationalShippingCollection=50;
  else if(totalitemQuantityCollection==4) internationalShippingCollection=50;
  else if(totalitemQuantityCollection==5) internationalShippingCollection=50;
  else if(totalitemQuantityCollection>5) internationalShippingCollection=50;

  totalitemQuantityShirtandBook=totalitemQuantityShirt + totalitemQuantityBook;
  //if(items[items.length-1].
  //alert(totalitemQuantityPoster);
 
 //Domestic Shirt
  
  
  if(totalitemQuantityShirtandBook==1) domesticShippingShirtandBook=6;
  else if(totalitemQuantityShirtandBook==2) domesticShippingShirtandBook=8;
  else if(totalitemQuantityShirtandBook==3) domesticShippingShirtandBook=9;
  else if(totalitemQuantityShirtandBook==4) domesticShippingShirtandBook=13;
  else if(totalitemQuantityShirtandBook==5) domesticShippingShirtandBook=14;
  else if(totalitemQuantityShirtandBook>5) domesticShippingShirtandBook=17;
  
  
  /*
  if(totalitemQuantityShirt==1) domesticShippingShirtandBook=6;
  else if(totalitemQuantityShirt==2) domesticShippingShirtandBook=8;
  else if(totalitemQuantityShirt==3) domesticShippingShirtandBook=9;
  else if(totalitemQuantityShirt==4) domesticShippingShirtandBook=13;
  else if(totalitemQuantityShirt==5) domesticShippingShirtandBook=14;
  else if(totalitemQuantityShirt>5) domesticShippingShirtandBook=17;*/
  
  //International Shirt
  if(totalitemQuantityShirtandBook==1) internationalShippingShirtandBook=9;
  else if(totalitemQuantityShirtandBook==2) internationalShippingShirtandBook=12;
  else if(totalitemQuantityShirtandBook>2) internationalShippingShirtandBook=16;  
  
  
  // Hat
  if(totalitemQuantityHat>0) 
  {
	  domesticShippingHat=7;
	  internationalShippingHat=15;
  }
   
   if(totalitemQuantityButton>0) 
  {
	  domesticShippingButton=1;
	  internationalShippingButton=1;
  }
  
  // Button
  
  
  // Book
  /*
  if(totalitemQuantityBook>0) 
  {
	  domesticShippingBook=9;
	  internationalShippingBook=12;
  }*/
  
  // Poster
  if(totalitemQuantityPoster>0) 
  {
	  domesticShippingPoster=5;
	  internationalShippingPoster=8;
  }
  
  internationalShipping= internationalShippingPoster + internationalShippingShirtandBook + internationalShippingHat +internationalShippingCollection +internationalShippingButton ;
  domesticShipping = domesticShippingShirtandBook  + domesticShippingPoster + domesticShippingHat + domesticShippingButton +domesticShippingCollection;
  

  // update the price of international shipping 
  // (specified as <input id='international-shipping' in the <form> below)
  document.getElementById('international-shipping').value =
      internationalShipping;
  document.getElementById('domestic-shipping').value =
      domesticShipping;

  // continue with checkout process
  return true;
}
