Index: /main/trunk/greenstone2/macros/seaweed.dm
===================================================================
--- /main/trunk/greenstone2/macros/seaweed.dm	(revision 23396)
+++ /main/trunk/greenstone2/macros/seaweed.dm	(revision 23396)
@@ -0,0 +1,198 @@
+package Global
+
+_unloadhandler_ {saveMetadata}
+
+_seaweed_ {
+
+
+<!--
+.editable-metadata \{ background-color: \#ffffd0 \}
+.editable-text     \{ background-color: \#e0ffe0 \}
+-->
+
+<style type="text/css">
+
+span.editable-metadata \{
+    position:relative; /*this is the key*/
+    z-index:24;
+\}
+
+div.editable-text \{
+    position:relative; /*this is the key*/
+    z-index:24;
+\}
+
+span.tooltip \{ display: none \}
+
+</style>
+
+
+<script type="text/javascript" src="_httpscript_/seaweed.js"></script>
+<script type="text/javascript" src="_httpscript_/gsajaxapi.js"></script>
+
+
+<script type="text/javascript">
+
+  function gsdefined(val) 
+  \{
+      return (typeof(val) != "undefined");
+  \}
+
+  var tooltipParentElem = null;
+
+  function showTooltip(elem) 
+  \{
+
+      if (de.getEditedElements) \{
+
+          // guard against getEditedElements() not being defined
+	  // this can happen if we get a onmouseover event
+	  // before the document is fully loaded
+
+          var editedHashSet = de.getEditedElements();
+
+          if (editedHashSet.contains(elem)) \{
+	      return;
+          \}
+      \}
+
+      elem.style.zIndex="25";
+
+      var metaname = elem.getAttribute("metaname");
+      var tooltip = document.createElement("span");
+      tooltip.setAttribute("class","tooltip");
+      tooltip.setAttribute("id","tooltip");
+
+      tooltip.style.position = "absolute";
+      tooltip.style.zIndex = "26";
+      tooltip.style.top = "0.9em";
+      tooltip.style.left = "1em";
+      tooltip.style.height = "1.1em";
+      tooltip.style.border = "1px solid #660";
+      tooltip.style.backgroundColor = "#ffffe0";
+      tooltip.style.color = "\#000";
+      //tooltip.style.textAlign = "center";
+      tooltip.style.padding = "0.2em";
+
+      tooltip.innerHTML = "<nobr>Click (and then type) to edit <i>" + metaname + "</i> metadata</nobr>";
+
+      tooltipParentElem = elem;
+      setTimeout("delayedShowTooltip()", 2000);
+      elem.appendChild(tooltip);
+      
+  \}
+
+  function delayedShowTooltip()
+  \{
+      if (tooltipParentElem!=null) \{
+
+          if (de.getEditedElements) \{
+              var editedHashSet = de.getEditedElements();
+
+              if (editedHashSet.contains(tooltipParentElem)) \{
+                  tooltipParentElem = null;
+	         return;
+              \}
+	  \}
+
+          var tooltip = document.getElementById("tooltip");
+          tooltip.style.display = "block";
+          setTimeout("delayedHideTooltip()", 5000);
+      \}
+  \}
+
+
+  function hideTooltip(elem) 
+  \{
+      var tooltip = document.getElementById("tooltip");
+      if (tooltip != null) \{
+          elem.removeChild(tooltip)
+          tooltip.style.display = "none";
+      \}
+
+      tooltipParentElem = null;
+
+      elem.style.zIndex="24";
+  \}
+
+  function delayedHideTooltip(elem) 
+  \{
+      if (tooltipParentElem!=null) \{
+          hideTooltip(tooltipParentElem);
+      \}
+  \}
+
+
+
+  var gsapi = new GSAjaxAPI("_gwcgi_","_cgiargc_");
+
+  window.onload=function()\{
+      try \{
+	  de.init();
+	  window.addEventListener('beforeunload',saveMetadata,true);
+	  
+        
+	   de.doc.declarePropertySets(\{
+                metadata: \{
+                    phMarkup: '<span style="background-color:#DDDDDD;color:black"><em>[Enter a value]</em></span>',
+                    name: "metadata"
+                \}
+	   \});
+		
+      \} 
+      catch(err) \{
+		alert("SeaWeed failed to initialise: " + err.message);
+      \}
+  \}
+
+  
+  
+  function saveMetadataElement(editedElem) 
+  \{
+       var docoid = editedElem.getAttribute("docoid");
+        
+       if (gsdefined(docoid)) \{
+           var metaname = editedElem.getAttribute("metaname");
+           var metapos  = editedElem.getAttribute("metapos");
+           var metavalue= editedElem.innerHTML;
+        
+           var metavalue = metavalue.replace(/&nbsp;/g, " ");
+        
+           // alert("docoid = " + docoid + " metaname = " + metaname + " metapos = " + metapos + " metavalue = " + metavalue);
+
+	   // console.log("docoid = " + docoid + " metaname = " + metaname + " metapos = " + metapos + " metavalue = " + metavalue);
+
+           gsapi.setDocumentMetadata(docoid,metaname,metapos,metavalue);
+        
+       	 \}
+
+      return true;
+  \}
+
+  function saveMetadata() 
+  \{
+      var editedArray = de.Changes.getChangedEditableSections();
+      // editedHashSet.iterate(function(item) \{ console.log(item.innerHTML); return true \} );
+
+      if (editedArray.length>0) \{
+          var commitChanges = confirm("Commit edited metadata?");
+	  if (commitChanges) \{
+		for (i=0; i<editedArray.length; i++)
+		  \{
+				saveMetadataElement(editedArray[i]);
+		  \}
+
+	  \}
+
+	  // whether commited or not, now clear list of edited values
+          //clearEditedElements();
+      \}
+
+
+  \}
+
+
+</script>
+
+
+}
