        var ajaxRequest = null;
        var ajaxRequestURL = "/TradePoint/Ajax/ItemMenu?actionType=loadNodes";
        var count = 0;
        var tree_categoriesToExpand = new Array();
        var tree_selectedCategoryNo = 0;
        var tree_selectedId;
        var tree_activeCatalogNo = "";
        
    /*    =========================================================
        leafClick()
        Triggered when a leaf in the tree is clicked.
        Expands and collapses a branch.
        Calls the server via Ajax to load the sub nodes. If they already are
        loaded they will be displayed and no server request made.
        =========================================================  */
        
        // GAC RBE 20080808 : added the 'brand' parameter
        function leafClick(categoryHrefEl, categoryNo, className, forceOpen, brand)
        {
            // get the parent element (LI)
            if(!categoryNo && categoryNo != 0)
            {
                var li = categoryHrefEl.parentNode;
                categoryNo = String(li.id).substr(4);
            }
            else
            {
                var li = document.getElementById('cat_'+categoryNo);
            }
            
            if(!li)
                return;
            

            // no sub cats means do not expand
            if(li.className.indexOf('tm_bullet')!= -1)
                return;
            
            // check if the node has been expanded
            if(li.className.indexOf('tm_opened')!= -1 && !forceOpen)
            {
                // update the LI
                li.className = 'tm_closed';
                
                // possibly expand another node
                tree_expandNextInQueue();
                
                // possibly update the selected node
                tree_refreshSelectedNode();
                return;
            }
            
            // if the subnodes are collapsed, they might still be loaded
            if(li.getAttribute('loaded') == 'yes')
            {
                // get the sub nodes container
                li.className = 'tm_opened';
                
                // possibly expand another node
                tree_expandNextInQueue();
                
                // possibly update the selected node
                tree_refreshSelectedNode();
                return;
            }
            
            // Possibly add an UL with temporary content
            var placeHolder = '<li><img src="/systemimages/pieSlicesSmall.gif" /></li>';
            var ul = document.getElementById('branch_'+categoryNo);
            if(ul)
                ul.innerHTML = placeHolder;
            else
                li.innerHTML += '<ul id="branch_'+categoryNo+'" class="'+className+'">'+placeHolder+'</ul>';
            
            // Send the AJAX request
            var url = ajaxRequestURL + "&parentCategoryNo=" + categoryNo + "&catalogNo=" + tree_activeCatalogNo;
            if ((brand != null) && (brand != undefined))
            {
                url += "&brand=" + brand;
            }
            
            ajaxRequest = Ajax.getTransport();
            if( ajaxRequest )
            {   
                ajaxRequest.open( "GET", url, true );
                ajaxRequest.onreadystatechange = expandTreeBranch;
                ajaxRequest.send( "" );
            }
            else
                alert('No AJAX transport found!');
        }
        
    /*    =========================================================
        expandTreeBranch()
        Triggered when an Ajax tree request returns.
        replaces the temporary placeholder with a UL listing of tree nodes.
        =========================================================  */
        function expandTreeBranch()
        {
            // only if ajaxRequest shows "loaded"
            if( ajaxRequest.readyState == 4 )
            { 
            
                // only if "OK"
                if( ajaxRequest.status == 200 )
                {
                    // get the returned result
                    var LINodes = ajaxRequest.responseText;
                    
                    // extract the id of the UL to populate
                    var separator = LINodes.indexOf('$');       
                    var parentCategoryNo = LINodes.substr(0,separator);
                    
                    // populate the UL with LI nodes
                    var UL = document.getElementById('branch_'+parentCategoryNo);
                    UL.innerHTML = LINodes.substr(separator+1);
                    
                    // update the parent node (LI)
                    var parentNode = document.getElementById('cat_'+parentCategoryNo);
                    parentNode.setAttribute('loaded', 'yes');
                    parentNode.className = 'tm_opened';

                    
                    // possibly update the selected node
                    tree_refreshSelectedNode();
                                        
                    // possibly expand another node
                    tree_expandNextInQueue();

                }
                else
                {
                    showAjaxError(ajaxRequest);
                    okToGo = false;
                }
            }
        }
        
    /*    =========================================================
        tree_setSelectedNode()
        stores the category number which should be marked as selected
        =========================================================  */
        function tree_setSelectedNode(categoryNo)
        {
            tree_selectedCategoryNo = categoryNo;
        }
        
    /*    =========================================================
        tree_setActiveCatalogNo()
        if the passed catalog number differs from the active catalog number
        the tree will be cleansed
        =========================================================  */
        function tree_setActiveCatalogNo(catalogNo)
        {
            if(tree_activeCatalogNo != catalogNo)
            {
                tree_activeCatalogNo = catalogNo;
            }
        }
        
    /*    =========================================================
        tree_selectNode()
        verifies and updates the class names of the selected node to ensure
        the right node is marked as selected
        =========================================================  */
        function tree_refreshSelectedNode()
        {
            var selectedLI = document.getElementById(tree_selectedId);
            
            if(!selectedLI && (tree_selectedCategoryNo || tree_selectedCategoryNo!=0))
                selectedLI = document.getElementById('cat_'+tree_selectedCategoryNo);
            
            if(!selectedLI)
                return;
            
            // if the node marked as selected is wrong
            if(selectedLI.id.substr(4) != tree_selectedCategoryNo)
            {
                // remove the tm_selected class from the currently selected node
                selectedLI.className.replace('tm_selected', '');
            }
            else
            {
                // ensure that the selected node has the tm_selected class applied
                if(selectedLI.className.indexOf('tm_selected') == -1 )
                {
                    // apply the tm_selected class to the correct LI
                    selectedLI.className += " tm_selected";
                }
                
                // update the selected id
                tree_selectedId = selectedLI.id;
            }
        }
        
    /*    =========================================================
        tree_setNodeExpansionQueue()
        Stores an array of nodes to open progressively.
        =========================================================  */
        function tree_setNodeExpansionQueue(categoryNos)
        {
            tree_categoriesToExpand = categoryNos;
        }
        function tree_appendToNodeExpansionQueue(categoryNos)
        {
            tree_categoriesToExpand = tree_categoriesToExpand.concat( categoryNos );
            
        }
        
    /*    =========================================================
        tree_expandNextInQueue()
        pos the last category in queue and expands it
        =========================================================  */
        function tree_expandNextInQueue()
        {
            if(tree_categoriesToExpand.length < 1)
                return false;
            
            // get and remove the first category number
            var catNo = tree_categoriesToExpand.shift();
            
            // Expand ithe category
            leafClick(null, catNo, '', true);
        }
        
    /*    =========================================================
        showAjaxError()
        Opens a new window and loads the error page caused by the Ajax
        server side code.
        =========================================================  */
        function showAjaxError(ajaxRequest)
        {
            var newWindow = window.open('','','location=no, menubar=no, toolbar=no, status=no');
            var oNewDoc = newWindow.document.open("text/html", "replace");
            var sMarkup = "<html><head><title>AJAX Response</title></head><body>"+ajaxRequest.responseText+"</body></html>";
            oNewDoc.write(sMarkup);
            oNewDoc.close();
        }
        
        
        
