Index: main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml
===================================================================
--- main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml	(revision 24955)
+++ main/trunk/model-cols-dev/peijones/etc/collectionConfig.xml	(revision 24956)
@@ -262,5 +262,5 @@
 								YAHOO.util.Connect.asyncRequest("GET", removeFromIndexURL, indexCallback);
 								YAHOO.util.Connect.asyncRequest("GET", removeFromArchivesURL, archiveCallback);
-								YAHOO.util.Connect.asyncRequest("GET", removeFromImportURL, callback);
+								YAHOO.util.Connect.asyncRequest("GET", removeFromImportURL, importCallback);
 							}
 							else {
@@ -466,17 +466,20 @@
 			function saveAndBuildCollection(col)
 			{			
+				console.log("BEFORE DELETE LOOP");
 				for(var j = 0; j &lt; gs.toDeleteArray.keys.length; j++)
 				{
+					console.log("IN DELETE LOOP");
 					var current = gs.toDeleteArray[gs.toDeleteArray.keys[j]];
 					if(current == null){continue;}
 					var metaToDelete = ["user", "text", "tags"];
-					
+					console.log("IN DELETE LOOP 1");
 					for(var l = 0; l &lt; metaToDelete.length; l++)
 					{
+					console.log("IN DELETE LOOP 2");
 						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;\
+							d=" + gs.cgiParams.d + "&amp;\
 							metaname=gstext." + metaToDelete[l] + "&amp;\
 							metavalue=" + ((l == 0) ? (current.user.name) : (current[metaToDelete[l]])); 
@@ -486,5 +489,5 @@
 							c=" + gs.cgiParams.c + "&amp;\
 							site=localsite&amp;\
-							docid=" + gs.cgiParams.d + "&amp;\
+							d=" + gs.cgiParams.d + "&amp;\
 							metaname=gstext." + metaToDelete[l] + "&amp;\
 							metavalue=" + ((l == 0) ? (current.user.name) : (current[metaToDelete[l]])); 
@@ -494,8 +497,8 @@
 							c=" + gs.cgiParams.c + "&amp;\
 							site=localsite&amp;\
-							docid=" + gs.cgiParams.d + "&amp;\
+							d=" + gs.cgiParams.d + "&amp;\
 							metaname=gstext." + metaToDelete[l] + "&amp;\
 							metavalue=" + ((l == 0) ? (current.user.name) : (current[metaToDelete[l]]));
-							
+							console.log("IN DELETE LOOP 3");
 						var deleteArchivesCallback = 
 						{
@@ -521,56 +524,62 @@
 				}
 				gs.toDeleteArray = new Array();
-			
-				var json = "[";
-				for(var i = 0; i &lt; gs.annotationArray.keys.length; i++)
+				gs.toDeleteArray.keys = new Array();
+				
+				if(gs.annotationArray.keys.length > 0)
 				{
-					var current = gs.annotationArray[gs.annotationArray.keys[i]];
-					if(current == null){continue;}					
-					var metaToAdd = ["user", "text", "tags"];
-					
-					for(var j = 0; j &lt; metaToAdd.length; j++)
+					var json = "[";
+					for(var i = 0; i &lt; gs.annotationArray.keys.length; i++)
 					{
-						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]] + '"}';
-						}
+						var current = gs.annotationArray[gs.annotationArray.keys[i]];
+						if(current == null){continue;}					
+						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 += ',';
+							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;
+
+					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);
 				}
-				json += "]";
+				
 				gs.annotationArray = new Array();
-
-				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;
-
-				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);
+				gs.annotationArray.keys = new Array();
 			}
 					
