Index: /main/trunk/greenstone3/web/interfaces/default/js/berrybasket/berrycheckout.js
===================================================================
--- /main/trunk/greenstone3/web/interfaces/default/js/berrybasket/berrycheckout.js	(revision 33107)
+++ /main/trunk/greenstone3/web/interfaces/default/js/berrybasket/berrycheckout.js	(revision 33108)
@@ -24,69 +24,17 @@
 
     // https://stackoverflow.com/questions/386281/how-to-implement-select-all-check-box-in-html
-    //https://stackoverflow.com/questions/590018/getting-all-selected-checkboxes-in-an-array
-    //https://www.w3schools.com/jsref/met_document_queryselectorall.asp
-    //https://www.w3schools.com/cssref/css_selectors.asp
-    var selectedCheckboxList = document.querySelectorAll('input[name=select-berry-checkbox]:checked');
-    if(selectedCheckboxList.length == 0) return; // nothing selected, so nothing to delete
-  
-    doDelete(selectedCheckboxList);
-}
-
-function deleteAll() {
-
-    if(docList.length == 0) return; // nothing to delete
-    
-    var  delurl = delurlPath; // var delurlPath is declared in ygDDPlayer.js.
-    // Just need to append each doc id separated by |, but this character needs to be URL encoded,
-    // else the delete doesn't work.
-
-    for(var i = 0; i < docList.length; i++) {
-	var doc = docList[i];
-	var doc_id = doc['collection']+":"+ doc['name'];
-
-	if((i+1) == docList.length) { // if it's the last id to process, don't append separator
-	    delurl += doc_id;
-	} else { // there's more ids to process, so append separator
-	    delurl += doc_id + "%7C"; // url-encoded version of |
-	}
-    }
-
-    // The following is a modified version of methods internal to
-    // ygDDPlayer.js's ygDDPlayer.prototype.onDragDrop
-    var delSuccess = function(o){ 
-	var result = o.responseXML;
-	
-	docList.length = 0; // https://www.jstips.co/en/javascript/two-ways-to-empty-an-array/	
-	
-	var content =  YAHOO.util.Dom.get('berryBasketContent');
-	while (content.hasChildNodes()) {
-	    content.removeChild(content.firstChild);
-	}  
-	content.appendChild(document.createTextNode('Your berry basket is empty.'));
-	
-	var trashbin =  YAHOO.util.Dom.get('trashbin');
-	if ( trashbin !=null){
-	    trashbin.style.background = 'url("interfaces/default/images/trash-full.png") 0 0 no-repeat';
-	}
-
-	var delall_checkbox = YAHOO.util.Dom.get('delall-checkbox');
-	delall_checkbox.checked = false; // deselect the delete-all checkbox
-    }
-
-    var delFailure = function(o){ alert("Deletion failed" + o);}
-    
-    var delcallback = {
-	success:delSuccess,
-	failure:delFailure,  
-	argument:null // supposed to be the ygDDPlayer object, but don't have a ref to it here, so trying null
-    }
-    // request_type defaults to GET, which is what's used for add and del, see ygDDPlayer.js.
-    YAHOO.util.Connect.asyncRequest(request_type, delurl , delcallback);
-    
-}
-
-
-function doDelete(selectedList) { // given list of selected checkboxes
-    
+    // https://stackoverflow.com/questions/590018/getting-all-selected-checkboxes-in-an-array
+    // https://www.w3schools.com/jsref/met_document_queryselectorall.asp
+    // https://www.w3schools.com/cssref/css_selectors.asp
+    var selectedList = document.querySelectorAll('input[name=select-berry-checkbox]:checked');
+    if(selectedList.length == 0) return; // nothing selected, so nothing to delete
+
+    // if all berries selected for deletion, can optimise
+    if(selectedList.length === docList.length) {
+	deleteAll();
+	return; // done!
+    }
+    
+    // otherwise selected list of berries is a proper subset of total berries (berries in docList)    
     var idsToDelete = [];
 
@@ -111,15 +59,41 @@
 	
     }
-    
+
+    var delAll = false;
+    doDelete(delAll, delurl, selectedList, idsToDelete);
+}
+
+function deleteAll() {
+
+    if(docList.length == 0) return; // nothing to delete
+    
+    var  delurl = delurlPath; // var delurlPath is declared in ygDDPlayer.js.
+    // Just need to append each doc id separated by |, but this character needs to be URL encoded,
+    // else the delete doesn't work.
+
+    for(var i = 0; i < docList.length; i++) {
+	var doc = docList[i];
+	var doc_id = doc['collection']+":"+ doc['name'];
+
+	if((i+1) == docList.length) { // if it's the last id to process, don't append separator
+	    delurl += doc_id;
+	} else { // there's more ids to process, so append separator (in URL encoded form!)
+	    delurl += doc_id + "%7C"; // url-encoded version of |
+	}
+    }
+    
+    var delAll = true;
+    doDelete(delAll, delurl, null, null);
+}
+
+
+function doDelete(deleteAll, delurl, selectedList, idsToDelete) { // given list of selected checkboxes
+
     // The following is a modified version of methods internal to
     // ygDDPlayer.js's ygDDPlayer.prototype.onDragDrop
     var delSuccess = function(o) {
 	var result = o.responseXML;
-
-	var deleteAll = false;
-	if(selectedList.length === docList.length) { // deleting all berries, can optimise
-	    deleteAll = true;
-	}
-	else { // Not deleting all berries, just a subset
+	
+	if(!deleteAll) { // then we're given a selection to delete: Not deleting all berries, just a subset
 	    // Remove id of selected doc to be deleted from docList.	    
 	    // Minor optimisation to double for loop, dependent on ordering of selected berries being
@@ -139,5 +113,5 @@
 		}
 	    }
-
+	    
 	    // remove the selected documents' HTML display elements
 	    var berryDocsList = YAHOO.util.Dom.get('berryDocsList'); // ordered list item containing the berries	
@@ -148,11 +122,11 @@
 	    }
 	}
-
-	// if all docs are deleted, then display "berry basket is empty" message
-	if (deleteAll || !berryDocsList.hasChildNodes()) {	    
-	    if(deleteAll) {
-		// if deleting all docs, just use the easy way to empty the docList array
-		docList.length = 0; // https://www.jstips.co/en/javascript/two-ways-to-empty-an-array/
-	    }
+    
+
+	// if all docs are deleted by this stage, then display "berry basket is empty" message
+	if (deleteAll || !berryDocsList.hasChildNodes()) { // 2nd clause no longer needed?, then this just becomes an else against the first if(!deleteAll) test
+	    
+	    // if deleting all docs, just use the easy way to empty the docList array
+	    docList.length = 0; // https://www.jstips.co/en/javascript/two-ways-to-empty-an-array/
 
 	    // Removing all child nodes (done one at a time) is more optimal
@@ -171,5 +145,5 @@
 	}
 
-	// deselect the delete-all and delete-selected checkboxes
+	// Ensure the delete-all and delete-selected checkboxes are deselected
 	YAHOO.util.Dom.get('delall-checkbox').checked = false; 
 	YAHOO.util.Dom.get('delselected-checkbox').checked = false; 
