
    function hideEl(el){
      var showEl = Ext.get(el);
      showEl.addClass('hiddenVis');
    }
    function showEl(el){
      var showEl = Ext.get(el);
      showEl.removeClass('hiddenVis');
    }

    window.onbeforeunload = function(){
      if (openEditors>0 && !restartREQUIRED)
        return "You have "+openEditors+" active editor window"+(openEditors!=1?'s':'')+" open. You will lose any unsaved work if you continue.";
    }; 

    String.prototype.stripHTML = function () {
        var reTag = /<(?:.|\s)*?>/g;
        return this.replace(reTag, "");
    };
    Ext.state.Manager.setProvider(new Ext.state.CookieProvider({
        expires: new Date(new Date().getTime()+(1000*60*60*24*7)) //7 days from now
    }));
    Ext.onReady(function(){
      Ext.QuickTips.init();
    });

    function checkShared(cls,val){
      $$('.share_sites_'+cls).each(function(s){if(val=='inv'){s.checked=!s.checked;}else{s.checked=val;}});
    }
    

    
    //Main Editor Class
    var fckCount=0;
    var openEditors=0;
    function callEditor(initOptions){

      var shareStore = new Ext.data.Store({
        autoLoad: true,
        url: '/ajax/editor/getSitesList.cfm',
        reader : new Ext.data.JsonReader({
            root : 'sites'                           
          },[
            {name: 'id', mapping: 'id'},
            {name: 'title', mapping: 'title'}
          ]
        )
      });
      //shareStore.load();
      
      var timeStore = new Ext.data.Store({
        autoLoad: true,
        url: '/ajax/editor/getTimes.cfm',
        reader : new Ext.data.JsonReader({
            root : 'times'                           
          },[
            {name: 'id', mapping: 'id'},
            {name: 'title', mapping: 'title'}
          ]
        )
      });
      
      var periodStore = new Ext.data.Store({
        autoLoad: true,
        url: '/ajax/editor/getPeriods.cfm',
        reader : new Ext.data.JsonReader({
            root : 'periods'                           
          },[
            {name: 'id', mapping: 'id'},
            {name: 'title', mapping: 'title'}
          ]
        )
      });
      
      var slowIEWarningEdit = new Ext.Panel({
                                              region: 'south', 
                                              margins: '5 0 0 0', 
                                              padding: 6, 
                                              bodyStyle: 'text-align: center; font-size: 10px', 
                                              html: '<strong>Tip:</strong> Editing content with <a href="http://www.mozilla.com/en-US/firefox/" target="_blank" style="color: black;">Firefox</a> or <a href="http://www.google.com/chrome" target="_blank" style="color: black;">Google Chrome</a> will enable more functionality including: Image Management, Paste from Word, Table Creation and more!', hidden: !Ext.isIE});
       
      var myFckCount = ++fckCount;
    

      //clearTimeout(RefreshID);
      var _self = this;
      var _settings = {};
        
      var editPanel = {};
      var theTabs = [];
      
      _settings.titleMaxLen = 200;
      _settings.dataTruncateLen = 600;
      _settings.editorModal = false;
      _settings.editorParentID = 0;
      _settings.editorDataID = 0;
      _settings.editorGCDID = 0;
      _settings.editorGCDID = 0;
      editPanel.showMETA = true;
            
      Ext.apply(_settings, initOptions);
      switch (_settings.editorType){
        case 'news':
          mainContentTitle = 'News Content';
          defWindowTitle = 'News';
          defProperType = 'News';
          editPanel.showGeneral = true;
          editPanel.showCategories = true;
          editPanel.showFiles = true;
          editPanel.showRSVP = false;
          editPanel.showThumbnail = true;
          editPanel.showMap = true;
          editPanel.showExtra = true;
          editPanel.showPublish = true;
          editPanel.showSideBar = true;
          break;
        case 'blog':
          mainContentTitle = 'Blog Content';
          defWindowTitle = 'Blog';
          defProperType = 'Blog';
          editPanel.showGeneral = true;
          editPanel.showCategories = true;
          editPanel.showFiles = true;
          editPanel.showRSVP = false;
          editPanel.showThumbnail = true;
          editPanel.showMap = true;
          editPanel.showExtra = true;
          editPanel.showPublish = true;          
          editPanel.showSideBar = true;
          break;
        case 'podcast':
          mainContentTitle = 'Description';
          defWindowTitle = 'Podcast';
          defProperType = 'Podcast';
          editPanel.showGeneral = true;
          editPanel.showCategories = true;
          editPanel.showFiles = true;
          editPanel.showMediaFiles = true;
          editPanel.showThumbnail = true;
          editPanel.showRSVP = false;
          editPanel.showMap = false;
          editPanel.showExtra = true;
          editPanel.showPublish = true;          
          editPanel.showSideBar = true;
          break;
        case 'cal':
        case 'event':
          mainContentTitle = 'Event Description';
          defWindowTitle = 'Event';
          defProperType = 'Event';
          editPanel.showGeneral = true;
          editPanel.showCategories = true;
          editPanel.showFiles = true;
          editPanel.showShare = true;
          editPanel.showRSVP = true;
          editPanel.showMap = true;
          editPanel.showExtra = true;
          editPanel.showEventPublish = true; 
          editPanel.showEventRepeat = true; 
          editPanel.showSideBar = true;
          break;
        case 'booking':
        case 'bookings':
          mainContentTitle = 'Reservation Description';
          defWindowTitle = 'Booking';
          defProperType = 'Booking';
          editPanel.showGeneral = true;
          editPanel.showCategories = false;
          editPanel.showFiles = true;
          editPanel.showShare = false;
          editPanel.showRSVP = false;
          editPanel.showMap = false;
          editPanel.showMETA = false;
          editPanel.showExtra = false;
          editPanel.showEventPublish = false; 
          editPanel.showBookingsPublish = true; 
          editPanel.showEventRepeat = false; 
          editPanel.showSideBar = true;
          break;
        case 'assignment':
          mainContentTitle = 'Page Content';
          defWindowTitle = 'Page';
          defProperType = 'Page';
          editPanel.showGeneral = true;
          editPanel.showThumbnail = true;
          editPanel.showFiles = true;
          editPanel.showGrading = true;
          editPanel.showDueDate = true;
          editPanel.showPublish = false;          
          editPanel.showSideBar = true;
          break;
        case 'page':
          mainContentTitle = 'Page Content';
          defWindowTitle = 'Page';
          defProperType = 'Page';
          editPanel.showGeneral = true;
          editPanel.showFiles = true;
          editPanel.showSideBar = true;
          break;
        case 'header':
          mainContentTitle = 'Category Content';
          defWindowTitle = 'Header Category';
          defProperType = 'Header Category';
          editPanel.showMETA = false;
          editPanel.showGeneral = true;
          editPanel.showFiles = false;
          editPanel.showSideBar = false;
          break;
        case 'Category':
          mainContentTitle = 'Category Content';
          defWindowTitle = 'Category';
          defProperType = 'Category';
          editPanel.showCategories = true;
          editPanel.showMETA = false;
          editPanel.showGeneral = true;
          editPanel.showFiles = false;
          editPanel.showSideBar = false;
          break;
        case 'Department':
          mainContentTitle = 'Department Content';
          defWindowTitle = 'Department';
          defProperType = 'Department';
          editPanel.showCategories = false;
          editPanel.showMETA = false;
          editPanel.showGeneral = true;
          editPanel.showPeriods = true;
          editPanel.showFiles = false;
          editPanel.showSideBar = true;
          break;
        case 'Class':
          mainContentTitle = 'Class Content';
          defWindowTitle = 'Class';
          defProperType = 'Class';
          editPanel.showCategories = false;
          editPanel.showMETA = false;
          editPanel.showGeneral = true;
          editPanel.showPeriods = true;
          editPanel.showFiles = false;
          editPanel.showSideBar = true;
          break;
        case 'Forum':
          mainContentTitle = 'Forum Category';
          defWindowTitle = 'Forum';
          defProperType = 'Forum';
          editPanel.showGeneral = true;
          break;
        case 'page_widget':
          mainContentTitle = 'Page Content';
          defWindowTitle = 'Page';
          defProperType = 'Page';
          editPanel.showGeneral = true;
          editPanel.showFiles = true;
          editPanel.showExtra = false;
          editPanel.showSideBar = false;
          break;
        case 'jobs':
          mainContentTitle = 'Job Description';
          defWindowTitle = 'Job';
          defProperType = 'Job';
          editPanel.showGeneral = true;
          editPanel.showCategories = true;
          editPanel.showFiles = true;
          editPanel.showMap = true;
          editPanel.showExtra = true;
          editPanel.showEventPublish = true;
          editPanel.showSideBar = true;
          break;
        default:
          return false;
      }      
      _settings.editorProperType = defProperType;
      _settings.editorWindowName = defWindowTitle;
            
      function doPageUpdate(closeWindow){
        
          var theItem = $$('.item_'+_settings.editorDataID);
          
          //if (!theItem)
          //  return false;
              
          var dataTitle = $('editTitle_'+_settings.winName).value;
          var summaryText = $('editPanel_content_'+_settings.winName).value;
          if($('editPanel_meta_summary_'+_settings.winName)&&_settings.dataTruncateLen>0)
            if($('editPanel_meta_summary_'+_settings.winName).value!='')
              summaryText = $('editPanel_meta_summary_'+_settings.winName).value;
          
          if($(theItemData))
            if(_settings.dataTruncateLen>0)
              summaryText = '<p>'+summaryText.stripHTML().truncate((_settings.dataTruncateLen+123), '... <a href="/#request.cyberschool.school.alias#/'+_settings.editorType+'&amp;mode=detail&amp;id='+_settings.editorDataID+'">View Article &raquo;</a>')+'</p>';

                    
          theItem.each(function(el, index){

            el.select('.data_title_text').each(function(s){
              s.update(dataTitle);
            });
            
            el.select('.data_header_link').each(function(s){
              s.update(dataTitle);
            });
            
            el.select('.data_body_content').each(function(s){
              s.update(summaryText);
            });

          });

        if (1==2){
          if ($('item_title_top'))
            var theItemTitle1 = $('item_title_top');
          if ($('item_title_'+_settings.editorDataID))
            var theItemTitle2 = $('item_title_'+_settings.editorDataID);
          if ($('item_data_'+_settings.editorDataID))
            var theItemData = $('item_data_'+_settings.editorDataID);

          if($(theItemTitle1))
            theItemTitle1.update($('editTitle_'+_settings.winName).value);
          if($(theItemTitle2))
            theItemTitle2.update($('editTitle_'+_settings.winName).value);
            
          var summaryText = $('editPanel_content_'+_settings.winName).value;
          //summaryText = summaryText.replace('src="','_src="');
          //summaryText = summaryText.replace('_cke_saved_src="','src="');       
          //summaryText = summaryText.replace('href="','_href="');
          //summaryText = summaryText.replace('_cke_saved_href="','href="');
          
          if($('editPanel_meta_summary_'+_settings.winName)&&_settings.dataTruncateLen>0)
            if($('editPanel_meta_summary_'+_settings.winName).value!='')
              summaryText = $('editPanel_meta_summary_'+_settings.winName).value;
          
          if($(theItemData)){
            if(_settings.dataTruncateLen>0)
              theItemData.update('<p>'+summaryText.stripHTML().truncate((_settings.dataTruncateLen+123), '... <a href="/#request.cyberschool.school.alias#/'+_settings.editorType+'&amp;mode=detail&amp;id='+_settings.editorDataID+'">View Article &raquo;</a>')+'</p>');
            else
              theItemData.update(summaryText);
          }
          setTimeout(function(){if($(theItem))theItem.highlight();},1000);
          
        }
        if (_settings.myPortlet)
          _settings.myPortlet.storeFN(_settings.myPortlet);
        if (_settings.navigationContextNode){
          var myFormVals = Ext.getCmp('editPanel_main_'+_settings.winName).getForm().getValues();          
          var curNavNode = _settings.navigationContextNode;
          curNavNode.setText(myFormVals.editor_title);
          if (_settings.editorType == "Forum" || _settings.editorType == "Category" || _settings.editorType == "header")
            curNavNode.attributes.id = _settings.editorDataID;
          curNavNode.attributes.title = myFormVals.editor_title;
          curNavNode.attributes.linkName = myFormVals.editor_title;
          if (curNavNode.attributes.data_type=="department" || curNavNode.attributes.data_type=="class"){
            curNavNode.attributes.gcd_id = _settings.editorDataID;
            curNavNode.setText(myFormVals.editor_title + ' (' + curNavNode.attributes.user_fullname + ')');
          }else{
            curNavNode.attributes.data_id = _settings.editorDataID;
          }
        }
        
        var theWin = Ext.getCmp('editPanel_win_'+_settings.winName);
        if (closeWindow && theWin.modal==true){
          var tUrl = defURLhref + Ext.getCmp('editTitleURL_'+_settings.winName).getValue();
          theWin.close();
          if (!_settings.navigationContextNode){
            Ext.MessageBox.wait('Loading Post Data...','Please wait');            
            if (currentURLCGIURL == tUrl){
              window.location.reload(true);
            }else{
              window.location.href = tUrl;
            }
          }
        }else if(closeWindow){
          theWin.close();
          
        }
      }
      function updateEditorTitle(){
        //checkForDirtyForm(true);
        var tmpTitle = _settings.editorTitle;
        if (_settings.editorWindowName)
          tmpTitle += ' - ' + _settings.editorWindowName;
		if(Ext.getCmp('editPanel_win_'+_settings.winName))  
        Ext.getCmp('editPanel_win_'+_settings.winName).setTitle(tmpTitle);
      }
      function checkForDirtyForm(skipTimer){
        return true;
        var form = mainPanel; //Ext.getCmp('editPanel_main_'+_settings.winName);
        if (form.getForm().isValid())
          setWindowTitle('Editing',true);
        else
          setWindowTitle('Editing (errors exist in form)',true);
        if (!skipTimer)
          setTimeout(function(){checkForDirtyForm();},1000);
      }
      function setEditorTitle(title, dontUpdate){
        _settings.editorTitle = title;
        if (!dontUpdate)
          updateEditorTitle();
      }
      function setWindowTitle(title, dontUpdate){
        _settings.editorWindowName = title;
        if (!dontUpdate)
          updateEditorTitle();
      }
      function checkRemainingCharacters(el, max){
        var el = $(el);
		var theValue = '<i>Untitled</i>';
        if (el && el.value.trim())
          theValue = el.value;
			setEditorTitle(theValue);
			var tmpRemain = max - theValue.length;
			if (Ext.getCmp('editTitle_Remain_'+_settings.winName).body)
			Ext.getCmp('editTitle_Remain_'+_settings.winName).body.update(tmpRemain + ' Characters Remaining');
		
      }
      function checkEditTitle(event, _settings, maxSize){
        var el = Event.element(event);
        if (el.value.length >= maxSize && event.keyCode != 8 && event.keyCode != 127 && (event.charCode >= 32 && event.charCode <= 126)){
          event.cancelBubble = true;
          event.returnValue = false;
          event.preventDefault();
        }
        checkRemainingCharacters(el, maxSize);        
        setTimeout(function(){checkRemainingCharacters(editTitle, maxSize);}, 10);
        if (el.value.length >= maxSize && event.keyCode != 8 && event.keyCode != 127 && (event.charCode >= 32 && event.charCode <= 126)){
          return false;
        }
      }
      
      function getUniqueTitleUrl(title){
        var tmpTitle = title.replace(/[^a-zA-Z0-9]/g, '-');
        tmpTitle = tmpTitle.replace(/-(-+)/g, '-');
        return tmpTitle.replace(/-$/g, '');
      }
      
      var tmpModuleName = currentPageAction == '' || currentPageAction == 'page' ? '' : currentPageAction + '/';
      var defURLhref= currentURLBaseSchool + tmpModuleName;
      var defURLtitle= '';
      var defURLtitleLast= '';
     
      var editingTitleNow = false;
      var editingTitleSeperate = false;
      
      var title = new Ext.Panel({
          title: defWindowTitle + ' Title',
          id: 'editPanel_title_'+_settings.winName,
          collapsible: true,
          items: 
                    new Ext.form.FieldSet({
                      labelWidth: 50,
                      labelAlign: 'top',
                      border: false,
                      defaults: {
                        anchor: '-30',
                        msgTarget: 'side'
                      },
                      items: [{
                                                  xtype: 'textfield',
                                                  ref: '../TitleFieldField',
                                                  name:'editor_title',
                                                  id: 'editTitle_'+_settings.winName,
                                                  maxLength: _settings.titleMaxLen,
                                                  selectOnFocus: true,
                                                  blankText: 'Title is required',
                                                  enableKeyEvents:true,
                                                  allowBlank: false,
                                                  fieldLabel: 'Title',
                                                  listeners: {
                                                    keypress: function(tf, e){
                                                      setTimeout(function(){
                                                        setEditorTitle(tf.getRawValue());
                                                        
                                                        //alert(defURLtitle + ' == ' + getUniqueTitleUrl(tf.getRawValue()));
                                                        if (editingTitleSeperate && defURLtitle == getUniqueTitleUrl(tf.getRawValue()))
                                                          editingTitleSeperate = false;
                                                        
                                                        if (!editingTitleSeperate){
                                                          defURLtitle = getUniqueTitleUrl(tf.getRawValue());
                                                          defURLtitleLast = defURLtitle;
                                                          var f = tf.ownerCt.ownerCt.UrlFieldField;
                                                          if (!editingTitleNow)
                                                            f.setValue(_settings.editorDataID + '-' + defURLtitle+'.html');
                                                          var df = tf.ownerCt.ownerCt.UrlDisplayField;
                                                          df.setValue(defURLhref +''+ _settings.editorDataID + '-' + defURLtitle+'.html');
                                                          
                                                        }
                                                      },50);
                                                    }
                                                  }
                                              },{
                                                  xtype: 'textfield',
                                                  ref: '../UrlFieldField',
                                                  readOnly: true,
                                                  name:'editor_title_url',
                                                  cls: 'x-form-text-noborder',
                                                  ctCls :'x-form-info',
                                                  id: 'editTitleURL_'+_settings.winName,
                                                  selectOnFocus: true,
                                                  blankText: 'URL is required',
                                                  enableKeyEvents:true,
                                                  allowBlank: false,
                                                  fieldLabel: 'URL Title',
                                                  //value: _settings.editorDataID + '-' + defURLtitle +'.html',
                                                  listeners: {
                                                    keypress: function(tf, e){
                                                      setTimeout(function(){
                                                        var tmpURLtitle = getUniqueTitleUrl(tf.getRawValue());                                                        
                                                        var df = tf.ownerCt.ownerCt.UrlDisplayField;
                                                        df.setValue(defURLhref +''+ _settings.editorDataID + '-' + tmpURLtitle+'.html');
                                                      },50);
                                                    },
                                                    focus: function(f){
                                                      f.setReadOnly(false);
                                                      editingTitleNow=true;
                                                      f.setValue(defURLtitle);
                                                      f.removeClass('x-form-text-noborder');
                                                    },
                                                    blur: function(f){
                                                      if (editingTitleNow)
                                                        defURLtitle = getUniqueTitleUrl(f.getRawValue());
                                                      
                                                      if (editingTitleNow && defURLtitle != defURLtitleLast)
                                                        editingTitleSeperate = true;
                                                        
                                                      editingTitleNow=false;
                                                      f.setReadOnly(true);
                                                      f.setValue(_settings.editorDataID + '-' + defURLtitle+'.html');
                                                      f.addClass('x-form-text-noborder');
                                                      var df = f.ownerCt.ownerCt.UrlDisplayField;
                                                      df.setValue(defURLhref +''+ _settings.editorDataID + '-' + defURLtitle+'.html');
                                                    }
                                                  }
                                              },{
                                                  xtype: 'textfield',
                                                  readOnly: true,
                                                  anchor: '0',
                                                  cls: 'x-form-text-noborder',
                                                  ref: '../UrlDisplayField',
                                                  fieldLabel: 'Full URL',
                                                  value: defURLhref +''+ _settings.editorDataID + '-' + defURLtitle+'.html'
                                              }]
                                            })
        });

        
      function getUnixTime(){
        return parseInt(new Date().getTime().toString().substring(0, 10))
      }
      var thumbnailImage = '/ajax/editor/resizeDataThumb.cfm?d='+_settings.editorDataID+'&type=orig&time=';
      function getThumbnailImage(){
        return thumbnailImage + getUnixTime();
      }
      function performThumbnailUpload(){
        
        var upThumbPanel = new Ext.FormPanel({
                                          labelWidth: 75, // label settings here cascade unless overridden
                                          clientValidation: true,
                                          standardSubmit:false, 
                                          fileUpload: true,
                                          isUpload: true,
                                          method: 'POST',
                                          border: false,
                                          items: [{
                                              border: false,
                                              xtype:'fieldset',
                                              defaults: {
                                                  anchor: '-20',
                                                  msgTarget: 'side'
                                              },
                                              defaultType: 'textfield',
                                              items :[{
                                                        xtype: 'displayfield',
                                                        hideLabel: true,
                                                        html: '<strong>We currently support the following image types:</strong><br /> jpg, png, gif, bmp (<a href="mailto:luis@iescentral.com?subject=Request%20for%20new%20thumbnail%20type%20in%20Editor">Suggest more</a>)<br /><br />'
                                                      },{
                                                        xtype: 'fileuploadfield',
                                                        emptyText: 'Select a image',
                                                        fieldLabel: 'Image File',
                                                        name: 'eventFile_1',
                                                        allowBlank: false,
                                                        buttonText: '',
                                                        buttonCfg: {
                                                            iconCls: 'upload-icon'
                                                        }
                                                      },{
                                                        xtype: 'button',
                                                        anchor: '0',
                                                        cls: 'bigPrint1',
                                                        text: 'Upload Thumbnail',
                                                        style: 'margin-top: 10px',
                                                        handler: function(){
                                                          Ext.Msg.wait('Please wait...', 'Uploading Thumbnail');
                                                          upThumbPanel.getForm().submit({
                                                            clientValidation: true, 
                                                            standardSubmit:false, 
                                                            fileUpload:true,
                                                            isUpload: true,
                                                            method: 'POST',
                                                            url:'/ajax/editor/uploadFile.cfm?t=_',
                                                            params: {
                                                              id: _settings.editorDataID,
                                                              uimg: 1,
                                                              action: _settings.editorType,
                                                              max:4
                                                            },
                                                            reader : new Ext.data.JsonReader({
                                                              success : '@success'
                                                            }),
                                                            success: function(form, action) {
                                                                var thumber = Ext.get('imgThumbPreview_'+ _settings.winName);
                                                                hideEl(thumber.id);
                                                                setTimeout(function(){
                                                                  Ext.Msg.hide();
                                                                  thumber.dom.src = getThumbnailImage();
                                                                }, 100);
                                                                winUploadThumbnail.hide();
                                                            },
                                                            failure: function(form, action) {
                                                              Ext.Msg.hide();
                                                              switch (action.failureType) {
                                                                  case Ext.form.Action.CLIENT_INVALID:
                                                                      Ext.Msg.alert('Failure', 'Please verify 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);
                                                              }
                                                            }
                                                          });
                                                        }
                                                      }
                                              ]
                                          }]
                                      });


        var winUploadThumbnail = new Ext.Window({title: 'Select a New Thumbnail', width: 400, height: 200, modal: true, resizable: false, closeAction:'close', items:upThumbPanel,
            buttons: [{
                        text: 'Cancel',
                        handler: function(){
                          winUploadThumbnail.close();
                        }
                      }]
        });
        winUploadThumbnail.show(this);
      }

      var thumbnailHelper = new Ext.Panel({
        title: 'Thumbnail',
        collapsible: true,
        bbar: [{
                text: 'Upload Image...',
                iconCls: 'upload-icon',
                handler: function(){doImageUpload();}
              },{
                text: 'Remove',
                iconCls: 'clear-icon',
                handler: function(){
                  Ext.Msg.wait('Please wait...', 'Removing Thumbnail');
                  Ext.Ajax.request({
                    url: '/action/deleteThumbnailFile.cfm',
                    reader : new Ext.data.JsonReader({
                      success : '@success'
                    }),
                    method: 'GET',
                    success: function(){
                      var thumber = Ext.get('imgThumbPreview_'+ _settings.winName);
                      hideEl(thumber.id);
                      setTimeout(function(){
                        Ext.Msg.hide();
                        thumber.dom.src = getThumbnailImage();
                      }, 100);
                    },
                    failure: function(){
                      Ext.Msg.hide();
                      Ext.Msg.alert('Error', 'There was an error removing the thumbnail for this entry. Please try again');
                    },
                    params: { id: _settings.editorDataID }
                  });
                }
              }],
        bodyStyle: 'padding: 0 5px; background: url(/common/images/ajax-fb.gif) center center no-repeat; min-height: 100px',
        html: '<img id="imgThumbPreview_'+ _settings.winName + '" onload="showEl(this);" src="'+ getThumbnailImage() +'" class="pngfix hiddenVis" style="background: white; width: 100%" />'
      });
      var publishHelper = new Ext.Panel({
          title: 'Publishing',
          collapsible: true,
          items: [
                    new Ext.form.FieldSet({
                      labelWidth: 50,
                      xtype: 'fieldset',
                      border: false,
                      defaults: {
                        anchor: '-30',
                        msgTarget: 'side'
                      },
                      defaultType: 'datefield',
                      items: [{
                          fieldLabel: 'Publish',
                          name:'editor_date_start',
                          id: 'startdt_'+_settings.winName,
                          vtype: 'daterange',
                          endDateField: 'enddt_'+_settings.winName,
                          blankText: 'Date to Publish is required',
                          allowBlank: false
                        },new Ext.form.ComboBox({
                          store: timeStore,
                          triggerAction: 'all',
                          allowBlank:false, 
                          editable: false,
                          mode: 'local',
                          hiddenName: 'editor_publish_time',
                          id: 'editor_publish_time_'+_settings.winName,
                          valueField: 'id',
                          displayField: 'title'
                      }),{
                          fieldLabel: 'Archive',
                          name:'editor_date_archive',
                          id: 'enddt_'+_settings.winName,
                          vtype: 'daterange',
                          startDateField: 'startdt_'+_settings.winName,
                          allowBlank: true
                        }]
                    })
                  ]
        });
      var publishEventHelper = new Ext.Panel({
          title: 'Event Duration',
          collapsible: true,
          items: [
                    new Ext.form.FieldSet({
                      labelWidth: 40,
                      xtype: 'fieldset',
                      border: false,
                      defaults: {
                        anchor: '-30',
                        msgTarget: 'side'
                      },
                      defaultType: 'datefield',
                      items: [{
                          fieldLabel: 'Start',
                          name:'event_start_date',
                          id: 'event_start_date_'+_settings.winName,
                          //vtype: 'daterange',
                          //endDateField: 'event_end_date_'+_settings.winName,
                          blankText: 'Date to Publish is required',
                          allowBlank: false
                        },new Ext.form.ComboBox({
                          store: timeStore,
                          triggerAction: 'all',
                          allowBlank:false, 
                          editable: false,
                          mode: 'local',
                          hiddenName: 'event_start_time',
                          id: 'event_start_time_'+_settings.winName,
                          valueField: 'id',
                          displayField: 'title'
                      }),{
                          fieldLabel: 'End',
                          name:'event_end_date',
                          id: 'event_end_date_'+_settings.winName,
                          vtype: 'daterange',
                          startDateField: 'event_start_date_'+_settings.winName,
                          allowBlank: true
                        },new Ext.form.ComboBox({
                          store: timeStore,
                          triggerAction: 'all',
                          allowBlank:true, 
                          editable: false,
                          mode: 'local',
                          hiddenName: 'event_end_time',
                          id: 'event_end_time_'+_settings.winName,
                          valueField: 'id',
                          displayField: 'title'
                      })]
                    })
                  ]
        });
        var catStore = new Ext.data.Store({
            autoLoad: true,
            url: '/ajax/editor/getCategories.cfm?type='+_settings.editorType+'&groupID='+_settings.editorGCDID,
            reader : new Ext.data.JsonReader({
                root : 'categories'                           
              },[
                {name: 'id', mapping: 'id'},
                {name: 'title', mapping: 'title'},
                {name: 'desc', mapping: 'desc'}
              ]
            )
        });
      catStore.load();
        var publishBookingsHelper = new Ext.Panel({
          title: 'Reservation Options',
          collapsible: true,
          items: [
                    new Ext.form.FieldSet({
                      labelWidth: 40,
                      xtype: 'fieldset',
                      labelAlign: 'top',                       
                      border: false,
                      defaults: {
                        anchor: '-30',
                        msgTarget: 'side'
                      },
                      defaultType: 'datefield',
                      items: [{
                          fieldLabel: 'Booking Date',
                          name:'event_start_date',
                          id: 'event_start_date_'+_settings.winName,
                          blankText: 'Date to Publish is required',
                          allowBlank: false
                        },new Ext.form.ComboBox({
                          fieldLabel: 'From the beginning of',
                          store: periodStore,
                          triggerAction: 'all',
                          allowBlank:false, 
                          editable: false,
                          mode: 'local',
                          hiddenName: 'event_start_period',
                          id: 'event_start_period_'+_settings.winName,
                          valueField: 'id',
                          displayField: 'title'
                      }),new Ext.form.ComboBox({
                          fieldLabel: 'To The End of',
                          store: periodStore,
                          triggerAction: 'all',
                          allowBlank:false, 
                          editable: false,
                          mode: 'local',
                          hiddenName: 'event_end_period',
                          id: 'event_end_period_'+_settings.winName,
                          valueField: 'id',
                          displayField: 'title'
                      }), new Ext.form.ComboBox({
                        store: catStore,
                        triggerAction: 'all',
                        allowBlank:false, 
                        editable: false,
                        mode: 'local',
                        fieldLabel: 'Location',
                        hiddenName: 'editor_category',
                        //name: 'editor_category',
                        id: 'editor_category_'+_settings.winName,
                        valueField: 'id',
                        displayField: 'title'
                      })]
                    })
                  ]
        });
      var DueDateHelper = new Ext.Panel({
          title: 'Assignment Duration',
          collapsible: true,
          items: [
                    new Ext.form.FieldSet({
                      labelWidth: 40,
                      xtype: 'fieldset',
                      border: false,
                      defaults: {
                        anchor: '-30',
                        msgTarget: 'side'
                      },
                      defaultType: 'datefield',
                      items: [{
                          fieldLabel: 'Start',
                          name:'event_start_date',
                          id: 'event_start_date_'+_settings.winName,
                          //vtype: 'daterange',
                          //endDateField: 'event_end_date_'+_settings.winName,
                          blankText: 'Date to Publish is required',
                          allowBlank: false
                        },{
                          fieldLabel: 'Due',
                          name:'event_end_date',
                          id: 'event_end_date_'+_settings.winName,
                          vtype: 'daterange',
                          startDateField: 'event_start_date_'+_settings.winName,
                          allowBlank: true
                        }]
                    })
                  ]
        });


      var repeatTypes= [
                          //[0, 'Does not repeat'],
                          [1, 'Every day (Mon-Sun)'],
                          [2, 'Every weekday (Mon-Fri)'],
                          [3, 'Every weekend (Sat-Sun)'],
                          [4, 'Every Mon., Wed., and Fri.'],
                          [5, 'Every Tues., and Thurs.'],
                          [6, 'Weekly'],
                          [7, 'Monthly'],
                          [8, 'Yearly']
                        ];
      var repeatStore = new Ext.data.ArrayStore({
          fields: [
             {name: 'id', mapping: 0},
             {name: 'title', mapping: 1}
          ]
      });
      repeatStore.loadData(repeatTypes);
      
      var eventRecurringHelper = new Ext.Panel({
          title: 'Recurring Event',
          collapsible: true,
          items: new Ext.form.FieldSet({
                    labelAlign: 'top',
                    xtype: 'fieldset',
                    border: false,
                    padding: 0,
                    defaults: {
                      anchor: '-30'
                    },
                    items: [new Ext.form.ComboBox({
                                                    store: repeatStore,
                                                    triggerAction: 'all',
                                                    allowBlank:false, 
                                                    editable: false,
                                                    mode: 'local',
                                                    fieldLabel: 'Repeats',
                                                    hiddenName: 'editor_repeat_type',
                                                    id: 'editor_repeat_'+_settings.winName,
                                                    valueField: 'id',
                                                    displayField: 'title'
                                                  }),{
                                                    xtype: 'spinnerfield',
                                                    fieldLabel: 'Interval',
                                                    name: 'editor_repeat_interval',
                                                    minValue: 1,
                                                    maxValue: 100,
                                                    anchor: '40%',
                                                    incrementValue: 1,
                                                    alternateIncrementValue: 2,
                                                    accelerate: true
                                                  }]
                  })
        });
      
      
      var theMiscPanel = [];
      if (editPanel.showCategories)
        theMiscPanel.push(new Ext.form.ComboBox({
                        store: catStore,
                        triggerAction: 'all',
                        allowBlank:false, 
                        editable: false,
                        mode: 'local',
                        fieldLabel: 'Category',
                        hiddenName: 'editor_category',
                        //name: 'editor_category',
                        id: 'editor_category_'+_settings.winName,
                        valueField: 'id',
                        displayField: 'title'
                      }));
      if (editPanel.showMap)
        theMiscPanel.push({
                        xtype: 'textfield',
                        name:'editor_map_address',
                        id: 'editPanel_map_address_'+_settings.winName,
                        maxLength: 255,
                        selectOnFocus: true,
                        enableKeyEvents:true,
                        fieldLabel: 'Address'
                      });
      if (editPanel.showRSVP)
        theMiscPanel.push({
                        xtype: 'checkbox', 
                        name: 'editor_rsvp',
                        boxLabel: 'Enable RSVP'
                    });
      
      if (theMiscPanel.length > 0)
        var miscHelper = new Ext.Panel({
            title: 'Misc',
            collapsible: true,
            items: [new Ext.form.FieldSet({
                    labelAlign: 'top',
                    xtype: 'fieldset',
                    border: false,
                    padding: 0,
                    defaults: {
                      anchor: '0'
                    },
                    items: theMiscPanel
              })]
          });
          
      if (editPanel.showMETA){
        var metaHelper = new Ext.Panel({
            title: 'Meta Info',
            collapsible: true,
            items: [new Ext.form.FieldSet({
                  labelAlign: 'top',
                  xtype: 'fieldset',
                  border: false,
                  defaults: {
                    anchor: '0',
                    msgTarget: 'side'
                  },
                  defaultType: 'textfield',
                  items: [{
                      xtype:'textfield',
                      fieldLabel: 'Keywords',
                      name:'editor_meta_keywords',
                      id: 'editPanel_meta_keywords_'+_settings.winName,
                      maskRe:/^([, _a-zA-Z0-9\-])+$/,
                      maxLength: 255, 
                      maxLengthText: 'Maximum keyword length is 255 characters',
                      allowBlank: true
                    },{
                      xtype:'textarea',
                      fieldLabel:'Summary',
                      name:'editor_meta_summary',
                      id: 'editPanel_meta_summary_'+_settings.winName,
                      maxLength: 255,
                      maxLengthText: 'Maximum summary length is 255 characters',
                      allowBlank: true,
                      height:160
                    }]
                })
              ]
          });
      }
      var extraHelper = new Ext.Panel({
        padding: 8,
        collapsible: true,
        title: 'Extra',
        html: 'test'
      });

      var periodPanel = {};
      if (editPanel.showPeriods){
        periodPanel = new Ext.Panel({
            title:'Periods',
            collapsible: true,
            items: [new Ext.form.FieldSet({
                                            labelWidth: 30,
                                            border: false,
                                            autoScroll: true, 
                                            items:[
                                              {border: false, bodyStyle: 'padding-bottom: 10px', html: '<strong>Please select the available periods for this class.</strong>'},
                                              new Ext.form.RadioGroup({
                                                  xtype: 'radiogroup',
                                                  hideLabel: true,
                                                  columns: 1,
                                                  fieldLabel: 'Schedule is',
                                                  items: [
                                                    {boxLabel: 'Entire Day', name: 'period_type', inputValue: 'entire_day', listeners: { check : showPeriodHelper }},
                                                    {boxLabel: 'First Half of Day', name: 'period_type', inputValue: 'first_half', listeners: { check : showPeriodHelper }},
                                                    {boxLabel: 'Last Half of Day', name: 'period_type', inputValue: 'last_half', listeners: { check : showPeriodHelper }},
                                                    {boxLabel: 'Various Periods', name: 'period_type', inputValue: 'defined', listeners: { check : showPeriodHelper }}
                                                  ]
                                              }),new Ext.form.CheckboxGroup({
                                                  xtype: 'checkboxgroup',
                                                  id: 'period_defined_list_'+_settings.winName,
                                                  columns: 1,
                                                  disabled: true,
                                                  fieldLabel: '',
                                                  items: [
                                                      {boxLabel: 'Period 0', name: 'period_defined_0'},
                                                      {boxLabel: 'Period 1', name: 'period_defined_1'},
                                                      {boxLabel: 'Period 2', name: 'period_defined_2'},
                                                      {boxLabel: 'Period 3', name: 'period_defined_3'},
                                                      {boxLabel: 'Period 4', name: 'period_defined_4'},
                                                      {boxLabel: 'Period 5', name: 'period_defined_5'},
                                                      {boxLabel: 'Period 6', name: 'period_defined_6'},
                                                      {boxLabel: 'Period 7', name: 'period_defined_7'},
                                                      {boxLabel: 'Period 8', name: 'period_defined_8'}
                                                  ]
                                              })
                                            ]
                                          })
                    ]
          });
        /*
        theTabs.push(new Ext.Panel({title:'Periods', border: false, autoScroll: true, items:[
              {border: false, padding: 12, html: '<strong>Please select the available periods for this class.</strong>'},
              {
                xtype:'fieldset',
                labelWidth: 10,
                border: false,
                autoHeight: true,
                items: [
                  {xtype: 'radio', boxLabel: 'Entire Day', name: 'period_type', inputValue: 'entire_day', listeners: { check : showPeriodHelper }, id: 'period_type_list_'+_settings.winName},
                  {xtype: 'radio', boxLabel: 'First Half (Before Lunch)', name: 'period_type', inputValue: 'first_half', listeners: { check : showPeriodHelper }},
                  {xtype: 'radio', boxLabel: 'Last Half (After Lunch)', name: 'period_type', inputValue: 'last_half', listeners: { check : showPeriodHelper }},
                  {xtype: 'radio', boxLabel: 'Defined List', name: 'period_type', inputValue: 'defined', listeners: { check : showPeriodHelper }}
                  ]
              },{
                  xtype:'fieldset',
                  labelWidth: 30,
                  disabled: true,
                  id: 'period_defined_list_'+_settings.winName,
                  bodyStyle:'padding: 0; margin: 0;',
                  border: false,
                  autoHeight: true,
                  items: [
                    {xtype: 'checkbox', boxLabel: 'Period 0', cls: 'period_defined_'+_settings.winName, name: 'period_defined_0'},
                    {xtype: 'checkbox', boxLabel: 'Period 1', cls: 'period_defined_'+_settings.winName, name: 'period_defined_1'},
                    {xtype: 'checkbox', boxLabel: 'Period 2', cls: 'period_defined_'+_settings.winName, name: 'period_defined_2'},
                    {xtype: 'checkbox', boxLabel: 'Period 3', cls: 'period_defined_'+_settings.winName, name: 'period_defined_3'},
                    {xtype: 'checkbox', boxLabel: 'Period 4', cls: 'period_defined_'+_settings.winName, name: 'period_defined_4'},
                    {xtype: 'checkbox', boxLabel: 'Period 5', cls: 'period_defined_'+_settings.winName, name: 'period_defined_5'},
                    {xtype: 'checkbox', boxLabel: 'Period 6', cls: 'period_defined_'+_settings.winName, name: 'period_defined_6'},
                    {xtype: 'checkbox', boxLabel: 'Period 7', cls: 'period_defined_'+_settings.winName, name: 'period_defined_7'},
                    {xtype: 'checkbox', boxLabel: 'Period 8', cls: 'period_defined_'+_settings.winName, name: 'period_defined_8'}
                  ]
              }
            ]
          })
        );
        */
      }

      
      var theHelpers = [];
      
      theHelpers.push(title);
      
      if(editPanel.showSideBar){
        if(editPanel.showThumbnail)
          theHelpers.push(thumbnailHelper);
        if(editPanel.showPeriods)
          theHelpers.push(periodPanel);
        if (editPanel.showPublish)
          theHelpers.push(publishHelper);
        if (editPanel.showEventPublish)
          theHelpers.push(publishEventHelper);
        if (editPanel.showBookingsPublish)
          theHelpers.push(publishBookingsHelper);
        if (editPanel.showEventRepeat)
          theHelpers.push(eventRecurringHelper);
        if (editPanel.showDueDate)
          theHelpers.push(DueDateHelper);
        if (miscHelper)
          theHelpers.push(miscHelper);
        if (metaHelper)
          theHelpers.push(metaHelper);
      }
        
      if (theHelpers.length > 0){
        var sideHelper = new Ext.Panel({
          id: 'editPanel_help_'+_settings.winName,
          autoScroll: true,
          region: 'east',
          title: 'Details',
          margins: '-1 0 -1 0',
          split: true,
          width: 235,
          collapsible: true,
          padding: 5,
          //layout: 'accordion',
          defaults: {
            //layout: 'fit',
            border: true,
            style: {marginBottom: '5px'}
          },
          items: theHelpers
        });
      }
      if (editPanel.showGeneral){
        if (Ext.isIE){
          var editorStructStuff = {
                            region: 'center',
                            xtype:'htmleditor',
                            name:'editor_content',
                            id:'editPanel_content_'+_settings.winName,
                            fieldLabel:'Content',
                            frame: false
                          };
        }else{
          var editorStructStuff = {
                            region: 'center',
                            xtype:'fckeditor',
                            ref:'theFCKEditor',
                            name:'editor_content',
                            id:'editPanel_content_'+_settings.winName,
                            fieldLabel:'Content'
                          };
        }
        
        theTabs.push(new Ext.Panel({
                          title: mainContentTitle,
                          layout: 'fit',
                          items: editorStructStuff
                      }));
        
      }
      if (editPanel.showRSVP && 1==2){
        var readerRSVP = new Ext.data.ArrayReader({}, [
           {name: 'name'},
           {name: 'type'},
           {name: 'adult'},
           {name: 'children'}
        ]);
        theTabs.push({title: 'RSVP',items: {
                      name:'editPanel_rsvp_'+_settings.winName,
                      id:'editPanel_rsvp_'+_settings.winName,
                      fieldLabel:'RSVP',
                      border: false,
                      padding: 10,
                      items: {
                                xtype:'fieldset',
                                checkboxToggle:true,
                                title: 'Use RSVP',
                                checkboxName:'editor_rsvp',
                                autoHeight:true,
                                autoWidth:true,
                                defaultType: 'textfield',
                                collapsed: true,
                                items: new Ext.grid.GridPanel({
                                    store: new Ext.data.GroupingStore({
                                        reader: readerRSVP,
                                        data: [
                                            ['Charlie Jacquez', 'Yes', 1, 2],
                                            ['Scott Steinbeck', 'Maybe', 1, 0],
                                            ['Josh Reed', 'No', 0, 0],
                                            ['Shawn Harrison', 'No', 1, 4]
                                        ],
                                        sortInfo:{field: 'type', direction: 'DESC'},
                                        groupField:'type'
                                    }),

                                    columns: [
                                        {id:'editPanel_col_name_'+_settings.winName, header: 'Name', width: 200, sortable: true, dataIndex: 'name'},
                                        {id:'editPanel_col_type_'+_settings.winName, header: 'Type', width: 80, sortable: true, dataIndex: 'type'},
                                        {id:'editPanel_col_adults_'+_settings.winName, header: 'Adults', width: 60, sortable: true, dataIndex: 'adults'},
                                        {id:'editPanel_col_children_'+_settings.winName, header: 'Childrens', width: 60, sortable: true, dataIndex: 'children'},
                                    ],

                                    view: new Ext.grid.GroupingView({
                                        forceFit:true,
                                        groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
                                    }),
                                    iconCls: 'icon-grid'
                                })  
                            }
                        }
                  });
      }

      function showPeriodHelper(cb,c){
        if (cb.inputValue == 'defined' && c){
          Ext.getCmp('period_defined_list_'+_settings.winName).setDisabled(false);
        }else if(cb.inputValue == 'defined' && !c){
          Ext.getCmp('period_defined_list_'+_settings.winName).setDisabled(true);
        }
      }

      if (editPanel.showShare){       
        var schoolListArr=[];
        var totalShares=shareStore.getTotalCount();
        for(var n=1;n<=totalShares;n++){
          var question = shareStore.getById(n);
          schoolListArr.push({xtype: 'checkbox', boxLabel: question.data['title'], cls: 'share_sites_'+_settings.winName, name: 'share_site_'+question.data['id']});
        }
        
        theTabs.push(new Ext.Panel({title:'Syndication', border: false, autoScroll: true, items:[
                {border: false, padding: 12, html: '<strong>Please choose where you would like to push this content.</strong><br /><br />Select: <a href="" class="selectLink selectAll" onclick="checkShared(\''+_settings.winName+'\', true); return false;">ALL</a> &bull; <a href="" class="selectLink selectNone" onclick="checkShared(\''+_settings.winName+'\', false); return false;">None</a> &bull; <a href="" class="selectLink selectInvert" onclick="checkShared(\''+_settings.winName+'\', \'inv\'); return false;">Invert</a>'},
                {
                  xtype:'fieldset',
                  labelWidth: 10,
                  border: false,
                  autoHeight: true,
                  items:schoolListArr
                }
              ]
            })
          );
      }
      
      if (editPanel.showMap && 1==2)
        theTabs.push(new Ext.Panel({title:'Map', border: false, autoHeight: true, items:[
                {
                  xtype:'fieldset',
                  //autoHeight:true,
                  labelWidth: 50,
                  border: false,
                  items:[{
                          xtype: 'textfield',
                          name:'editor_map_address',
                          id: 'editPanel_map_address_'+_settings.winName,
                          maxLength: 255,
                          anchor: '0',
                          selectOnFocus: true,
                          enableKeyEvents:true,
                          fieldLabel: 'Address'
                        }]
                },
                new Ext.Panel({layout: 'fit', border: false, padding: 10, height: 300, items: 
                  {
                    xtype: 'gmappanel',
                    zoomLevel: 14,
                    gmapType: 'map',
                    region: 'center',
                    border: true,
                    mapConfOpts: ['enableScrollWheelZoom','enableDoubleClickZoom','enableDragging'],
                    mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'],
                    setCenter: {
                      lat: '35.373157',
                      lng: '-119.004488',
                      marker: {title: 'Bakersfield, CA'}
                    }
                  }
                })
              ]
            })
          );
              
      if (editPanel.showExtra && 1==2)
        theTabs.push({title: 'Advanced', layout: 'fit', items: {
                      name:'editPanel_extra_'+_settings.winName,
                      id:'editPanel_extra_'+_settings.winName,
                      fieldLabel:'Extra',
                      autoHeight:true,
                      autoWidth:true,
                      html: 'extra'
                    }
                  });

      if (editPanel.showGrading){
        theTabs.push({title: 'Grading',items: tabGrade(_settings), layout: 'fit'});
      }
      if (editPanel.showFiles){
        var editor = new Ext.ux.grid.RowEditor({
            saveText: 'Update'
        });
        
        var winUploadFiles;
        var winUploadThumbnail;
        var winUploadMedia;
        function performMediaUpload(){
          var upPanel = new Ext.FormPanel({
                                            labelWidth: 75, // label settings here cascade unless overridden
                                            clientValidation: true,
                                            standardSubmit:false, 
                                            fileUpload: true,
                                            isUpload: true,
                                            method: 'POST',
                                            border: false,
                                            items: [{
                                                xtype:'fieldset',
                                                border: false,
                                                autoHeight:true,
                                                defaults: {
                                                    anchor: '-20',
                                                    msgTarget: 'side'
                                                },
                                                defaultType: 'textfield',
                                                items :[{
                                                          xtype: 'displayfield',
                                                          hideLabel: true,
                                                          html: '<strong>We currently support the following file extentions:</strong><br /> mp3, wav, avi, mpg, mpeg, wmv, mov, m4v, flv (<a href="mailto:luis@iescentral.com?subject=Request%20for%20new%20media%20type%20in%20Podcast">Suggest more</a>)<br /><br />'
                                                        },{
                                                          xtype: 'fileuploadfield',
                                                          emptyText: 'Select a file',
                                                          fieldLabel: 'Media File',
                                                          name: 'eventFile_1',
                                                          allowBlank: false,
                                                          buttonText: '',
                                                          buttonCfg: {
                                                            iconCls: 'upload-icon'
                                                          }
                                                        },{
                                                          xtype: 'displayfield',
                                                          style:'color:red',
                                                          html:'Please limit your uploads to under 100mb'
                                                        }
                                                ]
                                            }]
                                        });


          if (!winUploadMedia)
            winUploadMedia = new Ext.Window({
              title: 'Upload Podcast Media', width: 450, resizable: false, modal: true, closeAction:'hide', items:upPanel,
              buttons: [{
                          xtype: 'button',
                          text: 'Upload',
                          handler: function(){
                            Ext.Msg.alert('Notice', 'This file may take a few minutes to show up in the "File" Tab while conversion takes place.');
                            upPanel.getForm().submit({
                              clientValidation: true, 
                              standardSubmit:false, 
                              fileUpload:true,        
                              isUpload: true,
                              method: 'POST',
                              url:'/ajax/editor/uploadFile.cfm?t=_', 
                              waitMsg:'Uploading to '+_settings.editorProperType+'...',
                              params: {
                                id: _settings.editorDataID,
                                action: _settings.editorType,
                                max:1,
                                uq:1
                              },
                              errorReader : new Ext.data.JsonReader({
                                  root:'errors',
                                  successProperty:'success'
                                }, ['id', 'msg']),
                              success: function(form, action) {
                                  //Ext.getCmp('editPanel_win_'+_settings.winName).close();
                                  store.reload();
                                  winUploadMedia.hide();
                              },
                              failure: function(form, action) {
                                switch (action.failureType) {
                                    case Ext.form.Action.CLIENT_INVALID:
                                        Ext.Msg.alert('Failure', 'Please verify 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);
                                }
                              }
                            });
                          }
                        },{
                          xtype: 'button',
                          text: 'Cancel',
                          handler: function(){
                            winUploadMedia.hide();
                          }
                        }]
            });
          winUploadMedia.show(this);
        }
        function performFileUpload(isVideoUpload){
        
          if(isVideoUpload)
            return performMediaUpload();
          
          var upPanel = new Ext.FormPanel({
                                            labelWidth: 75, // label settings here cascade unless overridden
                                            clientValidation: true,
                                            standardSubmit:false, 
                                            fileUpload: true,
                                            isUpload: true,
                                            method: 'POST',
                                            border: false,
                                            items: [{
                                                xtype:'fieldset',
                                                border: false,
                                                autoHeight:true,
                                                defaults: {
                                                    anchor: '-20',
                                                    msgTarget: 'side'
                                                },
                                                defaultType: 'textfield',
                                                items :[{
                                                          xtype: 'displayfield',
                                                          hideLabel: true,
                                                          html: '<strong>We currently support the following file extentions:</strong><br /> jpg, gif, png, bmp, jpeg, notebook, doc, docx, pub, xls, zip, rar, ppt, txt, mp3, wav, avi, mpg, mpeg, wmv, mov, m4v, flv, pdf, xbk<br />(<a href="mailto:luis@iescentral.com?subject=Request%20for%20new%20media%20type%20in%20Podcast">Suggest more</a>)<br /><br />'
                                                        },{
                                                          xtype: 'fileuploadfield',
                                                          emptyText: 'Select a file',
                                                          fieldLabel: 'File #1',
                                                          name: 'eventFile_1',
                                                          allowBlank: false,
                                                          buttonText: '',
                                                          buttonCfg: {
                                                              iconCls: 'upload-icon'
                                                          }
                                                        },/*{
                                                          xtype: 'button',
                                                          hideLabel: true,
                                                          text: 'Upload More',
                                                          listeners: {
                                                            click: function(b,e ){
                                                              b.ownerCt.file2.setVisible(true);
                                                              b.ownerCt.file2.removeClass('hidden');
                                                              b.ownerCt.file3.setVisible(true);
                                                              b.ownerCt.file4.setVisible(true);
                                                            }
                                                          }
                                                        },*/{
                                                          xtype: 'fileuploadfield',
                                                          emptyText: 'Select a file',
                                                          fieldLabel: 'File #2',
                                                          name: 'eventFile_2',
                                                          ref: 'file2',
                                                          buttonText: '',
                                                          buttonCfg: {
                                                              iconCls: 'upload-icon'
                                                          }
                                                        },{
                                                          xtype: 'fileuploadfield',
                                                          emptyText: 'Select a file',
                                                          fieldLabel: 'File #3',
                                                          name: 'eventFile_3',
                                                          ref: 'file3',
                                                          buttonText: '',
                                                          buttonCfg: {
                                                              iconCls: 'upload-icon'
                                                          }
                                                        },{
                                                          xtype: 'fileuploadfield',
                                                          emptyText: 'Select a file',
                                                          fieldLabel: 'File #4',
                                                          name: 'eventFile_4',
                                                          ref: 'file4',
                                                          buttonText: '',
                                                          buttonCfg: {
                                                              iconCls: 'upload-icon'
                                                          }
                                                        },{
                                                          xtype: 'displayfield',
                                                          style:'color:red',
                                                          html:'Please limit your upload to under 100mb'
                                                        }
                                                ]
                                            }]
                                        });


          //if (!winUploadFiles)
          winUploadFiles = new Ext.Window({title: 'Upload Resource Files', width: 450, resizable: false, modal: true, closeAction:'close', items:upPanel,
            buttons: [{
                        xtype: 'button',
                        text: 'Upload',
                        handler: function(){
                          upPanel.getForm().submit({
                            clientValidation: true, 
                            standardSubmit:false, 
                            fileUpload:true,        
                            isUpload: true,
                            method: 'POST',
                            url:'/ajax/editor/uploadFile.cfm?t=_', 
                            waitMsg:'Uploading to '+_settings.editorProperType+'...',
                            params: {
                              id: _settings.editorDataID,
                              action: _settings.editorType,
                              max:4
                            },
                            errorReader : new Ext.data.JsonReader({
                                root:'errors',
                                successProperty:'success'
                              }, ['id', 'msg']),
                            success: function(form, action) {
                                //Ext.getCmp('editPanel_win_'+_settings.winName).close();
                                store.reload();
                                winUploadFiles.close();
                            },
                            failure: function(form, action) {
                              switch (action.failureType) {
                                  case Ext.form.Action.CLIENT_INVALID:
                                      Ext.Msg.alert('Failure', 'Please verify 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);
                              }
                            }
                          });
                        }
                      },{
                        xtype: 'button',
                        text: 'Cancel',
                        handler: function(){
                          winUploadFiles.hide();
                        }
                      }]
          });
          winUploadFiles.show(this);
          //upPanel.getForm().setValues({eventFile_1: '', eventFile_2: '', eventFile_3: '', eventFile_4: ''});
        }
        function doUpload(isVideoUpload){
          if (_settings.editorDataID==0){
            Ext.Msg.show({
              title:'Save document?',
              msg: 'New documents must be saved before you can upload files. Would you like to save now?',
              buttons: Ext.Msg.YESNO,
              fn: function(val){
                switch(val){
                  case 'yes':
                    saveForm(false, 1, isVideoUpload);
                    break;
                    
                  default:
                    return false;
                    break;
                }
              },
              animEl: 'elId',
              icon: Ext.MessageBox.QUESTION
            });
          }else{
            performFileUpload(isVideoUpload);
          }
        }
		
		function doImageUpload(){
          if (_settings.editorDataID==0){
            Ext.Msg.show({
              title:'Save document?',
              msg: 'New documents must be saved before you can upload Thumbnails. Would you like to save now?',
              buttons: Ext.Msg.YESNO,
              fn: function(val){
                switch(val){
                  case 'yes':
                    saveForm(false, 2, false);
                    break;
                    
                  default:
                    return false;
                    break;
                }
              },
              animEl: 'elId',
              icon: Ext.MessageBox.QUESTION
            });
          }else{
            performThumbnailUpload();
          }
        }

        var fileButtons = [];


        function ajaxRenameFile(record){
          var params = {fileID : record.id, fileTitle: record.get('filetitle'), fileDesc: record.get('filedesc'), fileName: record.get('filename'), priority: record.get('priority'), op : 'rename'};
          Ext.Ajax.request({
             url: '/ajax/editor/renameFile.cfm',
             reader : new Ext.data.JsonReader({
              success : '@success'
             }),
             success: function(response, opts) {
                var obj = Ext.decode(response.responseText);
                store.reload();
             },
             failure: function(response, opts) {
                store.reload();
                Ext.Msg.alert('Renaming failed', 'Whoops. We were unable to update \'' + record.get('filename') + '\'<br/><br/>Please contact your system administrator.');
             },
             method: 'GET', 'params': params
          });
        }
        function ajaxDeleteFile(store, record, index ){
          var params = {fileID : record.id, op : 'delete'};
          Ext.Ajax.request({
             url: '/ajax/editor/deleteFile.cfm',
             reader : new Ext.data.JsonReader({
              success : '@success'
             }),
             success: function(response, opts) {
                var obj = Ext.decode(response.responseText);
                return true;
             },
             failure: function(response, opts) {
                store.reload();
                Ext.Msg.alert('Deletion failed', 'Whoops. We were unable to recycle \'' + record.get('filename') + '\'<br/><br/>Please contact your system administrator.');
                return false;
             },
             method: 'GET', 'params': params
          });
        }
        
        var store = new Ext.data.GroupingStore({
            autoLoad: true,
            proxy: new Ext.data.HttpProxy ({
              url: '/ajax/editor/getFiles.cfm'
            }),
            baseParams: {id: _settings.editorDataID},
            reader : new Ext.data.XmlReader({
                record : 'file',
                id: 'id',
                success : '@success'
              },[
                  {name: 'id', mapping: 'id'},
                  {name: 'filetitle', mapping: 'filetitle'},
                  {name: 'filedesc', mapping: 'filedesc'},
                  {name: 'filename', mapping: 'filename'},
                  {name: 'filetype', mapping: 'filetype'},
                  {name: 'filesize', mapping: 'filesize', convert: Ext.util.Format.fileSize},
                  {name: 'priority', mapping: 'priority', type: 'int'}
                ]
            ),
            listeners: {
              update : function(store, record, operation ){
                switch (operation){
                  case 'edit':
                    ajaxRenameFile(record);
                 }
              },
              remove : ajaxDeleteFile
            },
            sortInfo: {field: 'priority', direction: 'ASC'}
        });
        var publicSortingOrder = {
                            hidden: true,
                            ref: '../PublicSortingOrder',
                            iconCls: 'iconSort',
                            id: 'orderButton_'+_settings.winName,
                            text: 'Public Sorting Order',
                            handler: function(){
                              if (store.getCount() < 2){
                                Ext.Msg.alert('No Files!', 'You must upload at least 2 files to change their Public Sorting Order.');
                                return false;
                              }
                              var newfiles = store.getRange();
                              if (newfiles.length < 2){
                                Ext.Msg.alert('Not Enough Files!', 'You must upload at least 2 files to change their Public Sorting Order.');
                                return false;
                              }
                              //alert(newfiles.toSource());
                              newfiles.each(function(c){c.leaf=true; c.id = c.data.id; c.text = c.data.filetitle || c.data.filename;});
                              newfiles = newfiles.sortBy(function(s) {return s.data.priority;});
                              
                              var treePanner = new Ext.tree.TreePanel({
                                            region: 'center',
                                            useArrows: true,
                                            autoScroll: true,
                                            containerScroll: true,
                                            animate: true,
                                            enableDD: true,
                                            rootVisible: false,
                                            root: {
                                                nodeType: 'async',
                                                text: 'Files',
                                                draggable: false,
                                                children: newfiles
                                            }
                                        });
                              
                              var myWin = new Ext.Window({
                                title: 'Public Sorting Order',
                                height: 450,
                                width: 350,
                                resizable: true,
                                border: false,
                                layout: 'border',
                                modal: true,
                                items: [ {region: 'north', padding: 5, margins: '0 0 5 0', html: '<strong>Drag and Drop files to specify the Public Sorting Order.</strong><br /><br />Click \'Update\' below when you are finished.'},
                                         treePanner
                                      ],
                                buttons: [{text: 'Update', handler: function(){
                                  var nnn=0;
                                  treePanner.getRootNode().childNodes.each(function(s){
                                      //alert(s.toSource());
                                      var rec = store.getById(s.id); 
                                      rec.beginEdit();
                                      rec.set('priority', nnn++); 
                                      rec.endEdit();
                                  });
                                  myWin.close();
                                }},{text:'Cancel', handler: function(){ myWin.close();} }]
                              });
                              myWin.show(this);
                            }
                            };
        
        var editor = new Ext.ux.grid.RowEditor({
            saveText: 'Update'
        });
        var expander = new Ext.ux.grid.RowExpander({
            tpl : new Ext.Template(
                '<p><b>Summary:</b> {filedesc}</p>'
            )
        });

        var theGrid = new Ext.grid.GridPanel({
                                                border: false,
                                                store: store,
                                                margins: '0 5 5 5',
                                                stripeRows: true,
                                                view: new Ext.grid.GroupingView({
                                                    markDirty: false
                                                }),
                                                plugins: [editor],
                                                columns: [new Ext.grid.RowNumberer(),
                                                        {
                                                          id: 'filetitle_'+_settings.winName,
                                                          header: 'File Title',
                                                          dataIndex: 'filetitle',
                                                          sortable: true,
                                                          width: 100,
                                                          editor: {
                                                            xtype: 'textfield',
                                                            maxLength: 200,
                                                            allowBlank: true
                                                          }
                                                        },{
                                                          id: 'filedesc_'+_settings.winName,
                                                          header: 'File Description',
                                                          dataIndex: 'filedesc',
                                                          sortable: true,
                                                          width: 300,
                                                          editor: {
                                                            xtype: 'textarea',
                                                            maxLength: 1000,
                                                            allowBlank: true
                                                          }
                                                        },{
                                                          id: 'filename_'+_settings.winName,
                                                          header: 'Filename',
                                                          dataIndex: 'filename',
                                                          sortable: true/*,
                                                          editor: {
                                                            xtype: 'textfield',
                                                            maxLength: 50,
                                                            allowBlank: false
                                                          }*/
                                                        },{
                                                          id: 'filetype_'+_settings.winName,
                                                          header: 'Type',
                                                          dataIndex: 'filetype',
                                                          width: 60,
                                                          sortable: true
                                                        },{
                                                          id: 'filesize_'+_settings.winName,
                                                          header: 'Filesize',
                                                          dataIndex: 'filesize',
                                                          width: 60,
                                                          sortable: true
                                                        },{
                                                          id: 'filesize_'+_settings.winName,
                                                          header: 'P.S.O.',
                                                          dataIndex: 'priority',
                                                          width: 40,
                                                          sortable: true
                                                        }],
                                                autoExpandColumn: 'filetitle_'+_settings.winName
                                            });
                                        
        theTabs.push({title: 'Files',items: theGrid, layout: 'fit',
                        listeners: {
                          activate: function(){
                            win.ReloadDataButton.hide();
                            win.ReloadFilesButton.show();
                            win.fileUploadButtonGroup.show();
                            win.PublicSortingOrder.show();
                            win.doLayout(false,true);
                          },
                          deactivate: function(){
                            win.ReloadDataButton.show();
                            win.ReloadFilesButton.hide();
                            win.fileUploadButtonGroup.hide();
                            win.PublicSortingOrder.hide();
                            win.doLayout(false,true);
                          }
                        }
                  });
        theGrid.getSelectionModel().on('selectionchange', function(sm){
            Ext.getCmp('removeButton_'+_settings.winName).setDisabled(sm.getCount() < 1);
        });

      }
        
      var tabs = new Ext.TabPanel({
          id: 'editPanel_tabs_'+_settings.winName,
          region: 'center',
          margins: '5 0 5 5',
          cmargins:'3 3 3 3',
          autoTabs:true,
          plain: true,
          activeTab:0,
          deferredRender:false,
          items: theTabs
        });
      /*var editPanelPanel = new Ext.Panel({
            id: 'editPanel_editor_'+_settings.winName,
            layout: 'border',            
            border: false,
            region: 'center',
            items: [tabs]
          });
      */
      var theItems = [];
      //theItems.push(editPanelPanel);
      theItems.push(tabs);
      if (sideHelper)
        theItems.push(sideHelper);
      theItems.push(slowIEWarningEdit);

      var jsonCols = [];
      jsonCols.push({name: 'editor_title', mapping: 'title'});
      jsonCols.push({name: 'editor_title_url', mapping: 'titleURL'});
      jsonCols.push({name: 'editor_content', mapping: 'content'});
      jsonCols.push({name: 'editor_rsvp', mapping: 'rsvp', type: 'bool'});
      jsonCols.push({name: 'editor_repeat_type', mapping: 'repeat/type'});
      jsonCols.push({name: 'editor_repeat_interval', mapping: 'repeat/interval'});
      jsonCols.push({name: 'editor_map_address', mapping: 'map'});
      jsonCols.push({name: 'editor_meta_keywords', mapping: 'keyword'});
      jsonCols.push({name: 'editor_meta_summary', mapping: 'summary'});
      jsonCols.push({name: 'editor_category', mapping: 'category'});
      jsonCols.push({name: 'editor_date_start', type:'date', mapping: 'dates/start', dateFormat:'m/d/y'});
      jsonCols.push({name: 'editor_date_archive', type:'date', mapping: 'dates/archive', dateFormat:'m/d/y'});
      jsonCols.push({name: 'editor_publish_time', mapping: 'dates/publish/time'});
      jsonCols.push({name: 'event_start_date', type:'date', mapping: 'dates/start', dateFormat:'m/d/y'});
      jsonCols.push({name: 'event_end_date', type:'date', mapping: 'dates/end', dateFormat:'m/d/y'});
      jsonCols.push({name: 'event_start_time', mapping: 'dates/publish/time'});
      jsonCols.push({name: 'event_end_time', mapping: 'dates/finish/time'});
      jsonCols.push({name: 'event_start_period', mapping: 'dates/publish/period'});
      jsonCols.push({name: 'event_end_period', mapping: 'dates/finish/period'});
      
      if (editPanel.showGrading){
        jsonCols.push({name: 'grading_enabled', mapping: 'grading/enabled', type: 'bool'});
        jsonCols.push({name: 'grading_style', mapping: 'grading/style'});
        jsonCols.push({name: 'grading_total_points', mapping: 'grading/total_points'});
        jsonCols.push({name: 'grading_bonus_points', mapping: 'grading/bonuses', type: 'bool'});
      }
      if(editPanel.showPeriods){
        jsonCols.push({name: 'period_type', mapping: 'period/type'});
        for(n=0;n<=8;n++) 
          jsonCols.push({name: 'period_defined_'+n, mapping: 'period/period_'+n, type: 'bool'});
      }
      
      var totalShares=shareStore.getTotalCount();
      for(var n=1;n<=totalShares;n++){
        var question = shareStore.getById(n);        
        jsonCols.push({name: 'share_site_'+question.data['id'], mapping: 'share/site_'+question.data['id'], type: 'bool'});
      }
      
    function getSource(sss) {
        var output = [], temp;
        for (var i in sss) {
            if (sss.hasOwnProperty(i)) {
                temp = i + ":";
                switch (typeof sss[i]) {
                    case "object" :
                        temp += getSource(sss[i]);
                        break;
                    case "string" :
                        temp += "\"" + sss[i] + "\"";    // add in some code to escape quotes
                        break;
                    default :
                        temp += sss[i];
                }
                output.push(temp);
            }
        }
        return "{" + output.join() + "}";
    }
      var mainPanel = new Ext.FormPanel({
            id: 'editPanel_main_'+_settings.winName,
            layout: 'border',
            border: false,
            items: theItems,
            reader : new Ext.data.XmlReader({
                  record : 'result',
                  success : '@success'
              }, jsonCols)
          });

      function windowCloseCheck(){
        if (_settings.navigationContextNode && _settings.editorDataID=="0"){
          var curNavNode = _settings.navigationContextNode;
          curNavNode.setText('stoopie!');
          curNavNode.attributes.deleted = true;
          curNavNode.remove();
        }
        win.close();
      }
      function saveForm(closeOnSave, openUploadOnSave, isVideoUpload){
        
        //mainPanel.getForm().getEl().dom.action = '/ajax/editor/submitEdit.cfm';
        var sb = Ext.getCmp('editPanel_statusbar_'+_settings.winName);
          sb.showBusy('Saving '+_settings.editorProperType+'...');

        //alert(_settings.toSource());
        //alert(_settings.editorGCDID.toSource());

        return mainPanel.getForm().submit({
            clientValidation: true,            
            url:'/ajax/editor/submitEdit.cfm', 
            waitMsg:'Saving '+_settings.editorProperType+'...',
            params: {
              editor_id: _settings.editorDataID,
              editor_gcd_id: _settings.editorGCDID == "false" || !_settings.editorGCDID ? 0 : _settings.editorGCDID,
              editor_type: _settings.editorType,
              editor_parent_id: _settings.editorParentID,
              editor_cat_type: _settings.catType
            },
            errorReader : new Ext.data.JsonReader({
                root:'errors',
                successProperty:'success'
              }, ['id', 'msg']),
            success: function(form, action) {
              if(action.result.data_id)
                _settings.editorDataID = action.result.data_id;
              if (_settings.editorDataID){
                var tf = title.TitleFieldField;
                var tmpURLtitle = getUniqueTitleUrl(tf.getRawValue());                                                        
                var ff = tf.ownerCt.ownerCt.UrlFieldField;
                var df = tf.ownerCt.ownerCt.UrlDisplayField;
                ff.setValue(_settings.editorDataID + '-' + defURLtitleLast+'.html');
                df.setValue(defURLhref +''+ _settings.editorDataID + '-' + defURLtitleLast+'.html');
              }
              doPageUpdate(closeOnSave);
              if (openUploadOnSave == 1)
                performFileUpload(isVideoUpload);
              else if (openUploadOnSave == 2)
                performThumbnailUpload();
              sb.setStatus({
                iconCls: 'x-status-saved',
                text: 'Last saved at ' + new Date().format('g:i:s A')
              });
              /* update navigation */

              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:
                //alert(action.result.toSource());
                  Ext.Msg.show({
                     title:action.result.title,
                     msg: action.result.msg,
                     buttons: Ext.Msg.OK,
                     icon: action.result.errType == 'error' ? Ext.MessageBox.ERROR : Ext.MessageBox.INFO
                  });
              }
              if (action.result.errType == 'error'){
                sb.setStatus({
                  text:'There was an error saving your data, please try again.',
                  iconCls:'x-status-error'
                });
              }else{
                sb.setStatus({
                  iconCls: 'x-status-saved',
                  text: 'Last saved at ' + new Date().format('g:i:s A')
                });
              }
              return false;
            }
        });

      }

      if (Ext.getCmp('editPanel_win_'+_settings.winName))
        return false;

      function setFCKtext(text){
        var fck = $('editPanel_content_'+_settings.winName);
        if (fck.MyisLoaded)
          fck.setValue();
        else
          setTimeout(function(){ setFCKtext(text); },500);
      }

      var triedLoading = 0;
      function loadData(){
        
        Ext.Msg.hide();
        //Ext.Msg.wait('Please Wait...', 'Loading Data');
        if (_settings.navigationContextNode && _settings.navigationContextNode.attributes.cat_id > 0){
          var newURL = '/ajax/editor/getData.cfm?id='+_settings.navigationContextNode.attributes.cat_id+'&type='+_settings.editorType+'&cat_type=category&date='+_settings.editorDefaultDate+'&t='+Number(new Date());
        }else{
          var newURL = '/ajax/editor/getData.cfm?id='+_settings.editorDataID+'&type='+_settings.editorType+'&cat_type='+_settings.catType+'&date='+_settings.editorDefaultDate+'&t='+Number(new Date());
        }
        mainPanel.getForm().load({url: newURL,
          success: function(f,a){
            Ext.Msg.hide();
            setTimeout(function(){
            }, 100);
            Ext.getCmp('saveWindow_'+_settings.winName).setDisabled(false);
            Ext.getCmp('saveCloseWindow_'+_settings.winName).setDisabled(false);

            openEditors++;
                      
            setEditorTitle(a.result.data.editor_title);
            defURLtitle = a.result.data.editor_title_url;
            defURLtitleLast = defURLtitle;
            editingTitleNow = true;
            var tf = Ext.getCmp('editPanel_title_'+_settings.winName);
            
            setTimeout(function(){
              var f = tf.UrlFieldField;
              f.setValue(_settings.editorDataID +'-'+ a.result.data.editor_title_url +'.html');
              
              var df = tf.UrlDisplayField;
              df.setValue(defURLhref + _settings.editorDataID +'-'+ a.result.data.editor_title_url +'.html');
            }, 100);
            
            if(editPanel.showGrading){
              setTimeout(function(){
                  if (a.result.data.grading_enabled)
                    Ext.getCmp('grading_enabled').expand(true);
                  else
                    Ext.getCmp('grading_enabled').collapse(true);
              }, 100);
            }
          }, 
          failure: function(f,a){
            var msg = triedLoading > 0 ? 'Would you like to try loading it again?<br /><br />For cyberschool support please contact <a href="mailto:luis@iescentral.com?subject=Site%20Error%20%5BD-'+_settings.editorDataID+'-'+_settings.editorType+'%5D">Luis Napolitano</a>.<br />[D-'+_settings.editorDataID+'-'+_settings.editorType+']' : 'Would you like to try loading it again?';
            Ext.Msg.show({
              title:'Error Loading Content',
              msg: 'There was an error retreiving your content.<br /><br />' + msg,
              buttons: Ext.Msg.YESNO,
              width: 400,
              fn: function(val){
                triedLoading++;
                if (val == 'yes')
                  setTimeout(function(){loadData();},50);
                else
                  windowCloseCheck();
              },
              icon: Ext.MessageBox.ERROR
            });
          }
        });
      }

        var fileUploadButtons = [];
        if (editPanel.showMediaFiles){
          var fileMediaButton = {
                              iconCls: 'file-media-icon',
                              text: 'Upload Media Files',
                              handler: function(){doUpload(true);}
                            };
          var fileUploadButton = {
                              iconCls: 'file-upload-icon',
                              text: 'Upload Files',
                              handler: function(){doUpload();}
                            };
          fileUploadButtons.push(fileMediaButton);
          fileUploadButtons.push(fileUploadButton);
        }else{
          var fileUploadButton = {
                              iconCls: 'file-upload-icon',
                              text: 'Upload Files',
                              handler: function(){doUpload();}
                            };
          fileUploadButtons.push(fileUploadButton);
        }
        var fileRefreshButton = {
                            iconCls: 'file-refresh-icon',
                            ref: '../../ReloadFilesButton',
                            id: 'refreshButton_'+_settings.winName,
                            hidden: true,
                            text: 'Refresh',
                            handler: function(){
                              store.reload();
                            }
                            };
        var fileRemoveButton = {
                            ref: '../removeBtn',
                            iconCls: 'file-delete-icon',
                            id: 'removeButton_'+_settings.winName,
                            text: 'Delete',
                            disabled: true,
                            handler: function(){
                                Ext.Msg.show({
                                  title:'Recycle File(s)',
                                  msg: 'Are you sure you want to send the selected file(s) to the Trash?',
                                  buttons: Ext.Msg.YESNO,
                                  fn: function(val){
                                    switch(val){
                                      case 'yes':
                                        editor.stopEditing();
                                        var s = theGrid.getSelectionModel().getSelections();
                                        for(var i = 0, r; r = s[i]; i++){
                                            store.remove(r);
                                        }
                                        break;
                                        
                                      default:
                                        return false;
                                        break;
                                    }
                                  },
                                  animEl: 'elId',
                                  icon: Ext.MessageBox.QUESTION
                                });
                              }
                          };      
      
      var toolBarButtons = [];
      toolBarButtons.push({
                            xtype:'buttongroup',
                            items: [{
                                      text:'Save',
                                      scale: 'small',
                                      id: 'saveWindow_'+_settings.winName,
                                      iconCls: 'iconEditorSaveBold',
                                      disabled: true,
                                      handler: function(){
                                          saveForm(false);
                                      }
                                    },{
                                      text:'Save &amp; Close',
                                      scale: 'small',
                                      id: 'saveCloseWindow_'+_settings.winName,
                                      iconCls: 'iconEditorSave',
                                      disabled: true,
                                      handler: function(){
                                          saveForm(true);
                                      }
                                    }]
                            });

        toolBarButtonsRefresh = [];
        toolBarButtonsRefresh.push({
                              text: 'Revert/Reload',
                              ref: '../../ReloadDataButton',
                              scale: 'small',
                              iconCls: 'iconEditorRefresh',
                              handler: function(){
                                    Ext.Msg.show({
                                      title:'Reload data?',
                                      msg: 'Are you sure you want to reload this data? You will lose any recent changes!',
                                      buttons: Ext.Msg.YESNO,
                                      fn: function(v){
                                        if (v=='yes')
                                          loadData();
                                      },
                                      icon: Ext.MessageBox.QUESTION
                                    });
                                        
                                  }
                            });

        if (fileRefreshButton)
          toolBarButtonsRefresh.push(fileRefreshButton);
        toolBarButtons.push({
                              xtype:'buttongroup',
                              items: toolBarButtonsRefresh
                          });
                          
        if (fileUploadButtons && fileRemoveButton)
          toolBarButtons.push({
                                xtype:'buttongroup',
                                ref: '../fileUploadButtonGroup',
                                hidden: true,
                                items: [fileUploadButtons, fileRemoveButton]
                            });
        if (publicSortingOrder)
          toolBarButtons.push(publicSortingOrder);
          
        toolBarButtons.push('->');
        toolBarButtons.push({
                              text: 'Fullscreen',
                              scale: 'small',
                              enableToggle : true,
                              iconCls: 'iconEditorFullscreen',
                              listeners: {
                                toggle: function(b,p){
                                  if (p){
                                    win.maximize();
                                  }else{
                                    win.restore();
                                  }                                
                                }
                              }
                            });
        toolBarButtons.push({
                              text: 'Close Editor',
                              scale: 'small',
                              iconCls: 'iconEditorClose',
                              handler: function(){
                                  windowCloseCheck();
                              }
                            });
      
      var win = new Ext.Window({
          id: 'editPanel_win_'+_settings.winName,
          stateID: 'editPanel_win_'+_settings.winName+'_NEW-1',
          plain: false,
          border: false,
          width:802,
          minWidth: 702,
          height:402,
          minHeight: 302,
          afterFn: _settings.afterFn ? _settings.afterFn : Ext.emptyFn,
          layout:'fit',
          title: 'Loading Editor...',
          closable: false,
          closeAction:'close',
          //maximizable: true,
          modal: _settings.editorModal,
          items: mainPanel,
          tbar: toolBarButtons,
          bbar: new Ext.ux.StatusBar({
            id: 'editPanel_statusbar_'+_settings.winName,
            defaultText: 'Ready'
          }),
          listeners: {
            afterRender: function(w){
              if(w.afterFn)
                w.afterFn();
            },
            show: function(w){
              setTimeout(function(){ loadData(); }, 10);
            },
            close: function(){
              openEditors--;
              if (openEditors<=0)
                openEditors=0;
            }
          }
      });
      win.show(this);
    }