/*
 * Ext JS Library 1.0.1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://www.extjs.com/license
 */
/* ComboBox Data
   ============= */
Ext.namespace('Ext.combodata');

Ext.combodata.type = [
['AL', 'Alabama'],
['WY', 'Wyoming']
];

/* Initialize JS
   ============= */
var qnameTextField, qemailTextField, qphoneTextField, qproductSelectField, qtypeSelectField, qstylenumTextField, qcolorTextField, qlocsSelectField, qurlTextField, qnotesTextArea;
   
Ext.onReady(function(){
	Ext.QuickTips.init();
	// turn on validation errors beside the field globally
	Ext.form.Field.prototype.msgTarget = 'side';

	if (Ext.get('submitQuoteForm')) {
		//alert('got submitQuoteForm');
		/* NAME */
		qnameTextField = new Ext.form.TextField({
			emptyText: 'First & Last Name...',
			name: 'name',
			allowBlank:false,
			msgTarget: 'errordiv',
			width: 100,
			height: 20
		});
		qnameTextField.applyTo('name');
		
		/* EMAIL */
		qemailTextField = new Ext.form.TextField({
			emptyText: 'E-mail Address...',
			name: 'email',
			vtype:'email',
			width:100,
			height: 20,
			allowBlank:false,
			msgTarget: 'errordiv'
		});
		qemailTextField.applyTo('email');
		
		/* PHONE */
		qphoneTextField = new Ext.form.TextField({
			emptyText: 'Telephone No...',
			name: 'phone',
			allowBlank:false,
			msgTarget: 'errordiv',
			width: 100,
			height: 20
		});
		qphoneTextField.applyTo('phone');
		
		/* PRODUCT */
		var store_type = new Ext.data.SimpleStore({
			fields: ['products'],
			data : [['Apparel'],['Banner'],['Table Drape'],['Apparel / Banner'],['Apparel / Drape'],['Banner / Drape'],['All Products']]
		});
		qproductSelectField = new Ext.form.ComboBox({
			emptyText: 'Select Products...',
			store: store_type,
			name: 'product',
			displayField:'products',
			typeAhead: true,
			mode: 'local',
			triggerAction: 'all',
			selectOnFocus:true,
			forceSelection: true,
			width: 100,
			height: 20
		});
		qproductSelectField.applyTo('product');
		
		/* TYPE */
		var store_type = new Ext.data.SimpleStore({
			fields: ['types'],
			data : [['Screenprinted'],['Embroidered']]
		});
		qtypeSelectField = new Ext.form.ComboBox({
			emptyText: 'Choose Type...',
			store: store_type,
			name: 'type',
			displayField:'types',
			typeAhead: true,
			mode: 'local',
			triggerAction: 'all',
			selectOnFocus:true,
			forceSelection: true,
			allowBlank:false,
			msgTarget: 'errordiv',
			width: 100,
			height: 20
		});
		qtypeSelectField.applyTo('type');
		
		/* STYLE */
		qstylenumTextField = new Ext.form.TextField({
			emptyText: 'Cat. Style Number...',
			name: 'style',
			allowBlank:true,
			width: 100,
			height: 20
		});
		qstylenumTextField.applyTo('style');
		
		/* COLOR */
		qcolorTextField = new Ext.form.TextField({
			emptyText: 'Garment Color...',
			name: 'color',
			allowBlank:true,
			width: 100,
			height: 20
		});
		qcolorTextField.applyTo('color');
		
		/* LOGO */
		qurlTextField = new Ext.form.TextField({
			emptyText: 'Quantity...',
			name: 'logo',
			allowBlank:true,
			width: 100,
			height: 20
		});
		qurlTextField.applyTo('logo');

		/* LOCS */
		var store_locs = new Ext.data.SimpleStore({
			fields: ['locsfield'],
			data : [['Front'],['Back'], ['(other - type in)']]
		});
		qlocsSelectField = new Ext.form.ComboBox({
			emptyText: 'Location(s)...',
			store: store_locs,
			name: 'locs',
			displayField:'locsfield',
			typeAhead: true,
			mode: 'local',
			triggerAction: 'all',
			selectOnFocus:true,
			forceSelection: false,
			width: 100,
			height: 20
		});
		qlocsSelectField.applyTo('locs');
		
		/* NOTES */
		qnotesTextArea = new Ext.form.TextArea({
			name: 'notes',
			grow: false,
			preventScrollbars: false,
			emptyText: 'Any Special Instructions?',
			value: '',
			width: 150,
			height: 30
		});
		qnotesTextArea.applyTo('notes');

	} // end else if form-step2
}); // end onReady( function() {
	
function form_handler() {
		try {

			var qnameTextFieldValidate = qnameTextField.validate();
			var qemailTextFieldValidate = qemailTextField.validate();
			var qphoneTextFieldValidate = qphoneTextField.validate();
			var qproductSelectFieldValidate = qproductSelectField.validate();
			var qtypeSelectFieldValidate = qtypeSelectField.validate();
			var qstylenumTextFieldValidate = qstylenumTextField.validate();
			var qcolorTextFieldValidate = qcolorTextField.validate();
			var qlocsSelectFieldValidate = qlocsSelectField.validate();
			var qurlTextFieldValidate = qurlTextField.validate();
			var qnotesTextAreaValidate = qnotesTextArea.validate();

			if (qnameTextFieldValidate && qemailTextFieldValidate && qphoneTextFieldValidate && qproductSelectFieldValidate && qtypeSelectFieldValidate && qstylenumTextFieldValidate && qcolorTextFieldValidate && qlocsSelectFieldValidate && qurlTextFieldValidate && qnotesTextAreaValidate) {
			//if (true) {
				//Ext.MessageBox.alert('Success', 'Moving on to the survey...');
				Ext.fly('submitQuoteForm').dom.submit();
			}
			else {
				alert('Error: Enter a valid NAME, EMAIL, PHONE, and screen/embroidered TYPE. (1)');
				//Ext.MessageBox.alert('Errors (try)', 'Please fix the errors noted.');
			}
		}
		catch(err) {
			if (qnameTextFieldValidate && qemailTextFieldValidate && qphoneTextFieldValidate && qproductSelectFieldValidate && qtypeSelectFieldValidate && qstylenumTextFieldValidate && qcolorTextFieldValidate && qlocsSelectFieldValidate && qurlTextFieldValidate && qnotesTextAreaValidate) {
			//if (true) {
				//Ext.MessageBox.alert('Success', 'Moving on to the survey...');
				Ext.fly('submitQuoteForm').dom.submit();
			}
			else {
				alert('Error: Enter a valid NAME, EMAIL, PHONE, and screen/embroidered TYPE. '+'(2)');
				//Ext.MessageBox.alert('Errors (catch)', 'Please fix the errors noted.');
			}
		}
	}
