// =========================================================================			 
// @function	AHAH function made by http://microformats.org/wiki/rest/ahah
// =========================================================================

function ahah(url, target, delay, method, parameters) {

  if (method == undefined) { 
	//  document.getElementById(target).innerHTML = 'caricamento dati in corso...';
	  if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	  } else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  if (req) {
		req.onreadystatechange = function() {
			ahahDone(url, target, delay, method, parameters);
		};
		req.open("GET", url, true);
		req.send("");
	  }  
  }
  if ( (method == "GET") || (method == "get") )
  {
	//  document.getElementById(target).innerHTML = 'caricamento dati in corso...';
	  if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	  } else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  if (req) {
		req.onreadystatechange = function() {
			ahahDone(url, target, delay, method, parameters);
		};
		req.open(method, url, true);
		req.send("");
	  }
  }

  if ( (method == "POST") || (method == "post") )
  {
	//  document.getElementById(target).innerHTML = 'caricamento dati in corso...';
	  if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	  } else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  if (req) {
		req.onreadystatechange = function() {
			ahahDone(url, target, delay, method, parameters);
		};
		req.open(method, url, true);
		req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		req.send(parameters);
	  }
  }
}

function ahahDone(url, target, delay, method, parameters) {
  if (req.readyState == 4) { 
    if (req.status == 200) { 
      document.getElementById(target).innerHTML = decodeURI(req.responseText);//decodeURI non è compatibile con Safari
      if (target=="risultatoRicerca") mostraRisultati();
      doppioClic()
    } else {
      document.getElementById(target).innerHTML="ahah error:\n"+req.statusText;
    }
  }
}
