/**
 * @author George Miller
 */
Ext.onReady(function(){
//initalize the quicktips
Ext.QuickTips.init();
//reference the default image
Ext.BLANK_IMAGE_URL = 'ext-3.0/resources/images/default/s.gif';

function submitForm(){
	var form = Ext.getCmp('emailform');
						
						if (form.form.isValid()) {
							waitMsg: 'Saving details', 
							form.form.submit({
								params: {
									action: 'submit'
								},
								success: function(form, action){
									var name = action.result.name;
									
												Ext.MessageBox.show({
							title: 'Successful Entry',
							width: 400,
							height: 200,
							msg: 'Thank you '+name+',<br>You have successfully entered your details, We will contact you as soon as possible',
							buttons: Ext.MessageBox.OK,
							icon: Ext.MessageBox.INFO
						});
											
							form.reset();
							
								},
								failure: function(form, action){
									if (action.result.errors.length > 0) {
										Ext.MessageBox.show({
							title: 'Error',
							width: 250,
							height: 150,
							msg: action.result.msg,
							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({
	width: 490,
	height: 470,
	id: 'emailform',
    title: '<div style="padding-bottom:10px;">Enter Your Details - We will contact you shortly</div>',
	baseCls: 'x-plain',
	labelAlign: 'top',
	renderTo: 'form',
	labelWidth: 200,
	frame: true,
	keys: {
        key: [10,13],
        fn: function(){ submitForm() }
    },
	defaultType: 'textfield',
	url: 'http://lighterpromotions.co.uk/includes/form_process.php',
	items: [{
		name: 'name',
		width: 400,
		allowBlank: false,
		fieldLabel: 'Name'
	},{
		name: 'company',
		width: 400,
		allowBlank: false,
		fieldLabel: 'Company Name'
	},{
		name: 'email',
		width: 400,
		allowBlank: false,
		vtype: 'email',
		fieldLabel: 'Email Address'
	},{
		name: 'phone',
		width: 400,
		allowBlank: false,
		fieldLabel: 'Contact No.'
	},{
		name: 'subject',
		width: 400,
		allowBlank: false,		
		fieldLabel: 'Subject'
	},{
		name: 'message',
		width: 485,
		allowBlank: false,		
		fieldLabel: 'Your Message',
		xtype: 'textarea',
		height:120,
		preventScrollbars: true
	}]
       ,buttons: [{
            text: 'Submit',
			iconCls: 'add16',
			scale: 'medium',
			handler: function(){
						submitForm();
					}
        },{
            text: 'Cancel',
			iconCls: 'add16',
			scale: 'medium',
			handler: function(){
				Ext.getCmp('emailform').getForm().reset();
			}
        }]	
});

});
