	var bChecking = false
	var arrPlaatsenPrev = new Array()
	var Plaatsen = new Array()
	var arrPlaatsen = new Array()
	var oXMLHTTP
	var sTypedValue = ''
	var bBrowserOk = window.ActiveXObject || window.XMLHttpRequest
	var MAC = ( navigator.appVersion.indexOf("Macintosh") != -1 )
	var IE = ( navigator.appVersion.indexOf("MSIE") != -1 )
	var IE50 = ( navigator.appVersion.indexOf("MSIE 5.0") != -1 )
	sZoek = '/plaatsen.php?plaats='
	bShow = false
	var nBreedte
	var nHeight = 0
	nHover = -1
	bHover = false
	bCancelEnterSubmit = false
	bFocused = true
	sVorige = ''
	var oInput
	var VorigeLetter = ''
	var arrPlaatsenOrigineel
	var sWidth1, sWidth2, sWidth3
	
	function ShowInput(oForm, sInput, sValue, nWidth, sExtra, bAan)
	{
		if ( document.getElementById && !( MAC && IE ) )
		{
			sWidth1 = nWidth + 'px'
			sWidth2 = (nWidth+2) + 'px'
			sWidth3 = '98%'
			sWidth4 = sWidth2
			document.getElementById('DefaultInput').innerHTML = ''
			if ( IE )
			{
				sWidth1 = '98%'
				sWidth2 = '98.4%'
				document.write('<div style="position:relative; padding-bottom:5px; width:' + sWidth1 + ';">')
				document.write('	<div style="position:absolute; z-index:99;left:0px; top:23px; width:' + sWidth1 + '; height:100px; ">')
				if ( !IE50 )
				{
					document.write('		<div id="FrameContainer" style="position:absolute; left:0px; top:0px; width:' + sWidth2 + '; height:100%;">')
					document.write('			<iframe id="iFrame" style="width:' + sWidth2 + '; height:0px;"></iframe>')
					document.write('		</div>')
				}
				document.write('		<div style="position:absolute; left:0px; top:0px;width:' + sWidth1 + ';">')
				document.write('			<div id="Lijst" style="width:' + sWidth1 + ';" onmouseout="MouseOutLijst()"></div>')
				document.write('		</div>')
				document.write('	</div>')
				document.write('	<input type="text" id="plaats" style="width:' + sWidth2 + ';" name="' + sInput + '" value="' + sValue + '" autocomplete="off" onfocus="Focused(true)" onblur="Focused(false)" onkeyup="Check(event)" /><br/>')
			}
			else
			{
				sWidth1 = '13.9em'
				sWidth2 = '14.4em'
				sWidth3 = '14.3em'
				document.write('<div style="position:relative; padding-bottom:5px; width:' + sWidth1 + ';">')
				document.write('	<input class="autocomplete" autocomplete="off" onfocus="Focused(true)" onblur="Focused(false)" onkeyup="Check(event)" name="' + sInput + '" value="' + sValue + '" style="width:' + sWidth1 + ';"><br/>')
				document.write('	<div id="Lijst" style="position:absolute; width:' + sWidth2 + ';" onmouseout="MouseOutLijst()"></div>')
			}
			document.write('</div>')
			oInput = oForm[sInput]
			oInput.focus()
			document.onclick = DocumentClick
			document.onkeyup = KeyUp
			document.onkeydown = KeyDown			
			nBreedte = nWidth
 		}
	}
	
	function Focused(b)
	{
		bFocused = b
	}

	function Focus()
	{
		bFocus = true
		oInput.focus()
	}
	
	function Blur()
	{
		bFocus = false
	}

	function CopyArray(aArray)
	{
		var Nieuw = new Array()
		for(i=0;i<aArray.length;i++)
		{
			Nieuw[i] = aArray[i]
		}
		return Nieuw
	}
	
	function FilterPlaatsen(sString)
	{
		sString = sString.toLowerCase()
		if ( arrPlaatsenOrigineel ) arrPlaatsen = CopyArray(arrPlaatsenOrigineel)
		for ( i=arrPlaatsen.length-1; i>-1; i-- )
		{
			if ( arrPlaatsen[i].substring(0, sString.length).toLowerCase() != sString ) Sloop(arrPlaatsen, i)
		}
		SetLijst()
	}
	
	function Sloop(arrPlaatsen, i)
	{
		for(n=i; n<arrPlaatsen.length-1; n++)
		{
			arrPlaatsen[n] = arrPlaatsen[n+1]
		}
		arrPlaatsen.length --
	}
	
	function Check(event)
	{
		if ( !bBrowserOk ) return
		if ( bChecking != false || oInput.value == sVorige ) return
		if ( event ) if ( event.keyCode == 13 ) return
		if ( oInput.value.length == 0 ) Hide()
		
		sTypedValue = oInput.value
		Letter = oInput.value.substring(0,1)
		sVorige = oInput.value
		
		if ( VorigeLetter == Letter )
		{
			FilterPlaatsen(oInput.value)
			return
		}

		VorigeLetter = Letter
		bChecking = true
		
		oXMLHTTP = false
		// ActiveXObject voor IE, XMLHttpRequest voor firefox
		if ( window.ActiveXObject ) oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP")
		if ( window.XMLHttpRequest ) oXMLHTTP = new XMLHttpRequest()

		if ( !oXMLHTTP )
		{
			// antieke browsers
			arrPlaatsen = ''
		}
		else
		{
			oXMLHTTP.onreadystatechange = function()
			{
				if (oXMLHTTP.readyState == 4)
				{
					arrPlaatsen = oXMLHTTP.responseText
					arrPlaatsen = arrPlaatsen.split(',')
					if ( arrPlaatsen != arrPlaatsenPrev )
					{
						arrPlaatsenPrev = arrPlaatsen
						SetCapitalArray(arrPlaatsen)
						arrPlaatsenOrigineel = CopyArray(arrPlaatsen)
						SetLijst()
						FilterPlaatsen(oInput.value)
					}
				}
			}

			oXMLHTTP.open("GET", sZoek + Letter , true)
			oXMLHTTP.send(null)
		}
	}
	
	function Hide()
	{
		bShow = false
		document.getElementById('Lijst').style.display = 'none'
		if ( IE && !IE50 ) document.getElementById('FrameContainer').style.display = 'none'
	}
	
	function SetLijst()
	{
		document.getElementById('Lijst').innerHTML = ''
		nAantal = arrPlaatsen.length > 5 ? 5 : arrPlaatsen.length
		n = 2 + 16 * nAantal
		if ( n > 120 ) n = 120
		nHeight = 73 - n
		if ( navigator.userAgent.indexOf("Firefox")>0 ) nHeight += 16
		
		nHeight = nHeight < 0 ? 0 : nHeight
		if ( arrPlaatsen[0] != '' )
		{
			nHover = -1
			s = '<table cellpadding=0 cellspacing=0 style="width:' + sWidth3 + ';">'
			for(i=0;i<nAantal;i++)
			{
				sPlaats = arrPlaatsen[i]
				sAantal = sPlaats.substring(sPlaats.indexOf('|')+1, sPlaats.length)
				sPlaats = sPlaats.substring(0, sPlaats.indexOf('|'))
				sPlaatsSlash = sPlaats.replace('\'', '\\\'')
				Plaatsen[i] = sPlaats
				s += '<tr class="gewoon" id="Link' + i + '" onmouseover="MouseOverLink(' + i + ')" onclick="Klik(\'' + sPlaatsSlash + '\')">'
				s += '<td class="plaats" title="' + sPlaats + ', ' + sAantal + ' woningen"><span class="aantal" style="float:right;">' + sAantal + '</span>' + sPlaats + '</td>'
				s += '</tr>'
			}
			s += '</table>'
			document.getElementById('Lijst').innerHTML += s
			
			bShow = true
			document.getElementById('Lijst').style.display = 'block'
			if ( IE && !IE50 ) document.getElementById('FrameContainer').style.display = 'block'
		}
		else
		{
			Hide()
		}
		if ( IE && !IE50 ) document.getElementById('iFrame').style.height = (document.getElementById('Lijst').clientHeight+2) + 'px'
		if ( nAantal == 0 ) Hide()
		bChecking = false
		MouseOverLink(0)
	}
	
	function MouseOverLink(i)
	{
		if ( nHover > -1 )
		{
			if ( document.getElementById('Link' + nHover) ) document.getElementById('Link' + nHover).className = 'gewoon'
		}
		nHover = i
		if ( i != -1 )
		{
			if ( document.getElementById('Link' + i) ) document.getElementById('Link' + i).className = 'LinkHover'
		}
	}
	
	function KeyDownLink(i)
	{
		if ( parseInt(document.getElementById('Lijst').scrollTop) < -36 + i*16 ) document.getElementById('Lijst').scrollTop = -36 + i*16
		if ( parseInt(document.getElementById('Lijst').scrollTop) > i*16 ) document.getElementById('Lijst').scrollTop = i*16
		MouseOverLink(i)
	}

	function BlurList()	{
		oInput.focus()
		MouseOverLink(-1)
		oInput.value = sTypedValue
	}
		
	function MouseOutLijst()
	{
		//nHover = -1
	}
	
	function Klik(s)
	{
		oInput.value = s
		bShow = false
		document.getElementById('Lijst').style.display = 'none'
		if ( IE && !IE50 ) document.getElementById('FrameContainer').style.display = 'none'
		oInput.focus()
	}
	

	function SetCapitalArray(a)
	{
		for(i=0;i<a.length;i++)
		{
			a[i] = SetCapitals(a[i])
		}
	}
	
	function MouseOut()
	{
		bHover = false
	}

	function MouseOver()
	{
		bHover = true
	}

	function SetCapitals(s)
	{
		if ( s.indexOf(' ') > -1 || s.indexOf('-') > -1 )
		{
			s = MultipleCapitals(s)
		}
		else
		{
			s = s.substring(0,1).toUpperCase() + s.substring(1,s.length).toLowerCase()
		}
		return s
	}
	
	function MultipleCapitals(sInput)
	{
		var sSeparators = ' -'
		var sOutput = sInput.substring(0,1).toUpperCase()
		for ( var i=1; i<sInput.length; i++ )
		{
			if ( sSeparators.indexOf(sInput.charAt(i-1)) > -1 )
			{
				sOutput += sInput.substring(i,i+1).toUpperCase()
			}
			else
			{
				sOutput += sInput.substring(i,i+1).toLowerCase()
			}
		}
		return sOutput
	}
	
	function DocumentClick() {
		if ( !bBrowserOk ) return
		if ( bHover == false )
		{
			Hide()
		}
	}
	
	function CheckKeypress(event) {
		if ( !bBrowserOk ) return
		if ( bShow == true )
		{
			if ( event.keyCode == 40 ) return false
			if ( event.keyCode == 38 ) return false
		}
		return true
	}
	
	function KeyDown(event)
	{
		if ( event.keyCode == 13 )
		{
			bCancelEnterSubmit = bShow
		}
		else
		{
			bCancelEnterSubmit = false
		}
		if ( event.keyCode == 34 ) GoDown(4)
		if ( event.keyCode == 33 ) GoUp(4)
		if ( event.keyCode == 40 ) GoDown(1)
		if ( event.keyCode == 38 ) GoUp(1)
	}
	
	function KeyUp(event)
	{
		if ( event.keyCode == 13 ) Enter()
		if ( event.keyCode == 27 ) Enter()
		if ( event.keyCode == 9 ) Enter()
	}
	
	function Enter(bEnter)
	{
		if ( !bBrowserOk ) return
		if ( bShow == true )
		{
			Hide()
			oInput.focus()
		}
	}
	
	function GoDown(n)
	{
		if ( !bBrowserOk ) return
		if ( bFocused == false ) return
		if ( bShow == false ) Check()
		n = nHover + n
		if ( !window.nAantal ) return
		if ( n > nAantal-1 )
		{
			n = 0
		}
		KeyDownLink(n)
	}

	function GoUp(n)
	{
		if ( !bBrowserOk ) return
		if ( bFocused == false ) return
		if ( bShow == false ) Check()
		n = nHover - n
		if ( n < 0 )
		{
			n = nAantal-1
		}
		KeyDownLink(n)
	}
	
	function CheckAutocompleteSubmit()
	{
		//alert( 'bFocused = ' + bFocused + '\nbShow = ' + bShow + '\nbCancelEnterSubmit = ' + bCancelEnterSubmit )
		if (( bFocused == true && bShow == true ) || bCancelEnterSubmit == true )
		{
			Hide()
			oInput.value = Plaatsen[nHover]
			bCancelEnterSubmit = false
			return false
		}
		
		return true;
	}