Index: main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 32833)
+++ main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 33125)
@@ -24,4 +24,6 @@
 	if(jsonNodeDiv.length)
 	{
+		console.log("@@@ JSON node div html: " + jsonNodeDiv.html());
+		
 		var jsonNodes = eval(jsonNodeDiv.html());
 		if(jsonNodes && jsonNodes.length > 0)
@@ -31,4 +33,5 @@
 				_docList[jsonNodes[i].nodeID] = jsonNodes[i];
 				_docList.ids.push(jsonNodes[i].nodeID);
+				console.log("@@@ JSON node: " + jsonNodes[i]);
 				createMarker(jsonNodes[i], true);
 			}
@@ -39,4 +42,5 @@
 			//$("#map_canvas").css({visibility:"hidden", height:"0px"});
 			$("#map_canvas").css({visibility:"hidden"});
+			//console.log("suppressing hiding the map");
 		}
 	}
@@ -82,5 +86,5 @@
 function setUpMap()
 {
-
+	//alert("@@@@in map-scripts::setUpMap()");
 	
 	var myOptions = 
@@ -93,4 +97,5 @@
 	
 	if ($map_canvas.length > 0) {
+		console.log("### map-scripts::setUpMap: map_canvas.exists");
 		_map = new google.maps.Map($map_canvas[0], myOptions);
 		google.maps.event.addListener(_map, 'bounds_changed', performSearchForMarkers);
@@ -104,4 +109,6 @@
 		return;
 	}
+	
+	
 	
 	_searchRunning = true;
@@ -145,4 +152,5 @@
     if(lngDelta == 0.1){lngDelta = 1; lngPrecision = 0; }
 	
+	/*
 	var query = "";
 	for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++)
@@ -183,4 +191,53 @@
 		}
 	}
+	*/
+	var query = "";
+	var iMax = Math.floor(latDistance / latDelta) + 1;
+	var jMax = Math.floor(lngDistance / lngDelta) + 1;;
+	for(var i = 0; i <= iMax; i++) //for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++)
+	{
+		for(var j = 0; j <= jMax; j++) //for(var j = 0; j <= Math.floor(lngDistance / lngDelta) + 1; j++)
+		{
+			//Some necessary variables
+			var newLat = neLat - (latDelta * i);
+			var newLatString = "" + newLat;
+			var newLatTrunc;
+			if(newLat < 0){newLatTrunc = Math.ceil(newLat);}
+			else{newLatTrunc = Math.floor(newLat);}
+			
+			var newLng = neLng - (lngDelta * j);
+			var newLngString = "" + newLng;
+			var newLngTrunc;
+			if(newLng < 0){newLngTrunc = Math.ceil(newLng);}
+			else{newLngTrunc = Math.floor(newLng);}
+
+			//Construct query
+			query += "(";
+			query += "CS:\"" + coordToAbsDirected(newLatTrunc, "lat");
+			//query += "CS:\"" + coordToAbsDirected(newLatTrunc, "lat") + "\" \"" + coordToAbsDirected(newLngTrunc, "lng") + "\""; //query += "LA:" + coordToAbsDirected(newLatTrunc, "lat");
+			if(latDelta != 1)
+			{ 
+				query += newLatString.substring(newLatString.indexOf(".") + 1, newLatString.indexOf(".") + latPrecision + 1);
+			}
+			query += " ";
+			//query += "+AND+";
+			
+			//query += "LN:" + coordToAbsDirected(newLngTrunc, "lng");
+			query += coordToAbsDirected(newLngTrunc, "lng");
+			if(lngDelta != 1)
+			{ 
+				query += newLngString.substring(newLngString.indexOf(".") + 1, newLngString.indexOf(".") + lngPrecision + 1);
+			}
+			query += "\"";			
+			query += ")";
+
+			//if(i != (Math.floor(latDistance / latDelta) + 1) || j != (Math.floor(lngDistance / lngDelta) + 1)){ query += "+OR+"; }
+			if(i != iMax || j != jMax){ query += "+OR+"; }
+		}
+	}
+	
+	// This works, why not from the double loop above?
+	//query = "(CS:\"" + coordToAbsDirected(newLatTrunc, "lat") + " " + coordToAbsDirected(newLngTrunc, "lng") + "\")";	
+	//alert("@@@@in map-scripts::performSearchForMarkers() - query: " + query);
 	
 	//var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes";
@@ -196,4 +253,6 @@
 			var startIndex = responseText.indexOf(">");
 			var endIndex = responseText.indexOf("</");
+
+			console.log("@@@@ performSearch, got response: " + responseText);
 
 			var jsonNodes = eval(responseText.substring(startIndex+1, endIndex));
@@ -278,5 +337,11 @@
 		}
 
+		if(!doc.lat) {
+			var coordInfo = getLatLngForCoord(doc.coord);
+			bounds.extend(new google.maps.LatLng(coordInfo.lat, coordInfo.lng));
+		}
+		else {
  	        bounds.extend(new google.maps.LatLng(doc.lat, doc.lng));
+		}
 	}
 	
@@ -291,4 +356,25 @@
 }
 
+function getLatLngForCoord(coord) {
+	
+	// https://stackoverflow.com/questions/2559318/how-to-check-for-an-undefined-or-null-variable-in-javascript
+	if(!coord) {
+		 // some_variable is either null, undefined, 0, NaN, false, or an empty string
+		console.log("@@@@ In map-scripts::getLatLngForCoord(): no or invalid coord info");
+		return null;
+	}
+	
+	// coord is of the form: "37S77 157E53"
+	// lat will be 37S77, lng 157E53.
+	var indexOfSpace = coord.indexOf(" ");
+	if(indexOfSpace === -1) {
+		console.log("@@@@ In map-scripts::getLatLngForCoord(): bad format for coord  " + coord);
+		return null;
+	}
+	var latitude = coord.substring(0, indexOfSpace);
+	var longitude = coord.substring(indexOfSpace+1);
+	return {lat: latitude, lng: longitude}; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects
+}
+
 function loopThroughMarkers()
 {
@@ -363,4 +449,5 @@
 			gs.functions.setArchivesMetadata(collection, site_name, nodeID, "Latitude", null, lat, null, "override", function(){callbackFunction();});
 			gs.functions.setArchivesMetadata(collection, site_name, nodeID, "Longitude", null, lng, null, "override", function(){callbackFunction();});
+			gs.functions.setArchivesMetadata(collection, site_name, nodeID, "Coordinate", null, lat + " " + lng, null, "override", function(){callbackFunction();});
 			console.log("NodeID: " + nodeID);
 			console.log("GPS Click handler in collection:" + collection + " in site: " + site_name + " for Doc: " + nodeID + "(" + lat + "," + lng + ")");
@@ -376,5 +463,10 @@
 		clearInterval(_intervalHandle);
 		_intervalHandle = null;
-		_map.panTo(new google.maps.LatLng(doc.lat, doc.lng));
+		if(!doc.lat) {
+			var coordInfo = getLatLngForCoord(doc.coord);
+			_map.panTo(new google.maps.LatLng(coordInfo.lat, coordInfo.lng));
+		} else {
+			_map.panTo(new google.maps.LatLng(doc.lat, doc.lng));
+		}
 		clearAllInfoBoxes();
 		doc.marker.markerInfo.open(_map, doc.marker);
@@ -398,5 +490,12 @@
 function createMarker(doc, mainMarker)
 {
-	var pos = new google.maps.LatLng(doc.lat,doc.lng);
+	var pos;
+	if(doc.lat) {
+		pos = new google.maps.LatLng(doc.lat,doc.lng);
+	} else {
+		var coordInfo = getLatLngForCoord(doc.coord);			
+		pos = new google.maps.LatLng(coordInfo.lat,coordInfo.lng);
+	}
+	
 	
 	var docEdit = (("docEdit" in gs.cgiParams) && (gs.cgiParams['docEdit']));
@@ -525,4 +624,13 @@
 }
 
+function performDistanceSearchWithCoordinates(id, coord, degrees)
+{
+	var coordInfo = getLatLngForCoord(doc.coord);
+	if(!coordInfo) {
+		console.log("@@@ ERROR in map-scripts::performDistanceSearchWithCoordinates: coordInfo is null");		
+	}
+	performDistanceSearch(id, coordInfo.lat, coordInfo.lng, degrees);
+}
+
 function performDistanceSearch(id, lat, lng, degrees)
 {
