var xmlHttp;
 
function getAddress(str){
  if (str.length==0){ 
    document.getElementById("postcode").innerHTML="";
    return;
  }
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null){
    alert ("Your browser does not support AJAX!");
    return;
  } 
  var url="getpc.php";
  url=url+"?field="+str;
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
} 
 
function explodeArray(item,delimiter){
  tempArray=new Array(1);
  var Count=0;
  var tempString=new String(item);
  while(tempString.indexOf(delimiter)>0){
    tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
    tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
    Count=Count+1
  }
  tempArray[Count]=tempString;
  return tempArray;
}
 
function stateChanged(){ 
  if (xmlHttp.readyState==4){ 
    var myarray = explodeArray(xmlHttp.responseText,',');
    if(myarray != ''){
      document.getElementById("plaats").value=myarray[0];
      document.getElementById("straat").value=myarray[1];
    }
  }
}
 
function GetXmlHttpObject(){
  var xmlHttp=null;
  try{
    xmlHttp=new XMLHttpRequest();
  }
  catch (e){
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e){
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}