// JavaScript Document

ContactPanel = function(config){
	Ext.apply(this, config);
	
	ContactPanel.superclass.constructor.call(this, {
		id: 'contact-form',
		labelWidth: 90,
		bodyStyle:'padding:5px 5px 0',
		title: 'Email Warlock and Bradford',
		defaults: {width: 230},
        defaultType: 'textfield',
		url: 'lib/func.sendemail.php',
		collapsible: false,
		frame: true,
		items: [{
				id: 'name-field',
                fieldLabel: 'Name',
                name: 'name',
                allowBlank:false,
				listeners: {
					'render': {
						fn: function(){
							this.focus();
						}
					}
				}
            },{
                fieldLabel: 'Subject',
                name: 'subject',
				allowBlank: false
            },{
                fieldLabel: 'Email',
                name: 'email',
                vtype:'email',
				allowBlank: false
            },{
				xtype: 'htmleditor',
				fieldLabel: 'Message',
				name: 'message',
				enableColors: false,
       			enableAlignments: false,
				enableSourceEdit: false,
				width: 500,
				allowBlank: false
			}],

        buttons: [{
            text: 'Send',
			handler: function(){
				this.getForm().submit({
					method: 'POST',
					success: function(f, a){
						Ext.Msg.alert("Email Sent!", "Thank you for taking the time to send us a message. We'll get back to you as soon as possible", this.handleSuccess, this);
					},
					failure: function(f,a){
					
					},
					scope: this
				});
			},
			scope:this
        },{
            text: 'Cancel',
			handler: function(){
				this.getForm().clearInvalid();
				this.getForm().reset();
			},
			scope: this
        }],

		renderTo: this.targetEl
	});


};
Ext.extend(ContactPanel, Ext.form.FormPanel, {
	handleSuccess: function(btn){
		this.getForm().clearInvalid();
		this.getForm().reset();
	}
});
