var schedulerContent = {
	id: 'schedulerForm',
	xtype: 'form',
	url:'/SubmitScheduler',
    frame: true,
    title: 'Schedule an Appointment',
    labelWidth: 150,
    bodyStyle: 'padding:5px 5px 5px 5px',
    autoScroll: true,
    boxMaxWidth: 600,
    items: [{
		xtype: 'combo',
		id: 'selectType',
		name: 'request',
		fieldLabel: 'I am interested in',
		emptyText: 'Please select one...',
		displayField: 'typeTitle',
		valueField: 'type',
		hiddenName: 'request',
		triggerAction: 'all',
		mode: 'local',
		width: 200,
	    store: new Ext.data.ArrayStore({
	        id: 0,
	        fields: ['type', 'typeTitle'],
	        data: [['A Free Estimate', 'A Free Estimate'], ['Scheduling My Repair', 'Scheduling My Repair']]
	    })
    },{
		xtype: 'combo',
		id: 'selectShop',
		name: 'shop',
		idProperty: 'id',
		fieldLabel: 'Shop Location',
		emptyText: 'Please select one...',
		displayField: 'location',
		valueField: 'id',
		hiddenName: 'shop',
		allowBlank: false,
		triggerAction: 'all',
		mode: 'local',
		width: 200,
		store: new Ext.data.JsonStore({
			root: 'root',
			fields: ['id', 'location' ,'phone'],
			data: { root: shops }
		})
    },{
        xtype: 'textfield',
        name: 'name',
        fieldLabel: 'Name',
        emptyText: '',
        width: 200
    },{
        xtype: 'textfield',
        name: 'address',
        fieldLabel: 'Address',
        emptyText: '',
        width: 200
    },{
        xtype: 'textfield',
        name: 'city',
        fieldLabel: 'City',
        emptyText: '',
        width: 200
    },{
        xtype: 'textfield',
        name: 'state',
        fieldLabel: 'State',
        emptyText: '',
        width: 50,
        maxLength: 2
    },{
        xtype: 'textfield',
        name: 'zip',
        fieldLabel: 'Zip',
        emptyText: '',
        width: 100
    },{
        xtype: 'textfield',
        name: 'phone',
        fieldLabel: 'Phone',
        emptyText: '',
        width: 200
    },{
        xtype: 'textfield',
        name: 'email',
        fieldLabel: 'Email',
        emptyText: '',
        width: 200
    },{
		xtype: 'combo',
		id: 'selectContact',
		name: 'contact',
		fieldLabel: 'Contact by',
		emptyText: 'Please select one...',
		displayField: 'contactTitle',
		valueField: 'contact',
		hiddenName: 'contact',
		triggerAction: 'all',
		mode: 'local',
		width: 200,
	    store: new Ext.data.ArrayStore({
	        id: 0,
	        fields: ['contact', 'contactTitle'],
	        data: [['phone', 'Phone'], ['email', 'Email']]
	    })
    },{
        xtype: 'textfield',
        name: 'car',
        fieldLabel: 'Type of Car',
        emptyText: '',
        width: 200
    },{
		xtype: 'combo',
		id: 'selectRefer',
		name: 'refer',
		fieldLabel: 'Referred by',
		emptyText: 'Please select one...',
		displayField: 'referTitle',
		valueField: 'refer',
		hiddenName: 'refer',
		triggerAction: 'all',
		mode: 'local',
		width: 200,
	    store: new Ext.data.ArrayStore({
	        id: 0,
	        fields: ['refer', 'referTitle'],
	        data: [['Print Ad', 'Print Ad'], ['Web', 'Web'], ['Insurance', 'Insurance'], ['Friend/Family', 'Friend/Family'], ['Repeat Customer', 'Repeat Customer'], ['Other', 'Other']]
	    })
    },{
        xtype: 'textarea',
        name: 'comments',
        fieldLabel: 'Comments/Questions',
        emptyText: '',
        width: 350
    },{
    	xtype: 'hidden',
    	name: 'referrer',
    	value: document.referrer
    }],
    buttonAlign: 'left',
    fbar: [{
    	xtype: 'button',
        text:'Submit Schedule Request',
        cls: 'x-icon-btn',
        handler: function(){
        	var schedulerForm = Ext.getCmp("schedulerForm");
        	schedulerForm.getForm().submit({
				url:'/SubmitScheduler',
				waitMsg: 'Submitting...',
			    success: function(form, action) {
			    	var selectShop = Ext.getCmp("selectShop");
			    	var shopid = selectShop.getValue();
			    	
			    	var phone = '{ <a href="javascript:Ext.getCmp(\'AppPane\').setActiveTab(\'locations_tab\');">choose location</a> }';
			    	if(shopid != ''){
				    	phone = selectShop.store.getById(selectShop.getValue()).data.phone;
			    	}
			    	
			    	schedulerForm.disable();
			    	
					Ext.MessageBox.alert('Schedule Request Submitted',
						'Your schedule request has been forwarded to the appropriate customer service representative.' +
						' Somebody should be contacting you shortly. If you do not hear back from us, feel free to call' +
						' us at anytime at ' + phone + '.');
			    },
			    failure: function(form, action) {
			        switch (action.failureType) {
			            case Ext.form.Action.CLIENT_INVALID:
			                Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
			                break;
			            case Ext.form.Action.CONNECT_FAILURE:
			                Ext.Msg.alert('Failure', 'Server or connection failure');
			                break;
			            case Ext.form.Action.SERVER_INVALID:
			               Ext.Msg.alert('Failure', action.result.msg);
			       }
			    }
        	});
    	}
	}]
};

function Scheduler(shopid)
{
	Ext.getCmp('AppPane').setActiveTab('scheduler_tab');
	
	if(!Ext.getCmp("schedulerForm").disabled)
	{
		Ext.getCmp("selectShop").setValue(shopid);
	}
}
