Index: /main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js
===================================================================
--- /main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 26428)
+++ /main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js	(revision 26429)
@@ -19,8 +19,8 @@
 	setUpMap();
 	
-	var jsonNodeDiv = document.getElementById("jsonNodes");
-	if(jsonNodeDiv)
-	{
-		var jsonNodes = eval(jsonNodeDiv.innerHTML);
+	var jsonNodeDiv = $("#jsonNodes");
+	if(jsonNodeDiv.length)
+	{
+		var jsonNodes = eval(jsonNodeDiv.html());
 		if(jsonNodes && jsonNodes.length > 0)
 		{
@@ -35,6 +35,5 @@
 		else
 		{
-			document.getElementById("map_canvas").style.visibility = "hidden";
-			document.getElementById("map_canvas").style.height = "0px";
+			$("#map_canvas").css({visibility:"hidden", height:"0px"});
 		}
 	}
@@ -44,11 +43,8 @@
 	if(_docList.ids.length > 1)
 	{
-		var startStopCheckbox = document.createElement("input");
-		startStopCheckbox.setAttribute("type", "checkbox");
-		startStopCheckbox.setAttribute("checked", "true");
-		startStopCheckbox.setAttribute("id", "scrollCheckbox");
-		startStopCheckbox.onclick = function()
-		{
-			if(startStopCheckbox.checked)
+		var startStopCheckbox = $("<input>", {"type": "checkbox", "checked": "true", "id": "scrollCheckbox"});
+		startStopCheckbox.click(function()
+		{
+			if(startStopCheckbox.attr("checked"))
 			{
 				if(_intervalHandle == null)
@@ -62,14 +58,10 @@
 				_intervalHandle = null;
 			}
-		};
-		
-		var label = document.createElement("span");
-		label.innerHTML = "Scroll through places";
-		
-		var container = document.createElement("DIV");
-		container.appendChild(startStopCheckbox);
-		container.appendChild(label);
-		container.setAttribute("class", "ui-widget-header ui-corner-all");
-		container.setAttribute("style", "clear:right; float:right; padding:0px 5px 3px 0px;");
+		});
+		
+		var label = $("<span>Scroll through places</span>");
+		var container = $("<div>", {"class": "ui-widget-header ui-corner-all", "style": "clear:right; float:right; padding:0px 5px 3px 0px;"});
+		container.append(startStopCheckbox);
+		container.append(label);
 
 		$(container).insertAfter("#map_canvas");
@@ -87,5 +79,5 @@
 		mapTypeId: google.maps.MapTypeId.HYBRID
 	};
-	_map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
+	_map = new google.maps.Map($("#map_canvas")[0], myOptions);
 	google.maps.event.addListener(_map, 'bounds_changed', performSearchForMarkers);
 }
@@ -179,44 +171,41 @@
 	}
 	
-	var ajax = new gs.functions.ajaxRequest();
-	ajax.open("GET", gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes", true);
-	ajax.onreadystatechange = function()
-	{
-		if(ajax.readyState == 4 && ajax.status == 200)
-		{
-			if(ajax.responseText.search("id=\"jsonNodes") != -1)
-			{
-				var startIndex = ajax.responseText.indexOf(">");
-				var endIndex = ajax.responseText.indexOf("</");
-
-				var jsonNodes = eval(ajax.responseText.substring(startIndex+1, endIndex));
-				if(jsonNodes && jsonNodes.length > 0)
+	var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=jsonNodes";
+	
+	$.ajax(url)
+	.success(function(responseText)
+	{
+		if(responseText.search("id=\"jsonNodes") != -1)
+		{
+			var startIndex = responseText.indexOf(">");
+			var endIndex = responseText.indexOf("</");
+
+			var jsonNodes = eval(responseText.substring(startIndex+1, endIndex));
+			if(jsonNodes && jsonNodes.length > 0)
+			{
+				for(var i = 0; i < jsonNodes.length; i++)
 				{
-					for(var i = 0; i < jsonNodes.length; i++)
+					var doc = jsonNodes[i];
+					
+					var found = false;
+					for(var j = 0; j < _docList.ids.length; j++){if(doc.nodeID == _docList.ids[j]){found = true; break;}}
+					
+					if(!found)
 					{
-						var doc = jsonNodes[i];
-						
-						var found = false;
-						for(var j = 0; j < _docList.ids.length; j++){if(doc.nodeID == _docList.ids[j]){found = true; break;}}
-						
-						if(!found)
-						{
-							_docList[doc.nodeID] = doc;
-							_docList.ids.push(doc.nodeID);
-
-							createMarker(doc, false);
-						}
+						_docList[doc.nodeID] = doc;
+						_docList.ids.push(doc.nodeID);
+
+						createMarker(doc, false);
 					}
 				}
 			}
-			else
-			{
-				console.log("No JSON information received");
-			}
-			
-			_searchRunning = false;
-		}
-	}
-	ajax.send();
+		}
+		else
+		{
+			console.log("No JSON information received");
+		}
+		
+		_searchRunning = false;
+	});
 }
 
@@ -342,9 +331,9 @@
 
 		var doc = visibleMarkers[_docList.loopIndex];
-		var elem = document.getElementById("div" + doc.nodeID);
-		if(elem)
-		{
-			elem.style.background = "#BBFFBB";
-			setTimeout(function(){elem.style.background = "";}, 2000);
+		var elem = gs.jqGet("div" + doc.nodeID);
+		if(elem.length)
+		{
+			elem.css("background", "#BBFFBB");
+			setTimeout(function(){elem.css("background", "");}, 2000);
 		}
 		_docList.loopIndex++;
@@ -371,5 +360,5 @@
 		clearAllInfoBoxes();
 		doc.marker.markerInfo.open(_map, doc.marker);
-		var scrollCheckbox = document.getElementById("scrollCheckbox");
+		var scrollCheckbox = $("#scrollCheckbox");
 		if(scrollCheckbox.checked)
 		{
@@ -412,5 +401,5 @@
 	}
 
-	var docElement = document.getElementById("div" + doc.nodeID);
+	var docElement = gs.jqGet("div" + doc.nodeID);
 	var parent;
 	if(docElement)
@@ -421,5 +410,5 @@
 	while(parent && parent.nodeName != "BODY")
 	{
-		if(parent.getAttribute("id") && parent.getAttribute("id").search("divCL") != -1)
+		if($(parent).attr("id") && $(parent).attr("id").search("divCL") != -1)
 		{
 			doc.parentCL = parent;
@@ -439,38 +428,33 @@
 function getSubClassifier(sectionID)
 {
-	var ajax = new gs.functions.ajaxRequest();
-	ajax.open("GET", gs.xsltParams.library_name + "?a=b&rt=s&s=ClassifierBrowse&c=" + gs.cgiParams.c + "&cl=" + sectionID + "&excerptid=jsonNodes", true);		
-	ajax.onreadystatechange = function()
-	{
-		if(ajax.readyState == 4 && ajax.status == 200)
-		{
-			var startIndex = ajax.responseText.indexOf(">");
-			var endIndex = ajax.responseText.indexOf("</");
-			
-			var jsonNodes = eval(ajax.responseText.substring(startIndex+1, endIndex));
-			if(jsonNodes && jsonNodes.length > 0)
-			{
-				for(var i = 0; i < jsonNodes.length; i++)
-				{
-					var doc = jsonNodes[i];
-					_docList[doc.nodeID] = doc;
-					_docList.ids.push(doc.nodeID);
-
-					createMarker(doc, false);
-				}
-				
-				document.getElementById("map_canvas").style.visibility = "visible";
-				document.getElementById("map_canvas").style.height = undefined;
-			}
-			
-			updateMap();
-		}
-		else if(ajax.readyState == 4)
-		{
-			console.log("Error getting subclassifiers");
-			return;
-		}
-	}
-	ajax.send();
+	var url = gs.xsltParams.library_name + "?a=b&rt=s&s=ClassifierBrowse&c=" + gs.cgiParams.c + "&cl=" + sectionID + "&excerptid=jsonNodes";
+	$.ajax(url)
+	.success(function(responseText)
+	{
+		var startIndex = responseText.indexOf(">");
+		var endIndex = responseText.indexOf("</");
+		
+		var jsonNodes = eval(responseText.substring(startIndex+1, endIndex));
+		if(jsonNodes && jsonNodes.length > 0)
+		{
+			for(var i = 0; i < jsonNodes.length; i++)
+			{
+				var doc = jsonNodes[i];
+				_docList[doc.nodeID] = doc;
+				_docList.ids.push(doc.nodeID);
+
+				createMarker(doc, false);
+			}
+			
+			$("#map_canvas").css({"visibility": "visible", "height": ""});
+		}
+		
+		updateMap();
+	})
+	.error(function()
+	{
+		console.log("Error getting subclassifiers");
+		return;
+	});	
 }
 
@@ -522,66 +506,59 @@
 	</xsl:template>';
 	
-	var ajax = new gs.functions.ajaxRequest();
-	ajax.open("GET", gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=nearbyDocs&ilt=" + inlineTemplate.replace(/ /, "%20"), true);		
-	ajax.onreadystatechange = function()
-	{
-		if(ajax.readyState == 4 && ajax.status == 200)
-		{
-			var response = ajax.responseText;
-			response = response.replace(/<img src="[^"]*map_marker.png"[^>]*>/g, "");
-
-			console.log(ajax.responseText);
-
-			var nearbyDocsArray = new Array();
-
-			var lats = new Array();
-			var lngs = new Array();
-
-			var matches = response.match(/___(-?[0-9\.]*)___/g);
-			for(var i = 0; i < matches.length; i += 2)
-			{
-				var matchLatFloat = parseFloat(matches[i].replace("___", ""));
-				var matchLngFloat = parseFloat(matches[i+1].replace("___", ""));
-
-				lats.push(matchLatFloat);
-				lngs.push(matchLngFloat);
-				
-				var distance = Math.sqrt(Math.pow(matchLatFloat - parseFloat(lat), 2) + Math.pow(matchLngFloat - parseFloat(lng), 2)) * (40000.0/360.0);
-				var distanceString = "" + distance;
-				distanceString = distanceString.substring(0, 6);
-
-				response = response.replace(matches[i] + matches[i+1], distanceString);
-			}
-			
-			var index = 0;
-			var i = 0;
-			while(true)
-			{
-				var distanceStart = response.indexOf("<td>", index);
-				if(distanceStart == -1)
-				{
-					break;
-				}
-				var distanceEnd = response.indexOf("</td>", distanceStart);
-				
-				var docLinkStart = response.indexOf("<td>", distanceEnd);
-				var docLinkEnd = response.indexOf("</td>", docLinkStart);
-				
-				var dist = response.substring(distanceStart + 4, distanceEnd);
-				var docLink = response.substring(docLinkStart + 4, docLinkEnd);
-
-				_nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]});
-				
-				index = docLinkEnd;
-			}
-			
-			sortByDistance();
-			
-			var toggle = document.getElementById("nearbyDocumentsToggle");
-			toggle.setAttribute("src", gs.imageURLs.collapse);
-			gs.functions.makeToggle(toggle, document.getElementById("nearbyDocuments"));
-		}
-	}
-	ajax.send();
+	var url = gs.xsltParams.library_name + "?a=q&s=RawQuery&rt=rd&c=" + gs.cgiParams.c + "&s1.rawquery=" + query + "&excerptid=nearbyDocs&ilt=" + inlineTemplate.replace(/ /, "%20");
+	$.ajax(url)
+	.success(function(response)
+	{
+		response = response.replace(/<img src="[^"]*map_marker.png"[^>]*>/g, "");
+
+		var nearbyDocsArray = new Array();
+
+		var lats = new Array();
+		var lngs = new Array();
+
+		var matches = response.match(/___(-?[0-9\.]*)___/g);
+		for(var i = 0; i < matches.length; i += 2)
+		{
+			var matchLatFloat = parseFloat(matches[i].replace("___", ""));
+			var matchLngFloat = parseFloat(matches[i+1].replace("___", ""));
+
+			lats.push(matchLatFloat);
+			lngs.push(matchLngFloat);
+			
+			var distance = Math.sqrt(Math.pow(matchLatFloat - parseFloat(lat), 2) + Math.pow(matchLngFloat - parseFloat(lng), 2)) * (40000.0/360.0);
+			var distanceString = "" + distance;
+			distanceString = distanceString.substring(0, 6);
+
+			response = response.replace(matches[i] + matches[i+1], distanceString);
+		}
+		
+		var index = 0;
+		var i = 0;
+		while(true)
+		{
+			var distanceStart = response.indexOf("<td>", index);
+			if(distanceStart == -1)
+			{
+				break;
+			}
+			var distanceEnd = response.indexOf("</td>", distanceStart);
+			
+			var docLinkStart = response.indexOf("<td>", distanceEnd);
+			var docLinkEnd = response.indexOf("</td>", docLinkStart);
+			
+			var dist = response.substring(distanceStart + 4, distanceEnd);
+			var docLink = response.substring(docLinkStart + 4, docLinkEnd);
+
+			_nearbyDocs.push({title:docLink, distance:dist, lat:lats[i], lng:lngs[i++]});
+			
+			index = docLinkEnd;
+		}
+		
+		sortByDistance();
+		
+		var toggle = $("#nearbyDocumentsToggle");
+		toggle.attr("src", gs.imageURLs.collapse);
+		gs.functions.makeToggle(toggle, $("#nearbyDocuments"));
+	});
 }
 
@@ -596,5 +573,5 @@
 	sortedTable += "</table>";
 	
-	document.getElementById("nearbyDocuments").innerHTML = sortedTable;
+	$("#nearbyDocuments").html(sortedTable);
 }
 
@@ -618,5 +595,5 @@
 	sortedTable += "</table>";
 	
-	document.getElementById("nearbyDocuments").innerHTML = sortedTable;
+	$("#nearbyDocuments").html(sortedTable);
 }
 
@@ -646,6 +623,6 @@
 	toggleSection = function(sectionID)
 	{
-		var section = document.getElementById("div" + sectionID);
-		var sectionToggle = document.getElementById("toggle" + sectionID);
+		var section = gs.jqGet("div" + sectionID);
+		var sectionToggle = gs.jqGet("toggle" + sectionID);
 		
 		if(sectionToggle == undefined)
@@ -658,6 +635,6 @@
 			if(isExpanded(sectionID))
 			{
-				section.style.display = "none";
-				sectionToggle.setAttribute("src", gs.imageURLs.expand);
+				section.css("display", "none");
+				sectionToggle.attr("src", gs.imageURLs.expand);
 				
 				if(openClassifiers[sectionID] != undefined)
@@ -668,6 +645,6 @@
 			else
 			{
-				section.style.display = "block";
-				sectionToggle.setAttribute("src", gs.imageURLs.collapse);
+				section.css("display", "block");
+				sectionToggle.attr("src", gs.imageURLs.collapse);
 				openClassifiers[sectionID] = true;	
 			}
@@ -686,8 +663,7 @@
 		{
 			inProgress[sectionID] = true;
-			var httpRequest = new gs.functions.ajaxRequest();
-			
-			var sectionToggle = document.getElementById("toggle" + sectionID);
-			sectionToggle.setAttribute("src", gs.imageURLs.loading);
+			
+			var sectionToggle = gs.jqGet("toggle" + sectionID);
+			sectionToggle.attr("src", gs.imageURLs.loading);
 
 			var url = gs.xsltParams.library_name + "/collection/" + gs.cgiParams.c + "/browse/" + sectionID.replace(/\./g, "/") + "?excerptid=div" + sectionID;
@@ -702,44 +678,33 @@
 				url = url.substring(0, url.indexOf("#"));
 			}
-			httpRequest.open('GET', url, true);
-			httpRequest.onreadystatechange = function() 
-			{
-				if (httpRequest.readyState == 4) 
+			
+			$.ajax(url)
+			.success(function(responseText)
+			{
+				var newDiv = $("<div>");										
+				var sibling = gs.jqGet("title" + sectionID);
+				sibling.before(newDiv);
+				
+				newDiv.html(responseText);
+				sectionToggle.attr("src", gs.imageURLs.collapse);
+				openClassifiers[sectionID] = true;	
+				
+				if(gs.cgiParams.berryBasket == "on")
 				{
-					if (httpRequest.status == 200) 
-					{
-						var newDiv = document.createElement("div");										
-						var sibling = document.getElementById("title" + sectionID);
-						var parent = sibling.parentNode;
-						if(sibling.nextSibling)
-						{
-							parent.insertBefore(newDiv, sibling.nextSibling);
-						}
-						else
-						{
-							parent.appendChild(newDiv);
-						}
-						
-						newDiv.innerHTML = httpRequest.responseText;
-						sectionToggle.setAttribute("src", gs.imageURLs.collapse);
-						openClassifiers[sectionID] = true;	
-						
-						if(gs.cgiParams.berryBasket == "on")
-						{
-							checkout();
-						}
-						updateOpenClassifiers();
-						getSubClassifier(sectionID);
-					}
-					else
-					{
-						sectionToggle.setAttribute("src", gs.imageURLs.expand);
-					}
-					inProgress[sectionID] = false;
-					busy = false;
+					checkout();
 				}
-			}
-			httpRequest.send();
-		}
-	}
-}
+				updateOpenClassifiers();
+				getSubClassifier(sectionID);
+			})
+			.error(function()
+			{
+				sectionToggle.attr("src", gs.imageURLs.expand);
+			})
+			.complete(function()
+			{
+				inProgress[sectionID] = false;
+				busy = false;
+			});
+		}
+	}
+}
