/**
 * @author Tyler
 */

Ext.onReady(function(){
	Ext.QuickTips.init();
	
	var contactFrm = new Ext.FormPanel({
		url: '/contact/contact',
		defaultType: 'textfield',
		waitMsgTarget: true,
		baseCls: 'x-plain',
		labelWidth: 150,
		labelAlign: 'left',
		defaults: {width: 310},
		items: [{
			fieldLabel: 'Name',
			name: 'name',
			allowBlank: false
		},{
			fieldLabel: 'Email Address',
			name: 'email',
			allowBlank: false,
			vtype: 'email'
		},{
			fieldLabel: 'Subject',
			name: 'subject',
			allowBlank: false
		},{
			xtype: 'checkbox',
			name: 'cc',
			fieldLabel: 'Send a copy to yourself',
			width: 10
		},{
			xtype: 'textarea',
			id: 'message',
			hideLabel: true,
			width: 490,
			height: 100
		}]
	});
	
	var window = new Ext.Window({
		title: 'Contact Us',
		width: 525,
        height:300,
        minWidth: 300,
        minHeight: 200,
        layout: 'fit',
        plain:true,
		closeAction: 'hide',
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        items: contactFrm,
		buttons: [{
			text: 'Send',
			handler: function(){
				if(contactFrm.form.isValid()){
					contactFrm.form.submit({
						waitMsg: 'Sending',
						success: function(){
							contactFrm.form.reset();
							window.hide();
							Ext.MessageBox.alert('Thank You','Your message has been sent.  We will try to get back to you as soon as possible.');
						},
						failure: function(){
							Ext.MessageBox.alert('Error','We are sorry but your message could not be sent.  Please try again.');
						}
					});
				}
			},
			scope: this
		},{
			text: 'Cancel',
			handler: function(){
				contactFrm.form.reset();
				window.hide();
			}
		}]
	})
	
	var button = new Ext.Button({
		text: 'Contact Us',
		renderTo: 'btn-contact',
		handler: function(){
			window.show(this);
		}
	});
});