





Ext.onReady(function(){

    Ext.QuickTips.init();

    Ext.form.Field.prototype.msgTarget = 'side';

function accepttest()
{
alert('test');
}

function acceptRegForm()
{
	var regisForm = regFormPanel.getForm();
	if (!regisForm.isValid())
	{
		Ext.MessageBox.alert('Incomplete Form',"Please complete the form and try again.");
		return;
	}
	else 
	{
		var theValues = regisForm.getValues();
//		if (theValues.state == "XX")
//		{
//			Ext.MessageBox.alert('Incomplete Form',"Please select a state and try again.");
//			return;
//		}
	}

	Ext.MessageBox.show({title:'Please wait...', msg:"Your information is being processed.<br>A confirmation screen will appear shortly", width:255});

//	Ext.get('submitBtn').disable();

	var success = function(obj, options)
	{

		procRegisResp = Ext.util.JSON.decode('(' + obj.responseText + ')');

		if (procRegisResp.payMethod == "paypal")
		{
			document.location.href="regis_3a.php?email=" + procRegisResp.email 
				+ "&singleCouple=" + procRegisResp.singleCouple
				+ "&partialComplete=" + procRegisResp.partialComplete
				+ "&regAmount=" + procRegisResp.regAmount
				+ "&registrationId=" + procRegisResp.registrationId
				+ "&comments=" + procRegisResp.comments;
		}
		else if (procRegisResp.payMethod == "check")
		{
			document.location.href="regis_3b.php?email=" + procRegisResp.email 
				+ "&singleCouple=" + procRegisResp.singleCouple
				+ "&partialComplete=" + procRegisResp.partialComplete
				+ "&regAmount=" + procRegisResp.regAmount
				+ "&registrationId=" + procRegisResp.registrationId;
		}


	}.createDelegate(this);

	var failure = function(obj)
	{
//		console.log(obj.responseText);
//		debugger;
		Ext.MessageBox.alert('Internal Error',"There was an error in the form submission. Please try again or call Roxanne Andrews: 970-461-9334");

	}.createDelegate(this);

	Ext.Ajax.request({
		method: "POST",
		url: "procRegis.php",
		params: regisForm.getValues(),
		success: success,
		failure: failure
	});
}

	var contactInfoFieldset = 
	{xtype:'fieldset', height:270, width:270, title:"Contact Info", defaultType: 'textfield', items:
	[
		{fieldLabel: '<span class="x-form-item-required">First Name</span>', name: 'fName', allowBlank: false, width:150},
		{fieldLabel: '<span class="x-form-item-required">Last Name</span>', name: 'lName', allowBlank: false, width:150},
		{fieldLabel: '<span class="x-form-item-required">Address</span>', name: 'address', allowBlank: false, width:150},
		{fieldLabel: '<span class="x-form-item-required">City</span>', name: 'city', allowBlank: false, width:150},
			{xtype:"combo", fieldLabel:'<span class="x-form-item-required">State</span>', value:'XX', editable:true, hiddenName:"state", width:150,
				validator: function(value) {
					//if(value=="XX") return "Please select a state";
					//else 
					return true;
				},
				store: new Ext.data.SimpleStore({
	    			fields: ['abbr', 'state'],
	    			data : Ext.exampledata.states // from states.js
				}), displayField:'state', valueField:'abbr', mode:'local', forceSelection:true, triggerAction:'all'},
	
			{xtype:"combo", fieldLabel:'<span class="x-form-item-required">Country</span>', value:'228', editable:false, hiddenName:"country", width:150,
				store: new Ext.data.SimpleStore({
	    			fields: ['abbr', 'full_name'],
	    			data : countries_list // from states.js
				}), displayField:'full_name', valueField:'abbr', mode:'local', forceSelection:true, triggerAction:'all'},
	
		{fieldLabel: '<span class="x-form-item-required">Phone</span>', name: 'phone', allowBlank: false, width:150},
		{fieldLabel: '<span class="x-form-item-required">Zip</span>', name: 'zip', allowBlank: true, width:150},
		{fieldLabel: '<span class="x-form-item-required">E-mail</span>', name: 'email', allowBlank: false, width:150, vtype:'email'}
	]};

	var paymentFieldSet =
	{xtype:'fieldset', height:320, width:320, title:"Payment", defaultType: 'textfield', items:
	[
        {xtype:"combo", fieldLabel: '<span class="x-form-item-required">Are you registering one person or a couple?</span>', hiddenName:'singleCouple',
			mode:'local', forceSelection:true, value:"single", editable:false, triggerAction:'all',displayField:'display', valueField:'value', width:130,         
 			store: new Ext.data.SimpleStore({
                fields: ['value', 'display'],
                data : [
        			['single', 'One Person ($250)'],
        			['couple', 'Couple ($400)']
   					]
            	})
		}
		,{xtype:"combo", fieldLabel: '<span class="x-form-item-required">What method of payment would you like to use?</span>', hiddenName:'payMethod',
			mode:'local', forceSelection:true, value:'paypal', editable:false, triggerAction:'all',displayField:'display', valueField:'value', width:130,         
 			store: new Ext.data.SimpleStore({
                fields: ['value', 'display'],
                data : [
        			['paypal', 'Credit Card'],
        			['check', 'Check']
					]
            	})
		}
		,{xtype:"combo", fieldLabel: '<span class="x-form-item-required">Will you be making a partial or complete payment today?</span>', hiddenName:'partialComplete',
			mode:'local', forceSelection:true, value:'complete', triggerAction:'all',displayField:'display', valueField:'value', width:170,         
 			store: new Ext.data.SimpleStore({
                fields: ['value', 'display'],
                data : [
        			['partial', 'Partial ($150)'],
        			['complete', 'Complete ($250 or $400)']
					]
            	})
		}
		,{xtype:"textarea", fieldLabel: '<span class="x-form-item-required">Comments- enter DATE, LOCATION, and NAME of workshop please</span>', name:'comments', width:200, height:60 }
	]};

	var regFormPanel = new Ext.form.FormPanel(
	{
	    labelWidth: 75,
	    border:false,
	    width: 670,
		height: 420,
		title: "Conference Registration",     
		defaultType: 'textfield',
		header:false,
		deferredRender: false,
		renderTo: 'regisFormDiv',
		bodyStyle:'padding:5px, margin:20px',
		items:
		[
			{xtype:"panel", border:false,header:false,layout:"column", width:690, labelWidth: 90, height:700,items:
			[
				{header:false, width:'320px', border:false,bodyStyle:'padding:0px; margin: 10px;',items:
				[ contactInfoFieldset ]},

				{header:false, columnWidth:1 ,border:false, bodyStyle:'padding:0px; margin: 10px;',items:
				[ paymentFieldSet,
					{xtype:"panel", border:false, header:false,layout:"column", width:130, height:30,items:
					[
						{header:false, columnWidth:.5, buttonAlign:'right', border:false,bodyStyle:'padding:0px; margin: 0px;',items:
						[{xtype:"button", id:"cancelBtn", text:"Cancel", disabled:false, handler:function(){window.close();} }]},

						{header:false, columnWidth:.5, buttonAlign:'right', border:false,bodyStyle:'padding:0px; margin: 0px;',items:
						[{xtype:"button", id:"submitBtn", text:"Submit", disabled:false, handler:acceptRegForm}]}
					]}
				]}
			]}
		]
	});


});

