calendarCategoryGrid = function(limitColumns, editCategories, command){
  var calSelect = new Ext.grid.CheckColumn({header: 'Display in calendar', dataIndex: 'calDisplay', width: 120, sortable: true, menuDisabled: true});
  var infoDSelect = new Ext.grid.CheckColumn({header: 'Display in InfoDirect', dataIndex: 'infoDDisplay', width: 110, sortable: true, menuDisabled: true});

  if (command == 'schedEventCategories') {
	var rowSelect = new Ext.grid.RadioSelectionModel();
  } else {
	var rowSelect = new Ext.grid.CheckboxSelectionModel();	  
  }
  
  var columns = [
	rowSelect,
    {header: 'Category',width: 150, id: 'calCategoryGridCol', sortable: true, menuDisabled: true, dataIndex: 'category', editor: new Ext.form.TextField()},
    calSelect,
    infoDSelect
  ];
      

    if(limitColumns){
        var cs = [];
        for(var i = 0, len = limitColumns.length; i < len; i++){
            cs.push(columns[limitColumns[i]]);
        }
        columns = cs;
    }
    
    calendarCategoryGrid.superclass.constructor.call(this, {
        store: new Ext.data.Store({
            url : 'main_menu/calendar_data.json.php',
            baseParams: {command: command},
   		   reader: new Ext.data.JsonReader({
			   root: 'eventCategories',
			   idProperty: 'catid',
      			fields: [
                  { name: 'catid', mapping: 'catid' }, 
                  { name: 'cattype', mapping: 'cattype' }, 
                  { name: 'category', mapping: 'category' }, 
                  { name: 'calDisplay', mapping: 'calDisplay', type: 'bool' },
                  { name: 'infoDDisplay', mapping: 'infoDDisplay', type: 'bool' },
                  { name: 'selected', mapping: 'selected', type: 'bool' }
               ]
            }),
            writer: new Ext.data.JsonWriter({writeAllFields: false }),
            autoLoad : false,
            autoSave : false,
            listeners: {
				write: function(){
					if (this.baseParams.command == "filterCategories") {
						calendarstore.reload();
					}
				}
			}
        }),
        columns: columns,
        plugins: [calSelect, infoDSelect],
        sm: rowSelect,
        editCategories: editCategories,
        autoExpandColumn: 'calCategoryGridCol',
        listeners: {
			beforeedit: function() {
				return this.editCategories;
			}
		}  
    });
}

Ext.extend(calendarCategoryGrid, Ext.grid.EditorGridPanel);
