Index: main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml
===================================================================
--- main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml	(revision 24893)
+++ main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml	(revision 24945)
@@ -1,117 +1,137 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <CollectionConfig xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-<metadataList><metadata lang="en" name="creator"></metadata><metadata lang="en" name="maintainer"></metadata><metadata lang="en" name="public">true</metadata></metadataList><displayItemList><displayItem assigned="true" lang="en" name="name">Pei-Jones-Flat</displayItem></displayItemList><search type="mgpp"><level name="document"><displayItem lang="en" name="name">document</displayItem></level><level name="section"><displayItem lang="en" name="name">section</displayItem></level><defaultLevel name="section"/><index name="text"><displayItem lang="en" name="name">text</displayItem></index><index name="Title"><displayItem lang="en" name="name">titles</displayItem></index><index name="Source"><displayItem lang="en" name="name">filenames</displayItem></index><index name="Plugin"/><defaultIndex name="text"/><indexOption><option name="accentfold"/><option name="casefold"/><option name="stem"/></indexOption><searchType name="plain"/><searchType name="simpleform"/><searchType name="advancedform"/><format><gsf:template match="documentNode"><td valign="top"><gsf:link type="document"><gsf:icon type="document"/></gsf:link></td><td><gsf:switch><gsf:metadata name="Title" select="ancestors" separator=": "/><gsf:when test="exists"><gsf:metadata name="Title" select="ancestors" separator=": "/>:</gsf:when></gsf:switch><gsf:link type="document"><gsf:metadata name="Title"/></gsf:link></td></gsf:template> </format></search><infodb type="gdbm"/><import><pluginList><plugin name="ZIPPlugin"/><plugin name="GreenstoneXMLPlugin"/><plugin name="TextPlugin"/><plugin name="HTMLPlugin"><option name="-process_exp" value="(timeglider.*)(?i)(\.html?)$"/><option name="-block_exp" value="(timeglider.*)(?i)(\.jpe?g|\.png|\.gif)$"/><option name="-keep_head"/></plugin><plugin name="EmailPlugin"/><plugin name="PDFPlugin"/><plugin name="RTFPlugin"/><plugin name="WordPlugin"/><plugin name="PostScriptPlugin"/><plugin name="PowerPointPlugin"/><plugin name="ExcelPlugin"/><plugin name="PagedImagePlugin"/><plugin name="ImagePlugin"/><plugin name="ISISPlugin"/><plugin name="NulPlugin"/><plugin name="OAIPlugin"/><plugin name="HTMLImagePlugin"/><plugin name="MetadataXMLPlugin"/><plugin name="ArchivesInfPlugin"/><plugin name="DirectoryPlugin"/></pluginList></import><browse><classifier name="List"><option name="-metadata" value="dc.Title;Title"/><option name="-partition_type_within_level" value="approximate_size"/><option name="-bookshelf_type" value="never"/></classifier><classifier name="AZCompactList"><option name="-metadata" value="Source"/><option name="-removesuffix" value="(?i)\\..*"/><option name="-buttonname" value="Source"/></classifier><format>
-			<gsf:template match="documentNode">
-				<td valign="top">
-					<gsf:link type="document">
-						<gsf:icon type="document"/>
-					</gsf:link>
-				</td>
-				<td valign="top">
-					<gsf:link type="source">
-						<gsf:choose-metadata>
-							<gsf:metadata name="thumbicon"/>
-							<gsf:metadata name="srcicon"/>
-						</gsf:choose-metadata>
-					</gsf:link>
-				</td>
-				<td valign="top">
-					<gsf:choose-metadata>
-						<gsf:metadata name="dc.Title"/>
-						<gsf:metadata name="exp.Title"/>
-						<gsf:metadata name="Title"/>
-						<gsf:default>Untitled</gsf:default>
-					</gsf:choose-metadata>
-					<gsf:switch>
-						<gsf:metadata name="Source"/>
-						<gsf:when test="exists">
-							<br/><i>(<gsf:metadata name="Source"/>)</i>
-						</gsf:when>
-					</gsf:switch>
-				</td>
-			</gsf:template>
-			
-			<gsf:template match="classifierNode">
-				<td valign="top">
-					<gsf:link type="classifier">
-						<gsf:icon type="classifier"/>
-					</gsf:link>
-				</td>
-				<td valign="top">
-					<gsf:metadata name="srclink"/>
-					<gsf:choose-metadata>
-						<gsf:metadata name="thumbicon"/>
-						<gsf:metadata name="srcicon"/>
-					</gsf:choose-metadata>
-					<gsf:metadata name="/srclink"/>
-				</td>
-				<td valign="top">
-					<gsf:choose-metadata>
-						<gsf:metadata name="dc.Title"/>
-						<gsf:metadata name="exp.Title"/>
-						<gsf:metadata name="Title"/>
-						<gsf:default>Untitled</gsf:default>
-					</gsf:choose-metadata>
-					<gsf:switch>
-						<gsf:metadata name="Source"/>
-						<gsf:when test="exists">
-							<br/><i>(<gsf:metadata name="Source"/>)</i>
-						</gsf:when>
-					</gsf:switch>
-				</td>
-			</gsf:template>
-			
-			<gsf:template match="classifierNode" mode="horizontal">
-				<gsf:link type="horizontal">
-					<gsf:metadata name="Title"/>
-				</gsf:link>
-			</gsf:template>
-		</format></browse><display><format>
-			<gsf:option name="sideBar" value="false"/>
-			<xsl:template name="additionalHeaderContent">
-				<!-- jQuery must be included before Annotator -->
-				<script src="sites/localsite/collect/peijones/js/annotator/lib/vendor/jquery.js"><xsl:text> </xsl:text></script>
-
-				<!-- If you're sure your users will only be using browsers modern
+<metadataList><metadata lang="en" name="creator"></metadata><metadata lang="en" name="maintainer"></metadata><metadata lang="en" name="public">true</metadata></metadataList><displayItemList><displayItem assigned="true" lang="en" name="name">Pei-Jones-Flat</displayItem></displayItemList><search type="mgpp"><level name="document"><displayItem lang="en" name="name">document</displayItem></level><level name="section"><displayItem lang="en" name="name">section</displayItem></level><defaultLevel name="document"/><index name="text"><displayItem lang="en" name="name">text</displayItem></index><index name="Title"><displayItem lang="en" name="name">titles</displayItem></index><index name="Source"><displayItem lang="en" name="name">filenames</displayItem></index><index name="Plugin"/><index name="gsimg.photoNote"><displayItem lang="en" name="name">photo annotations</displayItem></index><index name="gstext.tags"><displayItem lang="en" name="name">text annotations (tags)</displayItem></index><index name="gstext.text"><displayItem lang="en" name="name">text annotations (text)</displayItem></index><index name="gstext.user"><displayItem lang="en" name="name">text annotations (user)</displayItem></index><defaultIndex name="text"/><indexOption><option name="accentfold"/><option name="casefold"/><option name="stem"/></indexOption><searchType name="plain"/><searchType name="simpleform"/><searchType name="advancedform"/><format>
+      <gsf:template match="documentNode">
+        <td valign="top">
+          <gsf:link type="document">
+            <gsf:icon type="document"/>
+          </gsf:link>
+        </td>
+        <td>
+          <gsf:switch>
+            <gsf:metadata name="Title" select="ancestors" separator=": "/>
+            <gsf:when test="exists"><gsf:metadata name="Title" select="ancestors" separator=": "/>:</gsf:when>
+          </gsf:switch>
+          <gsf:link type="document">
+            <gsf:metadata name="Title"/>
+          </gsf:link>
+        </td>
+      </gsf:template>
+    </format></search><infodb type="gdbm"/><import><pluginList><plugin name="ZIPPlugin"/><plugin name="GreenstoneXMLPlugin"/><plugin name="TextPlugin"/><plugin name="HTMLPlugin"><option name="-process_exp" value="(timeglider.*)(?i)(\.html?)$"/><option name="-block_exp" value="(timeglider.*)(?i)(\.jpe?g|\.png|\.gif)$"/><option name="-keep_head"/></plugin><plugin name="EmailPlugin"/><plugin name="PDFPlugin"/><plugin name="RTFPlugin"/><plugin name="WordPlugin"/><plugin name="PostScriptPlugin"/><plugin name="PowerPointPlugin"/><plugin name="ExcelPlugin"/><plugin name="PagedImagePlugin"/><plugin name="ImagePlugin"/><plugin name="ISISPlugin"/><plugin name="NulPlugin"/><plugin name="OAIPlugin"/><plugin name="HTMLImagePlugin"/><plugin name="MetadataXMLPlugin"/><plugin name="ArchivesInfPlugin"/><plugin name="DirectoryPlugin"/></pluginList></import><browse><classifier name="List"><option name="-metadata" value="dc.Title;Title"/><option name="-partition_type_within_level" value="approximate_size"/><option name="-bookshelf_type" value="never"/></classifier><classifier name="AZCompactList"><option name="-metadata" value="Source"/><option name="-removesuffix" value="(?i)\\..*"/><option name="-buttonname" value="Source"/></classifier><format>
+      <gsf:template match="documentNode">
+        <td valign="top">
+          <gsf:link type="document">
+            <gsf:icon type="document"/>
+          </gsf:link>
+        </td>
+        <td valign="top">
+          <gsf:link type="source">
+            <gsf:choose-metadata>
+              <gsf:metadata name="thumbicon"/>
+              <gsf:metadata name="srcicon"/>
+            </gsf:choose-metadata>
+          </gsf:link>
+        </td>
+        <td valign="top">
+          <gsf:choose-metadata>
+            <gsf:metadata name="dc.Title"/>
+            <gsf:metadata name="exp.Title"/>
+            <gsf:metadata name="Title"/>
+            <gsf:default>Untitled</gsf:default>
+          </gsf:choose-metadata>
+          <gsf:switch>
+            <gsf:metadata name="Source"/>
+            <gsf:when test="exists">
+              <br/>
+              <i>(<gsf:metadata name="Source"/>)</i>
+            </gsf:when>
+          </gsf:switch>
+        </td>
+      </gsf:template>
+      <gsf:template match="classifierNode">
+        <td valign="top">
+          <gsf:link type="classifier">
+            <gsf:icon type="classifier"/>
+          </gsf:link>
+        </td>
+        <td valign="top">
+          <gsf:metadata name="srclink"/>
+          <gsf:choose-metadata>
+            <gsf:metadata name="thumbicon"/>
+            <gsf:metadata name="srcicon"/>
+          </gsf:choose-metadata>
+          <gsf:metadata name="/srclink"/>
+        </td>
+        <td valign="top">
+          <gsf:choose-metadata>
+            <gsf:metadata name="dc.Title"/>
+            <gsf:metadata name="exp.Title"/>
+            <gsf:metadata name="Title"/>
+            <gsf:default>Untitled</gsf:default>
+          </gsf:choose-metadata>
+          <gsf:switch>
+            <gsf:metadata name="Source"/>
+            <gsf:when test="exists">
+              <br/>
+              <i>(<gsf:metadata name="Source"/>)</i>
+            </gsf:when>
+          </gsf:switch>
+        </td>
+      </gsf:template>
+      <gsf:template match="classifierNode" mode="horizontal">
+        <gsf:link type="horizontal">
+          <gsf:metadata name="Title"/>
+        </gsf:link>
+      </gsf:template>
+    </format></browse><display><format>
+      <gsf:option name="sideBar" value="false"/>
+      <xsl:template name="additionalHeaderContent">
+        <!-- jQuery must be included before Annotator -->
+        <script src="sites/localsite/collect/peijones/js/annotator/lib/vendor/jquery.js">
+          <xsl:text> </xsl:text>
+        </script>
+        <!-- If you're sure your users will only be using browsers modern
 					 enough to have their own JSON.parse and JSON.stringify
 					 implementations you can skip this -->
-				<script src="sites/localsite/collect/peijones/js/annotator/lib/vendor/json2.js"><xsl:text> </xsl:text></script>
-
-				<script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator-full.min.js"><xsl:text> </xsl:text></script>
-				<!-- The main Annotator script -->
-				<!--<script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.min.js"><xsl:text> </xsl:text></script> -->
-
-				<!-- Annotator's styling and images -->
-				<link href="sites/localsite/collect/peijones/js/annotator/pkg/annotator.min.css" rel="stylesheet" type="text/css"/>
-
-				<!-- The following plugins are entirely optional -->
-
-				<!-- The Store plugin. Saves annotations to a remote backend -->
-				<!-- <script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.store.min.js"><xsl:text> </xsl:text></script> -->
-
-				<!-- The Auth plugin. Allows users of Annotator to authenticate themselves
+        <script src="sites/localsite/collect/peijones/js/annotator/lib/vendor/json2.js">
+          <xsl:text> </xsl:text>
+        </script>
+        <script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator-full.min.js">
+          <xsl:text> </xsl:text>
+        </script>
+        <!-- The main Annotator script -->
+        <!--<script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.min.js"><xsl:text> </xsl:text></script> -->
+        <!-- Annotator's styling and images -->
+        <link href="sites/localsite/collect/peijones/js/annotator/pkg/annotator.min.css" rel="stylesheet" type="text/css"/>
+        <!-- The following plugins are entirely optional -->
+        <!-- The Store plugin. Saves annotations to a remote backend -->
+        <!-- <script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.store.min.js"><xsl:text> </xsl:text></script> -->
+        <!-- The Auth plugin. Allows users of Annotator to authenticate themselves
 					 to the remote backend -->
-				<!--<script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.auth.min.js"><xsl:text> </xsl:text></script> -->
-				<!-- The Permissions plugin. See who created which annotation and create
+        <!--<script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.auth.min.js"><xsl:text> </xsl:text></script> -->
+        <!-- The Permissions plugin. See who created which annotation and create
 					 annotations as a specified user -->
-				<!--<script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.permissions.min.js"><xsl:text> </xsl:text></script> -->
-
-				<!-- The Tags plugin. Edit and display tag keywords on annotations -->
-				<!--<script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.tags.min.js"><xsl:text> </xsl:text></script> -->
-
-				<!-- The Markdown plugin. Treat annotation text as Markdown -->
-				<!-- <script src="sites/localsite/collect/peijones/js/annotator/lib/vendor/showdown.js"><xsl:text> </xsl:text></script> -->
-				<!-- <script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.markdown.min.js"><xsl:text> </xsl:text></script> --> 
-				
-				<!-- Photo note scripts -->
-				<script src="sites/localsite/collect/peijones/js/documentmaker/BrowserDetect.js" type="text/javascript"><xsl:text> </xsl:text></script>
-				<script src="sites/localsite/collect/peijones/js/documentmaker/PhotoNotes-1.5.js" type="text/javascript"><xsl:text> </xsl:text></script>
-				<link href="sites/localsite/collect/peijones/style/PhotoNotes-1.5.css" rel="stylesheet" type="text/css"/>
-				
-				<!-- Zoom scripts -->
-				<!--<script src="interfaces/{$interface_name}/js/jquery-1.4.2.js" type="text/javascript"><xsl:text> </xsl:text></script>-->
-				<script src="sites/localsite/collect/peijones/js/documentmaker/zoomer.jquery.js" type="text/javascript"><xsl:text> </xsl:text></script>    <link href="sites/localsite/collect/peijones/style/style.css" rel="stylesheet" type="text/css"/>
-				<script type="text/javascript">
-					<xsl:text disable-output-escaping="yes">
+        <!--<script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.permissions.min.js"><xsl:text> </xsl:text></script> -->
+        <!-- The Tags plugin. Edit and display tag keywords on annotations -->
+        <!--<script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.tags.min.js"><xsl:text> </xsl:text></script> -->
+        <!-- The Markdown plugin. Treat annotation text as Markdown -->
+        <!-- <script src="sites/localsite/collect/peijones/js/annotator/lib/vendor/showdown.js"><xsl:text> </xsl:text></script> -->
+        <!-- <script src="sites/localsite/collect/peijones/js/annotator/pkg/annotator.markdown.min.js"><xsl:text> </xsl:text></script> -->
+        <!-- Photo note scripts -->
+        <script src="sites/localsite/collect/peijones/js/documentmaker/BrowserDetect.js" type="text/javascript">
+          <xsl:text> </xsl:text>
+        </script>
+        <script src="sites/localsite/collect/peijones/js/documentmaker/PhotoNotes-1.5.js" type="text/javascript">
+          <xsl:text> </xsl:text>
+        </script>
+        <link href="sites/localsite/collect/peijones/style/PhotoNotes-1.5.css" rel="stylesheet" type="text/css"/>
+        <!-- Zoom scripts -->
+        <!--<script src="interfaces/{$interface_name}/js/jquery-1.4.2.js" type="text/javascript"><xsl:text> </xsl:text></script>-->
+        <script src="sites/localsite/collect/peijones/js/documentmaker/zoomer.jquery.js" type="text/javascript">
+          <xsl:text> </xsl:text>
+        </script>
+        <link href="sites/localsite/collect/peijones/style/style.css" rel="stylesheet" type="text/css"/>
+        <script type="text/javascript">
+          <xsl:text disable-output-escaping="yes">
 						_zoomEnabled = true;
 						function readyImagesForZoom()      
@@ -184,8 +204,8 @@
 							}
 						}    
-					</xsl:text>    
-				</script>
-				<script text="text/javascript">
-					<xsl:text disable-output-escaping="yes">
+					</xsl:text>
+        </script>
+        <script text="text/javascript">
+          <xsl:text disable-output-escaping="yes">
 						
 						var _posCount = 0;
@@ -236,20 +256,20 @@
 						function saveFunction(note)
 						{
-							var callback = 
-							{
-								success: function(response)
-								{
-									var updateURL = gs.siteMetadata.siteURL.replace("8080","9090") + gs.xsltParams.library_name + "?a=s&amp;sa=c";
-								
-									var updateCallback = 
-									{
-										success: function(response){},
-										failed: function(reponse){ alert("Failed in saveFunction() to update Greenstone server with: " + updateURL);}
-									};
-									
-									
-									YAHOO.util.Connect.asyncRequest("GET", updateURL, updateCallback);
-								},
-								failed: function(reponse){ alert("Failed in saveFunction() with note id: " + note.id)},
+							var saveIndexCallback = 
+							{
+								success: function(response){},
+								failed: function(reponse){ alert("Failed to save index metadata of note with id: " + note.id)},
+							};
+							
+							var saveArchivesCallback = 
+							{
+								success: function(response){buildFunction(gs.cgiParams.c);},
+								failed: function(response){ alert("Failed in save import metadata of note with id: " + note.id) }
+							};
+							
+							var saveImportCallback = 
+							{
+								success: function(response){},
+								failed: function(response){ alert("Failed in save import metadata of note with id: " + note.id) }
 							};
 							
@@ -257,6 +277,10 @@
 							var metaposStr = (note &amp;&amp; note.id &amp;&amp; note.id &gt; 0) ? note.id - 1 : _posCount;
 							
-							var saveURL = gs.siteMetadata.siteURL.replace("8080","9090") + "cgi-bin/metadata-server.pl?a=set-metadata&amp;site=localsite&amp;c=" + gs.cgiParams.c + "&amp;d=" + gs.cgiParams.d + "&amp;metaname=gsimg.photoNote&amp;metavalue=" + jsonVal + "&amp;metapos=" + metaposStr;
-							YAHOO.util.Connect.asyncRequest("GET", saveURL, callback);
+							var saveIndexURL = gs.siteMetadata.siteURL.replace("8080","9090") + "cgi-bin/metadata-server.pl?a=set-metadata&amp;site=localsite&amp;c=" + gs.cgiParams.c + "&amp;d=" + gs.cgiParams.d + "&amp;metaname=gsimg.photoNote&amp;metavalue=" + jsonVal + "&amp;metapos=" + metaposStr;
+							var saveArchivesURL = gs.siteMetadata.siteURL.replace("8080","9090") + "cgi-bin/metadata-server.pl?a=set-archives-metadata&amp;site=localsite&amp;c=" + gs.cgiParams.c + "&amp;d=" + gs.cgiParams.d + "&amp;metaname=gsimg.photoNote&amp;metavalue=" + jsonVal + "&amp;metapos=" + metaposStr;
+							var saveImportURL = gs.siteMetadata.siteURL.replace("8080","9090") + "cgi-bin/metadata-server.pl?a=set-import-metadata&amp;site=localsite&amp;c=" + gs.cgiParams.c + "&amp;d=" + gs.cgiParams.d + "&amp;metaname=gsimg.photoNote&amp;metavalue=" + jsonVal + "&amp;metapos=" + metaposStr;
+							YAHOO.util.Connect.asyncRequest("GET", saveIndexURL, saveIndexCallback);
+							YAHOO.util.Connect.asyncRequest("GET", saveArchivesURL, saveArchivesCallback);
+							YAHOO.util.Connect.asyncRequest("GET", saveImportURL, saveImportCallback);
 							
 							return 1;
@@ -315,10 +339,175 @@
 						window.onload = function(){initNotes(); readyImagesForZoom(); initAnnotator();};
 					</xsl:text>
-				</script>
+        </script>
+        <script text="text/javascript">
+          <xsl:text disable-output-escaping="yes">
+			
+			function checkLoop(pid, serverFunction, callback)
+			{
+				var startLoop = function()
+				{
+					var loopCallback = 
+					{
+						success:function(response)
+						{
+							var checkText = response.responseText;
+							if(checkText == null || checkText == "")
+							{
+								console.log("There was an error getting the XML to check the status of " + serverFunction);
+							}
+							else
+							{
+								var checkCodeStart = checkText.indexOf("code=\"") + 6;
+								var checkCodeEnd = checkText.indexOf("\"", checkCodeStart);
+								var code = checkText.substring(checkCodeStart, checkCodeEnd);
+								
+								if(code == 11 || code == 1) //11 is COMPLETED, 1 is success
+								{
+									callback();
+								}
+								else if(code == 12 || code == 3) //12 is HALTED, 3 is ERROR 
+								{
+									console.log("There was an error on the server, could not check status of " + serverFunction);
+								}
+								else
+								{
+									setTimeout(startLoop, 1000);
+								}
+							}
+						},
+						failed:function()
+						{
+							console.log("There was a problem checking the status of " + serverFunction)
+						}
+					}
+					YAHOO.util.Connect.asyncRequest("GET", gs.xsltParams.library_name + "?a=g&amp;rt=s&amp;ro=1&amp;s=" + serverFunction + "&amp;s1.pid=" + pid, loopCallback);
+				}
+				startLoop();
+			}
+		
+			function buildFunction(collection)
+			{
+				var buildCallback = 
+				{
+					success:function(response)
+					{
+						var buildText = response.responseText;
+						if(buildText == null || buildText == "")
+						{
+							console.log("There was an error getting the xml response from the building request");
+						}
+						else
+						{
+							var buildPIDStart = buildText.indexOf("pid=\"") + 5;
+							var buildPIDEnd = buildText.indexOf("\"", buildPIDStart);
+							var buildPID = buildText.substring(buildPIDStart, buildPIDEnd);
+							
+							checkLoop(buildPID, "BuildCollection", function()
+							{
+								var activateCallback = 
+								{
+									success: function(response)
+									{
+										var activateText = response.responseText;
+										if(activateText == null || activateText == "")
+										{
+											console.log("There was an error getting the xml response from the activating request");
+										}
+										else
+										{
+											var activatePIDStart = activateText.indexOf("pid=\"") + 5;
+											var activatePIDEnd = activateText.indexOf("\"", activatePIDStart);
+											var activatePID = activateText.substring(activatePIDStart, activatePIDEnd);
+											
+											checkLoop(activatePID, "ActivateCollection", function()
+											{
+												var updateCallback = 
+												{
+													success: function(response){},
+													failed: function(reponse){ alert("Failed in saveFunction() to re-read config files");}
+												};
+												YAHOO.util.Connect.asyncRequest("GET", gs.xsltParams.library_name + "?a=s&amp;sa=c", updateCallback);
+											});
+										}
+									},
+									failed: function(response)
+									{
+										console.log("Failed to get response from activate collection request");
+									}
+								}
+								YAHOO.util.Connect.asyncRequest("GET", gs.xsltParams.library_name + "?a=g&amp;rt=r&amp;ro=1&amp;s=ActivateCollection&amp;s1.collection=" + collection, activateCallback);
+							});
+						}
+					},
+					failed: function(){console.log("Failed to get build collection response")}
+				}
 				
-				<script text="text/javascript">
-					<xsl:text disable-output-escaping="yes">
+				YAHOO.util.Connect.asyncRequest("GET", gs.xsltParams.library_name + "?a=g&amp;rt=r&amp;ro=1&amp;s=BuildCollection&amp;s1.collection=" + collection, buildCallback);
+			}
+			
+			function saveAndBuildCollection(col)
+			{			
+				var json = "[";
+				for(var i = 0; i &lt; gs.annotationArray.keys.length; i++)
+				{
+					var current = gs.annotationArray[gs.annotationArray.keys[i]];
+					var metaToAdd = ["user", "text", "tags"];
+					
+					for(var j = 0; j &lt; metaToAdd.length; j++)
+					{
+						if(metaToAdd[j] == "user")
+						{
+							json += '{"docid":"' + gs.cgiParams.d + '", "metaname":"gstext.' + metaToAdd[j] + '", "metavalue":"' + current.user.name + '"}';
+						}
+						else
+						{
+							json += '{"docid":"' + gs.cgiParams.d + '", "metaname":"gstext.' + metaToAdd[j] + '", "metavalue":"' + current[metaToAdd[j]] + '"}';
+						}
+						
+						if(j != (metaToAdd.length - 1) || i != (gs.annotationArray.keys.length - 1))
+						{
+							json += ',';
+						}
+					}
+				}
+				json += "]";
+				
+				var saveArchivesURL = "cgi-bin/metadata-server.pl?a=set-archives-metadata-array&amp;c=" + gs.cgiParams.c + "&amp;site=localsite&amp;collect=" + gs.cgiParams.c + "&amp;json=" + json;
+				var saveIndexURL = "cgi-bin/metadata-server.pl?a=set-metadata-array&amp;c=" + gs.cgiParams.c + "&amp;site=localsite&amp;collect=" + gs.cgiParams.c + "&amp;json=" + json;
+				var saveImportURL = "cgi-bin/metadata-server.pl?a=set-import-metadata-array&amp;c=" + gs.cgiParams.c + "&amp;site=localsite&amp;collect=" + gs.cgiParams.c + "&amp;json=" + json; //FIX THIS
+				
+				var saveArchivesCallback = 
+				{
+					success:function(){console.log("Away to build"); buildFunction(gs.cgiParams.c);},
+					failed: function(){alert("Failed to save text annotations index metadata");}
+				}
+				YAHOO.util.Connect.asyncRequest("GET", saveArchivesURL, saveArchivesCallback);
+				
+				var saveIndexCallback =
+				{
+					success:function(){},
+					failed: function(){alert("Failed to save text annotations import metadata");}
+				}
+				YAHOO.util.Connect.asyncRequest("GET", saveIndexURL, saveIndexCallback);
+				
+				var saveImportCallback =
+				{
+					success:function(){},
+					failed: function(){alert("Failed to save text annotations import metadata");}
+				}
+				YAHOO.util.Connect.asyncRequest("GET", saveImportURL, saveImportCallback);
+			}
+					
 						function initAnnotator()
 						{		
+							gs.annotationArray = new Array();
+							gs.annotationArray.keys = new Array();
+							
+							var elem = document.getElementById("gs-document-text");
+							elem.innerHTML = '&lt;button id="saveButton"&gt;Save annotations&lt;/button&gt;&lt;br/&gt;' + elem.innerHTML;
+							
+							var button = document.getElementById("saveButton");
+							button.onclick = function(){saveAndBuildCollection(gs.cgiParams.c);};
+							
 							jQuery(function ($) {
 								if (typeof $.fn.annotator !== 'function') {
@@ -358,102 +547,103 @@
 						}
 					</xsl:text>
-				</script>
-			</xsl:template>
-			
-			<xsl:template name="documentImage">
-				<!-- Get the photo notes for this document node -->
-				<gsf:variable-struct name="photoNotes">
-					<gsf:metadata multiple="true" name="gsimg.photoNote" separator=", "/>
-				</gsf:variable-struct>
-				
-				<!-- Get details about the image for zooming -->
-				<h3>   
-					<gsf:choose-metadata>
-						<gsf:metadata name="dc.Title"/>
-						<gsf:metadata name="ex.Title"/>
-					</gsf:choose-metadata>
-				</h3>
-				<xsl:variable name="imageWidth">
-					<gsf:choose-metadata>
-						<gsf:metadata name="ImageWidth"/> 
-						<gsf:default>-1</gsf:default>  						
-					</gsf:choose-metadata>
-				</xsl:variable>
-				<xsl:variable name="imageHeight">
-					<gsf:choose-metadata>
-						<gsf:metadata name="ImageHeight"/> 
-						<gsf:default>-1</gsf:default>  						
-					</gsf:choose-metadata>
-				</xsl:variable>
-				<xsl:variable name="screenImageWidth">
-					<gsf:choose-metadata>
-						<gsf:metadata name="ScreenWidth"/> 
-						<gsf:default>-1</gsf:default>  						
-					</gsf:choose-metadata>
-				</xsl:variable>
-				<xsl:variable name="screenImageHeight">
-					<gsf:choose-metadata>
-						<gsf:metadata name="ScreenHeight"/> 
-						<gsf:default>-1</gsf:default>  						
-					</gsf:choose-metadata>
-				</xsl:variable>
-				<script type="text/javascript">
-					<xsl:text>largeImageHeight =</xsl:text><xsl:value-of select="$imageHeight"/><xsl:text>;</xsl:text>
-					<xsl:text>largeImageWidth =</xsl:text><xsl:value-of select="$imageWidth"/><xsl:text>;</xsl:text>
-					<xsl:text>smallImageHeight =</xsl:text><xsl:value-of select="$screenImageHeight"/><xsl:text>;</xsl:text>
-					<xsl:text>smallImageWidth =</xsl:text><xsl:value-of select="$screenImageWidth"/><xsl:text>;</xsl:text>
-				</script>
-				<div id="noZoom" style="display:block;">
-					<img style="width: {$screenImageWidth}; height: {$screenImageHeight};">
-									<xsl:attribute name="src">
-										<xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>/index/assoc/<gsf:metadata name="assocfilepath" select="root"/>/<gsf:metadata name="Screen"/>
-									</xsl:attribute>
-					</img>
-						<!--		
+        </script>
+      </xsl:template>
+      <xsl:template name="documentImage">
+        <!-- Get the photo notes for this document node -->
+        <gsf:variable-struct name="photoNotes">
+          <gsf:metadata multiple="true" name="gsimg.photoNote" separator=", "/>
+        </gsf:variable-struct>
+        <!-- Get details about the image for zooming -->
+        <h3>
+          <gsf:choose-metadata>
+            <gsf:metadata name="dc.Title"/>
+            <gsf:metadata name="ex.Title"/>
+          </gsf:choose-metadata>
+        </h3>
+        <xsl:variable name="imageWidth">
+          <gsf:choose-metadata>
+            <gsf:metadata name="ImageWidth"/>
+            <gsf:default>-1</gsf:default>
+          </gsf:choose-metadata>
+        </xsl:variable>
+        <xsl:variable name="imageHeight">
+          <gsf:choose-metadata>
+            <gsf:metadata name="ImageHeight"/>
+            <gsf:default>-1</gsf:default>
+          </gsf:choose-metadata>
+        </xsl:variable>
+        <xsl:variable name="screenImageWidth">
+          <gsf:choose-metadata>
+            <gsf:metadata name="ScreenWidth"/>
+            <gsf:default>-1</gsf:default>
+          </gsf:choose-metadata>
+        </xsl:variable>
+        <xsl:variable name="screenImageHeight">
+          <gsf:choose-metadata>
+            <gsf:metadata name="ScreenHeight"/>
+            <gsf:default>-1</gsf:default>
+          </gsf:choose-metadata>
+        </xsl:variable>
+        <script type="text/javascript">
+          <xsl:text>largeImageHeight =</xsl:text>
+          <xsl:value-of select="$imageHeight"/>
+          <xsl:text>;</xsl:text>
+          <xsl:text>largeImageWidth =</xsl:text>
+          <xsl:value-of select="$imageWidth"/>
+          <xsl:text>;</xsl:text>
+          <xsl:text>smallImageHeight =</xsl:text>
+          <xsl:value-of select="$screenImageHeight"/>
+          <xsl:text>;</xsl:text>
+          <xsl:text>smallImageWidth =</xsl:text>
+          <xsl:value-of select="$screenImageWidth"/>
+          <xsl:text>;</xsl:text>
+        </script>
+        <div id="noZoom" style="display:block;">
+          <img style="width: {$screenImageWidth}; height: {$screenImageHeight};">
+            <xsl:attribute name="src"><xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>/index/assoc/<gsf:metadata name="assocfilepath" select="root"/>/<gsf:metadata name="Screen"/></xsl:attribute>
+          </img>
+          <!--		
 					<gsf:metadata name="screenicon"/>
 					-->
-				</div>
-				<!--<xsl:if test="$imageHeight != -1">-->
-					<div id="wrap" style="display:none; width: {$screenImageWidth}; height: {$screenImageHeight};">
-						<div id="small" style="width: {$screenImageWidth}; height: {$screenImageHeight};">
-						<!--
+        </div>
+        <!--<xsl:if test="$imageHeight != -1">-->
+        <div id="wrap" style="display:none; width: {$screenImageWidth}; height: {$screenImageHeight};">
+          <div id="small" style="width: {$screenImageWidth}; height: {$screenImageHeight};">
+            <!--
 							<gsf:metadata name="screenicon"/>
 							-->
-							<img style="width: {$screenImageWidth}; height: {$screenImageHeight};">
-									<xsl:attribute name="src">
-										<xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>/index/assoc/<gsf:metadata name="assocfilepath" select="root"/>/<gsf:metadata name="Screen"/>
-									</xsl:attribute>
-							</img>	
-						</div>
-						<div id="mover">
-							<div id="overlay"><xsl:text> </xsl:text></div>
-							<div id="large">
-								<img style="width: {$imageWidth}; height: {$imageHeight};">
-									<xsl:attribute name="src">
-										<xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>/index/assoc/<gsf:metadata name="assocfilepath" select="root"/>/<gsf:metadata name="srclinkFile"/>
-									</xsl:attribute>
-								</img>
-							</div>
-						</div>
-					</div>
-					<input onclick="AddNote();" style="margin-left:30px;" type="button" value="Tag Photo!"/>
-				<!--</xsl:if>-->
-			</xsl:template>
-			
-		</format></display><replaceListRef id="gs2-standard"/><replaceListRef id="gs2-image"/><serviceRackList>
-        <!-- comment out the following serviceRack if you want to disable OAI for this collection -->
-        <serviceRack name="OAIPMH">
-            <ListMetadataFormats>
-                <!--What metadata sets to support is collection specific. To support other metadata schema, simply add a metadataFormat element here.
+            <img style="width: {$screenImageWidth}; height: {$screenImageHeight};">
+              <xsl:attribute name="src"><xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>/index/assoc/<gsf:metadata name="assocfilepath" select="root"/>/<gsf:metadata name="Screen"/></xsl:attribute>
+            </img>
+          </div>
+          <div id="mover">
+            <div id="overlay">
+              <xsl:text> </xsl:text>
+            </div>
+            <div id="large">
+              <img style="width: {$imageWidth}; height: {$imageHeight};">
+                <xsl:attribute name="src"><xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/collection/metadataList/metadata[@name='httpPath']"/>/index/assoc/<gsf:metadata name="assocfilepath" select="root"/>/<gsf:metadata name="srclinkFile"/></xsl:attribute>
+              </img>
+            </div>
+          </div>
+        </div>
+        <input onclick="AddNote();" style="margin-left:30px;" type="button" value="Tag Photo!"/>
+        <!--</xsl:if>-->
+      </xsl:template>
+    </format></display><replaceListRef id="gs2-standard"/><replaceListRef id="gs2-image"/><serviceRackList>
+    <!-- comment out the following serviceRack if you want to disable OAI for this collection -->
+    <serviceRack name="OAIPMH">
+      <ListMetadataFormats>
+        <!--What metadata sets to support is collection specific. To support other metadata schema, simply add a metadataFormat element here.
 	The support of unqualified Dublin Core metadata set is mandatory in the oai specification.
 	-->
-                <metadataFormat metadataPrefix="oai_dc">
-                    <metadataPrefix>oai_dc</metadataPrefix>
-                    <schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</schema>
-                    <metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>
-                    <!--<metadataElements>dc.Title,dc.Creator,dc.Subject,dc.Description,dc.Publisher,dc.Contributor,dc.Date,dc.Type,dc.Format,dc.Identifier,dc.Source,dc.Language,dc.Relation,dc.Coverage,dc.Rights</metadataElements>              
+        <metadataFormat metadataPrefix="oai_dc">
+          <metadataPrefix>oai_dc</metadataPrefix>
+          <schema>http://www.openarchives.org/OAI/2.0/oai_dc.xsd</schema>
+          <metadataNamespace>http://www.openarchives.org/OAI/2.0/oai_dc/</metadataNamespace>
+          <!--<metadataElements>dc.Title,dc.Creator,dc.Subject,dc.Description,dc.Publisher,dc.Contributor,dc.Date,dc.Type,dc.Format,dc.Identifier,dc.Source,dc.Language,dc.Relation,dc.Coverage,dc.Rights</metadataElements>              
 	  -->
-                    <mappingList>
-                        <!-- 
+          <mappingList>
+            <!-- 
 	    The mapping is in the form: <publicly supported metadata name>,<mapped metadata name>, short as <A>,<B> 
 	    The first metadata name is medatory; if there is no mapped name followed, then the first name must be used by the records and
@@ -466,9 +656,9 @@
 	    **The only case when this mapping is not present is that: 1. this metadata format is oai_dc; 2. the metadata is also stored in the database by Dublin Core's names.
 	    -->
-                        <mapping>dc.Title,Title</mapping>
-                        <!-- This mapping example means that the dc.Title is requested and the value of the metadata Title, which is used in this repository, is returned as response. -->
-                    </mappingList>
-                </metadataFormat>
-            </ListMetadataFormats>
-        </serviceRack>
-    </serviceRackList></CollectionConfig>
+            <mapping>dc.Title,Title</mapping>
+            <!-- This mapping example means that the dc.Title is requested and the value of the metadata Title, which is used in this repository, is returned as response. -->
+          </mappingList>
+        </metadataFormat>
+      </ListMetadataFormats>
+    </serviceRack>
+  </serviceRackList></CollectionConfig>
