

var map;
var gDir;

var geocoder = null;
var addressMarker;

var markersData = new Array();
var markers     = new Array();
var geocoder = null;
var gmarkers = [];
var markerPos = [];
var info = [];
var j = 0;
var counter = 0;

var name; 
var profile_id; 
var profile_name;
var addDate;
var comment; 
var directionsPanel;
var marker_html;
var from;
var to;


function gm_initialize() 
{
      if (GBrowserIsCompatible()) 
      {      
      
			//from = document.getElementById("from").value;
			//to = document.getElementById("to").value;
      
	        map = new GMap2(document.getElementById("map"));
			//gDir = new GDirections(map, document.getElementById("directions"));
	        //GEvent.addListener(gDir, "load", onGDirectionsLoad);
	        //GEvent.addListener(gDir, "error", handleErrors);

      }
}


function handleErrors()
{
   if (gDir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
     alert("Adresse konnte nicht gefunden werden.\nError code: " + gDir.getStatus().code);
   else if (gDir.getStatus().code == G_GEO_SERVER_ERROR)
     alert("GoogleMaps Server-Fehler.\n Error code: " + gDir.getStatus().code);
   else if (gDir.getStatus().code == G_GEO_MISSING_QUERY)
     alert("Bitte stellen Sie eine Anfrage.\n Error code: " + gDir.getStatus().code);
   else if (gDir.getStatus().code == G_GEO_BAD_KEY)
     alert("GoogleMaps Key ist ungültig. \n Error code: " + gDir.getStatus().code);
   else if (gDir.getStatus().code == G_GEO_BAD_REQUEST)
     alert("Falsche Anfrage...\n Error code: " + gDir.getStatus().code);
   else alert("An unknown error occurred.");	   
}


function onGDirectionsLoad()
{ 
	//document.getElementById("directions").style.display = "inline";
}



function maps_load_geo(address, params, html) 
{


	profile_id = params[0];
	profile_name = params[1];
	addDate = params[2];
	country = params[3];
	marker_html = html;
	


	if (GBrowserIsCompatible()) 
	{

       		geocoder = new GClientGeocoder();
       		map.addControl(new GSmallMapControl());
			showAddress(address);


	}
	else
	{
		alert("Sorry, leider ist die GoogleMaps API nicht kompatibel zu Ihrem Browser!");
	}
	
}


function createMarker(point) 
{
	
		
	var ctLogo = new GIcon(G_DEFAULT_ICON);
	ctLogo.image = "http://www.hcom-systeme.de/images/marker.png";
	ctLogo.iconSize = new GSize(32, 32);
	
	markerOptions = { icon:ctLogo }; 

	
	var marker = new GMarker(point, markerOptions);
	var displayHtml = marker_html;
	
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(displayHtml);
	});

	markerPos[j] 	= point;
	gmarkers[j] 	= marker;
	info[j]		= displayHtml;

	var zoomout="1";
	j++;
	return marker;
}



function setPosAndZoom(point, zoom)
{
	map.setCenter(point,zoom);
}	


function openMarker(index, zoom)
{
	if(zoom!=-1)
	{
		setPosAndZoom(markerPos[index],zoom);
		gmarkers[index].openInfoWindowHtml(info[index]);
	}
	else
	{
		//leave level of zoom as it is
		gmarkers[index].openInfoWindowHtml(info[index]);
	}
}


function showAddress(address) 
{
	geocoder.getLatLng(
		address,
		function(point) 
		{
			if (!point) 
			{
				alert(address + " nicht gefunden");
			} 
			else 
			{
				
				map.setCenter(point, 15);
				var marker = createMarker(point);
				map.addOverlay(marker);

			}
		}
	);
}



function generateRoute() 
{
	/*
	var from = document.getElementById("from").value;
	var to = document.getElementById("to").value;
	document.getElementById("directions_panel").style.border = "1px solid #CDCDCD";
	document.getElementById("route_controls").style.display = "none";
	document.getElementById("route_loaded_controls").style.display = "inline";
	document.getElementById("directions_panel").style.height = "472px";
	document.getElementById("directions_panel").className = "dir-loaded";
	setDirections(from, to, "de");
  	*/
}

function setDirections(fromAddress, toAddress, locale) 
{
	/*
  gDir.load("from: " + fromAddress + " to: " + toAddress,
            { preserveViewport: true, getSteps: true, locale: 'de' });
            */
}

function printRoute()
{
	/*
	var a = window.open('','','width=10,height=10');
	a.document.open("text/html");
	a.document.write(document.getElementById('directions').innerHTML);
	a.document.close();
	a.print();
	*/
}

function restartRoute()
{
	/*
	document.getElementById("directions_panel").style.height = "432px";
	document.getElementById("directions_panel").style.border = "0px";
	document.getElementById("route_controls").style.display = "inline";
	document.getElementById("route_loaded_controls").style.display = "none";
	document.getElementById("directions").style.display = "none";
	document.getElementById("directions_panel").className = "";
	*/
}











