/**
 * @author George Miller
 */
Ext.onReady(function(){
	
//initalize the quicktips
Ext.QuickTips.init();
//reference the default image
Ext.BLANK_IMAGE_URL = 'ext-2.2.1/resources/images/default/s.gif';

function submitForm(){
	var form = Ext.getCmp('emailform');
						
						if (form.form.isValid()) {
							Ext.MessageBox.show({
            title: 'Please wait',
           msg: 'Saving Edited Data...',
           progressText: 'Collecting items...',
           width:300,
           progress:true,
           closable:false
       });
							form.form.submit({
								params: {
									action: 'submit'
								},
								success: function(form, action){
								
									// this hideous block creates the bogus progress
									var f = function(v){
										return function(){
											if (v == 12) {
												Ext.MessageBox.hide();
												Ext.MessageBox.show({
							title: 'Email Sent Successfully',
							width: 400,
							height: 200,
							msg: 'Thank you for your enquiry, one of our team will reply to your message as soon as possible',
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.INFO
						});
											}
											else {
												var i = v / 11;
												Ext.MessageBox.updateProgress(i, Math.round(100 * i) + '% completed');
											}
										};
									};
									for (var i = 1; i < 13; i++) {
										setTimeout(f(i), i * 200);
									}
							form.reset();
							
								},
								failure: function(form, action){
									if (action.result.errors.length > 0) {
										Ext.MessageBox.show({
							title: 'Error',
							width: 250,
							height: 150,
							msg: action.result.errors,
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.WARNING
						})
									}
								}
							});
						}
						else {
							Ext.MessageBox.show({
							title: 'Error',
							width: 250,
							height: 150,
							msg: 'Please correct indicated errors',
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.WARNING
						})
						}
}

var form = new Ext.form.FormPanel({
	baseCls: 'x-plain',
	renderTo: 'form',
    title: '<div style="padding-left:3px; font-size: 20px; padding-bottom: 5px; color: #82cb39;">Start Your Claim Here</div>',
	labelAlign: 'top',
	layout: 'form',
	id: 'emailform',
	labelWidth: 200,
	frame: true,
	keys: {
        key: [10,13],
        fn: function(){ submitForm() }
    },
	defaultType: 'textfield',
	url: 'includes/form_process.php',
	items: [{
		name: 'name',
		width: 200,
		allowBlank: false,
		fieldLabel: 'Name'
	},{
		name: 'phone',
		width: 200,
		allowBlank: true,
		fieldLabel: 'Telephone'
	},{
		name: 'email',
		width: 200,
		allowBlank: false,
		vtype: 'email',
		fieldLabel: 'Email Address'
	},{
		xtype: 'combo',
		hiddenName: 'type',
		fieldLabel: 'Type of Accident',
	    width: 200,
		allowBlank: true,
		store: Ext.data.Question1,
	    forceSelection: true,
	    triggerAction: 'all',
	    emptyText:'select...',
	    selectOnFocus:true
	},{
		name: 'message',
		width: 200,
		allowBlank: false,		
		fieldLabel: 'Tell us briefly about the accident',
		xtype: 'textarea',
		height: 90,
		preventScrollbars: true
		
	}],
		   buttons: [{
            text: 'Submit',
			handler: function(){
						submitForm();
					}
        },{
            text: 'Cancel',
			handler: function(){
				Ext.getCmp('emailform').getForm().reset();
			}
        }]	
});


});
