var xhr = null;

function getXhr(){
  if(window.XMLHttpRequest) // Firefox et autres
    xhr = new XMLHttpRequest();
  else if(window.ActiveXObject){ // Internet Explorer 
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  else { // XMLHttpRequest non supporté par le navigateur 
    alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
    xhr = false;
  }
}

function getRue(where,entite) {
  document.body.style.cursor = 'wait';
  window.setTimeout("performGetRue('"+where+"','"+entite+"');", 100);
}

function performGetRue(where,entite) {
  getXhr();
  xhr.onreadystatechange = function(){
    if(xhr.readyState == 4 && xhr.status == 200){
      disphtml = xhr.responseText;
      document.getElementById(where).innerHTML = disphtml;
      document.body.style.cursor = 'default';
    }
  }
  document.getElementById(where).innerHTML = '';
  document.getElementById('tdagent').innerHTML = '';
  qstring = 'detail='+escape(entite);
  xhr.open("POST","proximite_liste_rues.php",true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send(qstring);
}

function getAgent(where,rue) {
  document.body.style.cursor = 'wait';
  window.setTimeout("performGetAgent('"+where+"','"+rue+"');", 100);
}

function performGetAgent(where,rue) {
  getXhr();
  xhr.onreadystatechange = function(){
    if(xhr.readyState == 4 && xhr.status == 200){
      disphtml = xhr.responseText;
      document.getElementById(where).innerHTML = disphtml;
      document.body.style.cursor = 'default';
    }
  }
  document.getElementById(where).innerHTML = '';
  qstring = 'detail='+escape(rue);
  xhr.open("POST","proximite_item_agent.php",true);
  xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  xhr.send(qstring);
}

