﻿    var _placesOriginalArray
    var _global;
   	var _placesArrayPrevious = new Array()
	var _places = new Array()
	var _placesArray = new Array()
	var _height = 0
	var _hover = -1
	var _isHover = false
	var _previousInput = ''
	var _checking = false	
    var _cancelEnterSubmit = false
    var _enabled = true
	var _focused = true
	var _xmlHTTP
	var _typedValue = ''
	var _browserOk = window.ActiveXObject || window.XMLHttpRequest
	var _search = '/modules/spp/callback.ashx?action=autoComplete&plaats=';
	var _show = false;
	var _input;
	var _lasturl = '';
	
	var IE = ( navigator.appVersion.indexOf("MSIE") != -1 )
	var IE50 = ( navigator.appVersion.indexOf("MSIE 5.0") != -1 )
	
	
	
function InsertOption(oNaar, oNew, nPlace)
 {
    oNaar.options.length ++
    var ii
    for( ii=oNaar.options.length-1; ii>nPlace; ii--)
    {
    oNaar.options[ii].text = oNaar.options[ii-1].text
    oNaar.options[ii].value = oNaar.options[ii-1].value
    }
    oNaar.options[nPlace] = oNew
}

function fnRemoveAllOptions(oSoort_woning)
{
    i=oSoort_woning.length;
    while(oSoort_woning.length > 0)
    {
        oSoort_woning.remove(i);
        i--;
    }
}

function fnGetOptions(sSoort_woning)
{
    oSoort_woning=document.getElementById(sSoort_woning);
    
    fnRemoveAllOptions(oSoort_woning);
    
    oNew = new Option('Geen voorkeur','Geen voorkeur');
    InsertOption(oSoort_woning,oNew,0);
    
    oNew = new Option('Bovenwoning','Bovenwoning');
    InsertOption(oSoort_woning,oNew,1);
    
    oNew = new Option('Benedenwoning','Benedenwoning');
    InsertOption(oSoort_woning,oNew,2);
    
    oNew = new Option('Maisonnette','Maisonnette');
    InsertOption(oSoort_woning,oNew,3);
    
    oNew = new Option('Galerijflat','Galerijflat');
    InsertOption(oSoort_woning,oNew,4);
    
    oNew = new Option('Portiekflat','Portiekflat');
    InsertOption(oSoort_woning,oNew,5);
    
    oNew = new Option('Beneden + bovenwoning','Beneden + bovenwoning');
    InsertOption(oSoort_woning,oNew,6);
    
    oNew = new Option('Verzorgingsflat','Verzorgingsflat');
    InsertOption(oSoort_woning,oNew,7);
    
}

function fnGetWhoonhuisOptions(sSoort_woning,sOptions)
{
    fnRemoveAllOptions(oSoort_woning);
    optionList = sOptions.split(",");
   
    for(i=0;i<optionList.length;i++)
    {
        nv= optionList[i].split(":");
        
        oNew = new Option(nv[0],nv[1]);
        InsertOption(oSoort_woning,oNew,i);
    }
}


function ChangeObjectType(oSelect,prefix,sWOptions)
{
    sValue = oSelect.value
    
    bDisabled = ( oSelect.value != 'WA' && oSelect.value != 'WW' && oSelect.value != '' )
			
    oSoort_woning=document.getElementById(prefix + "SelectSoortWoning");
    oBouwperiode=document.getElementById(prefix + "SelectConstructionPeriod");
    
    oRooms = document.getElementById(prefix + "SelectRooms");
    oBuildingArea  =document.getElementById(prefix + "SelectBuildingArea");
    oSurfaceArea  =document.getElementById(prefix + "SelectSurfaceArea");
    oLigging =document.getElementById(prefix + "Ligging");
			
	if(oSoort_woning != null)
	{
	    oSoort_woning.disabled = ( oSelect.value != 'WA' && oSelect.value != 'WW')
	    if(oSelect.value == 'WA')
	    {
	        
	        fnGetOptions(prefix + "SelectSoortWoning");
	    }
	    else if(oSelect.value == 'WW')
	    {
	        
	        fnGetWhoonhuisOptions(prefix + "SelectSoortWoning",sWOptions);
	    }
	}    
	
	if( oSelect.value == 'WB' || oSelect.value == 'WG' )
	{
	    if(oBouwperiode != null)
	    {
	        if(oSelect.value != 'WG')
	            oBouwperiode.disabled = true;
	        else
	            oBouwperiode.disabled = false;
	    }
	        
	    oRooms.disabled  = true;
	    oBuildingArea.disabled  = true;
	    oSurfaceArea.disabled  = true;
	}
	else
	{
	    if(oBouwperiode != null)
	        oBouwperiode.disabled = false;
	    oRooms.disabled  = false;
	    oBuildingArea.disabled  = false;
	    oSurfaceArea.disabled  = false;   
	}
	
	
    var chkBoxes = document.getElementsByTagName("input");
	
    for(i=0;i<chkBoxes.length;i++)
    {
        if(oSelect.value == 'WB' ||  oSelect.value == 'WG')
        {
            if(chkBoxes[i].getAttribute("type") == "checkbox")
                chkBoxes[i].disabled = true;
        }
        else
        {
            if(chkBoxes[i].getAttribute("type") == "checkbox")
                chkBoxes[i].disabled = false;
        }
    }
}

	
    function SetCurrentChoices(sPrefix)
	{
	    var sCurrentChoices = ''
		sCurrentChoices += CheckSelect("SoortBouw", 'Bestaande bouw', '0101',sPrefix)
		sCurrentChoices += CheckSelect("SoortBouw", 'Nieuwbouw', '0102',sPrefix)
		
		sCurrentChoices += CheckSelect("Object_Type", 'WW', '0201',sPrefix)
		sCurrentChoices += CheckSelect("Object_Type", 'WA', '0202',sPrefix)
		sCurrentChoices += CheckSelect("Object_Type", 'WB', '0203',sPrefix)
		sCurrentChoices += CheckSelect("Object_Type", 'WG', '0204',sPrefix)
		
		sCurrentChoices += CheckSelect("SoortWoning", 'recreatiewoning', '0401',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'woonboot', '0402',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'herenhuis', '0403',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'landgoed', '0404',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'eengezinswoning', '0405',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'villa', '0406',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'landhuis', '0407',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'bungalow', '0408',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'woonboerderij', '0409',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'grachtenpand', '0410',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'eenvoudige woning', '0411',sPrefix)
		

		sCurrentChoices += CheckSelect("Ligging", 'open ligging', '0601',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'in woonwijk', '0602',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'aan water', '0603',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'aan rustige weg', '0604',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'beschutte ligging', '0605',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'buiten bebouwde kom', '0606',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'aan park', '0607',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'in centrum', '0608',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'vrij uitzicht', '0609',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'aan drukke weg', '0610',sPrefix)
		sCurrentChoices += CheckSelect("Ligging", 'aan bosrand', '0611',sPrefix)

		sCurrentChoices += CheckSelect("AvailableSince", '1 dag', '1201',sPrefix)
		sCurrentChoices += CheckSelect("AvailableSince", '3 dagen', '1202',sPrefix)
		sCurrentChoices += CheckSelect("AvailableSince", '5 dagen', '1203',sPrefix)
		sCurrentChoices += CheckSelect("AvailableSince", '10 dagen', '1204',sPrefix)
		
		
		sCurrentChoices += CheckSelect("Rooms", '1+ kamers', '0702',sPrefix)
		sCurrentChoices += CheckSelect("Rooms", '2+ kamers', '0703',sPrefix)
		sCurrentChoices += CheckSelect("Rooms", '3+ kamers', '0704',sPrefix)
		sCurrentChoices += CheckSelect("Rooms", '4+ kamers', '0705',sPrefix)
		
		sCurrentChoices += CheckSelect("BuildingArea", '-50 m²', '0901',sPrefix)
		sCurrentChoices += CheckSelect("BuildingArea", '50 + m²', '0902',sPrefix)
		sCurrentChoices += CheckSelect("BuildingArea", '75 + m²', '0903',sPrefix)
		sCurrentChoices += CheckSelect("BuildingArea", '100 + m²', '0904',sPrefix)
		sCurrentChoices += CheckSelect("BuildingArea", '150 + m²', '0905',sPrefix)
		sCurrentChoices += CheckSelect("BuildingArea", '250 + m²', '0906',sPrefix)
		
		sCurrentChoices += CheckSelect("SurfaceArea", 'tot 250 m²', '1001',sPrefix)
		sCurrentChoices += CheckSelect("SurfaceArea", '250 + m²', '1002',sPrefix)
		sCurrentChoices += CheckSelect("SurfaceArea", '500 + m²', '1003',sPrefix)
		sCurrentChoices += CheckSelect("SurfaceArea", '1000 + m²', '1004',sPrefix)
		sCurrentChoices += CheckSelect("SurfaceArea", '2500 + m²', '1005',sPrefix)
		sCurrentChoices += CheckSelect("SurfaceArea", '5000+ m²', '1006',sPrefix)
		
		sCurrentChoices += CheckSelect("ConstructionPeriod", 'voor 1907', '0801',sPrefix)
		sCurrentChoices += CheckSelect("ConstructionPeriod", '1908-1930', '0802',sPrefix)
		sCurrentChoices += CheckSelect("ConstructionPeriod", '1930-1944', '0803',sPrefix)
		sCurrentChoices += CheckSelect("ConstructionPeriod", '1945-1959', '0804',sPrefix)
		sCurrentChoices += CheckSelect("ConstructionPeriod", '1960-1970', '0805',sPrefix)
		sCurrentChoices += CheckSelect("ConstructionPeriod", '1971-1981', '0806',sPrefix)
		sCurrentChoices += CheckSelect("ConstructionPeriod", '1982-1990', '0807',sPrefix)
		sCurrentChoices += CheckSelect("ConstructionPeriod", '1991-2000', '0808',sPrefix)
		sCurrentChoices += CheckSelect("ConstructionPeriod", 'na 2000', '0809',sPrefix)

		sCurrentChoices += CheckCheckBox('Tuin', '1101',sPrefix)
		sCurrentChoices += CheckCheckBox('Balkon', '1106',sPrefix)
		sCurrentChoices += CheckCheckBox('Garage', '1107',sPrefix)
		
		
		sCurrentChoices += CheckSelect("SoortWoning", 'Bovenwoning', '1301',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'Benedenwoning', '1302',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'Maisonnette', '1303',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'Galerijflat', '1304',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'Portiekflat', '1305',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'Beneden + bovenwoning', '1306',sPrefix)
		sCurrentChoices += CheckSelect("SoortWoning", 'Verzorgingsflat', '1307',sPrefix)
		
		sCurrentChoices += CheckCheckBox('CV', '1103',sPrefix)
		sCurrentChoices += CheckCheckBox('Openhaard', '1104',sPrefix)
		sCurrentChoices += CheckCheckBox('Zwembad', '1108',sPrefix)
		sCurrentChoices += CheckCheckBox('Airco', '1102',sPrefix)
		return sCurrentChoices;
	}
	
	function CheckSelect(sName, sValue, sCurrentChoice,sPrefix)
	{
		sCtrlName = sPrefix + "Select" + sName;
		oSelect=document.getElementById(sCtrlName);
		if(oSelect == null)
		    return '';
		else
		    return ( oSelect[oSelect.selectedIndex].value == sValue ? sCurrentChoice : '' )
	}
    
    function CheckCheckBox(sName, sCurrentChoice,sPrefix)
	{
	    sCtrlName = sPrefix + "Checkbox" + sName;
		if(document.getElementById(sCtrlName) == null)
		    return '';
		return ( document.getElementById(sCtrlName).checked == true ? sCurrentChoice : '' )
    }




    function GetSearchUrl(eventSelect,sPrefix,pageKey,searchType,backPageKey)
    {
        var minPrice;
        var maxPrice;
        var sfRange;
        var sfInput;
        var sfRegion;

        minPrice = sPrefix + "Select" + "MinPrice";
        maxPrice = sPrefix + "Select" + "MaxPrice";
        sfRange = sPrefix + "Select" + "Range";
        sfInput = sPrefix + "Input" + "PlaceZip";
        sfRegion = sPrefix + "Select" + "province";
        
        var oMinControl  = document.getElementById(minPrice);
        var oMaxControl = document.getElementById(maxPrice);
        var oRangeControl = document.getElementById(sfRange);
        var oInputControl = document.getElementById(sfInput);
        
        var oProvience = document.getElementById(sfRegion);
        var sProv;
        var sProvText;
        if(oProvience==null)
        {
            sProv = '';
            sProvText = '';
        }
        else
        {
            sProv= oProvience.value;
            if(oProvience.selectedIndex==0)
				sProvText = '';
			else
			    sProvText = oProvience.options[oProvience.selectedIndex].text;
        }
            
        var sExtSearch = SetCurrentChoices(sPrefix);
        
        var iMinValue = parseInt(oMinControl.value, 0);
        var iMaxValue = parseInt(oMaxControl.value, 0);
        if(iMaxValue == 0) iMaxValue = 1000000000;
        var iRangeValue = parseInt(oRangeControl.value, 0);
        var sInputValue = UrlEncode(oInputControl.value);
                
        var sPostalCode = sInputValue;
        if(sInputValue.length > 4)
        {
            sPostalCode = sInputValue.substr(0, 4);
        }       
        
        if(IsNumeric(sPostalCode) == true )
         {
            document.location.href = "/default.aspx?pageKey="+ pageKey +"&minPrice=" + iMinValue + "&maxPrice=" + iMaxValue + "&placeOrZip=" + sInputValue.toUpperCase() +"&range=" + iRangeValue + "&type=" + searchType + "&region=" + sProv + "&currentChoices=" + sExtSearch + "&SearchInputPage=" + backPageKey + "&ProvinceText=" + sProvText;
         }
         else
         {
            document.location.href = "/default.aspx?pageKey="+ pageKey +"&minPrice=" + iMinValue + "&maxPrice=" + iMaxValue + "&city=" + sInputValue.toUpperCase() +"&range=" + iRangeValue + "&type=" + searchType + "&region=" + sProv + "&currentChoices=" + sExtSearch + "&SearchInputPage=" + backPageKey + "&ProvinceText=" + sProvText;
         }
    }
    	
    function UrlEncode(text) 
    {		
		    text=ReplaceAll(text, "?", "%3F");
		    text=ReplaceAll(text, "=", "%3D");
		    text=ReplaceAll(text, "&", "%26");
		    text=ReplaceAll(text, " ", "+");
		    text=ReplaceAll(text, ",", "%2c");	
		    text=ReplaceAll(text, "'", "%27");	                						
		    return text;
     }
       
    function ReplaceAll(varb, replaceThis, replaceBy)
    {	
		    newvarbarray=varb.split(replaceThis);
		    newvarb=newvarbarray.join(replaceBy);	
		    return newvarb;
    }    	
    function checkPrices(eventSelect,sPrefix)
    {
        var minPrice;
        var maxPrice;
        minPrice = sPrefix + "MinPrice";
        maxPrice = sPrefix + "MaxPrice";
        var otherSelect = (eventSelect.name == minPrice) ? eventSelect.form.elements[maxPrice] : eventSelect.form.elements[minPrice];
        var thisValue = parseInt(eventSelect.options[eventSelect.selectedIndex].value, 10);
        var otherValue = parseInt(otherSelect.options[otherSelect.selectedIndex].value, 10);
        if (eventSelect.name == minPrice)
        {
	      if (thisValue >= otherValue)
	      {
		        for (var i = 0; i < otherSelect.options.length; i++)
    		    {
		    	    if (otherSelect.options[i].value > thisValue)
    		      {
        		        otherSelect.selectedIndex = i;
    				    break;
			      }
            }
	      }
        } else
        {
	      if (thisValue <= otherValue)
	      {
		        for (var i = (otherSelect.options.length - 1); i >= 0 ; i--)
		        {
    			      if (parseInt(otherSelect.options[i].value, 10) < thisValue)
		    	      {
				        otherSelect.selectedIndex = i;
    		            break;
		            }
    		    }
	      }
        }
    }


	function Check(eventSelect,event,sPrefix,searchType,nvmNumbers,searchControlId,filter,pageKey,ControlCode)
	{
        var sControl = sPrefix + "PlaceZip";
        var oControl = (eventSelect.name == sControl) ? eventSelect.form.elements[sControl] : null;	
		if ( !_browserOk ) return
		if (oControl == null) return
		if ( _enabled == false || _checking != false || oControl.value == _previousInput ) return
		if ( event ) if ( event.keyCode == 13 ) 
		{
             eval(document.getElementById(searchControlId).href);  
		     return false;
		}
        _input = oControl;		
	
		if ( oControl.value.length == 0 ) 
		{
    		Hide();
		    return true;    		
		}
		
		_typedValue = oControl.value
		Letter = oControl.value.substring(0,1)
		_previousInput = oControl.value
		
		var nLeft = GetElementLeft(oControl);
		var nTop = GetElementTop(oControl) + GetElementHeight(oControl);
		var nWidth = GetElementWidth(oControl) - 2;
		
	    document.getElementById('Lijst').style.left = nLeft+'px';
	    document.getElementById('Lijst').style.top = nTop+'px';
        document.getElementById('Lijst').style.width = nWidth+'px';

	    document.getElementById('iFrame').style.left = nLeft+'px';
	    document.getElementById('iFrame').style.top = nTop+'px';
        document.getElementById('iFrame').style.width = nWidth+'px';

	    document.getElementById('FrameContainer').style.left = nLeft+'px';
	    document.getElementById('FrameContainer').style.top = nTop+'px';
        document.getElementById('FrameContainer').style.width = nWidth+'px';
		_checking = true
		_xmlHTTP = false
		if ( window.ActiveXObject ) _xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP")
		if ( window.XMLHttpRequest ) _xmlHTTP = new XMLHttpRequest()

		if ( !_xmlHTTP )
		{
			_placesArray = ''
		}
		else
		{
			_xmlHTTP.onreadystatechange = function()
			{
				if (_xmlHTTP.readyState == 4)
				{
					_placesArray = _xmlHTTP.responseText
					sHeader = '<?xml?><plaatsen>'
					sFooter = '</plaatsen>'
					_placesArray = _placesArray.substring(sHeader.length, _placesArray.length - sFooter.length)
					_placesArray = _placesArray.split(',')
					if ( _placesArray != _placesArrayPrevious )
					{
						_placesArrayPrevious = _placesArray
						_placesOriginalArray = CopyArray(_placesArray)
						SetList()
						FilterPlaatsen(oControl.value)
						document.body.onkeydown     = KeyDown;
						document.body.onkeyup       = KeyUp;
						document.body.onkeypress    = CheckKeypress;
						document.body.onclick       = DocumentClick;
					}
				}
			}
			
            var searchAndNvm = "&type=" + searchType + "&nvmNumbers=" + nvmNumbers + "&filter=" + filter;
            if (_lasturl != _search + Letter + searchAndNvm )
            {
                _lasturl = _search + Letter + searchAndNvm;
			_xmlHTTP.open("GET", _search + Letter + searchAndNvm , true)
			_xmlHTTP.send(null)
		}
		else
		{
				FilterPlaatsen(oControl.value)
	}
	
			}
		}

	function CopyArray(aArray)
	{
		var newArray = new Array()
		for(i=0;i<aArray.length;i++)
		{
			newArray[i] = aArray[i]
		}
		return newArray
	}

	function SetList()
	{
		document.getElementById('Lijst').innerHTML = ''
		itemCount = _placesArray.length > 5 ? 5 : _placesArray.length
		n = 2 + 16 * itemCount
		if ( n > 120 ) n = 120
		_height = 73 - n
		if ( navigator.userAgent.indexOf("Firefox")>0 ) _height += 16
		
		_height = _height < 0 ? 0 : _height
		if ( _placesArray[0] != '' )
		{
			_hover = -1
			s = '<table cellpadding=0 cellspacing=0 style="width:' + '100%' + ';">'
			for(i=0;i<itemCount;i++)
			{
				placesList = _placesArray[i]
				sAantal = placesList.substring(placesList.indexOf('|')+1, placesList.length)
				placesList = placesList.substring(0, placesList.indexOf('|'))
				placeSlash = placesList.replace('\'', '\\\'')
				_places[i] = placesList
				s += '<tr class="gewoon" id="Link' + i + '" onmouseover="MouseOverLink(' + i + ')" onclick="Click(\'' + placeSlash + '\')">' 
				s += '<td class="plaats" title="' + placesList + ', ' + sAantal + ' woningen"><span class="aantal" style="float:right;">' + sAantal + '</span>' + placesList + '</td>'
				s += '</tr>'
			}
			s += '</table>'
			document.getElementById('Lijst').innerHTML += s
			
			_show = true
			document.getElementById('Lijst').style.display = 'block'
			document.getElementById('Lijst').style.position = 'absolute'			
			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 ( itemCount == 0 ) Hide()
		_checking = false
		MouseOverLink(0)
	}		
	
	function MouseOverLink(i)
	{   
		if ( _hover > -1 )
		{
			if ( document.getElementById('Link' + _hover) ) document.getElementById('Link' + _hover).className = 'gewoon'			
		}
		_hover = i
		if ( i != -1 )
		{
			if ( document.getElementById('Link' + i) ) document.getElementById('Link' + i).className = 'LinkHover'	
			
		}							
	}
	
	function Hide()
	{
		document.body.onkeydown = null;
		document.body.onkeyup = null;	
		document.body.onkeypress = null;
		document.body.onclick = null;	
        _previousInput	= '';
		_show = false
		document.getElementById('Lijst').style.display = 'none'
		if ( IE && !IE50 ) document.getElementById('FrameContainer').style.display = 'none'
	}

	function FilterPlaatsen(sString)
	{
		sString = sString.toLowerCase()
		if ( _placesOriginalArray ) _placesArray = CopyArray(_placesOriginalArray)
		for ( i=_placesArray.length-1; i>-1; i-- )
		{
			if ( _placesArray[i].substring(0, sString.length).toLowerCase() != sString ) Sloop(_placesArray, i)
		}
		SetList()
	}
	
	function Sloop(_placesArray, i)
	{
		for(n=i; n<_placesArray.length-1; n++)
		{
			_placesArray[n] = _placesArray[n+1]
		}
		_placesArray.length --
	}	
	
    function GetElementLeft(m_elem)
    {
	    var x = 0;
	    var elem;		
	    if(typeof(m_elem) == "object")
		    elem = m_elem;
	    else
		    elem = document.getElementById(m_elem);
    		
	    while (elem != null)
	    {
		    x += elem.offsetLeft;
		    elem = elem.offsetParent;
	    }
	    return parseInt(x);
    }
	
    function GetElementTop(m_elem)
    {
	    var y = 0;
	    var elem;
	    if(typeof(m_elem) == "object")
	    {
		    elem = m_elem;
	    }
	    else
	    {
		    elem = document.getElementById(m_elem);
	    }
	    while (elem != null)
	    {
		    y+= elem.offsetTop;
		    elem = elem.offsetParent;
	    }
	    return parseInt(y);
    }

    function GetElementWidth(m_elem)
    {
	    var elem;
	    if(typeof(m_elem) == "object")
	    {
		    elem = m_elem;
	    }
	    else
	    {
		    elem = document.getElementById(m_elem);
	    }
	    return parseInt(elem.offsetWidth);
    }

    function GetElementHeight(m_elem)
    {
	    var elem;
	    if(typeof(m_elem) == "object")
	    {
		    elem = m_elem;
	    }
	    else
	    {
		    elem = document.getElementById(m_elem);
	    }
	    return parseInt(elem.offsetHeight);
    }	

	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)
		_global=i;
		return false;
	}

	function DocumentClick()
	{
		if ( !_browserOk ) return
		if ( _isHover == false )
		{
			Hide()
		}
	}
	
	function CheckKeypress(e)
	{  	
        var key = window.event ? window.event.keyCode : e.which;

	    if ( !_browserOk ) return
	    if ( _show == true )
	    {
		    if ( key == 40 ) return false
		    if ( key == 38 ) return false
	    }
	    return true
	}
	
	function KeyDown(e)
	{
	    var key = window.event ? window.event.keyCode : e.which;

		if ( !_enabled ) return
		if ( key == 13 )
		{
			_cancelEnterSubmit = _show
		}
		else
		{
			_cancelEnterSubmit = false
		}
		if ( key == 34 ) GoDown(4)
		if ( key == 33 ) GoUp(4)
		if ( key == 40 ) GoDown(1)
		if ( key == 38 ) GoUp(1)
	}
	
	function KeyUp(e)
	{
	  	var key = window.event ? window.event.keyCode : e.which;

		if ( !_enabled ) return
		if ( key == 13 ) Enter()
		if ( key == 27 ) Enter()
		if ( key == 9 ) Enter()
	}
	
	function Enter(bEnter)
	{
	   	if ( !_browserOk ) return
		if ( _show == true )
		{
            CheckAutocompleteSubmit();
			Hide()
			_input.focus()
		}
	}
	
	function GoDown(n)
	{
		if ( !_browserOk ) return
		if ( _focused == false ) return
		if ( _show == false ) Check()
		n = _hover + n
		if ( !window.itemCount ) return
		if ( n > itemCount-1 )
		{
			n = 0
		}
		KeyDownLink(n)
	}

	function GoUp(n)
	{
		if ( !_browserOk ) return
		if ( _focused == false ) return
		if ( _show == false ) Check()
		n = _hover - n
		if ( n < 0 )
		{
			n = itemCount-1
		}
		KeyDownLink(n)
	}
	
	function CheckAutocompleteSubmit()
	{
		if (( _focused == true && _show == true ) || _cancelEnterSubmit == true )
		{
			Hide()
			_input.value = _places[_hover]
			_cancelEnterSubmit = false
			return false
		}
		
		return CheckInput()
     }
	
	function Click(s)
	{
		_input.value = s
		_show = false
		document.getElementById('Lijst').style.display = 'none'
		if ( IE && !IE50 ) document.getElementById('FrameContainer').style.display = 'none'
		_input.focus()
	}
	
	function IsNumeric(sText)
    {
       var ValidChars = "0123456789";
       var IsNumber = true;
       var Char;
       for (i = 0; i < sText.length && IsNumber == true; i++) 
       { 
         Char = sText.charAt(i); 
         if (ValidChars.indexOf(Char) == -1) 
         {
             IsNumber = false;
         }
       }
    return IsNumber;
   }