// JavaScript Document

var cargando = null;
var combo = null;
function fillCombo(tabla, id, campo, valor, campo_relacion, tipo, comboO, ld){
	
	if(tipo == 'like' && valor.length <= 2){
		//alert('here');
		return false;
	
	}
	var ajax = new Ajax();
	var dir;
	cargando = document.getElementById(ld);
	combo = document.getElementById(comboO);
	//alert ('http://' + document.location.host + '/includes_php/buscar_combos.php?tabla='+ tabla +'&id='+ id +'&campo=' + campo +'&valor=' + valor + '&campo_relacion=' + campo_relacion+ '&tipo=' + tipo, doFillCombo, 'xml');
	cleanCombo(combo);
	ajax.doGet('http://' + document.location.host + '/includes_php/buscar_combos.php?tabla='+ tabla +'&id='+ id +'&campo=' + campo +'&valor=' + valor + '&campo_relacion=' + campo_relacion+ '&tipo=' + tipo, doFillCombo, 'xml');
	
	cargando.style.display = 'block';
}
function doFillCombo(xml){
	var id = xml.getElementsByTagName('id');
	var campo = xml.getElementsByTagName('campo');
	for(var i = 0; i < id.length; i++) {
		//option = document.createElement("option");
		//option.value= id[i].firstChild.nodeValue;
		//option.text= campo[i].firstChild.nodeValue;
		//combo.appendChild(option);
		combo.options[i] = new Option(campo[i].firstChild.nodeValue, id[i].firstChild.nodeValue);
	}
	//option = document.createElement("option");
	//option.value = 0;
	//option.text = 'Otro';
	//combo.appendChild(option);
	combo.options[i] = new Option('Otro', 0);
	cargando.style.display = 'none';
}

function cleanCombo(combo) {
	while(combo.childNodes.length > 0) {
		combo.removeChild(combo.childNodes[0]);
	}
}