
function nuevoAjax()
{
	var xmlhttp=false;
	try
	{
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp=new XMLHttpRequest(); }
	return xmlhttp;
}





function ajaxDobleCombo1()
{
	var valor=document.getElementById("provincia").options[document.getElementById("provincia").selectedIndex].value;

	if(valor==0)
	{
		combo=document.getElementById("poblacion");
		combo.length=0;
		
		var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; 
		nuevaOpcion.innerHTML="Seleccione Población";
		combo.appendChild(nuevaOpcion);	
		combo.disabled=true;
	}
	else
		{
			combo=document.getElementById("poblacion");

			combo.enabled=true;
			combo.disabled=false;
			
			ajax=nuevoAjax();
			ajax.open("GET", "../../ficheros/gen_combo.php?tipo=1&valor="+valor,true);
			ajax.onreadystatechange=function()
			{
				if (ajax.readyState==1)
				{
					combo=document.getElementById("poblacion");
					combo.length=0;
					var nuevaOpcion=document.createElement("option"); nuevaOpcion.value=0; nuevaOpcion.innerHTML="Buscando...";

				}
				if (ajax.readyState==4)
				{
					if(ajax.responseXML.documentElement==null)
					{
						var  doc = new ActiveXObject("Msxml2.DOMDocument.4.0");
						doc.async = false;
						doc.loadXML(ajax.responseText);
					}
					else
					{
						var doc=ajax.responseXML;
					}

					var resp=doc.getElementsByTagName('response')[0];

					var nuevaOpcion=document.createElement("option"); 
					nuevaOpcion.value=""; nuevaOpcion.innerHTML="Seleccione Población";
					combo.appendChild(nuevaOpcion);

					for (i = 0; i < doc.getElementsByTagName('texto').length; i++)
						{
							var texto = doc.getElementsByTagName('texto')[i].firstChild.data;
							var valor = doc.getElementsByTagName('id')[i].firstChild.data;
							var selected = doc.getElementsByTagName('selected')[i].firstChild.data;
							var nuevaOpcion=document.createElement("option");
							nuevaOpcion.value=valor;
							nuevaOpcion.innerHTML=texto;
							if(selected)
								{
								nuevaOpcion.selected=true;
								}


							combo.appendChild(nuevaOpcion);
						}
						//document.getElementById("poblacion").innerHTML=ajax.responseText;
						combo.selectedIndex=0;
					}
				}
				ajax.send(null);
			}
		}
