function processShippingCharges(checkbox){
	if(checkbox.checked == 1){
		add_to_shopping_cart(1693);
	}
	else{
		 remove_from_shopping_cart(1693);
	}
}

function long_or_short_way_around() {
  return false;
}

function add_one_to_cart(productId,name) {
  if (!long_or_short_way_around()) {
    if (confirm("Add another "+name+" to your cart?")) {
      if (!add_to_shopping_cart(productId)) {
        alert('failure');  
      }
    }
  }
}

function add_to_cart(productId,name) {
  if (!long_or_short_way_around()) {  
    if (confirm("Add "+name+" to your cart?")) {
      if (!add_to_shopping_cart(productId)) {
        alert('failure');  
      }
    }
  }
}

function cart_callback(url) {
  /*
   * The data comes back in JSON format:
   * data[0] = {key: xxx, value: '<html data>'},
   * data[1] = {key: xxx, value: '<html data>'},
   * etc...
   */
  $.get(url + '?' + new Date().getTime(), {},
    success = function(data, status) {
      if ('success' == status) {
	    $(data).each(function(index, buttons) {
		  $('#shoppingCart' + buttons.key).html(buttons.value);
		});
	    update_small_cart();
	    return true;
	  }
    },
    'json'
  );
  return success;
}

function add_to_shopping_cart(productId) {
  if ($('#DiscountCode').length > 0) {
	var discount = $('#DiscountCode').val();
	if (discount != '') {
		productId = productId + '/' + discount;
	}
  }
  var success = false;
  if(productId != 1693){
    success = cart_callback('/products/add_to_cart/' + productId);
  }
  else{
	success = cart_callback('/products/add_to_cart/' + productId);
    if (false == success) {
    	update_small_cart();
    }
	$('#shoppingCartForm').load('/products/shopping_cart?'+new Date().getTime());
  }
  
  return success;
}

function remove_from_cart(productId,name) {
  if (!long_or_short_way_around()) {
    if (confirm("Completely remove "+name+" from your cart?")) {
      if (!remove_from_shopping_cart(productId)) {
        alert('failure');  
      }
    }
  }
}

function remove_one_from_cart(productId,name) {
  if (!long_or_short_way_around()) {
    if (confirm("Remove one "+name+" from your cart?")) {
      if (!remove_one_from_shopping_cart(productId)) {
        alert('failure');  
      }
    }
  }
}

function remove_from_shopping_cart(productId) {
  var success = false;
  if (productId != 1693) {
    success = cart_callback('/products/remove_from_cart/' + productId);
  }
  else{
    success = cart_callback('/products/remove_from_cart/' + productId);
    $('#international-shipping-flag').attr({'checked':''})
  }
  if (false == success) {
	  update_small_cart();
  }
  if ($('#shoppingCartForm').length > 0) {
    $('#shoppingCartForm').load('/products/shopping_cart?'+new Date().getTime());
  }
  return success;
}

function remove_one_from_shopping_cart(productId) {
  success = cart_callback('/products/remove_one_from_cart/' + productId);
  return success;
}

function update_small_cart() {
  $('#smallCart').load('/products/small_shopping_cart?'+new Date().getTime());
  if ($('#your-order-big').length > 0) {
    $('#your-order-big').load('/products/shopping_cart?'+new Date().getTime());
  }
}