SD.addPopup('behaviorRequest', new Ext.Window({
	layout: 'fit',
	title: 'Behavior Request',
	width: 450,
	height: 352,
	closeAction: 'hide',
	modal: true,
	tools: [{
		id: 'help',
		handler: function(btn) {
			helppopup.loadHelpFile("Behavior Request", 500, 455);
		}
	}],
	items: [{
		xtype: 'form',
		layout: 'form',
		monitorValid: true,
		id: 'disciplinepopup',
		border: false,
		bodyStyle: 'padding: 10px',
		items: [{
			xtype: 'combo',
			fieldLabel: 'Student Name',
			anchor: '100%',
			name: 'behaviorstudentname',
			id: 'behaviorstudentname',
			width: 300,
			listWidth: 300,
			emptyText: 'Select a student...',
			displayField: 'studentname',
			valueField: 'studentid',
			valueNotFoundText: "",
			allowBlank: false,
			typeAhead: true,
			triggerAction: 'all',
			autoLoad: false,
			store: activestudentnamestore
		},
		{
			xtype: 'datefield',
			fieldLabel: 'Date',
			value: new Date(),
			id: 'submitbehaviordate',
			allowBlank: false,
			anchor: '100%'
		},
		{
			xtype: 'combo',
			fieldLabel: 'Infraction',
			anchor: '100%',
			name: 'infractionid',
			id: 'infractionid',
			width: 300,
			listWidth: 300,
			allowBlank: false,
			emptyText: 'Select an infraction...',
			displayField: 'description',
			valueField: 'infractionid',
			valueNotFoundText: "",
			typeAhead: true,
			triggerAction: 'all',
			store: new Ext.data.Store({
				url: 'main_menu/behaviorrequest_data.json.php',
				baseParams: {
					command: 'getInfractions'
				},
				autoLoad: false,
				reader: new Ext.data.JsonReader({
					root: 'getInfractions'
				}, ['infractionid', 'description'])
			}),
			listeners: {
				select: function(combobox, record, index) {
					Ext.getCmp('behaviorrequestGrid').store.baseParams.studentid = Ext.getCmp('behaviorstudentname').getValue();
					Ext.getCmp('behaviorrequestGrid').store.baseParams.infractionid = Ext.getCmp('infractionid').getValue();
					Ext.getCmp('behaviorrequestGrid').store.load();
				}
			}
		},
		{
			xtype: 'textarea',
			fieldLabel: 'Memo',
			id: 'infractionmemo',
			anchor: '100%'
		},
		new behaviorrequestGrid()],
		listeners: {
			clientvalidation: function(form, valid) {
				if (valid) {
					Ext.getCmp('submitbutton').enable();
				}
				else {
					Ext.getCmp('submitbutton').disable();
				}
			}
		}
	}],
	buttonAlign: 'right',
	buttons: [{
		text: 'Submit',
		id: 'submitbutton',
		disabled: true,
		listeners: {
			click: function(button) {
				Ext.Ajax.request({
					url: 'main_menu/behaviorrequest_data.json.php',
					method: 'POST',
					params: {
						command: 'submitrequest',
						studentid: Ext.getCmp('behaviorstudentname').value,
						infractiondate: Ext.getCmp('submitbehaviordate').value,
						infractionid: Ext.getCmp('infractionid').value,
						memo: Ext.getCmp('infractionmemo').getValue()
					},
					success: function() {
						Ext.getCmp('disciplinepopup').getForm().reset();
						Ext.getCmp('behaviorrequestGrid').store.removeAll();
					},
					failure: function() {
						Ext.Msg.alert('Status', 'Unable to submit behavior notice.');
					}
				});
			}
		}
	},
	{
		text: 'Close',
		handler: function(btn) {
			this.ownerCt.ownerCt.hide();
		}
	}],
	listeners: {
		show: function() {
			Ext.getCmp('behaviorrequestGrid').store.load();
		}
	}
})
);

