function getXmlHttpRequestObject()
{
  if (window.XMLHttpRequest)
  {
	return new XMLHttpRequest(); //Not IE
  }
  else if (window.ActiveXObject)
  {
	return new ActiveXObject("Microsoft.XMLHTTP"); //IE
  }
  else
  {
	alert("No es posible cargar la página");
  }
}
	
var intval;

function mostrar(div, auto){
	var array_capas = new Array();
	array_capas[0] = "capa_tipo";
	array_capas[1] = "capa_zona";
	array_capas[2] = "capa_localidad";
	
	if(document.getElementById(div).style.display=='none')
	{
		document.getElementById(div).style.display='block';
		if (auto) intval=setTimeout("ocultar('"+div+"')",5000);
	}
	else ocultar(div);
	
	for(var i=0; i<3; i++)
	{
		if(array_capas[i] != div)
		{
			document.getElementById(array_capas[i]).style.display='none';
		}
	}
}
function ocultar(div){
	divIdioma=div;
	setTimeout(ocultarDelayed,100);
}
function ocultarDelayed(){
	document.getElementById(divIdioma).style.display='none';
}

function seleccionar(valor,texto,origen,destino){	
	document.getElementById(origen).value=texto;
	document.getElementById(destino).value=valor;
	if (destino == "zona")	
		cargar_pagina('../includes/buscador_recargar_localidad_eng.asp?recargar_localidad='+valor, 'zzzelect2');
	else
		if (destino == "localidad")
			cargar_pagina('../includes/buscador_recargar_zona_eng.asp?recargar_zona='+valor, 'zzzelect1');				
}

//Get our browser specific XmlHttpRequest object.
var receiveReq = getXmlHttpRequestObject();

//Initiate the asyncronous request.
function cargar_pagina(url, capa)
{
  //If our XmlHttpRequest object is not in the middle of a request, start the new asyncronous call.
  if (receiveReq.readyState == 4 || receiveReq.readyState == 0)
  { 
	//Setup the connection as a GET call to SayHello.html.
	//True explicity sets the request to asyncronous (default).
	receiveReq.open("GET", url, true);
	
	//Set the function that will be called when the XmlHttpRequest objects state changes.
	receiveReq.onreadystatechange = function(){controlar_carga(capa)};
	
	//Make the actual request.
	receiveReq.send(null);
  }
}

//Called every time our XmlHttpRequest objects state changes.
function controlar_carga(capa)
{
  //Check to see if the XmlHttpRequests state is finished.
  if (receiveReq.readyState == 4)
  {
	//Set the contents of our span element to the result of the asyncronous call.
	document.getElementById(capa).innerHTML = receiveReq.responseText;
  }
}