Index: /main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js
===================================================================
--- /main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js	(revision 24201)
+++ /main/trunk/greenstone3/web/interfaces/oran/js/gui_div.js	(revision 24202)
@@ -2,5 +2,81 @@
 console.log("Loading gui_div.js\n");
 
-// var initialised_iframe = "false";
+/* DOCUMENT SPECIFIC FUNCTIONS */
+
+function displayTOC(checkbox)
+{
+    if (checkbox.checked == true)
+    {
+        console.log("Show the TOC!");
+        displaySideBar(true);
+        $("#tableOfContents").css("display", "block");
+    }
+    else
+    {
+        console.log("Hide the TOC!");
+        $("#tableOfContents").css("display", "none");
+        if ($("#coverImage").css("display") == "none")
+            displaySideBar(false);
+    }
+
+    return;
+}
+
+function displayBookCover(checkbox)
+{
+    if (checkbox.checked == true)
+    {
+        console.log("Show the book cover!");
+        displaySideBar(true);
+        $("#coverImage").css("display", "block");
+    }
+    else
+    {
+        console.log("Hide the book cover!");
+        $("#coverImage").css("display", "none");
+        if ($("#tableOfContents").css("display") == "none")
+            displaySideBar(false);
+    }
+
+    return;
+}
+
+function displaySideBar(toggle)
+{
+    if (toggle == true)
+    {
+        console.log("Show the sidebar!");
+        $("#rightSidebar").css("display", "block");
+    }
+    else
+    {
+        console.log("Hide the sidebar!");
+        $("#rightSidebar").css("display", "none");
+    }
+
+    return;
+}
+
+
+function checkDocumentRadio()
+{
+    var selection = $('input[name="documentChanges"]'); //document.quiz.colour;
+
+    for (i=0; i<selection.length; i++)
+
+        if (selection[i].checked == true)
+            return selection[i].value;
+
+    return "this";
+}
+
+function saveDocumentChanges()
+{
+    console.log("Saving changes to "+checkDocumentRadio());
+}
+
+
+
+/* FUNCTIONS FOR FORMAT EDITING */                                                                    
 
 function onTextChange(item, text)
@@ -23,5 +99,4 @@
     //item.setAttribute("selected","selected");
 }
-
 
 //function createFormatStatement()
@@ -84,7 +159,54 @@
 }
 
+function checkClassifierRadio()
+{
+    var selection = $('input[name="classifiers"]'); //document.quiz.colour;
+
+    for (i=0; i<selection.length; i++)
+
+          if (selection[i].checked == true)
+              return selection[i].value;
+
+    return "this";
+
+}
+
 function updateFormatStatement()
 {
     var formatStatement = getFormatStatement();
+
+    var thisOrAll = checkClassifierRadio();
+    console.log(thisOrAll);
+    var myurl = document.URL;
+
+    var collection_name = getSubstring(myurl, "&c", "&");
+    var service_name = getSubstring(myurl, "&s", "&");  
+
+    if(thisOrAll == "all")
+        service_name = "AllClassifierBrowse";
+
+    var classifier_name = null;
+
+    if(service_name == "ClassifierBrowse")
+        classifier_name = getSubstring(myurl, "&cl", "&");
+
+    var post_url = "http://localhost:8989/greenstone3/format?a=f&sa=update&c=" + collection_name +"&s=" + service_name;
+
+    if(classifier_name != null)
+        post_url = post_url + "&cl=" + classifier_name;
+
+    $.post(post_url, {data: formatStatement}, function(data) {
+        //$('.result').innerHTML = data; //html(data);
+    
+        // An error is returned because there is no valid XSLT for a format update action, there probably shouldn't be one so we ignore what the post returns.    
+        console.log("Successfully updated");
+        //console.log(data);
+        }, 'html');
+}
+
+function saveFormatStatement()
+{
+    var formatStatement = getFormatStatement();
+    var thisOrAll = checkClassifierRadio();
 
     var myurl = document.URL;
@@ -94,8 +216,11 @@
     var classifier_name = null;
 
+    if(thisOrAll == "all")
+        service_name = "AllClassifierBrowse";
+
     if(service_name == "ClassifierBrowse")
         classifier_name = getSubstring(myurl, "&cl", "&");
 
-    var post_url = "http://localhost:8989/greenstone3/format?a=f&sa=update&c=" + collection_name +"&s=" + service_name;
+    var post_url = "http://localhost:8989/greenstone3/format?a=f&sa=save&c=" + collection_name +"&s=" + service_name;
 
     if(classifier_name != null)
@@ -104,32 +229,42 @@
     $.post(post_url, {data: formatStatement}, function(data) {
         //$('.result').innerHTML = data; //html(data);
-        console.log("Success, we have received data");
-        console.log(data);
+        
+        // An error is returned because there is no valid XSLT for a format update action, there probably shouldn't be one so we ignore what the post returns.    
+        console.log("Successfully saved");
+        //console.log(data);
         }, 'html');
 }
 
-function saveFormatStatement()
-{
-    var formatStatement = getFormatStatement();
-
+function getXSLT(classname)
+{
     var myurl = document.URL;
 
     var collection_name = getSubstring(myurl, "&c", "&");
-    var service_name = getSubstring(myurl, "&s", "&");
-    var classifier_name = null;
-
-    if(service_name == "ClassifierBrowse")
-        classifier_name = getSubstring(myurl, "&cl", "&");
-
-    var post_url = "http://localhost:8989/greenstone3/format?a=f&sa=save&c=" + collection_name +"&s=" + service_name;
-
-    if(classifier_name != null)
-        post_url = post_url + "&cl=" + classifier_name;
-
-    $.post(post_url, {data: formatStatement}, function(data) {
-        //$('.result').innerHTML = data; //html(data);
-        console.log("Success, we have received data");
-        console.log(data);
-        }, 'html');
+    var document_id = getSubstring(myurl, "&d", "&");
+    var document_type = getSubstring(myurl, "&dt", "&");
+    var prev_action = getSubstring(myurl, "&p.a", "&");
+    var prev_service = getSubstring(myurl, "&p.s", "&");
+    //var classifier_name = null;
+
+    //if(service_name == "ClassifierBrowse")
+    //    classifier_name = getSubstring(myurl, "&cl", "&");
+
+
+    //var post_url = "http://localhost:8989/greenstone3/format?a=f&sa=getXSLT&c=" + collection_name +"&s=" + service_name+"&d=" + document_id + "&o=skinandlib";
+    var post_url = "http://localhost:8989/greenstone3/format?a=d&c=" + collection_name + "&d=" + document_id + "&dt=" + document_type + "&p.a=" + prev_action + "&p.s=" + prev_service + "&o=skinandlib";
+
+    //if(classifier_name != null)
+    //    post_url = post_url + "&cl=" + classifier_name;
+
+    $.post(post_url, {data: classname}, function(data) {
+            //$('.result').innerHTML = data; //html(data);
+            console.log("Success, we have received data");
+            //console.log(data);
+            classname = "." + classname;
+            console.log(classname); //data.getElementsByTagName("div"));
+            var content = $( data ).find(classname);
+            console.log(content.xml());
+            $("#XSLTcode").val(content.xml());
+            }, 'xml');
 }
 
@@ -344,4 +479,18 @@
     var CURRENT_SELECT_VALUE = "";
 
+    /* DOCUMENT SPECIFIC FUNCTIONS */
+
+    $('.sectionHeader').click(function () {
+        console.log('section Header click *');
+        getXSLT("sectionHeader");
+        return false; //don't event bubble
+    });
+
+    $('.sectionContainer').click(function () {
+        console.log('section Container click *');
+        getXSLT("sectionContainer");
+        return false; // don't event bubble
+    });
+
     /*
     var iframe = document.getElementById('iframe');
@@ -567,8 +716,12 @@
     //$('.tr').resize_tables($(this)); //equalHeights();
 
+    $('#sectionHeader').click(function () {
+         console.log('section Header click *');
+         return true;
+    });
     
-    $('td').click(function () {
-         console.log('td click *');
-         return false;
+    $('#sectionContainer').click(function () {
+         console.log('section Container click *');
+         return true;
     });
 
Index: /main/trunk/greenstone3/web/interfaces/oran/transform/layouts/formatmanager.xsl
===================================================================
--- /main/trunk/greenstone3/web/interfaces/oran/transform/layouts/formatmanager.xsl	(revision 24201)
+++ /main/trunk/greenstone3/web/interfaces/oran/transform/layouts/formatmanager.xsl	(revision 24202)
@@ -19,5 +19,9 @@
         <!-- Sam2's div code -->
 
+        <script type="text/javascript" src="interfaces/oran/js/jquery-1.4.2.js"><xsl:text> </xsl:text></script>
+        <script type="text/javascript" src="interfaces/oran/js/jquery-ui-1.8rc1/ui/jquery-ui.js"><xsl:text> </xsl:text></script>
+        <script type="text/javascript" src="interfaces/oran/js/jquery.selectboxes.js"><xsl:text> </xsl:text></script>
         <script type="text/javascript" src="interfaces/oran/js/innerxhtml.js"><xsl:text> </xsl:text></script>
+        <script type="text/javascript" src="interfaces/oran/js/jquery.xml.js"><xsl:text> </xsl:text></script>
         <script type="text/javascript" src="interfaces/oran/js/gui_div.js"><xsl:text> </xsl:text></script>
        
@@ -53,4 +57,6 @@
             .droppable_hl { border: dashed 1px #ccc; background-color:#FFFFCC; }
 
+            #XSLTcode {width: 99%; }
+
             .elementToolBox {position: fixed; top: 25%; right: 0px; background: none repeat scroll 0% 0% white; width: 250px; }
 
@@ -62,24 +68,78 @@
         <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css"/> 
 
+
+
         <table width="100%" border="1"> 
 
-        <td width="75%">
-
-        <button id="updateFormatStatement" type="button" onclick="updateFormatStatement()">Update Format Statement</button>
-        <button id="saveFormatStatement" type="button" onclick="saveFormatStatement()">Save Format Statement</button>
-
-        <div id="formatStatement">
-            <div id="formatRoot">
-        
-        <xsl:call-template name="xml-to-gui">
-            <xsl:with-param name="node-set" select="//format"/> <!-- [@type='browse']"/>  -->
-            <xsl:with-param name="metadataSets" select="//metadataSetList"/> 
-        </xsl:call-template> 
-            </div>
-        </div>
-        </td>    
-
-
-        <td class="elementToolBox">
+            <td width="100%">
+                <xsl:choose>
+                    <xsl:when test="/page/pageRequest/@action = 'd'">
+                        <!-- TOC on or off -->
+                        <xsl:choose>
+                            <xsl:when test="/page/pageResponse/format[@type='display']/gsf:option[(@name='TOC') and (@value='true')]">
+                                <input type="checkbox" name="TOC" checked="checked" onclick="displayTOC(this)">Display Table of Contents (set to true)</input>
+                            </xsl:when>
+                            <xsl:otherwise>
+                                <input type="checkbox" name="TOC" onclick="displayTOC(this)">Display Table of Contents (set to false)</input>
+                            </xsl:otherwise>
+                        </xsl:choose> <br/>
+
+                        <!-- book cover image on or off -->
+                        <xsl:choose>
+                            <xsl:when test="/page/pageResponse/format[@type='display']/gsf:option[(@name='coverImage') and (@value='true')]">
+                                <input type="checkbox" name="bookCover" checked="checked" onclick="displayBookCover(this)">Display Book Cover Image (set to true)</input>
+                            </xsl:when>
+                            <xsl:otherwise>
+                                <input type="checkbox" name="bookCover" onclick="displayBookCover(this)">Display Book Cover Image (set to false)</input>
+                            </xsl:otherwise>
+                        </xsl:choose> <br/>
+
+                        <textarea id="XSLTcode" rows="5">
+                        The XSLT code for the relevant part of the page will be displayed here.
+                        </textarea>
+                        <!-- What are we doing?  It might be possible to tweak saveFormatStatement() if we are only dealing with format stuff but are we? -->
+                        <br/>
+                        <table>
+                            <td>
+                                <button id="saveDocumentChanges" type="button" onclick="saveDocumentChanges()">Save Changes</button>
+                            </td>
+                            <td>
+                                <form>
+                                    <input name="documentChanges" type="radio" id="applyToDocument" value="document" checked="true"/>Apply to this document only
+                                    <input name="documentChanges" type="radio" id="applyToCollection" value="collection" />Apply to collection
+                                </form>
+                            </td>
+                        </table>
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <table>
+                            <td>
+                                <button id="updateFormatStatement" type="button" onclick="updateFormatStatement()">Update Format Statement</button>
+                            </td>
+                            <td>
+                                <button id="saveFormatStatement" type="button" onclick="saveFormatStatement()">Save Format Statement</button>
+                            </td>
+                            <td>
+                                <form>
+                                    <input name="classifiers" type="radio" id="applyToThis" value="this" checked="true"/>This Classifier
+                                    <input name="classifiers" type="radio" id="applyToAll" value="all" />All Classifiers
+                                </form> 
+                            </td>
+                        </table>
+
+                        <div id="formatStatement">
+                            <div id="formatRoot">
+                                <xsl:call-template name="xml-to-gui">
+                                    <xsl:with-param name="node-set" select="//format"/> <!-- [@type='browse']"/>  -->
+                                    <xsl:with-param name="metadataSets" select="//metadataSetList"/> 
+                                </xsl:call-template> 
+                            </div>
+                        </div>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </td>    
+        </table>
+
+        <div class="elementToolBox">
             <h2> Elements to add </h2>
             <!-- <div class="header element_type_gsf_template css_gsf_template" title="gsf:template">TEMPLATE</div> -->
@@ -212,6 +272,5 @@
                 <div class="draggable_td css_td" title="gsf:column">NEW TABLE COLUMN</div>
 
-            </td>
-        </table>
+         </div>
 
         <!--
Index: /main/trunk/greenstone3/web/interfaces/oran/transform/pages/classifier.xsl
===================================================================
--- /main/trunk/greenstone3/web/interfaces/oran/transform/pages/classifier.xsl	(revision 24201)
+++ /main/trunk/greenstone3/web/interfaces/oran/transform/pages/classifier.xsl	(revision 24202)
@@ -48,5 +48,15 @@
 	TEMPLATE FOR DOCUMENTS
 	-->
-	<xsl:template match="documentNode">
+
+    <!--<xsl:template match="documentNode" priority="3">-->
+        <!-- show the document details -->
+        <!--<li class="document">
+            <a>
+                <xsl:attribute name="href"><xsl:value-of select="$library_name"/>?a=d&amp;c=<xsl:value-of select="/page/pageResponse/collection/@name"/>&amp;d=<xsl:value-of select="@nodeID"/>&amp;dt=<xsl:value-of select="@docType"/>&amp;p.a=b&amp;p.s=<xsl:value-of select="/page/pageResponse/service/@name"/>&amp;ed=1</xsl:attribute><xsl:value-of disable-output-escaping="yes"  select="metadataList/metadata[@name='Title']"/>
+            </a>
+        </li>
+    </xsl:template>-->
+
+	<xsl:template match="documentNode" priority="3">
 		<!-- The book icon -->
 		<td>
@@ -68,5 +78,5 @@
 			<xsl:call-template name="documentBerryForClassifierOrSearchPage"/>
 		</td>
-	</xsl:template>
+	</xsl:template>-->
 
 
Index: /main/trunk/greenstone3/web/interfaces/oran/transform/pages/document.xsl
===================================================================
--- /main/trunk/greenstone3/web/interfaces/oran/transform/pages/document.xsl	(revision 24201)
+++ /main/trunk/greenstone3/web/interfaces/oran/transform/pages/document.xsl	(revision 24202)
@@ -90,10 +90,17 @@
 
 						<!-- the book's cover image -->
-						<div id="coverImage"><gslib:coverImage/></div>
-
-						<!-- the contents -->
-						<div id="tableOfContents">
-							<xsl:apply-templates select="documentNode" mode="TOC"/>
-						</div>
+                        <!-- COULD BE WORTH SETTING THE STYLE TO DISPLAY:BLOCK OR DISPLAY:NONE BASED ON WHETHER FLAG IS TRUE OR FALSE -->
+                        <!-- OTHERWISE, IF FLAG IS FALSE AND WE WANT TO TURN BOOK COVER ON, NEED TO REQUEST THE NEW PAGE WITH FLAG SET -->
+                        <xsl:if test="/page/pageResponse/format[@type='display']/gsf:option[@name='coverImage']/@value='true'">
+    						<div id="coverImage"><gslib:coverImage/></div>
+                        </xsl:if>
+
+						<!-- the contents (if enabled) -->
+                        <!-- VALUE=<xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='TOC']/@value"/> -->
+                        <xsl:if test="/page/pageResponse/format[@type='display']/gsf:option[@name='TOC']/@value='true'">
+						    <div id="tableOfContents">
+							    <xsl:apply-templates select="documentNode" mode="TOC"/>
+						    </div>
+                        </xsl:if>
 					</div>
 				</td></tr>
@@ -142,5 +149,5 @@
 		<a name="{@nodeID}"><xsl:text> </xsl:text></a>
 		<!-- Section header -->
-		<table><tr>
+		<table class="sectionHeader"><tr>
 			<!-- Expand/collapse button -->
 			<td class="headerTD">
@@ -163,5 +170,6 @@
 						</span>
 					</xsl:if>
-					<xsl:value-of disable-output-escaping="yes" select="metadataList/metadata[@name = 'Title']"/> 
+                    <!-- Display the title for the section regardless of whether automatic section numbering is turned on -->
+					<span class="sectionTitle"><xsl:value-of disable-output-escaping="yes" select="metadataList/metadata[@name = 'Title']"/></span>
 				</p>
 			</td>
Index: /main/trunk/greenstone3/web/interfaces/oran/transform/pages/pref.xsl
===================================================================
--- /main/trunk/greenstone3/web/interfaces/oran/transform/pages/pref.xsl	(revision 24201)
+++ /main/trunk/greenstone3/web/interfaces/oran/transform/pages/pref.xsl	(revision 24202)
@@ -146,4 +146,18 @@
 					<br class="clear"/>
 
+                    <!-- format editing -->
+                    <div id="formateditprefs">
+                        <xsl:variable name="formatedit"><xsl:choose><xsl:when test="/page/pageRequest/paramList/param[@name='formatedit']"><xsl:value-of select="/page/pageRequest/paramList/param[@name='formatedit']/@value"/></xsl:when><xsl:otherwise>off</xsl:otherwise></xsl:choose></xsl:variable>
+                        <div class="paramLabel">
+                            <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'pref.formatedit')"/>
+                        </div>
+                        <div class="paramValue">
+                            <select name="formatedit">
+                                <option value="on"><xsl:if test="$formatedit='on'"><xsl:attribute name="selected"></xsl:attribute></xsl:if><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'pref.formatedit.on')"/></option>
+                                <option value="off"><xsl:if test="$formatedit='off'"><xsl:attribute name="selected"></xsl:attribute></xsl:if><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'pref.formatedit.off')"/></option>
+                            </select>
+                        </div>
+                        <br class="clear"/>
+                    </div>
 				</div>
 
