Index: /main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js
===================================================================
--- /main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js	(revision 27152)
+++ /main/trunk/greenstone3/web/interfaces/default/js/debug_scripts.js	(revision 27153)
@@ -14,5 +14,7 @@
 	var _itemSelected = false; //Used to prevent multiple elements from being highlighted
 	var _editModeText = false;
+	var _fromSelection = false;
 	var _selectedTemplate;
+	var _selectedInfoContainers = new Array();
 
 	//Page elements
@@ -27,5 +29,5 @@
 	var _editor;
 	var _editingDiv;
-	var _selectNewElementButton;
+	var _enableSelectorButton;
 	var _closeEditorButton;
 	var _xmlStatusBar;
@@ -98,39 +100,17 @@
 	{
 		//Used to enable the selector to get the templates of a particular area of the page
-		var enableSelectorButton = $("<button>Enable selector</button>");
-		enableSelectorButton.click(function()
-		{
-			if(!_debugOn)
-			{
-				enableSelectorButton.button("option", "label", "Disable selector");
-				$("a").click(function(e)
-				{
-					e.preventDefault();
-				});
-				_debugOn = true;
-			}
-			else
-			{
-				enableSelectorButton.button("option", "label", "Enable selector");
-				$("a").off("click");
-				clearAll();
-				_selectNewElementButton.button("option", "disabled", true);
-				_pauseSelector = false;
-				_debugOn = false;
-			}
-		});
-		_styleFunctions.push(function(){enableSelectorButton.button({icons:{primary:"ui-icon-power"}})});
-
-		//Used to change what is currently selected
-		_selectNewElementButton = $("<button>Select new element</button>");
-		_selectNewElementButton.click(function()
-		{
-			if(_pauseSelector)
-			{
-				_pauseSelector = false;
-				_selectNewElementButton.button("option", "disabled", true);
-			}
-		});
-		_styleFunctions.push(function(){_selectNewElementButton.button({icons:{primary:"ui-icon-pencil"}, disabled:true})});
+		_enableSelectorButton = $("<button>Select an element</button>");
+		_enableSelectorButton.click(function()
+		{
+			_enableSelectorButton.button("option", "label", "Select new element");
+			$("a").click(function(e)
+			{
+				e.preventDefault();
+			});
+			_debugOn = true;
+			_pauseSelector = false;
+			_enableSelectorButton.button("option", "disabled", true);
+		});
+		_styleFunctions.push(function(){_enableSelectorButton.button({icons:{primary:"ui-icon-power"}})});
 
 		//Used to minimise/restore the editor
@@ -172,5 +152,5 @@
 				try
 				{
-					var xml = $.parseXML('<testContainer xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil" xmlns:gslib="http://www.greenstone.org/skinning" xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat">' + xmlString + "</testContainer>");
+					var xml = $.parseXML('<testContainer xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil" xmlns:gslib="http://www.greenstone.org/skinning" xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat">' + xmlString + "</testContainer>");
 				}
 				catch(error)
@@ -276,6 +256,5 @@
 		_styleFunctions.push(function(){undoButton.button({icons:{primary:"ui-icon-arrowreturnthick-1-w"}})});
 
-		buttonDiv.append(enableSelectorButton);
-		buttonDiv.append(_selectNewElementButton);
+		buttonDiv.append(_enableSelectorButton);
 		buttonDiv.append(_closeEditorButton);
 		buttonDiv.append(_saveButton);
@@ -368,4 +347,9 @@
 			_fileSelector.append("<span>Files: </span>");
 			_fileSelector.append(selectBox);
+			
+			var currentSelectionOption = $("<option>[Current selection]</option>");
+			currentSelectionOption.val("currentSelection");
+			selectBox.append(currentSelectionOption);
+			
 			for(var i = 0; i < list.length; i++)
 			{
@@ -380,4 +364,16 @@
 				var selectedItem = selectBox.find(":selected");
 
+				if(selectedItem.val() == "currentSelection")
+				{
+					_templateSelector.children("select").empty();
+					for(var i = 0; i < _selectedInfoContainers.length; i++)
+					{
+						var currentContainer = _selectedInfoContainers[i];
+						_templateSelector.children("select").append(currentContainer);
+					}
+					_templateSelector.children("select").children().first().trigger("change");
+					return;
+				}
+				
 				if(!selectedItem.data("fileItem"))
 				{
@@ -394,14 +390,8 @@
 					var templateList = eval(templateListString);
 
-					clearAll();
-
 					_templateSelector.children("select").empty();
 					if(templateList.length == 0)
 					{
 						_templateSelector.children("select").append("<option>-- No templates --</option>");
-					}
-					else
-					{
-						_templateSelector.children("select").append("<option>-- Select a template --</option>");
 					}
 
@@ -441,4 +431,6 @@
 						_templateSelector.children("select").append(infoContainer);
 					}
+
+					_templateSelector.children("select").trigger("change");
 				});
 			});
@@ -617,10 +609,15 @@
 	var addMouseEventsToDebugElements = function(debugElems)
 	{
-		debugElems.click(function()
+		debugElems.click(function(e)
 		{
 			if(_debugOn)
 			{
+				$("a").off("click");
+				_debugOn = false;
 				_pauseSelector = true;
-				_selectNewElementButton.button("option", "disabled", false);
+				_enableSelectorButton.button("option", "disabled", false);
+				_templateSelector.children("select").trigger("change");
+				_fileSelector.children("select").val("currentSelection");
+				e.stopPropagation();
 			}
 		});
@@ -709,4 +706,6 @@
 						infoContainer.text(match);
 					}
+					
+					_selectedInfoContainers.push(infoContainer.clone(true));
 
 					_templateSelector.children("select").append(infoContainer);
@@ -727,5 +726,5 @@
 				clearAll();
 				_templateSelector.children("select").empty();
-				_templateSelector.children("select").append("<option>-- Select a template --</option>");
+				_selectedInfoContainers = new Array();
 			}
 		});
Index: /main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js
===================================================================
--- /main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js	(revision 27152)
+++ /main/trunk/greenstone3/web/interfaces/default/js/visual-xml-editor.js	(revision 27153)
@@ -271,4 +271,10 @@
 			endIndex = response.search("</templateList>");
 
+			if(startIndex == "<templateList>".length - 1)
+			{
+				console.log("Error retrieving GSLIB templates");
+				return;
+			}
+
 			var listString = response.substring(startIndex, endIndex);
 			var list = eval(listString.replace(/&quot;/g, "\""));
@@ -578,5 +584,5 @@
 		try
 		{
-			_xml = $.parseXML('<testContainer xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil" xmlns:gslib="http://www.greenstone.org/skinning" xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat">' + xmlString + "</testContainer>");
+			_xml = $.parseXML('<testContainer xmlns:xslt="http://www.w3.org/1999/XSL/Transform" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil" xmlns:gslib="http://www.greenstone.org/skinning" xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat">' + xmlString + "</testContainer>");
 			constructDivsRecursive(_editorDiv, _xml.firstChild);
 		}
