Index: main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts.js	(revision 32825)
+++ main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts.js	(revision 32832)
@@ -36,5 +36,4 @@
 var multiValuedMetadata = new Array(); // eg ["xx.Person", "xx.Location"];
 var mvm_delimiter = ";";
-var mapsIdsArray = []; //An array for the IDs of all the maps created
 
 /************************
@@ -163,36 +162,17 @@
 		});
 	newLink.click(function () {
-		console.log("Show/Hide Map Editor");
-
-		// Only if this 'id' element hasn't been initialied, then do the following 2 lines
-		if (mapEditor.map !== null) {
-			console.log(mapEditor.map.mapId);
-			console.log(mapsIdsArray.includes(id));
-		}
-
+		//console.log(" Show/Hide Map Editor ");
 		var clicked_mapEditor = gsmap_store["map-" + id];
 		
 		if (clicked_mapEditor.map == null) {
-			console.log("Initializing map for id: " + id);
-
 			clicked_mapEditor.initMapEditorControls();
 			clicked_mapEditor.initMapEditor();
-			//mapsIdsArray.push(clicked_mapEditor.map.mapId);
-		} /*
-		else if (mapsIdsArray.includes(id) == false) {
-			//mapEditor.initMapEditorControls();
-			//mapEditor.initMapEditor();
-			mapsIdsArray.push(mapEditor.map.mapId)
-		}
-*/
+		}
 		if (mapGPScontainer.css("display") == "none") {
-
 			linkLabel.html(gs.text.de.hide_map_gps);
 			linkIcon.attr("class", "ui-icon ui-icon-folder-open");
 			mapGPScontainer.css("display", "block");
-
 		} else {
 			linkLabel.html(gs.text.de.edit_map_gps);
-
 			linkIcon.attr("class", "ui-icon ui-icon-folder-collapsed");
 			mapGPScontainer.css("display", "none");
@@ -396,27 +376,4 @@
 	}
 
-	/*var changes = null;
-	//var changes = de.Changes.getChangedEditableSections();
-	for(var i = 0; i < changes.length; i++) {
-
-	var changedElem = changes[i];
-
-	//Get metadata name
-	var row = changedElem.parentNode;
-	var cells = row.getElementsByTagName("TD");
-	var nameCell = cells[0];
-	var name = nameCell.innerHTML;
-	var value = changedElem.innerHTML;
-	value = value.replace(/&nbsp;/g, " ");
-
-	var orig = changedElem.originalValue;
-	if (orig) {
-	orig = orig.replace(/&nbsp;/g, " ");
-	}
-	metadataChanges.push({collection:collection, docID:docID, name:name, value:value, orig:orig});
-	changedElem.originalValue = changedElem.innerHTML;
-
-	}
-	 */
 	if (metadataChanges.length == 0) {
 		console.log(gs.text.de.no_changes);
Index: main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor-history.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor-history.js	(revision 32825)
+++ main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor-history.js	(revision 32832)
@@ -10,8 +10,10 @@
 MapEditorHistory.prototype.undo = function () {
 	
-	for (var i = 0; i < this.mapEditor.overlays.length; i++) {
-		this.mapEditor.overlays[i].setMap(null);
-	}
+	
 	if (this.prevOverlays.length != 0) {
+		for (var i = 0; i < this.mapEditor.overlays.length; i++) {
+			this.mapEditor.overlays[i].setMap(null);
+		}
+		
 		this.mapEditor.selectedShapes = [];
 		this.mapEditor.overlays = [];
@@ -34,39 +36,41 @@
 
 	if (this.undoneOverlays.length != 0) {
-		var draggableCB = document.querySelector("input[name=draggableCB]").checked = false;
-		this.mapEditor.selectedShapes = [];
-		for (var i = 0; i < this.mapEditor.overlays.length; i++) {
-			this.mapEditor.overlays[i].setMap(null);
-		}
-
-		this.mapEditor.overlays = [];
-		var lastEntry = this.undoneOverlays[this.undoneOverlays.length - 1];
-		for (var i = 0; i < lastEntry.length; i++) {
-			this.mapEditor.overlays[i] = lastEntry[i];
-			this.mapEditor.overlays[i].setMap(this.mapEditor.map);
-			this.mapEditor.overlays[i].draggable = true;
-		}
-
-		var conditionPrevious = this.presentOverlays[0];
-		if (conditionPrevious !== undefined) {
-			if (conditionPrevious.length == 0) {
-				this.prevOverlays.push(this.presentOverlays[0]);
-			} else {
-				var overlays_copy = [];
-				for (var i = 0; i < this.presentOverlays[0].length; i++) {
-					var clone_shape = ShapesUtil.cloneShape(this.presentOverlays[0][i]);
-					if (ShapesUtil.overlayItemIsShape(clone_shape)) {
-						this.mapEditor.addShapeListeners(clone_shape, null);
-					} else {
-						this.mapEditor.addMarkerListeners(clone_shape, null);
+		if (this.undoneOverlays[this.undoneOverlays.length -1].length != 0) {
+			var draggableCB = document.querySelector("input[name=draggableCB]").checked = false;
+			this.mapEditor.selectedShapes = [];
+			for (var i = 0; i < this.mapEditor.overlays.length; i++) {
+				this.mapEditor.overlays[i].setMap(null);
+			}
+
+			this.mapEditor.overlays = [];
+			var lastEntry = this.undoneOverlays[this.undoneOverlays.length - 1];
+			for (var i = 0; i < lastEntry.length; i++) {
+				this.mapEditor.overlays[i] = lastEntry[i];
+				this.mapEditor.overlays[i].setMap(this.mapEditor.map);
+				this.mapEditor.overlays[i].draggable = true;
+			}
+
+			var conditionPrevious = this.presentOverlays[0];
+			if (conditionPrevious !== undefined) {
+				if (conditionPrevious.length == 0) {
+					this.prevOverlays.push(this.presentOverlays[0]);
+				} else {
+					var overlays_copy = [];
+					for (var i = 0; i < this.presentOverlays[0].length; i++) {
+						var clone_shape = ShapesUtil.cloneShape(this.presentOverlays[0][i]);
+						if (ShapesUtil.overlayItemIsShape(clone_shape)) {
+							this.mapEditor.addShapeListeners(clone_shape, null);
+						} else {
+							this.mapEditor.addMarkerListeners(clone_shape, null);
+						}
+						overlays_copy[i] = clone_shape;
 					}
-					overlays_copy[i] = clone_shape;
+					this.prevOverlays.push(overlays_copy);
 				}
-				this.prevOverlays.push(overlays_copy);
-			}
-		}
-		this.presentOverlays = [];
-		this.presentOverlays.push(this.undoneOverlays[this.undoneOverlays.length - 1]);
-		this.undoneOverlays.pop();
+			}
+			this.presentOverlays = [];
+			this.presentOverlays.push(this.undoneOverlays[this.undoneOverlays.length - 1]);
+			this.undoneOverlays.pop();
+		}
 	}
 }
Index: main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js	(revision 32825)
+++ main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js	(revision 32832)
@@ -4,4 +4,5 @@
 	this.id = id;
 	this.shiftKeyPressed = false;
+	this.ctrlKeyPressed = false;
 	this.beingDragged = false;
 	this.allowDeselect = true;
@@ -17,4 +18,5 @@
 	this.drawingManager;
 	this.selectedShape;
+	this.savedOverlays = null;
 	this.map = null;
 	this.counter = 0;
@@ -86,13 +88,13 @@
 	document.getElementById("thicknessRange" + "-" + this.id).addEventListener("mouseup", function () { that.shapeSpecsChangeMU() });
 	document.getElementById("colourOpacity" + "-" + this.id).addEventListener("mouseup", function() { that.shapeSpecsChangeMU() } );
-	document.onmousemove = function (ev) {
-		//How can I know the state of mouse from here
-		if (that.mouseState == 'down') {
-			//console.log('mouse down state')
-		}
-		if (that.mouseState == 'up') {
-			//console.log('mouse up state')
-		}
-	}
+//	document.onmousemove = function (ev) {
+//		//How can I know the state of mouse from here
+//		if (that.mouseState == 'down') {
+//			//console.log('mouse down state')
+//		}
+//		if (that.mouseState == 'up') {
+//			//console.log('mouse up state')
+//		}
+//	}
 
 	document.onmousedown = function (ev) {
@@ -108,32 +110,31 @@
 	}
 	
-	/* TODO: WORK IN PROGRESS
+	
+	//prompts the user to save the changes before reloading/leaving the page
 	window.onbeforeunload = function (e) {
-		var collection = gs.cgiParams.c;
-		var site_name = gs.xsltParams.site_name;
-		var documentID = this.id;
-		var metadataName = "MapOverlays";
+		var currentOverlays = JSON.stringify(ShapesUtil.overlayToJSON(that.overlays));
+		var enableMessage = currentOverlays !== that.savedOverlays;
+		var message = "Changes are not saved. Are you sure you want to leave?";
+		
+		console.log(currentOverlays);
+		console.log(that.savedOverlays);
+		console.log(enableMessage);
 		
 		
-		//functions.getArchivesMetadata = function(collection, site, documentID, metadataName, metadataPosition, responseFunction);
-		
-		
-		//responseFunction = console.log()
-		
-		var savedOverlays = null;
-		var enableMessage = that.overlays == savedOverlays;
-		var enableMessage = true;
-		var message = "Your confirmation message goes here.",
 		e = e || window.event;
 		// For IE and Firefox
 		if (e) {
+			
 			if(enableMessage){
-				e.returnValue = message;
-				// For Safari
-				return message;			
-			}
-		}
-	}*/
-	
+				if(currentOverlays !== "[]") {
+					alert(message);
+					e.returnValue = message;
+					
+					// For Safari
+					return message;	
+				}
+			}				
+		}
+	}
 }
 
@@ -256,5 +257,5 @@
 	// Add a style-selector control to the map.
 	var styleControl = document.getElementById('style-selector-control' + "-" + this.id);
-	this.map.controls[google.maps.ControlPosition.TOP_LEFT].push(styleControl);
+	this.map.controls[google.maps.ControlPosition.TOP_RIGHT].push(styleControl);
 
 	// Set the map's style to the initial value of the selector.
@@ -316,6 +317,5 @@
 			that.addMarkerListeners(newShape, e);
 			that.setSelection(newShape, e);
-		}
-		
+		}	
 	});
 
@@ -341,36 +341,43 @@
 
 	//Keyboard shortcuts			
-	var mapAndControls = $("#map-and-controls-" + this.id);
-
-        // Shifted to using jQuery so that key mappings don't just work on Chrome but on Firefox too (and hopefully Edge, Safari, etc)
-	mapAndControls.keypress(function (event) {	//mapAndControls.keydown(function (event) {	
-		// https://stackoverflow.com/questions/2220196/how-to-decode-character-pressed-from-jquerys-keydowns-event-handler
-		//var keyCode = String.fromCharCode(event.keyCode); // for keyDown
+	var mapAndControls = document.getElementById("map-and-controls-" + this.id); 
+	console.log(mapAndControls);
+	
+	//Sets shift as unpressed
+	mapAndControls.addEventListener('keyup', function (event) { 	
+		if (event.keyCode == '16') {
+			that.shiftKeyPressed = false;
+		}
+	});
+	
+	mapAndControls.addEventListener('keydown', function (event) { 
+
+		// https://stackoverflow.com/questions/2220196/how-to-decode-character-pressed-from-jquerys-keydowns-event-handler	
 		var keyCode = String.fromCharCode(event.which);
-		//alert("Key pressed: " + keyCode);
+//		console.log("Key pressed: " + keyCode);
 		
-		if (event.keyCode == 'shiftKey') {
+		//Sets shift as pressed
+		if (event.keyCode == '16') {
 			that.shiftKeyPressed = true;
 		}
-		else if (keyCode == 'y' && (event.ctrlKey || event.metaKey) ||
-			(keyCode == 'z' && keyCode == 'shiftKey' && (event.ctrlKey || event.metaKey))) {
+		else if (keyCode == 'Y' && (event.ctrlKey || event.metaKey)) {
 			that.mapEditorHistory.redo();
 		}
-		else if (keyCode == 'z' && (event.ctrlKey || event.metaKey)) {
+		else if (keyCode == 'Z' && (event.ctrlKey || event.metaKey) ) {
 			if (that.shiftKeyPressed == false) {
-				that.mapEditorHistory.undo();
-			}
-		}
-		else if (keyCode == 'a' && (event.ctrlKey || event.metaKey)) {
+			that.mapEditorHistory.undo();
+			}	
+		}
+		
+		else if (keyCode == 'A' && (event.ctrlKey || event.metaKey)) {
 			event.preventDefault();
 			that.drawingManager.setDrawingMode(null);
-			that.selectAll();
-
-		}
-		else if (keyCode == 'd' && (event.ctrlKey || event.metaKey)) {
+			that.selectAll();		
+		}
+		else if (keyCode == 'D' && (event.ctrlKey || event.metaKey)) {
 			event.preventDefault();
 			that.deselectAll();
 		}
-		else if (keyCode == '0' || keyCode == '`') {
+		else if (keyCode == '0' || keyCode == 'Ã' || keyCode == 'G') {
 
 			that.drawingManager.setDrawingMode(null);
@@ -385,37 +392,12 @@
 		} else if (keyCode == '5') {
 			that.drawingManager.setDrawingMode('rectangle');
-		} else if (keyCode == 's') {
-			that.saveToArchives();			
-		} else if (keyCode == 'q') {			
+		} else if (keyCode == 'S') {
+			that.saveToArchives();	
+		} else if (keyCode == 'Q') {			
 			that.printHistory();
 		}
-		//							console.log(keyCode);
-	});
-
-	/*
-	var mapHtml = document.getElementById("map-" + this.id);
-	var controlHtml = document.getElementById("ControlPanel-" + this.id);
-	controlHtml.addEventListener('click', function () {
-		console.log("*** ControlPanel clicked");
-	    mapHtml.focus() 
-	});
-	*/
-	
-	//Sets shift as pressed
-	mapAndControls.keydown(function (event) {
-		if (event.keyCode == 'shiftKey') {
-			that.shiftKeyPressed = true;
-
-		}
-
-	});
-
-	//Sets shift as unpressed
-	mapAndControls.keyup(function (event) {		
-		if (event.keyCode == 'shiftKey') {
-			that.shiftKeyPressed = false;
-		}
-
-	});
+//									console.log(keyCode);
+	});
+
 
 	this.buildColorPalette();
@@ -434,11 +416,12 @@
 			
 			// called when data has been retrieved from archives
-			var JSONString = responseText.getValue();			
-			that.LOAD(JSONString);
-			//var json_overlays = ShapesUtil.overlayToJSON(this.overlays);	
+			var JSONString = responseText.getValue();
+			if(JSONString !== "")
+			{
+				that.LOAD(JSONString);
+				that.savedOverlays = JSONString;
+			}
 		}
 	); // TODO: responseFunction in setMeta call
-	
-	
 }
 
@@ -468,5 +451,12 @@
 	//cLICK EVENT IF A MARKER IS CREATED
 	google.maps.event.addListener(newShape, 'click', function (e) {
-		that.setSelection(newShape, e);
+		if(that.shiftKeyPressed){
+			
+		} else {
+			that.mapEditorHistory.historyOverlayPush();
+			newShape.setMap(null);
+			that.mapEditorHistory.presentOverlayPush();			
+		}
+
 	});
 
@@ -539,12 +529,11 @@
 MapEditor.prototype.clearSelection = function () {
 	if (this.selectedShape) {
-		if (this.selectedShape.type !== 'marker') {
-			this.selectedShape.setEditable(false);
-			if (this.shiftKeyPressed == false) {
-				for (var i = 0; i < this.selectedShapes.length; i++) {
-					this.selectedShapes[i].setEditable(false);
+		if (this.shiftKeyPressed == false) {
+			for (var i = 0; i < this.selectedShapes.length; i++) {
+				if(this.selectedShapes[i].type !== 'marker') {
+					this.selectedShapes[i].setEditable(false);						
 				}
-				this.selectedShapes = [];
-			}
+			}
+			this.selectedShapes = [];
 		}
 		this.selectedShape = null;
@@ -589,5 +578,6 @@
 
 	} else if (shape.type == 'marker') {
-		this.clearSelection();
+		this.allowDeselect = false;
+		this.selectedShapes.push(shape);
 	}
 	this.selectedShape = shape;
@@ -666,5 +656,8 @@
 MapEditor.prototype.deselectAll = function () {
 	for (var i = 0; i < this.selectedShapes.length; i++) {
-		this.selectedShapes[i].setEditable(false);
+		if (this.selectedShapes[i].type !== google.maps.drawing.OverlayType.MARKER) {
+			this.selectedShapes[i].setEditable(false);
+		}
+		
 	}
 	this.selectedShapes = [];
@@ -673,5 +666,6 @@
 
 MapEditor.prototype.saveToArchives = function () {
-	alert("Save pressed");
+	var that = this;
+	console.log("Save pressed");
 	
 	var json_overlays = ShapesUtil.overlayToJSON(this.overlays);
@@ -683,7 +677,14 @@
 	// collection, site, documentID, metadataName, metadataPosition, metadataValue, prevMetadataValue, metamode, responseFunction	
 	gs.functions.setArchivesMetadata(collection, site_name, nodeID, metaname, 0, JSON.stringify(json_overlays), null, "override", function(){
-			alert("SAVED");
+			console.log("SAVED");
 		}
 	);
+	
+	gs.functions.getArchivesMetadata(collection, site_name, nodeID, metaname, 0, function(responseText){
+			var JSONString = responseText.getValue();
+			that.savedOverlays = JSONString;
+		}
+	);	
+	
 }
 
@@ -693,16 +694,12 @@
 	console.log("present ", this.mapEditorHistory.presentOverlays);
 	console.log("undone ", this.mapEditorHistory.undoneOverlays);
-	//console.log(this.selectedShapes);
-	var collection = gs.cgiParams.c;
-	console.log(collection);
-	console.log(this.overlays);
-	var json_overlays = ShapesUtil.overlayToJSON(this.overlays);
-	
-	console.log("JSON overlay:\n" + JSON.stringify(json_overlays));
-	
-	/*
-	this.LOAD('[{"strokeColor":"#32CD32","strokeWeight":1,"fillColor":"#32CD32","fillOpacity":0.4,"bounds":{"north":-37.78190971734986,"south":-37.787200748043546,"east":175.33850727431195,"west":175.3324991261186},"type":"rectangle"},{"strokeColor":"#FF8C00","strokeWeight":1,"fillColor":"#FF8C00","fillOpacity":0.4,"bounds":{"north":-37.78550494611987,"south":-37.791270513892385,"east":175.33764896742719,"west":175.3284650837602},"type":"rectangle"},{"strokeColor":"#000000","strokeWeight":1,"fillColor":"#000000","fillOpacity":0.4,"bounds":{"north":-37.793034009483115,"south":-37.79723909833998,"east":175.3225427662553,"west":175.31498966566937},"type":"rectangle"},{"strokeColor":"#4B0082","strokeWeight":5,"fillColor":"#4B0082","fillOpacity":0.62,"bounds":{"north":-37.78991395018121,"south":-37.79737474238258,"east":175.30846653334515,"west":175.2955060993852},"type":"rectangle"},{"strokeColor":"#000000","strokeWeight":1,"fillColor":"#000000","fillOpacity":0.4,"bounds":{"north":-37.79961283312584,"south":-37.80700483276894,"east":175.3281217610063,"west":175.31241474501508},"type":"rectangle"},{"geodesic":false,"strokeColor":"#FF8C00","strokeWeight":1,"path":[{"lat":-37.77824647420985,"lng":175.31842289320844},{"lat":-37.792627052698045,"lng":175.32425938002484},{"lat":-37.79079571942646,"lng":175.31061230055707},{"lat":-37.78597977458094,"lng":175.2910429035844},{"lat":-37.78055298179892,"lng":175.29413280836957},{"lat":-37.77912838266847,"lng":175.3034883534135},{"lat":-37.77668614885508,"lng":175.30537662856},{"lat":-37.78218106147165,"lng":175.3079515492143}],"type":"polygon","fillColor":"#FF8C00","fillOpacity":0.4},{"strokeColor":"#FF8C00","strokeWeight":1,"fillColor":"#FF8C00","fillOpacity":0.4,"center":{"lat":-37.7737689305036,"lng":175.33549693998134},"radius":811.9768269278177,"type":"circle"},{"position":{"lat":-37.77431167751719,"lng":175.3143825906161},"type":"marker"},{"position":{"lat":-37.782452404597294,"lng":175.3337803262118},"type":"marker"},{"geodesic":false,"strokeColor":"#4B0082","strokeOpacity":1,"strokeWeight":5,"path":[{"lat":-37.759203725669785,"lng":175.33033457820488},{"lat":-37.771688357854,"lng":175.35162058894707},{"lat":-37.79339574144619,"lng":175.3646668535955},{"lat":-37.81536797134891,"lng":175.35436717097832},{"lat":-37.819978597019684,"lng":175.32861796443535},{"lat":-37.81970739171663,"lng":175.2929123980291},{"lat":-37.806688365360884,"lng":175.26235667293145},{"lat":-37.795294834173575,"lng":175.25789347713066},{"lat":-37.78389954558992,"lng":175.2541169268377},{"lat":-37.77033143470697,"lng":175.26132670466973},{"lat":-37.760018005052494,"lng":175.27746287410332},{"lat":-37.75757514001425,"lng":175.31076518123223},{"lat":-37.759203725669785,"lng":175.33033457820488}],"type":"polyline"}]');
-	*/
-	 
+	console.log(this.selectedShapes);
+	
+	//var collection = gs.cgiParams.c;
+	//console.log(collection);
+	//console.log(this.overlays);
+	//var json_overlays = ShapesUtil.overlayToJSON(this.overlays);
+	
+
 }
 
@@ -712,4 +709,5 @@
 	
     var map_editor = Object.values(gsmap_store)[0];
+	
 	var new_overlays = ShapesUtil.JSONToOverlays(json_str);
 	for (var i=0; i<map_editor.overlays.length; i++) {
@@ -725,21 +723,27 @@
 	this.mapEditorHistory.presentOverlayPush();
 	
+	
+	//When the overlays are loaded from the metadate, they cannot be selected when clicked on them. 
+	//One fix for this issue is to delete all the sapes present then bring them back by 'undo', then they can be normally selected
+	this.deleteAllShapes();
+	this.mapEditorHistory.undo();
+	this.mapEditorHistory.prevOverlays = [];		
 }
 
 MapEditor.prototype.deleteSelectedShapes = function () {
-	//console.log("this fires");
-	this.mapEditorHistory.historyOverlayPush();
-	for (var i = 0; i < this.selectedShapes.length; i++) {
-		this.selectedShapes[i].setMap(null);
-
-		if (this.overlays.includes(this.selectedShapes[i])) {
-			const index = this.overlays.indexOf(this.selectedShapes[i]);
-			this.overlays.splice(index, 1);
-			this.selectedShapes[i].setEditable(false);
-		}
-	}
-	this.selectedShapes = [];
-	//console.log("this fires");
-	this.mapEditorHistory.presentOverlayPush();
+	if(this.selectedShapes.length !== 0) {
+		this.mapEditorHistory.historyOverlayPush();
+		for (var i = 0; i < this.selectedShapes.length; i++) {
+			this.selectedShapes[i].setMap(null);
+
+			if (this.overlays.includes(this.selectedShapes[i])) {
+				const index = this.overlays.indexOf(this.selectedShapes[i]);
+				this.overlays.splice(index, 1);
+//				this.selectedShapes[i].setEditable(false);
+			}
+		}
+		this.selectedShapes = [];
+		this.mapEditorHistory.presentOverlayPush();		
+	}
 }
 
@@ -757,11 +761,12 @@
 
 MapEditor.prototype.deleteAllShapes = function () {
-	//console.log("deleteAllShape() this.id = " + this.id);
-	this.mapEditorHistory.historyOverlayPush();
-	for (var i = 0; i < this.overlays.length; i++) {
-		this.overlays[i].setMap(null);
-	}
-	this.overlays = [];
-	this.mapEditorHistory.presentOverlayPush();
-}
-
+	if(this.overlays.length !== 0) {
+		//console.log("deleteAllShape() this.id = " + this.id);
+		this.mapEditorHistory.historyOverlayPush();
+		for (var i = 0; i < this.overlays.length; i++) {
+			this.overlays[i].setMap(null);
+		}
+		this.overlays = [];
+		this.mapEditorHistory.presentOverlayPush();
+	}
+}
Index: main/trunk/greenstone3/web/interfaces/default/js/map-scripts-shapes-util.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/map-scripts-shapes-util.js	(revision 32825)
+++ main/trunk/greenstone3/web/interfaces/default/js/map-scripts-shapes-util.js	(revision 32832)
@@ -57,5 +57,4 @@
 	var strokeWeight  = poly.strokeWeight;
 
-	//var path = poly.getPath();
 	clone_path = ShapesUtil.mvcClonePath(path);	
 	
@@ -74,6 +73,4 @@
 			type: type
 		});
-
-		//clone_polyline.type = google.maps.drawing.OverlayType.POLYLINE;
 	}
 	else {
@@ -94,5 +91,4 @@
 			type: type
 		});
-		//clone_polygon.type = google.maps.drawing.OverlayType.POLYGON;
 	}
 	
@@ -200,7 +196,4 @@
 			type: type
 		});
-
-	//clone_rect.type = google.maps.drawing.OverlayType.RECTANGLE;
-
 	return clone_rect;
 }
@@ -285,7 +278,4 @@
 			type: type
 		});
-
-	//clone_circ.type = google.maps.drawing.OverlayType.CIRCLE;
-
 	return clone_circ;
 }
@@ -333,10 +323,7 @@
 			clickable: true,
 			draggable: true,
-			editable: false,
+			editable: true,
 			type: google.maps.drawing.OverlayType.MARKER
 		})
-		
-		//clone_marker.type = google.maps.drawing.OverlayType.MARKER;
-
 	return clone_marker;
 }
@@ -471,5 +458,4 @@
 
 ShapesUtil.JSONToOverlays = function (json_shapes_str) {
-	
 	var json_shapes = JSON.parse(json_shapes_str);
 	
@@ -477,5 +463,4 @@
 	
 	for (var i=0; i<json_shapes.length; i++) {
-		
 		var json_shape = json_shapes[i];
 		var shape = ShapesUtil.JSONToShape(json_shape);
Index: main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 32825)
+++ main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 32832)
@@ -82,4 +82,6 @@
 function setUpMap()
 {
+
+	
 	var myOptions = 
 	    {
@@ -335,10 +337,9 @@
 
 function attachClickHandler(marker, nodeID)
-{
-
-	
+{	
 	google.maps.event.addListener(marker, 'click', function()
 	{
 		document.location.href = gs.xsltParams.library_name + "?a=d&ed=1&c=" + gs.cgiParams.c + "&d=" + nodeID + "&dt=hierarchy&p.a=b&p.sa=&p.s=ClassifierBrowse";
+		
 	});
 	
@@ -348,5 +349,5 @@
 			var lat = marker.getPosition().lat();
 			var lng = marker.getPosition().lng();
-			var collection = gs.cgiParams.c;;
+			var collection = gs.cgiParams.c;
 			var site_name = gs.xsltParams.site_name;
 			
@@ -362,5 +363,6 @@
 			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();});
-			
+			console.log(nodeID);
+			console.log("GPS Click handler in collection:" + collection + " in site: " + site_name + " for Doc: " + nodeID + "(" + lat + "," + lng + ")");
 		});
 	}
@@ -408,6 +410,4 @@
 	// Don't allow dragging if either 1. docEdit not on OR 2. logout is in the cgiParams
 	var draggable_val = (!docEdit || loggedOutVar) ? false : true;
-	
-	console.log(gs.cgiParams);
 	
 	var marker
@@ -433,6 +433,4 @@
 		});
 	}
-
-	console.log("doc = " + JSON.stringify(doc));
 	
 	var docElement = gs.jqGet("div" + doc.nodeID);
@@ -465,5 +463,6 @@
 	//console.log("Latitude " + newLat);
 	//console.log("Longitude " + newLng);
-	NewLatLng(newLat, newLng);
+	//NewLatLng(newLat, newLng);
+	
 //	// Define the LatLng coordinates for the polygon's path.
 //        var triangleCoords = [
Index: main/trunk/greenstone3/web/interfaces/default/transform/layouts/header.xsl
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/transform/layouts/header.xsl	(revision 32825)
+++ main/trunk/greenstone3/web/interfaces/default/transform/layouts/header.xsl	(revision 32832)
@@ -30,5 +30,6 @@
   <!-- is editing available for the collection? eg is there an archives folder? -->
   <xsl:variable name="isEditingAvailable">
-  <xsl:choose><xsl:when test="/page/pageResponse/collection/@no_archives">0</xsl:when><xsl:otherwise>1</xsl:otherwise></xsl:choose></xsl:variable>
+	<xsl:choose><xsl:when test="/page/pageResponse/collection/@no_archives">0</xsl:when><xsl:otherwise>1</xsl:otherwise></xsl:choose>
+  </xsl:variable>
   <!-- is a user logged in, and do they have editing rights for this collection? -->
   <xsl:variable name="userHasEditPermission">
@@ -57,4 +58,5 @@
     <xsl:variable name="collection"><xsl:call-template name="collectionName"/></xsl:variable>
     <xsl:variable name="site"><xsl:call-template name="siteName"/></xsl:variable>
+	 
     <title><xsl:value-of select="$page"/><xsl:if test="$collection != '' and $page != $collection"> :: <xsl:value-of select="$collection"/></xsl:if><xsl:if test="$page != $site"> :: <xsl:value-of select="$site"/></xsl:if></title>
     
@@ -109,12 +111,14 @@
     <xsl:if test="/page/pageRequest/userInformation and /page/pageRequest/userInformation/@editEnabled = 'true' and (util:contains(/page/pageRequest/userInformation/@groups, 'administrator') or util:contains(/page/pageRequest/userInformation/@groups, 'all-collections-editor') or util:contains(/page/pageRequest/userInformation/@groups, $thisCollectionEditor))">
       <xsl:if test="/page/pageRequest/paramList/param[(@name='docEdit') and (@value='on' or @value='true' or @value='1')]">
+	   
+		 
 		<script type="text/javascript" src="interfaces/{$interface_name}/js/ckeditor/ckeditor.js" defer="true"><xsl:text> </xsl:text></script>	
-		<!--			<xsl:call-template name="init-direct-edit"/> -->
+		<!--			<xsl:call-template name="init-direct-edit"/>	-->
 		
-		
-		<xsl:if test="/page/pageResponse/format[@type='display']/gsf:option[not(@name='mapEnabled')] or (/page/pageResponse/format[@type='display']/gsf:option[@name='mapEnabled']  and /page/pageResponse/format[@type='display']/gsf:option[@name='mapEnabled']/@value = 'false')">
+		<xsl:variable name="mapEnabled"><xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='mapEnabled']/@value"/></xsl:variable>
+		<xsl:if test="$mapEnabled = 'false' or $mapEnabled = ''">
 		  <xsl:call-template name="map-scripts"/>
 		</xsl:if>
-		
+	
 	  </xsl:if>
       <script type="text/javascript" src="interfaces/{$interface_name}/js/debug_scripts.js"><xsl:text> </xsl:text></script>
Index: main/trunk/greenstone3/web/interfaces/default/transform/pages/document.xsl
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/transform/pages/document.xsl	(revision 32825)
+++ main/trunk/greenstone3/web/interfaces/default/transform/pages/document.xsl	(revision 32832)
@@ -231,18 +231,15 @@
 					</xsl:for-each>
 				</table>
-				<div id="map-and-controls-{@nodeID}">
+				<div id="map-and-controls-{@nodeID}" tabindex="-1">
 					<div id="map-{@nodeID}" style="height: 300px;"><xsl:text> </xsl:text></div>
 					
 
-					<div id="ControlPanel-{@nodeID}" class="ControlPanel">
+					<div id="ControlPanel-{@nodeID}" class="ControlPanel" >
 						<div id="ControlButtons">
-							<script>
-							   //var myMapEditor = MapEditor('{@nodeID}');
-							</script>
-							<button onclick="deleteAllShape('{@nodeID}')" accesskey="c">Clear All</button>
-							<button onclick="deleteSelectedShape('{@nodeID}')" accesskey="b">Delete Selected</button>
-							<button onclick="undo('{@nodeID}')" accesskey="n">Undo</button>
-<!--							<button onclick="myMapEditor.getHistory().undo('{@nodeID}')" accesskey="n">Undo</button> -->
-							<button onclick="redo('{@nodeID}')" accesskey="n">Redo</button>
+	
+							<button onclick="gsmap_store['map-{@nodeID}'].deleteAllShapes()" >Clear All</button>
+							<button onclick="gsmap_store['map-{@nodeID}'].deleteSelectedShapes()" >Delete Selected</button>
+							<button onclick="gsmap_store['map-{@nodeID}'].mapEditorHistory.undo()" >Undo</button>
+							<button onclick="gsmap_store['map-{@nodeID}'].mapEditorHistory.redo()" >Redo</button>
 							<input type="checkbox" name="draggableCB" id="draggableCB-{@nodeID}" value="false" /> Lock all shapes location <br/>
 						</div>
@@ -265,5 +262,4 @@
 						</div>
 					</div>
-				-
 					<div id="style-selector-control-{@nodeID}"  class="map-control">
 					  <select id="style-selector-{@nodeID}" class="selector-control">
@@ -326,4 +322,5 @@
 			<script type="text/javascript" src="interfaces/{$interface_name}/js/documentedit_scripts.js"><xsl:text> </xsl:text></script>
 			<script type="text/javascript" src="interfaces/{$interface_name}/js/documentedit_scripts_util.js"><xsl:text> </xsl:text></script>
+			<script type="text/javascript" src="interfaces/{$interface_name}/js/map-scripts-shapes-util.js"><xsl:text> </xsl:text></script>
 			<script type="text/javascript" src="interfaces/{$interface_name}/js/map-scripts-editor-history.js"><xsl:text> </xsl:text></script>
 			<script type="text/javascript" src="interfaces/{$interface_name}/js/map-scripts-editor-themes.js"><xsl:text> </xsl:text></script>		
