
  function windowModuleConfig(modSettings){
    this._module = modSettings;
    var types= {
      hide_thumbnails: {},
      action_type: {},
      AJAX_SWITCHER: {},
      CAL_WIDTH: {},
      CELL_HEIGHT: {},
      HIDE_COMMENTS: {},
      HIDE_KEYWORDS: {},
      HIDE_META: {},
      LIST_MODE: {},
      maxitems: {},
      MINI_MODE: {},
      MINI_TITLE: {},
      MODE: {},
      MODULEACTION: {},
      NO_FIRST_SPACE: {},
      SHOW_CAT_IMAGE: {},
      TRUNCATE_TEXT: {}
    };
    
    var modTypes = {    
      /* PAGE */
      page: {
        layouts: [['default', '(Default)']],
        settings: {
          layout: {visible: false, value: 'default'}
        }
      },
      
      iframe: {
        layouts: [['default', '(Default)']],
        settings: {
          layout: {visible: false, value: 'default'},
          url: {visible: true, value: 'http://www.google.com/'},
          set_height: {visible: true, value: '200'}
        }
      },

      event: {
        layouts: [
          ['default', 'Month View'],
          ['week', 'Week View'],
          ['weekwithdays', 'Week w/Days'],
          ['weekdaysonly', 'Week (Days Only)'],
          ['day', 'Day View'],
          ['list', 'List View'],
          ['year', 'Year View']
          ],
        settings: {
          dateOffset: {visible: true, value: 0, type: 'int'},
          maxCalendarListDays: {visible: true, value: 0, type: 'int'},
          maxCalendarListItems: {visible: true, value: 0, type: 'int'},
          layout: {visible: false, value: 'default'}
        }
      },

      /* BLOG */
      blog: {
        layouts: [['default', '(Default)']],
        settings: {
          max_items_per_page: {visible: true, value: 10, type: 'int'},
          truncate_text: {visible: true, value: 0, type: 'int'},
          image_size: {visible: true, value: 0, type: 'int'},
          strip_tags: {visible: true, value: true, type: 'bool'},
          hide_list_thumbnails: {visible: true, value: false, type: 'bool'},
          hide_post_thumbnails: {visible: true, value: true, type: 'bool'},
          hide_posted_date: {visible: true, value: false, type: 'bool'},
          hide_author: {visible: true, value: false, type: 'bool'},
          hide_footer_links: {visible: true, value: false, type: 'bool'},
          layout: {visible: false, value: 'default'}
        }
      },
      
      /* NEWS */
      news: {
        layouts: [['default', '(Default)']],
        settings: {
          max_items_per_page: {visible: true, value: 10, type: 'int'},
          truncate_text: {visible: true, value: 0, type: 'int'},
          image_size: {visible: true, value: 0, type: 'int'},
          strip_tags: {visible: true, value: true, type: 'bool'},
          hide_list_thumbnails: {visible: true, value: false, type: 'bool'},
          hide_post_thumbnails: {visible: true, value: true, type: 'bool'},
          hide_posted_date: {visible: true, value: false, type: 'bool'},
          hide_author: {visible: true, value: false, type: 'bool'},
          hide_footer_links: {visible: true, value: false, type: 'bool'},
          layout: {visible: false, value: 'default'}
        }
      },
      
      /* WEATHER */
      weather: { 
        layouts: [['default', '(Default)'], ['compact', 'Compact'], ['detail', 'Detailed']],
        settings: {
          zipcode: {visible: true, value: '93313'},
          layout: {visible: false, value: 'default'}
        }
      },
      /* Slide Show */
      slideshow: { 
        layouts: [['default', '(Default)']],
        settings: {
          set_width: {visible: false, value: '100%'}, //besure to re-add argument to common/ext/portlet.js
          set_height: {visible: true, value: '200'},
          layout: {visible: false, value: 'default'}
        }
      },
      
      /* RSS */
      rss: { 
        layouts: [['default', '(Default)'], ['compact', 'Compact']],
        settings: {
          feedurl: {visible: true, value: ''},
          max_items_total: {visible: true, value: 0, type: 'int'},
          truncate_text: {visible: true, value: 0, type: 'int'},
          strip_tags: {visible: true, value: true, type: 'bool'},
          hide_post_thumbnails: {visible: true, value: true, type: 'bool'},
          hide_posted_date: {visible: true, value: false, type: 'bool'},
          hide_author: {visible: true, value: false, type: 'bool'},
          hide_footer_links: {visible: true, value: false, type: 'bool'},
          layout: {visible: false, value: 'default'}
        }
      }
    };
    var propertyNames = {
        feedurl: "Feed Url",
        hide_list_thumbnails: "Hide Thumbnail in List",
        hide_post_thumbnails: "Hide Thumbnail in Post",
        max_items_per_page: "Max Items per Page",
        max_items_total: "Max Items (0 = All)",
        strip_tags: "Strip HTML Tags",
        image_size: "Set image size (in pixles)",
        strip_tags_all: "Strip All Tags",
        hide_links: "Strip Links in Content",
        hide_posted_date: "Hide Posted Date",
        hide_author: "Hide Author Link",
        hide_footer_links: "Hide Footer Links",
        set_width: "Width",
        set_height: "Height",
        truncate_text: "Truncate Length (0 = None)",
        zipcode: "ZIP Code",
        dateOffset: "Date Offset (in Days)",
        maxCalendarListDays: "Max Days in List View (0=all)",
        maxCalendarListItems: "Max Items in List View (0=all)"
    };

    if (!modTypes[this._module.storeParams.keyword]){
      Ext.Msg.alert('Error', 'This module doesn\'t have any settings available.');
      return false;
    }
    var curModType = modTypes[this._module.storeParams.keyword];
    
    customEditors = {};
    tmpOptions = {};
    tmpOptionsLayout = curModType.settings.layout.value;
    for(moduleKey in curModType.settings){
      if (curModType.settings[moduleKey].visible){
        var curModValue = curModType.settings[moduleKey].value;
        if(typeof( this._module.values[moduleKey] ) != "undefined" && this._module.values[moduleKey]!='')
          curModValue = this._module.values[moduleKey];
        switch(curModType.settings[moduleKey].type){
          case "int":
            //curModValue = parseInt(curModValue);
            break;
          case "bool":
            tmpModValue = this._module.values[moduleKey];
            if (tmpModValue || tmpModValue == "true" || tmpModValue == "1")
              curModValue = true;
            else
              curModValue = false;
            break;
          default:
            break;
        }
        tmpOptions[moduleKey] = curModValue;
      }else{
        switch (moduleKey){
          case "layout":
            tmpOptionsLayout = this._module.values[moduleKey];
            break;
        }
      }
    }
    
    var _self = this;
    
    var meinItems = [];
    // meinItems nowl!
    meinItems.push({
                      xtype: 'textfield',
                      id: 'layoutTitle_' + this._module.storeParams.id,
                      fieldLabel: 'Title',
                      value: this._module.storeParams.alias
                    });
    meinItems.push({
                      xtype: 'combo',
                      id: 'layoutCombo_' + this._module.storeParams.id,
                      fieldLabel: 'Layout',
                      typeAhead: true,
                      forceSelection: true,
                      triggerAction: 'all',
                      lazyRender:true,
                      mode: 'local',
                      store: new Ext.data.ArrayStore({
                          id: 0,
                          fields: [
                              'myId',
                              'displayText'
                          ],
                          data: curModType.layouts
                      }),
                      value: tmpOptionsLayout,
                      valueField: 'myId',
                      displayField: 'displayText'
                    });
    
    var winModuleEdit = new Ext.Window({
          width:400,
          height:450,
          title: 'Widget Settings - ' + this._module.storeParams.alias,
          layout:'border',
          closeAction:'close',
          modal:true,
          maximizable:true,
          closable:true,
          border:false,
          items: [
                    new Ext.Panel({
                      region: 'north',
                      layout: 'form',
                      autoHeight:true,
                      padding: 10,
                      items: [{
                                xtype:'fieldset',
                                title: 'General',
                                autoHeight:true,
                                labelWidth: 50,
                                defaults: {
                                    anchor: '0'
                                  },
                                defaultType: 'textfield',
                                items :meinItems
                            }]
                    }),
                    new Ext.TabPanel({
                      region: 'center',
                      activeTab: 0,
                      items: [
                                new Ext.grid.PropertyGrid({
                                  title: 'Advanced',
                                  id: 'propertyGrid_' + this._module.storeParams.id,
                                  propertyNames: propertyNames,
                                  source: tmpOptions
                                })/*,
                                new windowPermissionUsers(true)*/
                              ]
                    })
                  ],
          //buttonAlign: 'left',
          buttons: [/*{
            text: 'Preview'
          },*/{
            text: 'Save',
            handler: function(){
              //alert(_self._module.storeParams.id);
              var tmpLT = Ext.getCmp('layoutTitle_' + _self._module.storeParams.id);
              var tmpLC = Ext.getCmp('layoutCombo_' + _self._module.storeParams.id);
              var tmpPG = Ext.getCmp('propertyGrid_' + _self._module.storeParams.id);
              var tmpSetData = tmpPG.source;
              var tmpSets = Object.extend(tmpSetData, {layout: tmpLC.value});
              var tmpSettings = Object.extend(tmpSets, {__alias: tmpLT.getValue()});
              setTimeout(function(){
                Ext.Msg.wait('Please Wait...', 'Saving Portal Settings');
                Ext.Ajax.request({
                   url: '/ajax/portals/updateSetting.cfm?id='+_self._module.storeParams.id+'&pid='+_self._module.storeParams.portletID,
                   method: 'POST',
                   params: tmpSettings,
                   reader : new Ext.data.JsonReader({
                    success : '@success'
                   }),
                   success: function(response, opts) {
                      var obj = Ext.decode(response.responseText);
                      if (obj.success){
                        Ext.Msg.hide();
                        if (_self._module.storeFN){
                          _self._module.values = tmpSets;
                          _self._module.storeParams = Object.extend(_self._module.storeParams, {alias: tmpLT.getValue()});
                          _self._module.setTitle("Applying Changes...");
                          _self._module.storeFN(_self._module);
                          winModuleEdit.close();
                        }else{
                          Ext.MessageBox.wait('Saving Settings...','Please wait');
                          winModuleEdit.close();
                          window.location.reload(true);
                        }
                      }else{
                        Ext.Msg.hide();
                        Ext.Msg.alert('Error Creating Portal', 'There was an error creating the specified portal. Please try again.');
                      }
                   },
                   failure: function(response, opts) {
                    Ext.Msg.hide();
                    Ext.Msg.alert('Error Creating Portal', 'There was a problem communicating with the server. Please check your internet connection and try again.');
                   }
                });   
              }, 500);
              
            }
          },{ text: 'Cancel', handler: function(){ winModuleEdit.close(); } }]
      });
    winModuleEdit.show(this);

  }
  

  function windowModuleLayout(modSettings){
    this._module = modSettings;
    var _self = this;
    
    var tmpOptionsOpacity = this._module.storeParams.myOpacity;
    var tmpOptionsLayout = this._module.storeParams.myLayout;

    var opacities = [];
    opacities.push([0, '0%']);
    opacities.push([5, '5%']);
    opacities.push([10, '10%']);
    opacities.push([15, '15%']);
    opacities.push([20, '20%']);
    opacities.push([25, '25%']);
    opacities.push([30, '30%']);
    opacities.push([35, '35%']);
    opacities.push([40, '40%']);
    opacities.push([45, '45%']);
    opacities.push([50, '50%']);
    opacities.push([55, '55%']);
    opacities.push([60, '60%']);
    opacities.push([65, '65%']);
    opacities.push([70, '70%']);
    opacities.push([75, '75%']);
    opacities.push([80, '80%']);
    opacities.push([85, '85%']);
    opacities.push([90, '90%']);
    opacities.push([95, '95%']);
    opacities.push([100, '100%']);
    
    var layouts = [];
    layouts.push(['', 'Default Blue']); //x-portlet
    layouts.push(['plain', 'Basic Panel']); //x-portlet x-portlet-plain x-portlet-plain-75
    layouts.push(['borderless', 'Basic Panel (Borderless)']); //x-portlet x-portlet-borderless x-portlet-borderless-75');
    layouts.push(['titleless', 'Titleless Panel']); //x-portlet x-portlet-edgeless x-portlet-edgeless-75');
    layouts.push(['edgeless', 'Titleless & Edgeless Panel']); //x-portlet x-portlet-edgeless x-portlet-edgeless-75');
    
    var winModuleLayout = new Ext.Window({
          width:300,
          title: 'Widget Style - ' + this._module.storeParams.alias,
          layout:'form',
          closeAction:'close',
          modal:true,
          border: true,
          sizable: false,
          closable:true,
          items: new Ext.FormPanel({
                  xtype:'fieldset',
                  padding: 5,
                  autoHeight:true,
                  labelAlign: 'top',
                  border: false,
                  labelWidth: 150,
                  defaults: {
                      anchor: '0'
                    },
                  defaultType: 'textfield',
                  items :[{
                            xtype: 'combo',
                            id: 'layoutCombo_' + this._module.storeParams.id,
                            fieldLabel: 'Layout',
                            typeAhead: true,
                            forceSelection: true,
                            triggerAction: 'all',
                            lazyRender:true,
                            mode: 'local',
                            store: new Ext.data.ArrayStore({
                                id: 0,
                                fields: [
                                    'myId',
                                    'displayText'
                                ],
                                data: layouts
                            }),
                            value: tmpOptionsLayout,
                            valueField: 'myId',
                            displayField: 'displayText'
                          },{
                            xtype: 'combo',
                            id: 'opacityCombo_' + this._module.storeParams.id,
                            fieldLabel: 'Background Transparency',
                            typeAhead: true,
                            forceSelection: true,
                            triggerAction: 'all',
                            lazyRender:true,
                            mode: 'local',
                            store: new Ext.data.ArrayStore({
                                id: 0,
                                fields: [
                                    'myId',
                                    'displayText'
                                ],
                                data: opacities
                            }),
                            value: tmpOptionsOpacity,
                            valueField: 'myId',
                            displayField: 'displayText'
                          }]
              }),
          //buttonAlign: 'left',
          buttons: [{
            text: 'Save',
            handler: function(){
              var tmpLC = Ext.getCmp('layoutCombo_' + _self._module.storeParams.id);
              var tmpPG = Ext.getCmp('opacityCombo_' + _self._module.storeParams.id);
              setTimeout(function(){
                Ext.Msg.wait('Please Wait...', 'Saving Portal Layout');
                Ext.Ajax.request({
                   url: '/ajax/portals/updateWidgetLayout.cfm?id='+_self._module.storeParams.id+'&pid='+_self._module.storeParams.portletID,
                   method: 'POST',
                   params: {layout: tmpLC.value, opacity: tmpPG.value},
                   reader : new Ext.data.JsonReader({
                    success : '@success'
                   }),
                   success: function(response, opts) {
                      var obj = Ext.decode(response.responseText);
                      if (obj.success){
                        Ext.Msg.hide();
                        Ext.MessageBox.wait('Refreshing Page...','Saving Portal Layout');
                        winModuleLayout.close();
                        window.location.reload(true);
                      }else{
                        Ext.Msg.hide();
                        Ext.Msg.alert('Error Saving Portal Layout', 'There was an error applying the selected style to this portal. Please try again.');
                      }
                   },
                   failure: function(response, opts) {
                    Ext.Msg.hide();
                    Ext.Msg.alert('Error Saving Portal Layout', 'There was a problem communicating with the server. Please check your internet connection and try again.');
                   }
                });   
              }, 500);
              
            }
          },{ text: 'Cancel', handler: function(){ winModuleLayout.close(); } }]
      });
    winModuleLayout.show(this);

  }