function dona_idx(num){
  document.getElementById("a_partir_de").value=num;
  if(num==0){
    id_sector=document.getElementById("sector").value;
    if(id_sector==0){document.getElementById("id_prov").value=0;}
    document.getElementById("id_sector").value=id_sector;  
  }
  else if(num==1){
    id_prov=document.getElementById("provincia").value;
    if(id_prov==0){document.getElementById("id_sector").value=0;}
    document.getElementById("id_prov").value=id_prov;    
  }   
}

function dona_url(){  
  id_s=document.getElementById("id_sector").value;     
  id_p=document.getElementById("id_prov").value;     
  result = getDataServer("proporciona_url_foro.php","?id_sector="+id_s+"&id_prov="+id_p,true); 
  document.getElementById("f_buscar").href="http://www.nuvisystem.com/"+result;     
}  

function getDataServer(url, vars){
   var xml = null;
   try{
       xml = new ActiveXObject("Microsoft.XMLHTTP");
   }catch(expeption){
       xml = new XMLHttpRequest();
   }
   xml.open("Get",url + vars, false);  
   xml.send(null);
   if(xml.status == 404) alert("Url no valida");
   return xml.responseText;
}

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

function carregaCombo(){
	a_partir_de=document.getElementById("a_partir_de").value;	
  if(a_partir_de==0){desti="provincia";origen="sector";}else{desti="sector";origen="provincia";}  
  selectOrigen=document.getElementById(origen);
  xml=crea_xml();
	selectDesti=document.getElementById(desti);
  id_s=document.getElementById("id_sector").value;
  id_p=document.getElementById("id_prov").value;		
  if(id_s==0 && origen=="sector"){
    a_partir_de=3;  
  }
  if(id_p==0 && origen=="provincia"){    
    a_partir_de=4; 
  }
	xml.open("GET", "carrega_selects_capcalera_nuvi_foro.php?id_sector="+id_s+"&a_partir_de="+a_partir_de+"&id_prov="+id_p, true);
	xml.onreadystatechange=function(){ 
		if (xml.readyState==4){
			selectDesti.parentNode.innerHTML=xml.responseText;
		} 
	}
	xml.send(null);
}
var fetSector=false;
var fetProvincia=false;

function inicial(quin){
  if(quin==0){
    if(fetSector==false){
      sector=document.getElementById("sector");
      result=getDataServer("capcalera_nuvisystem_foro.php","?inici="+1,true);
      array=result.split("*");
      sector.options.length=0; 
      sector.options.length=array[0];  
      i=1;e=1;   
      sector[0]=new Option("---Sector-------","0");      
      while(e-1<array[0]){
        sector[e]=new Option(array[i],array[i+1]);       
        i=i+2;
        e=e+1;
      }     
      fetSector=true;    
    }
  }
  else if(quin==1){
    if(fetProvincia==false){
      provincia=document.getElementById("provincia");
      result=getDataServer("capcalera_nuvisystem_foro.php","?inici="+2,true);
      array=result.split("*");
      provincia.options.length=0; 
      provincia.options.length=array[0];        
      i=1;e=1; 
      provincia[0]=new Option("---Localidad-------","0");         
      while(e-1<array[0]){
        provincia[e]=new Option(array[i],array[i+1]);
        i=i+2;
        e=e+1;
      }      
      fetProvincia=true;
    }
  }
}