	
	var icon;
    var garages = new Array();
    var geocoder;
    var googleGeoCoding;
    var ieFilterDisabled =false;
    var ieLTE7=false;
    var garageLng;
    var garageLat;
    		
    function searchMap() {
    	if (ieLTE7){
	    	ieFilterDisabled = isAlphaFilterDisabled()
      	}
      if (GBrowserIsCompatible() ) {
      	 
      	 	
      	  var mapNode=document.getElementById("map");
      	  if (mapNode){
      	  	mapNode.style.display='block';
        	var map = new GMap2(mapNode);
        	var c=new GSmallMapControl();
        	if(!ieFilterDisabled){
       			map.addControl(c);
       		}
			map.addControl(new GMapTypeControl());
			googleGeoCoding=false;
			if(googleGeoCoding){
    			geocoder = new GClientGeocoder();
    		}

			homeLng=getCoo(homeLng);
			homeLat=getCoo(homeLat);
			setZoomAndCenterForPointList(map);
        	
        	icon = createBsIcon();
       		markerGarages(map,garages);
        	markerHome(map,homeLat,homeLng,"<b>"+locationStr+"</b>");
          }
        
      }
    }
    
    function garageMap() {
    	if (ieLTE7){
	    	ieFilterDisabled = isAlphaFilterDisabled()
      	}
      if (GBrowserIsCompatible() ) {
      	 
      	 	
      	  var mapNode=document.getElementById("map");
      	  if (mapNode){
        	var map = new GMap2(mapNode);
        	var c=new GSmallMapControl();
        	if(!ieFilterDisabled){
       			map.addControl(c);
       		}
			map.addControl(new GMapTypeControl());
			googleGeoCoding=false;
			if(googleGeoCoding){
    			geocoder = new GClientGeocoder();
    		}

			garageLng=getCoo(garageLng);
			garageLat=getCoo(garageLat);
        	
        	 map.setCenter(new GLatLng(garageLat,garageLng),12);
        	 icon = createBsIcon();
        	 var marker=new GMarker(new GLatLng(garageLat,garageLng),{icon:icon});
        	 map.addOverlay(marker);
          }
        
      }
    }
     function smallGarageMap() {
    	if (ieLTE7){
	    	ieFilterDisabled = isAlphaFilterDisabled()
      	}
      if (GBrowserIsCompatible() ) {
      	 
      	 	
      	  var mapNode=document.getElementById("smallmap");
      	  if (mapNode){
        	var map = new GMap2(mapNode);
			garageLng=getCoo(garageLng);
			garageLat=getCoo(garageLat);
        	
        	 map.setCenter(new GLatLng(garageLat,garageLng),10);
        	 icon = createBsIcon();
        	 var marker=new GMarker(new GLatLng(garageLat,garageLng),{icon:icon});
        	 map.addOverlay(marker);
          }
        
      }
    }
    function overviewMap() {
    	if (ieLTE7){
	    	ieFilterDisabled = isAlphaFilterDisabled()
      	}
      if (GBrowserIsCompatible() ) {
      	 
      	 	
      	  var mapNode=document.getElementById("map");
      	  if (mapNode){
        	var map = new GMap2(mapNode);
        	var c=new GSmallMapControl();
        	if(!ieFilterDisabled){
       			map.addControl(c);
       		}
			map.addControl(new GMapTypeControl());
			googleGeoCoding=false;
			if(googleGeoCoding){
    			geocoder = new GClientGeocoder();
    		}

			setZoomAndCenterForPointList(map);
        	
        	icon = createRedIcon();
       		markerDieselGarages(map,garages);

          }
        
      }
    }
    
    function isAlphaFilterDisabled(tag){
    	var obj =document.getElementById("map");
    	if(obj){
			var d =document.createElement("div");
	    	var f= obj.appendChild(d);
	      	  f.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader()"
	      	 try{
	      	 	var t =f.filters(0);
	      	}catch(e){
	      		return true;
	      	}
      	}
    }
    
    function getCoo(val){
    	val = val/100000;
    	return val;
    }
    function Garage(b,l,n,str,plz,city,kdnr,page,re,tel,fax){
    	this.lat=getCoo(b);
    	this.lng=getCoo(l);
    	this.name=n.replace(/&amp;/g,'&');
    	this.street=str;
    	this.plz=plz;
    	this.city=city;
    	this.kdnr =kdnr;
    	this.page =page;
    	this.re =re;
    	this.tel=tel;
    	this.fax=fax;
    }
    
    function setZoomAndCenterForPointList(map){
    	//für ein array von punkten wird die Karte auf den richtigen Wert gezoot und zentriert
    	//maximale bounds bestimmen
		bounds = getBoundsForAllPoints(garages);
        //zoomLevel bestimmen, bei dem die bounds im sichtbaren bereich sind
        var z=map.getBoundsZoomLevel(bounds);
		
		// zusaetzlich soll die karte auch noch optimal zentriert werden
		var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
		var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
        map.setCenter(new GLatLng(clat,clng),z);
    }
    
    function getBoundsForAllPoints(pointArray){
    	var bounds = new GLatLngBounds();
    	for(var i=0;i<pointArray.length;i++){
        	
        	garage=pointArray[i];
        	p=new GLatLng(garage.lat,garage.lng);
        	 bounds.extend(p);
        }
        if(typeof(homeLat)!='undefined'){
        	p=new GLatLng(homeLat ,homeLng);
        	 bounds.extend(p);
        }
        return bounds;
    }
  
    
    function markerGarages(map,garages){
    	
    	for(var i=0;i<garages.length;i++){
        	garage=garages[i];
        	markerGarage(map,garage)
        	
        }
    
    }
    
    function markerGarage(map,garage){
		if (googleGeoCoding){
    		var adr = garage.street + ", " + garage.plz + " " + garage.city;
    		geocoder.getLatLng(
    			adr,
    			function(point){
    				var html="<span style='font-family:Arial;font-size:11px;'><b>"+garage.name+"</b><br />"+garage.street+"<br />"+garage.plz +" "+garage.city+"</span>";
					var m= addIconWithMarker(point,html,icon);
					map.addOverlay(m);
    			}
    		);
    	}else{
    		var cl="reloadPage(\""+garage.page+"?id="+garage.kdnr+"&amp;actiontype=setcookie&amp;re="+garage.re+"\");";
    		var tel="";
    		if(garage.tel !=''){
    			tel = "<br />"+telStr+": "+garage.tel;
    		}
    		var fax="";
    		if(garage.fax !=''){
    			fax = "<br />"+faxStr+": "+garage.fax;
    		}
    		var html="<div style='width:200px;font-family:Arial;font-size:11px;text-indent:-8px;padding-left:8px;'><img src='../images/arrow_8x7_blue.gif' border='0' alt='0'/><b><a href='#' onclick='"+cl+"'>"+garage.name+"</a></b><br />"+garage.street+"<br />"+garage.plz +" "+garage.city+tel+fax+"</div>";
			var title=garage.name +", " + garage.street +", " +garage.plz +" " + garage.city;
			var m= addIconWithMarker(new GLatLng(garage.lat,garage.lng),html,icon,title,cl);
			map.addOverlay(m);
    	}
    }
    function markerDieselGarages(map,garages){
    	
    	for(var i=0;i<garages.length;i++){
        	garage=garages[i];
        	markerDieselGarage(map,garage)
        	
        }
    
    }
    function markerDieselGarage(map,garage){
		if (googleGeoCoding){
    		var adr = garage.street + ", " + garage.plz + " " + garage.city;
    		geocoder.getLatLng(
    			adr,
    			function(point){
    				var html="<span style='font-family:Arial;font-size:11px;'><b>"+garage.name+"</b><br />"+garage.street+"<br />"+garage.plz +" "+garage.city+"</span>";
					var m= addIconWithMarker(point,html,icon);
					map.addOverlay(m);
    			}
    		);
    	}else{
    		var title=garage.name +", " + garage.street +", " +garage.plz +" " + garage.city;
    		var h="bs.asp?id="+garage.kdnr+"&actiontype=setcookie"
			var m= new GMarker(new GLatLng(garage.lat,garage.lng),{title:title,icon:icon});
			GEvent.addListener(m, "click", function() { document.location.href=h;});
			map.addOverlay(m);
    	}
    }
    
    
    function markerHome(map,lat,lng,txt){
    	var icon = createTinyIcon();
    	var html="<span style='font-family:Arial;font-size:11px;'>"+txt+"</span>";
    	var m= addIconWithMarker(new GLatLng(lat,lng),html,icon,'');
    	map.addOverlay(m);
        //GEvent.trigger(m,"click");
    }
    
    function addIconWithMarker(point,html,icon,title,clickfunc){
        var marker=new GMarker(point,{title:title,icon:icon});
        if(ieFilterDisabled){
        	if(clickfunc){
        		GEvent.addListener(marker, "click", function() {    eval(clickfunc);  });
        	}
        }else{
        	GEvent.addListener(marker, "click", function() {    marker.openInfoWindowHtml( html );  });
        }
       return marker;
    }
    
    function createTinyIcon(){ 
    	// Create our "tiny" marker icon
		var icon = new GIcon();
		icon.image = "/bs_xmlservice/images/BCS_Standpunkt.gif";
		icon.iconSize = new GSize(20, 20);
		icon.iconAnchor = new GPoint(7, 7);
		icon.infoWindowAnchor = new GPoint(15, 10);
		return icon;
	}
	function createRedIcon(){ 
		var icon = new GIcon();
		icon.image = "/bs_xmlservice/images/BCS_BDSStandort.gif";
		icon.iconSize = new GSize(11, 11);
		icon.iconAnchor = new GPoint(6, 6);
		icon.infoWindowAnchor = new GPoint(6, 6);
		return icon;
	}
    
    function createBsIcon(){
    	var icon = new GIcon();
    	icon.image = "/bs_xmlservice/images/BCS_Logo.gif";
    	icon.shadow = "/bs_xmlservice/images/BCS_Schatten.png";
    	icon.iconSize = new GSize(30, 30);
    	icon.shadowSize = new GSize(56, 27);
    	icon.iconAnchor = new GPoint(6, 20);
    	icon.infoWindowAnchor = new GPoint(15, 10);
    	return icon;
    }
    
    function addEvent(obj, evType, fn, useCapture){
	  if (obj.addEventListener){
	    obj.addEventListener(evType, fn, useCapture);
	    return true;
	  } else if (obj.attachEvent){
	    var r = obj.attachEvent("on"+evType, fn);
	    return r;
	  } else {
	    alert("Handler could not be attached");
	  }
	}
