/**
 * This javascript offers functions for the mapping templates.
 * This script needs the JQuery Framework
 *
 *@author: Ihsan B. Bikmaz namics ag Zürich
 *@copyright	(c) 2008 coop
 */

/**
 * Creating Namespaces.
 * Globale NS COOP
 * Event NS Events.
 * NS for Map.
 */
var COOP 	= {};
COOP.GeoCoder = {};
COOP.Events = {};
COOP.Gui = {};
COOP.Map 	= {
	ew			: null,
	map			: null,
	mapListner	: null,
	handleEvent : true,
	start 		: "",
	baseIcon	: []
};

/* Starting Point */
$(document).ready( function() { 
	COOP.Events.bindEventsNavigation();
	COOP.Events.bindEventsFilter();
	COOP.Events.bindResultListEvents();
	COOP.Events.bindEventsInfoBox();
	COOP.Events.bindEventsSearchCriteria();
	
	if (GBrowserIsCompatible()) {
		COOP.GeoCoder = new GClientGeocoder();
		COOP.Map.LoadMap();
	} else {
		alert("Sorry, the Google Maps API is not compatible with your browser");
	}

	$("#query").autocomplete("ajaxSuggest.do", {
	                delay:0,
	                minChars:4,
	                matchSubset:false,
	                matchContains:false,
	                cacheLength:1,
	                afterAutocompleteSelection: true,
					selectFirst: false,
	                autoFill: false,
	                scroll: true
			});

});

/**
  * Change the background of the Navigation when clicked
  */
COOP.Events.bindEventsNavigation = function ()
{
	$("#Navigation li").click( function(){
		$("li", this.parentNode).removeClass();
		$(this).addClass("active");
	});
}

/**
  * Hover event for the result list
  */
COOP.Events.bindResultListEvents = function ()
{
	$("#ResultList li").hover( 
		function(){$(this).addClass("bordered");},
		function(){$(this).removeClass("bordered");}
	);
	
}

COOP.Events.unbindResultListEvents = function () 
{
	//$("#ResultList li").unbind();
}

/**
  * Open and Close the additional filters
  */
COOP.Events.bindEventsFilter = function ()
{
	// open filters
	$("#AddFilterOpen").click( function(){
		$("#AdditionalFilters, #AddFilterClose").toggle();
		$(this).hide();
	});
	
	// close filters
	$("#AddFilterClose").click( function(){
		$("#AdditionalFilters, #AddFilterOpen").toggle();
		$(this).hide();
	});
}

COOP.Events.bindEventsInfoBox = function() {
	
	// jeweils die zwei anderen info-boxen schliessen und die eigene toggeln
	$("#InfoBox1").click( function(){
		$("#InfoBox2").removeClass("opened");
		$("#InfoBox2").addClass("closed");
		
		$("#InfoBox3").removeClass("opened");
		$("#InfoBox3").addClass("closed");
		
		$("#InfoBoxBenzin").removeClass("opened");
		$("#InfoBoxBenzin").addClass("closed");
		
		$("#InfoBoxEvents").removeClass("opened");
		$("#InfoBoxEvents").addClass("closed");
		
		$("#InfoBox1").toggleClass("closed");
		$("#InfoBox1").toggleClass("opened");
	});

	$("#InfoBoxBenzin").click( function(){
		$("#InfoBox1").removeClass("opened");
		$("#InfoBox1").addClass("closed");
		
		$("#InfoBox2").removeClass("opened");
		$("#InfoBox2").addClass("closed");
		
		$("#InfoBox3").removeClass("opened");
		$("#InfoBox3").addClass("closed");	
	
		$("#InfoBoxEvents").removeClass("opened");
		$("#InfoBoxEvents").addClass("closed");
	
		$("#InfoBoxBenzin").toggleClass("closed");
		$("#InfoBoxBenzin").toggleClass("opened");
	});


	$("#InfoBox2").click( function(){
		$("#InfoBox1").removeClass("opened");
		$("#InfoBox1").addClass("closed");
		
		$("#InfoBox3").removeClass("opened");
		$("#InfoBox3").addClass("closed");
		
		$("#InfoBoxBenzin").removeClass("opened");
		$("#InfoBoxBenzin").addClass("closed");

		$("#InfoBoxEvents").removeClass("opened");
		$("#InfoBoxEvents").addClass("closed");
		
	
		$("#InfoBox2").toggleClass("closed");
		$("#InfoBox2").toggleClass("opened");
	});

	$("#InfoBox3").click( function(){
		$("#InfoBox1").removeClass("opened");
		$("#InfoBox1").addClass("closed");
		
		$("#InfoBox2").removeClass("opened");
		$("#InfoBox2").addClass("closed");
		
		$("#InfoBoxBenzin").removeClass("opened");
		$("#InfoBoxBenzin").addClass("closed");
		
		$("#InfoBoxEvents").removeClass("opened");
		$("#InfoBoxEvents").addClass("closed");
		
		
		$("#InfoBox3").toggleClass("closed");
		$("#InfoBox3").toggleClass("opened");
	});
	
	$("#InfoBoxEvents").click( function(){
		$("#InfoBox1").removeClass("opened");
		$("#InfoBox1").addClass("closed");
		
		$("#InfoBox2").removeClass("opened");
		$("#InfoBox2").addClass("closed");
		
		$("#InfoBoxBenzin").removeClass("opened");
		$("#InfoBoxBenzin").addClass("closed");
		
		$("#InfoBox3").removeClass("opened");
		$("#InfoBox3").addClass("closed");
		
		$("#InfoBoxEvents").toggleClass("closed");
		$("#InfoBoxEvents").toggleClass("opened");
	});
}

COOP.Events.bindEventsSearchCriteria = function() {
	$(".filterCheckBox").click( function() {
		var name = $(this)[0].name;
		var state = $(this)[0].checked;
		setSearchCriteria(name,state);
	});
}

/**
 * Loads the map and creates the controls
 * Also the global map event handler can be added here.
 * We use the ewindow plugin for displaying custom flyouts 
 */
COOP.Map.LoadMap = function()
{     
	COOP.Map.map = new GMap2(document.getElementById("Map"));
	var map = COOP.Map.map;
	var loadMap = true;
	var timeSearch = false;
	
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	var startBetriebsnummer = $("#startBetriebsnummer")[0].value;
	if (startBetriebsnummer != "") {
		var center = new GLatLng($("#startLat")[0].value, $("#startLng")[0].value);
		var zoom = $("#startZoom")[0].value
		map.setCenter(center, zoom * 1);
		//die startnummer merken, wenn gesetzt werden die details gelasen (siehe ajax)
		COOP.Map.start = startBetriebsnummer;
		
	} else {
		var startQuery = $("#startQuery")[0].value;
		timeSearch = ($("#timeSearch")[0].value) == "true";
		if (startQuery != "" || timeSearch) {
			//alert("handling start query: " + startQuery + " timeSearch: " + timeSearch);
			$("#query")[0].value = startQuery;
			loadMap = false;
			
		} 
		var center = new GLatLng(47.0754, 8.1355);
		map.setCenter(center, 7);
		
	}
	
	
	var mapTypes = map.getMapTypes();
	for (var i = 0; i < mapTypes.length; i++) {
		mapTypes[i].getMinimumResolution = function() {
			return 7;
		}
		mapTypes[i].getMaximumResolution = function() {
			return 17;
		}
	}
	
	// Create an EWindow
	COOP.Map.ew = new EWindow(map, E_STYLE_COOP);      
	map.addOverlay(COOP.Map.ew);
	
	var icon 				= new GIcon();
	icon.image				= document.getElementById("pinImage").value;
	icon.shadow				= document.getElementById("pinShadowImage").value;
	var pinWidth			= document.getElementById("pinWidth").value;
    icon.iconSize 			= new GSize(pinWidth, 48);
    icon.iconAnchor 		= new GPoint(0, 48);
    icon.infoWindowAnchor 	= new GPoint(3, 38);
	COOP.Map.baseIcon['Coop'] = icon;
	
	COOP.Map.mapListener = GEvent.addListener(map, "moveend", function() {COOP.Map.mapChanged();});  
	//erster aufruf, damit die kantone erscheinen
	if (loadMap) {
		COOP.Map.mapChanged();
	} else {
		if (timeSearch) {
			newWin('showTimeSearch.do', '_blank', '');
		} else {
			showLocation();
		}
	}
	
}

/**
 * Create the marker with InfoWindow
 * @param	{GPoint}	point 		Position
 * @param	{String}	html 		Html for the flyout
 */
COOP.Map.createMarkerWithInfoWindow = function(lat, lng, html, betriebsnummer, closedescr)
{
    var myIcon 		= new GIcon(COOP.Map.baseIcon["Coop"]);
    markerOptions 	= { icon:myIcon };
    var point 		= new GLatLng(lat, lng);
    var marker 		= new GMarker(point, markerOptions);
	
	GEvent.addListener(marker, "click", function() 
	{
		COOP.Map.handleEvent=false;
		COOP.Map.map.setCenter(new GLatLng(lat, lng));
		COOP.Map.handleEvent=false;
		COOP.Map.map.panBy(new GSize(0,30)); 
		COOP.Map.ew.openOnMarker(marker, html, closedescr);
		COOP.Map.showDetail(betriebsnummer);
	});
	return marker;
}

/**
 * Create the marker 
 * @param	{GPoint}	point 		Position
 */
COOP.Map.createMarker = function(lat, lng, zoom)
{
    var myIcon 		= new GIcon(COOP.Map.baseIcon["Coop"]);
    markerOptions 	= { icon:myIcon };
    var point 		= new GLatLng(lat, lng);
    var marker 		= new GMarker(point, markerOptions);
    GEvent.addListener(marker, "click", function() 
	{
		COOP.Map.moveMap(lat, lng, zoom);
	});
	return marker;
}

/**
 * Aufruf der Detail-Daten
 */
COOP.Map.showDetail = function(betriebsnummer) {
	getVstInfo(betriebsnummer);
}


/**
 * Function um die Map neu zu positionieren
 */
COOP.Map.moveMap = function(lat, lng, zoom) {
	//alert("moving map lat: " + lat + " lng " + lng + " zoom " + zoom);
	var map = COOP.Map.map;
	var point = new GLatLng(lat * 1, lng * 1);
	COOP.Map.map.setCenter(point, zoom * 1);
 	//alert("map moved");
}


/**
 * Main Event handling function
 * löscht alle marker und ruft ajax event auf
 */
COOP.Map.mapChanged = function() {
	//prüfung, ob im moment überhaupt auf den event reagiert werden soll.
	//wenn ein move erfolgt, weil eine Fahne angeklickt wurde um die VST-Details zu sehen,
	//moved der Marker in die Mitte und es wird NICHT neu gelesen.
	if (COOP.Map.handleEvent) {
		var map = COOP.Map.map;
		var bounds = map.getBounds();
		var southWest = bounds.getSouthWest();
		var northEast = bounds.getNorthEast();
		var zoom = map.getZoom();
		COOP.Map.clearMap();
		getMarkersForArea(southWest, northEast, zoom);
	} else {
		COOP.Map.handleEvent = true;
	}
}

COOP.Map.clearMap = function() {
	var map = COOP.Map.map;
	//bisherige marker entfernen
	map.clearOverlays();
	//das event-window wieder hinzufügen
	map.addOverlay(COOP.Map.ew);
	//liste leeren
	COOP.Gui.clearStandortList();
}

/**
 * Returns html for the flyout content
 * @param	{String}	strTitel 		Title of the store
 * @param	{String}	strStreet 		Street and Nr.
 * @param	{String}	strZip 		Zip Code an
 * @param	{String}	strTel 		Telephone
 * @param	{String}	strChef 		Chef of the store
 * @retuns	{String}	Generated HTML
 */
COOP.Gui.flyoutHtml = function( strTitle, strStreet, strZip, strTel, strChef, strPhoneDescr, strChiefDescr)
{
 return	'<h1>'+ strTitle +'</h1>'
		+'<p>'+ strStreet +'</p>'
		+'<p>'+ strZip +'</p>'
		+'<p>' + strPhoneDescr + ':'+ strTel +'</p>'
		+'<br /><p>' + strChiefDescr + ': '+ strChef +'</p>'
}



/**
 * Remove all entries from the Standort-List
 */
COOP.Gui.clearStandortList = function() {
	$("#standortList").empty();
	$("#regionList").empty();
}

COOP.Gui.clearSearchResultList = function() {
	$("#searchResult").empty();
}

/**
 * Ein Standort (VST) der Liste hinzufügen
 */
COOP.Gui.appendStandortToList = function(betriebsnummer, name, street, city, phone, chief, lat, lng, phonedescr, chiefdescr, closedescr) {

	//create marker
	var html = COOP.Gui.flyoutHtml(name, street, city, phone, chief, phonedescr, chiefdescr);
	var marker = COOP.Map.createMarkerWithInfoWindow(lat, lng, html, betriebsnummer, closedescr);
	
	COOP.Map.map.addOverlay(marker);
	
	//get ul entry
	var list = $("#ResultList")[0];
	var ul = $("#standortList", list);
	if (ul.length == 0) {
		$("<ul id=\"standortList\" ></ul>").appendTo(list);
	}
	ul = $("#standortList", list)[0];
	
	//add entry to list
 	var li = $("<li><p class=\"title\">" + city + "</p><p>" + street + "</p></li>");
 	li.appendTo(ul);
 	
 	li.click(function() {
 		COOP.Gui.clearSearchResultList();
		COOP.Map.handleEvent=false;
		COOP.Map.map.setCenter(new GLatLng(lat, lng));
		COOP.Map.handleEvent=false;
		COOP.Map.map.panBy(new GSize(0,30)); 
		COOP.Map.ew.openOnMarker(marker, html, closedescr);
		COOP.Map.showDetail(betriebsnummer);
	});
 	
 	if (COOP.Map.start != "" && COOP.Map.start == betriebsnummer) {
 		COOP.Map.handleEvent=false;
		COOP.Map.map.panBy(new GSize(0,30)); 
		COOP.Map.ew.openOnMarker(marker, html, closedescr);
	}
}

/**
 * Eine Region (Kanton oder Ort) der Liste hinzufügen
 */
COOP.Gui.appendRegionToList = function(text, lat, lng, zoom) {
	
	//create marker
	var marker = COOP.Map.createMarker(lat, lng, zoom);
	COOP.Map.map.addOverlay(marker);

	//get ul entry
	var list = $("#ResultList")[0];
	var ul = $("#regionList", list);
	if (ul.length == 0 ) {
		ul = $("<ul id=\"regionList\" class=\"regional\"></ul>").appendTo(list);
	}
	ul = $("#regionList", list)[0];

	
	//add entry to list
 	var li = $("<li>" + text + "</li>");
 	li.appendTo(ul);
 	li.click(function(){ 
 		COOP.Gui.clearSearchResultList();
 		COOP.Map.moveMap(lat, lng, zoom); 
 	});
}

/**
 * Eine Region (Kanton oder Ort) der Liste hinzufügen
 */
COOP.Gui.appendSearchResultToList = function(text, lat, lng, zoom) {

	//get ul entry
	var list = $("#ResultList")[0];
	var ul = $("#searchResult", list);
	if (ul.length == 0) {
		$("<ul id=\"searchResult\" class=\"searchresult\"></ul>").appendTo(list);
	}
	ul = $("#searchResult", list)[0];

	
	//add entry to list
 	var li = $("<li>" + text + "</li>");
 	li.appendTo(ul);
 	li.click(function(){ COOP.Map.moveMap(lat, lng, zoom); });
}

/**
 * Hide the detail-Message and show the vst-detail-divs
 */
COOP.Gui.showInfoBoxen = function(openedBox) {
	$(".mapHelpInfo").hide("slow");
	$(".mapHelpInfo").empty();
	
	$("#Print").show();
	
	$("#InfoBoxGeneral").addClass("hidden");
	$("#InfoBoxGeneral").show();
	COOP.Gui.checkNameSize();
	$("#InfoBoxGeneral").removeClass("hidden");
	
	$("#InfoBox1").removeClass("opened").show();
	$("#InfoBox1").addClass("closed").show();

	if (openedBox == "InfoBoxBenzin") { 
		$("#InfoBoxBenzin").removeClass("opened").show();
		$("#InfoBoxBenzin").addClass("closed").show();
	} else {
		$("#InfoBoxBenzin").hide();
	}
	
	$("#InfoBox2").removeClass("opened").show();
	$("#InfoBox2").addClass("closed").show();
	
	$("#InfoBox3").removeClass("opened").show();
	$("#InfoBox3").addClass("closed").show();
	
	if ($("#InfoBoxEvents p").text().length > 0) {
		$("#InfoBoxEvents").removeClass("opened").show();
		$("#InfoBoxEvents").addClass("closed").show();
	} else {
		$("#InfoBoxEvents").hide();
	}

	//die richtige box öffnen
	$("#" + openedBox).removeClass("closed").addClass("opened");
	
	$("#RightContent").addClass("bordered");
	
}

/*
 * Set message in right content
 */
COOP.Gui.setDetailMessage = function(text) {
	
	$("#Print").hide("slow");
	$("#InfoBoxGeneral").hide("slow");
	$("#InfoBox1").hide("slow");
	$("#InfoBoxBenzin").hide("slow");
	$("#InfoBox2").hide("slow");
	$("#InfoBox3").hide("slow");
	$("#InfoBox1").hide("slow");
	$("#InfoBoxEvents").hide("slow");
	
	$("#RightContent").removeClass("bordered");
	$(".mapHelpInfo")[0].innerHTML = "";
	var msg = $("<div><p>" + text + "</p></div>");
	msg.appendTo($(".mapHelpInfo")[0]);
	$(".mapHelpInfo").show();
}

COOP.Gui.setVstData = function(xml) {
	//alert(xml.xml);
	var box = $("#InfoBoxGeneral")[0];
	
	//link für print
	$("#Print").unbind();
	$("#Print").click( function() {
		openPrintWindow();
		printWindow.location.href = "showPrintView.do?betrnr=" + $("betrnr",xml).text();
	});
	
	
	//Name und Adresse
	$("h1",box)[0].innerHTML = $("vst-name",xml).text();
	
	$(".address",box)[0].innerHTML = $("vst-adresse", xml).text();

	//link für startseite
	var startPageLink = "setStartPage.do?betrnr=" + $("betrnr",xml).text() ;
	startPageLink = startPageLink + "&zoom=" + COOP.Map.map.getZoom();
	$("#startpage").unbind();
	$("#startpage").click( function() {
		openPopup();
		popupWindow.location.href = startPageLink;
	});

	//Geschäftsführer
	var chief = $("vst-geschaeftsfuehrer", xml).text();
	if (chief == "") {
		$("#vst-geschaeftsfuehrer-h2",box).hide();
		$("#vst-geschaeftsfuehrer").empty();
	} else {
		$("#vst-geschaeftsfuehrer-h2",box).show();
		$("#vst-geschaeftsfuehrer")[0].innerHTML = chief;
	}
	
	//Parkplätze
	var parkplaetze = $("vst-parkplaetze", xml).text();
	var parkhaeuser = $("parkhaeuser", xml).text();
	if (parkplaetze == "" && parkhaeuser == "") {
		$("#vst-parkplaetze-h2").hide();
		$("#vst-parkplaetze").empty();
	} else {
		$("#vst-parkplaetze-h2").show();
		if (parkhaeuser == "") {
			$("#vst-parkplaetze")[0].innerHTML = parkplaetze;
		} else {
			$("#vst-parkplaetze")[0].innerHTML = parkhaeuser;
		}
	}
	
	//Routenplaner
	$("#vst-route")[0].href = $("vst-route",xml).text();
	$("#vst-fahrplan")[0].href = $("vst-fahrplan",xml).text();
	
	//Kredit, Debitkarten
	$("#vst-kreditkarten", box)[0].innerHTML = $("kreditkarten",xml).text();
	$("#vst-debitkarten", box)[0].innerHTML = $("debitkarten",xml).text();

	//Image
	var imageUrl = $("vst-image",xml).text();
	if (imageUrl == "") {
		$("#vst-image").hide();
	} else {
		$("#vst-image").show();
		$("#vst-image", box)[0].src = imageUrl;
	}
	
	//Benzinpreise
	var benzinpreise = $("benzinpreise", xml).text();
	$("#benzinpreise").empty();
	if (benzinpreise != "") {
		$("#benzinpreise").append($(benzinpreise));
	}
	
	//Standard-Öffnungszeiten
	var oeffnungszeiten = $("vst-oeffnung",xml).text();
	$("#vst-oeffnung").empty();
 	$("#vst-oeffnung").append($(oeffnungszeiten));

 	//Abendverkauf	
 	var abendverkauf = $("vst-abendverkauf", xml).text();
 	$("#vst-abendverkauf").empty();
 	if (abendverkauf != "") {
	 	$("#vst-abendverkauf").append($(abendverkauf));
	 }

	//Sonderverkauf
 	$("#vst-sonderverkauf").empty();
	if ($("vst-sonderverkauf", xml).length > 0) {
		$("#vst-sonderverkauf-h2").show();
	 	var sonderverkauf = $("vst-sonderverkauf", xml).text();
	 	$("#vst-sonderverkauf").append($(sonderverkauf));
	} else {
		$("#vst-sonderverkauf-h2").hide();
	} 	
	
	//angebot
	box = $("#InfoBox2")[0];
	var angebot = "<p>" + $("vst-sortiment", xml).text(); + "</p>";
	$(".tabContent",box).empty();
	$(".tabContent",box).append($(angebot));
	
	//dienstleistung
	box = $("#InfoBox3")[0];
	angebot = "<p>" + $("vst-dienstleistung", xml).text(); + "</p>";
	$(".tabContent",box).empty();
	$(".tabContent",box).append($(angebot));
	
	//events
	box = $("#InfoBoxEvents")[0];
	angebot = "<p>" + $("vst-event", xml).text(); + "</p>";
	$(".tabContent",box).empty();
	$(".tabContent",box).append($(angebot));

}

COOP.Gui.checkNameSize = function() {
	$("h1",$("#InfoBoxGeneral")).css("font-size", "1.63em");
	var width = $("h1",$("#InfoBoxGeneral")).width();
	if (width > 153) {
		$("h1",$("#InfoBoxGeneral")).css("font-size", "1.4em");
	} else {
		$("h1",$("#InfoBoxGeneral")).css("font-size", "1.63em");
	}
}

// showLocation() is called when you click on the Search button
// in the form.  It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
	var address = $("#SearchField input")[0].value + " CH";
	COOP.Gui.clearSearchResultList();
	if (address != "") {
		COOP.GeoCoder.getLocations(address, processSearchResult);
	}
}


// processSearchResult() is called when the geocoder returns an
// answer. 
function processSearchResult(response) {
	var searchNoResultMessage = $("#searchNoResultMessage")[0].value;
	if (!response || response.Status.code != 200) {
		//alert(searchNoResultMessage);
		//alert("Sorry, we were unable to geocode that address, Status-Code:" + response.Status.code);

		var vstName = $("#SearchField input")[0].value;
		var map = COOP.Map.map;
		var zoom = map.getZoom();
		getVstLocations(zoom, vstName);

	} else {
		COOP.Map.clearMap();
		var isSelected = false;
		if (response.Placemark != null) {
			
			for (i=0; i<response.Placemark.length; i++) {
				place = response.Placemark[i];
				lat = place.Point.coordinates[1];
				lng = place.Point.coordinates[0];
				//alert("found place " + place.address + " " + lat + " " + lng);
				if (lat < 48.05 && lat > 45.48 && lng <10.83 && lng > 5.44) {
					name = place.address;
					zoom = document.getElementById("SearchSelectBox").value;
					
					COOP.Gui.appendSearchResultToList(name, lat, lng, zoom)
					//addPlaceToList(lat, lng, zoom, name);
					if (!isSelected) {
						isSelected = true;
						var moveToLat = lat;
						var moveToLng = lng;
						var moveToZoom = zoom * 1;
					}
				} 
			}
		}
		if (isSelected) {
			COOP.Map.moveMap(moveToLat, moveToLng, moveToZoom);						
		} else {
			alert(searchNoResultMessage);
		}
	}
}

function processSearchVstResult(xml) {
	var searchNoResultMessage = $("#searchNoResultMessage")[0].value;
	if ($("status",xml).text() != "success") {
		if ($("status",xml).text() == "sessionNotValid") {
			window.location = window.location;
		} else {
			alert(searchNoResultMessage);
		}
	} else {
		//alert(xml.xml);
		COOP.Map.clearMap();
		var isSelected = false;
		var standortList = $("standort",xml);
		for (var i=0; i<standortList.length; i++) {
			var standort = standortList[i];
			var name = $("name",standort).text();
			var lat = $("lat", standort).text();
			var lng = $("lng", standort).text();
			//alert("found place " + place.address + " " + lat + " " + lng);
			if (lat < 48.05 && lat > 45.48 && lng <10.83 && lng > 5.44) {
				zoom = document.getElementById("SearchSelectBox").value;
				COOP.Gui.appendSearchResultToList(name, lat, lng, zoom)
				//addPlaceToList(lat, lng, zoom, name);
				if (!isSelected) {
					isSelected = true;
					var moveToLat = lat;
					var moveToLng = lng;
					var moveToZoom = zoom * 1;
				}
			} 
		}
		if (isSelected) {
			COOP.Map.moveMap(moveToLat, moveToLng, moveToZoom);						
		} else {
			alert(searchNoResultMessage);
		}
	}
}


$("#PoiDownload").click( function() {
	openPrintWindow();
	printWindow.location.href = "showPoiDownload.do";
});



