shopping_cart = {

    /*
     * Other functions
     */
    set_all_lines_check_state : function (check_state) {
      $$('#shopping_cart td.remove_checkbox input').each(function(input) {
          input.checked = check_state;
      });
    },
     

    /*
     * EVENT_HANDLERS
     */
    event_handlers : {
        remove_selected_click : function(ev) {
            Event.stop(ev);
            if(confirm(js_messages.confirm_remove_selected)) {
                $('form_operation').value = 'remove_selected';
                this.up('form').submit();
            }
        },
        
        select_all_click : function(ev) {
            Event.stop(ev);
            shopping_cart.set_all_lines_check_state(true);
        },
        
        select_none_click : function(ev) {
            Event.stop(ev);
            shopping_cart.set_all_lines_check_state(false);            
        }
    },

    /*
     * BEHAVIOURS
     */
    behaviours : {

       '.shopping_cart_selection' : function(div) {
            // Get the anchors
            var anchors = div.getElementsByTagName('a');
            // We known the order, so selection is easy!!
            var select_all_link = anchors[0];
            var select_none_link = anchors[1];
            
            // Set the event handlers
            Event.observe(select_all_link, 'click', shopping_cart.event_handlers.select_all_click.bindAsEventListener(select_all_link));
            Event.observe(select_none_link, 'click', shopping_cart.event_handlers.select_none_click.bindAsEventListener(select_none_link));
            
            // Show the div (no javascrtipt people with css support do not view them)
            Element.show(div);
       },
       
       '.remove_items' : function(a) {
           Event.observe(a, 'click', shopping_cart.event_handlers.remove_selected_click.bindAsEventListener(a));
       }
       
    }
};


// Register common rules
Behaviour.register(shopping_cart.behaviours);