  
  var win;
  var isReady = false;
  Ext.onReady(function () {
    isReady = true;
  });
  
  function scopeEdit(el, id, gcdID, monthID, monthName, subjectID, subjectName){
    if (!isReady){
      setTimeout("scopeEdit(" + id + ")", 1000);
      return false;
    }
    
    dialogHeight = 500;
		
    var scopeEdit = {
		title: "Scope Info", 
		height: dialogHeight, 
		html: '<iframe src="/ajax.cfm?frame=true&a=scope&mode=edit&tab=detail&id=' + id + '&month=' + monthID + '&gcdID=' + gcdID + '&sid=' + subjectID + '&s=' + currentSchoolAlias + '" style="width: 100%; border: 0; height: 100%"></iframe>'
		};
    
    var tabHolder = new Ext.TabPanel({
                                        activeTab: 0,                                   
                                        region: 'center',
                                        height: dialogHeight,
                                        items:[
                                         scopeEdit
                                        ]
                                    });

		var modTitle = "Scope & Sequence For " + subjectName + " in " + monthName;		

		var infoBox = {region: 'north', baseCls: '', cls: 'dialogHelpTitle', height: 48, border: 0, html: '<strong style="font-size: 13px; font-weight: bold">' + modTitle + '</strong><br /><a href="#">Click here to learn more about staff administration</a>'};

		var helpText = "<strong>Username</strong> is how the user will login to the site.<br /><br /><strong>First Name</strong> of the user logging in<br /><br /><strong>Last Name</strong> of the user logging in<br /><br/><br />...";
		var helpBox = {region: 'east', title: 'Help', split: true, width: 200, minSize: 150, layout:'fit', collapsible: true,  cls: 'dialogHelp', items: [{bodyStyle: 'padding: 10px; font-size: 1.4em', html: helpText}]};

    win = new Ext.Window({
      title: "Scope Editor",
      minWidth: 320,
      width: 600,
			layout:'fit',
      height: dialogHeight + 48,
      layout: 'border',
      modal: true,
      maximizable: true,
      closeAction: 'hide',
      items: [infoBox, tabHolder],
      buttons: [{
            text: 'Close',
            handler: function(){
             processUpdate('content', id);
              win.hide();
            }
          }]
      });
    win.show();
  }
  
  
  function subjectEdit(el, id, gcdID){
    
	var infoBox = {region: 'north', baseCls: '', cls: 'dialogHelpTitle', height: 48, border: 0, html: '<strong style="font-size: 13px; font-weight: bold">Type the new subject in the text area</strong>'};
	
	var subjectBox = {region: 'center', baseCls: '', cls: '', height: 48, border: 0, autoLoad: '/ajax.cfm?frame=true&a=scope&mode=edit&tab=subject&id=' + id + '&gcdID=' + gcdID + '&s=' + currentSchoolAlias };

	win = new Ext.Window({
      title: "Subject",
      minWidth: 320,
      width: 250,
	  layout:'fit',
      height: 250,
      layout: 'border',
      modal: true,
      maximizable: false,
      closeAction: 'hide',
      buttons: [],
      items: [infoBox,subjectBox],
      keys: {
        key: 27, // Esc key
        handler: function(){ win.hide(); },
        scope: this
      }
    });
    win.show();
  }
  
	function hmkEdit(options){
		if (!isReady){
			setTimeout("hmkEdit(" + 1 + ")", 1000);
			return false;
		}
		
		var tabHolder = new Ext.TabPanel({
																				activeTab: 0,                                   
																				region: 'center',
																				height: 300,
																				items:[
																				 scopeEdit
																				]
																		});


		win = new Ext.Window({
			title: "Scope Editor",
			minWidth: 320,
			width: 600,
			layout:'fit',
			height: 348,
			layout: 'border',
			modal: true,
			maximizable: true,
			closeAction: 'hide',
			items: [tabHolder],
			buttons: [{
						text: 'Close',
						handler: function(){
						 processUpdate('content', 1);
							win.hide();
						}
					}]
			});
		win.show();
	}
  
  
  	function subjectDel(el, id){
		
		Ext.Msg.confirm('Item Deletion','Are you sure you would like to delete this item?', 
						function(btn){
								if(btn == 'yes') {
									deleteItem(el, id);
                  $('scopelist').width = $('scopelist').getWidth() - 200;

									new Ajax.Request('/ajax/delete_subject.cfm', { method: 'post', parameters: {data: id}});
								}
							}
						);
	
	}
  
  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') {
									$(el).update('<a href="#" onclick="scopeEdit(\'scope_' + monthID + '_' + gcdID + '\',0,' + gcdID + ',' +monthID+',\''+ monthName +'\','+subjectID+',\''+subjectName+'\')\">Add</a>');
									new Ajax.Request('/ajax/delete_item.cfm', { method: 'post', parameters: {data: id}});
								}
							}
						);
	
	}
  

