/*
 * Ext JS Library 2.0.1
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */

Ext.onReady(function(){

   Ext.QuickTips.init();

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

Ext.namespace('Ext.exampledata');


Ext.exampledata.howhear = [
        ['Salesperson', 'Salesperson'],
        ['Builder', 'Builder / Contractor'],
        ['Magazine', 'Magazine'],
        ['Internet', 'Internet'],
        ['Radio', 'Radio Commercial'],
        ['TV', 'TV Commercial'],
        ['Billboard', 'Billboard'],
        ['Yellowpages', 'Yellowpages'],
        ['Friend', 'Friend'],
        ['Other', 'Other']
    ];

Ext.exampledata.subject = [
        ['General', 'General Inquiry'],
        ['Insulation', 'Insulation'],
        ['Gutters', 'Seamless Gutters'],
        ['Storage', 'Storage'],
        ['Shower Enclosures', 'Shower Enclosures'],
        ['Bathroom', 'Bathroom'],
        ['Mirrors', 'Mirrors'],
        ['Fireplaces', 'Fireplaces'],
        ['Website Related', 'Website Related']
    ];   

    var storeHH = new Ext.data.SimpleStore({
        fields: ['id', 'name'],
        data : Ext.exampledata.howhear
    });

    var storeSUB = new Ext.data.SimpleStore({
        fields: ['id', 'name'],
        data : Ext.exampledata.subject
    });
    
    var comboHH = new Ext.form.ComboBox({
        store: storeHH,
        displayField:'name',
        name: 'howhear',
   			fieldLabel: 'How did you hear about us',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'Select an option...',
        selectOnFocus:true,
        allowBlank:false
    });   

    var comboSUB = new Ext.form.ComboBox({
        store: storeSUB,
        displayField:'name',
        name: 'subject',
   			fieldLabel: 'Subject',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'Select an option...',
        selectOnFocus:true,
        allowBlank:false
    });
  
    var simple = new Ext.FormPanel({
        labelWidth: 175, // label settings here cascade unless overridden
        url:'aj-contactus.php',
        frame:true,
        title: ' ',
        bodyStyle:'padding:5px 5px 0',
        width: '100%',
        defaults: {width: 300},
        defaultType: 'textfield',

        items: [{
                fieldLabel: 'First Name',
                name: 'first',
                allowBlank:false
            },{
                fieldLabel: 'Last Name',
                name: 'last',
                allowBlank:false
            },{
                fieldLabel: 'Phone Number',
                name: 'phone',
                emptyText: '(888) 555-1212',
                allowBlank:false
            }, {
                fieldLabel: 'Email',
                name: 'email',
                vtype:'email'
            }, comboHH, 
            comboSUB,{
            xtype:'textarea',
            id:'message',
            fieldLabel:'Message',
            height:200
        		}
        ],

        buttons: [{
					text: 'Send Message',
					handler: function(){
						if(simple.getForm().isValid()){
							simple.getForm().submit({
								waitMsg: 'Sending Request...',
								success: function(form, action){
									Ext.MessageBox.alert('Successful', action.result.msg);
									simple.getForm().reset();
								},
								failure: function(form, action){	
									Ext.MessageBox.alert('Error Message', action.result.msg); 
								}
							});
						}else{
							Ext.MessageBox.alert('Errors', 'Please fill in the required fields');
						}
					}			
				}]
    });

    simple.render('Contact-Form');

});