
//<![CDATA[

var gMapActiveMarkers = new Array();

function gMap_addMarker(latLng, iconObj, otherData) {
	if (iconObj) {
		if (otherData.name && otherData.address1) {
			var infoWindowHtml = "<div class=\"gMap_infoWindow\"><b>" + otherData.name + "</b><br />";
			if (otherData.address1) infoWindowHtml += otherData.address1;
			if (otherData.address2) infoWindowHtml += ", " + otherData.address2;
			if (otherData.address1 || otherData.address2) infoWindowHtml += "<br />";
			if (otherData.city) infoWindowHtml += otherData.city + "<br />";
			if (otherData.postcode) infoWindowHtml += otherData.postcode + "<br />";
			if (otherData.tel) infoWindowHtml += "<b>Tel:</b> " + otherData.tel + "<br />";
			if (otherData.fax) infoWindowHtml += "<b>Fax:</b> " + otherData.fax + "<br />";
			if (otherData.email) infoWindowHtml += "<b>E-mail:</b> <a href=\"mailto:" + otherData.email + "\">" + otherData.email + "</a><br />";
			infoWindowHtml += "</div>";
			var iconClickable = true;
		} else {
			var iconClickable = false;
		}
		var theMarker = new GMarker(latLng, {clickable: iconClickable, icon:iconObj});
		if (infoWindowHtml) {
			theMarker.bindInfoWindowHtml(infoWindowHtml);
		}
	} else {
		theMarker = new GMarker(latLng, {clickable: true});
	}

	if (gMapOption_useMarkerManager) {
		if (otherData && otherData.type.maxzoom == 0) {
			otherData.type.maxzoom = null;
		}
		gMapMarkerManager.addMarker(theMarker, otherData.type.minzoom, otherData.type.maxzoom);
	} else {
		gMap.addOverlay(theMarker);
	}

	return theMarker;
}

function gMap_loadMarkers(typeIds, poiIds) {
	if (typeIds) {
		queryData = "typeid=" + typeIds;
	} else if (poiIds) {
		queryData = "id=" + poiIds;
	} else {
		queryData = "";
	}

	ajaxSendRequest("POST", "/wms/modules/maps/loadmarkers.php", queryData, function(responseText) {
		if (responseText.substring(0, 3) != "ERR") {
			var poiData = eval('(' + responseText + ')');
			if (poiData.pois.length) {
				for (var c = 0; c < poiData.pois.length; c++) {
					var theIcon = new GIcon(G_DEFAULT_ICON);
					theIcon.image = "/templates/images/" + poiData.pois[c].type.icon;
					theIcon.shadow = null;
					theIcon.iconSize = new GSize(20, 20);
					theIcon.iconAnchor = new GPoint(10, 10);

					gMap_addMarker(new GLatLng(poiData.pois[c].lat, poiData.pois[c].long), theIcon, poiData.pois[c]);
				}
			}
		} else {
			alert("An error occurred loading the map markers: " + responseText);
		}
	});
}

function gMap_clearMarkers() {
	gMap.clearOverlays();
}

function gMap_filterMarkers(activeFilters) {
	gMap_clearMarkers();
	gMap_loadMarkers(activeFilters);
}

function gMap_calculateMarkerFilters(elementId) {
	activeFilters = new Array();
	elements = document.getElementsByTagName('input');
	for (i in elements) {
		element = elements[i];
		if (element.type == 'checkbox' && element.id.substring(0, elementId.length) == elementId) {
			if (element.checked) {
				activeFilters.push(element.id.substring(elementId.length));
			}
		}
	}

	gMap_filterMarkers(activeFilters);
}

//]]>

