var xmlHttp = false;
init();

function init(){
/* Create a new XMLHttpRequest object to talk to the Web server */
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
    xmlHttp = false;
  }
}
@end @*/

if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
  xmlHttp = new XMLHttpRequest();
}
}

function callServer() {

 document.getElementById('statut').innerHTML='<img src="/hec/loading.gif" /> searching...';
  //document.getElementById("before").innerHTML = xmlHttp.readyState;

if (xmlHttp.readyState!=0)
{
	xmlHttp.onreadystatechange = function() {};
	xmlHttp.abort();
        //xmlHttp = new XMLHttpRequest();
        xmlHttp = false;
        init();
        
}

  //document.getElementById("after").innerHTML = xmlHttp.readyState;


  // Build the URL to connect to
  var query = unescape ( encodeURIComponent(document.getElementById("pub_query").value));
  var uid = unescape ( encodeURIComponent(document.getElementById("uid").value));
  var url = "/hec/recherche/resultats_publications?query="+escape(query)+"&uid="+escape(uid);

  // Open a connection to the server
  xmlHttp.open("GET", url, true);

  // Setup a function for the server to run when it's done
  xmlHttp.onreadystatechange = updatePage;



  // Send the request
  xmlHttp.send(null);
 
}


function updatePage() {
  if (xmlHttp.readyState == 4) {
    response = xmlHttp.responseText;
    document.getElementById("labelrequete").innerHTML = '';
    document.getElementById("publications").innerHTML = response;
    if (response=='') document.getElementById("publications").innerHTML = '<br><br>Aucun résultat.';
    document.getElementById('statut').innerHTML='';
  }
}


