$(function(){
    /*========================================================================================
    //----------------------------------------------------------------------------------------
    // START of the global cart functions
    //----------------------------------------------------------------------------------------
    ========================================================================================*/
    function updateCartTotal(passedCartID){
    //shows the total number of items in the cart at request
    //as well as the total dollar amount of the cart.
    //Dollar amount no longer used.
        $.ajax({
            type: "GET",
            url: "/ajax_functions/getCartTotal.asp",
            data: "cartID="+passedCartID,
            success: function(returnData){
                var totals = returnData.split(",");
                $('#CartSummary').html(' ('+totals[1]+')');
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                //not a logical error but a server error
                //i.e. 404, 500, etc.
                alert('Error:\n'+errorThrown+'\n'+textStatus+'\n'+XMLHttpRequest);
            }
        });
    }

    function CurrencyFormatted(amount){
        //formats the incoming string/number as currency
        //handles negative numbers as well as positive
        //will also add the leading 0s where needed.
        var i = parseFloat(amount);
        if(isNaN(i)){
            i = 0.00;
        }
        var minus = '';
        if(i < 0) {
            minus = '-';
        }
        i = Math.abs(i);
        i = parseInt((i + 0.005) * 100,10);
        i = i / 100;
        s = i.toString();
        if(s.indexOf('.') < 0) { s += '.00'; }
        if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
        s = '$'+ minus + s;
        return s;
    }
    /*========================================================================================
    //----------------------------------------------------------------------------------------
    // END GLOBAL CART FUNCTIONS
    //----------------------------------------------------------------------------------------
    ========================================================================================*/

    //update the cart summary if there's a cartID available.
    var cartID = getCookie('cartID');
    updateCartTotal(cartID);

    if (cartID.length==38){
        $('#ViewCartLink').attr('href','/view_cart.asp?CID='+cartID);
    }

    $('#btnEnterAddress').toggle();

    if(getCookie('cartID').length>0){
        $('#btnEnterAddress').toggle();
    }

    $('#ClearanceItems').click(function(){
        parent.location = '/view_category.asp?catID=76&mid=5&smid=52';
    });

});

