###
### Main "edit" template
###
### General wrapper for edit actions
###
##
## Is the document being edited by another user?
## If yes, warn about it and show a forcing link:
##
#if($tdoc.getLocked() && "$!request.get('force')" == '')
  #template("startpage.vm")
  <div class="main layoutsubsection">
   <div id="mainContentArea">
    ##
    $response.setStatus(423)
    #set($newquerystring = "$!{request.getQueryString().replaceAll('&', '&amp;').replaceAll('&amp;amp;', '&amp;')}"
                         + '&amp;force=1')
    #set($forceEditURL = $doc.getURL($xcontext.getAction(), ${newquerystring}))
    #xwikimessageboxstart($msg.get('notice') "$msg.get('doclockedby') $xwiki.getUserName($doc.getLockingUser())")
    <a href="$forceEditURL">$msg.get('forcelock')</a>
    #xwikimessageboxend()
    ##
   </div>## mainContentArea
  </div>## main layoutsubsection
  #template("endpage.vm")
#else
  ##
  ## Determine what editor to show
  ##
  $xwiki.jsfx.use('js/scriptaculous/scriptaculous.js')
  #if("$!editor" == '')
    ## Normally no special characters should exist in the editor parameter, so this is just a protection measure.
    #set($editor = "$!{escapetool.xml($request.getParameter('editor'))}")
    #if($editor == '')
      #if(($xwiki.getUserPreference('editor') == 'Wysiwyg') && ($doc.syntax.toIdString() != 'xwiki/1.0' || !$doc.isAdvancedContent()))
        #set($editor = 'wysiwyg')
      #else
        #set($editor = 'wiki')
      #end
    #end
  #end
  ##
  ## "Compute" the title
  ##
  #set($title = $xwiki.parseContent($msg.get('editpageTitle')))
  ##
  ## Header
  ##
  #template("xwikivars.vm")
  #template("layoutvars.vm")
  #template("htmlheader.vm")
  #template("header.vm")
  #template("menuedit.vm")
  #if($editor == 'wiki' || $editor == 'wysiwyg')
    <form id="edit" method="post" action="$doc.getURL('preview')" >
    <div class="hidden">
    ## CSRF prevention
    <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" />
    ## Pass the section number when the form is submitted in order to affect only the specified section.
    ## We need to test if the section number is present to prevent a NumberFormatException for the empty string.
    #if("$!{request.section}" != '')
      <input type="hidden" name="section" value="$!{escapetool.xml($request.section)}" />
    #end
    ## This input is used by the full screen widget: it stores the selector of the maximized element, so that the full screen can be restored when coming back from preview.
    <input type="hidden" name="x-maximized" value="$!{escapetool.xml($request.get('x-maximized'))}"/>
    </div>
  #end
  ##################
  ##   Edit zone  ##
  ##################
  
    <div id="contentcontainerinner">
	
	 <div class="bg-top">
		<div class="bg-top-left">
			<div class="bg-top-right">
			</div>## top right
		</div>## top left
	</div>## top
	<div class="contentinline">
  
  <div id="xwikieditor" class="layoutsection">
  <div id="xwikieditorinner">
  <div class="leftsidecolumns">
  <div id="editcolumn" class="editor editor-${editor}">
  <div class="alleditcontent">
  <div id="editmenu" class="actionmenu">
  #template("editmenu.vm")
  </div>
  <div id="mainEditArea">
  #template("hierarchy.vm")
  #if (($editor == 'wiki' || $editor == 'wysiwyg') && !$request.section)
    #template('editmeta.vm')
  #end
  #template("editmodes.vm")
  #template("edit${editor}.vm")
  ## This javascript must be placed here since it uses velocity variables set in the template above.
  <script type="text/javascript">
    //<![CDATA[
    if ($('tmEditWysiwyg')) {
      // Manage switch from wiki to wysiwyg, content must be preserved between those editors.
      Event.observe($('tmEditWysiwyg'), "click", function(event) {
        #if($doc.syntax.toIdString() == "xwiki/1.0")
        if (checkAdvancedContent('$msg.get("checkadvancedcontent")') == false) {
          Event.stop(event);
          return;
        }
        #end
        document.forms.${formname}.action='$doc.getURL("edit", "editor=wysiwyg&$languageparams")';
        document.forms.${formname}.submit();
        Event.stop(event);
      });

      // Manage switch from wysiwyg to wiki, content must be preserved between those editors.
      Event.observe($('tmEditWiki'), "click", function(event) {
        document.forms.${formname}.action='$doc.getURL("edit", "editor=wiki&$languageparams")';
        document.forms.${formname}.submit();
        Event.stop(event);
      });
    }
    //]]>
  </script>
  </div> ## mainEditArea
  </div> ## alleditcontent
  </div> ## editcolumn
  <div class="clearfloats"></div>
  </div> ## leftsidecolumns
  #template("editpanels.vm")
  <div class="clearfloats"></div>
  </div> ## xwikieditorinner
  </div> ## xwikieditor
  
   </div> ##contentinline
    <div class="bg-bottom">
      <div class="bg-bottom-left">
	  <div class="bg-bottom-right">
	  </div>## bottom right
	</div>## bottom left
  </div>## bg-bottom
</div> ## contentcontainerinner
  
  ##
  ## Footer
  ##
  #if($editor == 'wiki' || $editor == 'wysiwyg')
    </form>
  #end
  #template("footer.vm")
  #template("htmlfooter.vm")
#end
