function fnajax()
{
	try	{
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		try	{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try	{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	if (!xmlHttp && typeof XMLHttpRequest!="undefined") { xmlHttp=new XMLHttpRequest(); }

	return xmlHttp;

}

function SearchFilter(oAjax, Types, iID)
{

	proc = document.getElementById("curtain");
	proc.style.display="";
	cargarSelector(document.getElementById("municipios"), "");
	cargarSelector(document.getElementById("departamentos"), "");
	txt="";
	txt="Municipios";

	var d = document.getElementById(oAjax)
	var ajax=fnajax();
	ajax.open("GET", "get_combos.php?Search="+iID+"&SearchType="+Types, true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(null);
	
	if(iID==1) {
		while (document.getElementById("municipios").length)
			document.getElementById("municipios").remove(0);
		while (document.getElementById("departamentos").length)
			document.getElementById("departamentos").remove(0);
	}
	
	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==4){
			if(!ajax.responseText) {
				proc.style.display="none";
			}else{
				str_elementos=ajax.responseText;
				array_elementos	= str_elementos.split("|");
				Munis = String(array_elementos[0]);
				Deptos = String(array_elementos[1]);
				if(array_elementos[0]!="") cargarSelector(document.getElementById("municipios"), Munis);
				if(array_elementos[1]!="") cargarSelector(document.getElementById("departamentos"), Deptos);
				proc.style.display="none";
			}
		}
	}
}


/* funciones para los combos */
function addOpt(oCntrl, iPos, sTxt, sVal)
{
    var selOpcion=new Option(sTxt, sVal);
	eval(oCntrl.options[iPos]=selOpcion);
}

function inicializarSelector(obj_destino)
{
    while (obj_destino.length)
		obj_destino.remove(0);

	addOpt(obj_destino, 0, ' ', 0); //agrego la primer opción --- Seleccione ---
}

function cargarSelector(obj_destino, str_elementos)
{
	array_elementos	= str_elementos.split(";");

	inicializarSelector(obj_destino);
	//agrego el resto de los elementos
	for (i=0 ; i<array_elementos.length ; i++){
		array_elemento = array_elementos[i].split("#");
		if( array_elemento.length>1) addOpt(obj_destino, i+1, array_elemento[1], array_elemento[0]);
	}
}

