function initCrossHairs() {
	var isNS4=document.layers?true:false;
	var isIE=document.all?true:false;
	var isIE6=isIE&&document.getElementById?true:false;
	var isIE4=isIE&&!isIE6?true:false;
	var isNS6=!isIE6&&document.getElementById?true:false;
	var isNS=isNS4||isNS6;
	
	if(isNS4) {
		document.captureEvents(Event.MOUSEMOVE); 
		document.onmousemove=showMouseLocation; 
	} else if(isNS6) {
		document.addEventListener("mousemove", showMouseLocation, true);
	} else if(isIE) {
	 document.onmousemove=showMouseLocation;
	}
}

function showSelectedLocation(selectedVOffset,selectedHOffset) {
	var isNS4=document.layers?true:false;
	var isIE=document.all?true:false;
	var isIE6=isIE&&document.getElementById?true:false;
	var isIE4=isIE&&!isIE6?true:false;
	var isNS6=!isIE6&&document.getElementById?true:false;
	var isNS=isNS4||isNS6;
	
	if (isIE4) {
		return true ;
	}
	
	if (selectedVOffset == "" || selectedHOffset == "") {
		return true ;
	}
	if (!document.getElementById('kaart_van_nederland')) {
		return true ;
	}
	if (!document.getElementById('selected_location_crosshairs_vertical')) {
		return true ;
	}
	if (!document.getElementById('selected_location_crosshairs_horizontal')) {
		return true ;
	}
	theHScroll = 0 ;
	theVScroll = 0 ;
	
	if (window.document.body) {
		theHScroll = window.document.body.scrollLeft;
		theVScroll = window.document.body.scrollTop;
	} else if (window.document.documentElement && window.document.documentElement.scrollTop) {
		theHScroll = window.document.documentElement.scrollLeft;
		theVScroll = window.document.documentElement.scrollTop;
	} else if (window.pageYOffset) {
		theHScroll = window.pageXOffset;
		theVScroll = window.pageYOffset;
	}
	
	mapLeft = document.getElementById('kaart_van_nederland').style.left ;
	mapTop = document.getElementById('kaart_van_nederland').style.top ;
	
	if (mapLeft.indexOf("px") != -1) {
		mapLeft = mapLeft.substr(0,mapLeft.indexOf("px")) ;
	}
	if (mapTop.indexOf("px") != -1) {
		mapTop = mapTop.substr(0,mapTop.indexOf("px")) ;
	}
	mapLeft = parseInt(mapLeft) ;
	mapTop = parseInt(mapTop) ;
	
	selectedHOffset += mapLeft ;
	selectedVOffset += mapTop ;
	
	document.getElementById('selected_location_crosshairs_vertical').style.left = selectedHOffset + "px" ;
	document.getElementById('selected_location_crosshairs_horizontal').style.top = selectedVOffset + "px" ;
	document.getElementById('selected_location_crosshairs_box').style.left = (selectedHOffset-3) + "px" ;
	document.getElementById('selected_location_crosshairs_box').style.top = (selectedVOffset-3) + "px" ;
	if (getBrowserType() == "Internet Explorer") {
		document.getElementById('selected_location_crosshairs_box').style.width = 7 ;
		document.getElementById('selected_location_crosshairs_box').style.height = 7 ;
	}
	showLayer('selected_location_crosshairs_vertical','visible') ;
	showLayer('selected_location_crosshairs_horizontal','visible') ;
	showLayer('selected_location_crosshairs_box','visible') ;
}

function showMouseLocation(e) {
	var isNS4=document.layers?true:false;
	var isIE=document.all?true:false;
	var isIE6=isIE&&document.getElementById?true:false;
	var isIE4=isIE&&!isIE6?true:false;
	var isNS6=!isIE6&&document.getElementById?true:false;
	var isNS=isNS4||isNS6;
	
	if ( !document.getElementById('kaart_van_nederland') 
	  || !document.getElementById('latitude')
	  || !document.getElementById('longitude')
	  || !document.getElementById('cursor_crosshairs_horizontal')
	  || !document.getElementById('cursor_crosshairs_vertical') ) {
		return true ;
	}
	if (isIE4) {
		return true ;
	}
	theHScroll = 0 ;
	theVScroll = 0 ;
	if (window.pageYOffset) {
		theHScroll = window.pageXOffset;
		theVScroll = window.pageYOffset;
	} else if (window.document.body) {
		theHScroll = window.document.body.scrollLeft;
		theVScroll = window.document.body.scrollTop;
	} else if (window.document.documentElement && window.document.documentElement.scrollTop) {
		theHScroll = window.document.documentElement.scrollLeft;
		theVScroll = window.document.documentElement.scrollTop;
	}
		
	if (document.all) {
		mouseHOffset = event.clientX + theHScroll;
		mouseVOffset = event.clientY + theVScroll;
	} else {
		mouseHOffset = e.pageX ;
		mouseVOffset = e.pageY ;
	}
	
	var browserType = getBrowserType() ;
	if (browserType == "Mozilla") {
		mouseVOffset -= 1 ;
		mouseHOffset -= 1 ;
	} else if (browserType == "Internet Explorer" && getPlatform() == "Windows") {
		mouseHOffset  -= 2 ;
		mouseVOffset  -= 2 ;
	}
	
	mapLeft = document.getElementById('kaart_van_nederland').style.left ;
	mapTop = document.getElementById('kaart_van_nederland').style.top ;
	mapWidth = document.getElementById('kaart_van_nederland').style.width ;
	mapHeight = document.getElementById('kaart_van_nederland').style.height ;
	
	if (mapLeft.indexOf("px") != -1) {
		mapLeft = mapLeft.substr(0,mapLeft.indexOf("px")) ;
	}
	if (mapTop.indexOf("px") != -1) {
		mapTop = mapTop.substr(0,mapTop.indexOf("px")) ;
	}
	if (mapWidth.indexOf("px") != -1) {
		mapWidth = mapWidth.substr(0,mapWidth.indexOf("px")) ;
	}
	if (mapHeight.indexOf("px") != -1) {
		mapHeight = mapHeight.substr(0,mapHeight.indexOf("px")) ;
	}
	mapLeft = parseInt(mapLeft) ;
	mapTop = parseInt(mapTop) ;
	mapWidth = parseInt(mapWidth) ;
	mapHeight = parseInt(mapHeight) ;
	mapRight = mapLeft + mapWidth - 1 ;
	mapBottom = mapTop + mapHeight - 1 ;
	
	if (mouseHOffset < mapLeft || mouseHOffset > mapRight || mouseVOffset < mapTop || mouseVOffset > mapBottom) {
		showLayer('cursor_crosshairs_vertical','hidden') ;
		showLayer('cursor_crosshairs_horizontal','hidden') ;
	} else {
		document.getElementById('cursor_crosshairs_vertical').style.left = mouseHOffset + "px" ;
		document.getElementById('cursor_crosshairs_horizontal').style.top = mouseVOffset + "px" ;
		showLayer('cursor_crosshairs_vertical','visible') ;
		showLayer('cursor_crosshairs_horizontal','visible') ;
	}

	if (mouseHOffset < mapLeft || mouseHOffset > mapRight || mouseVOffset < mapTop || mouseVOffset > mapBottom) {
		if (document.getElementById('latitude')) {
			document.getElementById('latitude').innerHTML = "" ;
		}
		if (document.getElementById('longitude')) {
			document.getElementById('longitude').innerHTML = "" ;
		}
		if (document.getElementById('kaartvakje')) {
			document.getElementById('kaartvakje').innerHTML = "" ;
		}
	} else {
		mapLeftInDegrees = 3 ;
		mapRightInDegrees = 7.5 ;
		mapTopInDegrees = 54 ;
		mapBottomInDegrees = 50.5 ;
		mapWidthInDegrees = mapRightInDegrees - mapLeftInDegrees ;
		mapHeightInDegrees = mapTopInDegrees - mapBottomInDegrees ;
		
		longitudeInDecimalDegrees = mapLeftInDegrees + (((mouseHOffset-mapLeft)/mapWidth) * mapWidthInDegrees) ;
		latitudeInDecimalDegrees = mapTopInDegrees - (((mouseVOffset-mapTop)/mapHeight) * mapHeightInDegrees) ;
		
		longitudeInDegrees = Math.floor(longitudeInDecimalDegrees) ;
		latitudeInDegrees = Math.floor(latitudeInDecimalDegrees) ;
		
		longitudeInMinutes = Math.floor((longitudeInDecimalDegrees - longitudeInDegrees)*60)
		latitudeInMinutes = Math.floor((latitudeInDecimalDegrees - latitudeInDegrees)*60)
		
		document.getElementById('latitude').innerHTML = longitudeInDegrees + "&deg;" + longitudeInMinutes + "' OL" ;
		document.getElementById('longitude').innerHTML = latitudeInDegrees + "&deg;" + latitudeInMinutes + "' NB" ;

		// determine number of map square under cursor
		
		var squareWidthInPixels = 19 ;
		var squareHeightInPixels = 15 ;
		var numberOfColumns = 9 ;
		var numberOfRows = 14 ;
		
		var currentColumn = Math.ceil((mouseHOffset - mapLeft) / squareWidthInPixels) ;
		if (currentColumn < 1) {
			currentColumn = 1 ;
		} else if (currentColumn > numberOfColumns) {
			currentColumn = numberOfColumns ;
		}
		var currentRow = Math.ceil((mouseVOffset - mapTop) / squareHeightInPixels) ;
		if (currentRow < 1) {
			currentRow = 1 ;
		} else if (currentRow > numberOfRows) {
			currentRow = numberOfRows ;
		}
		currentSquare = currentColumn
		if (currentRow > 1) {
			currentSquare += ((currentRow-1)*numberOfColumns) ;
		}
		document.getElementById('kaartvakje').innerHTML = currentSquare ; 
		
//window.status = currentSquare ;

	}
	
}

function clearMouseLocation(e) {
	if ( !document.getElementById('latitude') 
	  || !document.getElementById('longitude')
	  || !document.getElementById('cursor_crosshairs_horizontal')
	  || !document.getElementById('cursor_crosshairs_vertical') ) {
		return true ;
	}
	document.getElementById('latitude').innerHTML = "" ;
	document.getElementById('longitude').innerHTML = "" ;
	showLayer('cursor_crosshairs_vertical','hidden') ;
	showLayer('cursor_crosshairs_horizontal','hidden') ;
}

function searchMap() {
	if ( !document.getElementById('kaart_van_nederland') 
	  || !document.getElementById('kaartvakje')
	  || !document.getElementById('latitude')
	  || !document.getElementById('longitude')
	  || !document.getElementById('cursor_crosshairs_horizontal')
	  || !document.getElementById('cursor_crosshairs_vertical') ) {
		return true ;
	}
	
	var kaartVakje = document.getElementById('kaartvakje').innerHTML ;
	if (kaartVakje == "" || kaartVakje == "&nbsp;" ) {
		return true ;
	}
	var breedte = document.getElementById('latitude').innerHTML ;
	var lengte = document.getElementById('longitude').innerHTML ;
	
	var crossHairsVerticalOffSet = document.getElementById('cursor_crosshairs_horizontal').style.top ;
	var crossHairsHorizontalOffSet = document.getElementById('cursor_crosshairs_vertical').style.left ;
	
	var mapTop = document.getElementById('kaart_van_nederland').style.top ;
	var mapLeft = document.getElementById('kaart_van_nederland').style.left ;
	
	if (mapTop.indexOf("px") != -1) {
		mapTop = mapTop.substr(0,mapTop.indexOf("px")) ;
	}
	if (mapLeft.indexOf("px") != -1) {
		mapLeft = mapLeft.substr(0,mapLeft.indexOf("px")) ;
	}
	if (crossHairsVerticalOffSet.indexOf("px") != -1) {
		crossHairsVerticalOffSet = crossHairsVerticalOffSet.substr(0,crossHairsVerticalOffSet.indexOf("px")) ;
	}
	if (crossHairsHorizontalOffSet.indexOf("px") != -1) {
		crossHairsHorizontalOffSet = crossHairsHorizontalOffSet.substr(0,crossHairsHorizontalOffSet.indexOf("px")) ;
	}
	mapLeft = parseInt(mapLeft) ;
	mapTop = parseInt(mapTop) ;
	crossHairsHorizontalOffSet = parseInt(crossHairsHorizontalOffSet) ;
	crossHairsVerticalOffSet = parseInt(crossHairsVerticalOffSet) ;
	
	var voffset = crossHairsVerticalOffSet - mapTop ;
	var hoffset = crossHairsHorizontalOffSet - mapLeft ;
	
	document.location.href = "zoeken.php?kaartvakje=" + kaartVakje + "&lengte=" + escape(lengte) + 
	  "&breedte=" + escape(breedte) + "&voffset=" + voffset + "&hoffset=" + hoffset ;
}