﻿


var __gm_browser_useragent = navigator.userAgent;

var __gm_is_ie = (__gm_browser_useragent.indexOf('MSIE') > 0) ? true : false;
var __gm_is_ie6 = (__gm_browser_useragent.indexOf('MSIE 6') > 0) ? true : false;
var __gm_is_safari = (__gm_browser_useragent.indexOf('Safari') > 0) ? true : false;

var __mapsearchactiondelay = 800; // ms Verzögerung Aktion - Suche


////////////////////////////////////////////////////////////////////////////////////////////////////
// GOOGLE MAPS LOGIK FÜR DIE "MAPS" (GROSSE WELTKARTE) HÄNDLERSUCHE
////////////////////////////////////////////////////////////////////////////////////////////////////

var vGoogleMapWorldWindow = null;

function openDsGoogleMapWindow(mvcurl) {

    if (vGoogleMapWorldWindow != null) {
        try {
            vGoogleMapWorldWindow.close();
        } catch (e) {
        }
    }

    vGoogleMapWorldWindow = window.open(mvcurl, "DsGoogleMapWindow", "scrollbars=no,menubar=no,locationbar=no,resizable=yes,status=no");
    
    return false;
}


GoogleMapWorldOverview = function() {

	this.me = null;                         // eigenes objekt
	this.map = null;                        // google maps objekt
	this.mapdiv = null;                     // div in dem die google map erstellt wird
	this.filterdiv = null;                  // div in dem der filterbereich abgebildet wird
	this.win = null;                        // fenster
	this.mapspeller = null;                 // objekt für die Wegbeschreibung

	this.markers = new Array();

	this.imageurl = null;                   // Pfad zu den Bildern
	this.dealerinfourl = null;              // URL zum Aufzupoppenden DIV beim Klick auf einen Punkt (Händler)
	this.countryinfourl = null;             // URL zum Aufzupoppenden DIV beim Klick auf einen Land

	this.pleasewaitdisplayed = null;        // Bitte warten box aktiv oder inaktiv
	this.pleasewaitmessage = null;          // Bitte warten box text
	this.detailopenedmessage = null;        // Text für Detail wurde im Parent geöffnet
	this.bigmarkerinfomessage = null;       // Infotext für die Zusammengefassten Punkte
	this.bigcouponmarkerinfomessage = null;       // Infotext für die Zusammengefassten Punkte inkl. coupon
	this.normalmarkerinfomessage = null;    // Infotext für einen einzelnen Marker
	this.normalcouponmarkerinfomessage = null;    // Infotext für einen einzelnen Coupon Marker
	this.headquaterinfomessage = null;      // Infotext für die Legende des Headquaters
	this.legendinfomessage = null;          // Infotext für die Legende
	this.filterdelaycalled = null;          // verzögerung für filterung
	this.dealermsgtrans = null;             // Übersetzung für "Händler" (dealer)
	this.filterrecalled = null;
	this.legendDiv = null;
	this.legendisclosed = null;             // Legende maximiert oder minimiert

	this.functiondelayersearch = null;

	this.__map_draw_markers_errorcount = null;

	// HILFSFUNKTION FÜR DIE LEGENDE
	this.__draw_legend = function(self) {

		if (self.legendisclosed == null) {
			self.legendisclosed = false;
		}

		var html = "" +
                "<table cellpadding=\"0\" cellspacing=\"1\" border=\"0\"> " +
                "    <tr> " +
                "       <td style=\"text-align:right;\"><div class=\"menutext\"><b>" + self.legendinfomessage + "&nbsp;&nbsp;</b></div></td> " +
                "       <td  align=\"center\"><div id=\"google_map_legend_minimizer\" style=\"cursor:pointer;\" /></td> " +
                "    </tr> " +
                "    <tr> " +
                "       <td colspan=\"2\"><div style=\"height:1px; border-top:solid 1px #E0D07D; border-bottom: 0; padding:0 0 0 0; margin: 0 0 0 0;\" ></div></td> " +
                "    </tr> " +
                "    <tr> " +
                "        <td align=\"right\" style=\"text-align:right;\"><div class=\"menutext\" style=\"text-align:right;\">" + self.headquaterinfomessage + "&nbsp;&nbsp;</div></td> " +
                "        <td align=\"center\" style=\"text-align:center;\"><img src=\"" + self.imageurl + "/googlemaps_point_headquater.gif" + "\" border=\"0\"/></td> " +
                "    </tr> " +
                "    <tr> " +
                "        <td align=\"right\" style=\"text-align:right;\"><div class=\"menutext\" style=\"text-align:right;\">" + self.lyonesscountryinfomessage + "&nbsp;&nbsp;</div></td> " +
                "        <td align=\"center\" style=\"text-align:center;\"><img src=\"" + self.imageurl + "/googlemaps_point_lyonesscountry.gif" + "\" border=\"0\"/></td> " +
                "    </tr> " +
                "    <tr> " +
                "        <td align=\"right\" style=\"text-align:right;\"><div class=\"menutext\" style=\"text-align:right;\">" + self.bigmarkerinfomessage + "&nbsp;&nbsp;</div></td> " +
                "        <td align=\"center\" style=\"text-align:center;\"><img src=\"" + self.imageurl + "/googlemaps_point_big.gif" + "\" border=\"0\"/></td> " +
                "    </tr> " +
                "    <tr> " +
                "        <td align=\"right\" style=\"text-align:right;\"><div class=\"menutext\" style=\"text-align:right;\">" + self.bigcouponmarkerinfomessage + "&nbsp;&nbsp;</div></td> " +
                "        <td align=\"center\" style=\"text-align:center;\"><img src=\"" + self.imageurl + "/googlemaps_point_big_coupon.gif" + "\" border=\"0\"/></td> " +
                "    </tr> " +
                "    <tr> " +
                "        <td align=\"right\" style=\"text-align:right;\"><div class=\"menutext\" style=\"text-align:right;\">" + self.normalmarkerinfomessage + "&nbsp;&nbsp;</div></td> " +
                "        <td align=\"center\" style=\"text-align:center;\"><img src=\"" + self.imageurl + "/googlemaps_point.gif" + "\" border=\"0\"/></td> " +
                "    </tr> " +
                "    <tr> " +
                "        <td align=\"right\" style=\"text-align:right;\"><div class=\"menutext\" style=\"text-align:right;\">" + self.normalcouponmarkerinfomessage + "&nbsp;&nbsp;</div></td> " +
                "        <td align=\"center\" style=\"text-align:center;\"><img src=\"" + self.imageurl + "/googlemaps_point_coupon.gif" + "\" border=\"0\"/></td> " +
                "    </tr> " +
                "</table> ";


		var htmlmin = "" +
                "<table cellpadding=\"0\" cellspacing=\"1\" border=\"0\"> " +
                "    <tr> " +
                "       <td style=\"text-align:right;\"><div class=\"menutext\"><b>" + self.legendinfomessage + "&nbsp;&nbsp;</b></div></td> " +
                "       <td  align=\"center\"><div id=\"google_map_legend_minimizer\" style=\"cursor:pointer;\" /></td> " +
                "    </tr> " +
                "</table>";


		self.legendDiv = document.createElement('div');
		self.legendDiv.id = "gmaplegenddiv";
		self.legendDiv.name = "gmaplegenddiv";
		self.legendDiv.innerHTML = html;
		self.legendDiv.style.position = "relative";
		self.legendDiv.style.border = "solid 1px #E0D07D";
		self.legendDiv.style.padding = "4px 4px 4px 4px";
		self.legendDiv.style.margin = "0px 0px 0px 0px";
		self.legendDiv.style.backgroundColor = "#FFFFFF";
		self.legendDiv.style.zIndex = "1";
		self.legendDiv.style.top = "30px";
		self.legendDiv.style.cssFloat = "right";
		self.legendDiv.style.styleFloat = "right";

		if (__gm_is_ie6 == true) {
			self.legendDiv.style.marginRight = "5px";
		} else {
			self.legendDiv.style.marginRight = "8px";
		}

		self.mapdiv.appendChild(self.legendDiv);

		self._make_legend_closer_callback(self, htmlmin, html);
	}


	this._make_legend_closer_callback = function(self, htmlmin, htmlmax) {

		var vLegendCloser = document.getElementById("google_map_legend_minimizer");
		if (vLegendCloser != null) {

			vLegendCloser.onclick = function() {

				if (self.legendisclosed == false) {

					self._minimizelegend(self, htmlmin, htmlmax);
					self.legendisclosed = true;

				} else {

					self._maximizelegend(self, htmlmin, htmlmax);
					self.legendisclosed = false;
				}
			}
		}
	}

	this._maximizelegend = function(self, htmlmin, htmlmax) {
		self.legendDiv.innerHTML = htmlmax;
		self._make_legend_closer_callback(self, htmlmin, htmlmax);
	}


	this._minimizelegend = function(self, htmlmin, htmlmax) {
		self.legendDiv.innerHTML = htmlmin;
		self._make_legend_closer_callback(self, htmlmin, htmlmax);
	}


	// HILFSFUNKTION FÜR CHECKBOXENAUSWAHL
	this.__filter_data_fct_get_ids = function(vprefixname) {

		var vResString = "";
		var vResStringAll = "";

		var vCidPrefix = vprefixname;
		var idx = 0;

		var vnochekced = 0;

		do {

			vEle = document.getElementById(vCidPrefix + idx);

			// selektierte ids
			if (vEle != null && vEle.checked == true) {
				vResString = vResString + vEle.value + ",";
				vnochekced++;
			}

			// alle ids
			if (vEle != null) {
				vResStringAll = vResStringAll + vEle.value + ",";
			}

			idx++;

		} while (vEle != null);

		vResString = trim(vResString, ",");
		vResStringAll = trim(vResStringAll, ",");

		if (vnochekced == 0) { return ""; }

		if (vResString == null || vResString == "") return vResStringAll;
		return vResString;
	}

	// HILFSFUNKTION ZUM AKTIVIEREN BZW. DEAKTIVIEREN DER FILTER-CHECKBOXEN
	this.__filter_data_fct_enable_disable_filter_fields = function(vprefixname, enabledisable) {

		var idx = 0;

		do {

			vEle = document.getElementById(vprefixname + idx);

			if (vEle != null) {
				vEle.disabled = enabledisable;
			}

			idx++;

		} while (vEle != null);
	}

	// HILFSFUNKTION ZUM ERMITTELN DES ZOOMS
	this.__map_get_zoom = function() {
		var vZoom = this.map.getZoom();
		return vZoom;
	}

	// HILFSFUNKTION UM EINEN MARKER HINZUZUFÜGEN
	this.__map_add_marker_to_array = function(marker) {
		this.markers.push(marker);
	}

	// ALLE MAP MARKER WIEDER ENTFERNEN
	this.__map_clear_markers = function() {

		for (var cnt = 0; cnt < this.markers.length; cnt++) {
			this.map.removeOverlay(this.markers[cnt]);
		}

		this.markers = new Array(); // Alle Markers wurden gelöscht.
	}


	// KARTNAKTIONEN EIN bzw. AUS SCHALTEN
	this.__enable_disable_card_handlers = function(self, istein) {

		/*
		if (istein == false) {

            self.map.disableDragging();
		self.map.disableDoubleClickZoom();
		self.map.disableContinuousZoom();
		self.map.disableScrollWheelZoom();

        } else {

            self.map.enableDragging();
		self.map.enableDoubleClickZoom();
		self.map.enableContinuousZoom();
		self.map.enableScrollWheelZoom();
		}
		*/
	}


	// MARKER AUF DIE KARTE ZEICHNEN
	this.__map_draw_markers = function(srcstring, self, overlaymessage) {

		try {

			// Solange wir Marker positionieren sperren wir alles andere der Karte
			self.__enable_disable_card_handlers(self, false);

			self.__map_clear_markers();


			var dealers = srcstring.split("#");
			if (srcstring != null && srcstring != "" && dealers != null && dealers.length >= 1) {

				var vTypeCode = dealers[0];

				vTypeCode = vTypeCode.replace(String.fromCharCode(10), "");
				vTypeCode = vTypeCode.replace(String.fromCharCode(13), "");

				// Der erste eintrag Kennzeichnet ob HÄNDLER oder LAND

				// HÄNDLER
				if (vTypeCode == "DEALER") {


					for (var x = 1; x < dealers.length; x++) {

						var dealersdetails = dealers[x].split(";");
						if (dealersdetails.length < 5) continue;

						var vLocId = dealersdetails[0];
						var vLocLat = dealersdetails[1];
						var vLocLng = dealersdetails[2];
						var vShrinkCount = dealersdetails[3];
						var vClusteredIds = dealersdetails[4];
						var vCouponCount = dealersdetails[5];

						var marker = map_get_marker(vLocId, vLocLat, vLocLng, 3, vShrinkCount, vCouponCount, self, vClusteredIds);

						self.map.addOverlay(marker);
						self.__map_add_marker_to_array(marker);
					}
				}

				// LAND
				if (vTypeCode == "COUNTRY") {

					
					for (var x = 1; x < dealers.length; x++) {

						var dealersdetails = dealers[x].split(";");

						var vCountryNumber = dealersdetails[0];
						var vCountryLocLat = dealersdetails[1];
						var vCountryLocLng = dealersdetails[2];
						var vIsHeadquater = dealersdetails[3];

						var vCountryLat = dealersdetails[4];
						var vCountryLng = dealersdetails[5];
						var vCountryZoom = dealersdetails[6];

						var marker = map_get_marker_countries(self, vCountryNumber, vCountryLocLat, vCountryLocLng, vIsHeadquater, vCountryLat, vCountryLng, vCountryZoom);

						self.map.addOverlay(marker);
						self.__map_add_marker_to_array(marker);
					}
				}
			}

			self.__map_draw_markers_errorcount = 0;

		} catch (e) {

			// Von Zeit zu Zeit bringt Google Maps einen Fehler bei zu schnellen klicken ->
			// Anscheinend tritt dieser auf wenn die Kartenelemente noch nicht vollständig aufgebaut sind und versucht wird
			// einen Marker zu zeichnen.
			// In diesen Fall versuchen wir die gesamte Prozedur einfach noch einmal. Das Ganze bis zu 3 mal wenn dann noch
			// nicht gutgegangen ignorieren wir den Fehler einfach.

			if (self.__map_draw_markers_errorcount == null) self.__map_draw_markers_errorcount = 0;
			self.__map_draw_markers_errorcount++;

			if (self.__map_draw_markers_errorcount < 3) {
				self._filter_data_fct(self);
			}

		} finally {

			if (overlaymessage != null) {
				overlaymessage.Clear();
				self.pleasewaitdisplayed = false;
			}

			self.filterdelaycalled = false;
			self.filterrecalled = false;

			self.__disable_enable_all_filters(self, false);


			// Solange wir Marker positionieren sperren wir alles andere der Karte
			self.__enable_disable_card_handlers(self, true);
		}
	}

	// FENSTERGRÖSSE ÄNDERN
	this._winresizeaction = function(win, mapdiv, filterdiv, map) {

		/*
		alert("mapdiv.style.height = " + mapdiv.style.height + "\n" +
		"win.document.body.clientHeight = " + win.document.body.clientHeight + "\n");
		*/

		mapdiv.style.height = (win.document.body.clientHeight - __rempx(mapdiv.style.borderBottomWidth) - __rempx(mapdiv.style.borderTopWidth)) + "px";
		filterdiv.style.height = (win.document.body.clientHeight - __rempx(filterdiv.style.borderBottomWidth) - __rempx(filterdiv.style.borderTopWidth)) + "px";



		if (map != null) {
			map.checkResize();
		}

		if (this.mapspeller != null && this.mapspeller.IsDisplayed() == true) {
			return this.mapspeller.RefreshSize();
		}

		return true;
	}

	// FILTER DER LÄNDER MALEN
	this._filter_drawer_fct = function(filterdiv, datafilterurl) {

		$.post(
                datafilterurl,
                { serveraction: "getfilter" },
                function(data) {
                	filterdiv.innerHTML = data;
                }
        );
	}

	this.__disable_enable_all_filters = function(self, enabledisable) {

		self.__filter_data_fct_enable_disable_filter_fields("chk_country_", enabledisable);
		self.__filter_data_fct_enable_disable_filter_fields("chk_category_", enabledisable);
		self.__filter_data_fct_enable_disable_filter_fields("chk_variante_", enabledisable);
	}

	this._filter_data_fct_delayed = function(self) {

		var datafilterurl = window.worldoverview.me.datafilterurl;
		var successcallerfunction = window.worldoverview.me.__map_draw_markers;

		self.__disable_enable_all_filters(self, true);

		var vcountryfilterstring = self.__filter_data_fct_get_ids("chk_country_");
		var vcategoriefilterstring = self.__filter_data_fct_get_ids("chk_category_");
		var vvariantfilterstring = self.__filter_data_fct_get_ids("chk_variante_");

		var llpoint_lo = self.map.fromContainerPixelToLatLng(new GPoint(0, 0));
		var llpoint_ru = self.map.fromContainerPixelToLatLng(new GPoint(self.mapdiv.clientWidth, self.mapdiv.clientHeight));

		var overlaymessage = null;

		if (self.pleasewaitdisplayed == false || self.pleasewaitdisplayed == null) {
			overlaymessage = putGoogleSearchMapPleaseWaitMessage(self.mapdiv, self.pleasewaitmessage, "absolute");
			self.pleasewaitdisplayed = true;
		}


		$.post(
            datafilterurl,
            { serveraction: "filterdata", countries: vcountryfilterstring, categories: vcategoriefilterstring, variants: vvariantfilterstring,
            	zoom: self.__map_get_zoom(),
            	y1: llpoint_lo.lat(), x1: llpoint_lo.lng(), y2: llpoint_ru.lat(), x2: llpoint_ru.lng()
            },
                function(data, textStatus) {
                	if (textStatus == "success") {
                		successcallerfunction(data, self, overlaymessage);
                	} else {
                		overlaymessage.Clear();
                		self.pleasewaitdisplayed = false;
                		self.__disable_enable_all_filters(self, false);
                	}
                }
        );

	}


	// FILTERN
	this._filter_data_fct = function(self) {

		if (self.functiondelayersearch == null) {

			self.functiondelayersearch = new FunctionDelayer
                (
                    "googlemap_world_fctdelay_search",
                    self._filter_data_fct_delayed, self, __mapsearchactiondelay
                 );
		}

		self.functiondelayersearch.Trigger();
	}



	this._remove_detail_overlay_message = function() {
		window.detailoverlaymessage.Clear();
	}
}

GoogleMapWorldOverview.prototype.DisplayDetailOpenWindow = function() {
    var detailoverlaymessage = putGoogleSearchMapPleaseWaitMessage(this.mapdiv, this.detailopenedmessage, "absolute");
    this.win.detailoverlaymessage = detailoverlaymessage;
    this.win.setTimeout("window.worldoverview._remove_detail_overlay_message()", 2500 /*ms*/);
}

GoogleMapWorldOverview.prototype.DrawLegend = function() {
    this.__draw_legend(this);
}


GoogleMapWorldOverview.prototype.SetDirectionSpeller = function(speller) {
    this.mapspeller;
}

GoogleMapWorldOverview.prototype.GetMap = function() {
    return this.map;
}   

GoogleMapWorldOverview.prototype.FilterData = function() {

    this._filter_data_fct(this.me);
}

GoogleMapWorldOverview.prototype.Init = function(
        self, win, mapdivid, filterdivid, datafilterurl, imageurl,
        dealerinfourl, countryinfourl, pleasewaitmessage, detailopenedmessage, bigmminfomessage, bigcouponmminfomessage, normalmminfomessage, normalcouponmminfomessage, headquaterinfomessage,
        lyonesscountryinfomessage, dealertrans, inlegendinfomessage) {

    this.me = self;
    this.win = win;
    this.mapdiv = document.getElementById(mapdivid);
    this.filterdiv = document.getElementById(filterdivid);
    this.datafilterurl = datafilterurl;
    this.countryinfourl = countryinfourl;

    this.win.mapdiv = this.mapdiv;
    this.win.filterdiv = this.filterdiv;
    this.win.map = this.map
    this.win.worldoverview = this.me;

    this.bigmarkerinfomessage = bigmminfomessage;
    this.bigcouponmarkerinfomessage = bigcouponmminfomessage;
    this.normalmarkerinfomessage = normalmminfomessage;
    this.normalcouponmarkerinfomessage = normalcouponmminfomessage;
    this.headquaterinfomessage = headquaterinfomessage;
    this.lyonesscountryinfomessage = lyonesscountryinfomessage;
    this.dealermsgtrans = dealertrans;
    this.legendinfomessage = inlegendinfomessage;

    this.imageurl = imageurl;
    this.dealerinfourl = dealerinfourl;
    this.pleasewaitmessage = pleasewaitmessage;
    this.detailopenedmessage = detailopenedmessage;
    this.filterrecalled = false;

    //window callbacks
    this.win.resizeaction = this._winresizeaction;
    this.win.drawfilteraction = this._filter_drawer_fct;

    // fenstergröße ändern
    this.win.onresize = function() {
        //alert("this.win.onresize");
        this.resizeaction(this, this.mapdiv, this.filterdiv, this.map);
    }

    // schliesen des fensters
    this.win.onbeforeunload = function() {
        GUnload(); // insbesondere für IE Speicherprobleme
    }

    // wichtiges gleich bei initialisierung ausführen
    this._winresizeaction(this.win, this.mapdiv, this.filterdiv);
}

GoogleMapWorldOverview.prototype.DrawMap = function () {
    
    this.map = new GMap2(this.mapdiv);
    this.map.setMapType(G_NORMAL_MAP); //G_NORMAL_MAP,G_HYBRID_MAP
    this.map.removeMapType(G_SATELLITE_MAP);
    this.map.addControl(new GLargeMapControl());
    this.map.addControl(new GMapTypeControl());
    this.map.enableScrollWheelZoom();


    var EuropaGLat = "45.95115";
    var EuropaGLng = "-34.453125";

    EuropaGLat = EuropaGLat.replace(".", ",");
    EuropaGLng = EuropaGLng.replace(".", ",");

    this.map.setCenter(new GLatLng(toNumber(EuropaGLat), toNumber(EuropaGLng)), 3); // EUROPAKARTE
    
    
    this.map.checkResize();

    var filtfct = this._filter_data_fct;
    var markfct = this.__map_draw_markers;
    var filturl = this.datafilterurl;
    var selfobj = this.me;
    var mapobj = this.map;


    GEvent.addListener(mapobj, 'zoomend', function() {
        filtfct(selfobj, __mapsearchactiondelay);
    });

    GEvent.addListener(mapobj, 'dragend', function() {
        filtfct(selfobj, __mapsearchactiondelay);
    });
}

GoogleMapWorldOverview.prototype.DrawFilter = function() {

    this._filter_drawer_fct(this.filterdiv, this.datafilterurl);
}



////////////////////////////////////////////////////////////////////////////////////////////////////
// VERZÖGERT EINEN FUNKTIONSAUFRUF
// verzögert so lange bis kein Trigger Event innerhalb der ms aufgetreten ist.
////////////////////////////////////////////////////////////////////////////////////////////////////

FunctionDelayer = function(name, successfunction, obj, ms) {

    this.name = name;
    this.succobject = obj;
    this.succfunction = successfunction;
    this.ms = ms;

    this.triggered = null;

    this.CheckWait = function(objectname) {

        if (window["fctdelayer_" + objectname].triggered == false) {
            // funktion aufrufen
            window["fctdelayer_" + objectname].triggered = null;
            successfunction(obj);
        } else {
            // es folgt ein weiterer aufruf
            window["fctdelayer_" + objectname].triggered = false;
            window.setTimeout("window[\"fctdelayer_" + objectname + "\"].CheckWait(\"" + objectname + "\")", window["fctdelayer_" + objectname].ms);
        }
    }
}

FunctionDelayer.prototype.Trigger = function() {

    if (this.triggered == false) {
    
        this.triggered = true;
        
    } else if (this.triggered == null) {

        this.triggered = false;
        window["fctdelayer_" + name] = this;
        window.setTimeout("window[\"fctdelayer_" + name + "\"].CheckWait(\"" + name + "\")", this.ms);
    }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// PARAMETER READER
////////////////////////////////////////////////////////////////////////////////////////////////////

ParameterReader = function(paramarray) {
    this.array = paramarray;
}

ParameterReader.prototype.Get = function (name) {
    return this.array[name];
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// GOOGLE MAPS LOGIK FÜR DIE NORMALE HÄNDLERSUCHE
////////////////////////////////////////////////////////////////////////////////////////////////////

GoogleMapOverview = function() {

    this.me = null;                     // Zeiger auf eigene Instanz
    this.imageurl = null;               // Pfad zu den Bildern
    this.mapdiv = null;                 // div der map
    this.map = null;                    // Die map selbst

    this.markers = new Array();         // Die aktuellen Marker auf der Karte

    this.transparams = null;            // Array mit allen benötigten übersetzungen
    this.defaultlocationdivid = null;   // DivId mit den Koordinaten und Zoomfaktor der Standardposition

    this.geocodeswriterurl = null;      // Url zu Controller zum Lesen der Daten
    this.dealerinfourl = null;          // Url zum Detail - Popup (Sprechblase)

    this.functiondelayersearch = null;  // Verzögerer für die Suche


    // ALLE MAP MARKER WIEDER ENTFERNEN
    this._map_clear_markers = function() {

        for (var cnt = 0; cnt < this.markers.length; cnt++) {
            this.map.removeOverlay(this.markers[cnt]);
        }

        this.markers = new Array(); // Alle Markers wurden gelöscht.
    }

    // HILFSFUNKTION UM EINEN MARKER HINZUZUFÜGEN
    this._map_add_marker_to_array = function(marker) {
        this.markers.push(marker);
    }

    // Die Marker auf der Karte positionieren
    this._drawMarkersFromString = function(srcstring, firstcall) {

        var dealers = srcstring.split("#");
        var batch = [];

        this._map_clear_markers();

        if (srcstring != null && srcstring != "" && dealers != null && dealers.length > 1) {

            for (var x = 0; x < dealers.length; x++) {

                var dealersdetails = dealers[x].split(";");

                if (x < dealers.length - 1) {

                    var vLocId = dealersdetails[0];
                    var vLocLat = dealersdetails[1];
                    var vLocLng = dealersdetails[2];
                    var vShrinkCount = dealersdetails[3];
                    var vClusteredIds = dealersdetails[4];
                    var vCouponCount = dealersdetails[5];
                    
                    var marker = map_get_marker(vLocId, vLocLat, vLocLng, 2, vShrinkCount,vCouponCount, this.me, vClusteredIds);

                    this.map.addOverlay(marker);
                    this._map_add_marker_to_array(marker);

                } else {

                    if (firstcall == true) {

                        // Der letzte Punkt bildet das Zentrum des Suchergebnisses
                        var vLatCenter = dealersdetails[0];
                        var VLngCenter = dealersdetails[1];
                        var vZoom = dealersdetails[2];

                        this.map.setCenter(new GLatLng(parseFloat(vLatCenter), parseFloat(VLngCenter)), parseInt(vZoom));
                    }
                }
            }
        }
    }

    // Liest die Daten neu und erstellt die Punkte (verzögert)
    this._filterfunction_delayed = function(self, firstcall) {

        if (firstcall == null) firstcall = false;

        self.overlaymessage = putGoogleSearchMapPleaseWaitMessage(self.mapdiv, self.transparams.Get("loading_locations"), "relative");

        var vIdString = document.getElementById("_dealerSearchResultMapDealerIds");
        if (vIdString != null && vIdString.innerHTML != null && vIdString.innerHTML != "") {

            var vZoom = self.map.getZoom();

            var llpoint_lo = self.map.fromContainerPixelToLatLng(new GPoint(0, 0));
            var llpoint_ru = self.map.fromContainerPixelToLatLng(new GPoint(self.mapdiv.clientWidth, self.mapdiv.clientHeight));

            $.post(self.geocodeswriterurl, { ids: vIdString.innerHTML, zoom: vZoom, pointlolat: llpoint_lo.lat(), pointlolng: llpoint_lo.lng(), pointrulat: llpoint_ru.lat(), pointrulng: llpoint_ru.lng() },

                function(data) {
                    self._drawMarkersFromString(data, firstcall);
                    self.overlaymessage.Clear();
                }
            );
        }
    }

    // Liest die Daten neu und erstellt die Punkte
    this._filterfunction = function(self) {
     
        if (self.functiondelayersearch == null) {

            self.functiondelayersearch = new FunctionDelayer
            (
                "googlemap_fctdelay_search",
                self._filterfunction_delayed, self, __mapsearchactiondelay
             );
        }

        self.functiondelayersearch.Trigger();
    }

    // Karte mit der Default Location und default Einstellungen befüllen    
    this._prefillmap = function(self) {

        //GUnload();

        this.map = new GMap2(self.mapdiv);
        this.map.setMapType(G_NORMAL_MAP);
        this.map.removeMapType(G_SATELLITE_MAP);
        this.map.addControl(new GLargeMapControl());
        this.map.addControl(new GMapTypeControl());
        this.map.enableScrollWheelZoom();

        this.map.checkResize();


        var bDefaultCenter = true;
        var defaultLocationDiv = document.getElementById(self.defaultlocationdivid);

        if (defaultLocationDiv != null) {

            var vSplited = defaultLocationDiv.innerHTML.split(";");
            this.map.setCenter(new GLatLng(parseFloat(vSplited[0]), parseFloat(vSplited[1])), parseInt(vSplited[2]));

            bDefaultCenter = false;
        }

        if (bDefaultCenter == true) {
            this.map.setCenter(new GLatLng(0, 0), 7);
        }

        this.map.checkResize();

        this._filterfunction_delayed(self, true);

        GEvent.addListener(this.map, 'zoomend', function() { self._filterfunction(self); });
        GEvent.addListener(this.map, 'dragend', function() { self._filterfunction(self); });
    }
}

GoogleMapOverview.prototype.GetMap = function () {
    return this.map;    
}

GoogleMapOverview.prototype.Init = function(win, mapdivid, deflocdivId, imagepath, geocodewriterpath, dealerinfopath, transarray) {

    this.me = this;
    this.mapdiv = document.getElementById(mapdivid);
    this.defaultlocationdivid = deflocdivId;
    this.transparams = new ParameterReader(transarray);
    this.geocodeswriterurl = geocodewriterpath;
    this.imageurl = imagepath;
    this.dealerinfourl = dealerinfopath;

    this._prefillmap(this.me);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// ALLGEMEINE FUNKTIONEN
////////////////////////////////////////////////////////////////////////////////////////////////////

// ROLLOVER EINES DIVS
function change_css(ele, classname) {
    ele.className = classname;
}


// HILFSFUNKTION FÜR CHECKBOXENAUSWAHL
function select_checkboxes_with_filterprefix_and_value(vprefixname,values) {

	
    var vResString = "";
    var vResStringAll = "";

    var vCidPrefix = vprefixname;
    var idx = 0;

    var vnochekced = 0;


    var myvalues = values.split(",");

    do {

        vEle = document.getElementById(vCidPrefix + idx);

        // selektierte ids
        if (vEle != null) {

            for (var cnt = 0; cnt < myvalues.length; cnt++) {
                if (vEle.value == myvalues[cnt]) {
                    vEle.checked = true;
                } else {
                    vEle.checked = false;
                }
            }
        }

        idx++;

    } while (vEle != null);

    return;
}


// ZOOMT IN EINEN BESTIMMTEN BEREICH
function map_zoom_area(map, vLat, vLng, vZoom) {

	map.setCenter(new GLatLng(parseFloat(vLat), parseFloat(vLng)), parseInt(vZoom));
    map.checkResize();
}


// ERSTELLT EINEN NEUEN MARKER FÜR EIN LAND
function map_get_marker_countries(self, vCountryNumber, vCountryLocLat, vCountryLocLng, vIsHeadquater, vCLat, vCLng, vCZoom) {

    var specialIcon = new GIcon(G_DEFAULT_ICON);

    if (vIsHeadquater == "True") {
        specialIcon.image = self.imageurl + "/googlemaps_point_headquater.gif"
        specialIcon.iconSize = new GSize(24, 24);
        specialIcon.shadow = null;
        specialIcon.iconAnchor = new GPoint(12, 12);
    } else {
        specialIcon.image = self.imageurl + "/googlemaps_point_lyonesscountry.gif";
        specialIcon.iconSize = new GSize(24, 24);
        specialIcon.shadow = null;
        specialIcon.iconAnchor = new GPoint(12, 12);
    }

    var disptitle = "";

    var markerOptions = { icon: specialIcon, title: disptitle };
    var point = new GLatLng(vCountryLocLat, vCountryLocLng);
    var marker = new GMarker(point, markerOptions);

    GEvent.addListener(marker, "click", function() { getDI_Country(marker, self.countryinfourl, vCountryNumber, vIsHeadquater); });
    GEvent.addListener(marker, "dblclick", function() { map_zoom_area(self.map, vCLat, vCLng, vCZoom); });
   
    return marker;
} 

// ERSTELLT EINEN NEUEN MARKER FÜR EINEN HÄNDLER
function map_get_marker (vLocId, vLocLat, vLocLng, variant, vShrinkCount,vCouponCount, self, clusteredids) {


    // aktuellen Karten Zoom ermitteln
    var vCurrentZoom = self.map.getZoom();
    var vNewZoom = vCurrentZoom + 1;
    if (vNewZoom > 18) vNewZoom = 18;

    var specialIcon = new GIcon(G_DEFAULT_ICON);
    if (vShrinkCount <= 1) {   
    	if (vCouponCount >= 1) {
    		specialIcon.image = self.imageurl + "/googlemaps_point_coupon.gif";
    	} else {
    		specialIcon.image = self.imageurl + "/googlemaps_point.gif"
    	}
        specialIcon.iconSize = new GSize(15, 20);
        specialIcon.shadow = null;
        specialIcon.iconAnchor = new GPoint(0, 0);
       } else {
			if (vCouponCount >= 1) {
       			specialIcon.image = self.imageurl + "/googlemaps_point_big_coupon.gif";
			} else {
       			specialIcon.image = self.imageurl + "/googlemaps_point_big.gif";
			}
        specialIcon.iconSize = new GSize(24, 24);
        specialIcon.shadow = null;
        specialIcon.iconAnchor = new GPoint(12, 12);
    }

    var disptitle = vShrinkCount + "";
    if (vShrinkCount <= 1) disptitle = "";

    var markerOptions = { icon: specialIcon, title: disptitle };
    var point = new GLatLng(vLocLat ,vLocLng);
    var marker = new GMarker(point, markerOptions);

    GEvent.addListener(marker, "click", function() { getDI(self.dealerinfourl, vLocId, marker, variant, vShrinkCount, clusteredids); });
    GEvent.addListener(marker, "dblclick", function() { map_zoom_area(self.map, vLocLat, vLocLng, vNewZoom); });

    return marker;
}


function doGoogleMapHandling(mapdivid) {

    // Wir benötigen dieses Timeout da ansonsten zwar der Ajax Call fertig ist aber
    // das HTML im Anzeige-DIV noch nicht aktualisiert ist.
    // Somit wäre das DIV "googlemap" noch nicht zu finden und wir erhalten im GMap2(...) eine
    // Javascript Fehlermeldung

    setTimeout("_doGoogleMapHandling('" + mapdivid + "')", 500);
}

// Google Map Handling
function _doGoogleMapHandling(mapdivid) {

    if (document.getElementById(mapdivid) == null) {
        doGoogleMapHandling(mapdivid);
        return
    }

    window.googlemapinitfunction();
}

// Bitte Warten Box für Google Map
function putGoogleSearchMapPleaseWaitMessage(mapdiv, message, pos) {

    var om = new OverlayMessage(mapdiv, pos);
    om.Set(message);

    return om;
}


// Funktion zum Aufrufen des Länder Infos (Sprechblase bei Klick auf Land)
function getDI_Country(marker, url, vCountryNumber, IsHeadquater) {

	var url = url + vCountryNumber + "&Variante=1&IsHeadquater=" + IsHeadquater;

	$.get(url, function(data) {
		
		infohtml = data;

		if (marker != null) {
			marker.openInfoWindowHtml(infohtml);
		} else {
			alert("no marker");
			return;
		}
	});
}


// Funktion zum Aufrufen des DealerInfos (Sprechblase bei Klick auf Händler)
function getDI(url, id, marker, variante, shrink, clusterids) {
	
    if (clusterids == null || clusterids == undefined) clusterids = "";

    
    var url = url; //+ id + "&Variante=" + variante + "&ShrinkCount=" + shrink + "&ClusteredDealerIds=" + clusterids;

    
    $.post(url,{DealerLocationID: id,Variante: variante, ShrinkCount:shrink,ClusteredDealerIds:clusterids}, function(data) {
    	
    	infohtml = data;

    	if (marker != null) {

    		marker.openInfoWindowHtml(infohtml);
    	} else {
    		alert("no marker");
    		return;
    	}
    });

    return;
}


function RegisterObjectInWindow(name, obj) {
    
    window[name] = obj;
}

function GetObjectFromWindow(name) {
    return window[name];
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// LOGIK FÜR HÄNDLERSUCHE -> WEGBESCHREIBUNG AUF MAP ERZEUGEN
////////////////////////////////////////////////////////////////////////////////////////////////////

DirectionSpeller = function(map, refresherfunction) {


    this.map = map;
    this.mapdiv = document.getElementById(map.getContainer().id);

    this.spellerarea = document.createElement('div');
    this.spellerarea_title = document.createElement('div');
    this.spellerarea_title_title = document.createElement('div');
    this.spellerarea_closer = document.createElement('div');
    this.spellerarea_minimizer = document.createElement('div');
    this.spellerarea_filter = document.createElement('div');
    this.spellerarea_displayarea = document.createElement('div');
    this.spellerarea_displayarea_innerarea = document.createElement('div');
    this.spellerarea_displayarea_innerarea.id = 'google_map_direction_speller_inner_display_area';
    this.spellerarea_refresher = document.createElement('input');
    this.spellerarea_refresher.setAttribute("type", "button");

    this.mapdiv.appendChild(this.spellerarea);
    this.spellerarea.appendChild(this.spellerarea_title);
    this.spellerarea.appendChild(this.spellerarea_displayarea);
    this.spellerarea.appendChild(this.spellerarea_filter);
    this.spellerarea_title.appendChild(this.spellerarea_closer);
    this.spellerarea_title.appendChild(this.spellerarea_minimizer);
    this.spellerarea_title.appendChild(this.spellerarea_title_title);

    this.directions = new GDirections(this.map, this.spellerarea_displayarea_innerarea);
    this.spellerarea_refresher.onclick = refresherfunction;

    this.visdisplayed = "";

    this.areawidth = '270';
    this.filterheight = '110';

    this.isworldmap = false;
    this.minimized = null;

    window.googlemapspellerarea = this;

    // MESSAGES
    this.messages_routefrom = "from";
    this.messages_routeto = "to";
    this.messages_title = "route description";
    this.messages_refresh = "calculate route";
    this.messages_no_data_found = "no data found";


    // SETTINGS FÜR DEN HAUPTBEREICH
    this.spellerarea.id = 'google_map_direction_speller';
    //this.spellerarea.style.opacity = '.90';
    //this.spellerarea.style.filter = 'alpha(opacity=90)';
    //this.spellerarea.style.border = "solid 4px red";

    // SETTINGS FÜR DIE TITELZEILE
    this.spellerarea_title.id = 'google_map_direction_speller_title';

    // SETTINGS FÜR DAS SCHLIESSEN ICON
    this.spellerarea_closer.id = 'google_map_direction_speller_closer';
    this.spellerarea_closer.style.cursor = 'pointer';

    // SETTINGS FÜR DAS MINIMIEREN ICON
    this.spellerarea_minimizer.id = 'google_map_direction_speller_minimizer';
    this.spellerarea_minimizer.style.cursor = 'pointer';


    var meself = this;

    this.spellerarea_closer.onclick = function() {

        var v_google_map_direction_speller = document.getElementById('google_map_direction_speller');
        if (v_google_map_direction_speller != null) {
            v_google_map_direction_speller.style.display = "none";
        }

        if (meself.directions != null) {
            meself.directions.clear();
        }
    }

    this.spellerarea_minimizer.onclick = function() {

        var vSpellerFilter = document.getElementById("google_map_direction_speller_filter");
        var vSpellerDispArea = document.getElementById("google_map_direction_speller_displayarea");
        var vSpellerArea = document.getElementById("google_map_direction_speller");
        var vTitle = document.getElementById("google_map_direction_speller_title");

        if (vSpellerFilter != null && vSpellerDispArea != null && vSpellerArea != null && vTitle != null) {

            if (window.googlemapspellerarea.minimized == null || window.googlemapspellerarea.minimized == false) {

                vSpellerFilter.style.display = "none";
                vSpellerDispArea.style.display = "none";

                vSpellerArea.style.height = "30px"; // TITEL HÖHE

                window.googlemapspellerarea.minimized = true;

            } else {

                vSpellerFilter.style.display = "block";
                vSpellerDispArea.style.display = "block";

                window.googlemapspellerarea.RefreshSize();
                window.googlemapspellerarea.minimized = false;
            }
        }
    }


    this.spellerarea_title_title.innerHTML = "<div id='google_map_direction_speller_title_title'>" + this.messages_title + "</div>";

    // SETTINGS FÜR DEN ANZEIGEBEREICH
    this.spellerarea_displayarea.id = 'google_map_direction_speller_displayarea';
    this.spellerarea_displayarea.appendChild(this.spellerarea_displayarea_innerarea);

    // SETTINGS FÜR DEN FILTERBEREICH
    this.spellerarea_filter.id = 'google_map_direction_speller_filter';
    this.spellerarea_filter.innerHTML = "" +
            "<table cellpadding='0' cellspacing='0' border='0' style='width:100%;' id='google_map_direction_speller_filter_table'>" +
            "   <tr>" +
            "       <td style='width:2%'></td>" +
            "       <td style='width:96%' align='left'><div id='google_map_direction_speller_filter_from_message'>" + this.messages_routefrom + "</div></td>" +
            "       <td style='width:2%'>&nbsp;</td> " +
            "   </tr>" +
            "   <tr>" +
            "       <td style='width:2%'></td>" +
            "       <td style='width:96%' align='right'><input type='text' id='googleroutefrom' style='width:260px' onkeypress=\"return submitOnEnter(event,'google_map_direction_speller_filter_refresher');\" /></td>" +
            "       <td style='width:2%'>&nbsp;</td> " +
            "   </tr>" +
            "   <tr>" +
            "       <td style='width:2%'></td>" +
            "       <td style='width:96%' align='left'><div id='google_map_direction_speller_filter_to_message'>" + this.messages_routeto + "</div></td>" +
            "       <td style='width:2%'>&nbsp;</td> " +
            "   </tr>" +
            "   <tr>" +
            "       <td style='width:2%'></td>" +
            "       <td style='width:96%' align='right'><input type='text' id='googlerouteto' style='width:260px' onkeypress=\"return submitOnEnter(event,'google_map_direction_speller_filter_refresher');\" /></td>" +
            "       <td style='width:2%'>&nbsp;</td> " +
            "   </tr>" +
            "   <tr>" +
            "       <td style='width:98%' aling='right' colspan='2' id='google_map_direction_speller_filter_refresherholder'></td>" +
            "       <td style='width:2%'></td>" +
            "   </tr>" +
            "   <tr>" +
            "       <td colspan='3'>&nbsp;</td>" +
            "   </tr>" +
            "</table>";

    // FUNKTIONEN
    this.refreshroute = function() {
        DirectionSpeller.ReFreshRoute(this.directions, this.messages_no_data_found);
    }

};

DirectionSpeller.CheckRefreshVisibility = function() {

    var fldrefresh = document.getElementById("google_map_direction_speller_filter_refresher");
    
  
    var fld1 = document.getElementById("googleroutefrom");
    var fld2 = document.getElementById("googlerouteto");

    if (fld1 == null || fld2 == null ||
            fld1.value == null || fld1.value == "" ||
            fld2.value == null || fld2.value == "") {

        fldrefresh.className = 'google_map_direction_speller_filter_refresher_inactive';
        fldrefresh.onmousedown = function() { return false; }
        return false;

    } else {

        fldrefresh.onmousedown = function() { return true; };
        fldrefresh.className = 'google_map_direction_speller_filter_refresher';
        return true;
    }
 
}


var vGlobalDirection = null;
var vGlobalCheckCount = 0;

function __CheckDirectionStatus(errmsg) {

    if (vGlobalDirection != null) {

        if (vGlobalDirection.getStatus().code == G_GEO_SERVER_ERROR && vGlobalCheckCount < 10) {
            vGlobalCheckCount++;
            window.setTimeout("__CheckDirectionStatus('" + errmsg + "')", 500);
        } else {

            if (vGlobalDirection.getStatus().code == G_GEO_SUCCESS) {
                // ALLES OK -> ROUTE WURDE GEFUNDEN
            } else {
                var vResultEle = document.getElementById("google_map_direction_speller_inner_display_area");
                if (vResultEle != null) {

                    var vTblMsg = "<table cellpadding='0' cellspacing='0' border='0' style='width:100%'>" +
                                  "     <tr>" +
                                  "       <td style='width:2%'></td>" +
                                  "       <td style='width:96%'></td>" +
                                  "       <td style='width:2%'>&nbsp;</td> " +
                                  "     </tr>" +
                                  "     <tr>" +
                                  "       <td style='width:2%'></td>" +
                                  "       <td style='width:96%'>" + errmsg + "</td>" +
                                  "       <td style='width:2%'>&nbsp;</td> " +
                                  "     </tr>" +
                                  "</table>";

                    vResultEle.innerHTML = vTblMsg;
                }
            }
        }
    }
}


DirectionSpeller.ReFreshRoute = function(dir, nodatamsg) {

    var vFromFld = document.getElementById("googleroutefrom");
    vFromFld.onkeyup = DirectionSpeller.CheckRefreshVisibility;

    var vToFld = document.getElementById("googlerouteto");
    vToFld.onkeyup = DirectionSpeller.CheckRefreshVisibility;

    var velerefresh = document.getElementById("google_map_direction_speller_filter_refresher");

    if (DirectionSpeller.CheckRefreshVisibility() == true) {

        var vLocString = "from: " + vFromFld.value + " to: " + vToFld.value;

        var vResultEle = document.getElementById("google_map_direction_speller_inner_display_area");
        if (vResultEle != null) {
            vResultEle.innerHTML = "";
        }

        dir.clear();
        vGlobalDirection = dir;
        dir.load(vLocString)

        vGlobalCheckCount = 0;
        __CheckDirectionStatus(nodatamsg);
    }

}

DirectionSpeller.prototype.IsDisplayed = function() {

    if (this.visdisplayed == "1") {
        return true;
    } else {
        return false;
    }
}

DirectionSpeller.prototype.SetRouteFromMessage = function(msg) {

    this.messages_routefrom = msg;
    var vFromEle = document.getElementById("google_map_direction_speller_filter_from_message");
    if (vFromEle != null) {
        vFromEle.innerHTML = msg;
    }
}

DirectionSpeller.prototype.SetRouteNoDataMessage = function(msg) {
    this.messages_no_data_found = msg;
}

DirectionSpeller.prototype.SetCalcRouteMessage = function(msg) {

    this.messages_refresh = msg;
    var vFromEle = document.getElementById("google_map_direction_speller_filter_refresher");
    if (vFromEle != null) {
        vFromEle.value = msg;
    }
}


DirectionSpeller.prototype.GetFromAdr = function() {
    var vToFld = document.getElementById("googlerouteto");
    if (vToFld != null) {
        return vToFld.value;
    } else {
        return "";
    }
}

DirectionSpeller.prototype.SetRouteToMessage = function(msg) {
    this.messages_routeto = msg;
    var vToEle = document.getElementById("google_map_direction_speller_filter_to_message");
    if (vToEle != null) {
        vToEle.innerHTML = msg;
    }
}

DirectionSpeller.prototype.SetTitle = function(msg) {
    this.messages_title = msg;
    var vTitleEle = document.getElementById("google_map_direction_speller_title_title");
    if (vTitleEle != null) {
        vTitleEle.innerHTML = msg;
    }
}

DirectionSpeller.prototype.SetFromAdr = function(from) {
    var vFromFld = document.getElementById("googleroutefrom");
    if (vFromFld != null) {
        vFromFld.value = from;
    }
}

DirectionSpeller.prototype.SetToAdr = function(to) {
    var vToFld = document.getElementById("googlerouteto");
    if (vToFld != null) {
        vToFld.value = to;
    }
}

DirectionSpeller.prototype.SetWorldMap = function() {
    this.isworldmap = true;
}

DirectionSpeller.prototype.Refresh = function() {
    this.refreshroute();
}

DirectionSpeller.prototype.CreateRefresher = function() {

    var vRefHolder = document.getElementById("google_map_direction_speller_filter_refresherholder");

    if (vRefHolder != null) {

        this.spellerarea_refresher.id = 'google_map_direction_speller_filter_refresher';
        this.spellerarea_refresher.className = 'google_map_direction_speller_filter_refresher';
        this.spellerarea_refresher.value = this.messages_refresh;
      
        vRefHolder.appendChild(this.spellerarea_refresher);
    }
}

DirectionSpeller.prototype.RefreshSize = function() {

    var minvalue = 4;

    if (__gm_is_ie6 == true) {

        this.spellerarea.style.width = this.areawidth + "px";
        this.spellerarea.style.height = (400 - minvalue) + "px";
        this.spellerarea.style.left = (this.mapdiv.clientWidth - this.areawidth - 3) + "px";

        this.spellerarea_displayarea.style.height = (400 - this.filterheight - minvalue - 50) + "px";

        this.spellerarea_displayarea.style.width = this.areawidth - 2 + "px";
        this.spellerarea_displayarea_innerarea.style.width = this.areawidth - 30 + "px";

        this.spellerarea_filter.style.display = "block";
        this.spellerarea_displayarea.style.display = "block";

    } else if (__gm_is_safari) {

        if (this.isworldmap == true) {
            minvalue = 40;
        } else {
            minvalue = 4;
        }

        if (this.isworldmap == true) {
            this.spellerarea.style.position = "absolute";
        }
        
        this.spellerarea.style.width = this.areawidth + "px";
        this.spellerarea.style.height = (this.mapdiv.clientHeight - minvalue) + "px";
        this.spellerarea.style.left = (this.mapdiv.clientWidth - this.areawidth - 4) + "px";

        this.spellerarea_displayarea.style.height = (this.mapdiv.clientHeight - this.filterheight - minvalue - 50) + "px";

        this.spellerarea_displayarea.style.width = this.areawidth - 2 + "px";
        this.spellerarea_displayarea_innerarea.style.width = this.areawidth - 30 + "px";

        this.spellerarea_filter.style.display = "block";
        this.spellerarea_displayarea.style.display = "block";

    } else {

        this.spellerarea.style.width = this.areawidth + "px";
        this.spellerarea.style.height = (this.mapdiv.clientHeight - minvalue) + "px";
        this.spellerarea.style.left = (this.mapdiv.clientWidth - this.areawidth - 3) + "px";

        this.spellerarea_displayarea.style.height = (this.mapdiv.clientHeight - this.filterheight - minvalue - 50) + "px";

        this.spellerarea_displayarea.style.width = this.areawidth - 2 + "px";
        this.spellerarea_displayarea_innerarea.style.width = this.areawidth - 30 + "px";

        this.spellerarea_filter.style.display = "block";
        this.spellerarea_displayarea.style.display = "block";

    }
}

DirectionSpeller.prototype.Display = function() {

    this.RefreshSize();
    this.CreateRefresher();

    this.spellerarea.style.display = "block";

    this.refreshroute();

    this.visdisplayed = "1";
}

DirectionSpeller.prototype.Hide = function() {
    this.spellerarea.style.display = "none";
}


////////////////////////////////////////////////////////////////////////////////////////////////////
// ERZEUGT EINE NACHRICHTEN - MELDUNG AUF DER GOOGLE MAP
////////////////////////////////////////////////////////////////////////////////////////////////////

OverlayMessage = function(container, pos) {

    this.overlay = document.createElement('div');
    container.appendChild(this.overlay);

    this.backgroundColor = '#EAF0F4';
    this.borderColor = '#CEB542';

    this.overlay.style.color = 'black';
    this.overlay.style.fontWeight = 'bold';

    if (pos == "absolute") {
        this.overlay.style.position = 'absolute';
    } else if (pos == "relative" || pos == null) {
        this.overlay.style.position = 'relative';
    }

    this.overlay.style.backgroundColor = this.backgroundColor;
    this.overlay.style.width = '40%';
    this.overlay.style.textAlign = 'center';
    this.overlay.style.marginLeft = 'auto';
    this.overlay.style.marginRight = 'auto';
    this.overlay.style.padding = '2em';
    this.overlay.style.borderWidth = '2px';
    this.overlay.style.borderStyle = 'ridge';
    this.overlay.style.borderColor = this.borderColor;
    this.overlay.style.zIndex = '150';
    this.overlay.style.opacity = '.90';
    this.overlay.style.filter = 'alpha(opacity=90)';
    this.overlay.style.fontSize = "14px";
    this.overlay.style.fontFamily = "Arial,Helvetia,sans-serif";
    this.overlay.style.display = 'none';


    if (pos == "absolute") {
        this.overlay.style.top = __rempx(container.style.top) + Math.round(((__rempx(container.style.height) / 2))) + "px";
        this.overlay.style.left = "25%";
    } else if (pos == "relative" || pos == null) {
        this.overlay.style.top = "40%";
    }
};




OverlayMessage.prototype.Set = function(message) {

    this.overlay.innerHTML = message;
    this.overlay.style.display = '';
};


OverlayMessage.prototype.Clear = function() {
    this.overlay.style.display = 'none';
};


OverlayMessage.prototype.SetBackgroundColor = function(color) {
    this.backgroundColor = this.overlay.style.backgroundColor = color;
};


OverlayMessage.prototype.SetBorderColor = function(color) {
    this.borderColor = this.overlay.style.borderColor = color;
};