var CombosDependientes = {
	init: function(){
		this.marcasStore = this.getDataStore();
		this.modeloStore = this.getDataStore();
		this.marcasStore.load();
		this.marcaCmb = new Ext.form.ComboBox({
			store: this.marcasStore,
			name: 'marca',
			id: 'marca',
			valueField: 'value',
			displayField: 'label',
			triggerAction: 'all',
			mode: 'local',
			width:155,
			applyTo:'marca',
			typeAhead: true,
			selectOnFocus:true,
			forceSelection:true,
			emptyText: 'Seleccione'
		});
		
		this.modeloCmb = new Ext.form.ComboBox({
			store: this.modeloStore,
			name: 'modelo',
			id: 'modelo',
			valueField: 'value',
			displayField: 'label',
			triggerAction: 'all',
			typeAhead: true,
			mode: 'local',
			width:155,
			applyTo:'modelo',
			forceSelection:true,
			selectOnFocus:true,
			emptyText: 'Elija la marca primero'
		});	
		this.addEvents();
	},
	
	getDataStore: function(){
		var store = new Ext.data.JsonStore({
			url:'fns_php/getDatosform.php',
			root:'data',
			fields: ['value','label']
		});
		return store;
	},
	
	addEvents: function(){
	    	this.marcaCmb.on('beforeselect',function(cmb,record,index){
			this.modeloCmb.clearValue();
			this.modeloStore.load({params:{marca:record.get('label')}});
		},this);
	}
};

Ext.onReady(CombosDependientes.init,CombosDependientes);