var xmlhttp
var div
//var imgdir = "http://www.sp3i.it/public/images/";
var imgdir = "";

function loadDoc(url,id,act,swi)
{
  if (swi && (document.getElementById(id).innerHTML!="")) 
  {
    document.getElementById(id).innerHTML="";
    document.getElementById(id).style.display="none";
    document.body.focus()
    return;
  }

  document.getElementById(id).style.display="block";
  document.getElementById(id).innerHTML="<center><img src='"+imgdir+"ajax-loader.gif'><br /><br /></center>";
//alert(document.getElementById(id).innerHTML);
  xmlhttp=null
  div = id

  try
  {
    // code for Mozilla, etc.
    if (window.XMLHttpRequest)
    {
      xmlhttp=new XMLHttpRequest()
      // some versions of Moz do not support the readyState property and the onreadystate event so we patch it!
      if(xmlhttp.readyState == null) 
      {
	xmlhttp.readyState = 1;
	xmlhttp.addEventListener("load", function() { xmlhttp.readyState = 4; if(typeof xmlhttp.onreadystatechange == "function") xmlhttp.onreadystatechange();}, false);
      }
    }
    // code for IE
    if (window.ActiveXObject)
    {
      xmlhttp=new ActiveXObject(_getXmlHttpProgID())
    }
    if (xmlhttp!=null)
    {
      xmlhttp.onreadystatechange=state_Change
      xmlhttp.open("GET",url,true)
      //xmlhttp.open("GET","http://127.0.0.1/sp3i/public/presentazione/corpo_primopiano_s1.asp",true)
      //xmlhttp.setRequestHeader('Accept','message/x-jl-formresult')
      xmlhttp.send(null)
    }
    else
    {
      alert("Your browser does not support XMLHTTP.")
    }
  }
  catch (ex) {};
  //throw new Error("Could not find an installed XML parser");
  
  document.body.focus();
}

function _getXmlHttpProgID()
{
  var progids = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
  for(var i = 0; i < progids.length; i++)
  {
    try
    {
      o = new ActiveXObject(progids[i]);
      return progids[i];
    }
    catch (ex) {};
  }
  throw new Error("Could not find an installed XML parser");
}

function state_Change()
{
  // if xmlhttp shows "loaded"
  if (xmlhttp.readyState==4)
  {
    // if "OK"
    if (xmlhttp.status==200)
    {
      document.getElementById(div).innerHTML=xmlhttp.responseText
    }
    else
    {
      document.getElementById(div).innerHTML="";
      document.getElementById(div).style.display="none";
      alert("Problem retrieving data:" + xmlhttp.statusText)
    }
  }
  else
  {
    document.getElementById(div).innerHTML="<center><img src='"+imgdir+"ajax-loader.gif'><br /><br /></center>";
  }
  document.body.focus();
}
