  var req;
  var which;
	var NnodoGlob;

	// Funzione che effettua la chiamata alla Action attraverso 
	// un url.  

  	function retrieveURL(url) {

	  	// se utilizzo un browser Internet Explorer
	
	    if (window.XMLHttpRequest) { 	
	    
	      req = new XMLHttpRequest();
	
	      req.onreadystatechange = processStateChange;
	
	     	 try {
				
				// uso metodo get
					
	       		 req.open("GET", url, true);
	
	     		 } catch (e) {
	
	        		alert(e);
	
	     		 }
	
	      req.send(null);
	
		// se utilizzo un browser Mozilla, Opera, Safari...
	
	    } else if(window.ActiveXObject) { // IE
	
	      req = new ActiveXObject("Microsoft.XMLHTTP");
	
	      if (req) {
	
	        req.onreadystatechange = processStateChange;
			
			// uso metodo get
	
	        req.open("GET", url, true);
	
	        req.send();
	
	      }
	
	    }
	
	  }
	  
function caricaNodo(select,Nnodo){
			
		LoadingStart();
		Nnodo=Nnodo+1;
		NnodoGlob=Nnodo;
		
		id_elemento=select.options[select.selectedIndex].value;
		url_action="getSelectOptionsVeloTable?id="+id_elemento+"&nodo="+NnodoGlob;
		
		retrieveURL(url_action);
}	  


function LoadingStart(){
		html="<div id=loading_testo><span id=\"testo\" class=\"normal10 grigio\">LOADING...</span></div>";
		html+= "<img src=\"img/loading.gif\" >";
		
		loading_cont = document.createElement("div");	
		loading_cont.setAttribute("id","loading_cont");
	
		document.getElementById("loading_div").appendChild(loading_cont);
		
		loading = document.createElement("div");	
		loading.setAttribute("id","loading");		
		loading.innerHTML=html;	
		
		document.getElementById("loading_cont").appendChild(loading);
	
	}
	
	
	function LoadingStartAction(){
		html="<div id=loading_testo><span id=\"testo\" class=\"normal10 grigio\">LOADING...</span></div>";
		html+= "<img src=\"../img/loading.gif\" >";
		
		loading_cont = document.createElement("div");	
		loading_cont.setAttribute("id","loading_cont");
	
		document.getElementById("loading_div").appendChild(loading_cont);
		
		loading = document.createElement("div");	
		loading.setAttribute("id","loading");		
		loading.innerHTML=html;	
		
		document.getElementById("loading_cont").appendChild(loading);
	
	}
	
	
function LoadingStop(){ 

	document.getElementById("loading_div").removeChild(document.getElementById("loading_cont"));
}




function processStateChange() {

		// Richiesta completata
	
	   	 if (req.readyState == 4) { 
	
			
		// gestione della risposta http a seconda del codice
		
		// codice 200=OK
			//alert('status: ' + req.status)
	     if (req.status == 200) { 

				 LoadingStop();
			//	 document.getElementById("nodo").innerHTML = '';
			//	document.getElementById("nodo").innerHTML = req.responseText;
			 alert(req.responseText);
	    alert(req.responseText.substring(req.responseText.length-500,req.responseText.length));
	  var NodoCorr=NnodoGlob-1;
	  			document.getElementById('nodo'+NodoCorr).innerHTML = '';
		document.getElementById('nodo'+NodoCorr).innerHTML = req.responseText;
	  
	    }

 	 }
}







function creaNodo(nome_nodo, nodo_padre){

		nuovo_nodo = document.createElement("div");	
		nuovo_nodo.setAttribute("id",nome_nodo);		
		
		document.getElementById(nodo_padre).appendChild(nuovo_nodo);	
		
		
		return nuovo_nodo;
	
	}

function caricaNextPg(url_action){
			LoadingStart();
		retrieveURL(url_action);
}


