// JavaScript Document
function objAjx(){
	    var xmlhttp = null;
	    if(window.XMLHttpRequest) 
	    {
		    xmlhttp = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera, Internet Explorer 7
	    } 
	    else if(window.ActiveXObject) 
	    {
		    try
		    {
			    xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); // Internet Explorer 6 
		    } 
		    catch(e) 
		    {
			    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer 4,5 
		    }
		    } 
	    else 
	    {
		    xmlhttp = null;
	    }
	    return xmlhttp;
    }
		function PageAjax(azione,pagina,div,invio){
//alert(azione)
		AjaX = objAjx();
		
         if(AjaX){
			 //Invio i dati in post 
			if(invio=="post"){
            args = azione.split("?")[1];
            file = azione.split("?")[0];
            AjaX.open("POST", pagina+file, true);
            AjaX.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			AjaX.send(args);
              AjaX.onreadystatechange=function(){
				  //alert(AjaX.responseText)
		  if(AjaX.readyState != 4) document.getElementById(div).innerHTML="Attendere prego......."	  
   //Se è andato tutto bene faccio vedere il risultato
      if (AjaX.readyState == 4 && AjaX.status==200){
		  //qui va la risposta in modolatà post
		  		 
 		  document.getElementById(div).innerHTML = AjaX.responseText 
     } 
	}
			}else{
           //Invio i dati in get
              AjaX.open('GET', pagina+azione+"&noCache="+ Math.floor(Math.random() * (9999)), true)
              AjaX.send(null) 
			  //Chiamo la funzione caricoRisultati quando c'è un cambio evento    
              AjaX.onreadystatechange=function(){
				  //alert(AjaX.responseText)
   //Se è andato tutto bene faccio vedere il risultato
      if (AjaX.readyState == 4 && AjaX.status==200){
		  if(pagina=="scarica.asp"){
		  var Arr = AjaX.responseText.split("|")
		  document.getElementById("file-"+Arr[0]).innerHTML = Arr[1];
		  var apri_file = window.open("","scarica_"+Arr[0]);
		  apri_file.focus();
		  }else{
 		  document.getElementById(div).innerHTML = AjaX.responseText;
		  }
	     }
	   } 
	 }
  }
}

