
// Restituisce una istanza dell'oggetto XMLHttp (cross-browser)
function getXMLHttp()
{
  var xmlhttp=false;
  // Utilizziamo la compilazione condizionale di JScript
  // per far fronte alle vecchie versioni di
  // Internet Explorer che non supportano i blocchi try/catch.
  /*@cc_on @*/
  /*@if (@_jscript_version >= 5)
  // Prova la creazione dell'oggetto ActiveX XMLHTTP
  try
  {
    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
  }
  catch (e)
  {
    try
    {
      xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch (E)
    {
      xmlhttp = false;
    }
  }
  @end @*/
  // Se il browser non è Internet Explorer viene creato
  // l'oggetto XMLHttpRequest (Netscape, Mozilla)
  if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
    xmlhttp = new XMLHttpRequest();
  }
  return xmlhttp;
}

// Si connette all'URL specificato, ne preleva i contenuti
// e li visualizza come contenuto del tag avente l'ID specificato
function getURL(url, id, mostra_id, nascondi_id)
{
  var xmlhttp = getXMLHttp();
  if (!xmlhttp)
  {
    alert('XMLHttp non supportato dal browser');
    return false;
  }

  
  xmlhttp.open('GET', url, true);
  xmlhttp.onreadystatechange=function()
  {
    if (xmlhttp.readyState==4)
    {
      
      if (xmlhttp.status == 200)
      {
        var elem = document.getElementById(id);
        if(elem == null)
          alert('Elemento inesistente: ' + id);
        else
          elem.innerHTML = xmlhttp.responseText;
					ahahEvalJS(id);
					if (mostra_id>'')	show(mostra_id);
					if (nascondi_id>'')	hide(nascondi_id);
      }
      else if (xmlhttp.status == 404)
        alert('URL inesistente: ' + url);
      else
        alert('Errore: ' + xmlhttp.status);
    }
  }
  xmlhttp.send(null)
}

ahahEvalJS = function(elementId) {
	var scripts = document.getElementById(elementId).getElementsByTagName('script');
	var code;
	for (var i = 0; i < scripts.length; i++) {
		code =	scripts[i].innerHTML ? scripts[i].innerHTML : 
			scripts[i].text ? scripts[i].text : 
			scripts[i].textContent;
		try {
			eval(code);
		} catch(e) {
			alert(e);
		}
	}
}





