
  function windowProfileConfig(profileSettings){
  
    this._profile = profileSettings;
    
    var profileTypes = {    
      /* ADMIN */
      'admin' : {
        layouts: [
          ['default', '(Default)'],
          ['rightalign', 'Right Aligned']
        ],
        settings: {
          hide_info: {visible: true, value: false, type: 'bool'},
          hide_photo: {visible: true, value: false, type: 'bool'},
          hide_classes: {visible: true, value: false, type: 'bool'},
          hide_departments: {visible: true, value: false, type: 'bool'},
          layout: {visible: false, value: 'default'}
        }
      }
    };
    var propertyNames = {
      hide_info: 'Hide Information',
      hide_classes: 'Hide Classes',
      hide_departments: 'Hide Departments',
      hide_photo: 'Hide Photo'      
    };

    var curModType = profileTypes[this._profile.storeParams.user_type];
    
    tmpOptions = {};
    tmpOptionsLayout = 0;
    for(profileKey in curModType.settings){
      if (curModType.settings[profileKey].visible){
        var curModValue = curModType.settings[profileKey].value;
        if(typeof( this._profile.values[profileKey] ) != "undefined" && this._profile.values[profileKey]!='')
          curModValue = this._profile.values[profileKey];
        switch(curModType.settings[profileKey].type){
          case "int":
            //curModValue = parseInt(curModValue);
            break;
          case "bool":
            tmpModValue = this._profile.values[profileKey];
            if (tmpModValue || tmpModValue == "true" || tmpModValue == "1")
              curModValue = true;
            else
              curModValue = false;
            break;
          default:
            break;
        }
        tmpOptions[profileKey] = curModValue;
      }else{
        switch (profileKey){
          case "layout":
            tmpOptionsLayout = this._profile.values[profileKey] || curModType.settings[profileKey].value;
            break;
        }
      }
    }
    
    var _self = this;
    
    var winProfileEdit = new Ext.Window({
          width:400,
          height:450,
          title: 'Profile Settings - ' + this._profile.storeParams.display_name,
          layout:'border',
          closeAction:'close',
          profileal:true,
          maximizable:true,
          closable:true,
          border:false,
          modal: true,
          items: [
                    new Ext.Panel({
                      region: 'north',
                      layout: 'form',
                      autoHeight:true,
                      padding: 10,
                      items: [{
                                xtype:'fieldset',
                                title: 'General',
                                autoHeight:true,
                                labelWidth: 80,
                                defaults: {
                                    anchor: '0'
                                  },
                                defaultType: 'textfield',
                                items :[{
                                          xtype: 'textfield',
                                          id: 'layoutTitle_' + this._profile.storeParams.user_id,
                                          fieldLabel: 'Display Title',
                                          value: this._profile.storeParams.display_name
                                        },{
                                          xtype: 'combo',
                                          id: 'layoutCombo_' + this._profile.storeParams.user_id,
                                          fieldLabel: 'Layout',
                                          typeAhead: true,
                                          forceSelection: true,
                                          triggerAction: 'all',
                                          lazyRender:true,
                                          profilee: 'local',
                                          store: new Ext.data.ArrayStore({
                                              id: 0,
                                              fields: [
                                                  'myId',
                                                  'displayText'
                                              ],
                                              data: curModType.layouts
                                          }),
                                          value: tmpOptionsLayout,
                                          valueField: 'myId',
                                          displayField: 'displayText'
                                        }]
                            }]
                    }),
                    new Ext.TabPanel({
                      region: 'center',
                      activeTab: 0,
                      items: [
                                new Ext.grid.PropertyGrid({
                                  title: 'Advanced',
                                  id: 'propertyGrid_' + this._profile.storeParams.user_id,
                                  propertyNames: propertyNames,
                                  source: tmpOptions
                                })
                              ]
                    })
                  ],
          buttons: [{
            text: 'Save',
            handler: function(){
              var tmpLT = Ext.getCmp('layoutTitle_' + _self._profile.storeParams.user_id);
              var tmpLC = Ext.getCmp('layoutCombo_' + _self._profile.storeParams.user_id);
              var tmpPG = Ext.getCmp('propertyGrid_' + _self._profile.storeParams.user_id);
              var tmpSetData = tmpPG.source;
              var tmpSets = Object.extend(tmpSetData, {layout: tmpLC.value});
              var tmpSettings = Object.extend(tmpSets, {__alias: tmpLT.getValue()});
              setTimeout(function(){
                new Ajax.Request('/ajax/profile/updateSetting.cfm?id='+_self._profile.storeParams.user_id, {
                    method:'post',
                    parameters: Object.toQueryString(tmpSettings),
                    onSuccess: function(){
                      Ext.MessageBox.wait('Saving Settings...','Please wait');
                      winProfileEdit.close();
                      window.location.reload(true);
                    }
                  });
              }, 500);
              
            }
          },{ text: 'Cancel', handler: function(){ winProfileEdit.close(); } }]
      });
    winProfileEdit.show(this);

  }
