var calendarImportPopup = new Ext.ux.simpleWizard({
	id: 'calendarImportPopup',
	title: 'Import',
	icon: 'images/satin_icons/calendar.png',
	headerText: 'Import a Calendar',
	info: 'Import a calendar from Microsoft Outlook, iCal, or Google Calendar.',
	items: [{
		xtype: 'form',
		id: 'importform',
		fileUpload: true,
		defaults: {
			style: 'margin-left:100px',
			border: false
		},
		items: [{
			xtype: 'label',
			text: 'Choose a file:'
		},
		{
			layout: 'form',
			items: [{
				xtype: 'fileuploadfield',
				id: 'import-file',
				allowBlank: false,
				hideLabel: true,
				width: 300,
				name: 'import-file',
				buttonText: 'Browse',
				buttonCfg: {
					width: 70
				}
			},
			{
				xtype: 'textfield',
				name: 'command',
				value: 'importCalendar',
				hidden: true
			},
			{
				xtype: 'textfield',
				name: 'offset',
				value: (-1 * new Date().getTimezoneOffset()),
				hidden: true
			}]
		}]
	}],
	buttons: [{
		text: 'Import',
		handler: function() {
			var form = Ext.getCmp('importform').getForm();
			//console.log(Ext.getCmp('import-file').getValue());
			//if(form.isValid()){
			form.submit({
				url: 'main_menu/calendar_data.json.php',
				baseParams: {
					command: 'importCalendar'
				},
				success: function(fp, o) { //if success
					eventArray = o.result.eventArray;
					for (i = 0; i < eventArray.length; i++) {
						for (j = 0; j < eventArray[i].length; j++) {
							startTime = eventArray[i][j].startTime;
							if (startTime.UTC == 1) {
								startTimeDate = new Date(startTime.year, startTime.month - 1, startTime.day, 0, 0, 0, 0);
								startTime.tzOffset = startTimeDate.getTimezoneOffset();
							}
							endTime = eventArray[i][j].endTime;
							if (endTime.UTC == 1) {
								endTimeDate = new Date(endTime.year, endTime.month - 1, endTime.day, 0, 0, 0, 0);
								endTime.tzOffset = endTimeDate.getTimezoneOffset();
							}
						}
					}
					Ext.Ajax.request({
						url: 'main_menu/calendar_data.json.php',
						params: {
							command: 'importCalendarDST',
							calendars: Ext.encode(eventArray)
						},
						success: function() {
							Ext.MessageBox.alert('Creation OK', 'uploading data success..');
						},
						failure: function() {
							Ext.MessageBox.alert('Error', 'uploading data failure');
						}
					});
				},
				failure: function(fp, o) { //if not success  
					Ext.MessageBox.alert('Warning', 'failure uploading data...');
				}
			});
			// }
		}
	},
	{
		text: 'Close',
		handler: function(btn) {
			this.ownerCt.ownerCt.hide();
		}
	}]
});

