var icons = [];
var saleicons = [];
var gIconArray = [];
var gmarkers = [];
var gmarkers_sale = [];
var gmarkers_poi = [];
var gdata = [];
var gdata_sale = [];
var gdata_poi = [];
var map;

var noRefresh = false;

var oldCenter;
var maxZoomOut;

var gLocalSearch_p01;
var gLocalSearch_p02;
var gLocalSearch_p03;
var gLocalSearch_p04;
var gLocalSearch_p05;
var gLocalSearch_p06;
var gLocalSearch_p07;
var gLocalSearch_p08;
var gLocalSearch_p09;
var gLocalSearch_p10;

var checkboxObjectArray = [];
var checkboxPOIArray = [];

function loadmap(){
	if (!GBrowserIsCompatible()) {
		return false;
	}

	checkboxObjectArray[0] = 'ms0';
	checkboxObjectArray[1] = 'ms1';
	checkboxObjectArray[2] = 'ms2';
	checkboxObjectArray[3] = 'ms3';
	checkboxObjectArray[4] = 'ms4';
	checkboxObjectArray[5] = 'ms5';
	checkboxObjectArray[6] = 'ms6';
	checkboxObjectArray[7] = 'ms7';
	checkboxObjectArray[8] = 'ms8';
	
	checkboxPOIArray[0] = 'poi01';
	checkboxPOIArray[1] = 'poi02';
	checkboxPOIArray[2] = 'poi03';
	checkboxPOIArray[3] = 'poi04';
	checkboxPOIArray[4] = 'poi05';
	checkboxPOIArray[5] = 'poi06';
	checkboxPOIArray[6] = 'poi07';
	checkboxPOIArray[7] = 'poi08';
	checkboxPOIArray[8] = 'poi09';
	checkboxPOIArray[9] = 'poi10';

	if (document.forms.searchform.mType.value==0 || document.forms.searchform.mType.value==1){
		var immoIcon = new GIcon();
		immoIcon.image = "images/marker/0/miet/icon_0.png";
		immoIcon.iconSize = new GSize(27, 21);
		immoIcon.iconAnchor = new GPoint(7, 28);
		immoIcon.infoWindowAnchor = new GPoint(26, 2);
		immoIcon.transparent = "images/marker/0/miet/trans_0.png";
		immoIcon.printImage = "images/marker/0/miet/iconie_0.gif";
		immoIcon.mozPrintImage = "images/marker/0/miet/iconff_0.gif";
		icons[0] = immoIcon;

		var immoIcon = new GIcon();
		immoIcon.image = "images/marker/0/miet/icon_1.png";
		immoIcon.iconSize = new GSize(27, 21);
		immoIcon.iconAnchor = new GPoint(7, 28);
		immoIcon.infoWindowAnchor = new GPoint(26, 2);
		immoIcon.transparent = "images/marker/0/miet/trans_1.png";
		immoIcon.printImage = "images/marker/0/miet/iconie_1.gif";
		immoIcon.mozPrintImage = "images/marker/0/miet/iconff_1.gif";
		icons[1] = immoIcon;

		var immoIcon = new GIcon();
		immoIcon.image = "images/marker/0/miet/icon_4.png";
		immoIcon.iconSize = new GSize(27, 21);
		immoIcon.iconAnchor = new GPoint(7, 28);
		immoIcon.infoWindowAnchor = new GPoint(26, 2);
		immoIcon.transparent = "images/marker/0/miet/trans_4.png";
		immoIcon.printImage = "images/marker/0/miet/iconie_4.gif";
		immoIcon.mozPrintImage = "images/marker/0/miet/iconff_4.gif";
		icons[4] = immoIcon;

		var immoIcon = new GIcon();
		immoIcon.image = "images/marker/0/miet/icon_7.png";
		immoIcon.iconSize = new GSize(33, 22);
		immoIcon.iconAnchor = new GPoint(7, 28);
		immoIcon.infoWindowAnchor = new GPoint(26, 2);
		immoIcon.transparent = "images/marker/0/miet/trans_7.png";
		immoIcon.printImage = "images/marker/0/miet/iconie_7.gif";
		immoIcon.mozPrintImage = "images/marker/0/miet/iconff_7.gif";
		icons[7] = immoIcon;

		var immoIcon = new GIcon();
		immoIcon.image = "images/marker/0/miet/icon_8.png";
		immoIcon.iconSize = new GSize(33, 22);
		immoIcon.iconAnchor = new GPoint(7, 28);
		immoIcon.infoWindowAnchor = new GPoint(26, 2);
		immoIcon.transparent = "images/marker/0/miet/trans_8.png";
		immoIcon.printImage = "images/marker/0/miet/iconie_8.gif";
		immoIcon.mozPrintImage = "images/marker/0/miet/iconff_8.gif";
		icons[8] = immoIcon;

		var immoIcon = new GIcon();
		immoIcon.image = "images/marker/0/miet/icon_10.png";
		immoIcon.iconSize = new GSize(33, 22);
		immoIcon.iconAnchor = new GPoint(7, 28);
		immoIcon.infoWindowAnchor = new GPoint(26, 2);
		immoIcon.transparent = "images/marker/0/miet/trans_10.png";
		immoIcon.printImage = "images/marker/0/miet/iconie_10.gif";
		immoIcon.mozPrintImage = "images/marker/0/miet/iconff_10.gif";
		icons[10] = immoIcon;

//BS Start saleIcon---------------------------------------------------------------

		var saleIcon = new GIcon();
		saleIcon.image = "images/marker/0/sale/icon_2.png";
		saleIcon.iconSize = new GSize(27, 21);
		saleIcon.iconAnchor = new GPoint(7, 28);
		saleIcon.infoWindowAnchor = new GPoint(26, 2);
		saleIcon.transparent = "images/marker/0/sale/trans_2.png";
		saleIcon.printImage = "images/marker/0/sale/iconie_2.gif";
		saleIcon.mozPrintImage = "images/marker/0/sale/iconff_2.gif";
		saleicons[2] = saleIcon;

		var saleIcon = new GIcon();
		saleIcon.image = "images/marker/0/sale/icon_3.png";
		saleIcon.iconSize = new GSize(27, 21);
		saleIcon.iconAnchor = new GPoint(7, 28);
		saleIcon.infoWindowAnchor = new GPoint(26, 2);
		saleIcon.transparent = "images/marker/0/sale/trans_3.png";
		saleIcon.printImage = "images/marker/0/sale/iconie_3.gif";
		saleIcon.mozPrintImage = "images/marker/0/sale/iconff_3.gif";
		saleicons[3] = saleIcon;

		var saleIcon = new GIcon();
		saleIcon.image = "images/marker/0/sale/icon_5.png";
		saleIcon.iconSize = new GSize(27, 21);
		saleIcon.iconAnchor = new GPoint(7, 28);
		saleIcon.infoWindowAnchor = new GPoint(26, 2);
		saleIcon.transparent = "images/marker/0/sale/trans_5.png";
		saleIcon.printImage = "images/marker/0/sale/iconie_5.gif";
		saleIcon.mozPrintImage = "images/marker/0/sale/iconff_5.gif";
		saleicons[5] = saleIcon;

		var saleIcon = new GIcon();
		saleIcon.image = "images/marker/0/sale/icon_7.png";
		saleIcon.iconSize = new GSize(33, 22);
		saleIcon.iconAnchor = new GPoint(7, 28);
		saleIcon.infoWindowAnchor = new GPoint(26, 2);
		saleIcon.transparent = "images/marker/0/sale/trans_7.png";
		saleIcon.printImage = "images/marker/0/sale/iconie_7.gif";
		saleIcon.mozPrintImage = "images/marker/0/saleiconff_7.gif";
		saleicons[7] = saleIcon;

		var saleIcon = new GIcon();
		saleIcon.image = "images/marker/0/sale/icon_8.png";
		saleIcon.iconSize = new GSize(33, 22);
		saleIcon.iconAnchor = new GPoint(7, 28);
		saleIcon.infoWindowAnchor = new GPoint(26, 2);
		saleIcon.transparent = "images/marker/0/sale/trans_8.png";
		saleIcon.printImage = "images/marker/0/sale/iconie_8.gif";
		saleIcon.mozPrintImage = "images/marker/0/sale/iconff_8.gif";
		saleicons[8] = saleIcon;

		var saleIcon = new GIcon();
		saleIcon.image = "images/marker/0/sale/icon_9.png";
		saleIcon.iconSize = new GSize(33, 22);
		saleIcon.iconAnchor = new GPoint(7, 28);
		saleIcon.infoWindowAnchor = new GPoint(26, 2);
		saleIcon.transparent = "images/marker/0/sale/trans_9.png";
		saleIcon.printImage = "images/marker/0/sale/iconie_9.gif";
		saleIcon.mozPrintImage = "images/marker/0/sale/iconff_9.gif";
		saleicons[9] = saleIcon;
		
		var saleIcon = new GIcon();
		saleIcon.image = "images/marker/0/sale/icon_10.png";
		saleIcon.iconSize = new GSize(33, 22);
		saleIcon.iconAnchor = new GPoint(7, 28);
		saleIcon.infoWindowAnchor = new GPoint(26, 2);
		saleIcon.transparent = "images/marker/0/sale/trans_10.png";
		saleIcon.printImage = "images/marker/0/sale/iconie_10.gif";
		saleIcon.mozPrintImage = "images/marker/0/sale/iconff_10.gif";
		saleicons[10] = saleIcon;

		var saleIcon = new GIcon();
		saleIcon.image = "images/marker/0/sale/icon_12.png";
		saleIcon.iconSize = new GSize(33, 22);
		saleIcon.iconAnchor = new GPoint(7, 28);
		saleIcon.infoWindowAnchor = new GPoint(26, 2);
		saleIcon.transparent = "images/marker/0/sale/trans_12.png";
		saleIcon.printImage = "images/marker/0/sale/iconie_12.gif";
		saleIcon.mozPrintImage = "images/marker/0/sale/iconff_12.gif";
		saleicons[12] = saleIcon;

//BS Ende saleIcon---------------------------------------------------------------

//BS Start poiIcon---------------------------------------------------------------

		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/restaurant.gif";
		poiIcon.iconSize = new GSize(27, 21);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/restaurant_trans.png";
		gIconArray['poi01'] = poiIcon;	
		
		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/schule.gif";
		poiIcon.iconSize = new GSize(27, 21);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/schule_trans.png";	
		gIconArray['poi02'] = poiIcon;
		
		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/parkhaus.gif";
		poiIcon.iconSize = new GSize(33, 22);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/parkhaus_trans.png";
		gIconArray['poi03'] = poiIcon;
		
		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/tankstelle.gif";
		poiIcon.iconSize = new GSize(33, 22);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/tankstelle_trans.png";
		gIconArray['poi04'] = poiIcon;
		
		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/mcdonalds.gif";
		poiIcon.iconSize = new GSize(27, 21);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/mcdonalds_trans.png";
		gIconArray['poi05'] = poiIcon;
		
		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/kino.gif";
		poiIcon.iconSize = new GSize(27, 21);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/kino_trans.png";
		gIconArray['poi06'] = poiIcon;
		
		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/krankenhaus.gif";
		poiIcon.iconSize = new GSize(33, 22);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/krankenhaus_trans.png";
		gIconArray['poi07'] = poiIcon;
		
		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/kindergarten.gif";
		poiIcon.iconSize = new GSize(33, 22);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/kindergarten_trans.png";
		gIconArray['poi08'] = poiIcon;
		
		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/apotheke.gif";
		poiIcon.iconSize = new GSize(27, 21);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/apotheke_trans.png";
		gIconArray['poi09'] = poiIcon;
		
		var poiIcon = new GIcon();
		poiIcon.image = "images/marker/0/poi/burgerking.gif";
		poiIcon.iconSize = new GSize(33, 22);
		poiIcon.iconAnchor = new GPoint(7, 28);
		poiIcon.infoWindowAnchor = new GPoint(26, 2);
		poiIcon.transparent = "images/marker/0/poi/burgerking_trans.png";
		gIconArray['poi10'] = poiIcon;

//BS Ende poiIcon---------------------------------------------------------------
	}

	map = new GMap2(document.getElementById("map"));
	//map.addControl(new GLargeMapControl());
	//map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl());
	map.setCenter(new GLatLng(51.1898,9.5923),6);
	oldCenter = map.getCenter();

	GEvent.addListener(map, "zoomend", function(oldLever,newLevel) {
			if (newLevel<maxZoomOut){
				if (document.forms.frel.autoreload.checked) liveSearchStart(true);
			}
		});
	GEvent.addListener(map, "moveend", function() {
		 	if (noRefresh==false){
				var mapbounds = map.getBounds();
				var width = Math.abs(mapbounds.getNorthEast().lat() - mapbounds.getSouthWest().lat());
				var height = Math.abs(mapbounds.getNorthEast().lng() - mapbounds.getSouthWest().lng());

				var latMove = Math.abs(oldCenter.lat() - map.getCenter().lat());
				var lngMove = Math.abs(oldCenter.lng() - map.getCenter().lng());

				var latPC = 100*latMove/width;
				var lngPC = 100*lngMove/height;

				if (latPC > 25 || lngPC > 25){
				//if (latMove > 0.005 || lngMove > 0.015){
		 			if (document.forms.frel.autoreload.checked){
		 				liveSearchStart(true);
		 				bMove = true;
		 			}
				}
	 		}else{
	 			noRefresh = false;
	 		}
		});
	showOrte();
}

function createMarker(point,index,icontype) {
  	var marker = new GMarker(point,icons[icontype]);
  	GEvent.addListener(marker, "click", function() {
    							noRefresh = true;
    							marker.openInfoWindowHtml(getInfo(index));
  							});
  	return marker;
}

function createMarkerSale(point,index,icontype) {
  	var marker = new GMarker(point,saleicons[icontype]);
  	GEvent.addListener(marker, "click", function() {
    							noRefresh = true;
    							marker.openInfoWindowHtml(getInfoSale(index));
  							});
  	return marker;
}

function createMarkerPOI(point,index,icontype) {
  	var marker = new GMarker(point,gIconArray[icontype]);
  	GEvent.addListener(marker, "click", function() {
    							noRefresh = true;
    							marker.openInfoWindowHtml(getInfoPOI(index));
  							});
  	return marker;
}

function createMarkerS(point,index,icon) {
  	var marker = new GMarker(point,icon);
  	GEvent.addListener(marker, "click", function() {
  							map.setCenter(point,13);
  							if (document.forms.frel.autoreload.checked==false) liveSearchStart(true);
  							});
  	return marker;
}


function showInfo(index){
	noRefresh=true;
	gmarkers[index].openInfoWindowHtml(getInfo(index));
}

function showInfoSale(index){
	noRefresh=true;
	gmarkers_sale[index].openInfoWindowHtml(getInfoSale(index));
}

function zoom(lat,lng,lvl){
	noRefresh=true;
	map.setCenter(new GLatLng(lat,lng),lvl);
}

function setGMapType(type){
	switch (type){
	case 2:
		map.setMapType(G_HYBRID_MAP);
		break;
	case 1:
		map.setMapType(G_SATELLITE_MAP);
		break;
	default:
		map.setMapType(G_NORMAL_MAP);
		break;
	}
}

function GZoomIN(){
	tmp=map.getZoom();
	if (tmp<17)map.setZoom(tmp+1);
}

function GZoomOUT(){
	tmp=map.getZoom();
	if (tmp>=6)map.setZoom(tmp-1);
}

//BS Start Search POI---------------------------------------------------------------

//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p01() {
	if (!gLocalSearch_p01.results) return;
	var parameter_p01;
	parameter_p01 = '';
	var phoneArray_p01 = [];
	for (var i = 0; i < gLocalSearch_p01.results.length; i++) {
		parameter_p01 += 
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p01.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p01.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p01.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p01.results[i].lat) +
		'&streetaddress=' + encodeURIComponent(gLocalSearch_p01.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p01.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p01.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p01.results[i].country);
		if (gLocalSearch_p01.results[i].ddUrl && gLocalSearch_p01.results[i].ddUrl != null) {
			parameter_p01 += '&ddurl=' + encodeURIComponent(gLocalSearch_p01.results[i].ddUrl);
		}
		if (gLocalSearch_p01.results[i].ddUrlToHere && gLocalSearch_p01.results[i].ddUrlToHere != null) {
			parameter_p01 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p01.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p01.results[i].ddUrlFromHere && gLocalSearch_p01.results[i].ddUrlFromHere != null) {
			parameter_p01 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p01.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p01.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p01.results[i].phoneNumbers.length; j++) {
				phoneArray_p01[j] = gLocalSearch_p01.results[i].phoneNumbers[j];
				if (!phoneArray_p01[j].type == '') {
					parameter_p01 +=
					'&phone'+ phoneArray_p01[j].type + '=' + encodeURIComponent(phoneArray_p01[j].number);
				}	
			}
		}
		parameter_p01 += '&poi_id=poi01';
		makeRequest('writepoiresults.php', parameter_p01);
		parameter_p01 = '';
	}
}
//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p02() {
	if (!gLocalSearch_p02.results) return;
	var parameter_p02;
	parameter_p02 = '';
	var phoneArray_p02 = [];
	for (var i = 0; i < gLocalSearch_p02.results.length; i++) {
		parameter_p02 += 
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p02.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p02.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p02.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p02.results[i].lat) +
		'&streetaddress=' + encodeURIComponent(gLocalSearch_p02.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p02.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p02.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p02.results[i].country);
		if (gLocalSearch_p02.results[i].ddUrl && gLocalSearch_p02.results[i].ddUrl != null) {
			parameter_p02 += '&ddurl=' + encodeURIComponent(gLocalSearch_p02.results[i].ddUrl);
		}
		if (gLocalSearch_p02.results[i].ddUrlToHere && gLocalSearch_p02.results[i].ddUrlToHere != null) {
			parameter_p02 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p02.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p02.results[i].ddUrlFromHere && gLocalSearch_p02.results[i].ddUrlFromHere != null) {
			parameter_p02 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p02.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p02.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p02.results[i].phoneNumbers.length; j++) {
				phoneArray_p02[j] = gLocalSearch_p02.results[i].phoneNumbers[j];
				if (!phoneArray_p02[j].type == '') {
					parameter_p02 +=
					'&phone'+ phoneArray_p02[j].type + '=' + encodeURIComponent(phoneArray_p02[j].number);
				}	
			}
		}
		parameter_p02 += '&poi_id=poi02';
		makeRequest('writepoiresults.php', parameter_p02);
		parameter_p02 = '';
	}
}
//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p03() {
	if (!gLocalSearch_p03.results) return;
	var parameter_p03;
	parameter_p03 = '';
	var phoneArray_p03 = [];
	for (var i = 0; i < gLocalSearch_p03.results.length; i++) {
		parameter_p03 += 
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p03.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p03.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p03.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p03.results[i].lat) +
		'&streetaddress=' + encodeURIComponent(gLocalSearch_p03.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p03.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p03.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p03.results[i].country);
		if (gLocalSearch_p03.results[i].ddUrl && gLocalSearch_p03.results[i].ddUrl != null) {
			parameter_p03 += '&ddurl=' + encodeURIComponent(gLocalSearch_p03.results[i].ddUrl);
		}
		if (gLocalSearch_p03.results[i].ddUrlToHere && gLocalSearch_p03.results[i].ddUrlToHere != null) {
			parameter_p03 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p03.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p03.results[i].ddUrlFromHere && gLocalSearch_p03.results[i].ddUrlFromHere != null) {
			parameter_p03 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p03.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p03.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p03.results[i].phoneNumbers.length; j++) {
				phoneArray_p03[j] = gLocalSearch_p03.results[i].phoneNumbers[j];
				if (!phoneArray_p03[j].type == '') {
					parameter_p03 +=
					'&phone'+ phoneArray_p03[j].type + '=' + encodeURIComponent(phoneArray_p03[j].number);
				}	
			}
		}
		parameter_p03 += '&poi_id=poi03';
		makeRequest('writepoiresults.php', parameter_p03);
		parameter_p03 = '';
	}
}
//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p04() {
	if (!gLocalSearch_p04.results) return;
	var parameter_p04;
	parameter_p04 = '';
	var phoneArray_p04 = [];	
	for (var i = 0; i < gLocalSearch_p04.results.length; i++) {
		parameter_p04 += 
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p04.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p04.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p04.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p04.results[i].lat) +
		'&streetaddress=' + encodeURIComponent(gLocalSearch_p04.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p04.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p04.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p04.results[i].country);
		if (gLocalSearch_p04.results[i].ddUrl && gLocalSearch_p04.results[i].ddUrl != null) {
			parameter_p04 += '&ddurl=' + encodeURIComponent(gLocalSearch_p04.results[i].ddUrl);
		}
		if (gLocalSearch_p04.results[i].ddUrlToHere && gLocalSearch_p04.results[i].ddUrlToHere != null) {
			parameter_p04 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p04.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p04.results[i].ddUrlFromHere && gLocalSearch_p04.results[i].ddUrlFromHere != null) {
			parameter_p04 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p04.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p04.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p04.results[i].phoneNumbers.length; j++) {
				phoneArray_p04[j] = gLocalSearch_p04.results[i].phoneNumbers[j];
				if (!phoneArray_p04[j].type == '') {
					parameter_p04 +=
					'&phone'+ phoneArray_p04[j].type + '=' + encodeURIComponent(phoneArray_p04[j].number);
				}	
			}
		}
		parameter_p04 +=  '&poi_id=poi04';
		makeRequest('writepoiresults.php', parameter_p04);
		parameter_p04 = '';
	}
}
//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p05() {
	if (!gLocalSearch_p05.results) return;
	var parameter_p05;
	parameter_p05 = '';
	var phoneArray_p05 = [];
	for (var i = 0; i < gLocalSearch_p05.results.length; i++) {
		parameter_p05 += 
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p05.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p05.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p05.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p05.results[i].lat) +
		'&streetaddress=' + encodeURIComponent(gLocalSearch_p05.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p05.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p05.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p05.results[i].country);
		if (gLocalSearch_p05.results[i].ddUrl && gLocalSearch_p05.results[i].ddUrl != null) {
			parameter_p05 += '&ddurl=' + encodeURIComponent(gLocalSearch_p05.results[i].ddUrl);
		}
		if (gLocalSearch_p05.results[i].ddUrlToHere && gLocalSearch_p05.results[i].ddUrlToHere != null) {
			parameter_p05 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p05.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p05.results[i].ddUrlFromHere && gLocalSearch_p05.results[i].ddUrlFromHere != null) {
			parameter_p05 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p05.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p05.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p05.results[i].phoneNumbers.length; j++) {
				phoneArray_p05[j] = gLocalSearch_p05.results[i].phoneNumbers[j];
				if (!phoneArray_p05[j].type == '') {
					parameter_p05 +=
					'&phone'+ phoneArray_p05[j].type + '=' + encodeURIComponent(phoneArray_p05[j].number);
				}	
			}
		}
		parameter_p05 += '&poi_id=poi05';
		makeRequest('writepoiresults.php', parameter_p05);
		parameter_p05 = '';
	}
}
//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p06() {
	if (!gLocalSearch_p06.results) return;
	var parameter_p06;
	parameter_p06 = '';
	var phoneArray_p06 = [];
	for (var i = 0; i < gLocalSearch_p06.results.length; i++) {
		parameter_p06 += 
		'&title=' + encodeURIComponent(gLocalSearch_p06.results[i].title) +
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p06.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p06.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p06.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p06.results[i].lat) +
		'&streetaddress=' + encodeURIComponent(gLocalSearch_p06.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p06.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p06.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p06.results[i].country);
		if (gLocalSearch_p06.results[i].ddUrl && gLocalSearch_p06.results[i].ddUrl != null) {
			parameter_p06 += '&ddurl=' + encodeURIComponent(gLocalSearch_p06.results[i].ddUrl);
		}
		if (gLocalSearch_p06.results[i].ddUrlToHere && gLocalSearch_p06.results[i].ddUrlToHere != null) {
			parameter_p06 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p06.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p06.results[i].ddUrlFromHere && gLocalSearch_p06.results[i].ddUrlFromHere != null) {
			parameter_p06 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p06.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p06.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p06.results[i].phoneNumbers.length; j++) {
				phoneArray_p06[j] = gLocalSearch_p06.results[i].phoneNumbers[j];
				if (!phoneArray_p06[j].type == '') {
					parameter_p06 +=
					'&phone'+ phoneArray_p06[j].type + '=' + encodeURIComponent(phoneArray_p06[j].number);
				}	
			}
		}
		parameter_p06 += '&poi_id=poi06';
		makeRequest('writepoiresults.php', parameter_p06);
		parameter_p06 = '';
	}
}
//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p07() {
	if (!gLocalSearch_p07.results) return;
	var parameter_p07;
	parameter_p07 = '';
	var phoneArray_p07 = [];
	for (var i = 0; i < gLocalSearch_p07.results.length; i++) {
		parameter_p07 += 
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p07.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p07.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p07.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p07.results[i].lat) +
		'&streetaddress=' + encodeURIComponent(gLocalSearch_p07.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p07.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p07.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p07.results[i].country);
		if (gLocalSearch_p07.results[i].ddUrl && gLocalSearch_p07.results[i].ddUrl != null) {
			parameter_p07 += '&ddurl=' + encodeURIComponent(gLocalSearch_p07.results[i].ddUrl);
		}
		if (gLocalSearch_p07.results[i].ddUrlToHere && gLocalSearch_p07.results[i].ddUrlToHere != null) {
			parameter_p07 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p07.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p07.results[i].ddUrlFromHere && gLocalSearch_p07.results[i].ddUrlFromHere != null) {
			parameter_p07 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p07.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p07.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p07.results[i].phoneNumbers.length; j++) {
				phoneArray_p07[j] = gLocalSearch_p07.results[i].phoneNumbers[j];
				if (!phoneArray_p07[j].type == '') {
					parameter_p07 +=
					'&phone'+ phoneArray_p07[j].type + '=' + encodeURIComponent(phoneArray_p07[j].number);
				}	
			}
		}
		parameter_p07 += '&poi_id=poi07';
		makeRequest('writepoiresults.php', parameter_p07);
		parameter_p07 = '';
	}
}
//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p08() {
	if (!gLocalSearch_p08.results) return;
	var parameter_p08;
	parameter_p08 = '';
	var phoneArray_p08 = [];
	for (var i = 0; i < gLocalSearch_p08.results.length; i++) {
		parameter_p08 += 
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p08.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p08.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p08.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p08.results[i].lat) +
		'&streetAddress=' + encodeURIComponent(gLocalSearch_p08.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p08.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p08.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p08.results[i].country);
		if (gLocalSearch_p08.results[i].ddUrl && gLocalSearch_p08.results[i].ddUrl != null) {
			parameter_p08 += '&ddurl=' + encodeURIComponent(gLocalSearch_p08.results[i].ddUrl);
		}
		if (gLocalSearch_p08.results[i].ddUrlToHere && gLocalSearch_p08.results[i].ddUrlToHere != null) {
			parameter_p08 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p08.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p08.results[i].ddUrlFromHere && gLocalSearch_p08.results[i].ddUrlFromHere != null) {
			parameter_p08 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p08.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p08.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p08.results[i].phoneNumbers.length; j++) {
				phoneArray_p08[j] = gLocalSearch_p08.results[i].phoneNumbers[j];
				if (!phoneArray_p08[j].type == '') {
					parameter_p08 +=
					'&phone'+ phoneArray_p08[j].type + '=' + encodeURIComponent(phoneArray_p08[j].number);
				}	
			}
		}
		parameter_p08 += '&poi_id=poi08';
		makeRequest('writepoiresults.php', parameter_p08);
		parameter_p08 = '';
	}
}
//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p09() {
	if (!gLocalSearch_p09.results) return;
	var parameter_p09;
	parameter_p09 = '';
	var phoneArray_p09 = [];
	for (var i = 0; i < gLocalSearch_p09.results.length; i++) {
		parameter_p09 += 
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p09.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p09.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p09.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p09.results[i].lat) +
		'&streetaddress=' + encodeURIComponent(gLocalSearch_p09.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p09.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p09.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p09.results[i].country);
		if (gLocalSearch_p09.results[i].ddUrl && gLocalSearch_p09.results[i].ddUrl != null) {
			parameter_p09 += '&ddurl=' + encodeURIComponent(gLocalSearch_p09.results[i].ddUrl);
		}
		if (gLocalSearch_p09.results[i].ddUrlToHere && gLocalSearch_p09.results[i].ddUrlToHere != null) {
			parameter_p09 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p09.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p09.results[i].ddUrlFromHere && gLocalSearch_p09.results[i].ddUrlFromHere != null) {
			parameter_p09 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p09.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p09.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p09.results[i].phoneNumbers.length; j++) {
				phoneArray_p09[j] = gLocalSearch_p09.results[i].phoneNumbers[j];
				if (!phoneArray_p09[j].type == '') {
					parameter_p09 +=
					'&phone'+ phoneArray_p09[j].type + '=' + encodeURIComponent(phoneArray_p09[j].number);
				}	
			}
		}
		parameter_p09 += '&poi_id=poi09';	
		makeRequest('writepoiresults.php', parameter_p09);		
		parameter_p09 = '';
	}
}
//-------------------------------------------------------------------------------//

// Called when Local Search results are returned, we fire queries in a mysql table to store the found results
function OnLocalSearch_p10() {
	if (!gLocalSearch_p10.results) return;
	var parameter_p10;
	parameter_p10 = '';
	var phoneArray_p10 = [];
	for (var i = 0; i < gLocalSearch_p10.results.length; i++) {
		parameter_p10 += 
		'&titlenoformatting=' + encodeURIComponent(gLocalSearch_p10.results[i].titleNoFormatting) +
		'&url=' + encodeURIComponent(gLocalSearch_p10.results[i].url) +
		'&lng=' + encodeURIComponent(gLocalSearch_p10.results[i].lng) +
		'&lat=' + encodeURIComponent(gLocalSearch_p10.results[i].lat) +
		'&streetAddress=' + encodeURIComponent(gLocalSearch_p10.results[i].streetAddress) +
		'&city=' + encodeURIComponent(gLocalSearch_p10.results[i].city) +
		'&region=' + encodeURIComponent(gLocalSearch_p10.results[i].region) +
		'&country=' + encodeURIComponent(gLocalSearch_p10.results[i].country);
		if (gLocalSearch_p10.results[i].ddUrl && gLocalSearch_p10.results[i].ddUrl != null) {
			parameter_p10 += '&ddurl=' + encodeURIComponent(gLocalSearch_p10.results[i].ddUrl);
		}
		if (gLocalSearch_p10.results[i].ddUrlToHere && gLocalSearch_p10.results[i].ddUrlToHere != null) {
			parameter_p10 += '&ddurltohere=' + encodeURIComponent(gLocalSearch_p10.results[i].ddUrlToHere);
		}
		if (gLocalSearch_p10.results[i].ddUrlFromHere && gLocalSearch_p10.results[i].ddUrlFromHere != null) {
			parameter_p10 += '&ddurlfromhere=' + encodeURIComponent(gLocalSearch_p10.results[i].ddUrlFromHere);
		}
		if (gLocalSearch_p10.results[i].phoneNumbers) {
			for (j = 0; j < gLocalSearch_p10.results[i].phoneNumbers.length; j++) {
				phoneArray_p10[j] = gLocalSearch_p10.results[i].phoneNumbers[j];
				if (!phoneArray_p10[j].type == '') {
					parameter_p10 +=
					'&phone'+ phoneArray_p10[j].type + '=' + encodeURIComponent(phoneArray_p10[j].number);
				}	
			}
		}
		parameter_p10 += '&poi_id=poi10';
		makeRequest('writepoiresults.php', parameter_p10);
		parameter_p10 = '';
	}
}
//-------------------------------------------------------------------------------//

//BS Ende Search POI---------------------------------------------------------------

GSearch.setOnLoadCallback(loadmap);

function fireQueries() {
	gSearchControl = new GSearchControl(); 
	gSearchControl.setResultSetSize(GSearch.LARGE_RESULTSET);
	var el = document.getElementById(checkboxPOIArray[0]);
	if (el.checked == true) {
		gLocalSearch_p01 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p01); 
		gLocalSearch_p01.setCenterPoint(map);
		gLocalSearch_p01.setSearchCompleteCallback(gLocalSearch_p01, OnLocalSearch_p01);
		gLocalSearch_p01.execute(el.value);
	}
	el = document.getElementById(checkboxPOIArray[1]);
	if (el.checked == true) {
		gLocalSearch_p02 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p02); 
		gLocalSearch_p02.setCenterPoint(map);
		gLocalSearch_p02.setSearchCompleteCallback(gLocalSearch_p02, OnLocalSearch_p02);
		gLocalSearch_p02.execute(el.value);
	}
	el = document.getElementById(checkboxPOIArray[2]);
	if (el.checked == true) {
		gLocalSearch_p03 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p03); 
		gLocalSearch_p03.setCenterPoint(map);
		gLocalSearch_p03.setSearchCompleteCallback(gLocalSearch_p03, OnLocalSearch_p03);
		gLocalSearch_p03.execute(el.value);
	}
	el = document.getElementById(checkboxPOIArray[3]);
	if (el.checked == true) {
		gLocalSearch_p04 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p04); 
		gLocalSearch_p04.setCenterPoint(map);
		gLocalSearch_p04.setSearchCompleteCallback(gLocalSearch_p04, OnLocalSearch_p04);
		gLocalSearch_p04.execute(el.value);
	}
	el = document.getElementById(checkboxPOIArray[4]);
	if (el.checked == true) {
		gLocalSearch_p05 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p05); 
		gLocalSearch_p05.setCenterPoint(map);
		gLocalSearch_p05.setSearchCompleteCallback(gLocalSearch_p05, OnLocalSearch_p05);
		gLocalSearch_p05.execute(el.value);
	}
	el = document.getElementById(checkboxPOIArray[5]);
	if (el.checked == true) {
		gLocalSearch_p06 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p06); 
		gLocalSearch_p06.setCenterPoint(map);
		gLocalSearch_p06.setSearchCompleteCallback(gLocalSearch_p06, OnLocalSearch_p06);
		gLocalSearch_p06.execute(el.value);
	}	
	el = document.getElementById(checkboxPOIArray[6]);
	if (el.checked == true) {
		gLocalSearch_p07 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p07); 
		gLocalSearch_p07.setCenterPoint(map);
		gLocalSearch_p07.setSearchCompleteCallback(gLocalSearch_p07, OnLocalSearch_p07);
		gLocalSearch_p07.execute(el.value);
	}
	el = document.getElementById(checkboxPOIArray[7]);
	if (el.checked == true) {
		gLocalSearch_p08 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p08); 
		gLocalSearch_p08.setCenterPoint(map);
		gLocalSearch_p08.setSearchCompleteCallback(gLocalSearch_p08, OnLocalSearch_p08);
		gLocalSearch_p08.execute(el.value);
	}
	el = document.getElementById(checkboxPOIArray[8]);
	if (el.checked == true) {
		gLocalSearch_p09 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p09); 
		gLocalSearch_p09.setCenterPoint(map);
		gLocalSearch_p09.setSearchCompleteCallback(gLocalSearch_p09, OnLocalSearch_p09);
		gLocalSearch_p09.execute(el.value);
	}
	el = document.getElementById(checkboxPOIArray[9]);
	if (el.checked == true) {
		gLocalSearch_p10 = new GlocalSearch();
		gSearchControl.addSearcher(gLocalSearch_p10); 
		gLocalSearch_p10.setCenterPoint(map);
		gLocalSearch_p10.setSearchCompleteCallback(gLocalSearch_p10, OnLocalSearch_p10);
		gLocalSearch_p10.execute(el.value);
	}
}

function makeRequest(url, parameters) {
	if (typeof makeRequestRoot == "undefined") {
		makeRequestRoot = "/mymaps24";
		makeRequestRoot = "";
	}
	var http_request = GXmlHttp.create();
	http_request.open('GET', makeRequestRoot + "/" + url + "?" + parameters, true);
	http_request.onreadystatechange = function() { 
				alertContents(http_request); 
				};
	http_request.send(null);	
}

function alertContents(http_request) {
	if (http_request.readyState == 4) {
		/*if (http_request.status == 200) {
			//alert(http_request.responseText);
			result = http_request.responseText;
			document.getElementById('debug').innerHTML += result;            
		} else {
			alert('There was a problem with the request.');
		}*/
		delete http_request;
	}
}