var contactApp = function(){
    var forms = {
        main: new Ext.form.FormPanel({
            url: '/message/contact',
            method: 'POST',
			frame:true,
            id: 'contactForm',
            renderTo: 'formContainer',
            labelAlign: 'top',
            defaults: {
                width: 250
            },
            items: [{
                xtype: 'combo',
                selectOnFocus: true,
                forceSelection: true,
                editable: false,
                fieldLabel: 'Are you a Buyadate.org member?',
                triggerAction: 'all',
                mode: 'local',
                hiddenName: 'memberstatus',
                valueField: 'value',
                displayField: 'display',
                store: new Ext.data.SimpleStore({
                    fields: ['value', 'display'],
                    data: [['1', 'Yes'], ['0', 'No']]
                }),
                allowBlank: false
            }, {
                xtype: 'textfield',
                fieldLabel: 'What is your Email address?',
                vtype: 'email',
                allowBlank: false,
                name: 'emailaddress'
            }, {
                xtype: 'combo',
                selectOnFocus: true,
                forceSelection: true,
                editable: false,
                fieldLabel: 'Question Type',
                triggerAction: 'all',
                mode: 'local',
                hiddenName: 'questiontype',
                valueField: 'value',
                displayField: 'display',
                store: new Ext.data.SimpleStore({
                    fields: ['value', 'display'],
                    data: [['1', 'Comment / Suggestions'], ['2', 'Business Partnerships'], ['3', 'Other']]
                }),
                allowBlank: false
            }, {
                xytpe: 'textfield',
                fieldLabel: 'Subject',
                name: 'subject',
                allowBlank: false
            }, {
                xtype: 'textarea',
                fieldLabel: 'Your message',
                width: 500,
                height: 150,
                allowBlank: false,
                name: 'message'
            }],
            buttons: [{
                text: 'Submit',
                iconCls: 'btn-apply',
                handler: function(){
                    var ownerCt = this.ownerCt;
                    
                    this.ownerCt.form.submit({
                        waitMsg: 'Sending Message...',
                        success: function(a, b){
                            var confirmationTemplate = new Ext.XTemplate('<tpl for="."><div><h3>Thank You!</h3><p>If your message requires a reply, one of our Community Care team members will get back to you as soon as possible.<br/><br/>We have assigned it tracking number {confirmation}, which you can reference at any time when working with our team. <br/><br/>We have tried to include as much information as possible in our <a href="http://www.buyadate.org">Help</a> section. <br/>If you have not looked there already, why not give it a try? </p></div></tpl>')
                            if (b.result.confirmation) {
                                var markup = confirmationTemplate.applyTemplate(b.result);
								document.getElementById('pageContainer').innerHTML = markup;
                            }
                        },
                        failure: function(a, b){
                        
                        }
                    });
                }
            }]
        })
    };
    
    return {
        init: function(a){
        
        }
    };
    
}

var ca;

Ext.onReady(function(){
    Ext.QuickTips.init();
    ca = contactApp();
    ca.init({});
})
