// Api Variablen
var usip;
var global_path;
var gmap_path;
var modul_path;
var modul_gfx;
var global_gfx;
var BTN_URL;
var IMG_URL;
var THB_URL;
var CHAINPIC_URL;
var flash_path;

var bg_div  = "bg_layer";
var content_div = "content_layer";
var timeStamp;

var ovMap;
var startLatLng;
var gmarkers = [];
var Gmarkers = [];
var html = [];
		
var icons = [];
var my_tooltip;  
var marker;
var mp;
// Routenplaner Varibalen
var geocoder = null;
var addressMarker;
var routeStart;
var routeEnd;
// Geocoder Variablen
var geo;
var geoMarker;
// MyHome
var myHomeMarker;
var myHomeID;
var mh_unlocked = false;
var mh_tpl;
// MarkerLatLng
var markerID;
var markerLat;
var markerLng;
var markerName;
var markerText;

// global mapevents
function getMapEvents(){
	//GmapService.instalize();
	
	getPath();
	//SuchFormulare installieren
	installSearchForm();
	//ListenOrderBtn installieren
	installOrderBtns()
	//Map Eventes
	map.enableDoubleClickZoom();
	map.enableScrollWheelZoom();
	map.enableContinuousZoom();
	new GKeyboardHandler(map);
	
	// Namentooltip Setup 
	my_tooltip = document.createElement("div");
	map.getPane(G_MAP_FLOAT_PANE).appendChild(my_tooltip);
	my_tooltip.style.visibility="hidden";  	
	
	// Event Listener
	GEvent.addDomListener(map.getContainer(), "DOMMouseScroll", wheelevent);
		map.getContainer().onmousewheel = wheelevent; 

	// karten click
	GEvent.addListener(map, "click", function(marker, point) {
		
		if(!marker){
			//Neuen MySearch erstellen
			placeMySearch(point.y,point.x);
		}else if(marker.cat == "geo"){
			//MySearch öffnen
			var point = marker.getPoint();
			geoMarker.openInfoWindowHtml('<div id="mySearch">'+getNorSearchTpl(point)+'</div>');
		}

	});
	// Mapinfos aktualisieren
	GEvent.addListener(map, "moveend", function(){ updateStatusBar(); });
	GEvent.addListener(map, "zoomend", function(){ updateStatusBar(); });

}
// Seitenscroller
function wheelevent(e){
	if (!e){
		e = window.event
	}
	if (e.preventDefault){
		e.preventDefault()
	}
e.returnValue = false;
}
// erstellt die aktuelle Zeit
function getTimeStamp() {
	timeStamp = new Date();
	// Setze Ablauf Datum Now = timestamp (1 Jahr)
	timeStamp = new Date(timeStamp.getTime() +1000*60*60*24*365);	
}
// Die kontur von Inputs Rot Färben
function changeBorder(id) {
	var input_array = new Array("geoString", "string", "circle_zip", "circle_km");
	
	for(var i=0; i<input_array.length; i++){
			//alert(input_array[i]+"!="+id);	
			if(input_array[i]!=id) $(input_array[i]).style.borderColor = "#999999";
		}

	var b = $(id).style;
		b.borderColor = "#ff0000";
		
}
// Switch Search Formulare
var searchForms;
var searchBtnLE;
var searchBtnRE;
var searchBtn;
//installiert die Suchen
function installSearchForm(){
	searchForms = $$("div.search_form");//Search Formulare
	searchBtnLE = $$("div.search_btn_l");//Btn Linke Ecke
	searchBtnRE = $$("div.search_btn_r");//Btn Rechte Ecke
	searchBtn	= $$("div.search_btn");//Such Btn
	
	for(var i=0;i<searchForms.length;i++){
		searchBtn[i].onclick = function(){switchToSearch(this);};//onclick event einbinden
	}
		
	searchForms[0].style.display = "block";
	searchBtnLE[0].className = "search_btn_active_l";
	searchBtnRE[0].className = "search_btn_active_r"
	searchBtn[0].className = "search_btn_active";
}
//handelt die Suchen
function switchToSearch(el){
	for(var i=0;i<searchForms.length;i++){
		searchForms[i].style.display = "none";
		searchBtnLE[i].className = "search_btn_l";
		searchBtnRE[i].className = "search_btn_r"
		searchBtn[i].className = "search_btn";
		//Index für aktiven Reiter bestimmen
		if(searchBtn[i].title == el.title) var index = i;
	}

	searchForms[index].style.display = "block";
	searchBtnLE[index].className = "search_btn_active_l";
	searchBtnRE[index].className = "search_btn_active_r"
	searchBtn[index].className = "search_btn_active";
}

// ändert die Ansicht
function switchOpinion(){
	var titles = new Array("zur Kartenansicht wechseln","zur Listenansicht wechseln");
	
	var art = $$("div.opinion");//map und list ins array fügen
	for(var i=0;i<art.length;i++){
		var oid = art[i].id;
		//ausgeblendete anzeigen
		if($(oid).style.display != "block"){
//			alert(oid+" Block!");
			$(oid).style.display = "block";
		//vorher aktive ansicht merken und btn erstellen dann ausblenden 
		} else {
//			alert(oid+" None!");
			var opinion = oid;
			var title 	= titles[i];
			
			$(oid).style.display = "none";
			$("PanelOpinion").innerHTML = "<img src=\""+BTN_URL+"/panel/"+opinion+".gif\" class=\"img_btn\" onClick=\"switchOpinion()\" title=\""+title+"\" />";
		}
	}

	if($("listEntries").innerHTML==""){
		changeCat($("listDD").options[$("listDD").selectedIndex].value);
	} 
	map.checkResize();//fr die Kartenansicht
}//fehler im ie6 Oo

var orderBtns = [];
//Installiert die Order Btns
function installOrderBtns(){
	orderBtns = $$("a.sort_btn");//Order Btns
	for(var i=0;i<orderBtns.length;i++){
		orderBtns[i].onclick = function(){changeOrder(this);};//onclick event einbinden
	}
}

// Hide'n'Show die SideBar
function hideNshowBar() {
	if($('ApiBox').style.display == "none") {
		var type = "block";
		var btn  = "hide";
	} else {
		var type = "none";
		var btn  = "show";
	}
	
	$('hs_btn').src					= BTN_URL+"/"+btn+"_bar.gif";
	$('ApiBox').style.display 		= type;
	$('ApiInfoBox').style.display 	= type;
	//Resize Checker
	var p = map.getCenter();
		map.checkResize();
		map.panTo(p)
}
// vom gespeichert punkt
function panToHome(){
	map.returnToSavedPosition();
}
//####################
var onControl;
var closeControl = false;

function CatControl() {}
//als GControl definieren	
CatControl.prototype = new GControl();
//Inhalt vorbereiten
CatControl.prototype.initialize = function(map) {
	var mapContainer = document.createElement("div");//grosser control container
		mapContainer.setAttribute("id", "mapContainer" , 1);
		
	var mapContainerBtn = document.createElement("div");//Suchergebniss Button
		mapContainer.appendChild(mapContainerBtn);
		mapContainerBtn.setAttribute("id", "mapBtn" , 1);		
		mapContainerBtn.setAttribute((document.all?"className":"class"), "mapContainerBtn" , 1);
		
	var mapContainerInsetBtn = document.createElement("div");
		mapContainerBtn.appendChild(mapContainerInsetBtn);
		mapContainerInsetBtn.setAttribute("id", "mapInsetBtn" , 1);
		mapContainerInsetBtn.setAttribute((document.all?"className":"class"), "mapContainerInsetBtn" , 1);
		mapContainerInsetBtn.innerHTML = "Liste";
		
	var mapContainerInsetBtnImg = document.createElement("div");
		mapContainerBtn.appendChild(mapContainerInsetBtnImg);
		mapContainerInsetBtnImg.setAttribute("id", "mapBtnImg" , 1);
		
	var mapContainerContent = document.createElement("div");//content container
		mapContainer.appendChild(mapContainerContent);
		//mapContainer.appendChild(document.createTextNode("Kategorien:"));
		mapContainerContent.setAttribute("id", "mapContainerContent" , 1);
		mapContainerContent.setAttribute((document.all?"className":"class"), "mapContainerAlpha" , 1);
	
	// Eintrag Divs
	var mapRouteContainer = document.createElement("div");
		mapContainerContent.appendChild(mapRouteContainer);
		mapRouteContainer.setAttribute("id", "mapRouteContainer" , 1);
		
	var mapRouteHeader = document.createElement("div");
		mapRouteContainer.appendChild(mapRouteHeader);
		mapRouteHeader.setAttribute("id", "mapRouteHeader" , 1);		

	var mapRoute = document.createElement("div");
		mapRouteContainer.appendChild(mapRoute);
		mapRoute.setAttribute("id", "mapRoute" , 1);
	
	var mapList = document.createElement("div");
		mapContainerContent.appendChild(mapList);
		mapList.setAttribute("id", "mapList" , 1);
		
	//Event Listener
	GEvent.addDomListener(mapContainerBtn, "click", function() {
		hideContentBar("click");
	});

	GEvent.addDomListener(mapContainerContent, "mouseover", function() {
		onControl = true;
		mapContainerContent.className = "";
		map.disableScrollWheelZoom();
	});

	GEvent.addDomListener(mapContainerContent, "mouseout", function() {
		onControl = false;
		window.setTimeout("setAlpha();",900);
	});

	map.getContainer().appendChild(mapContainer);
return mapContainer;
}

function hideContentBar(action){
	
	if(action == "click"){
		if(closeControl == true){
			closeControl = false;
		} else {
			closeControl = true;
		}
	}
	
	if($("mapContainerContent").style.display == "none" && closeControl == false){
		$("mapBtn_img").src = BTN_URL+"/mapBtn_close.gif";
		$("mapContainerContent").style.display = "block";
		$("mapBtn").className = "mapContainerBtn";
		$("mapInsetBtn").className = "mapContainerInsetBtn";
	} else {
		$("mapBtn_img").src = BTN_URL+"/mapBtn_show.gif";
		$("mapContainerContent").style.display = "none";
		$("mapBtn").className = "mapContainerBtnHide";
		$("mapInsetBtn").className = "mapContainerInsetBtnHide";
	}
}
//Control installieren
CatControl.prototype.getDefaultPosition = function() {
	return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 7));//rechts und oben
}
//setzt die Übersicht auf transparent
function setAlpha(){
	if(onControl == false){
		$('mapContainerContent').className= "mapContainerAlpha";
		map.enableScrollWheelZoom();
	}
}

//####################
// Div Layer Ergebniss Liste vorinstallieren - Start ~~~~~~~~~~~~~~~~~~
function createCatListbar(id, title, text, nums, name) {
	var	list_html ='<div class="ListHeader" onclick="handleList(\''+id+'\')" id="catheader_'+id+'" style="background-image:url('+global_gfx+'catpics/'+name+'.png);">';
		list_html+='<input type="checkbox" id="CheckBox_'+id+'" onclick="boxclick(this,'+id+')" class="ListCheckbox" checked="checked">&nbsp;';
		list_html+='<font title="'+nums+' Eintr&auml;ge">';
		list_html+='<img src="'+global_gfx+'btn/control/list_plus.gif" border=0 id="mapBtn_'+id+'" class="ListBtn">&nbsp;'+title+' ('+nums+')';
		list_html+='</font></div><div id=mapList_'+id+' class="ListBox" style="display:none;"></div>';
	
	$("mapList").innerHTML += list_html;//Übersicht Karte
	
	var entrie = document.createElement("option");
		entrie.setAttribute("value", id);
		entrie.innerHTML = title;
		$("listDD").appendChild(entrie);	
	//$("listDD").innerHTML += "<option value="+id+">"+title+"</option>";//Eintrag ins Listen DropDown
}
// MyPlaces Liste
function createMpListbar(nums) {
	var	list_html ='<div id="MyPlacesBox"><div class="MyPlacesListHeader" id="catheader_mp" onclick="handleList(\'mp\')">';
		list_html+='<input type="checkbox" id="CheckBox_mp" onclick="boxclick(this,\'mp\')" class="ListCheckbox" checked="checked">&nbsp;';
		list_html+='<font title="'+nums+' Eintr&auml;ge">';
		list_html+='<img src="'+global_gfx+'btn/control/list_plus.gif" border=0 id="mapBtn_mp" class="ListBtn">&nbsp;MyPlaces ('+nums+')';
		list_html+='</font></div><div id=mapList_mp class="ListBox" style="display:none;"></div></div>';
		
	$("mapList").innerHTML += list_html;
}
// ClassName function
document.getElementsByClassName = function (className){
	var elements = new Array ();
	var children = document.getElementsByTagName( "*" );
	for ( var a = 0; a < children.length; a++ ){
		if( children[a].className == className ) elements.push ( children[a] );
	}
	//Aktiven Marker anzeigen
return elements;
}
// Listen Elemente
document.handleListElement = function (id){
	var className = "List";
	//var elements = new Array ();
	var children = document.getElementsByTagName( "*" );
	for ( var a = 0; a < children.length; a++ ){
		if( children[a].className == className || children[a].className == className+"Vid" || children[a].tmpClassName ){
			//elements.push ( children[a] );
			//children[a].style.backgroundColor = "#ffffff";//zurück setzen deaktiviert aber die classe Oo
			if(children[a].tmpClassName) {
				children[a].className = children[a].tmpClassName;
			} else {
				children[a].className = children[a].className;
			}
		}
	}
	// Keinen aktiven marker
	if(!id){
		return false;	
	}
	window.setTimeout("activateElement("+id+")",200);
}
// händelt die Überischts Liste
function handleList(id,i) {
	//zeigt die Kategorie an
	if($("mapList_"+id).style.display == "none" && $("CheckBox_"+id).checked == true){
		$("mapList_"+id).style.display = "block";
		$("mapBtn_"+id).src = global_gfx+"btn/control/list_minus.gif";
	}
	//wenn die Kategorie schon offen is tue nix
	else if($("mapList_"+id).style.display == "block" && i){
		return true;
	}
	//versteckt die gedrückte liste wieder
	else {
		$("mapList_"+id).style.display = "none";
		$("mapBtn_"+id).src = global_gfx+"btn/control/list_plus.gif";
	}
		
	//blendet alle aus die nicht gewählt wurden
		var children  = document.getElementsByTagName( "*" );
		var className = "ListBox";
		for ( var a = 0; a < children.length; a++ ){
			if( children[a].className == className && children[a].id != "mapList_"+id){
				children[a].style.display = "none";
			}
		}
		
		var headers = document.getElementsByClassName("ListBtn");
		for ( var a = 0; a < headers.length; a++ ){
			if(headers[a].id != "mapBtn_"+id){
				$(headers[a].id).src = global_gfx+"btn/control/list_plus.gif";
			}
		}
		//Aktiven Liste anzeigen
		if(id&&i){
			//$("List"+id).style.display = "block";
			document.handleListElement(i);
		}
}
function activateElement(id){
	//Aktiven Marker anzeigen
	if(!$("marker_"+id).tmpClassName){
		$("marker_"+id).tmpClassName = $("marker_"+id).className;//speichert die Klasse in dem Temp
	}
	if($("marker_"+id).className == "ListVid"){
		$("marker_"+id).className = "ListActiveVid";//zeigt geklickten Video marker an
	} else {
		$("marker_"+id).className = "ListActive";//zeigt normalen geklickten Marker an
	}
	
	$("marker_"+id).scrollIntoView(false);
}
// Div Layer Ergebniss Liste vorinstallieren - Ende ~~~~~~~~~~~~~~~~~~~

// Icons - Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~	
function createIcon(iconCat, vid) {
	var baseIcon = new GIcon();
		baseIcon.image = global_gfx+"gmapmarker/red.png";
		baseIcon.shadow = global_gfx+"gmapmarker/shadow.png";
		baseIcon.iconSize = new GSize(25, 25);
		baseIcon.shadowSize = new GSize(25, 25);
		//mittel punkt des icons
		baseIcon.iconAnchor = new GPoint(12, 25);
		//wo beim icon die blase anfangen soll (left,top) in pixel
		baseIcon.infoWindowAnchor = new GPoint(15, 1);

	if(iconCat == "portal"){
		var icon = new GIcon(baseIcon);
			icon.image = global_gfx+"gmapmarker/"+ iconCat +".png";
			icon.shadow = global_gfx+"gmapmarker/shadow_portal.png";
			icon.iconSize = new GSize(35, 35);
			icon.shadowSize = new GSize(35, 35);
			icon.infoWindowAnchor = new GPoint(22, 8);
		icons[iconCat] = icon;
	} else {
		if(vid == "none") {
			var icon = new GIcon(baseIcon);
				icon.image = global_gfx+"gmapmarker/"+ iconCat +".png";
				icon.shadow = global_gfx+"gmapmarker/shadow.png";
			icons[iconCat] = icon;
		} 
		else {
			var icon = new GIcon(baseIcon);
				icon.image = global_gfx+"gmapmarker/"+ iconCat +"_video.png";
				icon.shadow = global_gfx+"gmapmarker/shadow_video.png";
				icon.iconSize = new GSize(35, 35);
				icon.shadowSize = new GSize(35, 35);
				icon.infoWindowAnchor = new GPoint(22, 8);
			icons[iconCat] = icon;
		}
	}
	return icons[iconCat];
}
// Icons - Ende ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Karten Functionen #1 - Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// == shows all markers of a particular category, and ensures the checkbox is checked ==
function show(id) {
	for (var i=0; i<gmarkers.length; i++) {
		if (gmarkers[i].mycategory == id) {
			gmarkers[i].show();
		}
	}
// == check the checkbox ==
	$("CheckBox_"+id).checked = true;
}
// == hides all markers of a particular category, and ensures the checkbox is cleared ==
function hide(id) {
	for (var i=0; i<gmarkers.length; i++) {
		if (gmarkers[i].mycategory == id) {
			gmarkers[i].hide();
		}
	}
// == clear the checkbox ==
//	$("CheckBox"+id).checked = false;
	handleList(id);
// == close the info window, in case its open on a marker that we just hid
	map.closeInfoWindow();
}
// == a checkbox has been clicked ==
function boxclick(box,id) {
	if (box.checked) {
		show(id);
	} else {
		hide(id);
	}
}
// == öffnet Tooltip ==
function myclick(i) {
	//GEvent.trigger(gmarkers[i],"click");
	document.handleListElement(i);//markiert den marker in der liste
	Gmarkers[i].openInfoWindowHtml(html[i]);
	setMarkerVisits(Gmarkers[i].id);
	hideContentBar();
}
// == zeigt Namen bei icon ==   
function mymouseover(i) {
	showMy_tooltip(Gmarkers[i])
}
// == löscht den Namen wieder ==
function mymouseout(i) {
	my_tooltip.style.visibility="hidden";
}
// == erstellt das Namentooltip ==
function showMy_tooltip(marker) {
    my_tooltip.innerHTML = marker.my_tooltip;
	var point=map.getCurrentMapType().getProjection().fromLatLngToPixel(map.fromDivPixelToLatLng(new GPoint(0,0),true),map.getZoom());
	var offset=map.getCurrentMapType().getProjection().fromLatLngToPixel(marker.getPoint(),map.getZoom());
	var anchor=marker.getIcon().iconAnchor;
	var width=marker.getIcon().iconSize.width;
	var height=my_tooltip.clientHeight;
	var pos = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(offset.x - point.x - anchor.x + width, offset.y - point.y -anchor.y -height)); 
	pos.apply(my_tooltip);
	my_tooltip.style.visibility="visible";
}	
// == refreshed die Statusbar ==
function updateStatusBar() {
	var center = map.getCenter();
	var zoom = map.getZoom();
	var oCoords = $("coords");
	oCoords.innerHTML = 'Mapinfos: (' + center.y.toFixed(6) + ',' + center.x.toFixed(6) + ') Zoomstufe: ' + zoom;
}
// == MyPlaces ==

// == MyHome ==
// zeigt den Btn an
function showMhBtn(){
	$('PanelMyHome').style.visibility = "visible";
	panToMyHome();
}
// führt die Map zu myHome
function panToMyHome(){
	map.panTo(myHomeMarker.getPoint());
}
// speichert MyHome Cookie #1
function saveMyHome(){
	// Daten Parser
	if(!myHomeID){
		getMyHomeID();// erzeugt cookies und gibt die id zurück
	} else {
		saveMyHomeData(myHomeID, markerLat, markerLng);
	}
}
// läd die Daten
function getMyHomeData(id){
	/*if(!modul_path){
		window.setTimeout("getMyHomeData("+id+")", 1000);
		return false;
	}*/
	var str_post = 'myHomeID=' + id;
	new Ajax.Request(gmap_path+'js/ajax/myHome.php?art=getData',
		{
			method:'post',
			postBody: str_post,
			onSuccess: function(t){
				var myHomeData	= t.responseText;
				var myHomeArray	= myHomeData.split("#");
					//füllt die Variablen
					markerLat	= myHomeArray[0];
					markerLng	= myHomeArray[1];
					markerName	= decodeURI(myHomeArray[2]);
					markerText	= decodeURI(myHomeArray[3]);
					//erzeugt MyHome
					fillMHPanel("Aktuelle MH Daten: Zoom "+markerLat+"  Laenge und Breitengrad "+markerLng+" # "+markerName);
					placeMyHome();
			},
			onFailure: function(t){
				fillMHPanel(t.responseText);
			}
	});
}
// speichert MyHome Daten
function saveMyHomeData(id, lat, lng) {
	//wenn noch keine id vorhanden ist
	if(!id) return false;
	
	fillMHPanel(id+" "+lat+" "+lng);
	var str_post = 'myHomeID=' + id;
		str_post += '&lat=' + lat;
		str_post += '&lng=' + lng;
	new Ajax.Request(gmap_path+'js/ajax/myHome.php?art=saveData',
		{
			method:'post',
			postBody: str_post,
			onSuccess: function(t){
				if(t.responseText == "Daten wurden gespeichert!") {
					fillMHPanel(t.responseText);
					getMyHomeData(id);//hohlt die gespeicherten Daten
				} else fillMHPanel(t.responseText);
			},
			onFailure: function(t){
				fillMHPanel(t.responseText);
			}
	});
}
// setzt MyHome auf die Karte
function placeMyHome(){
	if(myHomeMarker) {
		map.removeOverlay(myHomeMarker);
		map.removeOverlay(geoMarker)
	}
	else if(geoMarker) {
		map.closeInfoWindow();
		map.removeOverlay(geoMarker);
	}
	fillMHPanel("MyHome wird jetzt generiert");
	//MyHome
	var myHomePoint	= new GLatLng(markerLat,markerLng);
	var myHomeIcon	= createIcon("myhome", "none");
		mh_unlocked = false;
		mh_tpl 		= getNorMyHomeTpl(markerLat, markerLng, markerName, "myhome", markerText);

	myHomeMarker 	= new GMarker(myHomePoint,{icon:myHomeIcon,title:markerName,draggable:true});
	myHomeMarker.cat= "myhome";
	myHomeMarker.disableDragging();
	// Marker Listener
	GEvent.addListener(myHomeMarker, "click", function() {
		myHomeMarker.openInfoWindowHtml('<div id="myHome">'+mh_tpl+'</div>');										   
	});
	
	GEvent.addListener(myHomeMarker, "dragstart", function() {
		map.closeInfoWindow();
	});
	GEvent.addListener(myHomeMarker, "dragend", function() {
		var point = myHomeMarker.getPoint();
			markerLat = point.y.toFixed(6);
			markerLng = point.x.toFixed(6);
	});
	fillMHPanel("MyHome wird jetzt angezeigt");
	showMhBtn();
	map.addOverlay(myHomeMarker);
}
// löscht MyHome
function deleteMyHome(){
	//fillMHPanel("MyHomeId ist "+myHomeID);
	Check = confirm("Wirklich MyHome entfernen?");
	if (Check == true) {
		//cookie deaktiveren aber nicht löschen
  		getTimeStamp();	
		document.cookie = 'myhomeDEID='+myHomeID+'; expires='+timeStamp.toGMTString()+';';
		document.cookie = 'myhomeID=gelöscht; expires=Thu, 01-Jan-70 00:00:01 GMT;';
		$('PanelMyHome').style.visibility = "hidden";
		map.closeInfoWindow();// schließt overlay
		map.removeOverlay(myHomeMarker);// entfernt myHome
		map.returnToSavedPosition();// zum ursprung zurück
	}
}
// statusFenster für MyHome
function fillMHPanel(content){
	//Errors oder Successes in die Statusbar
	$('MyHomePanel').innerHTML = content;
}
// Karten Functionen #1 - Ende ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Marker - Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Eintrag für die Karte
function createMarker(i,data,art){
	//Variablen
	var lat = parseFloat(data.getAttribute("lat"));//Breitengrad
	var lng = parseFloat(data.getAttribute("lng"));//Längengrad
	var point = new GLatLng(lat,lng);//Zusammengesetzter Punkt
	var search_point = "@"+lat+","+lng;//Suchpunkt für Routenplaner
	var markerid = data.getAttribute("id");//Id aus der DB
	var title = data.getAttribute("title");//Titel
	var stars = data.getAttribute("stars");//Hotel Sterne
	var pic = data.getAttribute("pic");//Bild
	var pretel = data.getAttribute("pretel");//Telefon Vorwahl
	var tel = data.getAttribute("tel");//Telefon
	var email = data.getAttribute("email");//Email
	var hp = data.getAttribute("hp");//Homepage
	var cat = data.getAttribute("cat");//Kategorie Name
	var iconNR = data.getAttribute("iconid");//Kategorie ID
	var iconID = data.getAttribute("icon");//Kategorie Icon preafix
	var text = data.getAttribute("text");//Beschreibung
	var street = data.getAttribute("street");//Straße
	var city = data.getAttribute("city");//Ort
	var zip = data.getAttribute("zip");//Postleitzahl
	var vidPath = data.getAttribute("video");//Video Path für Flashplayer
	var copyright = data.getAttribute("copyright");//Copyright Link
	var copyrightUrl = data.getAttribute("copyrighturl");//Copyright Url
	// -> wird nich benutzt nur bei Premiere
	var prefax = data.getAttribute("prefax");//Fax Vorwahl
	var fax = data.getAttribute("fax");//Fax
	var obhp = data.getAttribute("obhp");//Buchungsurl
	var chainLogo = data.getAttribute("chainlogo");//Kettenlogo
    var icon = createIcon(iconID, vidPath);
	var marker = new GMarker(point, icon);
// === Store the category and name info as a marker properties ===
	marker.mycategory = iconNR;                                
	marker.myname = title;
	marker.id = markerid;
	marker.category = art;
	
// === Eintrag in die Liste schieben = Start ============================================
	if(i < 9) var nr = "0"+(i+1);
	else var nr = i+1;
	
	var arr_id = i+1;
	
	if(vidPath == "none") var classList = "List";
	else var classList = "ListVid";

	if(art == "pp"){
		ListMarkerID = $("mapList_"+iconNR);//fügt den eintrag in die passende Kategorie
	//MyPlace
	}else if(art == "mp"){
		ListMarkerID = $("mapList_mp");//fügt den Myplace in die Box
	}
		//Eintrag in die Mapansichts Liste
		ListMarkerID.innerHTML +='<div onClick="myclick('+arr_id+')" onmouseover="mymouseover('+arr_id+')" onmouseout="mymouseout()" class="'+classList+'" id="marker_'+arr_id+'"><b>'+nr+'.</b> '+title+'</div>';
		//Eintrag für die Listenansicht weiter unten!!!
// === Eintrag in die Liste schieben = Ende =============================================
	
// === Tooltip Inhalt = Start ===========================================================
	var fnc_title	= escape(title);//.replace(/'/g, "\´");
	var tpl 		= new Array();
		tpl.title 	= nr+'. '+title;//Title im tooltip
		tpl.text	= createText(text,markerid);//Beschreibungs text
		tpl.cat 	= cat;//Kategorie String z.b. Hotel
		tpl.catid 	= iconNR;//Kategorie ID
		tpl.catname	= iconID;//Kategorie ID
		tpl.stars 	= createStars(stars);//Hotelsterne
		tpl.logo 	= getLogo(pic,iconID);//Picture
		tpl.tel 	= getTel(pretel+'_'+tel, fnc_title);//Telfon Btn
		tpl.email 	= getEmail(email, fnc_title);//Email Btn
		tpl.hp	 	= getHomepage(hp, fnc_title);//Homepage Btn
		tpl.db	 	= getDB(street, zip, city, fnc_title);//DeutscheBahn Btn
		tpl.route 	= getRoute(search_point, fnc_title);//RoutenPlaner Btn
		tpl.ob		= getBooking(obhp);//OnlineBuchen Btn
		tpl.copy	= getCopyright(copyright, copyrightUrl);//Eintrag Copyright
		tpl.street	= street;//Straße
		tpl.zip		= zip;//Postleitzahl
		tpl.city	= city;//Ort
		tpl.telnr	= pretel+' '+tel;//Telefon String
		tpl.faxnr	= prefax+' '+fax//Fax String
		tpl.vid_url = vidPath;//Video Pfad
	
	// #### Templateauswahl ####
	//normales Template
	if(vidPath == "none") {
		//variabke für css
		var tt_typ = "norm_tt";
	 	//normales Template
		if(chainLogo=="none") {
		 var tt_tpl = getNorTpl(tpl);
		//Template mit Ketten Logo
		} else {
			tpl.chainlogo = getChainLogo(chainLogo, iconID);
		var tt_tpl = getNorTplwithChainLogo(tpl);
		}
	} else {
		//variabke für css
		var tt_typ = "vid_tt";
	 	//normales VideoTemplate
		if(chainLogo=="none") {
		 var tt_tpl = getVidTpl(tpl);
		//Videotemplate mit Ketten Logo
		} else {
		 	tpl.chainlogo = getChainLogo(chainLogo, iconID);
		var tt_tpl = getVidTplwithChainLogo(tpl);
		}
	}
	//Eintrag für die Listenansicht
	//$("ListList_"+iconNR).innerHTML += '<div id="marker_'+i+'">'+tt_tpl+'</div>';
	//UmrissDiv für das Tooltip
	var tpl = '<div class="gmapTooltip" id="'+tt_typ+'">'+tt_tpl+'</div>';
	
// === Namen Tooltip ==========================
	marker.my_tooltip = '<div class="cat_tooltip">'+title+'</div>';	
// === Tooltip Inhalt = Ende ==================
		
// === die Marker Listener ====================
	GEvent.addListener(marker,"click", function() {
		document.handleListElement();
		marker.openInfoWindowHtml(tpl);//,{maxUrl:"marker1.htm"}öffnet das Tooltip
		handleList(iconNR, arr_id);//zeigt die Kategorie Liste
		document.handleListElement(arr_id);//markiert den marker in der liste
		setMarkerVisits(markerid);//erhöht den Visitscounter
		hideContentBar(true);//blendet die content liste aus
	});   
	GEvent.addListener(marker,"infowindowclose", function() {
		document.handleListElement();//setzt die Liste zurück
		hideContentBar();//blendet die content liste wieder ein
	});
	GEvent.addListener(marker,"mouseover", function() {
		showMy_tooltip(marker);
	});
	GEvent.addListener(marker,"mouseout", function() {
		my_tooltip.style.visibility="hidden";
	});
	
// === Marker Arrays ============
	gmarkers.push(marker);
	Gmarkers[arr_id] = marker;
	html[arr_id] = tpl;
	
// === Ende der Function ============
	return marker;
}
// Anderes Portal
var gportale = new Array();
function createOtherPortal(i,data){
	//Variablen
	var id 		= data.getAttribute("id");//Id aus der DB
	var lat 	= parseFloat(data.getAttribute("lat"));//Breitengrad
	var lng 	= parseFloat(data.getAttribute("lng"));//Längengrad
	var point	= new GLatLng(lat,lng);//Zusammengesetzter Punkt
	var zoom 	= parseInt(data.getAttribute("zoom"));//Zoomstufe	

	var title 	= data.getAttribute("title");//Titel
    var icon 	= createIcon("portal");
	var marker 	= new GMarker(point, {icon:icon, zIndexProcess:setZindex});
                             
	marker.myname = title;
	marker.id = id;
	
// === Tooltip Inhalt = Start ===========================================================
	marker.my_tooltip = '<div class="cat_tooltip">Eintr&auml;ge aus der Umgebung von '+title+'</div>';	
// === Tooltip Inhalt = Ende ==================

// === die Marker Listener ====================
	GEvent.addListener(marker,"click", function() {
		//var changePortalEntries = confirm("Eintr\xE4ge aus der Umgebung von "+title+" wirklich anzeigen?");
			//if(changePortalEntries==true){
				my_tooltip.style.visibility="hidden";
				map.setCenter(point,zoom);
				map.savePosition();
				getGmapXml(xml_path+"?portalid="+id);
				list_portalid = id;
			//}
	});   
	GEvent.addListener(marker,"mouseover", function() {
		showMy_tooltip(marker);
	});
	GEvent.addListener(marker,"mouseout", function() {
		my_tooltip.style.visibility="hidden";
	});
	
// === Marker Arrays ============
	gportale.push(marker);

// === Ende der Function ============
	return marker;
}
// 
function setZindex(marker,b) {
return 1;
}
// Marker - Ende ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Xml Setup ~ Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Karten XML
var xml_path;
function getGmapXml(path) {
//	prompt("Xml Pfad!!!", path);
	//Page Loader
	showAD();
	//Alle Marker entfernen
	
	if(Gmarkers) {
		for(var i=1;i<Gmarkers.length;i++){
			map.removeOverlay(Gmarkers[i]);
		}
	}
	//Alle PortalMarker entfernen
	if(gportale){
		for(var i=0;i<gportale.length;i++){
			map.removeOverlay(gportale[i]);
		}
	}
	
GDownloadUrl(path, function(doc) {
	
	var xmlDoc = new GXml.parse(doc);

// === Erstelle Kategorien = Start =====================
	var	cats = xmlDoc.documentElement.getElementsByTagName("cat");

	$("mapList").innerHTML = "";//Übersichtsliste der Map
	$("listEntries").innerHTML = "";//MarkerListe von der Listenansicht
	$("listDD").innerHTML = "";//Übersichtsliste der Liste
	
	if(cats.length != 0) { 
		
		for (var i=0; i<cats.length; i++) {	
			var cat = createCatListbar(
						cats[i].getAttribute("id"),
            			cats[i].getAttribute("title"),
						cats[i].getAttribute("text"),
						cats[i].getAttribute("nums"),
						cats[i].getAttribute("name")
					  );
					 
			show(cats[i].getAttribute("id"));	 
		}
	}
// === Erstelle Kategorien = Ende ======================
// === Erstelle Marker = Start =====================
	var pps = xmlDoc.documentElement.getElementsByTagName("marker");
          
	for (var i=0; i<pps.length; i++) {
			pp = createMarker(i,pps[i],"pp");
			pp.cat = "entire";
		map.addOverlay(pp);
			//Hier die Listen Sachen erzeugen....
	}
	
	ppi = i;
	// Myplaces 
	var mps = xmlDoc.documentElement.getElementsByTagName("myplace");
	if(mps.length>0) {
		createMpListbar(mps.length);//MpListe installieren
		for (var i=0; i<mps.length; i++,ppi++) {
				mp = createMarker(ppi,mps[i],"mp");
				mp.cat = "myplace";
			map.addOverlay(mp);
		}
	}
// === Erstelle Marker = Ende ======================
// === Erstellte Listen an Div Layer Liste senden = Start =====================
	var markernum = xmlDoc.documentElement.getElementsByTagName("nums");
	var	totalnums = markernum[0].getAttribute("count");
		
	var result_div;
	
		if(totalnums > 1000) result_div += " Anzeige max. 1000 Einträge.";
		else if(totalnums > 1) result_div = totalnums+" Eintr&auml;ge wurden gefunden.";
		else if(totalnums == 1) result_div = "Es wurde 1 Eintrag gefunden.";
		else result_div = "Es wurden keine Eintr&auml;ge gefunden.";
	
	$("result").innerHTML = result_div;
// === Erstellte Listen an Div Layer Liste senden = Ende ======================
// === Erstelle Portale = Start =====================
	var	portale = xmlDoc.documentElement.getElementsByTagName("portal");

	//$("markerList").innerHTML = "";
	
	if(portale.length != 0) { 

		for (var i=0; i<portale.length; i++) {	
			var portal = createOtherPortal(i, portale[i]);
				portal.cat = "portal";
			map.addOverlay(portal);
		}
	}
// === Erstelle Portale = Ende ======================	
	// switcht zur gespeicherten Position
	map.returnToSavedPosition();
	// werbe layer wieder ausblenden
	window.setTimeout("closeOverlay();",200);
	});

}

//	Listen XML
var xml_list_path;
var xml_list_data;
var list_cat;
var list_portalid;
var list_order;
var list_sort;
var last_path;
var list_len;

// Kategorie ändern
function changeCat(id){
	list_cat = id;
	getListXml();
}
// Sortierung ändern
function changeOrder(el){
	//alle Buttons zurück setzen
	for(var i=0;i<orderBtns.length;i++){
		orderBtns[i].style.fontWeight = "normal";
		//den Inhalt in den Temp speichern
		if(!orderBtns[i].tmpInner){
			orderBtns[i].tmpInner = orderBtns[i].innerHTML;
		//wenn schon gespeichert dann nutzte den Originalen Inhalt
		} else {
			orderBtns[i].innerHTML = orderBtns[i].tmpInner;
		}
	}
	
	//wenn die gleiche Sortierart gewählt wurde dann switche zwischen Abwärts DESC und Aufwärts ASC 
	if(list_order == el.name && list_sort != "desc"){
		list_sort   = "desc";	
		var sortStr = "&and;";
	//standart Sortierung Aufwärts
	} else {
		list_order = el.name;
		list_sort  = "asc";
		var sortStr = "&or;";
	}
		
		//aktvien Btn Dick machen und hinten Aufwärts oder Abwärts anfügen
	el.style.fontWeight = "bold";
	el.innerHTML = el.tmpInner + "&nbsp;"+sortStr,
	//Liste neuladen
	getListXml();
}

function createListElement(data){
	//Variablen
	var lat 		= parseFloat(data.getAttribute("lat"));//Breitengrad
	var lng 		= parseFloat(data.getAttribute("lng"));//Längengrad
	var searchPoint	= "@"+lat+","+lng;//Suchpunkt für Routenplaner
	var dbID 		= data.getAttribute("id");//Id aus der DB
	var title 		= data.getAttribute("title");//Titel
	var stars 		= data.getAttribute("stars");//Hotel Sterne
	var pic 		= data.getAttribute("pic");//Bild
	var preTel 		= data.getAttribute("pretel");//Telefon Vorwahl
	var tel 		= data.getAttribute("tel");//Telefon
	var email 		= data.getAttribute("email");//Email
	var hp 			= data.getAttribute("hp");//Homepage
	var catName		= data.getAttribute("cat");//Kategorie Name
	var catID 		= data.getAttribute("iconid");//Kategorie ID
	var catIcon		= data.getAttribute("icon");//Kategorie Icon preafix
	var text 		= data.getAttribute("text");//Beschreibung
	var street 		= data.getAttribute("street");//Straße
	var city 		= data.getAttribute("city");//Ort
	var zip 		= data.getAttribute("zip");//Postleitzahl
	var vidUrl 		= data.getAttribute("video");//Video Path für Flashplayer
	var vidPicUrl	= data.getAttribute("video_pic");//Video Path für Flashplayer
	var copyright	= data.getAttribute("copyright");//Copyright Link
	var copyrightUrl = data.getAttribute("copyrighturl");//Copyright Url
	// -> wird nich benutzt nur bei Premiere
	var preFax 		= data.getAttribute("prefax");//Fax Vorwahl
	var fax 		= data.getAttribute("fax");//Fax
	var obhp 		= data.getAttribute("obhp");//Buchungsurl
	var chainLogo 	= data.getAttribute("chainlogo");//Kettenlogo
	//Template
	var fncTitle	= escape(title);//.replace(/'/g, "\´");
	var tpl 		= new Array();
		tpl.catId 	= catID;//Kategorie ID
		tpl.copy	= getCopyright(copyright, copyrightUrl);//Eintrag Copyright
		tpl.telnr	= preTel+' '+tel;//Telefon String
		tpl.faxnr	= preFax+' '+fax//Fax String
		
	//Template wahl
	if(vidUrl != "none"){
		var tpl = "list_video";
	} else {
		var tpl = "list_normal";
	}

	//Ausgabe	
	var myTpl	= new Template(loadetTpls[tpl]);

	// our data to be formatted by the template
	var show = {
			id:dbID,
			title:title,
			stars: obj_gmapTpl.createStars(stars),
			pic: obj_gmapTpl.getPic(pic,catIcon), 
			catName:catName, 
			text: obj_gmapTpl.createText(text,dbID), 
			street:street, 
			zip:zip, 
			city:city, 
			telBtn: obj_gmapTpl.getTel(preTel+'_'+tel, fncTitle), 
			emailBtn: obj_gmapTpl.getEmail(email, fncTitle), 
			hpBtn: obj_gmapTpl.getHomepage(hp, fncTitle), 
			dbBtn: obj_gmapTpl.getDB(street, zip, city, fncTitle), 
			routeBtn: obj_gmapTpl.getRoute(searchPoint, fncTitle), 
			obBtn: obj_gmapTpl.getBooking(obhp),
			vidUrl:vidUrl,
			vidPic: obj_gmapTpl.getVidPic(vidPicUrl,dbID),
			ovlVidPic: obj_gmapTpl.getOvlVidPic(vidUrl)
	};

	// let's format our data
	$("listEntries").innerHTML += myTpl.evaluate(show);
}

function createListArray(){
//	alert(xml_list_data.length);
	for (var i=0; i<xml_list_data.length; i++) {
			createListElement(xml_list_data[i]);
		//createListElement(i,les[i]);
	}
}

function getListXml() {
	var path = "";
		if(list_cat) path += "cat="+list_cat;//Kategorie hinzufügen wenn vorhanden
		if(list_order){
			path += "&order="+list_order;//Ordnung hinzufügen wenn vorhanden
			if(list_sort) path += "&sort="+list_sort;//Sortierung ASC oder DESC
		}
		if(list_portalid) path += "&portalid="+list_portalid;//Wenn anderes Portal gewählt wurde ran hängen
	
		if(path != "") path = xml_list_path+"?"+path;//Pfad für die Xml zusammen setzen
	
	//wenn der vorherige Pfad mit dem jetztigen übereinstimmt passiert nix
	if(path != last_path){
	
		last_path = path;//letzten pfad speichern
	
	//	prompt("Xml Pfad!!!", path);
		
		$("listEntries").innerHTML = "";//alte Einträge löschen
		
		GDownloadUrl(path, function(doc) {
			var xmlDoc 		= GXml.parse(doc);
			xml_list_data 	= xmlDoc.documentElement.getElementsByTagName("marker");
			
			//Lade Templates
			obj_gmapTpl.getTpl("list","list_normal");
			obj_gmapTpl.getTpl("list","list_video");
			
			window.setTimeout("createListArray()", 1000);
			
		// === Erstelle Marker = Ende ======================
		});

	}
}
// Xml Setup ~ Ende ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Umkreissuche - Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function doCircleSearch() {
	$("int").style.visibility = "visible";
	var zip = $("int_input").value;
	var km  = $("int_filter").value;
	
	var bool_send = true;
	
	var bool_array = new Array('int_input', 'int_filter');
	var bool_info = new Array('Plz', '0');
		
	for(var i=0;i<bool_array.length;i++) {
		if($(bool_array[i]).value == bool_info[i]) {
			bool_send = false;
			changeBorder(bool_array[i]);
		}
	}

	if(!bool_send) alert("Bitte die Rot markierten Felder beachten!");

	if(bool_send){
		getGmapXml(xml_path+"?zip="+zip+"&km="+km);
	}
}
// Umkreissuche - Ende ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Stichwortsuche - Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function doStringSearch() {
	$("string").style.visibility = "visible";
	var string = $("string_input").value;
	var filter = $("string_filter").value;
	
	var bool_send = true;
	
	var bool_array = new Array('string_input', 'string_filter');
	var bool_info = new Array('Suchbegriff', 'Filter ausw&auml;hlen');
		
	for(var i=0;i<bool_array.length;i++) {
		if($(bool_array[i]).value == bool_info[i]) {
			bool_send = false;
			changeBorder(bool_array[i]);
		}
	}

	if(!bool_send) alert("Bitte die Rot markierten Felder beachten!");

	if(bool_send){
		getGmapXml(xml_path+"?string="+string+"&filter="+filter);
	}
}
// Stichwortsuche - Ende ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Suche zurücksetzen
function resetSearch(id){
	if(id=="string"){
		$(id+"_input").value = "Suchbegriff";
	}else if(id=="int"){
		$(id+"_input").value = "Plz";
	}
	$(id+"_filter").selectedIndex = 0;
	$(id).style.visibility= "hidden";
	getGmapXml(xml_path);	
}

// Geocoder - Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function doAddressSearch(city) {
	if(city != "") var city = ", "+city;
	else var city = "";
	var search 	= $("geoString").value;
	
	if($("geoString").value == "Plz, Stadt, Strasse + Hausnummer") 
	{
		changeBorder("geoString");
		alert("Bitte das Rot markierte Feld beachten!");
		return false;
	}
	
	// ====== Perform the Geocoding ======        
	geo.getLocations(search+city, function (result)
		{
			if (result.Status.code == G_GEO_SUCCESS) {
			// gibt es mehre Ergebnisse dann Liste erstellen
			if (result.Placemark.length > 1) { 
				$("chooseList").innerHTML = "";
				var fc = document.createElement("option");
					fct = document.createTextNode("Meinten Sie:");
					fc.appendChild(fct);
					$("chooseList").appendChild(fc);
				// Loop through the results
				for (var i=0; i<result.Placemark.length; i++) {
					var p = result.Placemark[i].Point.coordinates;
					var choose = document.createElement("option");
						choose.setAttribute("value", p);
						choose.setAttribute("title", (i+1)+". "+result.Placemark[i].address);
					var chooseTitle = document.createTextNode((i+1)+". "+result.Placemark[i].address);
						choose.appendChild(chooseTitle);
						$("chooseList").appendChild(choose);
					//$("chooseList").appendChild() +='<div onClick="placeMySearch('+p[1]+','+p[0]+')" class="List">+'</div>';
                }
				$("chooseList").style.display = "block";
              }
              // ===== If there was a single marker =====
              else {
				$('chooseList').style.display = "none";
                $("chooseList").innerHTML = "";
                var p = result.Placemark[0].Point.coordinates;
                placeMySearch(p[1],p[0]);
              }
			}
			// ====== Decode the error status ======
            else {
              var reason="Code "+result.Status.code;
              if (reasons[result.Status.code]) {
                reason = reasons[result.Status.code]
              }
			  // ohne Portal Stadt nochmal suchen!!
			  doAddressSearch("");
              //alert('Could not find "'+search+ '" ' + reason);
			  
            }
		});
}
// aus dem choose in das place
function setChoosePlace(point){
	// wenn man z.b. auf meinten Sie drückt...
	if(point == "Meinten Sie:") return false;
	// splitte den string
	var geodata = point.split(",");
	placeMySearch(geodata[1], geodata[0]);
}
// setzte MySearch
function placeMySearch(lat, lng) {
	// löscht den vorherigen MySearch Marker
	if(geoMarker){
		map.removeOverlay(geoMarker);
	}
	// Funktions start
	var geoPoint  = new GLatLng(lat,lng);
	var geoIcon	  = createIcon("mysearch", "none");
	//setze LatLng in die globale Variable
	markerLat = lat;
	markerLng = lng;	
	//
	geoMarker = new GMarker(geoPoint, {icon: geoIcon, draggable: true});
	geoMarker.cat = "geo";
	// Marker Listener
	GEvent.addListener(geoMarker, "dragstart", function() {
		map.closeInfoWindow();
	});
	GEvent.addListener(geoMarker, "dragend", function() {
		var geoPoint = geoMarker.getPoint();
		markerLat = geoPoint.y.toFixed(6);
		markerLng = geoPoint.x.toFixed(6);
		geoMarker.openInfoWindowHtml('<div id="mySearch">'+getNorSearchTpl(geoPoint)+'</div>');
	});

	map.addOverlay(geoMarker);
	map.panTo(geoPoint);
	//map.setCenter(geoPoint, 13);
}
// Wenn Fehler auftreten
function handleCoderErrors(){
	if (geo.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (geo.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (geo.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (geo.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (geo.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
}
// lösche MySearch
function deleteMySearch(){
	map.closeInfoWindow();// schließt overlay
	map.removeOverlay(geoMarker);// entfernt myHome
}
// Geocoder  - Ende ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

// Routenplaner - Start ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var routeStart;
var routeFinish;
// Route löschen
function clearRoute(){
	gdir.clear();
	displayMarkers(true);
	$('mapList').style.display = "block";
	$('mapRouteContainer').style.display = "none";
	map.returnToSavedPosition();
}
// Eingabe an Google senden
function setDirections(fromAddress, toAddress, locale) {
	routeStart 	= unescape(fromAddress);
	routeFinish = unescape(toAddress);
	//alert(routeStart + "    " + routeFinish);
	gdir.load("from: " + routeStart + " to: " + routeFinish, { "locale": locale });
}
// blendet die markers aus
function displayMarkers(bool){
	for (var i=0; i<gmarkers.length; i++) {
		if (bool == false) {
			if(gmarkers[i].category == "pp"){
				gmarkers[i].hide();
			}
		} else {
			gmarkers[i].show();
		}
	}
}
// Wenn die Route berechnet wird
function onGDirectionsLoad(){ 
	$('mapList').style.display = "none";
	$('mapRouteHeader').innerHTML = "<img onclick=\"printRoute()\" src=\""+BTN_URL+"/print.gif\" alt=\"print\" class=\"img_btn\">&nbsp;<img onclick=\"clearRoute()\" src=\""+BTN_URL+"/close.gif\" alt=\"close\" class=\"img_btn\">";
	displayMarkers(false);
	map.closeInfoWindow();
	$('mapRouteContainer').style.display = "block";
}
// Wenn Fehler auftreten
function handleRouteErrors(){
	if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
	   else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
	   
	   else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gdir.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);

	   else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
	    
	   else alert("An unknown error occurred.");   
}
// Routenplaner - Ende ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~