function scopeEdit(initOptions){
    if(!canEdit){
    userLogin();
    scopeWin.close();
    }
    var windowHeight = 110;
    windowWidth = 390;

    var _self = this;
    var _settings = {};
    _settings.scopeID = 0;
    _settings.type = 0;
    _settings.gcdID = 0;    
    _settings.dateBracket = 0;    
    _settings.monthID = 0;    
    _settings.subjectID = 0;    
    _settings.title = 'Subject Editor';  
    
    Ext.apply(_settings, initOptions);
    
    if(_settings.type != 0){
        windowHeight = 310;
        windowWidth = 530;
    }
    function saveInfo(){
      ScopeInfoPanel.getForm().submit({
        clientValidation: true, 
        standardSubmit:false, 
        fileUpload:true,
        url:'/ajax/scope/saveData.cfm', 
        waitMsg:'Saving Changes...',
        params: {
          ID: _settings.scopeID,
          type:_settings.type,
          gcdID: _settings.gcdID,
          dateBracket: _settings.dateBracket,
          subjectID: _settings.subjectID
        },
        errorReader : new Ext.data.JsonReader({
            root:'extra',
            successProperty:'success'
          }, ['ImageID']),
        success: function(form, action) {
            ScopeWin.close();
            //window.location.reload(true);
							if(action.result.dataID != ''){
								var theItem = Ext.get('scope_' + _settings.monthID + '_' + _settings.subjectID);
								var updTemplate = '<a  class="editScope" onclick="scopeEdit({scopeID:' + action.result.dataID + ', monthID:' + _settings.monthID + ', gcdID:' + _settings.gcdID + ', dateBracket:\'' + _settings.dateBracket + '\', subjectID:' + _settings.subjectID + ', title:\'' + _settings.title + '\',type:1}); return false;">Edit</a><a  class="editScope" onclick="scopeItemDel(\'scope_' + _settings.monthID + '_' + _settings.subjectID + '\',' + action.result.dataID + ', ' +_settings.gcdID+ ', ' +_settings.monthID+ ',\'\',' + _settings.subjectID + ', \'' + _settings.title + '\'); return false;">Del</a>' + action.result.data;
								theItem.update(updTemplate);
							} else {
								loadLastPage();			
							}
						},
        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);
          }
        }
      });
    }
    
       
    var formItems = [];
        if(_settings.type == 0)
        formItems.push({fieldLabel: 'Title', anchor:'100%',name: 'title', maxLength:50, maxLengthText: 'Your Title Exceeds 50 Characters'});
        else
        formItems.push({fieldLabel: 'Description', anchor:'100% -20', name: 'desc', xtype: 'htmleditor', maxLength:250, maxLengthText: 'Your Title Exceeds 250 Characters', flex:1});
    
    var xmlCols = [];
        xmlCols.push({name: 'title', mapping: 'title'});
        xmlCols.push({name: 'desc', mapping: 'content'});
  
  
  var ScopeInfoPanel = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        bodyStyle:'padding:5px 5px 0',
        width: 390,
        reader : new Ext.data.XmlReader({
                          record : 'result',
                          success : '@success'
                      }, xmlCols),
        defaults: {width: 230},
        fileUpload:true,
        defaultType: 'textfield',
        items: [
        formItems
        ],
        listeners:{
          render:function(el){
           el.getForm().load({url:'/ajax/scope/getData.cfm?id='+_settings.scopeID+'&type='+_settings.type, waitMsg:'Loading Data....'});
           }
        },
        buttons: [{
            text: 'Save',
            handler: function(){ saveInfo();}
        },{
            text: 'Cancel',
            handler: function(){ ScopeWin.close() }
        }]
    });
    
 var ScopeWin = new Ext.Window({
          plain: true,
          title: _settings.title,
          width:windowWidth,
          minWidth: windowWidth,
          height:windowHeight,
          minheight:windowHeight,
          maxHeight: windowHeight,
          border: false,
          layout:'fit',
          closable: true,
          closeAction:'close',
          maximizable: true,
          modal: false,
          items: ScopeInfoPanel
      });
      ScopeWin.show(this);

};

function subjectDel(el, id){
		Ext.Msg.confirm('Item Deletion','Are you sure you would like to delete this item?', 
						function(btn){
								if(btn == 'yes') {
                  Ext.Ajax.request({
                    url:'/ajax/delete_subject.cfm', 
                    method: 'post', 
                    params: {data: id},
                    success:function(){
                      window.location.reload(true);
                    }
                  }
                  );
								}
							}
						);
	
	}
  
  function scopeItemDel(el, id, gcdID, monthID, monthName, subjectID, subjectName){
		
		Ext.Msg.confirm('Item Deletion','Are you sure you would like to delete this item?', 
						function(btn){
								if(btn == 'yes') {
									Ext.fly(el).update('<a href="" onclick="scopeEdit(\'scope_' + monthID + '_' + gcdID + '\',0,' + gcdID + ',' +monthID+',\''+ monthName +'\','+subjectID+',\''+subjectName+'\')\">Add</a>');
									Ext.Ajax.request({url:'/ajax/delete_item.cfm', method: 'post', params: {data: id}});
								}
							}
						);
	
	}

	
	
	
	// Temporary Spot till i change everything :)
	function hmkEdit(initOptions){
    if(!canEdit){
    userLogin();
    hmkWin.close();
    }
    windowHeight = 310;
    windowWidth = 530;

    var _self = this;
    var _settings = {};
    _settings.ID = 0;
    _settings.weekID = 0;
    _settings.monthID = 0;
    _settings.subjectID = 0;
    _settings.gcdID = currentPage.gcdID;    
    _settings.subjectName = 'None';  

    Ext.apply(_settings, initOptions);
    var monthList = ['January','February','March','April','May','June','July','August','September','October','November','December'];
		var editorTitle = monthList[_settings.monthID] + ' - Week ' + _settings.weekID + ': ' + _settings.subjectName;

    function saveInfo(){
      hmkInfoPanel.getForm().submit({
        url:'/ajax/hmk/saveData.cfm', 
        waitMsg:'Saving Changes...',
        params: {
          gcdID: _settings.gcdID,
          weekID: _settings.weekID,
          monthID: _settings.monthID,
          subjectID: _settings.subjectID
        },
        errorReader : new Ext.data.JsonReader({
            root:'extra',
            successProperty:'success'
          }, ['ImageID']),
        success: function(form, action) {
            hmkWin.close();
						if(action.result.dataID != ''){
								var theItem = Ext.get('sub_'+_settings.subjectID+'_dte_'+_settings.monthID+'_'+_settings.weekID);
								theItem.update(action.result.data);
							} else {
								loadLastPage();			
							}		
						},
        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);
          }
        }
      });
    }
    
       
    var formItems = [];
        formItems.push({fieldLabel: 'dataID', name: 'dataID', xtype: 'hidden'});
        formItems.push({fieldLabel: 'Description', anchor:'100% -20', name: 'desc', xtype: 'htmleditor', maxLength:250, maxLengthText: 'Your Title Exceeds 250 Characters', flex:1});
    
    var xmlCols = [];
        xmlCols.push({name: 'desc', mapping: 'content'});
        xmlCols.push({name: 'dataID', mapping: 'dataID'});
  
  var hmkInfoPanel = new Ext.FormPanel({
        labelWidth: 75, // label settings here cascade unless overridden
        frame:true,
        bodyStyle:'padding:5px 5px 0',
        width: 450,
        reader : new Ext.data.XmlReader({
                          record : 'result',
                          success : '@success'
                      }, xmlCols),
        defaults: {width: 230},
        fileUpload:true,
        defaultType: 'textfield',
        items: [
        formItems
        ],
        listeners:{
          render:function(el){
           el.getForm().load({url:'/ajax/hmk/getData.cfm?weekID=' + _settings.weekID + '&monthID=' + _settings.monthID + '&subjectID=' + _settings.subjectID, waitMsg:'Loading Data....'});
           }
        },
        buttons: [{
            text: 'Save',
            handler: function(){ saveInfo();}
        },{
            text: 'Cancel',
            handler: function(){ hmkWin.close() }
        }]
    });
    
 var hmkWin = new Ext.Window({
          plain: true,
          title: editorTitle,
          width:windowWidth,
          minWidth: windowWidth,
          height:windowHeight,
          minheight:windowHeight,
          maxHeight: windowHeight,
          border: false,
          layout:'fit',
          closable: true,
          closeAction:'close',
          maximizable: true,
          modal: false,
          items: hmkInfoPanel
      });
      hmkWin.show(this);

};




