
// ATTENZIONE !!!
// Non conviene dichiarare questa variabile a livello globale in quanto +
// chiamate ajax in sequenza non consentono di discriminare una istanza 
// di un XMLHttp Object da un'altra;
// var _xmlHttp=null; // This is the XMLHttp Object

// returns an XMLHttp object... gets it in an IE/Mozilla friendly way..
function getXMLHTTP(){
  var A=null;
  try{
    A=new ActiveXObject("Msxml2.XMLHTTP")
  }catch(e){
    try{
      A=new ActiveXObject("Microsoft.XMLHTTP")
    } catch(oc){
      A=null
    }
  }
  if(!A && typeof XMLHttpRequest != "undefined") {
    A=new XMLHttpRequest()
  }
  return A
}

// This function uses the xmlHttp object to send a message back to the server...
// url is the query string to send to the server 
function callAction(url, functionToCall){
  if(_xmlHttp&&_xmlHttp.readyState!=0){
    _xmlHttp.abort()
  }
  var _xmlHttp=getXMLHTTP();
  if(_xmlHttp){
    _xmlHttp.open("GET", url, true);
    _xmlHttp.onreadystatechange=function() {
      if(_xmlHttp.readyState==4){
      	if(_xmlHttp.status == 200 && _xmlHttp.responseText) {
      	  eval(functionToCall + "(_xmlHttp.responseText);");
      	}
      	else{
      		if(self.errorHandler){
      			//if an error occurs the function errorHandler is called if it's defined
				errorHandler();
      		}
      		else{
      			alert("Error: " + _xmlHttp.status + ".  " + _xmlHttp.statusText);
      		}
      	}
      }
    }
    ;

    // DON'T TRY TO TALK WHEN WE'RE LOCAL...
    // Comment out when running from a local file...
    //_xmlHttp.send(null)

    //********************
    //per problema della cache con IE7
    _xmlHttp.setRequestHeader("If-Modified-Since","Sat, 1 Jan 2000 00:00:00 GMT");
    d = new Date();
	t = d.getTime();
	thetimestring=t.toString(10);
	_xmlHttp.send(thetimestring);

  }
}

// Go read about encodeURIComponent here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsmthencodeuricomponent.asp
// Basically converts a string to a valid uri... (spaces become %20, etc, etc..)
// this function was nb...
function escapeURI(La){
  if(encodeURIComponent) {
    return encodeURIComponent(La);
  }
  if(escape) {
    return escape(La)
  }
}
