        var theTemplates = new Ext.data.JsonStore({
                                            fields: ['valID','texty'],
                                            root: 'templates',
                                            url: '/ajax/siteConfig/templateList.cfm'});

      function windowSchoolSettingsEditor(loadMode, schoolID, treenode){

        if (!canEdit)
          return false;

        theTemplates.load();
        /*
        
        function saveSchoolForm(){
          //alert(Ext.getCmp('winSchoolSettingsEditor').getForm().getValues().toSource());
          //return false;
          var thisForm = Ext.getCmp('winSchoolSettingsEditor').getForm();
          thisForm.submit({
            clientValidation: true,            
            url:'/ajax/siteconfig/site/submitConfig.cfm?s='+schoolID, 
            waitMsg:'Saving settings...',
            params: {},
            errorReader : new Ext.data.JsonReader({
                root:'errors',
                successProperty:'success'
            }, ['id', 'msg']),
            success: function(form, action) {
              //if(action.result.data_id)
            
              if (treenode)
                treenode.setText(thisForm.getValues().school_title);
              winSchoolSettingsEdit.close();              
              return true;
            },
            failure: function(form, action) {
              switch (action.failureType) {
                case Ext.form.Action.CLIENT_INVALID:
                  Ext.Msg.alert('Failure', 'Please verify all form 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);
              }
              Ext.Msg.hide();
              return false;
            }
          });
        }
        */
        
        var xmlCols = [];
        xmlCols.push({name: 'school_title', mapping: 'title/title'});
        xmlCols.push({name: 'school_shortTitle', mapping: 'title/short'});
        xmlCols.push({name: 'school_address', mapping: 'mailing_addr/address'});
        xmlCols.push({name: 'school_city', mapping: 'mailing_addr/city'});
        xmlCols.push({name: 'school_state', mapping: 'mailing_addr/state'});
        xmlCols.push({name: 'school_zip', mapping: 'mailing_addr/zip'});
        xmlCols.push({name: 'school_business', mapping: 'phone/business'});
        xmlCols.push({name: 'school_fax', mapping: 'phone/fax'});
        xmlCols.push({name: 'school_email', mapping: 'email/general'});
        xmlCols.push({name: 'school_webmaster', mapping: 'email/webmaster'});
        xmlCols.push({name: 'school_webmail', mapping: 'config/webmail'});
        xmlCols.push({name: 'school_analytics', mapping: 'config/analytics'});
        xmlCols.push({name: 'school_swearfilter', mapping: 'config/swearfilter'});
        xmlCols.push({name: 'school_holidaymode', mapping: 'config/holidaymode'});
        xmlCols.push({name: 'school_usechat', mapping: 'config/showchat'});
        xmlCols.push({name: 'school_usetranslator', mapping: 'config/showtranslator'});
        xmlCols.push({name: 'school_externalwarn', mapping: 'config/externalwarn'});
        xmlCols.push({name: 'school_meta_keywords', mapping: 'meta/keywords'});
        xmlCols.push({name: 'school_meta_desc', mapping: 'meta/desc'});
        xmlCols.push({name: 'school_template', mapping: 'config/template'});
        xmlCols.push({name: 'schoool_legal_terms', mapping: 'config/legal/terms'});
        xmlCols.push({name: 'schoool_legal_privacy', mapping: 'config/legal/privacy'});
        xmlCols.push({name: 'schoool_custom_css', mapping: 'config/custom/css'});
        xmlCols.push({name: 'schoool_custom_js', mapping: 'config/custom/js'});
        
        xmlCols.push({name: 'share_enabled', mapping: 'config/sharing/enabled', type: 'int'});
        for(n=0;n<=6;n++) 
          xmlCols.push({name: 'share_ext_'+n, mapping: 'config/sharing/sharing_ext_'+n, type: 'bool'});
    
        var navInfo = 'Changes will be applied when you click \'Save\' below.';
        
        var ies_Tab = {
                          title: 'IES Administration',
                          autoHeight:true,
                          defaultType: 'textfield',
                          id: loadMode ? 'tabSchoolSettingsEditor_ies' : 'winSchoolSettingsEditor_ies',
                          labelWidth: 85, // label settings here cascade unless overridden
                          waitMsgTarget: !Ext.isIE,
                          reader : new Ext.data.XmlReader({
                                record : 'result',
                                success : '@success'
                            }, xmlCols),
                          items :[new Ext.form.ComboBox({
                                    fieldLabel: 'Site Layout',
                                    hiddenName:'school_template',
                                    store: theTemplates,
                                    valueField:'valID',
                                    anchor: '0',
                                    displayField:'texty',
                                    forceSelection: true,
                                    triggerAction: 'all',
                                    selectOnFocus:true,
                                    allowBlank:false
                                  })]
                      };
        var info_Tab = {
                                        title: 'Site Info',
                                        autoHeight:true,
                                        defaultType: 'textfield',
                                        id: loadMode ? 'tabSchoolSettingsEditor_site' : 'winSchoolSettingsEditor_site',
                                        labelWidth: 85, // label settings here cascade unless overridden
                                        waitMsgTarget: !Ext.isIE,
                                        reader : new Ext.data.XmlReader({
                                              record : 'result',
                                              success : '@success'
                                          }, xmlCols),
                                        items :[{
                                          fieldLabel: 'Title',
                                          anchor: '0',
                                          name: 'school_title',
                                          allowBlank:false
                                        },{
                                          fieldLabel: 'Short Title',
                                          name: 'school_shortTitle',
                                          width: 140,
                                          allowBlank:false
                                        },new Ext.form.DisplayField({html: ''}),{
                                          fieldLabel: 'Keywords',
                                          anchor: '0',
                                          name: 'school_meta_keywords'
                                        },{
                                          xtype:'textarea',
                                          height:100,
                                          anchor: '0',
                                          fieldLabel: 'Description',
                                          name: 'school_meta_desc'
                                        }]
                                    };
        var contact_Tab = {
                                        title: 'Contact Info',
                                        autoShow: true,
                                        id: loadMode ? 'tabSchoolSettingsEditor_contact' : 'winSchoolSettingsEditor_contact',
                                        labelWidth: 85, // label settings here cascade unless overridden
                                        waitMsgTarget: !Ext.isIE,
                                        reader : new Ext.data.XmlReader({
                                              record : 'result',
                                              success : '@success'
                                          }, xmlCols),
                                        autoHeight:true,
                                        defaultType: 'textfield',
                                        labelWidth: 120,
                                        items :[{
                                                  fieldLabel: 'Business Phone',
                                                  name: 'school_business',
                                                  vtype: !Ext.isIE ? 'phone' : '',
                                                  width: 200,
                                                  allowBlank:false
                                                },{
                                                  fieldLabel: 'Business Fax',
                                                  name: 'school_fax',
                                                  vtype: !Ext.isIE ? 'phone' : '',
                                                  width: 200,
                                                  allowBlank:false
                                                },new Ext.form.DisplayField({html: ''}),{
                                                  fieldLabel: 'Business Address',
                                                  name: 'school_address',
                                                  anchor: '0',
                                                  allowBlank:false
                                                },{
                                                  fieldLabel: 'City',
                                                  name: 'school_city',
                                                  width: 200,
                                                  allowBlank:false
                                                },new Ext.form.ComboBox({
                                                  fieldLabel: 'State',
                                                  hiddenName:'school_state',
                                                  store: new Ext.data.ArrayStore({
                                                    fields: ['abbr', 'state'],
                                                    data : Ext.exampledata.states // from states.js
                                                  }),
                                                  valueField:'abbr',
                                                  displayField:'state',
                                                  forceSelection: true,
                                                  mode: 'local',
                                                  triggerAction: 'all',
                                                  emptyText:'Select a state...',
                                                  width: 200,
                                                  selectOnFocus:true,
                                                  allowBlank:false
                                                }),{
                                                  fieldLabel: 'ZIP',
                                                  name: 'school_zip',
                                                  width: 80,
                                                  minLength:5,
                                                  maxLength:5,
                                                  maskRe: /[0-9]/,
                                                  allowBlank:false
                                                },new Ext.form.DisplayField({html: ''}),{
                                                  fieldLabel: 'General Email',
                                                  name: 'school_email',
                                                  width: 200,
                                                  vtype:'email',
                                                  allowBlank:false
                                                },{
                                                  fieldLabel: 'Webmaster Email',
                                                  name: 'school_webmaster',
                                                  width: 200,
                                                  vtype:'email',
                                                  allowBlank:false
                                                },{
                                                  fieldLabel: 'Web Mail URL',
                                                  anchor: '0',
                                                  name: 'school_webmail'
                                                }]
                                    };
        var google_Tab = {
                                        title: 'Google Analytics',
                                        autoHeight:true,
                                        autoShow: true,
                                        id: loadMode ? 'tabSchoolSettingsEditor_google' : 'winSchoolSettingsEditor_google',
                                        labelWidth: 85, // label settings here cascade unless overridden
                                        waitMsgTarget: !Ext.isIE,
                                        reader : new Ext.data.XmlReader({
                                              record : 'result',
                                              success : '@success'
                                          }, xmlCols),
                                        defaultType: 'textfield',
                                        items :[
                                                  new Ext.form.DisplayField({
                                                    hideLabel: true,
                                                    html: '<strong>Google Analytics requires an API Key to work.</strong><br />You can register your key at <a href="http://www.google.com/analytics/" target="_blank"><img src="/common/images/google_analytics.png" style="position: relative; top: 10px; left: 2px; border="0" /></a><br /><br />'
                                                  }),
                                                  {
                                                    fieldLabel: 'API Key',
                                                    width: 200,
                                                    name: 'school_analytics'
                                                  }
                                                ]
                                    };
        var extra_Tab = {
                                        title: 'Misc. Options',
                                        autoHeight:true,
                                        autoShow: true,
                                        id: loadMode ? 'tabSchoolSettingsEditor_extra' : 'winSchoolSettingsEditor_extra',
                                        labelWidth: 85, // label settings here cascade unless overridden
                                        waitMsgTarget: !Ext.isIE,
                                        reader : new Ext.data.XmlReader({
                                              record : 'result',
                                              success : '@success'
                                          }, xmlCols),
                                        defaultType: 'textfield',
                                        defaults: {anchor: '0'},
                                        labelWidth: 1,
                                        items :[{
                                                  xtype: 'checkbox',
                                                  fieldLabel: '',
                                                  boxLabel: 'Enable Chat',
                                                  name: 'school_usechat'
                                                },{
                                                  xtype: 'checkbox',
                                                  fieldLabel: '',
                                                  boxLabel: 'Enable Translator',
                                                  name: 'school_usetranslator'
                                                },{
                                                  xtype: 'checkbox',
                                                  fieldLabel: '',
                                                  boxLabel: 'Swear Filter',
                                                  name: 'school_swearfilter'
                                                },{
                                                  xtype: 'checkbox',
                                                  fieldLabel: '',
                                                  boxLabel: 'Warn about External Links',
                                                  name: 'school_externalwarn'
                                                },{
                                                  xtype: 'checkbox',
                                                  fieldLabel: '',
                                                  boxLabel: 'Enable Holiday Mode (when extra graphics and/or effects are available)',
                                                  name: 'school_holidaymode'
                                                }]
                                    };
                                    
        function showShareHelper(cb,c){
          if (cb.inputValue == '1' && c){
            Ext.getCmp('sharing_defined_list').setDisabled(false);
          }else if(cb.inputValue == '1' && !c){
            Ext.getCmp('sharing_defined_list').setDisabled(true);
          }
        }
        var sharing_Tab = {
                                        title: 'Sharing Options',
                                        autoHeight:true,
                                        autoShow: true,
                                        id: loadMode ? 'tabSchoolSettingsEditor_sharing' : 'winSchoolSettingsEditor_sharing',
                                        waitMsgTarget: !Ext.isIE,
                                        reader : new Ext.data.XmlReader({
                                              record : 'result',
                                              success : '@success'
                                          }, xmlCols),
                                        defaults: {anchor: '0'},
                                        xtype: 'fieldset',
                                        labelWidth: 1,
                                        layout: 'form',
                                        items :[{
                                                    xtype: 'radiogroup',
                                                    columns: 1,
                                                    name: 'share_enabled',
                                                    items: [
                                                        {boxLabel: 'Disable', name: 'share_enabled', inputValue: '0', listeners: { check : showShareHelper }},
                                                        {boxLabel: 'Enable', name: 'share_enabled', inputValue: '1', listeners: { check : showShareHelper }}
                                                    ]
                                                },{
                                                    xtype: 'checkboxgroup',
                                                    id: 'sharing_defined_list',
                                                    columns: 1,
                                                    disabled: true,
                                                    items: [
                                                        {boxLabel: 'Share on Facebook', name: 'share_ext_0'},
                                                        {boxLabel: 'Share on Delicious', name: 'share_ext_1'},
                                                        {boxLabel: 'Share on StumbleUpon', name: 'share_ext_2'},
                                                        {boxLabel: 'Share on Digg', name: 'share_ext_3'},
                                                        {boxLabel: 'Share on Reddit', name: 'share_ext_4'},
                                                        {boxLabel: 'Share on Newsvine', name: 'share_ext_5'},
                                                        {boxLabel: 'Share on Magnolia', name: 'share_ext_6'}
                                                    ]
                                                }]
                                    };
                                    
        var terms_Tab = {
                                        title: 'Terms and Conditions',
                                        autoHeight:true,
                                        autoShow: true,
                                        id: loadMode ? 'tabSchoolSettingsEditor_terms' : 'winSchoolSettingsEditor_terms',
                                        labelWidth: 85, // label settings here cascade unless overridden
                                        waitMsgTarget: !Ext.isIE,
                                        reader : new Ext.data.XmlReader({
                                              record : 'result',
                                              success : '@success'
                                          }, xmlCols),
                                        padding: 0,
                                        defaults: {anchor: '0'},
                                        labelWidth: 1,
                                        items: {
                                                  xtype: 'htmleditor',
                                                  height: 300,
                                                  name: 'schoool_legal_terms'
                                                }
                                    };
                                    
        var privacy_Tab = {
                                        title: 'Privacy Policy',
                                        autoHeight:true,
                                        autoShow: true,
                                        id: loadMode ? 'tabSchoolSettingsEditor_privacy' : 'winSchoolSettingsEditor_privacy',
                                        labelWidth: 85, // label settings here cascade unless overridden
                                        waitMsgTarget: !Ext.isIE,
                                        reader : new Ext.data.XmlReader({
                                              record : 'result',
                                              success : '@success'
                                          }, xmlCols),
                                        padding: 0,
                                        defaults: {anchor: '0'},
                                        labelWidth: 1,
                                        items :{
                                                  xtype: 'htmleditor',
                                                  height: 300,
                                                  name: 'schoool_legal_privacy'
                                                }
                                    };
                                    
        var customCSS_Tab = {
                                        title: 'Custom CSS Styles',
                                        autoHeight:true,
                                        autoShow: true,
                                        id: loadMode ? 'tabSchoolSettingsEditor_customCSS' : 'winSchoolSettingsEditor_customCSS',
                                        labelWidth: 85,
                                        waitMsgTarget: !Ext.isIE,
                                        reader : new Ext.data.XmlReader({
                                              record : 'result',
                                              success : '@success'
                                          }, xmlCols),
                                        padding: 0,
                                        defaults: {anchor: '0'},
                                        labelWidth: 1,
                                        items :{
                                                  xtype: 'textarea',
                                                  height: 300,
                                                  name: 'schoool_custom_css'
                                                }
                                    };
                                    
        var customJS_Tab = {
                                        title: 'Custom Javascript',
                                        autoHeight:true,
                                        autoShow: true,
                                        id: loadMode ? 'tabSchoolSettingsEditor_customJS' : 'winSchoolSettingsEditor_customJS',
                                        labelWidth: 85,
                                        waitMsgTarget: !Ext.isIE,
                                        reader : new Ext.data.XmlReader({
                                              record : 'result',
                                              success : '@success'
                                          }, xmlCols),
                                        padding: 0,
                                        defaults: {anchor: '0'},
                                        labelWidth: 1,
                                        items :{
                                                  xtype: 'textarea',
                                                  height: 300,
                                                  name: 'schoool_custom_js'
                                                }
                                    };

        var tabItems = isSpecial ? [ies_Tab,info_Tab,contact_Tab,google_Tab,sharing_Tab,extra_Tab,terms_Tab,privacy_Tab,customCSS_Tab,customJS_Tab] : [info_Tab,contact_Tab,google_Tab,sharing_Tab,extra_Tab,terms_Tab,privacy_Tab];
        
        var schoolSiteConfigTab = new Ext.FormPanel({
                    title: 'General Info',
                    padding: 5,
                    id: loadMode ? 'tabSchoolSettingsEditor' : 'winSchoolSettingsEditor',
                    layout: 'fit',
                    waitMsgTarget: !Ext.isIE,
                    reader : new Ext.data.XmlReader({
                          record : 'result',
                          success : '@success'
                      }, xmlCols),
                    bodyStyle: 'background: #DFE8F6',
                    autoScroll: true,
                    items: new Ext.Panel({
                          layout: 'border',
                          border: false,
                          items: [
                            new Ext.Panel({
                              region: 'north',
                              border: true,
                              html: '<div class="siteConfigInfo"><div class="siteConfigHeader">Here you can configure your site!</div><div class="siteConfigText">'+navInfo+'</div></div>'
                            }),
                            new Ext.Panel({
                              region: 'center',
                              activeTab: 0,
                              margins: '5 0 0 0',
                              bodyStyle:'padding: 5px 10px 0',
                              border: true,
                              plain: true,
                              autoScroll: true,
                              defaults: {autoScroll:true, xtype: 'fieldset', bodyStyle:'padding:15px 10px 0'},
                              items: tabItems
                                  })
                                ]
                              })
                  });
        
        
        
        if (loadMode){
          schoolSiteConfigTab.title = 'General';
          return schoolSiteConfigTab;
        }
          
        var winSchoolSettingsEdit = new Ext.Window({
              width:400,
              height:550,
              title: 'School Settings Editor',
              layout:'fit',
              closeAction:'close',
              modal:true,
              closable:false,
              border:false,
              maximizable:true,
              items: schoolSiteConfigTab,
              buttons: [{
                text: 'Save',
                handler: saveSchoolForm
              },{ text: 'Cancel', handler: function(){ winSchoolSettingsEdit.close(); } }],
              listeners: {
                show: function(win){
                  var prefix = loadMode ? 'tabSchoolSettingsEditor' : 'winSchoolSettingsEditor';
                  Ext.getCmp(prefix).getForm().load({url:'/ajax/siteconfig/site/getSiteConfig.cfm?s='+schoolID, waitMsg:'Loading Setting...'});
                  /*
                  Ext.getCmp(prefix+'_site').getForm().load({url:'/ajax/siteconfig/site/getSiteConfig.cfm?s='+schoolID, waitMsg:'Loading Setting...'});
                  Ext.getCmp(prefix+'_contact').getForm().load({url:'/ajax/siteconfig/site/getSiteConfig.cfm?s='+schoolID, waitMsg:'Loading Setting...'});
                  Ext.getCmp(prefix+'_google').getForm().load({url:'/ajax/siteconfig/site/getSiteConfig.cfm?s='+schoolID, waitMsg:'Loading Setting...'});
                  Ext.getCmp(prefix+'_extra').getForm().load({url:'/ajax/siteconfig/site/getSiteConfig.cfm?s='+schoolID, waitMsg:'Loading Setting...'});
                  */
                }
              }
          });
        if (treenode)
          winSchoolSettingsEdit.setTitle('School Settings - ' + treenode.text);
        winSchoolSettingsEdit.show(this);
      }
      
      
reportingIn('generalTab');