brand.checkout = brand.checkout || {};

brand.checkout = {
    abort: false,
    
    /* MERGE NOTE: needed?
    isCartView: false,  
    hasErrors : false,
    
    canContinueCheckout: function(state) {
        console.log("brand.checkout.canContinueCheckout: " + state);
        var style = state ? "visibility:visible" : "visibility:hidden";
        $$(".btn-checkout").invoke("setStyle", style); 
    },     
     
    makeAdditionalInfoBtns: function() {  
        //console.log("brand.checkout.makeAdditionalInfo Btns");
        // popups
        var popargs = {
            w: 480,
            h: 660,
            resizable: "no",
            scrollbar: "yes"
        }   
        var popup_shipping = new generic.popup({        
            activator: "btn_popup_shipping",
            url: "/cms/checkout/popup/shipping_popup.tmpl", 
            resizable: popargs.resizable,
            scrollbars: popargs.scrollbars,
            width: popargs.w,
            height: popargs.h       
        });    
        var popup_tax = new generic.popup({     
            activator: "btn_popup_tax",
            url: "/cms/checkout/popup/tax_popup.tmpl",  
            resizable: popargs.resizable,
            scrollbars: popargs.scrollbars,
            width: popargs.w,
            height: 200   
        });
        var popup_returns = new generic.popup({ 
            activator: "btn_popup_returns",
            url: "/cms/checkout/popup/return_popup.tmpl",  
            resizable: popargs.resizable,
            scrollbars: popargs.scrollbars,
            width: popargs.w,
            height: 500   
        });     
        var popup_security = new generic.popup({    
            activator: "btn_popup_security",
            url: "/cms/checkout/popup/security_popup.tmpl", 
            resizable: popargs.resizable,
            scrollbars: popargs.scrollbars,
            width: popargs.w,
            height: popargs.h   
        }); 
    },
    */

    makeExitBtn: function() {
        //console.log("btn_exit_checkout");
        // exit checkout button: sends user to last page before entering checkout
        var btn_exit_checkout = $("btn_exit_checkout");

        if (btn_exit_checkout) {
            btn_exit_checkout.observe("click", function() {
                var loc = "/"; // home page default
                var ref = document.referrer;
                // redirect to home if coming from account section
                // have a feeling there will be more of these...
                if (ref && (ref.indexOf(".maccosmetics")>-1) && (ref.indexOf("checkout")==-1) && !(/account/g.test(ref)) && !(/macpro/g.test(ref)) ) {
                    loc = ref;
                }
                window.location = loc;
            });
        }
    }
  
};

        
brand.checkout.cartStatus = {  
    countNodeId: "global_cart_count",
    countContainerId: "shopping_bag_items", 
    
    init: function() {
        //console.log("brand.checkout.cartStatus.init");
        this.countNode = $(this.countNodeId); 
        var self = this;
          
        generic.events.observe("cart:countsUpdated", function(args) { 
            self.updateCount();
        });
          
        var countContainer = $(this.countContainerId);
        if (countContainer) {
            countContainer.removeClassName("hidden");
        } 
         
    }, 
    updateCount: function() {
        //console.log("brand.checkout.cartStatus.updateCount");
        if (this.countNode) { 
            this.countNode.innerHTML = generic.checkout.cart.getTotalItems();
        }
    }
}

