/**
 * @author christophertossing
 */

var formPanel;

Ext.onReady(function () {

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

    formPanel = new Ext.FormPanel({
		style: "text-align:left;",
		collapsible:true,
		animCollapse:false,
		renderTo:'divEmailForm',
		labelWidth:75,
		url: 'formSendMail.php',
		frame:true,
		title:'Send an email to Gaia',
		bodyStyle:'padding:5px 5px 0',
		width:350,
		defaults: { width:230, allowBlank:false },
		defaultType: 'textfield',

		items: [{
				fieldLabel: 'Name',
				name: 'visitor'
            },{
				fieldLabel: 'Email',
				name: 'visitormail',
				vtype:'email'
            },{
				fieldLabel: 'Subject',
				name: 'attn'
            },
            new Ext.form.TextArea({
				fieldLabel: 'Notes',
				name: 'notes'
            }),
            new Ext.form.Hidden({
            	name: 'ip',
            	value: ''
            }),
            new Ext.form.Hidden({
            	name: 'httpref',
            	value: ''
            }),
            new Ext.form.Hidden({
            	name: 'httpagent',
            	value: ''
            })
		],
        buttons: [{
            text: 'Submit',
            handler: function() {
            	formPanel.getForm().submit({
            		clientValidation:true,
            		failure:function(){
            			Ext.Msg.alert('Message Send Failure!', 'Form submission failed!\n\nPlease check your entries and try again.');
            		},
            		success:function(){
            			Ext.Msg.alert('Message Sent!', 'Thank you for your inquiry.\n\nI will get back to you as soon as possible.');
            			window.location=window.location;
            		}
            	});
            }
        }]
	});
});
