var xmlHttp;
var url;


/**
 * Do a request to a PHP file
 *
 * @param string parameters
 */
function makeRequest(parameters)
{
  /* try to get the XmlHttpObject */
  xmlHttp=getXmlHttpObject();
  
  /* if the object is null then notice the user */
  if(xmlHttp==null)
  {
    alert("Your browser does not support AJAX!");
    return;
  }
  
  /* prepare the url with the parameters for the request */
  url="http://www.ioscoop.com/engine/ajax/ajax.php"+parameters;
  
  /* add a random number to the url */
  url=url+"&sid="+Math.random();
  
  /* set the onreadystatechange element */
  xmlHttp.onreadystatechange=stateChanged;
  
  /* send the request */
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

/**
 * Get the XmlHttpObject
 *
 * @return var xmlHttp
 */
function getXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
    xmlHttp=new XMLHttpRequest();	//Firefox, Opera 8.0+, Safari
  }
  catch(e)
  {
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");	//Internet Explorer 6.0+
    }
    catch(e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");	//Internet Explorer 5.5+
    }
  }
  return xmlHttp;
}


/**
 * Read the JSON object and set all the div's to the retrieved values
 *
 * @param var req
 */
function setDataJSON(req)
{
  //alert(req.responseText);
  var data = eval("(" + req.responseText + ")");

  for(var i=0; i<data.items.length; i++)
  {
    document.getElementById(data.items[i].target).innerHTML=data.items[i].response;
  }
}


/**
 * Check the state of the request
 */
function stateChanged()
{
  if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  {
    if(xmlHttp.status==200)
    {
      setDataJSON(xmlHttp);
    }
    else
    {
      alert("Request failed! : " + xmlHttp.status);
    }
  }
}

