Ext.BLANK_IMAGE_URL = 'extjs/resources/images/default/s.gif';// reference local blank image
Ext.namespace('myExt', 'myExt.app');

carbonCost=8; // 1000kg of carbon = €8

var totalco2=0; var carCog=0; var motCog=0; var otherCog=0; var airCog=0; var airDist=0; var hqPeople=1; 
var cart=Array();
myExt.app = function() {
	return {
		init: function() {
			
			Ext.QuickTips.init(); var q = Ext.QuickTips.getQuickTip(); q.showDelay = 20; q.trackMouse = true; q.hideDelay=0; q.dismissDelay=0; q.autoHide=false;  //q.interceptTitles=true;
//			Ext.form.Field.prototype.msgTarget = 'side';
			
			// hideTrigger fix for IE
			Ext.form.TriggerField.override({ afterRender : function(){ Ext.form.TriggerField.superclass.afterRender.call(this); var y; if(Ext.isIE && !this.hideTrigger && this.el.getY() != (y = this.trigger.getY())){ this.el.position(); this.el.setY(y); } }});
			
			Ext.form.Field.prototype.afterRender = Ext.form.Field.prototype.afterRender.createInterceptor(function(){ if(this.disabled) this.container.parent().addClass('x-item-disabled'); });
			Ext.form.Field.prototype.disable = Ext.form.Field.prototype.disable.createInterceptor(function(){ if(this.container) this.container.parent().addClass('x-item-disabled'); });    
			Ext.form.Field.prototype.enable = Ext.form.Field.prototype.enable.createInterceptor(function(){ if(this.container) this.container.parent().removeClass('x-item-disabled'); }); 			
			
			var calcSum = new Ext.Panel({ renderTo:'calcSum', title:'Summary', id:'calcSumPanel',  frame:true, autoHeight:false, height:408, autoScroll:true, html:'<span id="emptySum" class="emptySum">Please add one or more...</span>'	});

			var totalForm = new Ext.FormPanel({ renderTo:'totalOffset', border:false, bodyStyle:'background:none;',
				defaultType:'textfield', defaults:{ width:80, hideLabel:true, readOnly:true },
				items:[ { id:'totalco2', style:'margin-bottom:8px; text-align:right;' }, { id:'totalCash', style:'text-align:right;' } ]
			});
			updateCounters();
			
			
	//*** DOMESTIC  PANEL **************************************************************************
			var carSubTypeStore = new Ext.data.SimpleStore({fields: [ 'name', 'subtype', 'cog' ], data:[] });
			var carForm = new Ext.myForm ({ title:'Car', renderTo:'domDiv', labelWidth:100,
				items:[
					{ fieldLabel:'Type', store:['Small','Medium','Large','Very Large'], listeners:{ select:carTypeSelect } },
					{ fieldLabel:'Subtype', disabled:true, id:'carSubType', store:carSubTypeStore, displayField: 'name', valueField: 'cog', listeners:{ select:carSubtypeSelect },
						tpl: '<tpl for="."><div class="x-combo-list-item"><div style="float:right; #margin-top:-1px; clear:right;">{subtype}</div>{name}</div></tpl>'
					},
					{ fieldLabel:'Annual km', editable:true, disabled:true, allowBlank:false, emptyText:'Please select or enter a number', id:'carAnnualKm', vtype:'numeric',
						listeners:{ select:function(){ Ext.getCmp('carButton').enable(); }, valid: function(){ Ext.getCmp('carButton').enable(); }, invalid: function(){ Ext.getCmp('carButton').disable();  }},
						store:['1,000','2,000','4,000','6,000','8,000','10,000','12,000','14,000','16,000','18,000','20,000','25,000','30,000','35,000','40,000','45,000','50,000','60,000','70,000','80,000','90,000','100,000']
					}
				],
				buttons: [ { text:'Add', id:'carButton', disabled:true, handler:function(b){  
					calculate('Car',Ext.getCmp('carAnnualKm').getRawValue(),carCog); 
					carForm.getForm().reset(); Ext.getCmp('carSubType').disable(); Ext.getCmp('carAnnualKm').disable(); b.disable(); 
				}}]
			});



			var motTypeStore = new Ext.data.SimpleStore({fields: [ 'name', 'subtype', 'cog' ], data:[ ['Small (incl Moped)','≤125cc','72.9'], ['Medium','≤500cc','93.9'], ['Large','›500cc','128.6'] ]});
			var motForm = new Ext.myForm({ title:'Motorbike', renderTo:'domDiv',
				items:[
					{ fieldLabel:'Type', id:'motType', store:motTypeStore, displayField: 'name', valueField: 'cog', listeners:{ select:motTypeSelect },
						tpl: '<tpl for="."><div class="x-combo-list-item"><div style="float:right; #margin-top:-1px; clear:right;">{subtype}</div>{name}</div></tpl>'
					},
					{ fieldLabel:'Annual km', editable:true, disabled:true, allowBlank:false, emptyText:'Please select or enter a number', id:'motAnnualKm', vtype:'numeric',
						listeners:{ valid: function(){ Ext.getCmp('motButton').enable(); }, invalid: function(){ Ext.getCmp('motButton').disable();  } },
						store:['1,000','2,000','4,000','6,000','8,000','10,000','12,000','14,000','16,000','18,000','20,000','25,000','30,000','35,000','40,000','45,000','50,000','60,000','70,000','80,000','90,000','100,000']
					}
				],
				buttons: [ { text:'Add', id:'motButton', disabled:true, handler:function(b){ 
					calculate('Motorbike',Ext.getCmp('motAnnualKm').getRawValue(),motCog); 
					motForm.getForm().reset(); Ext.getCmp('motAnnualKm').disable(); b.disable(); 
				}}]
			});


			var otherTypeStore = new Ext.data.SimpleStore({fields: [ 'name', 'cog' ], data:[ ['Train','44.3'], ['Bus','77.2'], ['Taxi','180'] ]});
			var otherForm = new Ext.myForm({ title:'Other Travel', renderTo:'domDiv',
				items:[
					{ fieldLabel:'Type', id:'otherType', store:otherTypeStore, displayField: 'name', valueField: 'cog', listeners:{ select:otherTypeSelect }},
					{ fieldLabel:'Weekly km', editable:true, disabled:true, allowBlank:false, emptyText:'Please select or enter a number', id:'otherWeeklyKm', vtype:'numeric',
						listeners:{ valid: function(){ Ext.getCmp('otherButton').enable(); }, invalid: function(){ Ext.getCmp('otherButton').disable(); } },
						store:['100','200','300','400','500','600','700','800','900','1,000']
					}				
				],
				buttons: [ { text:'Add', id:'otherButton', disabled:true, handler:function(b){ 
					var km=Ext.getCmp('otherWeeklyKm').getRawValue().replace(/,/g,'');
					calculate(Ext.getCmp('otherType').getRawValue(),parseFloat(km)*52,otherCog);	
					otherForm.getForm().reset(); Ext.getCmp('otherWeeklyKm').disable();	b.disable();
				}}]
			});
	//**********************************************************************************************
			


	//*** AIR TRAVEL PANEL *************************************************************************
			var airStore1 = new Ext.data.JsonStore({ root:'items', totalProperty:'total', id:'code', fields:['code','name', 'lat', 'lon'], url:'requests/airport.php' });
			var airStore2 = new Ext.data.JsonStore({ root:'items', totalProperty:'total', id:'code', fields:['code','name', 'lat', 'lon'], url:'requests/airport.php' });
			var airlineStore = new Ext.data.JsonStore({ root:'items', totalProperty:'total', fields:['id','name'], url:'requests/calculate.php' });
			var classStore = new Ext.data.JsonStore({ root:'items', totalProperty:'total', fields:['id','name', 'co2'], url:'requests/calculate.php' });
			var airForm = new Ext.myForm({ title:'Air Travel (individual flights)', renderTo:'airDiv',
				items:[
					{ xtype: 'radiogroup', columns:[0.99,30,40, 60], fieldLabel:'', labelSeparator:'', 
						 items: [
							  { xtype:'myCombo', id:'roundTripCombo', value:'Round Trip', store: ['Round Trip', 'One way'] },
							  { xtype:'box', autoEl:{ tag:'div', style:'padding-top: 2px; text-align:center;', html:'x' } },
							  { xtype:'myCombo', id:'persons', value:1, store:[1,2,3,4,5,6,7,8,9,10] },
							  { xtype:'box', autoEl:{ tag:'div', style:'padding-top: 2px; text-align:right;', html:'persons' } }
						 ]						
					},
					{ fieldLabel:'Departure From', id:'airFrom', store:airStore1, valueField: 'code', displayField: 'name', editable:true, hideTrigger:true,
						emptyText:'Please enter an airport name or code', mode:'remote', minChars:3, listWidth:300, 
						tpl: '<tpl for="."><div class="x-combo-list-item"><div style="float:right; #margin-top:-1px; clear:right;">{code}</div>{name}</div></tpl>',
						listeners:{ 
							select: function(){ airButtonCheck('select') }, 
							blur: function(){ airButtonCheck('blur') }, 
							beforequery:function(qe){ if (qe.query.length<3) { qe.combo.collapse(); return false } }
						}
					},
					{ fieldLabel:'Arrival To', id:'airTo', store:airStore2, displayField: 'name', valueField: 'code', editable:true, hideTrigger:true, 
						emptyText:'Please enter an airport name or code', mode:'remote', minChars:3, listWidth:300, 
						tpl: '<tpl for="."><div class="x-combo-list-item"><div style="float:right; #margin-top:-1px; clear:right;">{code}</div>{name}</div></tpl>',
						listeners:{ 
							select: function(){ airButtonCheck('select') }, 
							blur: function(){ airButtonCheck('blur') }, 
							beforequery:function(qe){ if (qe.query.length<3) { qe.combo.collapse(); return false } }
						}
					},
					{ xtype:'fieldset', title:'Optional', autoHeight:true, width:330, hidden:true, id:'optionFieldset', style:'padding-bottom:0;',
					items:[ 
						{ xtype:'fieldset', id:'airlineFieldset', hidden:true, border:false, autoHeight:true, labelAlign:'left', labelWidth:90, defaults:{ width: 195 }, style:'margin:0; padding:0 0 10px 0;', 
						items:[
							{ fieldLabel:'Airline', id:'airlines', xtype:'myCombo', store:airlineStore, displayField: 'name', valueField: 'id', editable:false, 
								emptyText:'Please select airline', mode:'local', listWidth:215,
								listeners:{ select: getAirClass	}
							},
							{ fieldLabel:'Class', id:'airclass', xtype:'myCombo', store:classStore, displayField: 'name', valueField: 'id', editable:false, listWidth:215,
								emptyText:'Please select class', mode:'local',  disabled:true, 
								tpl: '<tpl for="."><div class="x-combo-list-item"><div style="float:right; #margin-top:-1px; color:#999; clear:right;">({co2} tonnes of CO<sub>2</sub>)</div>{name}</div></tpl>',
								listeners:{ select: getCO2	}
							}
						]}, // inner fieldset
						{ xtype:'fieldset', border:false, autoHeight:true, labelAlign:'top', style:'margin:0;  padding:0;', 
						items:[
							{ xtype:'radiogroup', columns:[60,35,85,50,1.0 ], fieldLabel:'Is this a direct flight?', labelAlign:'top',
							items:[
								{ boxLabel: 'Yes', name: 'directflight', id:'directflightYES' },
								{ boxLabel: 'No', name: 'directflight', id:'directflightNO',
									listeners:{ check:function(chb,ch){ for(nd=1;nd<=3;nd++) Ext.getCmp('nodirect'+nd).setVisible(ch);  } }
								},
								{ xtype:'box', id:'nodirect1', hidden:true, autoEl:{ tag:'div', style:'padding-top: 9px; text-align:left;', html:', flight makes' } },
								{ xtype:'myCombo', id:'nodirect2', hidden:true, value:1, store:[1,2,3,4,5,6,7,8,9,10], width:30 },
								{ xtype:'box', id:'nodirect3', hidden:true, autoEl:{ tag:'div', style:'padding-top: 9px; padding-left:10px; text-align:left;', html:'stop(s)' } }
							]} // radiogroup items
						]} // inner fieldset
					]}, // outer fieldset items
					{ xtype:'box', id:'loadingDiv', width:34, height:34, style:'margin:10px auto; ', hidden:true, autoEl:{ tag:'div', html:'<img src="img/icons/loading.gif">' } }
				],// form items
				buttons: [ { text:'Add', id:'airButton', disabled:true, handler:function(b){ 
					if (Ext.getCmp('roundTripCombo').getValue()=='Round Trip'){ airDist*=2; airCog*=2; }
					airCog*=parseInt(Ext.getCmp('persons').getValue());
					if (Ext.getCmp('directflightNO').getValue()) airCog+=parseInt(Ext.getCmp('nodirect2').getValue())*204;
					if (aircalc('Air Travel',airDist,airCog,Ext.getCmp('airlines').getRawValue())){
						airCog=0; airDist=0;
						airForm.getForm().reset(); 
						Ext.getCmp('airclass').disable(); 
						Ext.getCmp('optionFieldset').hide(); 
						b.disable();
					}
				}}]
			});
	//**********************************************************************************************




			
	//*** HOME ENERGY PANEL ************************************************************************
			var homeQuestion = new Ext.myForm({ title:'Household or Individual?', defaults:{ width: 200 }, renderTo:'homeDiv', labelWidth: 180,
				items:[
					{ xtype:'label', text:'Do you wish to enter these amounts as an individual or as a household?', style:'font-size:10pt;' },
					{ xtype:'radiogroup', columns:[1.0,75,90], autoWidth:true, hideLabel:true,
					items:[
						{ boxLabel: 'Household', name: 'homeQuestion', id:'hqHousehold', checked:true },
						{ boxLabel: 'Individual', name: 'homeQuestion', id:'hqIndividual', listeners:{ check:showhqPeople } },
						{ xtype:'hint', text:'If you select &quot;Individual&quot;, we will divide the Home Energy carbon usage by the number of people in the household.', title:'Info' }
					]},
					{ fieldLabel:'Number of people in household', id:'hqPeople', xtype:'myCombo', editable:true, store:[1,2,3,4,5,6,7,8,9,10], width:50,
						listeners:{ select: function(){ savePeople(this.getRawValue()); }, blur: function(){ savePeople(this.getRawValue()); }  }
					}
				]
			});


			var homeStore = new Ext.data.SimpleStore({fields: [ 'name', 'cog' ], 
				data:[ ['Oil','3.17'], ['Biomass','0.129'], ['Coal','2.63'], ['LPG','1.63'], ['Peat Briquettes','1.36'], ['Gas (kWh)','0.204'], ['Gas (Monetary Value)','.204'] ]});
			var homeForm = new Ext.myForm({ title:'Fuel', defaults:{ width: 200 }, labelWidth:125, renderTo:'homeDiv',
				items:[
					{ fieldLabel:'Type', id:'homeType', store:homeStore, displayField: 'name', valueField: 'cog', listeners:{ select:homeTypeSelect }},
					{ fieldLabel:'Amount', editable:true, disabled:true, allowBlank:false, id:'homeValue', vtype:'numeric', emptyText:'Please select or enter a number', 
						displayField: 'name', valueField: 'value', store:[],
						listeners:{ valid: function(){ if(this.getRawValue()) Ext.getCmp('homeButton').enable(); }, invalid: function(){ Ext.getCmp('homeButton').disable(); } }
						
					}				
				],
				buttons: [ { text:'Add', id:'homeButton', disabled:true, handler:function(b){ 
					var type=Ext.getCmp('homeType').getRawValue();
					var index=Ext.getCmp('homeType').view.getSelectedIndexes();
					var value=Ext.getCmp('homeValue').getRawValue();
					var cog=Ext.getCmp('homeType').getValue();
					if (homeCalc(type, index, value, cog)){ homeForm.getForm().reset(); setLabel(''); b.disable(); }
				}}]
			});
	
		
			var homeForm2 = new Ext.myForm({ title:'Electricity', renderTo:'homeDiv',
				items:[
					{ xtype: 'radiogroup', columns:[130,0.98], autoWidth:true, hideLabel:true, cls:'energyForm2', 
						items: [
							{ boxLabel:'Annual kWh', name:'energyRadio', id:'energy1', checked:true, listeners:{ check:energyToggle } },
							{ xtype:'myCombo', id:'energyValue1', editable:true, allowBlank:false, vtype:'numeric',
								emptyText:'Please select or enter a number',
								listeners:{ valid: function(){ if (this.getRawValue().length>0) Ext.getCmp('homeButton2').enable(); }, invalid: function(){ Ext.getCmp('homeButton2').disable(); } },
								store:['500','1,000','1,500','2,000','2,500','3,000','3,500','4,000','4,500','5,000','6,000','7,000','8,000','9,000','10,000'] 
							},
							{ boxLabel:'Annual Cost', name:'energyRadio' },
							{ xtype:'myCombo', id:'energyValue2', editable:true, allowBlank:false, vtype:'numeric', disabled:true, emptyText:'Please select or enter a number',
								listeners:{ valid: function(){ if (this.getRawValue().length>0) Ext.getCmp('homeButton2').enable(); }, invalid: function(){ Ext.getCmp('homeButton2').disable(); } },
								store: ['€150','€200','€250','€300','€350','€400','€450','€500','€600','€700','€800','€900','€1,000','€1,200','€1,400','€1,600','€1,800','€2,000']
							}
						]						
					}
				],
				buttons: [ { text:'Add', id:'homeButton2', disabled:true, handler:function(b){ 
					var index=0, value=0;
					if (Ext.getCmp('energy1').getValue()){ index=10; value=Ext.getCmp('energyValue1').getRawValue(); }
					else { index=11; value=Ext.getCmp('energyValue2').getRawValue(); }
					if (homeCalc('Home Energy',index,value,0.67)){ homeForm2.getForm().reset(); b.disable(); }
				}}]
			});
	//**********************************************************************************************





	//*** QUICK CALCULATOR *************************************************************************
			var quickCitizenForm = new Ext.myForm({ title:'Annual Irish Citizen', renderTo:'quickDiv',
				items:[  {xtype:'box', autoWidth:true, autoEl:{tag:'div', html:'Each Irish person has an annual carbon footprint of 17.5 tonnes of CO<sub>2</sub>. To offset one year\'s emissions click here.'}} ],
				buttons: [ { text:'Add', id:'quickOffsetButton', handler:function(b){ quickOffsetCalc('Quick Offset',3,'1',17500);	quickOffsetForm.getForm().reset();	}}]
			});
			
			
			var quickOffsetForm = new Ext.myForm({ title:'Quick Offset', renderTo:'quickDiv',
				items:[
					{ xtype: 'radiogroup', columns:[120,0.95], autoWidth:true, hideLabel:true, 
						 items: [
							  { boxLabel:'Money', name:'quickOffsetRadio', id:'quickOffset11', checked:true, listeners:{ check:quickOffsetToggle } },
							  { xtype:'myCombo', id:'quickOffsetValue1', editable:true, allowBlank:false, vtype:'numeric',
									emptyText:'Please select or enter a number',
									listeners:{ valid: function(){ Ext.getCmp('quickOffsetButton').enable(); }, invalid: function(){ Ext.getCmp('quickOffsetButton').disable(); } },
									store:['€10','€20','€30','€40','€50','€60','€70','€80','€90','€100','€150','€200','€250','€300','€350','€400','€450','€500','€600','€700','€800','€900','€1,000','€1,200','€1,400','€1,600','€1,800','€2,000']
							  },
							  { boxLabel:'Kilograms of CO<sub>2</sub>', name:'quickOffsetRadio', id:'quickOffset12', listeners:{ check:quickOffsetToggle }  },
							  { xtype:'myCombo', id:'quickOffsetValue2', editable:true, allowBlank:false, vtype:'numeric', disabled:true, 
									emptyText:'Please select or enter a number',
									listeners:{ valid: function(){ Ext.getCmp('quickOffsetButton').enable(); }, invalid: function(){ Ext.getCmp('quickOffsetButton').disable(); } },
									store:['500','1,000','1,500','2,000','2,500','3,000','3,500','4,000','4,500','5,000','6,000','7,000','8,000','9,000','10,000'] }
						 ]						
					}
				],
				buttons: [ { text:'Add', id:'quickOffsetButton', disabled:true, handler:function(b){ 
					if (Ext.getCmp('quickOffset11').getValue()) quickOffsetCalc('Quick Offset',1,Ext.getCmp('quickOffsetValue1').getRawValue(),1000/carbonCost);
					if (Ext.getCmp('quickOffset12').getValue()) quickOffsetCalc('Quick Offset',2,Ext.getCmp('quickOffsetValue2').getRawValue(),1);
					quickOffsetForm.getForm().reset(); b.disable();
				}}]
			});
			
			
			var quickTravelForm = new Ext.myForm({ title:'Quick Travel+Home', renderTo:'quickDiv',
				items:[ 
					{ xtype: 'radiogroup', autoWidth:true, hideLabel:true, columns:[ 20, 0.5, 50, 0.5, 40], 
						items: [ 
							{ xtype:'separator' },// this is first column in a row
							{ boxLabel:'Short flight', inputValue:4, name:'quickTravel', checked:true }, { xtype:'hint', text:'A short haul flight is estimated to be approximately 1200 km to reflect your flights from Dublin to Northern Europe.', title:'Info' },
							{ boxLabel:'Average car', inputValue:5, name:'quickTravel' }, { xtype:'hint', text:'Average annual driving distance is 17000km. Based on a 1.6l petrol car, you would emit 3 tonnes of CO2 from driving.', title:'Info' },
							{ xtype:'separator' },// this is first column in a row
							{ boxLabel:'Long flight', inputValue:6, name:'quickTravel' }, { xtype:'hint', text:'A long haul flight is estimated to be approximately 12000 km to reflect your flights from Dublin to North America.', title:'Info' },
							{ boxLabel:'Average house', inputValue:7, name:'quickTravel' }, { xtype:'hint', text:'It is estimated that each Irish house releases 8.1 tonnes of CO2 per annum, energy use and heating.', title:'Info' }
						]
					}
				],
				buttons: [ { text:'Add', id:'quickTravelButton', handler:function(b){ 
					var qt=quickTravelForm.getForm().getValues(false).quickTravel, qcog=0;
					if (qt==4) qcog=151.2; if (qt==5) qcog=3000; if (qt==6) qcog=1320; if (qt==7) qcog=8100;
					quickOffsetCalc('Quick Travel+Home',qt,'1',qcog);
					quickTravelForm.getForm().reset(); 
				}}]
			});
			
			
			
			var quickEventsForm = new Ext.myForm({ title:'Quick Events', renderTo:'quickDiv',
				items:[ 
					{ xtype: 'radiogroup', autoWidth:true, hideLabel:true, columns:[ 20, 0.5, 50, 0.5, 40], 
						items: [ 
							{ xtype:'separator' },// this is first column in a row
							{ boxLabel:'New baby', inputValue:8, name:'quickEvents', checked:true }, { xtype:'hint', text:'Offset your baby\'s first year, estimated to release 17.5 tonnes of CO2.', title:'Info' },
							{ boxLabel:'Graduation', inputValue:9, name:'quickEvents' }, { xtype:'hint', text:'Offset one year of a student\'s college life with 17.5 tonnes CO2.', title:'Info' },
							{ xtype:'separator' },// this is first column in a row
							{ boxLabel:'Small wedding', inputValue:10, name:'quickEvents' }, { xtype:'hint', text:'With approximately 100 guests, sharing rooms at the hotel and with up to 30 people flying to the wedding.', title:'Info' },
							{ boxLabel:'Small party', inputValue:11, name:'quickEvents' }, { xtype:'hint', text:'With approximately 50 guests including up to 10 people flying in to attend.', title:'Info' },
							{ xtype:'separator' },// this is first column in a row
							{ boxLabel:'Large wedding', inputValue:12, name:'quickEvents' }, { xtype:'hint', text:'With approximately 250 guests, sharing rooms at the hotel and with up to 80 people flying to the wedding.', title:'Info' },
							{ boxLabel:'Large party', inputValue:13, name:'quickEvents' }, { xtype:'hint', text:'With approximately 100 guests including up to 30 people flying in to attend.', title:'Info' }
						]
					}
				],
				buttons: [ { text:'Add', id:'quickEventsButton', handler:function(b){ 
					var qt=quickEventsForm.getForm().getValues(false).quickEvents, qcog=0;
					if (qt==8) qcog=17500; if (qt==9) qcog=17500; if (qt==10) qcog=18000; if (qt==11) qcog=1800; if (qt==12) qcog=36000; if (qt==13) qcog=16500;
					quickOffsetCalc('Quick Events',qt,1,qcog);
					quickEventsForm.getForm().reset(); 
				}}]
			});
	//**********************************************************************************************


			switchMenu();
			readPeople();
			readCart();
			
			hideLoader();
		}// end init
	};// end return
}(); // end app
Ext.onReady(myExt.app.init, myExt.app);

function savePeople(ile){ hqPeople=ile; Ext.Ajax.request({ url: 'requests/cart.php', params:{ action:'savePeople', people: ile }}); }

function readPeople(){
	Ext.Ajax.request({ url: 'requests/cart.php', params:{ action:'readPeople' }, 
		success:function(resp){ 
			hqPeople=parseInt(resp.responseText);
			if (hqPeople>1){
				Ext.getCmp('hqHousehold').setValue(false); 
				Ext.getCmp('hqIndividual').setValue(true); 
				Ext.getCmp('hqPeople').setValue(hqPeople);
			}
			else showhqPeople(null,false);
		}	
	});
}

function showhqPeople(chb,ch){
	var hqp=Ext.getCmp('hqPeople');
	if (ch){ 
		hqp.enable(); hqp.show(); hqp.getEl().up('.x-form-item').setDisplayed(true); 
		hqp.setValue(1);
	}
	else { 
		hqp.disable(); hqp.hide(); hqp.getEl().up('.x-form-item').setDisplayed(false); 
		if (chb!=null) { hqp.setValue(1); savePeople(1); }
	}
	
}

