    var oActive = new Object;
    oActive.nodeName = 'none';
                 
    function tree_navigate(oLI,oAnchor) {
        
      if (oAnchor.nodeName.toLowerCase() == 'a') {

         // Mark active and set folder img to open
    
           if (oActive.nodeName.toLowerCase() == 'a') {
             oActive.removeClassName('active');    
           }
           
           // Set anchor as active and change folder image to open
    
            oActive = oAnchor;
            oActive.addClassName('active');
        
         // Set href for clicked A (if href is not set)
    /*
           strHREF = oAnchor.readAttribute('href');
           strTarget = oAnchor.readAttribute('target');
    
           if (! strHREF) { strHREF = 'http://www.webon.net'; }
           if (! strTarget) { strTarget = '_blank'; }
    
           oAnchor.writeAttribute('href',strHREF);
           oAnchor.writeAttribute('target',strTarget);
           */

        return true;
      }            
    
    }
    
    function tree_getchildren(oTree,oParams,oLI) {
    
         // Fetch childnodes and append them to LI
         
         var sURL = 'http://knutb.com/getchildren.php?id=' + oLI.id;

         new Ajax.Request(sURL,{
         
            onFailure:function(resp) {               
            },

            onSuccess:function(resp) {
                        
               if (resp.responseText == 'test1') {                
                return true;
               }
               
               var oUL = new Element('ul');

               var aChildren = resp.responseText.evalJSON();
               
               aChildren.each(
                function(oChild) {
                  var oNew = new Element('li');
                  oNew.id = oChild.nodeid;

                  if (oChild.has_children == 1) {
                    oNew.addClassName('tclosed');
                  }

                  var oAnchor = new Element('a');

                  var oName = document.createTextNode(' ' + oChild.name);

                  oAnchor.appendChild(oName);
                  oNew.appendChild(oAnchor);

                  oUL.appendChild(oNew);
                }
               );

               oLI.appendChild(oUL);
            }
                        
          } 
         );

    }

    function tree_store_expanded(oTree) {
    
        // Find ID for all expanded LIs
        
        var aExp = new Array;
        
        var sExp = oTree.select('li.topen').each(
         function(oLI) {
          if (oLI.id) {
           aExp.push(oLI.id);
          } 
         }
        );
        
        var sExp = aExp.join('¤');
        
        var sURL = 'http://knutb.com/exp.html&' + oTree.id + '_expanded=' + sExp;
                
        new Ajax.Request(sURL);      
      
    }

 function jfk_tree_click(e) {
    var treemenu = $(this);
    var oParams = arguments[1];
      
    // Find clicked element and corresponding LI

      var oElem = $(Event.element(e));

      if(oElem.readAttribute('href') != null){
        Event.stop(e);
      }

         
      var strNN = oElem.nodeName.toLowerCase(); 
    
      var oLI = $(oElem);
      
      if (strNN != 'li') { 
       oLI = oElem.up('li');
      }
      
      
      if (! oLI) { return true; }

      // If node is open and collapse is clicked, close the node
                        
      //  if (oLI.hasClassName('topen') && strNN=='li') {
          if (oLI.hasClassName('topen')) {
          
          oLI.removeClassName('topen');
          oLI.addClassName('tclosed');
      
          if (oParams.func_close) {
           eval(oParams.func_close + '(treemenu,oParams,oLI)');
          }
          
         // If url for storing expanded elements is present, use it to store expanded nodes 
          
           //if (oParams.func_exp) {
           //  eval(oParams.func_exp + '(treemenu)');         
           //}
                                         
           var aNodes = treemenu.select('.topen');
           var aExp = [];
           aNodes.each(
            function(oNode) {
              if (oNode.id != oLI.id) {
               aExp.push(oNode.id);
              } 
            }
           );
           
           var sExp = aExp.join(',');     
          if(oElem.readAttribute('href')){
             location.href = oElem.href + '&jfkmenu_exp='+sExp;
          }else{
             new Ajax.Request('/wsp/jfknudtzen/frontend.cgi?jfkmenu_exp='+sExp);
          }
          return true;
        }
      
      // If node is closed, open it 
      
        if (oLI.hasClassName('tclosed')) {
        
           // Check if we must fetch childnode info
        
           var aChildren = oLI.select('ul');
        
           if (aChildren.length < 1) { 
             if (oParams.func_getchildren) {
                eval(oParams.func_getchildren + '(treemenu,oParams,oLI)');
             } 
           }
           
          oLI.removeClassName('tclosed');
          oLI.addClassName('topen');

          if (oParams.func_open) {
           eval(oParams.func_open + '(treemenu,oParams,oLI)');
          } 
           
        } 
        
        var aNodes = treemenu.select('.topen');
        var aExp = [];
        aNodes.each(
         function(oNode) {
           aExp.push(oNode.id);
         }
        );
        
        var sExp = aExp.join(',');                  
        if(oElem.readAttribute('href')){
          location.href = oElem.href + '&jfkmenu_exp='+sExp;
        }else{
          new Ajax.Request('/wsp/jfknudtzen/frontend.cgi?jfkmenu_exp='+sExp);
        }
       // If url for storing expanded elements is present, use it to store expanded nodes 
        
         if (oParams.func_exp) {
           eval(oParams.func_exp + '(treemenu)');         
         }
                

       // If clicked element is anchor, call func_navigate

        if (strNN !='li' && oParams.func_navigate) {
                  
          eval(oParams.func_navigate + '(oLI,oElem);');
                
        }     
                       
   }

