/**
  * Ext 2.0 Linked Combos Tutorial
  * by Jozef Sakalos, aka Saki
  * http://extjs.com/learn/Tutorial:Linked_Combos_Tutorial_for_Ext_2
  */
 
// reference local blank image
Ext.BLANK_IMAGE_URL = 'ext/s.gif';
 
// create application
LCombo.app = function() {
    // private functions
 var formObject;
 
    // public space
    return {
 
        // public methods
        init: function() {
		
 formObject = new Ext.form.FormPanel({
  standardSubmit: true,
                 renderTo:document.getElementById('search_maps')
				,id: 'search-form'
                ,width: 200
                ,height:110
                ,style:'margin:0px'
                ,bodyStyle:'padding:0px;background:transparent'
                ,title:'.'
                ,defaults: {xtype:'combo'}
				,url: '/selected-map.html'				
                ,items:[{
                     fieldLabel:'.'
                    ,displayField:'county'
                    ,valueField:'c_id'
					,value:'Select a County'
					,emptyText: 'Select a County'						
					,style:'width:165px'
	                ,hiddenName:'sel_county'					
                    ,store: new Ext.data.SimpleStore({
                         fields:['c_id', 'county']
                        ,data:LCombo.counties
                    })
                    ,triggerAction:'all'
                    ,mode:'local'
                    ,listeners:{select:{fn:function(combo, value) {
                        var comboCity = Ext.getCmp('combo-town');        
                        comboCity.clearValue();
                        comboCity.store.filter('c_id', combo.getValue());
						if (combo.getValue() == '20' || combo.getValue() == '34' ) document.getElementById('combo-town').value = 'MANs not yet handed over';
                        }}
                    }
 
                },{
                     fieldLabel:'.'
					,emptyText: 'Select a City / Town'					 
                    ,displayField:'town'
	                ,hiddenName:'sel_town'
					,value:'Select a City / Town'
					,style:'width:165px'					
                    ,valueField:'t_id'
                    ,id:'combo-town'
                    ,store: new Ext.data.SimpleStore({
                         fields:['t_id', 'c_id', 'town']
                        ,data:LCombo.towns
                    })
                    ,triggerAction:'all'
                    ,mode:'local'
                    ,lastQuery:''
//					,onFocus : function(){ var n = document.getElementById('combo-town').size;
//											document.getElementById('combo-town').value=n; }
                }],
				
buttons: [{
        text: '',
		icon:'../images/btn_search.jpg',
width: 81,height: 30,style:'margin:0px 0px 0 0;',		
        handler: function(){
            var fp = this.ownerCt.ownerCt,
                form = fp.getForm();
            if (form.isValid()) {
                // check if there are baseParams and if
                // hiddent items have been added already
                if (fp.baseParams && !fp.paramsAdded) {
                    // add hidden items for all baseParams
                    for (i in fp.baseParams) {
                        fp.add({
                            xtype: 'hidden',
                            name: i,
                            value: fp.baseParams[i]
                        });
                    }
                    fp.doLayout();
                    // set a custom flag to prevent re-adding
                    fp.paramsAdded = true;
                }
                form.submit();
            }
        }
    }]

				
            });
        }
    };
}(); // end of app
 
// end of file