// JavaScript Document

// funzione per assegnare l'oggetto XMLHttpRequest
// compatibile con i browsers pių recenti e diffusi
function assegnaXMLHttpRequest() {

// lista delle variabili locali
var
 // variabile di ritorno, nulla di default
 XHR = null,
 
 // informazioni sul nome del browser
 browserUtente = navigator.userAgent.toUpperCase();


 // browser standard con supporto nativo
 // non importa il tipo di browser
 if(typeof(XMLHttpRequest) === "function" || typeof(XMLHttpRequest) === "object")
  XHR = new XMLHttpRequest();

 // browser Internet Explorer
 // č necessario filtrare la versione 4
 else if(
  window.ActiveXObject &&
  browserUtente.indexOf("MSIE 4") < 0
 ) {
 
  // la versione 6 di IE ha un nome differente
  // per il tipo di oggetto ActiveX
  if(browserUtente.indexOf("MSIE 5") < 0)
   XHR = new ActiveXObject("Msxml2.XMLHTTP");

  // le versioni 5 e 5.5 invece sfruttano lo stesso nome
  else
   XHR = new ActiveXObject("Microsoft.XMLHTTP");
 }

 return XHR;
} 


function count_donazione(myDiv){
  
	var ajax = assegnaXMLHttpRequest();
			
	if(ajax)
	{
		// applicativo AJAX
        var current_Div=document.getElementById(myDiv);
		//email = document.getElementById("harvester").email.value;
		current_Div.innerHTML="Caricamento in corso";

		// inizializzo la richiesta in post
		ajax.open("post", "count_donazione.asp", true);
		
		// imposto il giusto header
		ajax.setRequestHeader("content-type", "application/x-www-form-urlencoded");
	
		// ulteriore header consigliato per richieste get o post
		// da scrivere prima di utilizzare send

		ajax.setRequestHeader("connection", "close"); 
		ajax.onreadystatechange = function() {
		
		if (ajax.readyState == 4){
			if (ajax.status == 200) {
			    var xml=ajax.responseXML;
				var testo = xml.getElementsByTagName("message")[0].firstChild.nodeValue;
				current_Div.innerHTML=testo;
		   	} 
			else {
		   		current_Div.innerHTML="si &egrave; verificato un errore, riprovare pi&ugrave; tardi "+ajax.readyState;
			}
		}
		else {
			current_Div.innerHTML="si &egrave; verificato un errore, riprovare pi&ugrave; tardi "+ajax.readyState;
		}
}
		// effettuo la richiesta 
		ajax.send("");
	}
	else
	{
		alert("XMLHttpRequest non supportato")
	}
}