Index: main/trunk/greenstone2/web/script/gsajaxapi.js
===================================================================
--- main/trunk/greenstone2/web/script/gsajaxapi.js	(revision 23466)
+++ main/trunk/greenstone2/web/script/gsajaxapi.js	(revision 23740)
@@ -26,6 +26,16 @@
     }
 
-
-    this.urlGetAsync = function(url,locid)
+    this.indexserverURL = function()
+    {
+        return this.apiURL("index-server.pl");
+    }
+
+    this.explodeserverURL = function()
+    {
+        return this.apiURL("explode-server.pl");
+    }
+
+
+    this.urlGetAsync = function(url,callback)
     {
        var xmlHttp;
@@ -49,17 +59,32 @@
          }
        }
-    
-       xmlHttp.onreadystatechange=function() {
-         if(xmlHttp.readyState==4) {
-           if (locelem != null) {
-             var locelem = document.getElementById(locid);
-    
-             locelem.innerHTML = xmlHttp.responseText;
-           }
-         }
-       }
-    
-       xmlHttp.open("GET",url,true);
-       xmlHttp.send(null);
+
+	var typeof_callback = typeof(callback);
+	if ((typeof_callback == "string") || (typeof_callback == "number") || (typeof_callback == "boolean")) {
+	    var locid = callback;
+
+	    xmlHttp.onreadystatechange=function() {
+		if(xmlHttp.readyState==4) {
+		    if (locelem != null) {
+			var locelem = document.getElementById(locid);
+			
+			locelem.innerHTML = xmlHttp.responseText;
+		    }
+		}
+	    }
+	}
+	else if (typeof_callback == "function") {
+	    xmlHttp.onreadystatechange=function() {
+		if(xmlHttp.readyState==4) {
+		    callback(xmlHttp);
+		}
+	    }
+	}
+	else {
+	    alert("Unrecognized type of callback value: " + typeof_callback);
+	}
+
+	xmlHttp.open("GET",url,true);
+	xmlHttp.send(null);
     }
     
@@ -98,4 +123,5 @@
     }
     
+
     
     this.setLiveMetadata = function(id,metaname,metavalue)
@@ -114,49 +140,66 @@
     }
     
-	 this._setMetadata = function(mode,docid,metaname,metapos,metavalue,metamode)
-    {
-        var mdserver = this.metadataserverURL();
-    
-        var url = mdserver + "?a=set" + mode + "-metadata";
-        url += "&c="+collect_;
-        url += "&d="+docid;
-        url += "&metaname=" + metaname;
+    this._setMetadata = function(mode,docid,metaname,metapos,metavalue,metamode)
+    {
+        var mdserver = this.metadataserverURL();
+    
+        var params = "a=set" + mode + "-metadata";
+        params += "&c="+collect_;
+        params += "&d="+docid;
+        params += "&metaname=" + metaname;
         if (metapos!=null) {
-            url += "&metapos=" + metapos;
-        }
-        url += "&metavalue=" + metavalue;
-		if (metamode!=null) {
-            url += "&metamode=" + metamode;
-        }
-	// alert("url = " + url);
-    
-        this.urlGetSync(url);
+            params += "&metapos=" + metapos;
+        }
+        params += "&metavalue=" + metavalue;
+	if (metamode!=null) {
+            params += "&metamode=" + metamode;
+	}
+	// alert("params = " + params);
+	
+	//alert(mdserver + "?" + params);
+
+        this.urlGetSync(mdserver + "?" + params);
+        //this.urlPostSync(mdserver,params);
     }
     
     this.setDocumentMetadata = function(docid,metaname,metapos,metavalue)
     {
-		// Allow for three param call to function, where metapos is missed out
+	// Allow for three param call to function, where metapos is missed out
         if (metavalue==null) {
 	    // 4 param case
 	    metavalue = metapos;
 	    metapos = null;
-		}
-	
-		this._setMetadata("",docid,metaname,metapos,metavalue);
-		// this._setMetadata("-archives",docid,metaname,metapos,metavalue,"override");
-    }
-
-	 this.setNewDocumentMetadata = function(docid,metaname,metavalue)
-    {
-		this._setMetadata("",docid,metaname,null,metavalue);
-		this._setMetadata("-archives",docid,metaname,null,metavalue,"accumulate");
-    }
-	
-	this.setImportMetadata = function(docid,metaname,metapos,metavalue)
-    {
-		this._setMetadata("-import",docid,metaname,metapos,metavalue);
-    }
-	
-
+	}
+	
+	this._setMetadata("",docid,metaname,metapos,metavalue);
+	this._setMetadata("-archives",docid,metaname,metapos,metavalue,"override");
+    }
+
+    this.setNewDocumentMetadata = function(docid,metaname,metavalue)
+    {
+	this._setMetadata("",docid,metaname,null,metavalue);
+	this._setMetadata("-archives",docid,metaname,null,metavalue,"accumulate");
+    }
+	
+    this.setImportMetadata = function(docid,metaname,metapos,metavalue)
+    {
+	this._setMetadata("-import",docid,metaname,metapos,metavalue,"override");
+    }
+	
+
+    this.explodeDocument = function(docid)
+    {
+        var exserver = this.explodeserverURL();
+
+        var url = exserver + "?a=explode";
+        url += "&c="+collect_;
+        url += "&d="+docid;
+
+	// alert("url = " + url);
+	
+        this.urlGetSync(url);
+    }
+    
+    // consider name change to reindexDocument
     this.documentReindex = function(docid)
     {
@@ -171,5 +214,23 @@
         this.urlGetSync(url);
     }
-    
+
+
+    this.reindexCollection = function(mode,callback)
+    {
+        if (mode==null) {
+	    mode = "incremental";
+	}
+
+        var idserver = this.indexserverURL();
+    
+        var url = idserver + "?a=" + mode + "-rebuild";
+        url += "&c="+collect_;
+
+	// alert("url = " + url);
+    
+        this.urlGetAsync(url,callback);
+    }    
+    
+
     this.getLiveMetadata = function(id,metaname)
     {
