var url = "postcode/postcode_conv.php?param="; // The server-side script
function handleHttpResponse() {
  if (http.readyState == 4) {
    /*  alert(http.responseText);  */
    if (http.responseText.indexOf('invalid') == -1) {
   
      // Use the XML DOM to unpack the city and state data 
      var xmlDocument = http.responseXML; 
      var straat = xmlDocument.getElementsByTagName('straat').item(0).firstChild.data;
      var plaats = xmlDocument.getElementsByTagName('plaats').item(0).firstChild.data;
      var postcode = xmlDocument.getElementsByTagName('cleanpostcode').item(0).firstChild.data; 
      document.getElementById('postcode').value = postcode;   
      document.getElementById('straat').value = straat;
      document.getElementById('plaats').value = plaats;
      isWorking = false;
    }
  }
}                                                    
var isWorking = false;
function updateCityState() {   
  if (!isWorking && http) {
    var zipValue = document.getElementById("postcode").value;  
    var straatValue= document.getElementById("straat").value;
    var plaatsValue= document.getElementById("plaats").value;  
    myrefresh= Math.floor(Math.random()*100000)


    http.open("GET", url + escape(zipValue) + '&straat=' + escape(straatValue) + '&plaats=' + escape(plaatsValue)+ '&refresh=' + escape(myrefresh) , 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

