SD.calendar.addPopup('exportPopup', new Ext.ux.simpleWizard({
	id: 'calendarExportPopup',
	title: 'Export',
	icon: 'images/satin_icons/calendar.png',
	headerText: 'Export a Calendar',
	info: 'Export a calendar to Microsoft Outlook, iCal, or Google Calendar.',
	layout: 'auto',
	items: [{
		xtype: 'form',
		border: false,
		padding: '10 20 20 40',
		id: 'exportform',
		items: [{
			xtype: 'compositefield',
			fieldLabel: 'Date range',
			anchor: '100%',
			items: [{
				xtype: 'radio',
				id: 'exportdaterange',
				flex: 1,
				//fieldLabel: 'Label',
				hideLabel: true,
				//Legacy code?
				boxLabel: 'Month:',
				width: 65,
				inputValue: 'month',
				checked: true,
				name: 'exportdaterange',
				listeners: {
					check: function(radio, checked) {
						if (checked) {
							Ext.getCmp('exportmonth').enable();
							Ext.getCmp('exportmonth').focus();
						} else {
							Ext.getCmp('exportmonth').disable();
						}
					}
				}
			},
			{
				xtype: 'datefield',
				//fieldLabel: 'Label',
				id: 'exportmonth',
				format: 'm/Y'
			}]
		},
		{
			xtype: 'radio',
			boxLabel: 'Entire school year',
			anchor: '100%',
			name: 'exportdaterange',
			inputValue: 'year'
		}]
	}],
	fbar: {
		xtype: 'toolbar',
		items: [{
			xtype: 'button',
			text: 'Export',
			handler: function(btn) {
				var popup = this.ownerCt.ownerCt;
				downloadFileContents('main_menu/calendar_data.json.php', {
					command: 'exportCalendar',
					duration: Ext.getCmp('exportdaterange').getValue().inputValue,
					month: Ext.getCmp('exportmonth').getValue().format('Y-m-d')
				});
			}
		},
		{
			xtype: 'button',
			text: 'Close',
			handler: function(btn) {
				this.ownerCt.ownerCt.hide();
			}
		}]
	},
	listeners: {
		show: function(popup) {
			if (Ext.getCmp('exportdaterange').getValue().inputValue == 'month') {
				Ext.getCmp('exportmonth').setValue(new Date(cal.getCalendarMonth() + '/01/' + cal.getCalendarYear()));
				Ext.getCmp('exportmonth').enable();
				Ext.getCmp('exportmonth').focus();
			}
		}
	}
})
);

