onerror = stopError;
function stopError(){
	return true;
}

var filter_array = new Array();
var notfallNow = false;
var aktFilter = 1;

filter_array[1] = "enercity-profipartner";
filter_array[29] = "wasser";
filter_array[40] = "entkalkungsanlagen";
filter_array[41] = "filteranlagen";
filter_array[42] = "foerderanlagen";
filter_array[27] = "sanitaer";
filter_array[56] = "rohrreinigung";
filter_array[59] = "sanitaerinstallationen";
filter_array[2] = "elektro";
filter_array[46] = "anlagensteuerung";
filter_array[45] = "elektroinstallation";
filter_array[47] = "hausanschluesse-zaehler";
filter_array[48] = "e-check";
filter_array[30] = "kaelte--klimatechnik";
filter_array[43] = "klimatechnik";
filter_array[31] = "kaeltetechnik";
filter_array[24] = "erneuerbare-energie";
filter_array[34] = "erdwaermepumpen";
filter_array[25] = "photovoltaik";
filter_array[35] = "blockheizkraftwerk";
filter_array[32] = "solarthermie";
filter_array[33] = "luftwärmepumpen";
filter_array[26] = "telekommunikation";
filter_array[3] = "heizung";
filter_array[8] = "heizungsanlagen";
filter_array[52] = "vaillant";
filter_array[53] = "buderus";
filter_array[54] = "viessmann";
filter_array[60] = "de-dietrich";
filter_array[61] = "wolf";
filter_array[62] = "weishaupt";
filter_array[9] = "fernwaerme";
filter_array[44] = "gas-check";
filter_array[55] = "schornsteinfeger";
var startmarker = false;
var _lock = false;

      // this variable will collect the html which will eventually be placed in the side_bar

      // arrays to hold copies of the markers and html used by the side_bar
      // because the function closure trick doesnt work there
      var gmarkers = [];
      var gicons = [];
     // global "map" variable
      var map = null;
      var markers = [];
      var akt_filter = null;

      gicons["red"] = new google.maps.MarkerImage("/mapIcons/marker_red.png",
      // This marker is 20 pixels wide by 34 pixels tall.
      new google.maps.Size(20, 34),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is at 9,34.
      new google.maps.Point(9, 34));
	// Marker sizes are expressed as a Size of X,Y
	// where the origin of the image (0,0) is located
	// in the top left of the image.

	// Origins, anchor positions and coordinates of the marker
	// increase in the X direction to the right and in
	// the Y direction down.

	var infobox = [];
	var infoboxid = []

  var iconImage = new google.maps.MarkerImage('/mapIcons/marker_red.png',
      // This marker is 20 pixels wide by 34 pixels tall.
      new google.maps.Size(20, 34),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is at 9,34.
      new google.maps.Point(9, 34));
  var iconShadow = new google.maps.MarkerImage('http://www.google.com/mapfiles/shadow50.png',
      // The shadow image is larger in the horizontal dimension
      // while the position and offset are the same as for the main image.
      new google.maps.Size(37, 34),
      new google.maps.Point(0,0),
      new google.maps.Point(9, 34));
      // Shapes define the clickable region of the icon.
      // The type defines an HTML &lt;area&gt; element 'poly' which
      // traces out a polygon as a series of X,Y points. The final
      // coordinate closes the poly by connecting to the first
      // coordinate.
  var iconShape = {
      coord: [9,0,6,1,4,2,2,4,0,8,0,12,1,14,2,16,5,19,7,23,8,26,9,30,9,34,11,34,11,30,12,26,13,24,14,21,16,18,18,16,20,12,20,8,18,4,16,2,15,1,13,0],
      type: 'poly'
  };

function getMarkerImage(icon,size) {
   if ((typeof(icon)=="undefined") || (icon==null)) {
      icon = "1";
   }
   var folder = "";
   var wh = "";
   if ((size == 2) || (size == 3)) {
        folder = "";
		wh = 32;
   }
   else if (size == 1) {
        folder = "medium/";
        wh = 18;
   } else {
		folder = "smal/";
		wh = 9;
   }
      var gicon = new google.maps.MarkerImage("/mapIcons/"+ folder + icon +".png",
      // This marker is 20 pixels wide by 34 pixels tall.
      new google.maps.Size(wh, wh),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is at 6,20.
      new google.maps.Point(9, 34));
   return gicon;

}

// A function to create the marker and set up the event window function
function createMarker(latlng,name,html,color,icon,size,filter,id,startmarker,notfall) {
   var contentString = html;
   var MyzIndex = "";
   if (size == 3) {
		MyzIndex = -10;
   }
   else if (size == 2) {
        MyzIndex = -1000;
   } else {
		MyzIndex = -100000;
   }

    var marker = new google.maps.Marker({
        position: latlng,
        icon: getMarkerImage(icon,size),
        //shadow: iconShadow,
        map: map,
	id: id,
        title: name,
        zIndex: Math.round(latlng.lat()*MyzIndex)<<5,
        size: size,
        filter: filter,
	notfall: notfall
    });
    google.maps.event.addListener(marker, 'click', function() {
        //infowindow.setContent(contentString);
        //infowindow.open(map,marker);
        });
    google.maps.event.addListener(marker, 'mouseover', function() {
	if (_lock == true) {
		// wenn wir _lock haben, dann haben wir das fenster manuell aufgemacht.
		return;
	}
        //infowindow.setContent(contentString);
        //infowindow.open(map,marker);
        var tmp = new SmartInfoWindow({position: marker.getPosition(), map: map, content: contentString, size: size, marker_id: id});
        infobox.push(tmp);
	changeUri("",id);
	// wenn wir mehr als 2 sekunden auf einer infobox sind, dann wollen wir das speichern
	startTimer(1);
    });
        // Switch icon on marker mouseover and mouseout
        google.maps.event.addListener(marker, "mouseout", function() {
          //infowindow.close();
	  //startTimer(0);
		//for (var i = 0;i<infobox.length;i++) {
		//    infobox[i].setMap(null);
		//}

        });
	if (startmarker == 1) {
		_lock = true;
		var tmp = new SmartInfoWindow({position: marker.getPosition(), map: map, content: contentString, size: size, marker_id: id});
		infobox.push(tmp);
		changeUri("",id);
		latlng = latlng+"";
		latlng = latlng.replace("(","");
		latlng = latlng.replace(")","");
		latlng = latlng.replace(" ","");
		var latlang = latlng.split(",");
		centerAddress("",parseFloat(latlang[0]), parseFloat(latlang[1]));
		//window.setTimeout("centerAddress(\"\", " + parseFloat(latlang[0]) + "," + parseFloat(latlang[1]) + ");",400);	
	}

    gmarkers.push(marker);
    infoboxid[id] = gmarkers.length-1;
    // add a line to the side_bar html
    var marker_num = gmarkers.length-1;
}

function initialize() {
  // create the map
  var myOptions = {
    zoom: 14,
    scrollwheel: false,
    center: new google.maps.LatLng(52.37209,9.735662),
    mapTypeControl: false,
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
    navigationControl: true,
    navigationControlOptions: {
        style: google.maps.NavigationControlStyle.ZOOM_PAN,
        position: google.maps.ControlPosition.RIGHT_TOP
    },
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    disableDefaultUI: true
  }
  map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
  // create a div to position the navigation
  var controlDiv = document.createElement('DIV');
  controlDiv.style.height = "40px";
  controlDiv.index = 1;
  map.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlDiv);

  google.maps.event.addListener(map, 'zoom_changed', onZoomChanged);

  google.maps.event.addListener(map, 'click', function() {
        //infowindow.close();
	for (var i = 0;i<infobox.length;i++) {
	    infobox[i].setMap(null);
	}
  });
  google.maps.event.addListener(map, 'mouseout', function() {
        //infowindow.close();
	//startTimer(0);
        //for (var i = 0;i<infobox.length;i++) {
        //    infobox[i].setMap(null);
        //}
  });
	//Beim verschieben Adressfeld aktualisieren
	google.maps.event.addListener(map, 'dragend', function()
	{
		address();
	});
        google.maps.event.addListener(map, 'dragstart', function()
        {
                for (var i = 0;i<infobox.length;i++) {
                    infobox[i].setMap(null);
                }

	});



      // Read the data from example.xml
      downloadUrl("/js/xml.php", function(doc) {
        var xmlDoc = xmlParse(doc);
        markers = xmlDoc.documentElement.getElementsByTagName("marker");
	// wenn wir ein startmarker haben wollen wir die infobox aufmachen
	var anchor = window.location.hash;
	anchor = anchor.split("/");
	var tmp = parseInt(anchor[anchor.length-2]);


        for (var i = 0; i < markers.length; i++) {
	//for (var i = 0; i < 20;  i++) {
          // obtain the attribues of each marker
          var lat = parseFloat(markers[i].getAttribute("lat"));
          var lng = parseFloat(markers[i].getAttribute("lng"));
          var point = new google.maps.LatLng(lat,lng);
          var html = html_entity_decode(markers[i].getAttribute("html"));
          var label = ""; // markers[i].getAttribute("label");
          var filter = markers[i].getAttribute("filter");
	  var notfall = markers[i].getAttribute("notfall");
	  var id =  markers[i].getAttribute("id");
          if (akt_filter == null) {
            var icon = 1;
		  } else {
          	var icon = markers[i].getAttribute("icon");
		  }
          var size = markers[i].getAttribute("size");
	  // haben wir bereits einen start marker?
	  if (tmp == id) {
		// create marker
		startmarker = 1
		var marker = createMarker(point,label,html,"blue",icon,size,filter,id,1,notfall);
	  } else {
		// create marker
		var marker = createMarker(point,label,html,"blue",icon,size,filter,id,"",notfall);
	  }
	}
      });
      address();
	// menu aktualisieren
	window.setTimeout("anchorToMenu()",400);
	//anchorToMenu();
}
/**
 * Toggles Marker Manager visibility.
 */
var showMarketManager = false;

function toggleMarkerManager(MyElement) {
	if (MyElement.checked == true) {
	    
		if (gmarkers) {
			for (i in gmarkers) {
			    // marker ausblenden
				gmarkers[i].setMap(null);
				// marker icon aendern
				//gmarkers[i].setIcon(getMarkerImage(3,gmarkers[i].size));
				
			}
		}
	} else {
		if (gmarkers) {
			for (i in gmarkers) {
				gmarkers[i].setMap(map);
				//gmarkers[i].setIcon(getMarkerImage(1,gmarkers[i].size));
			}
		}
	}
}


function html_entity_decode(str){
/*Firefox (and IE if the string contains no elements surrounded by angle brackets )*/
  try{
  var ta=document.createElement("textarea");
  ta.innerHTML=str;
  return ta.value;
  }catch(e){};
/*Internet Explorer*/
  try{
  var d=document.createElement("div");
  d.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  if(typeof d.innerText!="undefined")return d.innerText;/*Sadly this strips tags as well*/
  }catch(e){}
}


var infowindow = new google.maps.InfoWindow(
  {
    size: new google.maps.Size(150,50)
});
infowindow.setZIndex(250);
  
function activate_Menu(MyId) {
	MyId = MyId.replace("/li_/","");
	MySetMenuNormal(MyId);
	var tmp = document.getElementById("li_"+MyId);
	if (tmp) {
		//tmp.childNodes[0].style.fontWeight = "bold";
		tmp.className = "bold";
	}

        var anchor_ = window.frames["framemaps"].location.hash;
        anchor_ = anchor_.split("/");
	var menu_block = [];
        for (nn=1;nn<anchor_.length;nn++) {
                var tmp = parseInt(anchor_[nn]);
                if (tmp) {
                        // wenn wir eine zahl haben wollen wir hier aufhoeren
                        break;
                }
                for (var ni = 1; ni < 99; ni++) {
                        if (!filter_array[ni]) {
                                continue;
                        }
			if (menu_block[ni] == 1) {
				continue;
			}
			var object = document.getElementById("ul_"+ni);
			if (!object) {
				continue;
			}
                        if (filter_array[ni] == anchor_[nn]) {
				menu_block[ni] = "1";
				object.style.display = "block";
			} else {
				object.style.display = "none";	
			}
                }
        }
        if (MyId == 1) {

                document.getElementById("0").className = "bold";
        } else {
		document.getElementById("0").className = "normal";
        }

	// hier alles durchgehen und andere menus schliessen

	/*
	var object = document.getElementById("ul_"+MyId);
	if (!object) {
		return;
	}
	if (object.style.display == "none") {
	    object.style.display = "block";
	} else {
        	object.style.display = "none";
	}
	*/
}
/*
function MyChangeFilter(MyFilter) {
	alert(window.frames["frame_maps"]);
	window.frames["frame_maps"].MyChangeFilter(MyFilter);
	return "";
	_lock = false;
	activate_Menu(MyFilter);
        var anchor = window.location.hash;
	var tmp = anchor.split("/");
        var MyData = {"filter": tmp[tmp.length-2],"anchor":anchor};
        logData(JSON.stringify(MyData),2);
	window.setTimeout("changeFilter('"+MyFilter+"')",200);
}
*/
function MySetMenuNormal(MyId) {
	for(var n = 0; n < 99; n++) {
		if (!filter_array[n]) {
			continue;
		}
		if (n == MyId) {
			continue;
		}
		var element = document.getElementById("li_"+n);
		if (element) {
			//element.style.fontWeight = "100";
			element.className = "normal";
		}
	}
	return "";
	// alles hier nach brauchen wir nicht mehr
	var one = document.getElementById("icon_menu").childNodes;
	for(var i = 0;i < one.length;i++) {
		if (one[i].nodeName == "UL") {
			one[i].className = "";
			one[i].childNodes[0].style.fontWeight = "normal";
			var two = one[i].childNodes;
			for(var n = 0;n < two.length;n++) {
				if ((two[n].childNodes[0]) && (two[n].childNodes[0].style)) {
					two[n].childNodes[0].style.fontWeight = "normal";
				}
				if ((two[n].nodeName == "UL") || (two[n].nodeName == "LI")) {
					//var three = document.getElementById(two[n].id).childNodes;
					var three = two[n].childNodes;
					for(var x = 0;x < three.length;x++) {
						if ((three[x].childNodes[0]) && (three[x].childNodes[0].style)) {
							three[x].childNodes[0].style.fontWeight = "normal";
						}
						if ((three[x].nodeName == "UL") || (three[x].nodeName == "LI")) {
							var five = three[x].childNodes;
							for(var y = 0;y < five.length;y++) {
								if ((five[y].childNodes[0]) && (five[y].childNodes[0].style)) {
									five[y].childNodes[0].style.fontWeight = "normal";
								}
								if ((five[y].nodeName == "UL") || (five[y].nodeName == "LI")) {
									var six = five[y].childNodes;
									for(var z = 0;z < six.length;z++) {
										if ((six[z].childNodes[0]) && (six[z].childNodes[0].style))
											six[z].childNodes[0].style.fontWeight = "normal";
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
function changeFilter(MyFilter,startmarker) {
	window.frames['framemaps'].changeFilter(MyFilter,startmarker);
	return "";
	//alert(MyFilter + " -" + startmarker);
	aktFilter = MyFilter;
	if (gmarkers) {
          var anchor = window.location.hash;
          anchor = anchor.split("/");
          var tmp = parseInt(anchor[anchor.length-2]);
	  if (!startmarker) {
		startmarker = "";
	  } else {
	  }
  	  if (!startmarker) {
		for (var i = 0;i<infobox.length;i++) {
			infobox[i].setMap(null);
          	}
	  }
		for (i in gmarkers) {
		    if (MyFilter == 1) {
				if (notfallNow == true) {
					// nur notfall anzeigen
					if (gmarkers[i].notfall == 1) {
						gmarkers[i].setIcon(getMarkerImage(MyFilter,gmarkers[i].size));
						gmarkers[i].setMap(map);
					}
					else {
						gmarkers[i].setMap(null);
					}
				} else {
					// einfach alle anzeigen
					gmarkers[i].setIcon(getMarkerImage(MyFilter,gmarkers[i].size));
					gmarkers[i].setMap(map);
				}
				continue;
			}
			// nur notfall anzeigen
			//alert("a");
			//gmarkers[i].setMap(map);
			var filter = gmarkers[i].filter.split(",");
			for(var n = 0;n<filter.length;n++) {
			    var ok = null;
				if (filter[n] == MyFilter) {
					gmarkers[i].setIcon(getMarkerImage(MyFilter,gmarkers[i].size));
					ok = 1
					break;
				} 
			}
			if (ok == null) {
				gmarkers[i].setMap(null);
			} else {
                                if (notfallNow == true) {
                                        if (gmarkers[i].notfall == 1) {
                                                gmarkers[i].setMap(map); 
					} else {
						gmarkers[i].setMap(null);
					}
                                } else {
					gmarkers[i].setMap(map);
				}
			}
			//gmarkers[i].setIcon(getMarkerImage(MyFilter,gmarkers[i].size));
		}
	}
}
function switchMenu() {
        for (var i = 0;i<infobox.length;i++) {
            infobox[i].setMap(null);
        }

	if (document.getElementById("icon_menu").style.display == "none") {
		document.getElementById("icon_menu").style.display = "block";
		document.getElementById("smaller").innerHTML = "<span style=\"padding-right:20px;\"><a href=\"javascript:showFavorites()\"><img src=\"images/star_h.png\"> Favoriten anzeigen</a></span><a href=\"javascript:switchMenu()\"><img src=\"images/pfeil_l.jpg\" class='right'></a>";
		document.getElementById("controll").style.width = "260px";
 	} else {
        	document.getElementById("icon_menu").style.display = "none";
        	document.getElementById("smaller").innerHTML = "<a href=\"javascript:switchMenu()\"><img src=\"images/pfeil_r.jpg\" class='right'></a>";
        	document.getElementById("controll").style.width = "30px";
	}
}

//Einzoomen
function zoomIn() {
	var z = map.getZoom();
	if(z < 16) z++;
	map.setZoom(z);

}
//Auszoomen
function zoomOut() {
	var z = map.getZoom();
	if(z > 13) z--;
	map.setZoom(z);
}

var inProcess = false;
function onZoomChanged() {
    if (inProcess) return;

    if (map.getZoom() > 16) {
        inProcess = true;
        map.setZoom(16);
        inProcess = false;
        return
    }
    else if (map.getZoom() < 13) {
        inProcess = true;
        map.setZoom(13);
        inProcess = false;
        return;
    }
}

var coder = null;
var coder = new google.maps.Geocoder();

function centerAddress (ad,lat,lng){
	if ((bubble == 1) && (!lat)) {
		bubble = 0;
		return;
	}
	if ((lat) && (lng)) {
		 map.pos = new google.maps.LatLng(lat,lng);
		 map.setCenter(map.pos,13);
		 address();
	
	} else {
		if(!ad.match(/( deutschland| de| de$| germany)/i)) ad += ' deutschland';
		coder.geocode( { 'address': ad },
		function(result, stat) {
			//Wenn Status okay, dann erstes Ergebnis
			if (stat == google.maps.GeocoderStatus.OK) {
				map.pos = new google.maps.LatLng(result[0].geometry.location.lat(), result[0].geometry.location.lng());
				map.setCenter(map.pos);
				address();
			}
		});
	}
}
function address() {
		//Überprüfung
		if(!dojo.byId('address')) return false;
		//Center auslesen
		coder.geocode( { location: map.getCenter() },
		function(results, stat) {
			//Status prüfen und erstes Ergebnis verwenden
			if (stat == google.maps.GeocoderStatus.OK) {
				row = results[0];
				var country = false;
				var street  = false;
				var city    = false;
				var post    = false;
				//Adressdaten zerlegen
				dojo.forEach(row.address_components, function(adr)
				{
					dojo.forEach(adr.types, function(type)
					{
						if(type == 'country'    ) country = adr.long_name;
						if(type == 'route'      ) street  = adr.long_name;
						if(type == 'locality'   ) city    = adr.long_name;
						if(type == 'postal_code') post    = adr.long_name;
					});
				});
				//Adresse formatieren und ausgeben
				var name = (street ? street+', ' : '')+(post ? post+' '+city : city);
				dojo.byId('address').value = name;
			}
		});
}
var frame = {
	show: function(url)
	{
		dojo.byId('frame').src = url;
		dojo.animateProperty(
	    {
			node: dojo.byId('_webpage'),
			properties: {
				opacity: {start:0, end: 0.8}
			},
			onBegin: function()
			{
				this.node.style.display = 'block';
			}
		}).play();
		dojo.animateProperty(
	    {
			node: dojo.byId('webpage'),
			properties: {
				opacity: {start:0, end: 1}
			},
			onBegin: function()
			{
				this.node.style.display = 'block';
			}
		}).play();
	},
	hide: function()
	{
		dojo.animateProperty(
	    {
			node: dojo.byId('_webpage'),
			properties: {
				opacity: {start:0.8, end: 0}
			},
			onEnd: function()
			{
				this.node.style.display = 'none';
				dojo.byId('frame').src = '';
				for (var i = 0;i<infobox.length;i++) {
					infobox[i].setMap(null);
				}
			}
		}).play();
		dojo.animateProperty(
	    {
			node: dojo.byId('webpage'),
			properties: {
				opacity: {start:1, end: 0}
			},
			onEnd: function()
			{
				this.node.style.display = 'none';
                                for (var i = 0;i<infobox.length;i++) {
                                        infobox[i].setMap(null);
                                }

			}
		}).play();
	}
}

function changeUri(MyUri,infobox) {
	//window.frames["frame_maps"].location.href="http://maps.k7i.de/#!"+MyUri;
	//window.frames["frame_maps"].changeUri(MyUri,infobox);
	return "";
	if (infobox) {
		// wenn wir eine infobox id haben, dann wollen wir den anker aendern
		if (window.location.hash) {
			var anchor = window.location.hash;
			anchor = anchor.split("/");
			var tmp = parseInt(anchor[anchor.length-2]);
			if (tmp) {
				// hier haben wir bereits eine id
				var anchor = window.location.hash;
				tmp = "/" + tmp;
				anchor = anchor.replace(tmp,"");
				window.location.href = anchor + infobox + "/"
			} else {
				_lock = false;
				window.location.href = window.location.hash + infobox + "/";
			}
		} else {
			window.location.href = "#!/" + infobox + "/";
		}
	} else {
		window.location.href = "#!/" + MyUri + "/";
	}
}
function anchorToMenu() {
	if (!startmarker) {
		_lock = false;
	}
	var anchor = window.location.hash;
	anchor = anchor.split("/");
	for (n=1;n<anchor.length;n++) {
		var tmp = parseInt(anchor[n]);
		if (tmp) {
			// wenn wir eine zahl haben wollen wir hier aufhoeren
			break;
		}
		for (var i = 1; i < 99; i++) {
			if (!filter_array[i]) {
				continue;
			}
			if (filter_array[i] == anchor[n]) {
				//MyChangeFilter(i+"");
				activate_Menu(i+"");
				if (n == anchor.length-2) {
					// letztes element, hier die filter aktualisieren
					changeFilter(i+"",anchor[anchor.length-2]);	
				}
			}		
		}	
	}
	//alert(infoboxid[tmp]);
	//infobox[infoboxid[tmp]].setMap(map);
}
function getFavoriteStar2(MyId) {
	var n = "favorite_"+MyId;
	a = document.cookie;
	res = '';
	while(a != '') {
		cookiename = a.substring(0,a.search('='));
		cookiewert = a.substring(a.search('=')+1,a.search(';'));
		if(cookiewert == '') {
			cookiewert = a.substring(a.search('=')+1,a.length);
		}
		if(n == cookiename){
			res = cookiewert;
		}
		i = a.search(';')+1;
		if(i == 0){
			i = a.length
		}
		a = a.substring(i,a.length);
	}
	//alert(res);
	if (res == 1) {
		return "<img title='Zur Merkerliste hinzuf&uuml;gen' onClick=\"delFavorite(" + MyId + ")\" src='/images/star_h.png'>";
	} else {
		return "<img title='Zur Merkerliste hinzuf&uuml;gen' onClick=\"addFavorite(" + MyId + ")\" src='/images/star.png'>";
	}
}
function getFavoriteStar(MyId) {
	var keks = document.cookie;

	// Anfangsposition des Name=Wert-Paars suchen
	var posName = keks.indexOf("; favorite_" + MyId + "=");
	if (posName == -1) {
		// vielleicht war's der erste Name in der Liste?
		if (keks.indexOf(name + "=") == 0) posName = 0;
		// nein? dann abbrechen mit Rückgabewert null
		else {
			return "<img title='Zur Merkerliste hinzuf&uuml;gen' onClick=\"addFavorite(" + MyId + ");this.src='/images/star_h.png';\" src='/images/star.png'>";
		}
	}

	// Anfangs- und Endposition suchen
	var wertAnfang = keks.indexOf("=", posName)+1;
	var wertEnde = keks.indexOf(";", posName+1);
	if (wertEnde == -1) wertEnde = keks.length;

	// auslesen und zurückgeben
	var wert = keks.substring(wertAnfang, wertEnde);
	if (wert == 1) {
		return "<img title='Von Merkerliste l&ouml;schen' onClick=\"delFavorite(" + MyId + ");this.src='/images/star.png';\" src='/images/star_h.png'>";
        } else {
		return "<img title='Zur Merkerliste hinzuf&uuml;gen' onClick=\"delFavorite(" + MyId + ");this.src='/images/star_h.png';\" src='/images/star.png'>";
	}

}
function addFavorite(MyId) {
	var a = new Date();
	var e = 1000*60*60*24*365;
	a = new Date(a.getTime() +e);
	var n = "favorite_"+MyId;
	var w = 1;
	document.cookie = n+'='+w+'; expires='+a.toGMTString()+';';
	buildFavorites();
        var anchor = window.location.hash;
        var MyData = {"handwerker": MyId,"anchor":anchor};
	if (JSON)
        	logData(JSON.stringify(MyData),5);
}
function delFavorite(MyId) {
	window.frames['framemaps'].delFavorite(MyId);
	MyId = "favorite_"+MyId;
	document.cookie = MyId+'=0; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	buildFavorites();
}
function showFavorites() {
	if (document.getElementById("menu").style.display == "none") {
		document.getElementById("my_favs").style.display = "none";
		document.getElementById("smaller").innerHTML = "<span style=\"padding-right:20px;\"><a href=\"javascript:showFavorites()\"><img src=\"images/star_h.png\"> Favoriten anzeigen</a></span>";
		document.getElementById("menu").style.display = "block";
	} else {
		document.getElementById("menu").style.display = "none";
		document.getElementById("smaller").innerHTML = "<span style=\"padding-right:20px;\"><a href=\"javascript:showFavorites()\"><img src=\"images/star_h.png\"> Navigation anzeigen</a></span>";
		document.getElementById("my_favs").style.display = "block";
		buildFavorites();
	}
}
function buildFavorites(favs) {
	var keks = document.cookie;
	var keks_array = keks.split(";");
	var favs = [];
	for (var n = 0; n < keks_array.length;n++) {
		if (keks_array[n].search("/favorite/")) {
			var val = keks_array[n];
			val = val.replace("favorite_","");
			val = val.split("=");
			if ((val[0]>1) && val[1] == 1) {
				favs.push(val[0]);
			}
		}
	}

	if (favs.length < 1) {
		// Keine Favoriten
		var element = document.getElementById("my_favs");
		element.innerHTML = "";
	} else {
		var element = document.getElementById("my_favs");
		var output = "<div>";
		var infoboxid = window.frames["framemaps"].infoboxid;
		var markers = window.frames["framemaps"].markers;
		var pattern = /<h1>(\w.+)<\/h1>/i;
		for (var i = 0;i<favs.length;i++) {
			var MyId = infoboxid[parseInt(favs[i])];
			var html = html_entity_decode(markers[MyId].getAttribute("html"));
			pattern.exec(html);
			var title = RegExp.$1;
			var title2 = title;
			if (title.length > 25) {
				title = title.substr(0,25)+"...";
			}
			output = output + "<div class='favsimg'><img title='Von Merkerliste l&ouml;schen' style='cursor:pointer;' onClick=\"delFavorite('"+parseInt(favs[i])+"');\" src='images/star_h.png'></div><div class='favstitle'><h1><a href='javascript:showInfobox("+parseInt(favs[i])+",4)' title='"+title2+"'>"+title+"</a></h1></div><div class='clear'></div>";
		}
		element.innerHTML = output+ "</div>";
	}
}
function showInfobox(MyId,MyType) {
	window.frames['framemaps'].showInfobox(MyId,MyType);
}
function highlight(MyElement) {
	MyElement.select();
}
//var MyData = {"haendler": "1","filer":2};
//logData(JSON.stringify(MyData),1);
function logData(MyData,type) {
	// type 1 = normaler hover
	// type 2 = kategorie
	// type 3 = suche
	// type 4 = favoriten
	// type 5 = favoriten hinzugefuegt
	// type 6 = landingpage
	// type 7 = close page
	// wir wollen auch noch zoomstufe speichern
	var img = new Image();
	img.src = "http://maps.k7i.de/log.php?data="+escape(MyData)+"&type="+type;
}

function setNotfall(value) {
	notfallNow = value;
	changeFilter(aktFilter)
}



// landingpage speichern
var anchor = window.location.hash;
var MyData = {"referrer":document.referrer, "anchor":anchor};
if (JSON) {
	logData(JSON.stringify(MyData),6);
}
onunload =
	function() {
		var anchor = window.location.hash;
		var MyData = {"referrer":document.referrer, "anchor":anchor};
		if (JSON) {
			logData(JSON.stringify(MyData),7);
		}
	};
function activate_Menu2() {

}

