Index: main/trunk/greenstone2/macros/document.dm
===================================================================
--- main/trunk/greenstone2/macros/document.dm	(revision 27292)
+++ main/trunk/greenstone2/macros/document.dm	(revision 27293)
@@ -166,4 +166,18 @@
 
 	function addUserComment(_username, _comment, _docid, doc) \{
+
+		// don't add empty strings for name/comment		
+
+		// http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript
+		var trimmed_username=_username.replace(/^\s+|\s+$/g, '');
+		var trimmed_comment = _comment.replace(/^\s+|\s+$/g, '');
+		
+		if(!trimmed_username || !trimmed_comment) \{
+		      doc.AddUserCommentForm.comment.value = "";
+		      doc.AddUserCommentForm.username.value = "";
+		      doc.getElementById("usercommentfeedback").innerHTML = "_text-is-empty_";
+		      return;
+		\}
+
 		// Need to the add user comment meta of username, timestamp and comment to the
 		// topmost section of the document. So only get the docId up to any period mark:
@@ -241,5 +255,8 @@
 
 		// update display of existing user comments to show the newly added comment
-		loadUserComments();
+		var usercommentdiv = document.getElementById("usercomments");
+		if(usercommentdiv != undefined) \{
+		     displayInUserCommentList(usercommentdiv, _username, _timestamp, _comment);
+		\}
 	\}
 </script>
Index: main/trunk/greenstone2/macros/english.dm
===================================================================
--- main/trunk/greenstone2/macros/english.dm	(revision 27292)
+++ main/trunk/greenstone2/macros/english.dm	(revision 27293)
@@ -340,4 +340,5 @@
 _textaddcomment_ {add comment}
 _textcommentsubmitted_ {Comment Submitted}
+_text-is-empty_ {Can't add empty values}
 
 _textgoto_ {go to page}
Index: main/trunk/greenstone2/macros/style.dm
===================================================================
--- main/trunk/greenstone2/macros/style.dm	(revision 27292)
+++ main/trunk/greenstone2/macros/style.dm	(revision 27293)
@@ -244,7 +244,7 @@
     // http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss
     // Call as: alert(timestamp.printTime());
-    String.prototype.printTime = function () \{
-      var timestamp    = parseInt(this, 10); // don't forget the second param
-      var date = new Date(timestamp);
+    function formatTime(timestamp) \{
+      var int_timestamp    = parseInt(timestamp, 10); // don't forget the second param
+      var date = new Date(int_timestamp);
       return date.toLocaleDateString() + " " + date.toLocaleTimeString();   
    \}
@@ -313,9 +313,9 @@
 			
 		metapos++;
-		username = gsapi.getArchivesMetadata(doc_id, "username", metapos);
+		username = gsapi.getArchivesMetadata(doc_id, "username", metapos);//, "_cgiargun_", "_cgiargpw_");
 	\}
 
 	// No need to sort by time, 
-	// as the array is already stored sorted and hence retrieved in the right order by using metapost counter
+	// as the array is already stored sorted and hence retrieved in the right order by using metapos counter
 	// If sorting the array of comment records, which would be by timestamp, see
 	// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort
@@ -328,5 +328,5 @@
 	
 	// create the output HTML for all comments in one go now
-	// (we do this here altogether to hopefully avoid reloading the page for each comment)
+	// (we do this here for all values together to hopefully avoid reloading the page for each comment)
 
 	for(var i = 0; i < metapos; i++) \{
@@ -339,28 +339,5 @@
 
 		// for each usercomment, create a child div with the username, timestamp and comment
-
-		var divgroup=document.createElement("div");
-		var attr=document.createAttribute("class");
-		attr.nodeValue="usercomment";
-		divgroup.setAttributeNode(attr);
-
-		var divuser=document.createElement("div");
-		var divtime=document.createElement("div");
-		var divcomment=document.createElement("div");
-
-	
-		divgroup.appendChild(divuser);
-		var txt=document.createTextNode(username);
-		divuser.appendChild(txt);
-
-		divgroup.appendChild(divtime);
-		txt=document.createTextNode(timestamp.printTime()); // formate timestamp for date/time display
-		divtime.appendChild(txt);
-
-		divgroup.appendChild(divcomment);
-		txt=document.createTextNode(comment);
-		divcomment.appendChild(txt);
-
-		usercommentdiv.appendChild(divgroup);
+		displayInUserCommentList(usercommentdiv, username, timestamp, comment);
 	\}
 
@@ -368,4 +345,31 @@
     \}
 
+    function displayInUserCommentList(usercommentdiv, username, timestamp, comment) \{
+
+    	var divgroup=document.createElement("div");
+	var attr=document.createAttribute("class");
+	attr.nodeValue="usercomment";
+	divgroup.setAttributeNode(attr);
+
+	var divuser=document.createElement("div");
+	var divtime=document.createElement("div");
+	var divcomment=document.createElement("div");
+
+	
+	divgroup.appendChild(divuser);
+	var txt=document.createTextNode(username);
+	divuser.appendChild(txt);
+
+	divgroup.appendChild(divtime);
+	txt=document.createTextNode(formatTime(timestamp)); // format timestamp for date/time display
+	divtime.appendChild(txt);
+
+	divgroup.appendChild(divcomment);
+	txt=document.createTextNode(comment);
+	divcomment.appendChild(txt);
+
+	usercommentdiv.appendChild(divgroup);
+    	     
+    \}
 
     // http://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load
