Ext.onReady(function(){

    Ext.QuickTips.init();
    
    // turn on validation errors beside the field globally
    Ext.form.Field.prototype.msgTarget = 'side';

    var bd = Ext.getBody();	
    
    var contactpanel = new Ext.FormPanel({
        labelAlign: 'side',        
        buttonAlign: 'right',
        
        bodyBorder:false,
        border:false,
        frame:false,
        hideBorders:true,
        bodyStyle: 'margin-top:10px',
        
        width: 390,
        labelWidth: 80,
        items: [
		
		{
			xtype: 'textfield',
			fieldLabel: 'Name',
			value: '',
			labelSeparator: '',
			name: 'ed_name',
			anchor: '92%'
		},
{
			xtype: 'textfield',
			fieldLabel: 'Phone',
			value: '',
			labelSeparator: '',
			name: 'ed_phone',
			anchor: '92%'              			
		},
{
			xtype: 'textfield',
			fieldLabel: 'Email',
			value: '',
			labelSeparator: '',
			name: 'ed_email',
			allowBlank:false,
			anchor: '92%'              			
		},
{
			xtype: 'textarea',
			fieldLabel: 'Message',
			value: '',
			labelSeparator: '',
			name: 'ed_message',
			anchor: '92%'              			
		}
	],

	buttons: [{
            text: 'Send Message',
            handler: function()
            		{
            			contactpanel.getForm().submit({
            									clientValidation: true,
							                    url: '/sendmsg.php',
							                    success: function(form, action) {
														// history.go(-1);
														setTimeout("Ext.Msg.alert('Success', 'Thank you for contacting Skye Recruitment. We will get back to you as soon as possible');", 500);
																				
																			    },
											    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", "Could not communicate with the server, message not sent");
																		                break;
																		            case Ext.form.Action.SERVER_INVALID:
																		               Ext.Msg.alert("Failure", "An unknown error occured, message not sent : "+ action.result.msg);
																		       								}
																				}

							                });
            			
            		}
        },{
            text: 'Cancel',
            handler: function()
            		{
            			history.go(-1);
            		}
        }]
	});
contactpanel.render('right');
});
