 /*
	Copyright (c) 2010 by Nop.
	Copying or reuse require explicit approval by the author.
 */

function toggleLayer(id) {
  e = document.getElementById(id);
  if( e.style.display=='none' ) showLayer(id);
  else hideLayer(id);
}

function showLayer( id ) {
  e = document.getElementById(id);
  e.style.display = "block";
}

function hideLayer(id) {
  e = document.getElementById(id);
  e.style.display = "none";
}

function isVisible(id) {
  e = document.getElementById(id);
  return e.style.display != "none";
}

function activateTool( select )
{
	dirVisible = isVisible( 'dirs' );
	
	if( select != 'editors' )
		hideLayer( 'editors' );
	if( select != 'toolbar' )
		hideLayer( 'toolbar' );
	if( select != 'dirs' )
		hideLayer( 'dirs' );
	
	toggleLayer( select );
	
	if( dirVisible || isVisible( 'dirs' ) )
		switchPOILayer();
}

function switchPOILayer()
{
	if( pois )
	{
		var z = map.getZoom();
		// poi layer is active for high zoom info mode tool
		if( z >= 12 && isVisible( 'dirs' ) )
			pois.setVisibility(true);
		else
			pois.setVisibility(false);
	}
}

function enableKeyboard( isActive )
{
	if( isActive )
		map.controls[0].activate();
	else
		map.controls[0].deactivate();
}

function setHighlight(id, isSelected, colNormal, colHigh ) {
  e = document.getElementById(id);
  if( isSelected )
  {
	e.style.color = colHigh;
	e.style.fontWeight = "bold";
	}
  else
  {
	e.style.color = colNormal;
	e.style.fontWeight = "normal";
	}
}

function setVisible( id, isVisible )
{
	if( isVisible )
		showLayer( id );
	else
		hideLayer( id );
}
/*
function showUploadLayer() {
  // first we need to fix the form's action to contain the query
  // parameters of the permalink
  e = document.getElementById("uplform");
  path = e.action.replace(/[?].* /, "");
  perm = document.getElementById("permalink").href.replace(/.*[?]/, "");
  e.action = path+'?'+perm;
  showLayer('uploadLayer', 'block');
}*/
function setCursor(id, cursor) {
  var e = document.getElementById(id);
  e.style.cursor = cursor;
}

function showMapKey( id )
{
	var show = ( id == 'mapkey_nodes' );
	setVisible( 'mapkey_nodes', show );
	setHighlight( 'mapkey_nodes_menu', show, "#000070", "#FFFFFF" );
	
	show = ( id == 'mapkey_ways' );
	setVisible( 'mapkey_ways', show );
	setHighlight( 'mapkey_ways_menu', show, "#000070", "#FFFFFF" );

	show = ( id == 'mapkey_ground' );
	setVisible( 'mapkey_ground', show );
	setHighlight( 'mapkey_ground_menu', show, "#000070", "#FFFFFF" );
}


// Geolocation by Claudius Heinrichs

function getPosition() {
	if (navigator.geolocation) {
		try {
			navigator.geolocation.getCurrentPosition(usePosition,
			  function(error){
				// Error while retrieving Geolocation from Browser, e.g. user didn't allow access
			});
		  } catch (e) {
			alert("Exception while retrieving Geolocation from Browser.");
		  }
		}
	}

function usePosition(position) {
	lat = position.coords.latitude;
	lon = position.coords.longitude;
	var lonlat = new OpenLayers.LonLat(lon, lat);
	lonlat = p2p(p4326, p900913, lonlat);
	map.setCenter(lonlat, 15, false, false);
	//updateScale;
	//updateLocation;
  }

// *** Fügt eine E-Mail-Adresse ein ***
function insertMail(mailnam,mailsvr,maildom,text)
{
  document.write('<a href="mailto:'+mailnam+'@'+mailsvr+'.'+maildom+'">'+text+'</a>');
}

function printMap()
{
	gpxTrack.store();

	perma = document.getElementById('permalink.topo').href;
	perma = perma.replace( '/index.php?', '/print_de.php?' );
	//alert(perma);
	window.open( perma );
}


