  
  var catWin;
  var currentAction;
  var currentItemID;
 
  var isReady = false;
  Ext.onReady(function () {
    isReady = true;
  });

  var catDetails;
  var catITunes;
  
  var dialogHeight;

  function add2EditCat(ID, currentAction){
    if (ID > 0){
      catWin.setTitle('Updated Category #' + ID + '...');
      currentID = ID;
      if(currentAction == 'podcast'){
      evtFiles = Ext.getCmp('tab_itunes');
      evtFiles.enable();
      evtFiles.html = '<iframe id="filesFormWin" src="' + buildLink(linkFileTabType, ID, 'category', true) + '" style="border: 0; width: 100%; height: 100%"></iframe>';
		}
      evtThumb = Ext.getCmp('tab_uploadThumb');
      evtThumb.enable();
      evtThumb.html = '<iframe id="uploadFormWin" src="' + buildLink('upload_image', ID, 'category', true) + '" style="border: 0; width: 100%; height: 100%"></iframe>';
		
      helpPane = Ext.getCmp('help_pane');
      helpPane.body.update(getTitle(ID, currentAction));
    }
  }
  
    function setEditCatTitle(titleStr){
    if (currentID > 0)
      catWin.setTitle(titleStr);
  }

  //(itemID, gatewayAction){
  function editCategory(itemID, gcdID, gatewayAction, catType){
	
    if (podVideoShowing == true){
        $f(0).hide();
    }
  
    //Set our highlight ID for when we refresh.
    currentID = itemID;
    
    //Ensure these values are
    if (dateHint == '')
      var dateHint = 0;
    if (gcdID == '')
      var gcdID = 0;
    if (ccID == '')
      var ccID = 0;
    
    if (catType == 'channel'){
      var windowTitle = 'Loading Channel #' + itemID + '...';
      if (itemID == 0)
        var windowTitle = 'Add New Channel';
    }else if(catType == 'location'){
      var windowTitle = 'Loading Location #' + itemID + '...';
      if (itemID == 0)
        var windowTitle = 'Add New Location';
      else
        var windowTitle = 'Edit Location';
    }else{
      var windowTitle = 'Loading Category #' + itemID + '...';
      if (itemID == 0)
        var windowTitle = 'Add New Category';
    }
    
    switch(gatewayAction){
      case 'hmk':
      case 'bookings':
      case 'blog':
      case 'gallery':
      case 'gcd':
      case 'jobs':
      case 'assignment':
      case 'news':
      case 'cal':
        break;
        
      case 'podcast':
        linkFileTabType = 'itunes';
        break;
        
      default:
        return false;
        break;
    }
      
    dialogHeight = 550;
    dialogWidth = 680;
    
    catDetails = {
        title: 'Details',
        id: 'tab_detail',
        height: dialogHeight,
        html: '<iframe src="/ajax.cfm?frame=true&a=edit&mode=editCat&id=' + itemID + '&s=' + currentSchoolAlias + '&gcdid=' + gcdID + '&ccAction=' + gatewayAction + '&catType=' + catType + '&new=category&s=' + currentSchoolAlias +'" style="width: 100%; border: 0; height: 100%"></iframe>'
      };
    if (gatewayAction == 'podcast'){
    catITunes = {
        title: 'iTunes',
        id: 'tab_itunes',
        height: dialogHeight,
        html: '<iframe id="filesFormWin" src="' + buildLink(linkFileTabType, itemID, gatewayAction, true) + '" style="border: 0; width: 100%; height: 100%"></iframe>'
      };
      }
    eventUploadImage = {
        title: 'Thumbnail',
        id: 'tab_uploadThumb',
        height: dialogHeight,
        html: '<iframe id="uploadFormWin" src="' + buildLink('upload_image', itemID, 'category', true) + '" style="border: 0; width: 100%; height: 100%"></iframe>'
      };

                   
    if (itemID == 0){
      if (gatewayAction == 'podcast')
        catITunes.disabled = true;
      eventUploadImage.disabled = true;
    }
    
    if (gatewayAction != 'podcast'){
    var tabHolder = 
    new Ext.TabPanel({
                      activeTab: 0,                                                                                
                      region: 'center',
                      height: dialogHeight,
                      items: [catDetails,
                              eventUploadImage]
                  });
    } else {
                       
    var tabHolder = 
    new Ext.TabPanel({
                      activeTab: 0,                                                                                
                      region: 'center',
                      height: dialogHeight,
                      items: [catDetails,
                              catITunes,
                              eventUploadImage]
                  });
    }
                                    
    //,eventUploadImage

  
    var helpBox = {region: 'north', id: 'help_pane', baseCls: '', cls: 'calendarHelpTitle', height: 48, border: 0, html: getTitle(itemID, catType)};

    catWin = new Ext.Window({
        title: windowTitle,
        minWidth: dialogWidth,
        width: dialogWidth,
        minHeight: dialogHeight - 48,
        height: dialogHeight - 48,
        layout: 'border',
        modal: true,
        closeAction: 'hide',
        maximizable: false,
        closable: false,
        items: [helpBox, tabHolder],
        buttons: [{
                    text: 'Close',
                    handler: function(){
                      processWindowUpdate();
                      catWin.hide();
                    }
                  }]
      });
    catWin.show();
  }

  function processWindowUpdate(){
    currentID=0;
    parent.window.location = parent.window.location;
    if (podVideoShowing == true){
        $f(0).show();
    }
	
  }
  
    	function catDel(el, id){
		
		Ext.Msg.confirm('Item Deletion','Are you sure you would like to delete this item? Doing so will delete all items associated with it.', 
						function(btn){if(btn == 'yes') {
							deleteItem(el, id);
							new Ajax.Request('/ajax/delete_cat.cfm', { method: "post", parameters: {data: id}});
							}});
}	
