 	var bChecking = false
	var arrFoo = new Array()
	var arrPlaatsenPrev = new Array()
	var Plaatsen = new Array()
	var arrPlaatsen = new Array()
	var arrIDs = new Array()
	var arrKeywords = 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 = 'searchlocations.aspx?plaats='
	//sZoek = 'proxy.aspx?proxytarget=searchlocations&plaats='
	sLanguage= 'en'
	sZoek = '';
	bShow = false
	var nBreedte
	var nHeight = 0
	nHover = -1
	bHover = false
	bCancelEnterSubmit = false
	bEnabled = true
	bFocused = true
	sVorige = ''
	var oInput
	var VorigeLetter = ''
	var arrPlaatsenOrigineel
	var arrIDsOrigineel
	var arrKeywordsOrigineel
	var sWidth1, sWidth2, sWidthList
	var AccountID

	//Timing
	var StartOphalenTijd
	var EindOphalenTijd
	var StartProcessingTijd
	var EindProcessingTijd
	var blnInitialising = true;
	
	onlocationselected =  function( sDescription, intID ) { }
	
	function ShowInput( oForm, sInput, sValue, nWidthFrame, nWidthList, sExtra, bAan, intAccountID, blnSetFocus, strZoek, strLanguage)
	{
		if(strLanguage != '')
		{
			if(strLanguage != 'en' && strLanguage != 'EN' && strLanguage != 'NL' && strLanguage != 'nl')
			{
				sLanguage = 'en';
			}
			else
			{
				sLanguage = strLanguage;
			}
		}

		sZoek = strZoek;
		AccountID = intAccountID
		if ( document.getElementById && !( MAC && IE ) )
		{
			sWidth1 = nWidthFrame + 'px'
			sWidth2 = (nWidthFrame+2) + 'px'
			sWidthList = nWidthList + 'px'
			sWidth4 = sWidth2
			document.getElementById('DefaultInput').innerHTML = ''
			if ( IE )
			{
				//sWidth1 = '100%'
				sWidth2 = '100.4%'
				document.write('<div style="z-index: 999; position:relative; padding-bottom:0px; width:' + sWidth1 + ';">')
				document.write('	<div style="z-index: 999; position:absolute; left:0px; top:23px; width:' + sWidth1 + '; height:80px; ">')
				if ( !IE50 )
				{
					document.write('		<div id="FrameContainer" style="z-index: 999; position:absolute; left:0px; top:0px; width:' + sWidth2 + '; height:100%;">')
					document.write('			<iframe id="iFrame" style="z-index: 999; width:' + sWidth2 + '; height:0px;"></iframe>')
					document.write('		</div>')
				}
				document.write('		<div style="z-index: 999; position:absolute; left:0px; top:0px;width:' + sWidthList + ';">')
				document.write('			<div id="Lijst" style="width:' + sWidthList + ';" onmouseout="MouseOutLijst()"></div>')
				document.write('		</div>')
				document.write('	</div>')
				document.write('	<input type="text" class="input_enabled" id="' + sInput + '" style="width:' + sWidth2 + ';" name="' + sInput + '" value="' + sValue + '" autocomplete="off" onfocus="Focused(true)" onblur="Focused(false)" onkeyup="Check(event)" /><br/>')
			}
			else
			{
				//sWidth1 = '19.9em'
				sWidth2 = '20.4em'
				sWidth3 = '20.3em'
				document.write('<div style="z-index: 999;position:relative; padding-bottom:0px; width:' + sWidth1 + ';">')
				document.write('	<input class="autocomplete" autocomplete="off" onfocus="Focused(true)" onblur="Focused(false)" onkeyup="Check(event)" id="' + sInput + '" +  name="' + sInput + '" value="' + sValue + '" style="width:' + sWidth1 + ';"><br/>')
				document.write('	<div id="Lijst" style="position:absolute; width:' + sWidthList + ';" onmouseout="MouseOutLijst()"></div>')
			}
			document.write('	<div id="Message" style="position:absolute; width:' + sWidth2 + ';" onmouseout="MouseOutLijst()"></div>')
			document.write('	<div style="width=200px; top=200px; position:absolute;"><input type="hidden" id="DropDownLocationID" value="0" /></div>')
			document.write('	<div style="top=230px; position:absolute;"><input style="width=300px;" type="hidden" id="DropDownLocationName" value="" /></div>')
			document.write('	<div style="width=200px; top=300px; left=200px; position:absolute;"><input type="hidden" id="OutputText" value="" /></div>')
			document.write('</div>')
			oInput = oForm[sInput]
			if(blnSetFocus)
			{
				oInput.focus();
			}
			document.onclick = DocumentClick
			document.onkeyup = KeyUp
			document.onkeydown = KeyDown
			nBreedte = nWidthFrame
 		}
	}
	
	function ShowMessageDiv(strMessage)
	{
		document.getElementById('Message').style.display = 'block';
		document.getElementById('Message').style.visibility = 'visible';
		document.getElementById('Message').innerHTML = strMessage;
	}
	
	function HideMessageDiv()
	{
		document.getElementById('Message').style.display = 'none';
		document.getElementById('Message').style.visibility = 'hidden';
		document.getElementById('Message').innerHTML = ''
	}
	
	function Focused(b)
	{
		bFocused = b;
		
		if(b)
		{
			oInput.select();
		}
	}

	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)
	{
		if ( oInput.value.length >= 3 )
		{
			sString = sString.toLowerCase()
			if ( arrPlaatsenOrigineel )
			{
				arrPlaatsen = CopyArray( arrPlaatsenOrigineel )
				arrIDs = CopyArray( arrIDsOrigineel )
				arrKeywords = CopyArray( arrKeywordsOrigineel )
			}
			
			for ( i=arrPlaatsen.length-1; i>-1; i-- )
			{
				if(arrKeywords[i] != null && arrKeywords[i] != undefined)
				{
					if ( ( arrPlaatsen[i].toLowerCase().indexOf(sString) == -1 ) && ( arrKeywords[i].toLowerCase().indexOf(sString) == -1 ) ) Sloop(arrPlaatsen, arrIDs, arrKeywords, i );
				}
			}
		}
		SetLijst()
	}
	
	function Sloop(arrPlaatsen, arrIDs, arrKeywords, i)
	{
		for(n=i; n<arrPlaatsen.length-1; n++)
		{
			arrPlaatsen[ n ] = arrPlaatsen[ n + 1 ]
			arrIDs[ n ] = arrIDs[ n + 1 ]
			arrKeywords[ n ] = arrKeywords[ n + 1 ]
		}
		arrPlaatsen.length--
		arrIDs.length--
		arrKeywords.length--
	}
	
	function clearArrays()
	{
		arrPlaatsen.length = 0;
		arrIDs.length = 0;
		arrKeywords.length = 0;
		document.getElementById('OutputText').value = 'geen 3;' + arrPlaatsen.length;

	}
	
	function Check(event)
	{
		if(event.keyCode == 27 || (event.keyCode == 8 && oInput.value.length < 3))//Escape of backspace; close message
		{	
			HideMessageDiv();
		//	VorigeLetter	= '';
		//	Letter			= '';
		}
		
		if ( !bBrowserOk ) return
		if ( bEnabled == false || bChecking != false ) return //removed: || oInput.value == sVorige
		if ( event ) if ( event.keyCode == 13 ) return
		if ( event ) if ( event.keyCode == 34 ) return
		if ( event ) if ( event.keyCode == 33 ) return
		if ( event ) if ( event.keyCode == 40 ) return
		if ( event ) if ( event.keyCode == 38 ) return

		if ( oInput.value.length < 3 )
		{
			Hide();
			HideMessageDiv();
			clearArrays();
		//	VorigeLetter	= '';
		//	Letter			= '';
			return;
		}
		document.getElementById('OutputText').value = 'wel 3:    ' + arrPlaatsen.length;
		
		ShowMessageDiv('Searching, please wait....');
		
		sTypedValue = oInput.value
		Letter = oInput.value.substring(0,3)
		sVorige = oInput.value
		
		if ( VorigeLetter == Letter )
		{
			FilterPlaatsen(oInput.value)
			return
		}
		
		//if ( VorigeLetter == Letter && (event.keyCode != 8 && arrPlaatsen.length > 1))//Indien backspace en nog geen plaatsen gevonden dan opnieuw array ophalen 
		//{
//			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()
		//oXMLHTTP = new XMLHTTP()
		//oXMLHTTP.onerror = function(description) { alert('Error: ' + description) }


		if ( !oXMLHTTP )
		{
			// antieke browsers
			arrPlaatsen = ''
		}
		else
		{
			oXMLHTTP.onreadystatechange = function()
			{
				if (oXMLHTTP.readyState == 4)
				{
					EindOphalenTijd = new Date()
					//alert( EindOphalenTijd.getTime() - StartOphalenTijd.getTime() )

					StartProcessingTijd = new Date()
					arrFoo = oXMLHTTP.responseText
					
					//window.clipboardData.setData('text', arrFoo);
					
					//var x = oXMLHTTP.responseText;
					//window.clipboardData.setData('Text',x);
					//alert('copied');

					sHeader = '<plaatsen>'
					sFooter = '</plaatsen>'
					arrFoo = arrFoo.substring(sHeader.length, arrFoo.length - sFooter.length)
					
					arrFoo = arrFoo.split( ';' )
					//arrPlaatsen = arrPlaatsen.substring(sHeader.length, arrPlaatsen.length - sFooter.length)
					//arrPlaatsen = arrPlaatsen.split(';')
					for( i = 0; i < arrFoo.length; i++ )
					{
						strItem = arrFoo[ i ]
						tempArr = strItem.split( '|' )
						
						arrPlaatsen[ i ] = tempArr[ 0 ]
						arrIDs[ i ] = tempArr[ 1 ]
						arrKeywords[ i ] = tempArr[ 2 ]
					}
					//if ( arrPlaatsen != arrPlaatsenPrev )
					//{
						//arrPlaatsenPrev = arrPlaatsen
						//SetCapitalArray(arrPlaatsen)
						arrPlaatsenOrigineel = CopyArray( arrPlaatsen )
						arrIDsOrigineel = CopyArray( arrIDs )
						arrKeywordsOrigineel = CopyArray( arrKeywords )
						SetLijst()
						FilterPlaatsen(oInput.value)
					//}
					EindProcessingTijd = new Date()
					//alert( EindProcessingTijd.getTime() - StartProcessingTijd.getTime() )
				}
			}

			//oXMLHTTP.open("GET", sZoek + Letter , true) oInput.value
			StartOphalenTijd = new Date()
			
			//TODO:Ombouwen proxy ook moduleid mee kan geven ipv account id
			//voorlopig 611 hardcoded
			AccountID = "611";
     var search;
     if( document.getElementById('ProductType')!=null)
     {
      search =  sZoek + oInput.value + '&accountid=' + AccountID + '&language=' + sLanguage + '&producttype=' + document.getElementById('ProductType').value;
     }
     else
     {
      search =  sZoek + oInput.value + '&accountid=' + AccountID + '&language=' + sLanguage;
     }
    
  oXMLHTTP.open("GET",search) 
			oXMLHTTP.send(null)
		}
	}
	
	function Hide()
	{
		bShow = false
		document.getElementById('Lijst').style.display = 'none'
		if ( IE && !IE50 ) document.getElementById('FrameContainer').style.display = 'none'
	}
	
	function ShowLijst()
	{
		document.getElementById('Lijst').style.display = 'block'
		if ( IE && !IE50 ) document.getElementById('FrameContainer').style.display = 'block';
	}
	
function SetLijst()
	{
		document.getElementById('Lijst').innerHTML = ''
		nAantal = arrPlaatsen.length > 150 ? 150 : 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:' + sWidthList + ';">'
			for( i = 0; i < nAantal; i++ )
			{
				sPlaats = arrPlaatsen[i]
								
				sPlaatsSlash = sPlaats.replace( '\'', '\\\'' )
				s += '<tr class="gewoon" id="Link' + i + '" onmouseover="MouseOverLink(' + i + ')" onclick="CheckAutocompleteSubmit()">'
				s += '<td class="plaats" title="' + sPlaats + '">' + sPlaats + '</td>'
				s += '</tr>'
			}
			s += '</table>'
			document.getElementById('Lijst').innerHTML += s
			
			bShow = true

			var MaxItems = 30;
			
			if(arrPlaatsen.length > MaxItems)
			{
				HideMessageDiv();
				document.getElementById('Lijst').style.height = (MaxItems * 13) + 2;
			}
			else
			{
				HideMessageDiv();
				document.getElementById('Lijst').style.height = (arrPlaatsen.length * 13) + 2;
			}
			ShowLijst();
		}
		else
		{
			Hide()
		}
		if ( IE && !IE50 ) document.getElementById('iFrame').style.height = (document.getElementById('Lijst').clientHeight+2) + 'px'
		if ( nAantal == 0 ) Hide()
		bChecking = false

		if ( nAantal == 0 ) 
		{
		ShowMessageDiv('No results found.');
		}
		
		//Controleren of het zoekresultaat aan de hand van de url parameter gelijk is aan 1.
		//Zo ja, het enige zoekresultaat weergeven in "pickuplocation_ac"
		if (getLocation("location") !== "" && nAantal == 1)
		{			
			document.getElementById('pickuplocation_ac').value = TrimString(arrPlaatsen[0].toString());
			document.getElementById('pickuplocation').value = TrimString(arrPlaatsen[0].toString());
			document.getElementById('pickuplocationId').value = TrimString(arrIDs[0].toString());
			document.getElementById('dropofflocationId').value = TrimString(arrIDs[0].toString());
			document.getElementById('ChangeLocation').className = 'donotdisplay';
			document.getElementById('NoChangeLocation').className = 'block';						
			Hide();			
		}
		if (getLocation("location") !== "" && nAantal > 1)
		{			
			document.getElementById('ChangeLocation').className = 'block';
			document.getElementById('NoChangeLocation').className = 'donotdisplay';
			//document.getElementById('pickuplocation_ac').focus();
		}
		
	}

	
	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'
		}
		if(i > -1)
		{
			document.getElementById('DropDownLocationID').value = arrIDs[i];
			document.getElementById('DropDownLocationName').value = arrPlaatsen[i];
		}
	}
	
	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
		//oInput.blur()
		MouseOverLink(i)
	}
	
	function BlurList()
	{
		oInput.focus()
		MouseOverLink(-1)
		oInput.value = sTypedValue
	}
	
	function MouseOutLijst()
	{
		//nHover = -1
	}
	
	/*function Klik(s, sID)
	{
		Hide();
		
		oInput.focus()
		
		//document.getElementById('drdDropOffLocations').value = sID
		//document.getElementById('drdPickUpLocations').value = sID
		//document.frmSelectCar.locationFoundDescriptionPickUp.value = s

		onlocationselected( s, sID )
	}*/
	

	function SetCapitalArray(a)
	{
		for(i=0;i<a.length;i++)
		{
			a[i] = SetCapitals(a[i])
		}
	}
	
	function ToggleLijst()
	{
		if ( document.getElementById('Lijst').style.display == 'block' )
		{
			bShow = false
			document.getElementById('Lijst').style.display = 'none'
			if ( IE && !IE50 ) document.getElementById('FrameContainer').style.display = 'none'
		}
		else
		{
			bShow = true
			document.getElementById('Lijst').style.display = 'block'
			if ( IE && !IE50 ) document.getElementById('FrameContainer').style.display = 'block'
		}
		return false
	}
	
	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 ( !bEnabled ) return
		
		if( !event ) {
		    //if the browser did not pass the event information to the
			//function, we will have to obtain it from the event register
			if( window.event ) {
				//Internet Explorer
				event = window.event;
			} else {
				//total failure, we have no way of referencing the event
				return;
			}
		}
		
		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 ( !bEnabled ) return
		
		if( !event ) {
		    //if the browser did not pass the event information to the
			//function, we will have to obtain it from the event register
			if( window.event ) {
				//Internet Explorer
				event = window.event;
			} else {
				//total failure, we have no way of referencing the event
				return;
			}
		}
		
		if ( event.keyCode == 13 )
		{
			CheckAutocompleteSubmit()
		}
		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()
	{
		var intChosenLocationID		= document.getElementById('DropDownLocationID').value;
		var strChosenLocationName	= document.getElementById('DropDownLocationName').value;

		//if (( bFocused == true && bShow == true ) || bCancelEnterSubmit == true )
		//{
			Hide()
			onlocationselected(strChosenLocationName, intChosenLocationID);
			bCancelEnterSubmit = false
			updateFormXml('searchForm');
			passForm('searchForm');
			document.getElementById('ChangeLocation').className='donotdisplay';
			document.getElementById('NoChangeLocation').className='';
			document.getElementById('DisplayLocation').innerHTML= document.getElementById('DropDownLocationName').value;
			return false
		//}
		
		//return CheckInput()
	}

//Functie die de url parameter als string ophaalt
function getLocation(strParamName)
{
   var strReturn = "";
   var strHref = document.location.href;
	  
   if ( strHref.indexOf("?") > -1 )
   {
	var strQueryString = strHref.substring(strHref.indexOf("&")).toLowerCase();
	var aQueryString = strQueryString.split("&");
	    
	for (var iParam = 0; iParam < aQueryString.length; iParam++)
	{
		if (aQueryString[iParam].indexOf(strParamName + "=") > -1 )
		{
		    var aParam = aQueryString[iParam].split("=");
		    strReturn = aParam[1];
		    break;
		}
	}
    }
    return strReturn;
}

//Functie die controleert of er een parameter wordt meegegeven aan de url
function showLocations(event)
{
//Er is wel een parameter meegegeven aan de url
	if(getLocation("location") !== "")
	{
		//Vul de waarde van de parameter in het locatieveld en focus op dit veld
		document.getElementById('pickuplocation_ac').value = (getLocation("location"));
		document.getElementById('pickuplocation_ac').focus();
				
		//Check de parameter met de database en geef de mogelijkheden weer in dropdown
		Check(event);
	}
} 

