if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("mapCanvas") ); map.setCenter(new GLatLng(-5.52, 35) ,5, G_HYBRID_MAP); map.addControl(new GLargeMapControl()); // map.addControl(new GSmallMapControl()); map.addControl(new CustomTypeControl()); map.enableDragging() ; map.enableDoubleClickZoom() ; var icon = new GIcon(); icon.image = "images/mapicons/o.png"; icon.iconSize = new GSize(11, 11); icon.iconAnchor = new GPoint(5, 5); var icon2 = new GIcon(); icon2.image = "images/mapicons/transparent.gif"; icon2.iconSize = new GSize(16, 16); icon2.iconAnchor = new GPoint(8, 8); mapLeft = removePx(document.getElementById('mapCanvas').style.left) ; mapTop = removePx(document.getElementById('mapCanvas').style.top) ; mapWidth = removePx(document.getElementById('mapCanvas').style.width) ; mapHeight = removePx(document.getElementById('mapCanvas').style.height) ; if (browserType == "Mozilla" ) { mapLeft = mapLeft - 1 ; mapTop = mapTop - 1 ; } mapRight = mapLeft + mapWidth - 1 ; mapBottom = mapTop + mapHeight - 1 ; makeMouseDownPoint() ; // Polygoon tekenen var points = []; // Draw polygon on map GEvent.addListener(map, 'click', function(overlay, point) { if ( selectedMapTool == "maptoollasso" && mouseIsInInfoWindow != "yes") { if (overlay && points.length > 2) { points.push(points[0]); map.clearOverlays(); map.addOverlay(new GPolyline(points, "#FFFF00", 2, 1)); var thisPolygonGoogleMaps = "" ; var thisPolygonSQL = "" ; for (var i = 0 ; i < points.length; i ++) { if (i > 0) { thisPolygonGoogleMaps += "," ; thisPolygonSQL += "," ; } var thisLongitude = points[i].lng() ; var thisLatitude = points[i].lat() ; thisPolygonGoogleMaps += thisLatitude + " " + thisLongitude ; thisPolygonSQL += thisLongitude + " " + thisLatitude ; } showRectangleOrLassoSelection(thisPolygonGoogleMaps,thisPolygonSQL,"points","no") ; document.getElementById("storemapselectionresults").innerHTML = "" ; ajaxGetData('/inc/res.storemapseleection.php?points='+escape(thisPolygonSQL)+'&areaid=','storemapselectionresults'); points = [] ; } else if (point) { numberOfPoints = points.length ; if (numberOfPoints == 0) { clearAll(false) ; } else if (numberOfPoints > 1) { var startPoint = map.fromContainerPixelToLatLng(points[0]) ; var endPoint = map.fromContainerPixelToLatLng(points[numberOfPoints-1]) ; if (startPoint.toString() == endPoint.toString() ) { clearAll(false) ; } } else { map.clearOverlays(); } points.push(point); map.addOverlay(new GPolyline(points, "#FFFF00", 2, 1)); map.addOverlay(new GMarker(points[0], icon)); } } else { makeMouseDownPoint(); } }); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } var preload_maptool_1 = new Image ; preload_maptool_1.src = "images/maptools/grab_hover.jpg" ; var preload_maptool_2 = new Image ; preload_maptool_2.src = "images/maptools/rectangle_hover.jpg" ; var preload_maptool_3 = new Image ; preload_maptool_3.src = "images/maptools/lasso_hover.jpg" ; var preload_maptool_4 = new Image ; preload_maptool_4.src = "images/maptools/grab_selected.jpg" ; var preload_maptool_5 = new Image ; preload_maptool_5.src = "images/maptools/rectangle_selected.jpg" ; var preload_maptool_6 = new Image ; preload_maptool_6.src = "images/maptools/lasso_selected.jpg" ; unloadWindow = false ; var selectedMapTool = "maptoolgrab" ; var mouseIsInInfoWindow = "no" ; var selectionStartHorizontal = 0 ; var selectionStartVertical = 0 ; var selectionVerticalOffset = 0 var selectionHorizontalOffset = 0 ; var selectionStatus = "ready" ; var selectedArea = "" ; var boxHTML = "
[boxcontent]
" ; var searchHTML = "" + "" + "
" + "\"\"" + "[searchlink][sourcename]
" ; var closeBoxHTML = "\"\"" ; var searchLinkText = "Search in this area" ; var searchLinkText2 = "Search in [area]" ; var searchLink = "" ; function mouseoverMapTool(thisID) { if (selectedMapTool != thisID) { document.getElementById(thisID).src = "images/maptools/" + thisID.substr(7) + "_hover.png" ; } } function mouseoutMapTool(thisID) { if (selectedMapTool != thisID) { document.getElementById(thisID).src = "images/maptools/" + thisID.substr(7) + ".png" ; } } function selectMapTool(thisID) { if (selectedMapTool != thisID) { var thisImage = "images/maptools/" + selectedMapTool.substr(7) + ".png" ; ; document.getElementById(selectedMapTool).src = thisImage ; thisImage = "images/maptools/" + thisID.substr(7) + "_selected.png" ; document.getElementById(thisID).src = thisImage ; selectedMapTool = thisID ; if (thisID == "maptoolgrab") { map.enableDragging() ; map.enableDoubleClickZoom() ; } else { map.disableDragging() ; map.disableDoubleClickZoom() ; } if (selectedMapTool == "maptoollasso" && thisID != "maptoollasso") { var numberOfPoints = points.length ; if (numberOfPoints > 1) { var startPoint = map.fromContainerPixelToLatLng(points[0]) ; var endPoint = map.fromContainerPixelToLatLng(points[numberOfPoints-1]) ; if (startPoint.toString() != endPoint.toString() ) { clearAll(false) ; } } } makeMouseDownPoint() ; document.getElementById("rectanglebox").style.visibility = "hidden" ; selectionStatus = "" ; } } function clearAll(clearCachedSelection) { hideInfoWindow() ; map.clearOverlays(); makeMouseDownPoint() ; if (points) { points.length = 0; } if (clearCachedSelection == true) { document.getElementById("storemapselectionresults").innerHTML = "" ; ajaxGetData('/inc/res.storemapseleection.php','storemapselectionresults'); } } var mousedownmarker; function makeMouseDownPoint() { if (selectedMapTool != "maptoolrectangle") { return true ; } mousedownmarker = new GMarker(new GLatLng(0,0), icon2) ; map.addOverlay(mousedownmarker) ; GEvent.addListener(mousedownmarker, "mousedown", function() { startRectangleSelection() ; }) ; GEvent.addListener(mousedownmarker, "mouseup", function() { endRectangleSelection() ; }) ; } function startRectangleSelection() { if (selectedMapTool != "maptoolrectangle" || selectionStatus == "selecting") { return true ; } if (selectionVerticalOffset == "" || selectionHorizontalOffset == "" ) { return true ; } if (selectionHorizontalOffset < mapLeft || selectionHorizontalOffset > mapRight || selectionVerticalOffset < mapTop || selectionVerticalOffset > mapBottom) { return true ; } if (map.getZoom() <= 1) { alert("Sorry, the rectangle selection tool is not available at this zoom level.") ; return true ; } clearAll(false) ; selectionStartHorizontal = selectionHorizontalOffset ; selectionStartVertical = selectionVerticalOffset ; selectionStatus = "selecting" ; } function updateRectangleSelection(coordinatesInDegrees) { if (selectedMapTool != "maptoolrectangle") { return true ; } var verticalOffset = selectionVerticalOffset ; var horizontalOffset = selectionHorizontalOffset ; mousedownmarker.setPoint(coordinatesInDegrees) ; if (selectionStatus != "selecting") { return true ; } var startVerticalOffset = selectionStartVertical ; var startHorizontalOffset = selectionStartHorizontal ; if (horizontalOffset < mapLeft) { horizontalOffset = mapLeft; } else if (horizontalOffset > mapRight) { horizontalOffset = mapRight ; } if (verticalOffset < mapTop) { verticalOffset = mapTop ; } else if (verticalOffset > mapBottom) { verticalOffset = mapBottom ; } if (verticalOffset > startVerticalOffset) { var selectionTop = startVerticalOffset ; var selectionBottom = verticalOffset ; if (browserType == "Safari") { selectionBottom = selectionBottom - 2 ; } } else { selectionTop = verticalOffset ; selectionBottom = startVerticalOffset ; } if (horizontalOffset > startHorizontalOffset) { var selectionLeft = startHorizontalOffset ; var selectionRight = horizontalOffset ; if (browserType == "Safari") { selectionRight = selectionRight - 2 ; } } else { var selectionLeft = horizontalOffset ; var selectionRight = startHorizontalOffset ; } var selectionBoxWidth = parseInt(selectionRight) - parseInt(selectionLeft) + 1 ; var selectionBoxHeight = parseInt(selectionBottom) - parseInt(selectionTop) + 1 ; var selectionBoxTop = parseInt(selectionTop) ; var selectionBoxLeft = parseInt(selectionLeft) ; if (browserType == "Mozilla") { selectionBoxTop = selectionBoxTop + 1 ; selectionBoxLeft = selectionBoxLeft + 1 ; selectionBoxWidth = selectionBoxWidth - 2 ; selectionBoxHeight = selectionBoxHeight - 2 ; } if (selectionBoxWidth < 0) { selectionBoxWidth = 0 ; } if (selectionBoxHeight < 0) { selectionBoxHeight = 0 ; } document.getElementById('rectanglebox').style.top = selectionBoxTop + "px" ; document.getElementById('rectanglebox').style.left = selectionBoxLeft + "px" ; document.getElementById('rectanglebox').style.width = selectionBoxWidth + "px" ; document.getElementById('rectanglebox').style.height = selectionBoxHeight + "px" ; document.getElementById('rectanglebox').style.visibility = "visible" ; } function endRectangleSelection() { if (selectedMapTool != "maptoolrectangle" || selectionStatus != "selecting") { return true ; } var startVertical = selectionStartVertical ; var startHorizontal = selectionStartHorizontal ; var endVertical = selectionVerticalOffset ; var endHorizontal = selectionHorizontalOffset ; if (browserType == "Mozilla" ) { startVertical += 1 ; startHorizontal += 1 ; endVertical += 1 ; endHorizontal += 1 ; } if (startHorizontal < mapLeft) { startHorizontal = mapLeft; } else if (startHorizontal > mapRight) { startHorizontal = mapRight ; } if (startVertical < mapTop) { startVertical = mapTop ; } else if (startVertical > mapBottom) { startVertical = mapBottom ; } if (endHorizontal < mapLeft) { endHorizontal = mapLeft; } else if (endHorizontal > mapRight) { endHorizontal = mapRight ; } if (endVertical < mapTop) { endVertical = mapTop ; } else if (endVertical > mapBottom) { endVertical = mapBottom ; } if (Math.abs(startHorizontal - endHorizontal) < 10 && Math.abs(startVertical - endVertical) < 10) { return true ; } if ( startHorizontal != endVertical || startHorizontal != endHorizontal ) { selectionStatus = "ready" ; } var points = new Array(); for (var i = 0 ; i < 5; i ++) { if (i == 0 || i == 4) { var thisHOffset = startHorizontal ; var thisVOffset = startVertical ; } else if (i == 1) { var thisHOffset = endHorizontal ; var thisVOffset = startVertical ; } else if (i == 2) { var thisHOffset = endHorizontal ; var thisVOffset = endVertical ; } else if (i == 3) { var thisHOffset = startHorizontal ; var thisVOffset = endVertical ; } var mapMouseHOffset = thisHOffset - mapLeft ; var mapMouseVOffset = thisVOffset - mapTop ; coordinatesInDegrees = map.fromContainerPixelToLatLng(new GPoint(mapMouseHOffset,mapMouseVOffset)) ; points.push(coordinatesInDegrees) ; } var thisPolygonGoogleMaps = "" ; var thisPolygonSQL = "" ; for (var i = 0 ; i < points.length; i ++) { if (i > 0) { thisPolygonGoogleMaps += "," ; thisPolygonSQL += "," ; } var thisLongitude = points[i].lng() ; var thisLatitude = points[i].lat() ; thisPolygonGoogleMaps += thisLatitude + " " + thisLongitude ; thisPolygonSQL += thisLongitude + " " + thisLatitude ; } showRectangleOrLassoSelection(thisPolygonGoogleMaps,thisPolygonSQL,"rectangle","no") ; document.getElementById("storemapselectionresults").innerHTML = "" ; ajaxGetData('/inc/res.storemapseleection.php?points=&rectangle='+escape(thisPolygonSQL)+'&areaid=','storemapselectionresults'); } function showRectangleOrLassoSelection(thisPolygonGoogleMaps,thisPolygonSQL,pointsOrRectangle,newMap) { var coordinatePairs = thisPolygonGoogleMaps.split(",") ; var points = new Array() ; for (var i = 0 ; i < coordinatePairs.length; i ++) { theseCoordinates = coordinatePairs[i].split(" ") ; theseCoordinates = new GLatLng(theseCoordinates[0],theseCoordinates[1]) ; points.push(theseCoordinates) ; } map.addOverlay(new GPolyline(points, "#FFFF00", 2, 1)); document.getElementById("rectanglebox").style.visibility = "hidden" ; searchLink = "search_results.php?newSearch=1&" + pointsOrRectangle + "=" + escape(thisPolygonSQL) ; for (var i = 0 ; i < coordinatePairs.length; i ++) { var theseCoordinates = coordinatePairs[i].split(" ") ; var thisLatitude = parseFloat(theseCoordinates[0]) ; var thisLongitude = parseFloat(theseCoordinates[1]) ; if (i == 0) { var minimumLatitude = thisLatitude ; var maximumLatitude = thisLatitude ; var minimumLongitude = thisLongitude ; var maximumLongitude = thisLongitude ; continue ; } if (thisLatitude > maximumLatitude) { maximumLatitude = thisLatitude ; } else if (thisLatitude < minimumLatitude) { minimumLatitude = thisLatitude ; } if (thisLongitude > maximumLongitude) { maximumLongitude = thisLongitude ; } else if (thisLongitude < minimumLongitude) { minimumLongitude = thisLongitude ; } } var centerLatitude = ((minimumLatitude + maximumLatitude) / 2); var centerLongitude = ((minimumLongitude + maximumLongitude) / 2); if (newMap == "yes") { var bounds = new GLatLngBounds(); var corner1 = new GLatLng(minimumLatitude,minimumLongitude); bounds.extend(corner1); var corner2 = new GLatLng(maximumLatitude,maximumLongitude); bounds.extend(corner2); var zoomLevel = map.getBoundsZoomLevel(bounds) - 2 ; if (zoomLevel <= 1) { zoomLevel = 2 ; } map.setZoom(zoomLevel); var point = new GLatLng(centerLatitude,centerLongitude) ; map.setCenter(point); } var infoWindowLatitude = centerLatitude + (Math.abs(maximumLatitude-centerLatitude)*0.3) ; var infoWindowLongitude = centerLongitude + (Math.abs(maximumLongitude-centerLongitude)*0.3) ; var thisPoint = new GLatLng(infoWindowLatitude,infoWindowLongitude) ; var thisHTML = searchHTML.replace("[searchlink]",searchLinkText) ; thisHTML = thisHTML.replace("[sourcename]","") ; thisHTML = boxHTML.replace("[boxcontent]",thisHTML) ; thisHTML = thisHTML.replace("[closebox]",closeBoxHTML) ; showInfoWindow(thisPoint,thisHTML) ; } var ewindow ; function showInfoWindow(point,html) { hideInfoWindow(); ewindow = new EWindow(map, E_STYLE_2); map.addOverlay(ewindow); ewindow.openOnMap(point, html) ; map.panBy(new GSize(-20,55)) ; } function hideInfoWindow() { if (ewindow) { ewindow.hide() ; } mouseIsInInfoWindow = "no" ; } function selectMapArea(itemID) { if (!itemID || itemID == "") { return true ; } data = ajaxGetDataSynch('/inc/res.geoareas.php?areaid=' + itemID,'maparearesults'); document.getElementById("maparearesults").innerHTML = data; showMapArea(data); } function showMapArea(data) { var jsonData = eval ('(' + data + ')') ; if (!jsonData.minimumLatitude || jsonData.minimumLatitude == "") { return true ; } var centerLatitude = ((jsonData.minimumLatitude + jsonData.maximumLatitude) / 2); var centerLongitude = ((jsonData.minimumLongitude + jsonData.maximumLongitude) / 2); var infoWindowLatitude = centerLatitude + (Math.abs(jsonData.maximumLatitude-centerLatitude)*0.3) ; var infoWindowLongitude = centerLongitude + (Math.abs(jsonData.maximumLongitude-centerLongitude)*0.3) ; var infoWindowPoint = new GLatLng(infoWindowLatitude,infoWindowLongitude); var areaName = jsonData.name ; if (jsonData.source) { var sourceName = " ("+ jsonData.source + ")" ; } else { var sourceName = "" ; } document.getElementById("storemapselectionresults").innerHTML = "" ; ajaxGetData('/inc/res.storemapseleection.phpareaid=' + jsonData.id + '&points=&rectangle=','storemapselectionresults'); // Some browsers crash if number of points in polygon exceeds �400 // Maximise number of points to be draw in polygon on Google Maps var maxNumberOfPointsInPolygon = 400; var oldArea = selectedArea ; selectedArea = data ; clearAll(false) ; var nameHTML = "[name]" ; if (oldArea == "" ) { if (map.getZoom() > 7) { map.setZoom(7); } var point = new GLatLng(centerLatitude,centerLongitude); map.panTo(point); var marker = new GMarker(point, icon); map.addOverlay(marker); var thisHTML = nameHTML.replace("[name]",areaName) ; thisHTML = boxHTML.replace("[boxcontent]",thisHTML) ; thisHTML = thisHTML.replace("[closebox]","") ; showInfoWindow(infoWindowPoint, thisHTML) ; map.panTo(point); window.setTimeout(function() { map.removeOverlay(marker); var bounds = new GLatLngBounds(); var corner1 = new GLatLng(jsonData.minimumLatitude,jsonData.minimumLongitude); bounds.extend(corner1); var corner2 = new GLatLng(jsonData.maximumLatitude,jsonData.maximumLongitude); bounds.extend(corner2); hideInfoWindow(); map.setZoom(map.getBoundsZoomLevel(bounds) - 1); map.setCenter(point); for (var i = 0; i < jsonData.lines.length; i++) { var pts = []; var numberOfPointsInPolygon = jsonData.lines[i].points.length; var counterStep = Math.ceil(numberOfPointsInPolygon/maxNumberOfPointsInPolygon); var k = 0; for (j = 0; j < numberOfPointsInPolygon; j += counterStep) { if (j <= numberOfPointsInPolygon) { pts[k] = new GLatLng(jsonData.lines[i].points[j].lat, jsonData.lines[i].points[j].lng); k++; } } if (counterStep > 1 && j < numberOfPointsInPolygon) { pts[k++] = new GLatLng(jsonData.lines[i].points[1].lat, jsonData.lines[i].points[1].lng); } map.addOverlay(new GPolyline(pts, "#FFFF00", 2, 1)); } searchLink = "search_results.php?newSearch=1&areaid=" + jsonData.id ; var thisHTML = searchHTML.replace("[searchlink]",searchLinkText2.replace("[area]",areaName)) ; thisHTML = thisHTML.replace("[sourcename]",sourceName) ; thisHTML = boxHTML.replace("[boxcontent]",thisHTML) ; thisHTML = thisHTML.replace("[closebox]",closeBoxHTML) ; showInfoWindow(infoWindowPoint, thisHTML) ; resetMapAreaMenus() ; }, 1500); } else { var oldJsonData = eval ('(' + oldArea + ')') ; var oldCenterLatitude = ((oldJsonData.minimumLatitude + oldJsonData.maximumLatitude) / 2); var oldCenterLongitude = ((oldJsonData.minimumLongitude + oldJsonData.maximumLongitude) / 2); var oldName = oldJsonData.name ; var oldPoint = new GLatLng(oldCenterLatitude,oldCenterLongitude); var oldMarker = new GMarker(oldPoint, icon); map.addOverlay(oldMarker); var thisHTML = nameHTML.replace("[name]",oldName) ; thisHTML = boxHTML.replace("[boxcontent]",thisHTML) ; thisHTML = thisHTML.replace("[closebox]","") ; showInfoWindow(oldPoint, thisHTML) ; if (map.getZoom() > 7) { map.setZoom(7); } var point = new GLatLng(centerLatitude,centerLongitude); var newMarker = new GMarker(point, icon); window.setTimeout(function() { map.addOverlay(newMarker); var thisHTML = nameHTML.replace("[name]",areaName) ; thisHTML = boxHTML.replace("[boxcontent]",thisHTML) ; thisHTML = thisHTML.replace("[closebox]","") ; showInfoWindow(point, thisHTML) ; map.panTo(point); }, 800); window.setTimeout(function() { map.removeOverlay(oldMarker); map.removeOverlay(newMarker); var bounds = new GLatLngBounds(); var corner1 = new GLatLng(jsonData.minimumLatitude,jsonData.minimumLongitude); bounds.extend(corner1); var corner2 = new GLatLng(jsonData.maximumLatitude,jsonData.maximumLongitude); bounds.extend(corner2); hideInfoWindow(); map.setZoom(map.getBoundsZoomLevel(bounds) - 1); map.setCenter(point); for (var i = 0; i < jsonData.lines.length; i++) { var pts = []; var numberOfPointsInPolygon = jsonData.lines[i].points.length; var counterStep = Math.ceil(numberOfPointsInPolygon/maxNumberOfPointsInPolygon); var k = 0; for (j = 0; j < numberOfPointsInPolygon; j += counterStep) { if (j <= numberOfPointsInPolygon) { pts[k] = new GLatLng(jsonData.lines[i].points[j].lat, jsonData.lines[i].points[j].lng); k++; } } if (counterStep > 1 && j < numberOfPointsInPolygon) { pts[k++] = new GLatLng(jsonData.lines[i].points[1].lat, jsonData.lines[i].points[1].lng); } map.addOverlay(new GPolyline(pts, "#FFFF00", 2, 1)); } searchLink = "search_results.php?newSearch=1&areaid=" + jsonData.id ; var thisHTML = searchHTML.replace("[searchlink]",searchLinkText2.replace("[area]",areaName)) ; thisHTML = thisHTML.replace("[sourcename]",sourceName) ; thisHTML = boxHTML.replace("[boxcontent]",thisHTML) ; thisHTML = thisHTML.replace("[closebox]",closeBoxHTML) ; showInfoWindow(infoWindowPoint, thisHTML) ; resetMapAreaMenus() ; }, 2500); } } function showStoredMapArea(data) { var maxNumberOfPointsInPolygon = 400; var data = unescape(data) ; var jsonData = eval ('(' + data + ')') ; if (!jsonData.minimumLatitude || jsonData.minimumLatitude == "") { return true ; } var centerLatitude = ((jsonData.minimumLatitude + jsonData.maximumLatitude) / 2); var centerLongitude = ((jsonData.minimumLongitude + jsonData.maximumLongitude) / 2); var infoWindowLatitude = centerLatitude + (Math.abs(jsonData.maximumLatitude-centerLatitude)*0.3) ; var infoWindowLongitude = centerLongitude + (Math.abs(jsonData.maximumLongitude-centerLongitude)*0.3) ; var infoWindowPoint = new GLatLng(infoWindowLatitude,infoWindowLongitude); var name = jsonData.name ; if (jsonData.source) { var sourceName = " ("+ jsonData.source + ")" ; } else { var sourceName = "" ; } selectedArea = data ; var nameHTML = "

[name]

" ; var point = new GLatLng(centerLatitude,centerLongitude); var bounds = new GLatLngBounds(); var corner1 = new GLatLng(jsonData.minimumLatitude,jsonData.minimumLongitude); bounds.extend(corner1); var corner2 = new GLatLng(jsonData.maximumLatitude,jsonData.maximumLongitude); bounds.extend(corner2); var zoomLevel = map.getBoundsZoomLevel(bounds) - 1 ; if (zoomLevel <= 1) { zoomLevel = 2 ; } map.setZoom(zoomLevel); map.setCenter(point); for (var i = 0; i < jsonData.lines.length; i++) { var pts = []; var numberOfPointsInPolygon = jsonData.lines[i].points.length; var counterStep = Math.ceil(numberOfPointsInPolygon/maxNumberOfPointsInPolygon); var k = 0; for (j = 0; j < numberOfPointsInPolygon; j += counterStep) { if (j <= numberOfPointsInPolygon) { pts[k] = new GLatLng(jsonData.lines[i].points[j].lat, jsonData.lines[i].points[j].lng); k++; } } if (counterStep > 1 && j < numberOfPointsInPolygon) { pts[k++] = new GLatLng(jsonData.lines[i].points[1].lat, jsonData.lines[i].points[1].lng); } map.addOverlay(new GPolyline(pts, "#FFFF00", 2, 1)); } searchLink = "search_results.php?newSearch=1&areaid=" + jsonData.id ; var thisHTML = searchHTML.replace("[searchlink]",searchLinkText2.replace("[area]",name)) ; thisHTML = thisHTML.replace("[sourcename]",sourceName) ; thisHTML = boxHTML.replace("[boxcontent]",thisHTML) ; thisHTML = thisHTML.replace("[closebox]",closeBoxHTML) ; showInfoWindow(infoWindowPoint, thisHTML) ; } function resetMapAreaMenus() { var counter = 0 ; while (document.getElementById("selectmaparea" + counter)) { var thisMenu = document.getElementById("selectmaparea" + counter) ; counter ++ ; thisMenu.options[0].selected = "selected" ; for (var i = 1 ; i < thisMenu.options.length; i++) { thisMenu.options[i].selected = "" ; } } } function showOrHideAdvancedSearchOption(thisOption) { var thisLayer = document.getElementById("map" + thisOption + "selection") ; var thisImage = document.getElementById("map" + thisOption + "selectionarrow") ; if (thisLayer.style.visibility == "hidden") { thisImage.src = "images/advanced_search_arrow_down.gif" ; thisLayer.style.height = "" ; thisLayer.style.visibility = "visible" ; } else { thisImage.src = "images/advanced_search_arrow_right.gif" ; thisLayer.style.height = "1px" ; thisLayer.style.visibility = "hidden" ; } } function startMapSearch() { var advancedSearchOptions = getAdvancedSearchOptions() ; if (advancedSearchOptions != "error") { document.location.href = searchLink + advancedSearchOptions ; } } function getAdvancedSearchOptions() { var thisLayer = document.getElementById("mapdateselection") ; if (!thisLayer) { return "" ; } else if (thisLayer.style.display == "block") { return "" ; } var startDate = "" ; var endDate = "" ; var thisCategory = "" ; var thisSource = "" ; if (document.getElementById("mapdateselection").style.visibility == "visible") { var fromOrTo = new Array("from","to") ; var theseMenus = new Array("day","month","year") ; var theseDateValues = new Array() ; var theseDateNames = new Array() ; var listOfMonths = new Array() ; for (var thisFromToCounter = 0 ; thisFromToCounter < fromOrTo.length; thisFromToCounter ++ ) { var thisFromOrTo = fromOrTo[thisFromToCounter] ; theseDateValues[thisFromOrTo] = new Array() ; theseDateNames[thisFromOrTo] = new Array() ; for (var thisMenuCounter = 0 ; thisMenuCounter < theseMenus.length; thisMenuCounter ++ ) { var thisMenuName = theseMenus[thisMenuCounter] ; var thisMenu = document.getElementById("select" + thisMenuName + thisFromOrTo) ; theseDateValues[thisFromOrTo][thisMenuName] = "" ; theseDateNames[thisFromOrTo][thisMenuName] = "" ; for (var thisMenuItem = 0 ; thisMenuItem < thisMenu.options.length; thisMenuItem++) { if (thisFromToCounter == 0 && thisMenuName == "month") { var thisMonthNumber = thisMenu.options[thisMenuItem].value ; var thisMonthName = thisMenu.options[thisMenuItem].innerHTML ; if (thisMonthNumber != "") { listOfMonths[thisMonthNumber] = thisMonthName ; } } if (thisMenu.options[thisMenuItem].selected == true) { theseDateValues[thisFromOrTo][thisMenuName] = thisMenu.options[thisMenuItem].value ; theseDateNames[thisFromOrTo][thisMenuName] = thisMenu.options[thisMenuItem].innerHTML ; break ; } } } } for (var thisFromToCounter = 0 ; thisFromToCounter < fromOrTo.length; thisFromToCounter ++ ) { var thisFromOrTo = fromOrTo[thisFromToCounter] ; var thisDay = theseDateValues[thisFromOrTo]["day"] ; var thisMonth = theseDateValues[thisFromOrTo]["month"] ; var thisYear = theseDateValues[thisFromOrTo]["year"] ; if (thisDay + thisMonth + thisYear == "") { continue ; } var thisMonthName = theseDateNames[thisFromOrTo]["month"] + " " + theseDateNames[thisFromOrTo]["year"] ; if (thisDay != "" && thisMonth == "") { if (thisFromOrTo == "from") { alert ("Invalid start date. Please select a month and year.") ; } else { alert ("Invalid end date. Please select a month and year.") ; } return "error" ; } else if (thisYear == "") { if (thisFromOrTo == "from") { alert ("Invalid start date. Please select a year.") ; } else { alert ("Invalid end date. Please select a year.") ; } return "error" ; } if (thisMonth == "") { if (thisFromOrTo == "from") { thisMonth = 1 ; } else { thisMonth = 12 ; } theseDateValues[thisFromOrTo]["month"] = thisMonth ; theseDateNames[thisFromOrTo]["month"] = listOfMonths[thisMonth] ; } else { var lastDayOfMonth = getLastDayOfMonth(thisMonth,thisYear) ; if (parseInt(thisDay) > lastDayOfMonth) { if (thisFromOrTo == "from") { thisWarning = "Invalid start date. [month] had no more than [days] days." ; } else { thisWarning = "Invalid end date. [month] had no more than [days] days." ; } var thisWarning = thisWarning.replace("[month]",thisMonthName) ; thisWarning = thisWarning.replace("[days]",lastDayOfMonth) ; alert (thisWarning) ; return "error" ; } } if (thisDay == "") { if (thisFromOrTo == "from") { thisDay = 1 ; } else { thisDay = getLastDayOfMonth(thisMonth,thisYear) ; } theseDateValues[thisFromOrTo]["day"] = thisDay ; } } var startDay = theseDateValues["from"]["day"] ; var startMonth = theseDateValues["from"]["month"] ; var startYear = theseDateValues["from"]["year"] ; var endDay = theseDateValues["to"]["day"] ; var endMonth = theseDateValues["to"]["month"] ; var endYear = theseDateValues["to"]["year"] ; var startDateIsLaterOrEqualToEndDate = true ; if (startDay + startMonth + startYear != "" && endDay + endMonth + endYear != "") { if (startYear > endYear) { startDateIsLaterOrEqualToEndDate = false ; } else if (startYear == endYear) { if (startMonth > endMonth) { startDateIsLaterOrEqualToEndDate = false ; } else if (startMonth == endMonth) { if (startDay > endDay) { startDateIsLaterOrEqualToEndDate = false ; } } } } if (startDateIsLaterOrEqualToEndDate == false) { var thisWarning = "Invalid date range. The start date ([startdate]) must be earlier than the end date ([enddate])." ; thisWarning = thisWarning.replace("[startdate]", startDay + " " + theseDateNames["from"]["month"] + " " + startYear) ; thisWarning = thisWarning.replace("[enddate]", endDay + " " + theseDateNames["to"]["month"] + " " + endYear) ; alert (thisWarning) ; return "error" ; } if (startDay + startMonth + startYear != "") { if (startDay < 10) { startDay = "0" + startDay ; } if (startMonth < 10) { startMonth = "0" + startMonth ; } startDate = startYear + "-" + startMonth + "-" + startDay ; } if (endDay + endMonth + endYear != "") { if (endDay < 10) { endDay = "0" + endDay ; } if (endMonth < 10) { endMonth = "0" + endMonth ; } endDate = endYear + "-" + endMonth + "-" + endDay ; } } if (document.getElementById("mapcategoryselection").style.visibility == "visible") { var thisMenu = document.getElementById("selectcategory") ; for (var thisMenuItem = 0 ; thisMenuItem < thisMenu.options.length; thisMenuItem++) { if (thisMenu.options[thisMenuItem].selected == true) { thisCategory = thisMenu.options[thisMenuItem].value ; break ; } } } if (document.getElementById("mapsourceselection").style.visibility == "visible") { var thisMenu = document.getElementById("selectsource") ; for (var thisMenuItem = 0 ; thisMenuItem < thisMenu.options.length; thisMenuItem++) { if (thisMenu.options[thisMenuItem].selected == true) { thisSource = thisMenu.options[thisMenuItem].value ; break ; } } } var advancedSearchParameters = "" ; if (startDate != "") { advancedSearchParameters += "&start_date=" + startDate ; } if (endDate != "") { advancedSearchParameters += "&end_date=" + endDate ; } advancedSearchParameters += "&map_category=" + thisCategory ; advancedSearchParameters += "&source=" + thisSource ; return advancedSearchParameters ; } function getLastDayOfMonth(thisMonth,thisYear) { if (thisMonth == 1 || thisMonth == 3 || thisMonth == 5 || thisMonth == 7 || thisMonth == 8 || thisMonth == 10 || thisMonth == 12) { return 31 ; } else if (thisMonth == 2) { if (thisMonth/4 == Math.floor(thisMonth/4)) { return 29 ; } else { return 28 ; } } else { return 30 ; } }