// Transformacin automtica de combos a EXT
// Augusto

function getElementsByTagNames(list,obj) {
	if (!obj) var obj = document;
	var tagNames = list.split(',');
	var resultArray = new Array();
	for (var i=0;i<tagNames.length;i++) {
		var tags = obj.getElementsByTagName(tagNames[i]);
		for (var j=0;j<tags.length;j++) {
			resultArray.push(tags[j]);
		}
	}
	var testNode = resultArray[0];
	if (!testNode) return [];
	if (testNode.sourceIndex) {
		resultArray.sort(function (a,b) {
				return a.sourceIndex - b.sourceIndex;
		});
	}
	else if (testNode.compareDocumentPosition) {
		resultArray.sort(function (a,b) {
				return 3 - (a.compareDocumentPosition(b) & 6);
		});
	}
	return resultArray;
}

oCombo = getElementsByTagNames('select') 
lLen = oCombo.length;

for ( i = 0; i < lLen; i++ ) {
	
	var converted = new Ext.form.ComboBox({
		typeAhead: true,
		triggerAction: 'all',
		transform:oCombo[i].name,
		width:125,
		forceSelection:true,
		selectOnFocus:true
	});
	
	if(oCombo[i].id == "cmbCountry") {
		
		converted.on('select', function(box, record, index) {
			
			FiltroPais = Ext.get("cmbCountry").getValue() != "0" ? Ext.get("cmbCountry").getValue() : "";
			PC_EjecutarFiltros();			
			grid.render();
			
		});	
	}
	
	if(oCombo[i].id == "cmbCont") {
				
		converted.on('select', function(box, record, index) 
		{
			FiltroContinente = Ext.get("cmbCont").getValue() != "0" ? Ext.get("cmbCont").getValue() : "";
			
			Ext.get("countryTd").hide();
			Ext.get("countryTd").load({
				url: "/include/http/paises.php",
				scripts:true, 
				params: "Rubro_Id=" + FiltroRubro + "&Continente_Id=" + FiltroContinente,
				text: "Loading...",
				callback: armoCombo
			});			
			
			// Vacio el filtro pais:
			FiltroPais = "";
					
			PC_EjecutarFiltros();
			grid.render();
		});	
	}
	
}
