function getXMLHTTPRequest()
{
var req = false;
try
  {
   req = new XMLHttpRequest(); /* e.g. Firefox */
  }
catch(err1)
  {
  try
    {
     req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
    }
  catch(err2)
    {
    try
      {
       req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
      }
      catch(err3)
        {
         req = false;
        }
    }
  }
return req;
}

var myRequest = getXMLHTTPRequest();
var myRequest2 = getXMLHTTPRequest();

function AjaxGetStreet(postcode) {

var myRandom=parseInt(Math.random()*99999999);

myRequest.open("GET", "getstreet.php?postcode=" + postcode + "&rand=" + myRandom, true);
myRequest.onreadystatechange = responseAjax;
myRequest.send(null);

}


function responseAjax() {
    // we are only interested in readyState of 4, i.e. "loaded"
    if(myRequest.readyState == 4) {
        // if server HTTP response is "OK"
        if(myRequest.status == 200) {
             document.getElementById('adres').value = myRequest.responseText;
             AjaxGetCity(document.getElementById('postcode').value);
        } else {
            // issue an error message for any other HTTP response
            alert("Ajax response error: " + myRequest.statusText);
        }
    }
}

function AjaxGetCity(postcode) {

var myRandom=parseInt(Math.random()*99999999);

myRequest2.open("GET", "getcity.php?postcode=" + postcode + "&rand=" + myRandom, true);
myRequest2.onreadystatechange = responseAjax2;
myRequest2.send(null);

}

function responseAjax2() {
    // we are only interested in readyState of 4, i.e. "loaded"
    if(myRequest.readyState == 4) {
        // if server HTTP response is "OK"
        if(myRequest2.status == 200) {
             document.getElementById('plaats').value = myRequest2.responseText;
             if(myRequest2.responseText == "Ongeldige postcode"){
             	document.getElementById("submitDiv").style.display = "none";
             	document.getElementById("showError").style.display = "block";
             }
             else
             {
             	document.getElementById("submitDiv").style.display = "block";
             	document.getElementById("showError").style.display = "none";
             }
        } else {
            // issue an error message for any other HTTP response
            alert("Ajax response error: " + myRequest2.statusText);
        }
    }
}
