// leitet die CategoryId der Veranstaltungen an die Datei load_events_by_category.php weiter - Copyright: Florian Häußler
function loadEventsByCategory(categoryId) {
	$.ajax({
		type: "POST",
		url: "/php/ajax/load_events_by_category.php",
		data: "categoryId="+categoryId,
		success: function(data) {
			$('#categoryEvents').html(data);
		}
	});
}

// leitet die CategoryId der Boote an die Datei load_boats_by_category.php weiter - Copyright: Florian Häußler
function loadBoatsByCategory(categoryId) {
	$.ajax({
		type: "POST",
		url: "/php/ajax/load_boats_by_category.php",
		data: "categoryId="+categoryId,
		success: function(data) {
			$('#categoryBoats').html(data);
		}
	});
}

function calcKw(ps) {
	ps = ps.replace(/,/g, ".");
	kw = Math.round(ps / 1.35962162);
	$("#powerKw").val(kw);
}

function calcPs(kw) {
	kw = kw.replace(/,/g, ".");
	ps = Math.round(kw / 0.73549875);
	$("#powerPs").val(ps);	
}

function reportPoiComment(poiId, userId) {
	if (confirm("Wenn ein Kommentar anstößige oder rassistische Äusserungen, Werbung oder andere unzulässige Inhalte enthält können sie ihn hiermit melden. Das Wassersportlotse-Team wird den Kommentar gegebenenfalls löschen.\n\nWollen sie den Kommentar wirklich melden?")) {
		$.ajax({
			type: "POST",
			url: "/php/ajax/report_poi_comment.php",
			data: "poiId="+poiId+"&userId="+userId,
			async: false,
			success: function() {
				loadPoiInfo(poiId);
			}
		});		
	}
}
function checkValidNumbers() {
	$('.valid-number').keyup(function(e) {
		validKeyCodes = Array(44, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 110, 188, 190);
		tmpVal = "";
		comma_at = null;
		points_at = Array();
		for (i = 0; i < $(this).val().length; i++) {
			if (jQuery.inArray($(this).val().charCodeAt(i), validKeyCodes) >= 0) {
				if ($(this).val().charCodeAt(i) == 44 && comma_at != null) continue;
				if (comma_at != null && i > comma_at + 2) continue;
				if ($(this).val().charCodeAt(i) == 44) comma_at = i;
				
				tmpVal += $(this).val().charAt(i);
			}
		}
		$(this).val(tmpVal);
	});
}
