// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		getMap()												+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function getMap()
{
	if (navigator.appName == "Netscape") 
		return parent.Kaart.document.map;
	else 
		return parent.Kaart.map;
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		LayerExist()
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function LayerExist(LayerName)
{
 	var AllLayers = getMap().getMapLayersEx();
	var LayerNum = AllLayers.size();  

	var i = 0;
	var gevonden = false;
	do 	
	{
		var CurLayerName = AllLayers.item(i).getName();
		if (CurLayerName == LayerName)
			gevonden = true;
		i+=1;
	}
	while ((gevonden == false)&&(i < LayerNum));
	return gevonden;
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		TurnOffLayers()	
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function TurnOffLayers()
{
	if (LayerExist("PFI"))
		getMap().getMapLayer("PFI").setVisibility(false);
		getMap().getMapLayer("StreetMarker").setVisibility(false);
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomScale()	
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomScale (y, x, scale)
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("zoomScale "+y+" "+x+" "+scale);
	else
	{
		if (getMap().isBusy() == false)
		{
			TurnOffLayers();
			if (y == 0 || x == 0) alert ("Coordinates not available");
			else 
			{
				getMap().zoomScale(y,x,scale);
			}
		}
		else alert ("Please wait... \nViewer is loading")
	}
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomScaleAndMark()	
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomScaleAndMark (y, x, scale, marker, ym, xm)
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("zoomScaleAndMark "+y+" "+x+" "+scale+" "+ym+" "+xm+" "+marker);
	else
	{
		if (getMap().isBusy() == false)
		{
			TurnOffLayers();
			if (y == 0 || x == 0) 
				alert ("Coordinates not available");
			else 
			{
				if (marker != "")
				{
					var markerlayer = getMap().getMapLayer(marker);
					var SQLwhere = "Y = " + ym + " and X = " + xm;
					markerlayer.setSQLWhere(SQLwhere);
					markerlayer.setVisibility(true);
				}
				getMap().zoomScale(y,x,scale);
			}
		}
		else alert ("Please wait... \nViewer is loading")
	}
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomScalePostcode()	
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomScalePostcode (y, x, value)
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("zoomScalePostcode "+y+" "+x+" "+value);
	else
	{
		if (getMap().isBusy() == false)
		{
			TurnOffLayers();
			if (y == 0 || x == 0) alert ("Coordinates not available");
			else 
				{
					getMap().getMapLayer("PFI").setVisibility(true);
					getMap().zoomScale(y,x,value);
				}
		}
		else alert ("Please wait... \nViewer is loading")
	}
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomGotoArea(source,location)					+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomGotoArea(source,location)
{
	if (source == "AA8")
		getMap().zoomGotoLocation('municipality',location,5000);
	if (source == "AA9")
		getMap().zoomGotoLocation('submunicipality',location,5000);
	if (source == "SET")
		getMap().zoomGotoLocation('settlement',location,5000);
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomGotoPostCode(location)					+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomGotoPostCode(location)
{
	getMap().getMapLayer("PFI_g20").setSQLWhere("FEATURE_NAME='" + location + "'");
	getMap().getMapLayer("PFI_g20").setVisibility(true);
	getMap().zoomGotoLocation("postalcode",location,1);
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomMinMax(MinX, MinY, MaxX, MaxY)
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomMinMax(MinX, MinY, MaxX, MaxY)
{
	var x = (MaxX+MinX)/2;	
	var y = (MaxY+MinY)/2;

	var breedte = Math.abs(MaxX-MinX);	
	var hoogte = Math.abs(MaxY-MinY);
	breedte = breedte + (breedte/10);
	hoogte = hoogte + (hoogte/10);	
	if (breedte < 500) breedte = 500;
	if (hoogte < 400) hoogte = 400;	
	var factor=breedte/hoogte;
		
	var hoogtemap=getMap().getHeight("M");
	var breedtemap=getMap().getWidth("M");
	var factormap=breedtemap/hoogtemap;

	if (factormap>factor) //map is minder hoog 
		getMap().zoomWidth(y,x,breedte*(factormap/factor),"M");
	else
		getMap().zoomWidth(y,x,breedte,"M");
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomGotoStreet(ROA_IDs)					+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomGotoStreet(ROA_IDs)
{
	var ids = "'" + ROA_IDs.replace(/,/g,"','") + "'";
	getMap().getMapLayer("ROA").setSQLWhere("id in (" + ids + ")");
	getMap().getMapLayer("ROA").setVisibility(true);
	getMap().zoomGotoLocation("street",ROA_IDs,1);
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomMinMaxStreet(ROA_IDs)					+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomMinMaxStreet(ROA_IDs, MinX, MinY, MaxX, MaxY)
{
	var ids = "'" + ROA_IDs.replace(/,/g,"','") + "'";
	getMap().getMapLayer("ROA").setSQLWhere("feature_id in (" + ids + ")");
	getMap().getMapLayer("ROA").setVisibility(true);
	zoomMinMax(MinX, MinY, MaxX, MaxY);
}
