/*** JavaScript-funktionen für die Promobil Stellplatz-DB
*    erstellt von B. Hanisch am 12.11.08
***/
/* Variablen für Start-Seite initialisieren */
var HTTP_GET_VARS = new Array();
var centerLat = 50.780444;
var centerLng = 9.180081;
var startZoom = 4;
var map;
var mapbreite;
var maphoehe;
var mapbounds;
var breitekachel = 95;
var hoehekachel = 95;
var kachelarray = new Array();
var kachelneu;
var marker;
var baseIcon;
var clusterIcon;
var clusterIconStart;
var clusterIconStartklein;

var markerOptions;
var clusterOptions;
var clusterOptionsStart;
var clusterOptionsStartklein;

var markerManager;
var clusterManager;

var bounds;
var is_clicked=0;
var is_loaded=0;
var xmlHttp = null;
var xmlHttpListe = null;
var anzahl_listenelement = 10;
var anzahl_jumplist_eintraege = 5;

var sucheZoomlat = "";
var sucheZoomlng = "";
var sucheZoom;

var geocoder;

/*** Funktion initialisiert die Start-Map ***/
function init(){
	retrieve_Parameter();
		
       map = new GMap2(document.getElementById("map"));
	
	//map.zoomIn();
	
	if(HTTP_GET_VARS.length > 0 ){
		sucheZoomStufe();				
	}
	else{
		map.setCenter(new GLatLng(centerLat, centerLng), startZoom);

	}
       map.addControl(new GLargeMapControl());
      	map.addControl(new GMapTypeControl());
	map.enableContinuousZoom();
	//map.enableScrollWheelZoom	();
	var size = map.getSize();

       mapbreite = size.width;
       maphoehe = size.height;
	mapbounds = map.getBounds();
	 
	//alert(mapbounds.getNorthEast());
	//alert(mapbounds.getSouthWest());

	create_icon();
	create_cluster();
	create_cluster_startseite();
	create_cluster_startseite_klein();

	
	xmlHttp = create_xmlHttp();
	xmlHttpListe = create_xmlHttp();

	retrieve_kacheln();
	retrieve_Markers();
	
			
	GEvent.addListener(map, 'zoomend', function(){
		
		if(is_clicked == 1){
			is_clicked = 0;

		}
		else {
			mapbounds = map.getBounds();
			retrieve_kacheln();
			retrieve_Markers();
			
		}

	});
	
	GEvent.addListener(map, 'dragend', function(){
		//alert(map.getCenter());
		if(is_clicked == 1){
			is_clicked == 0;

		}
		else{	
			mapbounds = map.getBounds();
			retrieve_kacheln();
			retrieve_Markers();
		}
	});
	GEvent.addListener(map, 'movestart', function(){
		is_clicked = 0;
		
	});

	GEvent.addListener(map, 'click', function(){
		map.closeInfoWindow();
		is_clicked = 0;
		
	});

	GEvent.addListener(map, 'infowindowopen', function(){
		is_clicked=1;
	});

		
}

/*** ermittelt die GET-Parameter der URL ***/
function retrieve_Parameter(){
	var parameter = decodeURI(window.location.search.substr(1,document.location.search.length));
	//alert(parameter);
	var Ergebnis = parameter.search(/skip.+/);

	if(parameter != '' && Ergebnis == -1){
		HTTP_GET_VARS[0] = new Object();

    		gArr = parameter.split('&');
    		for(i=0; i<gArr.length; ++i)
        	{
       		v='';
			vArr=gArr[i].split('=');
        		if(vArr.length>1){
				v=vArr[1];
				//if(vArr[0] == 'ort' || vArr[0] == 'plz' || vArr[0] == 'land' || vArr[0] == 'region' || vArr[0] == 'bundesland' || vArr[0] == 'stellplatz' || vArr[0] == 'gebuehr' || vArr[0] == 'rubrik' || vArr[0] == 'strom || vArr[0] == 'mobile' || vArr[0] == 'wasser' || vArr[0] == 'wlan' || vArr[0] == 'entsorgung' || vArr[0] == 'tiere'){
				HTTP_GET_VARS[0][unescape(vArr[0])] = unescape(v);
				//}
			}
        	}
    	}

}

/*** ermittelt die Geodaten der Kacheln ***/
function retrieve_kacheln(){
	var i=0;
	var x=0;
	var y=0;
	var hoeheangepasst = (maphoehe*breitekachel)/mapbreite;
		
	kachelneu = '{';
		while ((i+breitekachel) <= mapbreite){
         	while ((x+hoehekachel) <= maphoehe){
			//ecke links oben
			var nordwest = map.fromContainerPixelToLatLng(new GPoint(i,x));
			//marker = new GMarker(nordwest, markerOptions);
			//map.addOverlay(marker);

			//ecke rechts oben
			var nordost = map.fromContainerPixelToLatLng(new GPoint(i+breitekachel,x));
			//marker = new GMarker(nordost, markerOptions);
			//map.addOverlay(marker);


			// Ecke links unten
			var suedwest = map.fromContainerPixelToLatLng(new GPoint(i,x+hoehekachel));
			//marker = new GMarker(suedwest, markerOptions);
			//map.addOverlay(marker);
			
			// Ecke rechts unten
			//var suedost = map.fromContainerPixelToLatLng(new GPoint(i+breitekachel,x+hoehekachel));
			//marker = new GMarker(suedwest, markerOptions);
			//map.addOverlay(marker);

																
			kachelneu += '"p' + y + '":{"nordwestlat":'+ nordwest.lat() +', "nordwestlng":'+ nordwest.lng() +', "nordostlat":'+ nordost.lat() +', "nordostlng":'+ nordost.lng() +', "suedwestlat":'+ suedwest.lat() +', "suedwestlng":'+ suedwest.lng() +' },';

			x += hoehekachel;
			y++;
		}
	      x=0;
	      i+=breitekachel;
		
         }
	kachelneu += ' "p":1}';
	//alert(kachelneu);
	
}
/*** erstellt ein neues Icon für alle Marker der Map ***/
function create_icon(){
	baseIcon = new GIcon();
       baseIcon.image = "/stellplaetze/img/pro_marker.png";
	baseIcon.iconSize = new GSize(47, 40);

	baseIcon.shadow = "/stellplaetze/img/pro_marker_schatten.png";
	baseIcon.shadowSize = new GSize(47, 40);

       baseIcon.iconAnchor = new GPoint(9, 34);
       baseIcon.infoWindowAnchor = new GPoint(15, 2);

	markerOptions = { icon:baseIcon };

}

/*** erstellt ein neues Icon für die Cluster der Map ***/
function create_cluster(){
	clusterIcon = new GIcon();
       clusterIcon.image = "/stellplaetze/img/kachel_90_neu.png";

	clusterIcon.iconSize = new GSize(90, 90);

	clusterIcon.shadow = "";
	clusterIcon.shadowSize = "";

       clusterIcon.iconAnchor = new GPoint(0, 0);
       clusterIcon.infoWindowAnchor = new GPoint(9, 2);

	clusterOptions = { icon:clusterIcon };

}

/*** erstellt ein neues Icon für die Cluster der Startseite ***/
function create_cluster_startseite(){
	clusterIconStart = new GIcon();
       clusterIconStart.image = "/stellplaetze/img/cluster_startseite.png";

	clusterIconStart.iconSize = new GSize(68, 66);

	clusterIconStart.shadow = "";
	clusterIconStart.shadowSize = "";

       clusterIconStart.iconAnchor = new GPoint(0, 0);
       clusterIconStart.infoWindowAnchor = new GPoint(9, 2);

	clusterOptionsStart = { icon:clusterIconStart };

}

/*** erstellt ein neues Icon für die Cluster der Startseite ***/
function create_cluster_startseite_klein(){
	clusterIconStartklein = new GIcon();
       clusterIconStartklein.image = "/stellplaetze/img/cluster_startseite_kleiner.png";

	clusterIconStartklein.iconSize = new GSize(50, 49);

	clusterIconStartklein.shadow = "";
	clusterIconStartklein.shadowSize = "";

       clusterIconStartklein.iconAnchor = new GPoint(0, 0);
       clusterIconStartklein.infoWindowAnchor = new GPoint(9, 2);

	clusterOptionsStartklein = { icon:clusterIconStartklein };

}



/*** erstellt ein AJAX-Object ***/
function create_xmlHttp(){
	var ajax;
	// Mozilla, Opera, Safari sowie Internet Explorer (ab v7)
	if (typeof XMLHttpRequest != 'undefined') {
    		ajax = new XMLHttpRequest();
	}
	if (!ajax) {
    		// Internet Explorer 6 und älter
	if (window.ActiveXObject){
	
		try {
        		ajax = new ActiveXObject("Msxml2.XMLHTTP.6.0");
    		} catch(e) {
        		try {
            		ajax = new ActiveXObject("Microsoft.XMLHTTP");
        		} catch(e) {
            		ajax = null;
			}
    		}
	}
	}
	return ajax;

}
/*** ermittelt die URL ohne Parameter ***/
function retrieve_URL(){
	var url = document.URL;
	var suche = url.indexOf("?");
	url = url.substring(0, suche);
	return url;
}

/*** zeigt das Warte-Icon auf der Map ***/
function show_waitIcon(){
window.setTimeout("", 2000);
	var divwait = document.getElementById("wait");
	divwait.style.display = 'block';

}

/*** verbirgt Warte-Icon auf der Map ***/
function hide_waitIcon(){
	var divwait = document.getElementById("wait");
	divwait.style.display = 'none';

}


/*** fügt einen Marker der Map hinzu ***/
function add_Marker(lat,lng, id, land, img, plz, ort, titel, bis5euro, urltitel){
	
		var marker = new GMarker(new GLatLng(lat,lng), markerOptions);
		map.addOverlay(marker);
		//markerManager.addMarker(marker,0,17);
		var cont = document.createElement("div");
		cont.style.fontFamily = "Verdana,Arial";
  		cont.style.fontSize = "11px";
		
		
		cont.innerHTML = '<a href="http://www.promobil.de/reise/wohnmobilstellplatz-'+ urltitel + '/wohnmobilstellplaetze.276476.7.htm?stellplatzid='+ id +'" target="_blank" style="color:#0001b8;clear:both;"><div style="text-decoration:none;float:left;clear:both;margin-top:3px;padding-bottom:2px;font-size:12px;font-weight:bold;">' + titel + '</div></a><br>';
		cont.innerHTML += '<br/>';
		if(img != undefined){
		cont.innerHTML += '<img src="http://images.stellplatz.promobil.de/'+ img +'" style="float:left;width:90px;margin-right:5px;">';
		}
		cont.innerHTML += '<p>';
		if(land != undefined){
		cont.innerHTML += land + ' - ';
		} 
		if(plz != undefined){
		cont.innerHTML += plz + ' - ';
		} 
		if(ort != undefined){
		cont.innerHTML += ort;
		} 
		cont.innerHTML += '<br/>';

		if(bis5euro == 1){
			cont.innerHTML += 'Bis 5 &euro;<br/>';
		}
		cont.innerHTML += '<b><a href="http://www.promobil.de/reise/wohnmobilstellplatz-' + urltitel + '/wohnmobilstellplaetze.276476.7.htm?stellplatzid='+ id +'" target="_blank" style="color:#0001b8;">mehr &raquo;</a></b></p>';

		GEvent.addListener(marker, "click", function() {
		map.closeInfoWindow();
  		marker.openInfoWindowHtml(cont);
 		});

		GEvent.addListener(marker, "mouseover", function() {
		map.closeInfoWindow();
		marker.openInfoWindowHtml(cont);

  		});


		
}

/*** fügt einen Cluster der Map hinzu ***/
function add_Cluster(nwlat,nwlng, nelat, nelng, swlat, swlng, anz){

	var marker = new GMarker(new GLatLng(nwlat,nwlng), clusterOptions);
	map.addOverlay(marker);
	//clusterManager.addMarker(marker,0,17); 
	
	var rechteck = new GLatLngBounds(new GLatLng(swlat, swlng), new GLatLng(nelat, nelng))
	//alert (rechteck);
	
	var zoomlevel = map.getBoundsZoomLevel(rechteck);
	//alert(zoomlevel);

	var centerrechteck = rechteck.getCenter();
	
	
	GEvent.addListener(marker, 'mouseover', function() {
		marker.openToolTip(anz);
	});

	GEvent.addListener(marker, 'mouseout', function() {
		marker.closeToolTip();
	});
	GEvent.addListener(marker, 'click', function() {
		map.setCenter(centerrechteck, zoomlevel);

	});


}
/*** Tooltip-Overlay-Object erzeugen ***/
function ToolTip(marker, html, width){
	this.html_ = html;
	this.width_ = (width ? width + 'px' : 'auto');
	this.marker_ = marker;
}

ToolTip.prototype = new GOverlay();

ToolTip.prototype.initialize = function(map) {
	var div = document.createElement("div");
	div.style.display = 'none';
	map.getPane(G_MAP_FLOAT_PANE).appendChild(div);
	
	this.map_ = map;
	this.container_ = div;
}

ToolTip.prototype.remove = function() {
	this.container_.parentNode.removeChild(
		this.container_);
}

ToolTip.prototype.copy = function() {
	return new ToolTip(this.html_);
}

ToolTip.prototype.redraw = function(force) {
	if (!force) return;
	
	var pixelLocation = this.map_.fromLatLngToDivPixel(
	this.marker_.getPoint());
	this.container_.innerHTML = this.html_;
	this.container_.style.position = 'relative';
	this.container_.style.left = (pixelLocation.x - 20) + "px";
	this.container_.style.top = (pixelLocation.y - 80) + "px";
	//this.container_.style.left = "px";
	//this.container_.style.top = (pixelLocation.y-70) + "px";

	this.container_.style.width = "141px";
	this.container_.style.height = "71px";

	this.container_.style.font ='11px/14px verdana, arial, sans';
	this.container_.style.border = 'none';
	this.container_.style.backgroundImage = 'url(/stellplaetze/img/tooltip.png)';
	this.container_.style.backgroundRepeat = 'no-repeat';
	this.container_.style.padding = '8px';
	this.container_.style.whiteSpace = 'nowrap';
	if(this.width_ != 'auto') 
		this.container_.style.overflow = 'hidden';
	this.container_.style.display = 'block';
} 

GMarker.prototype.ToolTipInstance = null;

GMarker.prototype.openToolTip = function(anz) {
	// don't show the tool tip if there is acustom info window
	if(this.ToolTipInstance == null) {
		var content = anz + " Stellpl&auml;tze.<br>Bitte klicken Sie hier<br>f&uuml;r Stellpl&auml;tze<br>in diesem Gebiet.";
		this.ToolTipInstance = new ToolTip(this,content)
		map.addOverlay(this.ToolTipInstance);
	}
}

GMarker.prototype.openToolTipStartseite = function(land) {
	// don't show the tool tip if there is acustom info window
	if(this.ToolTipInstance == null) {
		var content = "Bitte klicken Sie hier<br>um die Stellpl&auml;tze<br>in " + land + "<br>anzuzeigen.";
		this.ToolTipInstance = new ToolTip(this,content)
		map.addOverlay(this.ToolTipInstance);
	}
}


GMarker.prototype.closeToolTip = function() {
	if(this.ToolTipInstance != null) {
		map.removeOverlay(this.ToolTipInstance);
		this.ToolTipInstance = null;
	}
}

GMarker.prototype.closeToolTipStartseite = function() {
	if(this.ToolTipInstance != null) {
		map.removeOverlay(this.ToolTipInstance);
		this.ToolTipInstance = null;
	}
}
/*** legt den Ausschnitt/die Zoomstufe anhand des ausgewählten Landes fest ***/
function sucheZoomStufe(){
//alert(HTTP_GET_VARS[0]['land']);

	switch(HTTP_GET_VARS[0]['land']){
		case 'D': 
		//Deutschland
		sucheZoomstufeByRegion();
		//sucheZoomlat = "50.875311";
		//sucheZoomlng = "10.327148";
		//sucheZoom = 6;
		break;
							
		case 'A': 
		//Oesterreich
		sucheZoomlat = "47.420654";
		sucheZoomlng = "13.392334";
		sucheZoom = 7;
		break;
	
		case 'CH':
		//Schweiz
		sucheZoomlat = "46.905246";
		sucheZoomlng = "8.360596";
		sucheZoom = 7;
		break;

		case 'I':
		//Italien
	 	sucheZoomlat = "41.93";
		sucheZoomlng = "12.1";
		sucheZoom = 6;
		break;
		
		case 'F':
		//Frankreich
	 	sucheZoomlat = "47.33";
		sucheZoomlng = "2.17";
		sucheZoom = 6;
		break;

		default:
		//Europa
		sucheZoomlat = "50.780444";
		sucheZoomlng = "9.180081";

		sucheZoom = 4;
		break;

	}
	var obj = new GLatLng(sucheZoomlat,sucheZoomlng);
	map.setCenter(new GLatLng(sucheZoomlat,sucheZoomlng), sucheZoom);

}
/*** legt den Ausschnitt/die Zoomstufe anhand des ausgewählten Bundeslandes fest ***/
function sucheZoomstufeByRegion(){
	if(HTTP_GET_VARS[0]['bundesland'] != ""){
		switch(HTTP_GET_VARS[0]['bundesland']){
		case 'BW': 
		//Ba.-Wü. 
		sucheZoomlat = "48.687334";
		sucheZoomlng = "9.014282";
		sucheZoom = 8;
		break;
							
		case 'BAY': 
		//Bayern 
		sucheZoomlat = "48.741701";
		sucheZoomlng = "11.546631";
		sucheZoom = 7;
		break;
	
		case 'HES':
		//Hessen 
		sucheZoomlat = "50.520775";
		sucheZoomlng = "8.8166";
		sucheZoom = 8;
		break;
		
		case 'RPF':
		//Rheinland-pfalz 
		sucheZoomlat = "49.93000812460691";
		sucheZoomlng = "7.481689453125";
		sucheZoom = 8;
		break;
		
		
		case 'NRW':
		//Nordrhein-Westfalen 
		sucheZoomlat = "51.91716758909015";
		sucheZoomlng = "7.8662109375";
		sucheZoom = 8;
		break;
		
		case 'SAR':
		//Saarland  
		sucheZoomlat = "49.44670029695473";
		sucheZoomlng = "7.1356201171875";
		sucheZoom = 9;
		break;


		case 'NS':
		//Niedersachsen  
		sucheZoomlat = "52.928774525801366";
		sucheZoomlng = "9.239501953125";
		sucheZoom = 7;
		break;
		
		case 'SH':
		//schleswig-Holstein 
		sucheZoomlat = "54.149567212540525";
		sucheZoomlng = "10.1513671875";
		sucheZoom = 7;
		break;


		case 'BB':
		//Brandenburg 
		sucheZoomlat = "52.35211857272093";
		sucheZoomlng = "13.6065673828125";
		sucheZoom = 8;
		break;

		case 'SAC':
		//Sachsen
		sucheZoomlat = "51.15867686442365";
		sucheZoomlng = "13.5791015625";
		sucheZoom = 7;
		break;

		case 'SAA':
		//Sachsen-Anhalt
		sucheZoomlat = "52.22779941887071";
		sucheZoomlng = "11.88720703125";
		sucheZoom = 7;
		break;

		case 'MV':
		//Mecklenburg-Vorpommern 
		sucheZoomlat = "53.657661020298";
		sucheZoomlng = "12.711181640625";
		sucheZoom = 7;
		break;

		case 'TH':
		//Thueringen 
		sucheZoomlat = "51.04830113331224";
		sucheZoomlng = "11.2060546875";
		sucheZoom = 8;
		break;

		default:
		//Deutschland
		sucheZoomlat = "50.875311";
		sucheZoomlng = "10.327148";
		sucheZoom = 6;
		break;

		}

	}
	else{
		//Deutschland
		sucheZoomlat = "50.875311";
		sucheZoomlng = "10.327148";
		sucheZoom = 6;

	}

}

/*** statische Übersicht von Europa ***/
function retrieve_overview(){

//var m = new GMarker( new GLatLng(49.2236111111,13.5944444444), markerOptions);
//map.addOverlay(m);

	if (xmlHttp) {
							
			xmlHttp.open("GET", '/stellplaetze/retrieve_anzahl.php?_tuiro', true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.onreadystatechange = function () {
        		if (xmlHttp.readyState == 4) {
				var jscript = xmlHttp.responseText;
				eval(jscript);
				var liste = document.getElementById("stellplatzliste");
				liste.innerHTML = "";

				var anzeige_anzahl = document.getElementById("stellplatzanzahl");
				if(typeof gesamtanzahl  != 'undefined'){
					anzeige_anzahl.innerHTML = "Anzeige: " + gesamtanzahl + " Stellpl&auml;tze";
				}							
			}
										
   			};
			xmlHttp.send(null);
		
		} //ende xmlHttp

	/*** Deutschland ***/
	var m = new GMarker(new GLatLng(52.0,6.5), clusterOptionsStart);
	map.addOverlay(m);
	GEvent.addListener(m, 'click', function() {
		map.setCenter(new GLatLng(50.875311,10.327148), 6);

	});
	GEvent.addListener(m, 'mouseover', function() {
		m.openToolTipStartseite('Deutschland');
	});

	GEvent.addListener(m, 'mouseout', function() {
		m.closeToolTipStartseite();
	});
	/*** Deutschland ***/

	/*** Österreich ***/
	var oe = new GMarker(new GLatLng(49.2,11.952637), clusterOptionsStartklein);
	map.addOverlay(oe);
	GEvent.addListener(oe, 'click', function() {
		map.setCenter(new GLatLng(47.420654,13.392334), 7);

	});
	GEvent.addListener(oe, 'mouseover', function() {
		oe.openToolTipStartseite('&Ouml;sterreich');
	});

	GEvent.addListener(oe, 'mouseout', function() {
		oe.closeToolTipStartseite();
	});
	
	/*** Österreich ***/

	/*** Schweiz ***/
	var ch = new GMarker(new GLatLng(47.9,6.8), clusterOptionsStartklein);
	map.addOverlay(ch);
	GEvent.addListener(ch, 'click', function() {
		map.setCenter(new GLatLng(46.84516443029276,8.41552734375), 7);

	});
	GEvent.addListener(ch, 'mouseover', function() {
		ch.openToolTipStartseite('Schweiz');
	});

	GEvent.addListener(ch, 'mouseout', function() {
		ch.closeToolTipStartseite();
	});
	
	/*** Schweiz ***/

	/*** Frankreich ***/
	var fr = new GMarker(new GLatLng(48.5,0.2), clusterOptionsStart);
	map.addOverlay(fr);
	GEvent.addListener(fr, 'click', function() {
		map.setCenter(new GLatLng(47.33882269482199, 2.17529296875), 6);

	});
	GEvent.addListener(fr, 'mouseover', function() {
		fr.openToolTipStartseite('Frankreich');
	});

	GEvent.addListener(fr, 'mouseout', function() {
		fr.closeToolTipStartseite();
	});
	
	/*** Frankreich ***/

	/*** Italien ***/
	var it = new GMarker(new GLatLng(44.03,11.20), clusterOptionsStart);
	map.addOverlay(it);
	GEvent.addListener(it, 'click', function() {
		map.setCenter(new GLatLng(41.93, 12.1), 6);

	});
	GEvent.addListener(it, 'mouseover', function() {
		it.openToolTipStartseite('Italien');
	});

	GEvent.addListener(it, 'mouseout', function() {
		it.closeToolTipStartseite();
	});
	
	/*** Italien ***/


	hide_waitIcon();


}

/*** Führt ein Neuladen des Banners und des Statistik-Pixels aus ***/
function updateBanner(){

if(document.getElementById("leaderboard") != null){
	document.getElementById("leaderboard").innerHTML = document.getElementById("leaderboard").innerHTML;
}
if(document.getElementById("skyscraper") != null){
	document.getElementById("skyscraper").innerHTML = document.getElementById("skyscraper").innerHTML;
}
if(document.getElementById("bannerhpa") != null){
	document.getElementById("bannerhpa").innerHTML = document.getElementById("bannerhpa").innerHTML;
}
if(document.getElementById("bannerfullsize") != null){
	document.getElementById("bannerfullsize").innerHTML = document.getElementById("bannerfullsize").innerHTML;
}
if(document.getElementById("track") != null){
	document.getElementById("track").innerHTML = document.getElementById("track").innerHTML;
}

}

/*** generiert Such-Parameter-String zur Übergabe an PHP-Script ***/
function create_parameter(){
	var parameter;
		if(typeof HTTP_GET_VARS[0]['land'] != 'undefined'){
			parameter = '&land='+HTTP_GET_VARS[0]['land'];
		}

		if(typeof HTTP_GET_VARS[0]['plz'] != 'undefined' && HTTP_GET_VARS[0]['plz'] != 'PLZ'){	
			parameter += '&plz='+HTTP_GET_VARS[0]['plz'];
		}

			
		if(typeof HTTP_GET_VARS[0]['ort'] != 'undefined' && HTTP_GET_VARS[0]['ort'] != 'Ort'){	
			parameter += '&ort=' + HTTP_GET_VARS[0]['ort'];
		}

		if(typeof HTTP_GET_VARS[0]['region'] != 'undefined'){
			parameter += '&region=' + encodeURI(HTTP_GET_VARS[0]['region']);
					}

		if(typeof HTTP_GET_VARS[0]['bundesland'] != 'undefined'){
			parameter += '&bundesland=' + encodeURI(HTTP_GET_VARS[0]['bundesland']);
					}

		
		if(typeof HTTP_GET_VARS[0]['stellplatz'] != 'undefined' && HTTP_GET_VARS[0]['stellplatz'] != 'Stellplatzname'){
			parameter += '&stellplatz='+HTTP_GET_VARS[0]['stellplatz'];
		}


		if(typeof HTTP_GET_VARS[0]['gebuehr'] != 'undefined'){
			parameter += '&gebuehr='+HTTP_GET_VARS[0]['gebuehr'];
		}

		if(typeof HTTP_GET_VARS[0]['rubrik'] != 'undefined'){
			parameter += '&rubrik='+HTTP_GET_VARS[0]['rubrik'];
		}

		if(typeof HTTP_GET_VARS[0]['strom'] != 'undefined'){
			parameter += '&strom='+HTTP_GET_VARS[0]['strom'];
		}
		
		if(typeof HTTP_GET_VARS[0]['wasser'] != 'undefined'){
			parameter += '&wasser='+HTTP_GET_VARS[0]['wasser'];
		}
			
		if(typeof HTTP_GET_VARS[0]['wlan'] != 'undefined'){
			parameter += '&wlan='+HTTP_GET_VARS[0]['wlan'];
		}
			
		if(typeof HTTP_GET_VARS[0]['entsorgung'] != 'undefined'){
			parameter += '&entsorgung='+HTTP_GET_VARS[0]['entsorgung'];
		}

		if(typeof HTTP_GET_VARS[0]['tiere'] != 'undefined'){
			parameter += '&tiere='+HTTP_GET_VARS[0]['tiere'];
		}

		if(typeof HTTP_GET_VARS[0]['CH'] != 'undefined'){
			parameter += '&CH='+HTTP_GET_VARS[0]['CH'];
		}

		if(typeof HTTP_GET_VARS[0]['Dusche'] != 'undefined'){
			parameter += '&Dusche='+HTTP_GET_VARS[0]['Dusche'];
		}

	return parameter;
}

/*** ermittelt Marker des Kartenausschnitts aus DB ***/
function retrieve_Markers(){
	var anz_suchparameter = HTTP_GET_VARS.length;
	var points;
	var kacheln;

	var anzahl_ausschnitt;
	var gesamtanzahl;
	
	map.clearOverlays();	
	
	//markerManager.clearMarkers();
	//clusterManager.clearMarkers();
	
	//wenn gesucht wurde
	if(anz_suchparameter > 0){
		//Top20-Liste ausblenden
		document.getElementById("top20").style.display = 'none';
		//Per AJAX die Marker holen
		if (xmlHttp) {
	
			var param = create_parameter();
			//alert(param);
			
			xmlHttp.open("POST", '/stellplaetze/retrieve_markers_suche.php', true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//xmlHttp.setRequestHeader("Content-length", params.length);
			//xmlHttp.setRequestHeader("Connection", "close");
		
			xmlHttp.onreadystatechange = function () {
        		if (xmlHttp.readyState == 4) {
				document.getElementById("wait").style.display = 'none';
				
				var jscript = xmlHttp.responseText;
				//var report1 = document.getElementById("daten");
				//report1.innerHTML = jscript;
				eval(jscript);
				
				var anzeige_anzahl = document.getElementById("stellplatzanzahl");
				var anzeige_anzahl_liste = document.getElementById("stellplatzanzahlliste");

				if(typeof anzahl_suche != 'undefined' && typeof gesamtanzahl  != 'undefined'){
					anzeige_anzahl.innerHTML = "Anzeige: " + anzahl_suche + " von " + gesamtanzahl + " Stellpl&auml;tze";
					if(anzahl_suche > 0)
					anzeige_anzahl_liste.innerHTML = "Anzeige: " + anzahl_suche + " von " + gesamtanzahl + " Stellpl&auml;tze";
				}							
				
				//Einzelne Punkte der Karte erzeugen
				if(typeof points != 'undefined'){
		
					for (i in points) {
						add_Marker(points[i].lat,points[i].lng,points[i].id,points[i].info,points[i].imgliste, points[i].plz, points[i].ort,points[i].title, points[i].bis5euro, points[i].url_title);
					}
					
					if(typeof HTTP_GET_VARS[0]['plz'] != 'undefined' || typeof HTTP_GET_VARS[0]['ort'] != 'undefined'){
						
						if(!geocoder) geocoder = new GClientGeocoder();
						var adress = "";
						if(HTTP_GET_VARS[0]['plz'] != "" && HTTP_GET_VARS[0]['plz'] != "PLZ" && typeof HTTP_GET_VARS[0]['plz'] != 'undefined') {
							adress += HTTP_GET_VARS[0]['plz'] + ' ';
							adress += 'Deutschland ';
						}
							
						if( typeof HTTP_GET_VARS[0]['ort'] != 'undefined' && HTTP_GET_VARS[0]['ort'] != "" && HTTP_GET_VARS[0]['ort'] != "Ort"){
							//alert('huhu');
							 adress += HTTP_GET_VARS[0]['ort'];
							adress += ' Deutschland ';

						}

						//alert(adress);
						geocoder.getLatLng(adress, 
						function (response){
							if(!response){
								//alert('Fehler');
							}
							else{
								//var test = response;
								//alert(test);
								
									//map.setCenter(response, 11);
									map.setCenter(response);

							}
						}
						);
					}
				}
				if(anzahl_suche == 0){
					var report1 = document.getElementById("stellplatzliste");
					report1.innerHTML = '<div style="font-size:11px;">Die von Ihnen gesuchten Begriffe ergaben keine Treffer.</div>';

				}
				//Artikelliste generieren
				if(typeof anzahl_suche != 'undefined' && anzahl_suche > 0){
					get_Stellplatzliste(0, anzahl_suche);
				}
				
			}
			else if(xmlHttp.readyState == 1){
				show_waitIcon();			
			}

							
   			};
			xmlHttp.send(param);
		
		} //ende xmlHttp
	
	}
	//wenn Map mit Start-Zoom aufgerufen wird	
	else if(map.getZoom() <= 4){
		retrieve_overview();
	}
	else{		
	//Top20-Liste ausblenden
	document.getElementById("top20").style.display = 'none';

	//Per AJAX die Marker holen
		if (xmlHttp) {
			var params = "kacheln="+kachelneu;
				
			xmlHttp.open("POST", '/stellplaetze/retrieve_markers.php', true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			//xmlHttp.setRequestHeader("Content-length", params.length);
			//xmlHttp.setRequestHeader("Connection", "close");
		
			xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				document.getElementById("wait").style.display = 'none';

				if (xmlHttp.status == 200) {
					

					var jscript = xmlHttp.responseText;
					var report1 = document.getElementById("daten");
					//report1.innerHTML = jscript;
					eval(jscript);
				
					var anzeige_anzahl = document.getElementById("stellplatzanzahl");
					var anzeige_anzahl_liste = document.getElementById("stellplatzanzahlliste");

					if(typeof anzahl_ausschnitt != 'undefined' && typeof gesamtanzahl  != 'undefined'){
						anzeige_anzahl.innerHTML = "Anzeige: " + anzahl_ausschnitt + " von " + gesamtanzahl + " Stellpl&auml;tze";
						anzeige_anzahl_liste.innerHTML = "Anzeige: " + anzahl_ausschnitt + " von " + gesamtanzahl + " Stellpl&auml;tze";

					}							
					//Cluster erzeugen
					if(typeof kacheln != 'undefined'){
						for (i in kacheln) {
						add_Cluster(kacheln[i].nwlat,kacheln[i].nwlng, kacheln[i].nelat,kacheln[i].nelng, kacheln[i].swlat,kacheln[i].swlng, kacheln[i].anzahlpoi);
						}
					//clusterManager.refresh(); 
					}
				
					//Einzelne Punkte der Liste erzeugen
					if(typeof points != 'undefined'){
						for (i in points) {
						add_Marker(points[i].lat,points[i].lng,points[i].id,points[i].land,points[i].imgliste, points[i].plz, points[i].ort, points[i].title, points[i].bis5euro, points[i].url_title);
						}
					//markerManager.refresh(); 

					}
				
					//Artikelliste generieren
					if(typeof anzahl_ausschnitt  != 'undefined' && anzahl_ausschnitt > 0){
					get_Stellplatzliste(0, anzahl_ausschnitt);
					updateBanner();
					}
				}
								
			}
			else if(xmlHttp.readyState == 1){
				show_waitIcon();				
			}
							
   			};
			xmlHttp.send(params);
			 
		} //ende xmlHttp
	} //ende Zoomlevel
			
}

/*** generiert die JumpList ***/
function create_Jumplist(anzahl, skip, beschriftung, position){
	
	//Gesamt-Anzahl der Seiten, welche in der Jumplist dargestellt werden können
	var pages = Math.ceil(anzahl/anzahl_listenelement);
	//alert("Seiten: "+pages);
	
	//Ermitteln, ab welchem Eintrag die Jumplist beginnen soll
	if(skip >= (anzahl_listenelement*anzahl_jumplist_eintraege)){
		var seite_start = ((skip+anzahl_listenelement)/anzahl_listenelement)-anzahl_jumplist_eintraege;
	}
	else{
		var seite_start = 0;
	}

	
	
	var divclass = "";
	var prev = "";
	var next = "";
	
	if(position == 'jumplisttop'){
		divclass = "reiter_l2 nicht_drucken";

	}
	else{
		divclass = "reiter_l2 reiter_l2_unten";
	}
	
	var element = '<div class="' + divclass + '"><strong>' + beschriftung + '</strong><p>';
	

	for(i=0; i < anzahl_jumplist_eintraege && i < pages; i++){
		//erstes Element
         	if(i == 0){

			if(((seite_start+i)*anzahl_listenelement) == skip){
				element += '<a href="#liste" onclick="get_Stellplatzliste(' + ((seite_start+i)*anzahl_listenelement) + ',' + anzahl + ')" class="first aktiv">' + (seite_start+i+1) + '</a>';
				//weiter-Button generieren
				next = '<a href="#liste" onclick="get_Stellplatzliste(' + ((seite_start+i+1)*anzahl_listenelement) + ',' + anzahl + ')" class="next"></a>';
			}
			else{
				element += '<a href="#liste" onclick="get_Stellplatzliste(' + ((seite_start+i)*anzahl_listenelement) + ',' + anzahl + ')" class="first">' + (seite_start+i+1) + '</a>';
			}
		}
		else{
			//Aktives Element
			if(((seite_start+i)*anzahl_listenelement) == skip){
				element += '<a href="#liste" onclick="get_Stellplatzliste(' + ((seite_start+i)*anzahl_listenelement) + ',' + anzahl + ')" class="aktiv">' + (seite_start+i+1) + '</a>';

				//zurueck-Button generieren
				prev = '<a href="#liste" onclick="get_Stellplatzliste(' + ((seite_start+i-1)*anzahl_listenelement) + ',' + anzahl + ')" class="prev"></a>';

				//weiter-Button generieren
				next = '<a href="#liste" onclick="get_Stellplatzliste(' + ((seite_start+i+1)*anzahl_listenelement) + ',' + anzahl + ')" class="next"></a>';

			}
			else {
				element += '<a href="#liste" onclick="get_Stellplatzliste(' + ((seite_start+i)*anzahl_listenelement) + ',' + anzahl + ')">' + (seite_start+i+1) + '</a>';
			}
		}

				
		
		//Maximum ist erreicht, wenn es weitere Seiten gibt wird der Weiter-Button ausgegeben
		if(i == (anzahl_jumplist_eintraege-1) && i < pages){
			
			element += '</p><div>' + prev + '<span>bl&auml;ttern</span>' + next +'</div></div>';
		}
		else if(i == (anzahl_jumplist_eintraege-1) && i >= pages){
			element += '</p></div>';
		}
		else if(i == (pages-1)){
			element += '</p></div>';
		}

	}
	return element;
	
}

/*** generiert die Liste der Stellplätze ***/
function get_Stellplatzliste(skip, anzahl){
	
	var writeListe = document.getElementById("stellplatzliste");
	var liste = "";
	var points;
	
	//obere Jumplist
	liste += create_Jumplist(anzahl, skip, "Stellpl&auml;tze", "jumplisttop");
	
	//Per AJAX die Stellplätze für die aktuelle Seite holen
	if (xmlHttpListe) {
		var mapsw = mapbounds.getSouthWest();
		var mapne = mapbounds.getNorthEast();

		//wenn gesucht wurde, die Parameter aus dem Formular uebergeben
		if(HTTP_GET_VARS.length > 0){
			var params = create_parameter();
			params += "&start="+skip;
			params += "&limit="+anzahl_listenelement;
			//alert (params);
			xmlHttpListe.open("POST", '/stellplaetze/retrieve_markers_suche.php', true);
			xmlHttpListe.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		
			
		}
		else{ 
			var params = "nordostlat="+mapne.lat()+"&nordostlng="+mapne.lng()+"&suedwestlat="+mapsw.lat()+"&suedwestlng="+mapsw.lng()+"&start="+skip+"&limit="+anzahl_listenelement;
			//alert(params);
			xmlHttpListe.open("POST", '/stellplaetze/retrieve_liste.php', true);
			xmlHttpListe.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		
		}
		
		xmlHttpListe.onreadystatechange = function () {
        		if (xmlHttpListe.readyState == 4) {
				var jscript = xmlHttpListe.responseText;
				//var report1 = document.getElementById("daten");
				//report1.innerHTML = jscript;
				
				eval(jscript);
				//u = retrieve_URL();
				
				//Listeneintraege erzeugen
				if(typeof points != 'undefined'){
					liste += '<span class="leerraum_2px">&nbsp;</span>';

					for (i in points) {
						liste += '<div class="box_links marginbottom_2px highlight nicht_drucken">';
						u = "http://www.promobil.de/reise/wohnmobilstellplatz-" + points[i].url_title + "/wohnmobilstellplaetze.276476.7.htm";

						if(points[i].imgliste != ''){
						liste += '<a href="' + u + '?stellplatzid=' + points[i].id + '" target="_blank"><img class="bild" src="http://images.stellplatz.promobil.de/' + points[i].imgliste +'" width="150" alt="" title="" /></a>';
						}
						liste += '<div class="text"><h2><a href="' + u + '?stellplatzid=' + points[i].id + '" target="_blank">';
						if( points[i].title != ''){
						 	liste += points[i].title; 						
						}
						else{
							liste += 'Dies ist der Titel';
						}

						liste += '</a></h2><p class="mit_wertung">';
						if(points[i].land == 'D'){
							liste += '<a href="http://www.promobil.de/reise/gratis-download-gps-daten-zu-rund-2-700-stellplaetzen-in-deutschland.335317.7.htm" target="_blank"><img src="http://images.promobil.de/stellplaetze/img/gps_download_liste_de.jpg" style="float:right"></a>';
						}
						liste += points[i].land + ' - ';
						liste += points[i].plz + ' ' + points[i].ort + '<br/>';
						if( points[i].bis5euro == 1){
							liste += 'Bis 5 &euro;<br/>';

						}
						liste += '<b><a href="' + u + '?stellplatzid=' + points[i].id + '" target="_blank">mehr &raquo;</a></b>';

						liste += '</p></div><br class="c"><br class="c"></div>';

					}
				}
				//untere Jumplist
				liste += create_Jumplist(anzahl, skip, " ", "jumplistbottom");
				writeListe.innerHTML = liste;
			}
							
   		 	};
			xmlHttpListe.send(params); 


						
		}
	

}

window.onload = init;
window.onunload = GUnload;