

function centremap(type, address, retryaddress, llpoint, showthisid, showurl) 
{
	if (GBrowserIsCompatible()) 
	{
		map = new GMap2(document.getElementById("googlemap"));
		if(type != 'small') {
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
		}
		else {
			document.getElementById("googlemap").onclick = function() {
				//document.location.href = 'articlemap.asp?id=' + showthisid;	
				document.location.href = showurl; //'/map/' + showthisid;					
			}
			map.disableDragging();
			map.disableInfoWindow();
			map.disableDoubleClickZoom();
			map.disableContinuousZoom();
			map.disableScrollWheelZoom();
		}
		geocoder = new GClientGeocoder();
				
		if (llpoint == false)
		{
			geocoder.getLatLng
			(
				address, 
				function(point) 
				{
					if (!point) 
					{
						if(retryaddress != false)
						{
							/*try again only with the retry*/
							centremap(type, retryaddress, false, false, showthisid, showurl);
						}
						else
						{
							/*place not found text*/
							document.getElementById("googlemap").style.display = 'none';
							document.getElementById("googlemapnotfound").style.display = 'block';
						}
					} 
					else 
					{
						if(retryaddress == false)
						{
							/*retry address, zoom out*/
							var zoomlevel = 13;
						}
						else
						{
							/*orginal address, zoom in*/
							if(type != 'small') {var zoomlevel = 15;} else {var zoomlevel = 14;}
						}	 
						map.setCenter(point, zoomlevel, G_NORMAL_MAP); //G_HYBRID_MAP
						GEvent.addListener(map, "moveend", function() {
							map.clearOverlays();
							if(map.getZoom() < 9){
								alert('U bent te ver uitgezoomd, zoom in voor meer gegevens.');
							}
							else {
								placevisible(type, map.getBounds(), showthisid);
							}
						});
						placevisible(type, map.getBounds(), showthisid); 
					}
				}
			);
		}
		else
		{
			var point = llpoint;
			if(type != 'small' && type != 'walk') {
				var zoomlevel = 15;
			} 
			else {
				var zoomlevel = 14;
			}
			map.setCenter(point, zoomlevel, G_NORMAL_MAP);
			
			if(type != 'walk') {
				GEvent.addListener(map, "moveend", function() {
					map.clearOverlays();
					if(map.getZoom() < 9){
						alert('U bent te ver uitgezoomd, zoom in voor meer gegevens.');
					}
					else {
						placevisible(type, map.getBounds(), showthisid);
					}
				});
				placevisible(type, map.getBounds(), showthisid);
			}
		}
	}
}


function placemap() 
{
	if (GBrowserIsCompatible()) 
	{
		map = new GMap2(document.getElementById("googlemap"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
		
		map.setCenter(new GLatLng(0,0),0);
		bounds = new GLatLngBounds();
	}
}
function placemaprender() 
{
	map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds), G_NORMAL_MAP);
}


function placevisible(type, bounds, showthisid)
{
	//alert(bounds);
	loadXML('/searchmap.asp?type=' + type + '&bounds=' + bounds + '&showthisid=' + showthisid);
}

function addmap(type, showthisid, iconurl, llpoint, title, text, img, objclass, showurl) 
{
	icon = new GIcon(G_DEFAULT_ICON);
	icon.image = iconurl //"images/i/map_museum.png";
	icon.shadow = "";
	icon.iconSize = new GSize(20, 34);
	
	if(bounds != null)
	{
		bounds.extend(llpoint);
	}
	
	//var point = llpoint;
	//map.setCenter(point, 15, G_HYBRID_MAP);
	var marker = new GMarker(llpoint, icon);
	map.addOverlay(marker);
	
	if(type!='small'){
		GEvent.addListener(marker, "click", function() {
			//alert('click: ' + title);
			if(currentmarker != null)
			{
				closebox();	
			}
													 
			map.disableDragging();
			map.setCenter(llpoint);
			
			var obj = document.createElement('div');
			obj.id = 'infobox';
			obj.className = objclass;
			
			var h3 = document.createElement('h3');
			h3.innerHTML = title;
			obj.appendChild(h3);
			var p = document.createElement('p');
			if(img != null) {
				p.innerHTML = '<img src="'+img+'" alt="" title="" width="100">' + text + ' <a class="close" href="javascript: void(0);" onclick="return closebox();"><span>[sluiten]</span></a>';
			}
			else {
				p.innerHTML = text + ' <a class="close" href="javascript: void(0);" onclick="return closebox();"><span>[sluiten]</span></a>';
			}
			obj.appendChild(p);
			
			document.getElementById('googlemap').appendChild(obj);
			obj.style.marginTop = (map.fromLatLngToContainerPixel(marker.getPoint()).y - 145) + 'px';
			obj.style.marginLeft = (map.fromLatLngToContainerPixel(marker.getPoint()).x - 5) + 'px';
			
			currentmarker = marker;
		});
	}
	else {
		GEvent.addListener(marker, "click", function() {
			//document.location.href = 'articlemap.asp?id=' + showthisid;	
			document.location.href = showurl; //'/map/' + showthisid;	
		});
	}
}
function closebox()
{
	var obj = document.getElementById('infobox');
	obj.parentNode.removeChild(obj);
	currentmarker=null;
	map.enableDragging();
	return false;
}
function loadXML(page)
{
	//alert(page);
	var req = null; 
	if(window.XMLHttpRequest)
	{
		req = new XMLHttpRequest(); 
	}
	else if (window.ActiveXObject)
	{
		req  = new ActiveXObject("Microsoft.XMLHTTP"); 
	}
	req.onreadystatechange = function()
	{ 
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				//goed
				//eval(followfunction);
				//alert(req.responseText);
				eval(req.responseText);
			}
			else
			{
				//fout
				alert(req.status + " " + req.statusText);
			}
		} 
	}; 
	req.open("GET", page, true); 
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	req.send(null); 
}
function init()
{
	// ===== menu's =========================================================
	var menu = document.getElementById('mainmenu');
	var lis = menu.childNodes;
	
	for(var i=0;i<lis.length;i++)
	{
		var submenu = lis[i].getElementsByTagName('ul')[0];
		if(submenu)
		{
			lis[i].onmouseover = function()
			{
				var thesubm = this.getElementsByTagName('ul')[0];
				if(thesubm)
				{
					thesubm.style.left = (findPos(this)[0]) + 'px';
					thesubm.style.display = 'block';
				}
			}
			lis[i].onmouseout = function()
			{
				var thesubm = this.getElementsByTagName('ul')[0];
				if(thesubm)
				{
					thesubm.style.display = 'none';
				}
			}
		}
	}
	
	var pictviewer = document.getElementById('pictviewer');
	if(pictviewer) {/*
		var newimg = pictviewer.getElementsByTagName('img')[0]
		newimg.onmouseover = new Function("showlic('"+newimg.className+"')");
		newimg.onmouseout = new Function("hidelic()")
	
		var license = document.getElementById('license');
		license.onmouseover = new Function("showlic('"+newimg.className+"')");
		license.onmouseout = new Function("hidelic()")*/
		
		
		var allas = pictviewer.getElementsByTagName('a');
		for(var i=0;i<allas.length;i++)
		{
			var src = allas[i].getElementsByTagName('img')[0].src;
			var cls = allas[i].getElementsByTagName('img')[0].className;
			src = src.substr(src.lastIndexOf('/')+1);
			
			allas[i].onclick = new Function("showimg('"+src+"','"+cls+"',"+i+");return false;");
		}
	}
	// ===== menu's =========================================================
	
	// ===== europe map =====================================================
	var europemap = document.getElementById('map');
	if(europemap == null) { europemap = document.getElementById('countrymap') }
	var maptitle = document.getElementById('maptitle');
	
	if(europemap != null && maptitle != null) {
		var areas = europemap.getElementsByTagName('area');
		for(var i=0;i<areas.length;i++) {
			areas[i].onmouseover = new Function("document.getElementById('maptitle').innerHTML = '&nbsp;-&nbsp;' + this.title;");
			areas[i].onmouseout = new Function("document.getElementById('maptitle').innerHTML = '';");
		}
	}
	// ===== europe map =====================================================
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}


function showimg(imgsrc, imgcls, curi)
{
	var pictviewer = document.getElementById('pictviewer');
	var alllis = pictviewer.getElementsByTagName('li');
	var firstli = alllis[0];
	var firstimg = firstli.getElementsByTagName('img')[0];
	
	curi = curi + 1;
	for(var i=0;i<alllis.length;i++)
	{
		if(alllis[i].className == 'active')
		{
			alllis[i].className = '';
		}
	}
	pictviewer.getElementsByTagName('li')[curi].className = 'active';
	
	var newimg = document.createElement('img');
	newimg.src = 'http://www.oorlogsmusea.nl/upload/' + imgsrc;
	if(imgcls.length > 0) {
		newimg.className = imgcls;
		//newimg.onmouseover = new Function("showlic('"+imgcls+"')");
		//newimg.onmouseout = new Function("hidelic()")
	}
	firstli.removeChild(firstimg);
	firstli.appendChild(newimg);
	/*
	var license = document.getElementById('license');
	license.onmouseover = new Function("showlic('"+imgcls+"')");
	license.onmouseout = new Function("hidelic()")*/
}

function showlic(imgcls) {
	var pictviewer = document.getElementById('pictviewer');
	var alllis = pictviewer.getElementsByTagName('li');
	var firstli = alllis[0];
	var firstimg = firstli.getElementsByTagName('img')[0];
	
	var license = document.getElementById('license');
	var newlimg = license.getElementsByTagName('a')[0];
	if(newlimg) {
		license.removeChild(newlimg);
	}
	
	
	if(imgcls.length > 0) {
	
		var newa = document.createElement('a');
		newa.href='http://www.stiwot.nl';
		newa.target='_blank';
		license.appendChild(newa);
		
		var newlimg = document.createElement('img');
		newlimg.src = 'http://www.oorlogsmusea.nl/images/i/' + imgcls + '.png';
		newlimg.className = imgcls;
		newa.appendChild(newlimg);
		license.style.display = 'block';
		license.style.left= (findPos(firstimg)[0] + 5) + 'px';
		license.style.top= (findPos(firstimg)[1] + 5) + 'px';
	}
	else {
		license.style.display = 'none';	
	}
}

function hidelic() {
	var license = document.getElementById('license');
	license.style.display = 'none';	
	
}

function checkfeedback()
{
	var name = document.getElementById('a1').value;
	var email = document.getElementById('a2').value;
	var message = document.getElementById('a3').value;
	
	
	if(name == '' || email == '' || message == '') {
		alert('Alle velden zijn verplicht.');	
		return false;
	}
	else if(email.indexOf('@') == -1 || email.indexOf('.') == -1) {
		alert('Een geldig e-mailadres is verplicht.');	
		return false;
	}
	
	return true;
}
function checkcontact()
{
	var name = document.getElementById('naam').value;
	var email = document.getElementById('email').value;
	var subject = document.getElementById('onderwerp').value;
	var message = document.getElementById('bericht').value;
	
	
	if(name == '' || email == '' || message == '' || subject == '') {
		alert('Alle velden zijn verplicht.');	
		return false;
	}
	else if(email.indexOf('@') == -1 || email.indexOf('.') == -1) {
		alert('Een geldig e-mailadres is verplicht.');	
		return false;
	}
	
	return true;
}

function timediff(starttime)
{
	return ((new Date().getTime()-starttime)/1000).toString().replace('.',',');
}
function getdis_v2(id, here, there) {
	var gDirections = new GDirections(null, null);
	
	GEvent.addListener(gDirections, 'load', function(){ // Listnener fordirections on load
		var res = gDirections.getDistance().meters / 1000;
		res = res.toFixed(1);
		res = res.toString();
		if(res.indexOf('.') == -1) {
			res = res + '.0';
		}
		
		res = res + ' km';
		document.getElementById(id).innerHTML = res;
	});
	
	gDirections.loadFromWaypoints([here,there], {getSteps:true})
  
			
}
function doem(thisid, t1,t2)
{
	thisid.href = 'mailto: ' + t1 + '@' + t2;
}

function doprint()
{
	window.print();
	return false;
}

var gbl_helptitle = '';
function dohelp(elm) 
{
	elm.onclick = function() { return false; }
	elm.onmouseout = function() { exithelp(elm); }
	gbl_helptitle = elm.title;
	elm.title = '';
	var dh_popup = document.createElement('div');
	dh_popup.id = 'popup';
	dh_title = document.createElement('h3');
	dh_title.innerHTML = 'Oorlogsmusea.nl - Help';
	dh_popup.appendChild(dh_title);
	dh_text = document.createElement('p');
	dh_text.innerHTML = gbl_helptitle;
	dh_popup.appendChild(dh_text);
	dh_popup.style.left = (findPos(elm)[0] - 300) + 'px'
	dh_popup.style.top = (findPos(elm)[1] - 20) + 'px'
	document.getElementsByTagName('body')[0].appendChild(dh_popup);
}
function exithelp(elm) 
{
	elm.title = gbl_helptitle;
	document.getElementsByTagName('body')[0].removeChild(document.getElementById('popup'));
}


function checkfields()
{
	var pass=true;
	var arguments=checkfields.arguments;
	if (arguments.length > 0)
	{
		for (i=0; i < arguments.length; i++)
		{
			if (document.getElementById(arguments[i]).value=="" && pass==true)
			{
				pass=false;
			}
		}
	}
	if (pass==false)
	{
		alert("U heeft niet alle velden gevuld!");
		return false;
	}
	else
	{
		return true;
	}
}

function searchcheck() {
	var sfld = document.getElementById('searchtxt');
	if(sfld.value.length == 0) {
		alert('Een zoekterm is verplicht.');
		return false;
	}
	else {
		return true;	
	}
}


//set global vars
var map = null;
var geocoder = null;
var currentmarker = null;
var bounds = null;
//set init
window.onload = init;