Index: main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js	(revision 31558)
+++ main/trunk/greenstone3/web/interfaces/default/js/javascript-global-functions.js	(revision 31559)
@@ -467,7 +467,4 @@
     // check for any caller overrides
     if(opts != null) {
-	//if(opts["use_payload_in_data_not_url_form"] != null) {
-	  //  _use_payload_in_data_not_url_form = opts["use_payload_in_data_not_url_form"];
-	//}
 	if(opts["requestMethod"] != null) {
 	    method = opts["requestMethod"];
@@ -502,6 +499,4 @@
     if(_use_payload_in_data_not_url_form) { // using data payload to do AJAX (regardless of request method)
 	
-	//method = "POST";
-
 	// for get-meta operations, go directly through metadata-server.pl
 	// for set-meta ops, should go via GS3 authentication, which is off the GS3 library servlet
@@ -519,5 +514,5 @@
     // finally, can do the AJAX call
 
-    console.log("*** Away to call: " + url);
+    //console.log("*** Away to call: " + url);
     var ajaxResponse = async_setting ? "*** No response received yet, async ajax request" : null;
 
@@ -529,5 +524,5 @@
 	    .success(function(response) {
 		ajaxResponse = response;
-		console.log("** (" + callingFunction + ") Response received from server: " + ajaxResponse);
+//		console.log("** (" + callingFunction + ") Response received from server: " + ajaxResponse);
 		
 		//var xml = $.parseXML(response);
@@ -564,10 +559,10 @@
 	}
 	
-	console.log("*** (" + callingFunction + ") Response from server: " + ajaxResponse);
-
-    }
-    
-    console.log("*** Finished ajax call to: " + url);    
-    console.log("*** Got response: " + ajaxResponse);
+//	console.log("*** (" + callingFunction + ") Response from server: " + ajaxResponse);
+
+    }
+    
+//    console.log("*** Finished ajax call to: " + url);    
+//    console.log("*** Got response: " + ajaxResponse);
 
     return ajaxResponse;
Index: main/trunk/greenstone3/web/interfaces/default/js/user_comments.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/user_comments.js	(revision 31558)
+++ main/trunk/greenstone3/web/interfaces/default/js/user_comments.js	(revision 31559)
@@ -10,4 +10,6 @@
 // http://stackoverflow.com/questions/33514915/what-s-the-difference-between-and-while-declaring-a-javascript-array
 // http://www.nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/
+// stackoverflow.com/questions/36661748/what-is-the-exact-negation-of-ifvariable-in-javascript
+// http://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript
 
 /***************
@@ -15,4 +17,5 @@
 ****************/
 
+// avoid making usercomments js functions global (which attaches them as properties to the window object)
 gs.usercomments = {};
 
@@ -28,9 +31,7 @@
 
     // don't bother loading comments if we're not on a document page (in which case there's no docid)
-    var doc_id = gs.variables["d"]; ///"_cgiargdJssafe_"; //escape("cgiargd");
-
-    // stackoverflow.com/questions/36661748/what-is-the-exact-negation-of-ifvariable-in-javascript
-    if(!doc_id) { // vs http://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript
-	
+    var doc_id = gs.variables["d"]; ///"_cgiargdJssafe_" in GS2
+
+    if(!doc_id) {	
 	return;
     }
@@ -40,4 +41,6 @@
     // asynchronously, this is to help prevent any overlap in these functions' access of meta files in
     // index|archives|import.
+    // Prevent users from adding comments by disabling the submit button
+    // until existing comments have been retrieved and displayed
     var submitButton = document.getElementById("usercommentSubmitButton");    
     if(submitButton) { // there'll be no submitButton if the comment form is not displayed (user not logged in)
@@ -45,9 +48,4 @@
     }
 
-    
-    // don't allow users to add comments (disable the submit button)
-    // until existing comments have been retrieved and displayed
-    //document.getElementById("usercommentSubmitButton").disabled = true;
-
     // Since we have a docid, get toplevel section of the docid
     
@@ -78,5 +76,4 @@
 
     var docArray = [doc_rec];
-    //alert(JSON.stringify(docArray));
 
     //var json_result_str = gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index");
@@ -100,14 +97,10 @@
     // Using JavaScript's feature sensing to detect which of the two we're dealing with:
     var json_result_str = (data.responseText) ? data.responseText : data; 
-        // http://stackoverflow.com/questions/6286542/how-can-i-check-if-a-var-is-a-string-in-javascript
-        //var json_result_str = (typeof data !== 'string') ? data.responseText : data;
-        //alert("Type of ajax get result: " + typeof (data));
-
-    //	alert(json_result_str);
-    console.log("Got to display: " + json_result_str);
+
+    //console.log("Got user comments to display: " + json_result_str);
+
     var result = JSON.parse(json_result_str);
     // result contains only one docrec (result[0]), since we asked for the usercomments of one docid
     var metatable = result[0].metatable;
-    //	alert(JSON.stringify(metatable));
     
     var i = 0;
@@ -122,5 +115,5 @@
 	attr.nodeValue="usercommentheading";
 	heading.setAttributeNode(attr);
-	var txt=document.createTextNode(gs.variables["textusercommentssection"]); ///"_textusercommentssection_");
+	var txt=document.createTextNode(gs.variables["textusercommentssection"]); ///"_textusercommentssection_" in GS2
 	heading.appendChild(txt);
 	usercommentdiv.appendChild(heading);
@@ -141,6 +134,4 @@
 	    var comment = metatable[2].metavals[i].metavalue; 
 	    
-	    //alert("Comment: " + username + " " + timestamp + " " + comment);
-	    
 	    // No need to sort by time, as the meta are already stored sorted 
 	    // and hence retrieved in the right order by using the i (metapos) counter
@@ -156,5 +147,6 @@
     
     var submitButton = document.getElementById("usercommentSubmitButton");
-    // Now we've finished loading all user comments, allow the user to add a comment
+    // Now we've finished loading all user comments,
+    // allow the user to add a comment by enabling the submit button again
     if(submitButton) {
 	submitButton.disabled = false;
@@ -165,6 +157,4 @@
 gs.usercomments.displayInUserCommentList = function(usercommentdiv, username, timestamp, comment) {
     
-    //alert("Comment: " + username + " " + timestamp + " " + comment);
-
     var divgroup=document.createElement("div");
     var attr=document.createAttribute("class");
@@ -198,12 +188,4 @@
 }
 
-
-// Unused. Replaced in favour of call to escape() in setMetaArray function that calls urlPostSync
-// http://stackoverflow.com/questions/6020714/escape-html-using-jquery
-gs.usercomments.safeHTML = function(str) {
-    return str.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"',"&quot;").replace("'","&#x27;").replace("/", "&#x2F;"); //"\\""
-}
-
-
 gs.usercomments.addUserComment = function(_username, _comment, _docid, doc) {
     
@@ -214,8 +196,8 @@
     var trimmed_comment = _comment.replace(/^\s+|\s+$/g, '');
     
-    if(!trimmed_comment) { // || !trimmed_username
+    if(!trimmed_comment) {
 	doc.AddUserCommentForm.comment.value = "";		      
 	//document.AddUserCommentForm.username.value = "";
-	document.getElementById("usercommentfeedback").innerHTML = gs.variables["textisempty"]; ///"_textisempty_";
+	document.getElementById("usercommentfeedback").innerHTML = gs.variables["textisempty"]; ///"_textisempty_" in GS2
 	return;
     }
@@ -236,25 +218,9 @@
     var _timestamp = new Date().getTime(); // div by 1000 to get seconds. valueOf() may return string
     
-    //alert("username:" + _username
-    //+ "\\ncomment: " + _comment
-    //+ "\\ncollection: " + collection 
-    //+ "\\ndocid: " + _docid
-    //+ "\\ntimestamp: " + _timestamp); 
-    
-    
-    // Entity encode the values before storing (at least <, >, forward slash.
-    // And single and double quote, ampersand)
-    // http://stackoverflow.com/questions/6020714/escape-html-using-jquery
-    // setMetadataArray escapes the entire JSON, is that better than escaping individually here?
-    //_docid = escape(_docid);
-    //_timestamp = escape(_timestamp);
-    //_username = escape(_username); //safeHTML(_username);
-    //_comment = escape(_comment); //safeHTML(_comment);
-    
-    // Use this if making individual api calls to set username meta, then timestamp then comment meta
-    // GSAPI already knows the collection
-    //gsapi.setMetadata(_docid, "username", null, _username, "accumulate", "import|archives|index");
-    //gsapi.setMetadata(_docid, "usertimestamp", null, _timestamp, "accumulate", "import|archives|index");
-    //gsapi.setMetadata(_docid, "usercomment", null, _comment, "accumulate", "import|archives|index");
+    // setMetadataArray escapes the entire JSON, so we don't individually escape the fields here
+    // If we did, and called gsapi.setMetadata or gs.functions (in javascript-global-functions.js) instead,
+    // then resort to escaping first, e.g.
+    // _comment = escape(_comment);
+    // gsapi.setMetadata(_docid, "usercomment", null, _comment, "accumulate", "import|archives|index");
     
     
@@ -287,6 +253,4 @@
     
     var docArray = [doc_rec];
-    
-    //alert(JSON.stringify(docArray));
     
     // Don't allow the user to submit further comments until the metadata has been updated
@@ -301,6 +265,6 @@
 	function(ajaxResult) { return gs.usercomments.doneUpdatingMetatada(ajaxResult, _username, _timestamp, _comment); },
 	false); // false for asynchronous, 
-    // this is ok since we're disabling the comment submit button, so no further set-meta-array calls can be
-    // made until the ajax call returns and the callback is called which re-enables the submit button
+    // async here is ok since we're disabling the comment submit button, so no further set-meta-array calls
+    // can be made until the ajax call returns and the callback is called which re-enables the submit button
     // But disabling submit does not protect against concurrent access such as someone else editing the 
     // document (doing set-meta operations, updating archives/index/import) at the same time as someone else
@@ -311,14 +275,8 @@
 gs.usercomments.doneUpdatingMetatada = function(data, _username, _timestamp, _comment)
 {
-
     // data is xmlHttpRequest Object if gsajaxapi is used for the ajax call.
     // And data is a string if jQuery AJAX was used.
     // Using JavaScript's feature sensing to detect which of the two we're dealing with:
     var result = (data.responseText) ? data.responseText : data;        
-        // http://stackoverflow.com/questions/6286542/how-can-i-check-if-a-var-is-a-string-in-javascript
-        //var result = (typeof data !== 'string') ? data.responseText : data;
-        // alert("Type of ajax set result: " + typeof(data));
-
-    //alert("Received post response to setMeta: " + result); // just the HTML page
 
     // clear the comment field as it has now been submitted, but not the username field
@@ -336,5 +294,4 @@
 	errormessage="ERROR: Unable to add comment. " + error;
 	document.getElementById("usercommentfeedback").innerHTML = errormessage;
-	//alert("Result: " + result);
     } 
     else if (responseErrorIndex != -1) {
@@ -344,8 +301,7 @@
 	errormessage="ERROR: Unable to add comment. " + error;
 	document.getElementById("usercommentfeedback").innerHTML = errormessage;
-	//alert("Result: " + result);
     }
     else { // success!
-	document.getElementById("usercommentfeedback").innerHTML = gs.variables["textcommentsubmitted"]; ///"_textcommentsubmitted_";		
+	document.getElementById("usercommentfeedback").innerHTML = gs.variables["textcommentsubmitted"]; ///"_textcommentsubmitted_" in GS2
 	
 	// update display of existing user comments to show the newly added comment
@@ -364,5 +320,4 @@
     gs.usercomments.loadUserComments();
 
-    //$("div#commentarea").html("<textarea required=\"required\" name=\"comment\" rows=\"10\" cols=\"64\" placeholder=\"Add your comment here...\"></textarea>");
     $("div#commentarea").html('<textarea required="required" name="comment" rows="10" cols="64" placeholder="Add your comment here..."></textarea>');
 
Index: main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl	(revision 31558)
+++ main/trunk/greenstone3/web/interfaces/default/transform/layouts/usercomments.xsl	(revision 31559)
@@ -42,5 +42,5 @@
 	  <div>
 	    <p><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'usercomments.add')"/></p>
-	    <!-- The textarea will be added in by javascript into div#commentarea to avoid the problem of XML turning empty tags into self-closing ones and a self-closing text-area becomes invalid HTML -->
+	    <!-- The textarea will be added in by javascript into div#commentarea to avoid the problem of XML turning empty tags into self-closing ones and a self-closing text-area becomes invalid HTML. It will look like: -->
 	    <!--<textarea required="required" name="comment" rows="10" cols="64" placeholder="Add your comment here..."></textarea>-->
 	    <div id="commentarea">Comment area to appear here</div>
