// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		Max()						+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function Max(taal)
{
	if (taal == 'NL') window.open("../nl/liggingsplan.asp","max","toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=800,height=600,top=0,left=0,maximize=yes")
	if (taal == 'FR') window.open("../fr/liggingsplan.asp","max","toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=800,height=600,top=0,left=0")
	if (taal == 'EN') window.open("../en/liggingsplan.asp","max","toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,menubar=no,width=800,height=600,top=0,left=0")
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Basic Mapguide functions
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function getMap()
{ 
	//alert(navigator.appName);
	if (navigator.appName == "Netscape") 
	{
		//alert(parent.Kaart.document.map);
		return parent.Kaart.document.map;
	}
	else 
		return parent.Kaart.map;
}

function mg_selectMode()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("MGmethod selectMode" );
	else
	{
		var version = getMap().getVersion();
		if (version >= "5.0.0.0")
			getMap().selectMode(); 
	}
}

function mg_zoomInMode()
{
	//alert('mg_zoomInMode');
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("MGmethod zoomInMode" );
	else
	{
		//alert('switch to zoom in mode');
		getMap().zoomInMode(); 
	}
}

function mg_zoomOutMode()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("MGmethod zoomOutMode" );
	else
		getMap().zoomOutMode(); 
}

function mg_panMode()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("MGmethod panMode" );
	else
		getMap().panMode(); 
}

function mg_zoomPrevious()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("MGmethod zoomPrevious" );
	else
		getMap().zoomPrevious(); 
}

function mg_zoomOut()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("MGmethod zoomOut" );
	else
		getMap().zoomOut(); 
}

function mg_copyMap()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("MGmethod copyMap" );
	else
		getMap().copyMap(); 
}

function mg_preferencesDlg()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("MGmethod preferencesDlg" );
	else
		getMap().preferencesDlg(); 
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		printMap()	
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function printMap()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("PrintMap" );
	else
	{
		if (getMap().isBusy() == false)
		{
			var version = getMap().getVersion();
			if (version >= "5.0.0.0")
			{
				getMap().pageSetupDlg();		
				getMap().printDlg();
			}
			else
			{
				getMap().pageSetupDlg();
				getMap().printDlg();
			}
		}
		else alert("The Viewer is busy ... \nplease try again in a few seconds");
	}
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomGotoScale()		
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomGotoScale (box, category)
{
	parent.digitizeFunction = 2;
	parent.scalekey = box.options[box.selectedIndex].value;
	if (parent.scalekey == "none") 
		alert ("You have to select a scale \nin order to zoom to it");
	else 
	{
		if (parent.Kaart.MacIE) 
			parent.Kaart.SendToJavaViewer("digitizePoint " + parent.digitizeFunction + " " + parent.scalekey);
		else
			var point = getMap().digitizePoint();
	}
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomWidthHeight(km,x,y)
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomWidthHeight(km,x,y)
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("zoomWidthHeight "+ km +" "+ x +" "+ y);
	else
	{
		var hoogte=getMap().getHeight("KM");
		var breedte=getMap().getWidth("KM");
		var factor=breedte/hoogte;
		if (hoogte>breedte)
			getMap().zoomWidth(y,x,km,"KM");
		else
			getMap().zoomWidth(y,x,km*factor,"KM");	
	}
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomMinMax(MinY, MaxY, MinX, MaxX)
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomMinMax(MinY, MaxY, MinX, MaxX)
{
	var x = (MaxX+MinX)/2;	
	var y = (MaxY+MinY)/2;

	var breedte = Math.abs(MaxX-MinX) / 1000;	
	var hoogte = Math.abs(MaxY-MinY) / 1000;
	var factor=breedte/hoogte;
		
	var hoogtemap=getMap().getHeight("KM");
	var breedtemap=getMap().getWidth("KM");
	var factormap=breedtemap/hoogtemap;

	if (factormap>factor) //map is minder hoog 
		getMap().zoomWidth(y,x,breedte*(factormap/factor),"KM");
	else
		getMap().zoomWidth(y,x,breedte,"KM");	
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomGoToValue()										+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomGotoValue (y, x, scale, CountryCode)
{
	if (x == 0 || y == 0) 
		alert ("Coordinates not available");
	else
	{
		if (parent.Kaart.MacIE) {
			parent.Kaart.SendToJavaViewer("zoomScale " + y + " " + x + " " + scale); }
		else
		{
			if (getMap().isBusy() == false)
			{
				SetCountry(CountryCode);
				SetCountrySelect(CountryCode);
				if (getMap().isBusy() == false)
					getMap().zoomScale(y,x,scale); 
				else
					parent.MapToDo = "getMap().zoomScale("+y+","+x+","+scale+");";
			}
			else 
				alert ("Please wait... \nViewer is loading");
		}
	}
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		getInfoVest()										
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function getInfoVest (key)
{
	parent.Info.document.location=("../Common/info.asp?key=" + key + "&name=&layer=vestigingen");
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		zoomGoTo()										
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function zoomGoTo()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("MGmethod zoomGotoDlg" );
	else
	{
		if (getMap().isBusy() == false)
		{
			getMap().zoomGotoDlg();
		}
		else alert ("Please wait... \nViewer is loading")
	}
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		GoToFramePage()		
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function GoToFramePage (Page)
{
	parent.Info.document.location=Page;
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		ShowOffices()		
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function ShowOffices(Page)
{
	if (toolbarform.Country.value == "P")
		alert ("This function is not applicfable for the PICC Demo data");
	else
		parent.Info.document.location=Page;
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		GotoMainPage()	
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function GoToMainPage(Page)
{
	parent.document.location=Page;
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		GetDistance()	
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function GetDistance ()
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("viewDistance");
	else
		var reply = getMap().viewDistance ("KM");
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		Reset()	
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function Reset()
{
	if (parent.Kaart.MacIE) 
	{
		parent.Kaart.SendToJavaViewer("Reset");
		parent.Info.document.location="gotovb.htm";
	}
	else
	{
		if (getMap().isBusy() == false)
		{
			var mapURL = getMap().getUrl();
			getMap().setUrl(mapURL);
			if (mapURL.indexOf("PICC") > 0) 
				parent.Info.document.location="PICC_remarks.htm";
			else
				parent.Info.document.location="gotovb.htm";
		}
		else alert("The Viewer is busy ... \nplease try again in a few seconds");
	}
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		SetLanguage(LangSelect)										+
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function SetLanguage(LangSelect)
{
	var mapURL = getMap().getUrl();
	if (mapURL.indexOf("PICC") > 0)
		return null;
	if (mapURL.indexOf("Seachart") > 0)
		return null;

	var	sdfNlFr = "AA0,AA1,AA2,AA7,AA8,AA9,AFI,FWE,POI,RAI,RFI,ROA10,ROA2030,ROA4051,ROA5280,SET,WFI,";

	var sdfChanged = false;
	var Language = LangSelect.options[LangSelect.selectedIndex].value;
	var TaalSdf = "";	
	if (Language == "Dutch")
		TaalSdf = "_Nl";
	else if (Language == "French")
		TaalSdf = "_Fr"	;
	
 	var AllLayers = getMap().getMapLayersEx();
	var LayerNum = AllLayers.size();  
	for (i=0; i < LayerNum; i++)
	{
		var CurLayer = AllLayers.item(i);
		var LayerType = CurLayer.getType();
	
		if (LayerType != "Drawing" && LayerType != "DrawingObject")
		{ 
			var LayerSetup = CurLayer.getLayerSetup();
			if (LayerSetup == null)
				alert("Can not get the map layer setup for "+CurLayer.getName()+", change the security for this layer to: allow access to map layer setup from API. Call GIS support.");
			else
			{
				var SourceType = LayerSetup.getSourceType();
				if (SourceType == "SpatialDataFile")
				{
					var GenSdf = "";
					var sdfname = "";
					var sdfOrig = LayerSetup.getDataFile().toLowerCase();
					var sdfOrig = sdfOrig.replace(/\"/g,"");
					var sdf = sdfOrig.replace(/_nl|_fr/i,"");
					var posg = sdf.indexOf("_g");
					var posp = sdf.indexOf(".");
					if (posp < 0 ) posp = sdf.length;

					if (posg >= 0)
					{
						sdfname = sdf.substring(0, posg).toUpperCase();
						sdfnameExt = sdf.substring(posp, sdf.length).toUpperCase();
						GenSdf = sdf.substring(posg, posp);
					}
					else
						sdfname = sdf.substring(0, posp).toUpperCase();
	
					if (sdfNlFr.indexOf(sdfname+",") >= 0)
					{
						sdfNew = sdfname + TaalSdf + GenSdf + sdfnameExt;
						if (sdfOrig != sdfNew.toLowerCase())
						{
//alert(sdfOrig + " --> " + sdfNew)						;
							var reply = LayerSetup.setDataFile(sdfNew);
							sdfChanged = true;
						}
					}
				}
			}
		}
	} 
	if (sdfChanged == true)
		getMap().refresh();
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		SetCountry(CountrySelect)
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function SetCountry(CountrySelect)
{
	if (parent.Kaart.MacIE) 
		parent.Kaart.SendToJavaViewer("SetCountry "+CountrySelect);
	else
	{
		if (getMap().isBusy() == false)
		{
			// The pages to show at the right are dependent on 
			// - the country: no goto for PICC
			// - the language of the user: examples in dutch or french
			var SearchFrameURL= "";
			var InfoFrameURL= "";
			var BaseURL = parent.document.URL;
			var PosLastSlash = BaseURL.lastIndexOf("/")+1;

			var mapURL = getMap().getUrl();
			var mapURL = mapURL.toLowerCase();
			var pos1 = mapURL.indexOf("/liggingsplan")+1;
			var pos2 = mapURL.indexOf("?",pos1);
			var CurrentMap = mapURL.substring(pos1,pos2);

			switch (CountrySelect)
			{
				case "S":
					SearchFrameURL= BaseURL.substr(0,PosLastSlash) + "seachart.htm";
					InfoFrameURL= BaseURL.substr(0,PosLastSlash) + "seachart_remarks.htm";
					if (CurrentMap != "Seachart.mwf")
						mapURL = "../mwf/Seachart.mwf"
					break;
				case "P":
					SearchFrameURL= BaseURL.substr(0,PosLastSlash) + "PICC.htm";
					InfoFrameURL= BaseURL.substr(0,PosLastSlash) + "PICC_remarks.htm";
					if (CurrentMap != "PICC.mwf")
						mapURL = "../mwf/PICC.mwf"
					break;
				case "N":
					SearchFrameURL= BaseURL.substr(0,PosLastSlash) + "goto.htm";
					InfoFrameURL= BaseURL.substr(0,PosLastSlash) + "../common/blanc.htm"; // gotovbNl ?!
					if (CurrentMap != "liggingsplannl.mwf")
						mapURL = "../mwf/liggingsplannl.mwf"
					break;
				case "L":
					SearchFrameURL= BaseURL.substr(0,PosLastSlash) + "goto.htm";
					InfoFrameURL= BaseURL.substr(0,PosLastSlash) + "../common/blanc.htm";
					if (CurrentMap != "liggingsplanlux.mwf")
						mapURL = "../mwf/liggingsplanlux.mwf"
					break;
				case "B":
					SearchFrameURL= BaseURL.substr(0,PosLastSlash) + "goto.htm";
					InfoFrameURL= BaseURL.substr(0,PosLastSlash) + "../common/lijst.asp";
					if (CurrentMap != "liggingsplan.mwf")
						mapURL = "../mwf/liggingsplan.mwf"
					break;				
				default : 
					SearchFrameURL= BaseURL.substr(0,PosLastSlash) + "goto.htm";
					InfoFrameURL= BaseURL.substr(0,PosLastSlash) + "../common/blanc.htm";
					if (CurrentMap != "liggingsplan.mwf")
						mapURL = "../mwf/liggingsplan.mwf"
			}
			getMap().setUrl(mapURL + "?TOOLBAR=OFF&LAYERSVIEWWIDTH=1&ext=.mwf");
			parent.Search.document.location = SearchFrameURL;
			parent.Info.document.location = InfoFrameURL;
	
		}
		else alert("The Viewer is busy ... \nplease try again in a few seconds");
	}
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		SetCountrySelect(CountrySelect)
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function SetCountrySelect(CountrySelect)
{
	if (navigator.appName == "Netscape") 
		var Country = parent.ToolBar.document.toolbarform.Country;
	else 	
		var Country = parent.ToolBar.toolbarform.Country;
		
	var i = 0;
	var gevonden = false;
	do 	
	{
		if (Country.options[i].value == CountrySelect)
		{
			gevonden = true;
			var index = i;
		}
		i+=1;
	}
	while ((gevonden == false)&&(i < Country.options.length));
	
	if ((gevonden)&&(Country.selectedIndex != index))
		Country.selectedIndex = index;
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Function		SetLegende()
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
function SetLegend(checked)
{
	if ((navigator.appVersion.indexOf("Win") != -1)&&(navigator.appName.indexOf("Microsoft Internet Explorer") != -1))
	{
		if (checked)
			getMap().LayersViewWidth = 150;
		else
			getMap().LayersViewWidth = 1;
	}
	else
	{
		alert("Not supported for this browser, to view the legend drag the left border of the map.");
	}
}