
function cargaMunicipios(select)
{
	document.getElementById("resultados").innerHTML="";
	var option=select.options[select.selectedIndex];
	
	var post=select.name+"="+select.value; 
	var zoom;
	(select.name=="departamento") ? zoom=7 : zoom=13;
	
	map.setCenter(new GLatLng(option.getAttribute("latitude"),option.getAttribute("longitude")), zoom);
	 
	if(select.name=="departamento")
	{
		ajax=creaAJAX();
		ajax.open("POST", "ajax.php?obtieneMunicipios&"+uid(),true);
		ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		ajax.send(post);
		
		ajax.onreadystatechange=function(){
			if(ajax.readyState==4){
				
				var respuesta=ajax.responseText;
				
				
				document.getElementById("capa_muni").innerHTML=respuesta;
				
				
			}
		}
	}
}


/*CREACION DEL OBJETO AJAX*/
function creaAJAX(){
	var xhr = false;
  	if(window.XMLHttpRequest){
    	xhr = new XMLHttpRequest();
  	}else if(window.ActiveXObject){
    		try{
      		xhr = new ActiveXObject("Msxml2.XMLHTTP");
      		}catch(e){
      			try{
        			xhr = new ActiveXObject("Microsoft.XMLHTTP");
      				}catch(e){
        				xhr = false;
      				}
    		}
  	}
  	return xhr;
}

function buscar() 
{
	var key = document.getElementById("clave").value.toLowerCase();

	var b=document.getElementById("resultados");
	
	b.innerHTML="";
	
	var div="<div id='in'>";
	
	
	
	if(document.getElementById("ips").checked)
	{
	
	for(var i=0;i<ips.length;i++)
	{
		if(ips[i].descripcion.toLowerCase().match(key) || ips[i].muni.toLowerCase().match(key) || ips[i].depa.toLowerCase().match(key))
		{
			div+="<a id='"+i+"' href='javascript:map.setCenter(new GLatLng("+ips[i].latitude+", "+ips[i].longitude+"),17);'><table width='95%' border='0' cellspacing='0' cellpadding='0'> <tr> <td><img src='images/icon.png' width='26' height='24' /></td> <td class='tit_encontrados_azul'>"+ips[i].descripcion+"</td> </tr> </table></a> ";

		}
	}
	}
	
	
	if(document.getElementById("farma").checked)
	{
	for(var i=0;i<farma.length;i++)
	{
	
		
		if((farma[i].descripcion.toLowerCase().match(key)) || (farma[i].muni.toLowerCase().match(key)) || ips[i].depa.toLowerCase().match(key))
		{
			div+="<a id='"+i+"' href='javascript:map.setCenter(new GLatLng("+farma[i].latitude+", "+farma[i].longitude+"),17);'><table width='95%' border='0' cellspacing='0' cellpadding='0'> <tr> <td><img src='images/icon2.png' width='26' height='24' /></td> <td class='tit_encontrados_azul'>"+farma[i].descripcion+"</td> </tr> </table></a> ";

		}
	}
	
	}
	
	div+="</div>";
	
	b.innerHTML+=div; 
	
}	

function uid(){
	return "uid="+Math.random()*Math.random()*Math.random();
}
