      var forumMenu = new Ext.menu.Menu({
                                        items: [
                                                  {
                                                    id: 'mnu_item-edit_forumitem',
                                                    iconCls: 'cpi_userSettings',
                                                    text: 'Properties'
                                                  },{
                                                    id: 'mnu_item-edit_forumdelete',
                                                    iconCls: 'file-permdelete-icon',
                                                    text: 'Delete Item'
                                                  }
                                                ],
                                        listeners: {
                                          itemclick: function(item) {
                                            var n = item.parentMenu.contextNode;
                                            switch (item.id) {
                                              case 'mnu_item-edit_forumitem':
                                                if (n.parentNode) {
                                                  setTimeout(function(){
                                                    callEditor({navigationContextNode: n, editorDataID: n.attributes.id, editorType: 'Forum', editorModal: true});
                                                  }, 100);
                                                }
                                                break;
                                              case 'mnu_item-edit_forumdelete':
                                                msgTitle = 'Delete Main Forum Category?';
                                                msgStr = 'You are about to delete a forum. This will also remove all sub-topics and posts. Are you sure you want to do this?';
                                                if (n.parentNode) {
                                                  Ext.Msg.show({
                                                    title: msgTitle,
                                                    msg: msgStr,
                                                    buttons: Ext.Msg.YESNO,
                                                    fn: function(btn){
                                                      if (btn == 'yes'){
                                                        n.attributes.deleted=true;
                                                        n.getUI().hide();
                                                      }
                                                    },
                                                    icon: Ext.MessageBox.QUESTION
                                                  });
                                                }
                                                break;
                                            }
                                          }
                                        }
                                      });
      function windowForumEditor(initOptions){
        var _self = this;
        this._settings = {};
        Ext.apply(this._settings, initOptions);
        var loadMode = this._settings.loadMode;
        
        var loading = 2;
        
        if (!canEdit)
          return false;

        this.tree2 = new Ext.tree.TreePanel({
              id : 'mainForumList_adder',
              useArrows:true,
              autoScroll:true,
              animate:true,
              height:200,
              region: 'center',
              enableDD:true,
              //tbar: [{text: 'Add'},{text: 'Rename'},{text: 'Delete'}],
              containerScroll: true,
              rootVisible: false,
              root: { nodeType: 'async', allowDrop: false},
              dataUrl : '/ajax/siteconfig/moduleList.cfm?mode=forum',
              listeners: {
                load: function(node){
                  loading--;
                  if (loading < 1)
                    Ext.Msg.hide();
                },
                checkchange: function(node, checked){
                  if(checked){
                    node.getUI().addClass('complete');
                  }else{
                    node.getUI().removeClass('complete');
                  }
                }
              }
          });

        this.tree = new Ext.tree.TreePanel({
              useArrows:true,
              id : 'mainForumList',
              autoScroll:true,
              animate:true,
              region: 'center',
              enableDD:true,
              containerScroll: true,
              rootVisible: false,
              root: { nodeType: 'async'},
              dataUrl : '/ajax/siteconfig/forum/forumNodes.cfm',
              //contextMenu: gcdMenu,
              listeners: {
                load: function(node){
                  loading--;
                  if (loading < 1)
                    Ext.Msg.hide();
                },
                beforenodedrop: function(e){
                  if (e.source.tree.id!=e.tree.id){
                    var newEl = e.dropNode.clone();
                    newEl.leaf=false;
                    newEl.getUI().toggleCheck(true);                    
                    e.dropNode = newEl;
                    if (newEl.attributes.data_type=='header'){
                      setTimeout(function(){
                        callEditor({navigationContextNode: newEl, editorDataID: 0, editorType: 'Forum', editorModal: true});
                      }, 100);
                    }else if (newEl.attributes.data_type=='category'){
                      setTimeout(function(){
                        callEditor({navigationContextNode: newEl, editorDataID: 0, editorType: 'Forum', editorModal: true});
                      }, 100);
                    }
                  }
                },
                contextmenu: function(node, e) {
                  node.select();
                  var c = forumMenu;
                  c.contextNode = node;
                  c.showAt(e.getXY());
                },
                checkchange: function(node, checked){
                  if(checked){
                    node.getUI().addClass('complete');
                  }else{
                    node.getUI().removeClass('complete');
                  }
                }
              }
          });
        var treeLeft = new Ext.Panel({
          border: false,
          region: 'center',
          margins:'0 0 0 0',
          layout: 'border',
          items: [
            {
              region: 'north', 
              margins:'0 0 -1 0',
              baseCls: 'siteConfigHeaderTab',
              cmargins:'3 3 3 3', 
              border: true, 
              html: '<strong>Current Forum Configuration</strong>'
            },this.tree]
        });
        var treeRight = new Ext.Panel({
          border: false,
          region: 'east',
          layout: 'border',
          margins:'0 0 0 5',
          cmargins:'3 3 3 3',
          width: 230,
          items: [
            {
              region: 'north', 
              margins:'0 0 -1 0',
              baseCls: 'siteConfigHeaderTab',
              cmargins:'3 3 3 3', 
              border: true, 
              html: '<strong>Available Options</strong>'
            },{
              region: 'south', 
              margins:'10 10 10 10',
              cmargins:'3 3 3 3',
              baseCls: 'x-plain', 
              border: true, 
              html: '<strong>Drag & Drop above options</strong> to create and activate them.'
            },this.tree2]
        });
        var navInfo = 'Changes will be applied when you click \'Save\' below.';
        this.treeHolder = new Ext.Panel({
          border: false,          
          layout: 'fit',
          bodyStyle: 'background: #DFE8F6',
          id: 'tabForumEditor',
          items: new Ext.Panel({
              border: false,     
              ref : 'borderLayout', 
              layout: 'border',
              items: [
                {
                  region: 'south',
                  collapsible: true,
                  margins:'5 0 0 0',
                  cmargins: '5 0 0 0',
                  title: 'Help',
                  collapsed: true,
                  border: true, 
                  html: '<div class="siteConfigInfo"><div class="siteConfigHeader">Organize your Forum Categories and Topics list here.</div><div class="siteConfigText">'+navInfo+'</div></div>'
                },
                treeLeft,
                treeRight]
            })
        });

        this.winForumEdit = new Ext.Window({
              minWidth:600,
              minHeight:400,
              width:600,
              height:500,
              constrainHeader:true,
              title: 'Forum Manager',
              iconCls: 'cpi_forumManager',
              layout:'fit',
              tools:[{
                id:'help',
                handler: function(event, toolEl, panel){
                  //alert(_self.treeHolder.borderLayout.layout.south.panel.toSource());
                  _self.treeHolder.borderLayout.layout.south.panel.toggleCollapse(true);
                }
              }],
              closeAction:'close',
              modal:true,
              closable:true,
              border:true,
              resizable: false,
              defaults: {autoScroll:true, padding: 5},
              items: this.treeHolder,
              bodyStyle: 'background: #ddd;',
              listeners: {
                render: function(){
                  Ext.Msg.wait('Loading Forum Items...', 'Please wait');
                }
              },
              buttons: [{
                text: 'Save',
                handler: function(){
                  var tmpSerial = new Ext.tree.JsonTreeSerializer(_self.tree, { nodeFilter: function(node) {
                      //node.attributes.linkURL = encodeURIComponent(decodeURI(decodeURI(decodeURI(decodeURI(decodeURI(node.attributes.linkURL))))));
                      return true;
                    }});
                  Ext.Msg.wait('Saving your forum configuration. This may take a few seconds.', 'Please wait...');
                  Ext.Ajax.request({
                    url: '/ajax/siteconfig/forum/updateForum.cfm',
                    method: 'POST',
                    params: { forumData : Base64.encode(tmpSerial.toString())},
                    reader : new Ext.data.JsonReader({
                    success : '@success'
                    }),
                    success: function(response, opts) {
                      Ext.Msg.hide();
                      //_self._settings.sc.triggerReload();
                      _self.winForumEdit.close();
                      window.location.reload(true);
                    },
                    failure: function(response, opts) {
                      Ext.Msg.alert('Whoops!', 'There was an error saving the Forum Configuration.');
                    }
                  });
                }
              },{ text: 'Cancel', handler: function(){ _self.winForumEdit.close(); } }]
          });
        this.winForumEdit.show(this);

      }
      
reportingIn('forumTab');

