/*
 * 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');

var debugvalid = false;
var sucessmsg = 'Your message was sent please allow 12-24 hours for a response.';

Ext.exampledata.timeframe = [
        ['0-6 Months', '0-6 Months'],
        ['6-12 Months', '6-12 Months'],
        ['1 Year or Greater', '1 Year of Greater']
    ];

Ext.exampledata.subject = [
        ['Website Design', 'Website Design'],
        ['Graphic Design', 'Graphic Design'],
        ['Web-App Development', 'Web-App Development'],
        ['Professional Services', 'Professional Services'],
        ['General Inquiry', 'General Inquiry'],
        ['Site Related', 'Site Related']
    ];
    
Ext.exampledata.conmethod = [
        ['Phone', 'Phone'],
        ['Email', 'Email']
    ];  
       
    var storeTIME = new Ext.data.SimpleStore({
        fields: ['id', 'name'],
        data : Ext.exampledata.timeframe
    });
       
    var storeSUB = new Ext.data.SimpleStore({
        fields: ['id', 'name'],
        data : Ext.exampledata.subject
    });

    var storeCON = new Ext.data.SimpleStore({
        fields: ['id', 'name'],
        data : Ext.exampledata.conmethod
    });
  
    var comboTIME = new Ext.form.ComboBox({
        store: storeTIME,
        displayField:'name',
        name: 'timeframe',
   			fieldLabel: 'Time Frame for Work',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'Select an option...',
        selectOnFocus:true,
        allowBlank:true
    });
    
    var comboSUB = new Ext.form.ComboBox({
        store: storeSUB,
        displayField:'name',
        name: 'subject',
   			fieldLabel: 'Service Requested',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'Select an option...',
        selectOnFocus:true,
        allowBlank:true
    });

    var comboCON = new Ext.form.ComboBox({
        store: storeCON,
        displayField:'name',
        name: 'prefcon',
   			fieldLabel: 'Method of Contact',
        typeAhead: true,
        mode: 'local',
        triggerAction: 'all',
        emptyText:'Select an option...',
        selectOnFocus:true,
        allowBlank:debugvalid
    });
              
    var simple = new Ext.FormPanel({
        labelWidth: 175, // label settings here cascade unless overridden
        url:'ajax-contact.php',
        frame:true,
        title: 'General Inquiry Form',
        bodyStyle:'padding:5px 5px 0',
        width: '475',
        defaults: {width: 250},
        defaultType: 'textfield',

        items: [{xtype:'fieldset',
            title: 'Contact Information',
            collapsible: false,
            autoHeight:true,
            autoWidth:true,
            defaults: {width: 250},
            defaultType: 'textfield',
            items :[{
				                fieldLabel: 'First Name',
				                name: 'first',
				                allowBlank:debugvalid
				            },{
				                fieldLabel: 'Last Name',
				                name: 'last',
				                allowBlank:debugvalid
				            },{
				                fieldLabel: 'Company Name',
				                name: 'company',
				                allowBlank:true
				            },{
				                fieldLabel: 'Phone Number',
				                name: 'phone',
				                emptyText: '(888) 555-1212',
				                allowBlank:debugvalid
				            }, {
				                fieldLabel: 'Email',
				                name: 'email',
				                vtype:'email',
				             		allowBlank:debugvalid
				            }, comboCON
            			]
            }, {xtype:'fieldset',
            title: 'Project Information',
            collapsible: false,
            autoHeight:true,
            autoWidth:true,
            defaults: {width: 250},
            defaultType: 'textfield',
            items :[{
				                fieldLabel: 'Current Website',
				                name: 'website',
				                allowBlank:true
				            }, comboTIME,comboSUB, {
				                fieldLabel: 'Estimated Budget',
				                name: 'budget',
				                emptyText: '$ (USD)',
				                allowBlank:true
				            }
            			]
            }, {
            	xtype:'fieldset',
	            title: 'Additional Information',
	            collapsible: false,
	            autoHeight:true,
	            autoWidth:true,
	            defaults: {width: 250},
	            defaultType: 'textfield',
	            items :[{		
	            						xtype:'textarea',
							            id:'message',
							            fieldLabel:'Questions / Comments',
							            height:200
					            }
	            			]
            }
        ],

        buttons: [{
					text: 'Send Request',
					handler: function(){
						if(simple.getForm().isValid()){
							simple.getForm().submit({
								waitMsg: 'Sending Request...',
								success: function(form, action){
									Ext.MessageBox.alert('Successful', action.result.msg);
									Googlecconversion('1013172543', 'CL0cCKmt0QEQv5KP4wM', 0);
									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');

});

/*
{
	columnWidth:0.15,
	layout: 'column',
	//buttonAlign:'right',
	height:125,
	bodyStyle:'padding:15px 0 0px 25px',
	items:[{
					xtype:'radio',
					//layout: 'form',
					boxLabel:"From-To",
					hideLabel:true,
					name: 'radio',
					inputValue:"radiovalue",
					id:'radio1',
					onClick:criteria
					},{ xtype:'radio',
					//layout: 'form',
					boxLabel:"All",
					hideLabel:true,
					name: 'radio',
					id:'radio2',
					inputValue:"all",
					onClick:disableFields
	}]
}
*/