// 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){
		return false;
	}
	var ajax = new Ajax();
	cargando = document.getElementById(ld);
	combo = document.getElementById(comboO);
	cleanCombo(combo);
	ajax.doGet('../../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 fillCombo2(tabla, id, campo, valor, campo_relacion, tipo, comboO, ld){
	if(tipo == 'like' && valor.length <= 2){
		return false;
	}
	var ajax = new Ajax();
	cargando = document.getElementById(ld);
	combo = document.getElementById(comboO);
	cleanCombo(combo);
	ajax.doGet('../../includes_php/buscar_combos2.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);
	}
	cargando.style.display = 'none';
}

function cleanCombo(combo) {
	while(combo.childNodes.length > 0) {
		combo.removeChild(combo.childNodes[0]);
	}
}
