
function cartRemoveItem(id) {
    loading();
    $.post(baseUrl + '/action/removeCartItem/', { cartitem: id },
    function(data){
        $('#cart-item_' + id).fadeOut("slow", function(){ $('#cart-item_' + id).remove(); updateCart(data); });
                          
    }, "json");
  
    return false;
}
	
function cartChangeQuantity(id, quantity) {
    loading();
    $.post(baseUrl + '/action/updateCartItemQuantity/', { cartitem: id, quantity: quantity }, updateCart, "json");
    return false;
}
	
function cartChangeType(id, type) {
    loading();
	$(".removeCoupon").trigger('click');
    $.post(baseUrl + '/action/updateCartItemType/', { cartitem: id, type: type }, updateCart, "json");
    return false;
}
	
function getUpdates(id) {
    loading();
    $.post(baseUrl + '/action/getUpdates/', { cart: id }, updateCart, "json");
    return false;
}

function cartChangeShipping(id, type) {
    loading();
    $.post(baseUrl + '/action/updateShippingType/', {  cart: id, type: type }, updateCart, "json");
    return false;
}
        
function updateCart(data)
{
    
    $('#loader').hide();
    $('.cart-subtotal h2').css('opacity','1');
        
    if(data.subtotal != undefined)
        $('.subtotal').html(data.subtotal);
          
    if(data.shipping != undefined)
        $('.shipping').html(data.shipping);
          
    if(data.total != undefined)
        $('.total').html(data.total);
          
    $('.discounts').html(data.discounts);
            
    if(data.discounts > 0)
        $('#discountSpan').css('display', 'block');
    else
        $('#discountSpan').hide();
          
    
    if(! data.coupons || data.coupons.length == 0)
    {
        $('#coupons_desc').html("").css("display", "none");
        $('#coupons_value').html("").css("display", "none");
    }
    else
    {  
        var couponsDesc = "";
        var couponsVal  = "";
                    
        $.each(data.coupons, function()
        {
            couponsDesc += "<b>" + this.name + "</b> (" + this.value_desc + " off " + this.parent + ") <a href=\"#"+this.id+"\" class=\"removeCoupon\">remove</a><br />";
            couponsVal += "-$" + this.value + "<br />";
        });

        $('#coupons_desc').html(couponsDesc).css("display", "block");
        $('#coupons_value').html(couponsVal).css("display", "block");
        $('.removeCoupon').click(removeCoupon);
    }
    
    if(data.items)
    {
      $.each(data.items, function()
      {
          if(this.total != undefined)
              $('#cart-item_' + this.id + ' .gtotal').text(this.total);

          if(this.subtotal != undefined)
              $('#cart-item_' + this.id + ' .gsubtotal').text(this.subtotal);

          if(this.quantity != undefined)
              $('#cart-item_' + this.id + '_quantity').val(this.quantity);

          if(this.printed != undefined)
          {
              if(this.printed == 'true')
                  $('#cart-item_' + this.id + ' img').attr('src', site_url('i/guides/med-icon.png'));
              else
                  $('#cart-item_' + this.id + ' img').attr('src', site_url('i/ui/pdf.png'));
          }

      });
    }
                
    if($('.cart-guide').length == 0)
    {
        $('.hide').hide();
        $('.empty').fadeIn();
    }

    if($('#shipping').val() == 'CCINT' || $('#shipping').val() == 'USPSREG') {
        $('#shippingTrackable').show();
    }
    else
    {
        $('#shippingTrackable').hide();
    }
  
    if($('#content-area option:selected[data-printed=1]').length > 0)
    {
        $('#shipping').show();
        $('#shipping_none').hide();
    }
    else
    {
        $('#shipping, #shippingTrackable').hide();
        $('#shipping_none').show();
    }
            
    return false;
            
}