function editPortalInformation(initOptions){
    if(!canEdit){
      userLogin();
      catWin.close();
    }
    var windowHeight = 180;

    var _self = this;
    var _settings = {};
    _settings.portalID = 0;
    _settings.updateTreeNode = false;
    _settings.updateStore = false;
    _settings.treeNode = {};
        
    Ext.apply(_settings, initOptions);
    //alert(_settings.data.toSource());
    
    if (initOptions.refreshStore)
      _settings.updateStore = true;
      
    if (initOptions.treeNode)
      _settings.updateTreeNode = true;

    function saveCategory(){
      PhotoInfoPanel.getForm().submit({
        clientValidation: true,
        url:'/ajax/portals/updatePortal.cfm', 
        waitMsg:'Saving Information, Please Wait...',
        params: {
          ID: _settings.data.xtypeID,
          gcdID: _settings.gcdID
        },
        errorReader : new Ext.data.JsonReader({
          successProperty:'success'
        }),
        success: function(form, action) {
            _settings.portalID = action.result.portalID;
            if (_settings.updateTreeNode){
              _settings.treeNode.attributes.xtypeID = _settings.portalID;
            }
            catWin.close();
            return true;

        },
        failure: function(form, action) {                
          _settings.portalID = action.result.portalID;
          _settings.treeNode.attributes.xtypeID = _settings.portalID;
          
          if ((action.result.portalID > 0 && action.result.urlID == 0) || (action.result.portalID > 0 && action.result.urlID > 0)){
            urlField.markInvalid('The URL is already taken');
            Ext.Msg.alert('URL in use!', 'The URL Title specified is already used. Please specify a different title.');
            return false;
          }
          switch (action.failureType) {
              case Ext.form.Action.CLIENT_INVALID:
                  Ext.Msg.alert('Failure', 'Please verify fields are correct.');
                  break;
              case Ext.form.Action.CONNECT_FAILURE:
                  Ext.Msg.alert('Failure', 'Ajax communication failed');
                  break;
              case Ext.form.Action.SERVER_INVALID:
              default:
                  Ext.Msg.alert('Failure', action.result.msg);
          }
        }
      });
    }

    var titleField = new Ext.form.TextField({
      fieldLabel: 'Portal Title', 
      ref: '../../title', 
      anchor:'100%', 
      name: 'title', 
      maxLength:50, 
      maxLengthText: 'Your Title Exceeds 100 Characters'
    });
    var urlField = new Ext.form.TextField({
      fieldLabel: 'URL Title', 
      ref: '../../url', 
      anchor:'100%', 
      name: 'url', 
      maxLength:50, 
      maxLengthText: 'Your URL Exceeds 50 Characters'
    });
    var displayField = new Ext.form.DisplayField({
      anchor:'100%', 
      html: 'Please specify a unique URL Title.<br /><br />A blank URL Title is permitted and suggested for use as the home page.'
    });

    var xmlCols = [];
    xmlCols.push({name: 'title', mapping: 'title'});
    xmlCols.push({name: 'url', mapping: 'url'});


  var PhotoInfoPanel = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        //frame:true,
        border: true,        
        padding: 10,
        reader : new Ext.data.XmlReader({
                          record : 'result',
                          success : '@success'
                      }, xmlCols),
        defaults: {width: 230},
        defaultType: 'textfield',
        items: [titleField, urlField, displayField],
        listeners:{
          render:function(el){
            el.getForm().load({url:'/ajax/portals/getPortalData.cfm?id='+_settings.data.xtypeID, waitMsg:'Loading Data....'});
          }
        }        
    });
    
    TitleBar = 'New Portal';
    if(_settings.data.xtypeID > 0)
      TitleBar = 'Edit Portal';
      
    var catWin = new Ext.Window({
          id: 'portalPanel_win_' + _settings.photoID,
          title: TitleBar,
          width:390,
          minWidth: 390,
          modal: _settings.updateTreeNode,
          height:210,
          padding: 5,
          border: true,
          layout:'fit',
          closable: true,
          closeAction:'close',
          resizable: false,
          items: PhotoInfoPanel,
          buttons: [{
                      text: 'Save',
                      handler: function(){ saveCategory();}
                  },{
                      text: 'Cancel',
                      handler: function(){ catWin.close() }
                  }]
      });
      catWin.show(this);
};


  var currentModuleMode = 'page';
  var currentModuleDataID = 0;
  var currentModuleDataTitle = '';
  var currentModuleDataAuthor = '';
  var currentModuleToAdd;
  var currentPortalToAddTo;
  var navHandler = function(editor, incr){
    var l = Ext.getCmp('add_new_module_wizard_panel').getLayout();
    var i = l.activeItem.id.split('card-')[1];
    var i2 = i.split('-');
    if (i2[0] >= 3 && incr == 1){
      switch(currentModuleMode){
        case 'page':
          Ext.Msg.wait('Please Wait...', 'Creating New Portal');
          Ext.Ajax.request({
             url: '/ajax/portals/createPortalPage.cfm',
             method: 'GET',
             params : { wID: currentPortalToAddTo, s: currentSchool.id, pageID: currentModuleDataID},
             reader : new Ext.data.JsonReader({
              success : '@success'
             }),
             success: function(response, opts) {
                var obj = Ext.decode(response.responseText);
                if (obj.success){
                  Ext.getCmp('add_new_module_wizard').close();
                  Ext.Msg.hide();
                  Ext.Msg.wait('Added! Reloading Portal...', 'Creating New Page');
                  //this._module.sc.triggerReload();
                  document.location.reload(true);
                }else{
                  Ext.Msg.hide();
                  Ext.Msg.alert('Error Creating Widget', 'There was an error creating the specified widget. Please try again.');
                }
             },
             failure: function(response, opts) {
              Ext.Msg.hide();
              Ext.Msg.alert('Error Creating Widget', 'There was a problem communicating with the server. Please check your internet connection and try again.');
             }
          });   

          break;
        case 'module':
          Ext.Msg.wait('Please Wait...', 'Creating New Portal');
          Ext.Ajax.request({
             url: '/ajax/portals/createPortal.cfm',
             method: 'GET',
             'params': { maID: currentModuleToAdd.data.alias, s: currentSchool.id, wID: currentPortalToAddTo},
             reader : new Ext.data.JsonReader({
              success : '@success'
             }),
             success: function(response, opts) {
                var obj = Ext.decode(response.responseText);
                if (obj.success){
                  Ext.getCmp('add_new_module_wizard').close();
                  Ext.Msg.hide();
                  Ext.Msg.wait('Added! Reloading Portal...', 'Creating New Widget');
                  //this._module.sc.triggerReload();
                  document.location.reload(true);
                }else{
                  Ext.Msg.hide();
                  Ext.Msg.alert('Error Creating Widget', 'There was an error creating the specified widget. Please try again.');
                }
             },
             failure: function(response, opts) {
              Ext.Msg.hide();
              Ext.Msg.alert('Error Creating Widget', 'There was a problem communicating with the server. Please check your internet connection and try again.');
             }
          });   
          break;
      }
      return false;
    }
    var next = parseInt(i2[0]) + incr;
    var nextn = next;
    if ((incr==1 && i2[0]==1) || (incr==-1 && i2[0]==3)){
      nextn = 2;
      switch(Ext.getCmp('add_new_module_wizard_form_main').getForm().getValues().newWidgetType){
        case 'feed':
          next = 'card-2-rss';
          break;
        case 'social':
          next = 'card-2-social';
          break;
        case 'page':
          next = 'card-2-page';
          break;
        case 'module':
          if (incr==1){
            next = 'card-3-final';
            nextn = 3;
          }else{
            next = 'card-1';
            nextn = 1;
          }
          break;
      }
    }
    if (incr==-1 && i2[0]==2){
      next = 1
      nextn = 1;
    }else if(incr==1 && i2[0]==2){
      next = 'card-3-final';
      nextn = 3;
    }
    l.setActiveItem(next);
    Ext.getCmp('card-prev').setDisabled(nextn==0);
    Ext.getCmp('card-next').setText(nextn==3 ? 'Finish' : 'Next &raquo;');
    
  };
  
  var windowAddWidget = function(modSettings){
    this._module = modSettings;
    currentPortalToAddTo = this._module.wID;
    var _self = this;    
		
		var _settings = {};
		_settings.gcdID = 0;
        
    Ext.apply(_settings, modSettings);
    var winAddWidget = new Ext.Window({
          id: 'add_new_module_wizard',
          iconCls: 'cpi_homeWidgets',
          stateful: false,
          width:550,
          height:400,
          title: 'Add Widget',
          closeAction:'close',
          resizable: false,
          modal:true,
          closable:true,
          buttons: [{
              id: 'card-prev',
              handler: navHandler.createDelegate(this, [this, -1]),
              disabled: true,
              text: '&laquo; Previous'
          },{
              id: 'card-next',
              handler: navHandler.createDelegate(this, [this, 1]),
              text: 'Next &raquo;'
          }],
          layout: 'border',
          items: [
                    new Ext.Panel({
                      region: 'west',
                      width: 165,
                      border: false,
                      bodyStyle: 'background: #99BBE8 url(/common/images/wizard/wizard_logo.jpg) bottom center no-repeat;',
                      html: '<div style="float: right; margin: 15px; height: 61px; width: 61px; background: url(/common/images/wizard/wizard_new.jpg);"></div>'
                    }),
                    new Ext.Panel({
                      id: 'add_new_module_wizard_panel',
                      region: 'center',
                      layout:'card',
                      activeItem: 0,
                      border: false,
                      items: [{
                                id: 'card-0',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                  {
                                    region: 'north',
                                    html: '<h3 class="wizardTitle">Welcome to the New Widget Wizard!</h3><p class="wizardDescription">This is the first step towards adding a new widget to your page. Click Next when you are ready to begin.</p>'
                                  },                                  
                                  {
                                    region: 'center',
                                    html: ' '
                                  }                                
                                ]
                              },{
                                id: 'card-1',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                        {
                                          region: 'north',
                                          html: '<h3 class="wizardTitle">Choose a Widget Type</h3><p class="wizardDescription">What kind of widget would you like to create?</p>'
                                        },                                  
                                        new Ext.FormPanel({
                                                id: 'add_new_module_wizard_form_main',
                                                region: 'center',
                                                labelAlign: 'right',
                                                waitMsgTarget: true,
                                                items: [
                                                          new Ext.form.FieldSet({
                                                              title: 'New Portal Widget',
                                                              autoHeight: true,
                                                              defaultType: 'textfield',
                                                              items: [{
                                                                        xtype: 'radiogroup',
                                                                        fieldLabel: 'Module Type',
                                                                        hideLabel: true,
                                                                        itemCls: 'x-check-group-alt',
                                                                        name: 'newWidgetType',
                                                                        columns: 1,
                                                                        items: [
                                                                            //{boxLabel: 'RSS Feed', name: 'newWidgetType', inputValue: 'feed', checked: true},
                                                                            //{boxLabel: 'Social Networking', name: 'newWidgetType', inputValue: 'social'},
                                                                            {boxLabel: 'Content Page', name: 'newWidgetType', inputValue: 'page', checked: true},
                                                                            {boxLabel: 'Select Module:', name: 'newWidgetType', inputValue: 'module'}
                                                                        ],
                                                                        listeners: {
                                                                          change : function(rg, r){
                                                                            currentModuleMode = r.inputValue;
                                                                          }
                                                                        }
                                                                      },
                                                                        new Ext.form.ComboBox({
                                                                                                fieldLabel: '',
                                                                                                hideLabel: true,
                                                                                                store: new Ext.data.Store({
                                                                                                    autoLoad: true,
                                                                                                    url: '/ajax/portals/portalsModuleListCreate.cfm?gcd='+_settings.gcdID,
                                                                                                    reader : new Ext.data.JsonReader({
                                                                                                        root : 'modules'
                                                                                                      },[
                                                                                                        {name: 'alias', mapping: 'module_alias_id'},
                                                                                                        {name: 'title', mapping: 'text'},
                                                                                                        {name: 'iconCls', mapping: 'iconCls'}
                                                                                                      ]
                                                                                                    ),
                                                                                                    listeners: {
                                                                                                      load: function(s,r,o){
                                                                                                        currentModuleToAdd = r[0];
                                                                                                      }
                                                                                                    }
                                                                                                }),
                                                                                                mode: 'remote',
                                                                                                width: 318,
                                                                                                valueField:'alias',
                                                                                                displayField:'title',
                                                                                                hiddenName: 'new_module_alias_name',
                                                                                                hiddenId: 'new_module_alias_id',
                                                                                                typeAhead: true,
                                                                                                forceSelection: true,
                                                                                                triggerAction: 'all',
                                                                                                value: 1,
                                                                                                selectOnFocus:true,
                                                                                                itemSelector: 'div.search-item',
                                                                                                tpl:new Ext.XTemplate(
                                                                                                  '<tpl for="."><div class="search-item search-item-module">',
                                                                                                    '<span class="iconHolder {iconCls}"></span>',
                                                                                                    '<span class="iconText">{title}</span>',
                                                                                                    '<br class="clear" />',
                                                                                                  '</div></tpl>'
                                                                                                ),
                                                                                                listeners: {  
                                                                                                  'select': function(c,r,i){
                                                                                                    currentModuleToAdd = r;
                                                                                                    var tmpPanel = Ext.getCmp('add_new_module_wizard_form_main').getForm();
                                                                                                    tmpPanel.setValues({'newWidgetType': 'module'});
                                                                                                  }
                                                                                                }
                                                                                            })
                                                                      ]
                                                            })
                                                      ]
                                          })
                                  ]
                              },{
                                id: 'card-2-rss',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                  {
                                    region: 'north',
                                    height: 70,
                                    html: '<h3 class="wizardTitle">Configure the RSS Feed</h3>' //<p class="wizardDescription">These settings will define it\'s public behavior.</p>'
                                  },
                                  new Ext.FormPanel({
                                                id: 'add_new_module_wizard_form_rss',
                                                region: 'center',
                                                labelAlign: 'right',
                                                labelWidth: 35,
                                                waitMsgTarget: true,
                                                items: [
                                                          new Ext.form.FieldSet({
                                                                                  title: 'RSS Settings',
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items: [
                                                                                          {
                                                                                            fieldLabel: 'Title',
                                                                                            width: 270,
                                                                                            name: 'rss_title'
                                                                                          },{
                                                                                            fieldLabel: 'URL',
                                                                                            width: 270,
                                                                                            name: 'rss_feed',
                                                                                            value: 'http://'
                                                                                          },
                                                                                          {
                                                                                            xtype: 'panel',
                                                                                            border: false,
                                                                                            bodyStyle: 'color: #777; font-size: 10px; margin-left: 40px;',
                                                                                            html: '<b>Example:</b> http://www.example.com/rss'
                                                                                          }
                                                                                        ]
                                                                                }),
                                                          new Ext.form.FieldSet({
                                                                                  title: 'Advanced Settings',
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items: new Ext.grid.PropertyGrid({
                                                                                                                      height: 80,
                                                                                                                      id: 'add_new_module_wizard_form_rss_adv'
                                                                                                                    })
                                                                                })
                                                        ]
                                                      })

                                                                
                                ]
                              },{
                                id: 'card-2-social',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                  {
                                    region: 'north',
                                    height: 70,
                                    html: '<h3 class="wizardTitle">Select and Configure your Networks</h3>' //<p class="wizardDescription">These settings will define it\'s public behavior.</p>'
                                  },
                                  new Ext.FormPanel({
                                                id: 'add_new_module_wizard_form_social',
                                                region: 'center',
                                                autoScroll: true,
                                                labelAlign: 'right',
                                                labelWidth: 65,
                                                waitMsgTarget: true,
                                                items: [
                                                          new Ext.form.FieldSet({
                                                                                  title: 'Facebook',
                                                                                  checkboxToggle: true,
                                                                                  collapsed: true,
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items: [
                                                                                            {
                                                                                              fieldLabel: 'Username',
                                                                                              width: 240,
                                                                                              name: 'social_facebook_username'
                                                                                            },
                                                                                            {
                                                                                              xtype: 'panel',
                                                                                              border: false,
                                                                                              bodyStyle: 'color: #777; font-size: 10px; margin-left: 70px;',
                                                                                              html: '<b>Example:</b> http://www.facebook.com/<b>username</b>'
                                                                                            }
                                                                                          ]
                                                                                }),
                                                          new Ext.form.FieldSet({
                                                                                  title: 'MySpace',
                                                                                  checkboxToggle: true,
                                                                                  collapsed: true,
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items: [
                                                                                            {
                                                                                              fieldLabel: 'Username',
                                                                                              width: 240,
                                                                                              name: 'social_myspace_username'
                                                                                            },
                                                                                            {
                                                                                              xtype: 'panel',
                                                                                              border: false,
                                                                                              bodyStyle: 'color: #777; font-size: 10px; margin-left: 70px;',
                                                                                              html: '<b>Example:</b> http://www.myspace.com/<b>username</b>'
                                                                                            }
                                                                                          ]
                                                                                }),
                                                          new Ext.form.FieldSet({
                                                                                  title: 'Twitter',
                                                                                  checkboxToggle: true,
                                                                                  collapsed: true,
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items: [
                                                                                            {
                                                                                              fieldLabel: 'Username',
                                                                                              width: 240,
                                                                                              name: 'social_twitter_username'
                                                                                            },
                                                                                            {
                                                                                              xtype: 'panel',
                                                                                              border: false,
                                                                                              bodyStyle: 'color: #777; font-size: 10px; margin-left: 70px;',
                                                                                              html: '<b>Example:</b> http://www.twitter.com/<b>username</b>'
                                                                                            }
                                                                                          ]
                                                                                }),
                                                          new Ext.form.FieldSet({
                                                                                  title: 'Live Journal',
                                                                                  checkboxToggle: true,
                                                                                  collapsed: true,
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items: [
                                                                                            {
                                                                                              fieldLabel: 'Username',
                                                                                              width: 240,
                                                                                              name: 'social_livejournal_username'
                                                                                            },
                                                                                            {
                                                                                              xtype: 'panel',
                                                                                              border: false,
                                                                                              bodyStyle: 'color: #777; font-size: 10px; margin-left: 70px;',
                                                                                              html: '<b>Example:</b> http://<b>username</b>.livejournal.com/'
                                                                                            }
                                                                                          ]
                                                                                }),
                                                          new Ext.form.FieldSet({
                                                                                  title: 'Orkut',
                                                                                  checkboxToggle: true,
                                                                                  collapsed: true,
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items: [
                                                                                            {
                                                                                              fieldLabel: 'User ID',
                                                                                              width: 240,
                                                                                              name: 'social_orkut_username'
                                                                                            },
                                                                                            {
                                                                                              xtype: 'panel',
                                                                                              border: false,
                                                                                              bodyStyle: 'color: #777; font-size: 10px; margin-left: 70px;',
                                                                                              html: '<b>Example:</b> http://www.orkut.com/Main#Profile?uid=<b>user_id</b>'
                                                                                            }
                                                                                          ]
                                                                                }),
                                                          new Ext.form.FieldSet({
                                                                                  title: 'Email',
                                                                                  checkboxToggle: true,
                                                                                  collapsed: true,
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items: [
                                                                                            {
                                                                                              fieldLabel: 'Email',
                                                                                              width: 240,
                                                                                              name: 'social_email_account'
                                                                                            },
                                                                                            {
                                                                                              xtype: 'panel',
                                                                                              border: false,
                                                                                              bodyStyle: 'color: #777; font-size: 10px; margin-left: 70px;',
                                                                                              html: '<b>Example:</b> example@server.com'
                                                                                            }
                                                                                          ]
                                                                                })
                                                        ]
                                                      })
                                                                
                                ]
                              },{
                                id: 'card-2-page',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                  {
                                    region: 'north',
                                    height: 70,
                                    html: '<h3 class="wizardTitle">What kind of Content?</h3>' //<p class="wizardDescription">These settings will define it\'s public behavior.</p>'
                                  },
                                  new Ext.FormPanel({
                                                id: 'add_new_module_wizard_form_page',
                                                region: 'center',
                                                labelAlign: 'right',
                                                waitMsgTarget: true,
                                                items: [
                                                          new Ext.form.FieldSet({
                                                                                  title: 'Select a Content Type',
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items:[
                                                                                          {
                                                                                            xtype: 'radiogroup',
                                                                                            hideLabel: true,
                                                                                            itemCls: 'x-check-group-alt',
                                                                                            name: 'newPageType',
                                                                                            columns: 1,
                                                                                            items: [
                                                                                                {boxLabel: 'New Page', name: 'newPageType', inputValue: 'new', checked: true},
                                                                                                {boxLabel: 'Existing Page', name: 'newPageType', inputValue: 'existing'}
                                                                                            ]
                                                                                          },{
                                                                                            xtype: 'displayfield',
                                                                                            ref: 'newPageTitle',
                                                                                            hideLabel: true,
                                                                                            html: ''
                                                                                          },{
                                                                                            xtype: 'button',
                                                                                            text: 'Browse for Content...',
                                                                                            listeners: {  
                                                                                              'click': function(b, e){
                                                                                                var tmpPanel = Ext.getCmp('add_new_module_wizard_form_page').getForm();
                                                                                                tmpPanel.setValues({'newPageType': 'existing'});
                                                                                                
                                                                                                browseForPage({titleNode: b.ownerCt.newPageTitle});
                                                                                                
                                                                                              }
                                                                                            }
                                                                                          }
                                                                                        ]
                                                                                })
                                                        ]
                                                    })

                                                                
                                ]
                              },/*{
                                id: 'card-2-module',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                  {
                                    region: 'north',
                                    height: 70,
                                    html: '<h3 class="wizardTitle">Configure your New Module!</h3>'
                                  },
                                  new Ext.FormPanel({
                                                id: 'add_new_module_wizard_form_module',
                                                region: 'center',
                                                labelAlign: 'right',
                                                waitMsgTarget: true,
                                                items: [
                                                          new Ext.form.FieldSet({
                                                                                  title: 'Select a Content Type',
                                                                                  border: true,
                                                                                  defaultType: 'textfield',
                                                                                  items: new Ext.grid.PropertyGrid({
                                                                                                                      height: 195,
                                                                                                                      id: 'add_new_module_wizard_form_module_adv'
                                                                                                                    })
                                                                                })
                                                        ]
                                                    })

                                                                
                                ]
                              },*/{
                                id: 'card-3-final',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                  {
                                    region: 'north',
                                    html: '<h3 class="wizardTitle">New Widget is Ready to Save!</h3><p class="wizardDescription">Click &apos;Finish&apos; to add your new widget and reload the portal.</p>'
                                  },
                                  {
                                    region: 'center',
                                    html: ''
                                  }
                                ]
                              }]
                    })
                  ]
      });
    winAddWidget.show(this);
  }

  var layoutHandler = function(editor, incr){
    var l = Ext.getCmp('edit_layout_wizard_panel').getLayout();
    var i = l.activeItem.id.split('layout-')[1];
    var i2 = i.split('-');
    if (i2[0] >= 2 && incr == 1){
      var portLayout = Ext.get('edit_layout_wizard_combo_id').dom.value;
      Ext.Msg.wait('Please wait...', 'Saving Portal Layout');
      Ext.Ajax.request({
          url:'/ajax/portals/updateLayout.cfm',
          method: 'GET',
          params : { id: editor._portal.id, layout: portLayout},
          success: function(response) {
            Ext.Msg.wait('Saving Portal Layout &amp; Reloading Page...', 'Please wait');
            //Ext.getCmp('edit_layout_wizard').close();
            document.location.reload(true);
            return false;
            Ext.Msg.hide();
            //Ext.Msg.wait('Added! Reloading Portal...', 'Creating New Widget');
            //this._portal.sc.triggerReload();
          }
        });
      return false;
    }
    var next = parseInt(i2[0]) + incr;
    l.setActiveItem(next);
    Ext.getCmp('layout-prev').setDisabled(next==0);
    Ext.getCmp('layout-next').setText(next==2 ? 'Finish' : 'Next &raquo;');
  };
  
  var windowEditLayout = function(portSettings){
    this._portal = portSettings;
    var _self = this;
    var layoutStore = new Ext.data.Store({
          url: '/ajax/login/getLayouts.cfm',
          reader : new Ext.data.JsonReader({
              root : 'layouts'
            },[
                {name: 'id', mapping: 'id'},
                {name: 'text', mapping: 'text'},
                {name: 'image', mapping: 'image'}
              ]
          ),
          listeners: {
            load: function(s,r,o){
              for(n=0;n<=r.length;n++){
                if (r[n].data.id == _self._portal.layout){
                  Ext.getCmp('edit_layout_wizard_combo').setValue(r[n].data.text);
                  break;
                }
              }
            }
          }
      });
    var winEditLayout = new Ext.Window({
          id: 'edit_layout_wizard',
          stateful: false,
          iconCls: 'cpi_homeLayout',
          width:550,
          height:400,
          title: 'Edit Layout',
          closeAction:'close',
          resizable: false,
          modal:true,
          closable:true,
          buttons: [{
              id: 'layout-prev',
              handler: layoutHandler.createDelegate(this, [this, -1]),
              disabled: true,
              text: '&laquo; Previous'
          },{
              id: 'layout-next',
              handler: layoutHandler.createDelegate(this, [this, 1]),
              text: 'Next &raquo;'
          }],
          layout: 'border',
          items: [
                    new Ext.Panel({
                      region: 'west',
                      width: 165,
                      border: false,
                      bodyStyle: 'background: #99BBE8 url(/common/images/wizard/wizard_logo.jpg) bottom center no-repeat;',
                      html: '<div style="float: right; margin: 15px; height: 61px; width: 61px; background: url(/common/images/wizard/wizard_new.jpg);"></div>'
                    }),
                    new Ext.Panel({
                      id: 'edit_layout_wizard_panel',
                      region: 'center',
                      layout:'card',
                      deferredRender: false,
                      activeItem: 0,
                      border: false,
                      items: [{
                                id: 'layout-0',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                  {
                                    region: 'north',
                                    html: '<h3 class="wizardTitle">Welcome to the Portal Layout Selector!</h3><p class="wizardDescription">This is the first step towards updating your portal layout.</p>'
                                  },                                  
                                  {
                                    region: 'center',
                                    html: ' '
                                  }                                
                                ]
                              },{
                                id: 'layout-1',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                  {
                                    region: 'north',
                                    html: '<h3 class="wizardTitle">Select a Portal Layout</h3>'
                                  },                                  
                                  {
                                    region: 'center',
                                    items: new Ext.form.FieldSet({
                                                                    title: 'Choose a Portal Layout:',
                                                                    border: true,
                                                                    defaultType: 'textfield',
                                                                    items: new Ext.form.ComboBox({
                                                                      id: 'edit_layout_wizard_combo',
                                                                      hiddenName: 'edit_layout_wizard_combo_name',
                                                                      hiddenId: 'edit_layout_wizard_combo_id',
                                                                      tpl: '<tpl for="."><div class="x-combo-list-item"><span class="layoutImage"><img src="/common/images/panel_images/{image}" /></span> <span class="layoutCaption">{text}</span><br class="clear" /></div></tpl>',
                                                                      store: layoutStore,
                                                                      hideLabel: true,
                                                                      valueField:'id',
                                                                      displayField:'text',
                                                                      width: 318,
                                                                      typeAhead: true,
                                                                      forceSelection: true,
                                                                      mode: 'local',
                                                                      triggerAction: 'all',
                                                                      emptyText:'Select a layout...',
                                                                      selectOnFocus:true
                                                                    })
                                                                  })
                                  }                                
                                ]
                              },{
                                id: 'layout-2',
                                layout: 'border',
                                border: false,
                                defaults: { padding: 15, border: false },
                                items: [
                                  {
                                    region: 'north',
                                    html: '<h3 class="wizardTitle">Portal Layout is Ready to Save!</h3><p class="wizardDescription">Click Finish to apply your layout changes and reload the portal.</p>'
                                  },                                  
                                  {
                                    region: 'center',
                                    html: ' '
                                  }                                
                                ]
                              }]
                    })
                  ]
      });
    winEditLayout.show(this);
    layoutStore.load();
  }
  
function browseForPage(settings){
  var _self = this;
  this._settings = {};
  
  Ext.apply(this._settings, settings);
  
  var reader = new Ext.data.XmlReader({
        record : 'result',
        success : '@success',
        totalProperty : '@totalCount'
    }, [
     {name: 'id', type: 'int', mapping: 'id'},
     {name: 'title', mapping: 'title'},
     {name: 'created', type: 'date', dateFormat: 'm/d/y', mapping: 'created'},
     {name: 'updated', type: 'date', dateFormat: 'm/d/y', mapping: 'updated'},
     {name: 'author', mapping: 'author'}
  ]);

  var expander = new Ext.grid.RowExpander({
      tpl : new Ext.Template(
          '<span style="padding: 10px">{content}</span><br>'
      )
  });

  this.store = new Ext.data.Store({
            url: '/ajax/portals/getAllPages.cfm',
            reader: reader,
            remoteSort: true,
            listeners: {
              load: function(s, r, o){
                for(var n=0; n < r.length; n++){
                  r[n].set('title', Base64.decode(r[n].get('title')));
                  r[n].set('author', Base64.decode(r[n].get('author')));
                  r[n].commit();
                }
              }
            }
        });
  this.store.setDefaultSort('updated', 'desc');
  
  this.grid = new Ext.grid.GridPanel({
          region: 'center',
          border: true,
          stripeRows: true,
          loadMask: true,
          store: this.store,
          autoExpandColumn: 'title',
          sm: new Ext.grid.RowSelectionModel({
            singleSelect:true,
            listeners: {
              rowselect : function(sm, rI, r){
                currentModuleDataTitle = r.get('title');
                currentModuleDataAuthor = r.get('author');
                currentModuleDataID = r.get('id');
                _self.browseWin.openBtn.enable();
                _self.browseWin.previewPane.load({
                    url: '/ajax/portals/getPageContent.cfm',
                    params: {id: currentModuleDataID},
                    text: 'Loading...',
                    timeout: 30,
                    scripts: false
                });
              }
            }
          }),
          cm: new Ext.grid.ColumnModel({
              defaults: {
                  sortable: true
              },
              columns: [
                  {header: "ID", width: 30, dataIndex: 'id', markDirty: false},
                  {id:'title',header: "Title", dataIndex: 'title', markDirty: false},
                  {header: "Author", width: 180, dataIndex: 'author', markDirty: false},
                  {header: "Last Updated", width: 100, renderer: Ext.util.Format.dateRenderer('m/d/Y'), dataIndex: 'updated', markDirty: false}
              ]
          }),
          listeners: {
            render: function(w){
              _self.store.load({params:{start:0, limit:25}});
            },
            rowdblclick : function(g, rI, e){
              currentModuleDataTitle = g.getStore().getAt(rI).get('title');
              currentModuleDataAuthor = g.getStore().getAt(rI).get('author');
              currentModuleDataID = g.getStore().getAt(rI).get('id');
              _self.browseWin.openBtn.handler();
            }
          },
          maximizable: true,
          animCollapse: false,
          bbar: new Ext.PagingToolbar({
              pageSize: 25,
              store: this.store,
              displayInfo: true,
              displayMsg: 'Displaying Pages {0} - {1} of {2}',
              emptyMsg: "No topics to display"
          })
      });

  this.browseWin = new Ext.Window({
    width: 600,
    height: 400,
    title: 'Browse for Page...',
    closable: true,
    maximizable: true,
    constrainHeader: true,
    modal:true,
    buttons: [
      {text: 'Open', disabled: true, ref: '../openBtn', handler: function(){
        if (_self._settings.titleNode){
          _self._settings.titleNode.update('<strong>'+ currentModuleDataTitle + '</strong><br />by: ' + currentModuleDataAuthor);
        }
        if (_self._settings.navigationContextNode){
          _self._settings.navigationContextNode.attributes.data_id = currentModuleDataID;
          _self._settings.navigationContextNode.attributes.data_type = 'page';
          _self._settings.navigationContextNode.attributes.title = currentModuleDataTitle;
          _self._settings.navigationContextNode.setText(currentModuleDataTitle);
          _self._settings.navigationContextNode.getUI().addClass('iconPageView');
        }
        _self.browseWin.close();
      }},
      {text: 'Cancel', handler: function(){
        if (_self._settings.navigationContextNode)
          _self._settings.navigationContextNode.remove();
        _self.browseWin.close();
      }}
    ],
    layout: 'fit',
    padding: 5,
    items: new Ext.Panel({
      layout: 'border',
      border: false,
      items: [this.grid,
        {
          split: true,
          collapsible: true,
          title: 'Preview',
          region: 'south',
          cmargins: '5 0 0 0',
          ref: '../previewPane',
          padding: 10,
          height: 90,
          html: '<strong>Content Preview</strong><br />Select an item above to get started.<br /><span style="color: #999; font-size: 10px;">*Styles may not render the same as on the page</span>'
        }
      ]
    })
  });
  this.browseWin.show(this);
}

