
function GeoDataClass()
{
    this.Initialize = function()
    {
        this.Previous = ''
        this.Wijk = ''
        this.Plaats = ''
        this.Regio = ''
        this.Provincie = ''
        this.isDelayed = false
        this.Delay = 2000
    }
    
    this.Set = function(x, y, z)
    {
        this.x = x
        this.y = y
        this.z = z

        if (this.isDelayed == false && this.xPrev != this.x || this.yPrev != this.y)
        {
            this.xPrev = this.x
            this.yPrev = this.y
            this.zPrev = this.z
            this.isDelayed = true
            this.CallXmlHttp(this.x, this.y)
            setTimeout('GeoData.StopDelay()', this.Delay)
        }
        else if (this.zPrev != this.z)
        {
            this.SetText()
        }
    }
    
    this.SetGeo = function(sHTML)
    {
        aValues = sHTML.split('|')
        this.Wijk = aValues[0]
        this.Plaats = aValues[1]
        this.Regio = aValues[2]
        this.Provincie = aValues[3]
        this.SetText()
    }
    
    this.GetZoomLevel = function()
    {
        var gebied = 'land'
        switch(GoogleMap.getZoom())
        {
            case 6: case 7: gebied = 'land'; break;
            case 8: case 9: gebied = 'provincie'; break;
            case 10: case 11: gebied = 'regio'; break;
            case 12: case 13: gebied = 'plaats'; break;
            case 14: case 15: gebied = 'wijk'; break;
            case 16: case 17: case 18: case 19: gebied = 'straat'; break;
        }
        return gebied
    }
    
    this.SetText = function()
    {
        document.getElementById(Settings.GeoProvincieId).value = this.Provincie
        document.getElementById(Settings.GeoRegioId).value = this.Regio
        document.getElementById(Settings.GeoPlaatsId).value = this.Plaats
        document.getElementById(Settings.GeoWijkId).value = this.Wijk
        
        switch(this.GetZoomLevel())
        {
            case 'land':
                document.getElementById(Settings.GeoProvincieId).value = ''
                document.getElementById(Settings.GeoRegioId).value = ''
                document.getElementById(Settings.GeoPlaatsId).value = ''
                document.getElementById(Settings.GeoWijkId).value = ''
                break;
            case 'provincie':
                document.getElementById(Settings.GeoRegioId).value = ''
                document.getElementById(Settings.GeoPlaatsId).value = ''
                document.getElementById(Settings.GeoWijkId).value = ''
                break;
            case 'regio': 
                document.getElementById(Settings.GeoPlaatsId).value = ''
                document.getElementById(Settings.GeoWijkId).value = ''
                break;
            case 'plaats': 
                document.getElementById(Settings.GeoWijkId).value = ''
                break;
            case 'wijk': 
                break;
        }
        if (document.getElementById(Settings.KaartAlsLocatieId).checked == true && this.Previous != this.ConcatLocation())
        {
            document.getElementById(Settings.GeoSubmitterId).click()
            Resultaatlijst.Clear()
            document.getElementById('Loading').style.display = 'block'
        }
        this.Previous = this.ConcatLocation()
    }
    
    this.ConcatLocation = function()
    {
        var s = document.getElementById(Settings.GeoProvincieId).value + '|'
        s += document.getElementById(Settings.GeoRegioId).value + '|'
        s += document.getElementById(Settings.GeoPlaatsId).value + '|'
        s += document.getElementById(Settings.GeoWijkId).value + '|'
        s += this.GetZoomLevel()
        return s
    }
    
    this.StopDelay = function()
    {
        this.isDelayed = false
        if (this.xPrev != this.x || this.yPrev != this.y)
        {
            this.Set(this.x, this.y, this.z)
        }
        else if (this.zPrev != this.z)
        {
            this.SetText()
        }
    }

	this.CallXmlHttp = function(x, y)
	{
		var XMLHTTP = false
		if ( window.ActiveXObject ) XMLHTTP = new ActiveXObject("Microsoft.XMLHTTP")
		if ( window.XMLHttpRequest ) XMLHTTP = new XMLHttpRequest()

		XMLHTTP.onreadystatechange = function()
		{
			if (XMLHTTP.readyState == 4)
			{
				var sText = XMLHTTP.responseText
				XMLHTTP = null
				GeoData.SetGeo(sText)
			}
		}
		
        x = 121858 + (x - 4.9) / (5.69 - 4.9) * (176157 - 121858);
        y = 317868 + (y - 50.85) / (52.37 - 50.85) * (487326 - 317868);
        
        x = Math.round(x)
        y = Math.round(y)

		URL = Settings.GeoCoordinaatUrl + '?x=' + x + '&y=' + y
		
		XMLHTTP.open("GET", URL, true)
		XMLHTTP.send(null)
		
	}    
}