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("http://www.nuvisystem.com/proporciona_url.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", "http://www.nuvisystem.com/carrega_selects_capcalera_nuvi.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);

}
