//=================================================================================================
//	You can delete these three functions if not needed.
//-------------------------------------------------------------------------------------------------
function customBodyLoad( sender )
{
	repositionDiv("submenu", -415, 955, 63);
}
//=================================================================================================
function customBodyResize( sender, size )
{
	repositionDiv("submenu", -415, 955, 63);
}
//=================================================================================================
function customBodyScroll( sender )
{
}
//=================================================================================================
function showSubMenu(target)
{
	submenu = document.getElementById(target);
	
	for (var i = 0; i < mainCats.length; i++)
	{			
		document.getElementById("submenu" + mainCats[i]).style.display = "none";
	}
	
	if (submenu)
		submenu.style.display = "block";
}
//=================================================================================================
function showEvenementen()
{
	document.getElementById("aEvenementen").className  = "current";
	document.getElementById("aTentoonstellingen").className  = "";
	document.getElementById("divEvenementen").style.display = "";
	document.getElementById("divTentoonstellingen").style.display = "none";
}
//=================================================================================================
function changeDatumEvenement()
{
	document.getElementById("datum").value = calEvenementen.date().formatString("dd-MM-yyyy");
	document.forms["frmEvenementenSearch"].submit();
}
//=================================================================================================
function showTentoonstellingen()
{
	document.getElementById("aEvenementen").className  = "";
	document.getElementById("aTentoonstellingen").className  = "current";
	document.getElementById("divEvenementen").style.display = "none";
	document.getElementById("divTentoonstellingen").style.display = "";
}
//=================================================================================================
function showZoekBoekDetails()
{
	document.getElementById("aDetails").className  = "current";
	document.getElementById("divZoekBoekDetails").style.display = "";
	
	if( document.getElementById("aFotos"))
	{
		document.getElementById("aFotos").className  = "";
		document.getElementById("divZoekBoekFotos").style.display = "none";
	}
}
//=================================================================================================
function showZoekBoekFotos()
{
	document.getElementById("aDetails").className  = "";
	document.getElementById("aFotos").className  = "current";
	document.getElementById("divZoekBoekDetails").style.display = "none";
	document.getElementById("divZoekBoekFotos").style.display = "";
}
//=================================================================================================
//	GOOGLE MAPS
//=================================================================================================
function initGoogleMap(lat, lon)
{
	var
		url       = new Url(),
		divGoogle = document.getElementById("divGoogle");
	
	if ( divGoogle )
	{
		if ( GBrowserIsCompatible() )
		{
			map    = new GMap2( document.getElementById("divGoogle") );
			center = new GLatLng( lat, lon );
			
			map.setCenter( center, 16 );
			map.setMapType(G_SATELLITE_MAP);
			map.addControl( new GSmallMapControl() );
			map.addControl( new GMapTypeControl() );
			
			var marker = new GMarker(new GLatLng(lat, lon));
			map.addOverlay(marker);	
		}
		else
			alert("Helaas is uw browser niet geschikt voor deze kaart.");
	}
}
//=================================================================================================
var
	map, center, 
	markers = new Array();
//=================================================================================================
function setMarker(lat, lon)
{
	var marker = new GMarker(new GLatLng(lat, lon));
	map.addOverlay(marker);			
}
//=================================================================================================
function clearField(target, defaultValue)
{
	var from = document.getElementById(target);
	
	if (from.value == defaultValue)
	{
		from.value = "";
	}	
}
//=================================================================================================
function submitDirection(e, fromAdress, target, defaultValue )
{
	var key=e.keyCode;
	
	if (key==13)
	{
		getDirections(fromAdress, target, defaultValue);
	}
}
//=================================================================================================
function getDirections(fromAdress, target, defaultValue)
{
	var from = document.getElementById(target);
	if(from)
	{		
		if (from.value != defaultValue && from.value != '')
		{
			window.open("misc/getDirections.aspx?from=" + from.value + "&to=" + fromAdress);
		}
		else
		{
			alert("nog geen postcode ingevoerd")
		}
	}
}
//=================================================================================================
function plotDirections(to, from)
{
	var map;
	var directionsPanel;
	var directions;	
	  
	map = new GMap2(document.getElementById("divGoogleMap"));  
	map.addControl( new GSmallMapControl() );
	map.addControl( new GMapTypeControl() );
	directionsPanel = document.getElementById("divGoogleDirections");  
	map.setCenter(new GLatLng(53.04,5.65), 13);  
	directions = new GDirections(map, directionsPanel);  	
	directions.load("from: "+ from + " to: " + to,
                { "locale": "nl_NL" });	
}
//=================================================================================================
var
	request = null;
//-------------------------------------------------------------------------------------------------
function GetSubCategorieen()
{
	request = new XMLHttpRequest();
	
	if ( request != null )
	{
		request.onreadystatechange = ProcessResponse;
		request.open("GET", "/misc/getSubcategorieen.aspx?ID=" + document.getElementById("sector").value,  true);
		request.send( null );		
	}
	
	return false;
}
//=================================================================================================
function ProcessResponse()
{
	if ( request.readyState == 4 )
	{
		if ( request.status == 200 )
		{
				var dsRoot=request.responseXML.documentElement;  
				var ddlOrders = document.getElementById("subsector");
				for (var count = ddlOrders.options.length-1;count >-1; count--)
				{
					ddlOrders.options[count] = null;
				}

				var orders = dsRoot.getElementsByTagName('Subsector');
				var text; 
				var listItem;
				var subCount = 0;

//				listItem = new Option( '-- Geen voorkeur --', '',  false, false);
//				ddlOrders.options[ddlOrders.length] = listItem;
				
				for (var count = 0; count < orders.length; count++)
				{						
					listItem = new Option(orders[count].getAttribute("Name"), orders[count].getAttribute("ID"),  false, false);
					ddlOrders.options[ddlOrders.length] = listItem;
				}
		}
		else
		{
			alert("Error retrieving data!" );
		}
	}
}
//=================================================================================================
function clearTextField(target, text)
{
	var textfield = document.getElementById(target);
		
	if (textfield)
	{	
		if (textfield.value == text)
			textfield.value = "";
	}
}
//=================================================================================================
var menuTimer;
//=================================================================================================
function hideMenu( id )
{
	//alert("hideMenu( " + valueString( document.getElementById( sender ) ) + " )");
	//toggleSubmenu( sender.id.substr(1), false );
	menuTimer = setTimeout("toggleSubmenu( " + id + ", false );", 1000 );
}
//=================================================================================================
function showMenu( id, catCount )
{
	for (var i = 1; i <= catCount; i++)
		toggleSubmenu( i, false );
	
	clearTimeout(menuTimer);

	//alert("showMenu( " + valueString( eval("submenu_" + sender.id.substr(1)).style.display ) + " )");
	toggleSubmenu( id, true );
}
//=================================================================================================
function mouseoverSubCat( sender )
{
	//alert("mouseoverSubCat( " + valueString( sender ) + " )");
	//sender.style.display = "block";
	clearTimeout(menuTimer);
}
//=================================================================================================
function mouseoutSubCat( sender )
{
	//alert("mouseoutSubCat( " + valueString( sender ) + " )");
	//sender.style.display = "none";		// vuurt al bij het binnengaan van subitem. Is op te lossen met timeouts, maar lastig (Erwin). Opgelost me onderstaande event op subitem
	menuTimer = setTimeout('document.getElementById("' + sender.id + '").style.display = "none";' , 1000 );
}
//=================================================================================================
function toggleSubmenu( id, on)
{
	var submenu = document.getElementById( "submenu_" + id )
	
	if (submenu)
		submenu.style.display = on ? "block" : "none";
}
//=================================================================================================
function mouseoverSubitem( )
{
	clearTimeout(menuTimer);
}
//=================================================================================================
function repositionDiv(name, left, width, defaultLeft )
{
	var div = document.getElementById(name);
	
	if (div)
	{
		if (document.body.offsetWidth > width)
		{			
			div.style.left = Math.round(left + (document.body.offsetWidth / 2)) + "px";
		}
		else
		{		
			div.style.left = defaultLeft + "px";
		}
	}
}
//=================================================================================================
function gotoTab(index)
{
	if ($("tab_1"))
		$("tab_1").className = "";
		
	if ($("tab_2"))
		$("tab_2").className = "";
		
	if ($("tab_3"))
		$("tab_3").className = "";

	if ($("content_1"))
		$("content_1").style.display = "none";
	if ($("content_2"))
		$("content_2").style.display = "none";
	if ($("content_3"))
		$("content_3").style.display = "none";

	$("tab_" + index).className = "current";
	$("content_" + index).style.display = "";
}
//=================================================================================================
function loader()
{
	if ($("loaderbackground"))
		$("loaderbackground").style.display = "";

	if ($("loader"))
	{
		$("loader").style.display = "";
		setTimeout('document.images["imgLoader"].src = "/img/loader.gif"', 200); 
	}

	return true;	
}
//=================================================================================================
var baseIcon;
var map;
//=================================================================================================
function initBaseIcon()
{
	var currentUrl = new Url();

	baseIcon = new GIcon();
	baseIcon.image = currentUrl.server() + "img/icon_fietsen.png";
	baseIcon.iconSize = new GSize(38, 39);
	baseIcon.iconAnchor = new GPoint(19, 19);
	//baseIcon.infoWindowAnchor = new GPoint(20, 25);
}
//=================================================================================================
function initializeMap()
{
	if (GBrowserIsCompatible())
	{
		map = new GMap2(document.getElementById("map_canvas"));
	
		map.addControl(new GLargeMapControl3D());
		map.addControl(new GMenuMapTypeControl());
		//map.setMapType(G_HYBRID_MAP);

		initBaseIcon();		
		var point = new GLatLng(52.964357, 6.091919);
		map.setCenter(point, 10);

		map.enableContinuousZoom();		
		map.enableScrollWheelZoom();
	}
}
//=================================================================================================
function getIcon(actID)
{
	var icon = "";
	var currentUrl = new Url();	

	if (actID == 23147)
		icon = currentUrl.server() + "img/icon_fietsen.png";
	if (actID == 23148)
		icon = currentUrl.server() + "img/icon_wellness.png";
	if (actID == 23149)
		icon = currentUrl.server() + "img/icon_wandelen.png";
	if (actID == 23150)
		icon = currentUrl.server() + "img/icon_nordicWalking.png";
	if (actID == 23151)
		icon = currentUrl.server() + "img/icon_kunstCultuur.png";
	if (actID == 23152)
		icon = currentUrl.server() + "img/icon_gastronomie.png";
	if (actID == 23153)
		icon = currentUrl.server() + "img/icon_sportief.png";
	if (actID == 23154)
		icon = currentUrl.server() + "img/icon_paarden.png";
	if (actID == 23155)
		icon = currentUrl.server() + "img/icon_varen.png";

	return icon;
}
//=================================================================================================
function addToMap(latitude, longitude, ID, actID, helptekst)
{

	var icon = baseIcon;

	icon.image = getIcon(actID);

	var point = new GLatLng(latitude, longitude);

	var marker = new PdMarker(point, icon);

	var html = "<div class='shortDesc'>" + helptekst + "</div>";

	marker.setTooltip(html);
	marker.setOpacity(100); 
	
	var url = new Url();

	GEvent.addListener(marker, 'click', function()
	{
		location.href = url.add("itmID", ID).filter("dagen", "personen", "locatie", "activiteit");
	});
	

	map.addOverlay(marker);
}
//=================================================================================================
function addMultipleToMap(latitude, longitude, arr)
{
	var currentUrl = new Url();

	var icon = baseIcon;

	if (arr.length > 10)
		icon.image = currentUrl.server() + "img/icon_10+.png";
	else
		icon.image = currentUrl.server() + "img/icon_" + arr.length + ".png";

	var point = new GLatLng(latitude, longitude);
	var marker = new PdMarker(point, icon);


	var html = "<div class='shortDesc'>Er zijn meerdere arrangementen op deze locatie, klik om deze te bekijken</div>";

	var displayWindow = "";
	var icon = "";

	for (var i = 0; i < arr.length; i++)
	{
		var link = new Url();

		link = link.add("itmID", arr[i][0]).filter("dagen", "activiteit", "locatie", "personen", "catID");
		
	
		icon = getIcon(arr[i][1]);
		
		displayWindow += 	
				"<a href=\"" + link + "\">" +
				"	<img src=\"" + icon + "\" border=\"0\" alt=\"" + arr[i][2] + "\"/>" +
				"	<span>" + arr[i][2] + "</span>" +
				"</a>";
	}

	GEvent.addListener(marker, 'click', function()
	{
		if (!marker.detailOpen)
			map.closeAllWindows();


		var lat = this.getPoint().lat();
		var lng = this.getPoint().lng();

		map.savePosition();

		var center = map.fromLatLngToDivPixel(map.getCenter());
		var current = map.fromLatLngToDivPixel(this.getPoint());
		var fromCenter = subGPoints(current, center);

		map.panBy(new GSize(-fromCenter.x - 80, -fromCenter.y  + 80));	
	});


	marker.setTooltip(html);
	marker.setOpacity(100);
	marker.setDetailWinHTML(displayWindow);
	marker.showDetailOnClick = true;

	map.addOverlay(marker);

}
//=================================================================================================	
function subGPoints(a, b)
{
	//returns the distance in pixels between point a and b

	return new GPoint(a.x - b.x, a.y - b.y);
}