var lessonplansRetrievePopup = new Ext.Window({
   layout: 'fit',
   closeAction:'hide',
   modal: true,
   resizable: false,
   title: 'Retrieve a Lesson Plan',
   width: 350,
   height: 430,
   bodyStyle: 'background-color: white;',
   autoScroll: true,
   /*
tools: [{
        id:'help',
        handler: function(btn){
            helppopup.loadHelpFile("retrieve a lesson plan", 400, 350);
        }  
   }],
*/
   items: new lessonplansRetrieveGrid(),
   fbar: {
        xtype: 'toolbar',
        items: [
            {
                xtype: 'button',
                text: 'Retrieve',
                id: 'lp_retrieve',
                listeners: {
                    click: function(btn){ 
                        //save new, or changed, assignment
                        var record = Ext.getCmp('lp_retrieve_grid').selModel.getSelected();
         
                        Ext.Msg.show({ 
                            title:'Overwrite current week?', 
                            msg: 'Would you like to view this lesson plan in the current week? If you answer "No" the lesson plan will load as the week of "'+record.data.datefrom+'".', 
                            buttons: Ext.Msg.YESNOCANCEL, 
                            icon: Ext.MessageBox.WARNING,
                            fn: function(btn) {
                                if (btn == 'no') {
                                    dateField = Ext.getCmp('lessonplan_weekof');
                                    dateField.setValue(record.data.datefrom);
                                    dateField.fireEvent('change',dateField, new Date(record.data.datefrom));
                                } else if (btn == 'cancel') {
                                    return false;
                                } else if (btn == 'yes') {
                                   Ext.Ajax.request({
                                     url: 'teacher_tools/lessonplans_data.json.php',
                                     success: function(){
                                        lessonplans.store.load();
                                        assignmentStore.load();
                                     },
                                     failure: function(){},
                                     params: { command: 'retrievePlan', fromdate: record.data.datefrom, todate: record.data.dateto, courseid: Ext.getCmp('lessonplan_course').getValue(), weekof: Ext.getCmp('lessonplan_weekof').getValue().format('m/d/Y')}
                                  });                                        
                                }
                                Ext.getCmp('lessonplan_course').setValue(record.data.courseid);
                                lessonplansRetrievePopup.hide();
                            }
                        });
                    }
                }
            },
            {
                xtype: 'button',
                text: 'Cancel',
                handler: function(btn){ 
                    this.ownerCt.ownerCt.hide();
                } 
            }
        ]
   },
   listeners: {
      show: function (popup) {
         Ext.getCmp('lp_retrieve_teacher').setValue(SchoolDynamics.TeacherID);
         //Ext.getCmp('lp_retrieve_grid').getView().toggleCourse(Ext.getCmp('lessonplan_course').getValue());
      }
   }
});
