Index: main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml
===================================================================
--- main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml	(revision 24947)
+++ main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml	(revision 24948)
@@ -207,5 +207,5 @@
         </script>
         <script text="text/javascript">
-          <xsl:text disable-output-escaping="yes">
+			<xsl:text disable-output-escaping="yes">
 						
 						var _posCount = 0;
@@ -243,4 +243,5 @@
 											}
 										}
+										_posCount--;
 									},
 									failed: function(){alert("Failed to delete index metadata of note with id: " + note.id);},
@@ -358,5 +359,5 @@
         </script>
         <script text="text/javascript">
-          <xsl:text disable-output-escaping="yes">
+			<xsl:text disable-output-escaping="yes">
 			
 			function checkLoop(pid, serverFunction, callback)
@@ -465,8 +466,64 @@
 			function saveAndBuildCollection(col)
 			{			
+				for(var j = 0; j &lt; gs.toDeleteArray.keys.length; j++)
+				{
+					var current = gs.toDeleteArray[gs.toDeleteArray.keys[j]];
+					if(current == null){continue;}
+					var metaToDelete = ["user", "text", "tags"];
+					
+					for(var l = 0; l &lt; metaToDelete.length; l++)
+					{
+						var deleteArchivesURL = "cgi-bin/metadata-server.pl?\
+							a=remove-archives-metadata&amp;\
+							c=" + gs.cgiParams.c + "&amp;\
+							site=localsite&amp;\
+							docid=" + gs.cgiParams.d + "&amp;\
+							metaname=gstext." + metaToDelete[l] + "&amp;\
+							metavalue=" + ((l == 2) ? (current.user.name) : (current[metaToDelete[l]])); 
+							
+						var deleteIndexURL = "cgi-bin/metadata-server.pl?\
+							a=remove-metadata&amp;\
+							c=" + gs.cgiParams.c + "&amp;\
+							site=localsite&amp;\
+							docid=" + gs.cgiParams.d + "&amp;\
+							metaname=gstext." + metaToDelete[l] + "&amp;\
+							metavalue=" + ((l == 2) ? (current.user.name) : (current[metaToDelete[l]])); 
+							
+						var deleteImportURL = "cgi-bin/metadata-server.pl?\
+							a=remove-import-metadata&amp;\
+							c=" + gs.cgiParams.c + "&amp;\
+							site=localsite&amp;\
+							docid=" + gs.cgiParams.d + "&amp;\
+							metaname=gstext." + metaToDelete[l] + "&amp;\
+							metavalue=" + ((l == 2) ? (current.user.name) : (current[metaToDelete[l]]));
+							
+						var deleteArchivesCallback = 
+						{
+							success:function(){},
+							failed: function(){alert("Failed to save text annotations index metadata");}
+						}
+						YAHOO.util.Connect.asyncRequest("GET", deleteArchivesURL, deleteArchivesCallback);
+
+						var deleteIndexCallback =
+						{
+							success:function(){},
+							failed: function(){alert("Failed to save text annotations import metadata");}
+						}
+						YAHOO.util.Connect.asyncRequest("GET", deleteIndexURL, deleteIndexCallback);
+
+						var deleteImportCallback =
+						{
+							success:function(){},
+							failed: function(){alert("Failed to save text annotations import metadata");}
+						}
+						YAHOO.util.Connect.asyncRequest("GET", deleteImportURL, deleteImportCallback);
+					}
+				}
+			
 				var json = "[";
 				for(var i = 0; i &lt; gs.annotationArray.keys.length; i++)
 				{
 					var current = gs.annotationArray[gs.annotationArray.keys[i]];
+					if(current == null){continue;}					
 					var metaToAdd = ["user", "text", "tags"];
 					
@@ -481,5 +538,5 @@
 							json += '{"docid":"' + gs.cgiParams.d + '", "metaname":"gstext.' + metaToAdd[j] + '", "metavalue":"' + current[metaToAdd[j]] + '"}';
 						}
-						
+
 						if(j != (metaToAdd.length - 1) || i != (gs.annotationArray.keys.length - 1))
 						{
@@ -489,9 +546,9 @@
 				}
 				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 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;
+
 				var saveArchivesCallback = 
 				{
@@ -500,5 +557,5 @@
 				}
 				YAHOO.util.Connect.asyncRequest("GET", saveArchivesURL, saveArchivesCallback);
-				
+
 				var saveIndexCallback =
 				{
@@ -507,5 +564,5 @@
 				}
 				YAHOO.util.Connect.asyncRequest("GET", saveIndexURL, saveIndexCallback);
-				
+
 				var saveImportCallback =
 				{
@@ -516,52 +573,42 @@
 			}
 					
-						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') {
-									alert("Ooops! it looks like you haven't built the Annotator concatenation file. " + "Either download a tagged release from GitHub, or modify the Cakefile to point " + "at your copy of the YUI compressor and run `cake package`.");
-								} else {	
-									/*
-									jQuery('#gs-document-text').annotator()
-									.annotator('addPlugin', 'Store', {
-										prefix: 'http://annotateit.org/api',
-										annotationData: {'uri':document.URL}
-									})
-									.annotator('addPlugin', 'Auth', {
-										userId: 'papitha',          // Your AnnotateIt username
-										consumerKey: '39fc339cf058bd22176771b3e33c5dac',           // Your Account Key
-										authToken: '852b7fc25396d2aedf9aeb44dd58518faa679dbf027892164bfb81900bd09741' // Your Auth Token
-									});
-									*/	
-
-									jQuery(function ($) {
-										// Include AnnotateIt credentials to load the store plugin.
-										$('#gs-document-text').annotator().annotator('setupPlugins', {
-											userId:    'papitha',
-											userName:  'Papitha',
-											accountId: '39fc339cf058bd22176771b3e33c5dac',
-											authToken: '852b7fc25396d2aedf9aeb44dd58518faa679dbf027892164bfb81900bd09741',	
-										}, {
-											Store: 
-											{
-												prefix: 'http://localhost:5000',
-												annotationData: {'uri':gs.cgiParams.c + "-" + gs.cgiParams.d},
-												loadFromSearch: {'uri':gs.cgiParams.c + "-" + gs.cgiParams.d}
-											}
-										});
-									});
+			function initAnnotator()
+			{		
+				gs.annotationArray = new Array();
+				gs.annotationArray.keys = new Array();
+				
+				gs.toDeleteArray = new Array();
+				gs.toDeleteArray.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') {
+						alert("Ooops! it looks like you haven't built the Annotator concatenation file. " + "Either download a tagged release from GitHub, or modify the Cakefile to point " + "at your copy of the YUI compressor and run `cake package`.");
+					} else {
+						jQuery(function ($) {
+							// Include AnnotateIt credentials to load the store plugin.
+							$('#gs-document-text').annotator().annotator('setupPlugins', {
+								userId:    'papitha',
+								userName:  'Papitha',
+								accountId: '39fc339cf058bd22176771b3e33c5dac',
+								authToken: '852b7fc25396d2aedf9aeb44dd58518faa679dbf027892164bfb81900bd09741',	
+							}, {
+								Store: 
+								{
+									prefix: 'http://localhost:5000',
+									annotationData: {'uri':gs.cgiParams.c + "-" + gs.cgiParams.d},
+									loadFromSearch: {'uri':gs.cgiParams.c + "-" + gs.cgiParams.d}
 								}
 							});
-						}
-					</xsl:text>
+						});
+					}
+				});
+			}
+		</xsl:text>
         </script>
       </xsl:template>
Index: main/trunk/model-cols-dev/peijones/js/annotator/pkg/annotator-full.min.js
===================================================================
--- main/trunk/model-cols-dev/peijones/js/annotator/pkg/annotator-full.min.js	(revision 24947)
+++ main/trunk/model-cols-dev/peijones/js/annotator/pkg/annotator-full.min.js	(revision 24948)
@@ -659,8 +659,15 @@
             var w, v, y, x;
             x = u.highlights;
+			
             for (v = 0, y = x.length; v < y; v++) {
                 w = x[v];
                 h(w).replaceWith(w.childNodes)
             }
+			
+			var rangeString = u.ranges[0].startOffset + "_" + u.ranges[0].endOffset;
+			gs.toDeleteArray[rangeString] = gs.annotationArray[rangeString];
+			gs.toDeleteArray.keys.push(rangeString);
+			gs.annotationArray[rangeString] = null;
+			
             this.publish("annotationDeleted", [u]);
             return u
