   var http_request = false; 
   var cont='marco';
   function sndReqCat(pag) {	
		var thediv = document.getElementById(cont); // the div			
		var dire='searchdest.php?p='+provincia+'&o='+nota+'&pd='+provinciad+'&od='+notad;	
	  	thediv.innerHTML = '<span class="loading"><br><br><br><br><br><br><br><br><br><br><br><strong>Cargando...</strong><br><img src="images/working.gif" /><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></span>';		
			
	}
	
      
   function makeRequest_Cate(url) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 // alert("explorer "+url);
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
	  //alert("explorer d win "+url);
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
  
  
       if (!http_request) {
         alert ("No se pudo crear la instancia XMLHTTP");
         return false;
      }
      http_request.onreadystatechange = alertContentsCat;	 
      http_request.open('GET', url, true);
      http_request.send(null);	
   }



  function alertContentsCat() {	
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
			//AQUIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
            result = http_request.responseText;			
			var update = new Array();
			//alert("entre: "+result.indexOf('|'));
			//if(result.indexOf('|') != -1)
			//{
				update = result.split('|');	
				//changeTextCat(update[0], update[1]);
				//alert( "separando el contenido");
				//alert(update[0]+"    "+ update[1]+"    "+update[2]);
				changeTextCat(update[0]);
			//}     
         } 
		 
		 else {
            alert("Error en petición de BD");
         }
	
      }

   }




	function inicio(div,id,nivel) {		
	if (id>=0)
	{
		cont=div;
	    var thediv = document.getElementById(cont); // the div
		if (div=='provincia')
				{var dire='provincias.php?n='+nivel;	}
		if (div=='canton')
				{var dire='cantones.php?p='+id+'&n='+nivel;}				
		if (div=='parroquia')
				{var dire='parroquias.php?c='+id;}
		if (div=='recintos')
				{var dire='recintos.php?p='+id;}					
	  	thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);	
	}

	}
	function dignidad(div,id)
	{
		if (id>=0)
		{			
			if (id==1) presidente();
			if (id==2) inicio('provincia',0,2);
			if (id==3) inicio('provincia',0,3);
			if (id==4) inicio('provincia',0,4);
			if (id==5) inicio('provincia',0,5);
			if (id==6) inicio('provincia',0,6);
			if (id==7) inicio('provincia',0,7);		
			if (id==8) parlamentarios(0,5);
			if (id==9) asambleistasnacionales(0,5);
			if ((id!=1)&&(id!=5))
			//document.getElementById('map').innerHTML ='-';
			document.getElementById('provincia').innerHTML ='';
		}
		
	}
	
	function presidente()
	{
		var dire='presidente.php';	
		cont='map';
		var thediv = document.getElementById(cont);
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);			
	}
	function prefecto(prv)
	{
		var dire='prefecto.php?p='+prv;	
		cont='map';
		var thediv = document.getElementById(cont);
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);	
	}
	function DipProvincial(inicio,fin,prv)
	{
		var dire='asambleistaprovincial.php?i='+inicio+'&f='+fin+'&p='+prv;	
		cont='map';
		var thediv = document.getElementById(cont);
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);	
	}
	function consejalesrurales(inicio,fin,prv)
	{
		var dire='consejalesrurales.php?i='+inicio+'&f='+fin+'&p='+prv;
		cont='map';
		var thediv = document.getElementById(cont);
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);	
	}
	
	function alcalde(can)
	{
		var dire='alcalde.php?c='+can;
		cont='map';
		var thediv = document.getElementById(cont);
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);	
	}
	
	function consejalesurbanos(inicio,fin,can)
	{
		var dire='consejalesurbanos.php?i='+inicio+'&f='+fin+'&c='+can;	
		cont='map';
		var thediv = document.getElementById(cont);
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);	
	}
	function juntaparroquial(inicio,fin,parr)
	{
		var dire='juntaparroquial.php?i='+inicio+'&f='+fin+'&p='+parr;	
		cont='map';
		var thediv = document.getElementById(cont);
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);	
	}
	
	function parlamentarios(inicio,fin)
	{
		var dire='parlamentario.php?i='+inicio+'&f='+fin;	
		cont='map';
		var thediv = document.getElementById(cont);
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);	
	}
	
	function asambleistasnacionales(inicio,fin)
	{
		
		var dire='asambleistanacional.php?i='+inicio+'&f='+fin;	
		//alert(dire);
		cont='map';
		var thediv = document.getElementById(cont);
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><br><img src="images/working.gif" /></span>';						
		makeRequest_Cate(dire);	
	}
	
	
	function changeTextCat(text) {
		// Detect Browser
		id = parseInt(cont);
		var IE = (document.all) ? 1 : 0;
		var DOM = 0; 
		if (parseInt(navigator.appVersion) >=5) {DOM=1};		
		// Grab the content from the requested "div" and show it in the "container"
		if (DOM) {			
			if (id==-1)	{
			//	alert("aqui va: "+text+'  meter:  cate1['+nivel+']');
					var viewer = document.getElementById(cont);	}
				
			else
				var viewer = document.getElementById(cont); // the div
				viewer.innerHTML = text;	
		}  else if(IE) {
			
//			si es provinvia
			if (id==-1){
//				alert("aqui esta el nivel: "+text+'  meter:  cate1['+nivel+']');
				document.all[cont].innerHTML = text;}
			else{
			//alert(text);
			//	alert ("ponisndo un cantonnnnn: "+ text);
				document.all[cont].innerHTML = text;

			}
//          si es canton		
		}
	}


	function sndReqCat_rec(categoria, nivel) {
		
		var thediv = document.getElementById('cate_'+nivel); // the div
		if(categoria == 0){
			thediv.innerHTML = '';
			return false;
		}
		
		nivel++;
		thediv.innerHTML = '<span class="loading"><strong>Cargando...</strong><img src="working.gif" /></span>';
		
		makeRequest_rec('ajax.php?c='+categoria+'&n='+nivel);
	}


   function makeRequest_rec(url) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert("No se pudo crear la instancia XMLHTTP");
         return false;
      }
      http_request.onreadystatechange = alertContents_rec;
      http_request.open('GET', url, true);
      http_request.send(null);
   }


   function alertContents_rec() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
		   result = http_request.responseText;			
			var update = new Array();			
			if(result.indexOf('|') != -1) {
				update = result.split('|');
				changeTextCat_rec(update[0], update[1],update[2]);
			}       
         } else {
            alert("Error en petición de BD");
         }
      }
   }
	
	function changeTextCat_rec(div2show, text,nivel) {
		n=nivel-1;
	
		// Detect Browser
		id = parseInt(div2show);
		var IE = (document.all) ? 1 : 0;
		var DOM = 0; 
		if (parseInt(navigator.appVersion) >=5) {DOM=1};
	
		// Grab the content from the requested "div" and show it in the "container"
		if (DOM) {
			var viewer = document.getElementById('cate_'+n);
			viewer.innerHTML = text;		
		}  else if(IE) {
			document.all['cate_'+n].innerHTML = text;
		}
	}
	
	
	
	
	
	
	
