﻿//prompts the user to ensure they want to clear the entire cart contents.
function confirmClearCart() {
  if (confirm("Are you sure you want to clear your cart?")) {
    clearCart();    
  }
}

//Changes the total price when rate drop-down is selected.
function updateTotal(cartTotal) {
    var OldShippingFee = new String();
    OldShippingFee = document.cartform.shippingrates.options[document.cartform.shippingrates.selectedIndex].value;
    var NewShippingFee = OldShippingFee.replace(currencyPrefix, "");
    var ShippingFee = parseFloat(NewShippingFee)
	
	cartTotal = parseFloat(cartTotal) 
	if (ShippingFee != 0){
	var aTotal= (ShippingFee) + (cartTotal);
	var newTotal= aTotal.toFixed(2);
	document.getElementById('CartTotalHolder').innerHTML = "<strong>" + currencyPrefix + newTotal + "</strong>";
	document.getElementById('excludingfees').innerHTML = "(excluding taxes)";
}

else {
    document.getElementById('CartTotalHolder').innerHTML = "<strong>" + currencyPrefix + cartTotal.toFixed(2) + "</strong>";
	document.getElementById('excludingfees').innerHTML = "(excluding taxes & shipping)";
    }
}

//Removes a specified item from a cart.
function deleteCartItem(itemID){
	document.getElementById('cartitemid').value= itemID ;
	document.getElementById('actiontype').value='delete';
	document.cartform.submit();
}

//Cleares the entire shopping cart
function clearCart(){
	document.getElementById('cartitemid').value='all';
	document.getElementById('actiontype').value='clearall';
	document.cartform.submit();
}

//Update the all of the quantities in the cart
function updateCart(){
	document.getElementById('cartitemid').value='all';
	document.getElementById('actiontype').value='updateall';
	document.cartform.submit();
}

//generates calculated shipping rates specified in DestZip form
function getShippingRates(){
	document.getElementById('actiontype').value='getshippingrates';
	document.cartform.submit();
}

//Post the cart to Google Checkout
function postCartToGoogle(){
    document.getElementById('actiontype').value='gccheckout';
    document.cartform.submit();
}

//Post the cart with normal checkout
function checkout() {
    document.getElementById('actiontype').value = 'checkout';
    document.cartform.submit();
}
