function loadPoiInfo(id) {
	$("#infoBox").html("<img src='/media/images/ajax-loader.gif' style='margin:105px' />")
	$.ajax({
		type: "POST",
		url: "/php/ajax/show_marker_info.php",
		data: "id="+id,
		success: function(data) {
			$("#infoBox").html(data);
			$(".fg-button").hover(
				function(){ 
					$(this).addClass("ui-state-hover"); 
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			);
			$('.star').rating({
				callback: function(value, link) {
					var rating = value;
					var poiId = $(this).attr("id");
					var ratingType = $(this).attr("name");
					$.ajax({
						type: "POST",
						url: "/php/ajax/update_poi_rating.php",
						async: false,
						data: "rating="+rating+"&poiId="+poiId+"&ratingType="+ratingType,
						success: function (data) {
							
						}
					});	
				}
			});
			$("#poiCommentForm").submit(function() {
				$("#poiCommentForm").validate({
					messages: {
						comment: "Bitte Kommentar eingeben."	
					}	
				});
				if($("#poiCommentForm").valid()) {
					var response = $(this).ajaxSubmit({
						async: false,
						success: function() {
							loadPoiInfo($("#commentPoiId").val());	
						}
					});	
				}	
				return false;
			});	
			$(".poiCommentReport").click(function() {
				var response = $.ajax({
					type: "post",
					url: "/php/ajax/load_comment_report_form.php",
					data: "commentId="+this.id,
					async: false
				}).responseText; 
				// perform the effect 
			    $(this).fadeOut().fadeIn();
			    api = $("#overlay").overlay();
			    api.load();
			    $("#overlayContent").html(response);
			    $(".fg-button").hover(
					function(){ 
						$(this).addClass("ui-state-hover"); 
					},
					function(){ 
						$(this).removeClass("ui-state-hover"); 
					}
				);
				$("#commentReportForm").submit(function() {
					$("#commentReportForm").validate({
						messages: {
							text: "<br/>Bitte geben sie den Grund für ihre Beschwerde ein."	
						}	
					});
					if($("#commentReportForm").valid()) {
						var response = $(this).ajaxSubmit({
							async: false,
							success: function() {
								$("#overlayContent").html("Ihre Beschwerde wurde registriert!");	
							}
						});	
					}	
					return false;
				});	
			});
			// Cancel Button entfernen; keine Idee wie man da ne ID übergeben kann :'( 
			$(".rating-cancel").remove();
		}
	});
}

function loadNewAndEditPoiForm(poiId) {
	globalMap.removeControl(zoomControl);
	if (poiId) {
		tempEditMarker = globalMarkers[poiId].copy();
		tempEditMarkerSmall = globalMarkersSmall[poiId].copy();
		addMarkerListener(tempEditMarker, poiId);
		addMarkerListener(tempEditMarkerSmall, poiId);
		globalMarkers[poiId].enableDragging();	
		globalMarkersSmall[poiId].enableDragging();	
	}
	$.ajax({
		url: "/php/ajax/load_new_and_edit_poi_form.php",
		type: "POST",
		data: "poiId="+poiId,
		success: function(data) {
			$("#infoBox").html(data);
			$(".fg-button").hover(
				function(){ 
					$(this).addClass("ui-state-hover"); 
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			);
			$('#newPoiForm').submit(function() { 
				$("#newPoiForm").validate({
				   errorContainer: "#newPoiErrorHolder",
				   errorLabelContainer: "#newPoiErrorHolder ul",
				   wrapper: "li",
				   messages: {
				   		name: "Bitte Name angeben.",
				   		latitude: "Bitte einen Punkt auf der Karte anklicken.",
				   		longitude: "Bitte einen Punkt auf der Karte anklicken.",
				   		type: "Bitte wählen sie die Art des Markers."
				   }
				});
				if ($("#newPoiForm").valid()) {
					$("#newPoiFormLoader").show();
					//$("#newPoiForm input,button,textarea").attr("disabled", "disabled");
					$("#poiSubmit").attr("disabled", "disabled");
					$(this).ajaxSubmit({
						success: function(poiId) {
							/*var type = $('#newPoiForm #type').fieldValue();
							// großen Marker aktualisieren
							if (globalMarkers[poiId]) {
								globalMarkerManager.removeMarker(globalMarkers[poiId]);	
							}
							theMarkerOptions = createMarkerOptions(type[0], false);
							var latitude = $('#newPoiForm #latitude').fieldValue();
							var longitude = $('#newPoiForm #longitude').fieldValue();
							theMarker = createMarker(new GLatLng(latitude[0], longitude[0]), theMarkerOptions, poiId);
							theMarker.disableDragging();
							globalMarkerManager.addMarker(theMarker, 14);
							globalMarkers[poiId] = theMarker;
							// kleinen Marker aktualisieren
							if (globalMarkersSmall[poiId]) {
								globalMarkerManager.removeMarker(globalMarkersSmall[poiId]);
							}
							theMarkerOptions = createMarkerOptions(type[0], true);
							var latitude = $('#newPoiForm #latitude').fieldValue();
							var longitude = $('#newPoiForm #longitude').fieldValue();
							theMarker = createMarker(new GLatLng(latitude[0], longitude[0]), theMarkerOptions, poiId);
							theMarker.disableDragging();
							globalMarkerManager.addMarker(theMarker, 12, 13);
							globalMarkersSmall[poiId] = theMarker;
							// Marker-Manager neuladen
							globalMarkerManager.refresh();
							$("#newPoiForm input,button,textarea").attr("disabled", "");*/	
							loadMapIconInfo();								
						}
					});
				} else {
					return false;	
				}
				
				return false;
			});
		}	
	})	
}

function loadMapIconInfo(editMarkerId) {
	globalMap.addControl(zoomControl);
	if (editMarkerId == null) editMarkerId = false;
	$.ajax({
		url: "/php/ajax/load_map_icon_info.php",
		type: "POST",
		success: function(data) {
			$("#infoBox").html(data);
			if (tempMarkers[0] != undefined && tempMarkers[1] != undefined) {
				globalMarkerManager.removeMarker(tempMarkers[0]);
				globalMarkerManager.removeMarker(tempMarkers[1]);
				globalMarkerManager.refresh();
			}
			if (editMarkerId) {
				globalMarkers[editMarkerId].setLatLng(tempEditMarker.getLatLng());
				globalMarkers[editMarkerId].disableDragging();
				globalMarkersSmall[editMarkerId].setLatLng(tempEditMarker.getLatLng());
				globalMarkersSmall[editMarkerId].disableDragging();
				globalMarkerManager.refresh();
			}
			$(".fg-button").hover(
				function(){ 
					$(this).addClass("ui-state-hover"); 
				},
				function(){ 
					$(this).removeClass("ui-state-hover"); 
				}
			);
		}	
	})		
}

function loadNewBoatForm() {
	$.ajax({
		url: "/php/ajax/load_new_boat_form.php",
		success: function(data) {
			$("#categoryBoats").html(data);
			$("#newBoatForm").submit(function() {
				$("#newBoatForm").validate({
					errorContainer: "#newBoatErrorHolder",
				   	errorLabelContainer: "#newBoatErrorHolder ul",
				  	wrapper: "li",
					messages: {
						name: "Bitte geben sie den Namen des Bootes ein.",
						description: "Bitte geben sie eine Beschreibung des Boots ein.",
						price: "Bitte geben sie einen Preis für ihr Angebot an.",
						termsOfContent: "Bitte lesen und akzeptieren sie die Nutzungsbedingungen!"	
					}	
				});
		 		if($("#newBoatForm").valid()) {
					$(this).ajaxSubmit({
						async: false,
						success: function(data) {
							window.location.href = "/content/bootsmarkt/"+data;
						}
					});	
				}		
		 		return false;
		 	});
			$("#file").fileUpload({
				fileExt: "*.png;*.jpg;*.gif",
				fileDesc: "Bitte wählen sie eine Bild-Datei aus.",
				sizeLimit: "500000",
				uploader: "/media/flash/uploader.swf",
				script: "/php/ajax/do_boat_image_upload.php",
				buttonText: "Durchsuchen",
				auto: true,
				multi: true,
				onError: function (a, b, c, d) {
			         if (d.status == 404)
			            alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
			         else if (d.type === "HTTP")
			            alert('error '+d.type+": "+d.status);
			         else if (d.type ==="File Size") {
			            $(".fileName").html("Datei zu groß. Maximal: "+Math.round(d.sizeLimit/1024)+'KB');
			            return false;
			         } else
			            alert('error '+d.type+": "+d.text);
				},
				onComplete: function(event, queueId, fileObj, response) {
					$(".percentage").html(" komplett hochgeladen");
					$(".cancel").hide();
					//$("#uploadButton").hide();
					//$("#fileQueue").after("<img src='/media/images/tmp/"+response+"' style='float:left;height:150px;' />");
					$("#fileQueue").after("<input class='uploadedFile' id='file_"+queueId+"' name='file_"+queueId+"' type='hidden' value='"+response+"' />");
					return false;
				}
			});
		}
	});		
}

function loadWaterWayKilometerSelector(areaId, kilometer) {
	$.ajax({
		url: "/php/ajax/load_water_way_kilometer_selector.php",
		type: "POST",
		data: "areaId="+areaId+"&kilometer="+kilometer,
		success: function(data) {
			$("#kilometerSelectBox").html(data);	
		}
	});	
}
