var url = "/administration/scripts/scriptaculous-js-1.8.1/autocompletion.php?param="; // The server-side script
function apercu(f,id)
    {
    var a_cp = f.a_cp.value;
	var url = url
    var xhr;
    if (window.XMLHttpRequest) xhr = new XMLHttpRequest();
    else if (window.ActiveXObject) xhr = new ActiveXObject('Microsoft.XMLHTTP');
    else
        {
        alert('JavaScript : votre navigateur ne supporte pas les objets XMLHttpRequest...');
        return;
        }
    xhr.open('POST','/administration/scripts/scriptaculous-js-1.8.1/autocompletion.php',true);
    xhr.onreadystatechange = function()
        {
        if (xhr.readyState == 4)
            {
				<!-- Insere le contenu dans le corps de la page -->
            if (document.getElementById) document.getElementById(id).innerHTML = xhr.responseText;
            }
        }
    xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
    var data = 'a_cp='+escape(a_cp);
    xhr.send(data);
    }

/* http://www.webpasties.com/xmlHttpRequest/xmlHttpRequest_tutorial_3.html */

function handleHttpResponse() {
  if (http.readyState == 4) {
    if (http.responseText.indexOf('invalid') == -1) {
      // Use the XML DOM to unpack the city and state data 
      var xmlDocument = http.responseXML;
      var a_ville = xmlDocument.getElementsByTagName('a_ville').item(0).firstChild.data;
      var a_insee = xmlDocument.getElementsByTagName('a_insee').item(0).firstChild.data;
	  var a_cp = xmlDocument.getElementsByTagName('a_cp').item(0).firstChild.data;
  
	document.getElementById('a_ville').value = a_ville;
    document.getElementById('a_insee').value = a_insee;
	document.getElementById('a_cp').value = a_cp;
		
      isWorking = false;
    }
  }
}
var isWorking = false;
function updateCityState() {
  if (!isWorking && http) {
    var zipValue = document.getElementById("d_insee").value;
    http.open("GET", url + escape(zipValue), true);
    http.onreadystatechange = handleHttpResponse;
    isWorking = true;
    http.send(null);
  }
}
function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml");
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
