Index: typo3/template.php
===================================================================
--- typo3/template.php	(revision 2956)
+++ typo3/template.php	(working copy)
@@ -1805,10 +1805,26 @@
 			}
 		}
 	}
+
+
+	/**
+	 * Function to load a HTML template file with markers. Can be overriden with  
+	 * 
+	 * @param	string		tmpl name, usually in the typo3/template/ directory, can be overriden by 
+	 * @param	string		Default width/height, defined like 'width="12" height="14"'
+	 * @param	integer		Mode: 0 (zero) is default and returns src/width/height. 1 returns value of src+backpath, 2 returns value of w/h.
+	 * @return	string		Returns ' src="[backPath][src]" [wHattribs]'
+	 * @see skinImgFile()
+	 */
+	function getHtmlTemplate($filename)	{
+		if ($GLOBALS['TBE_STYLES']['htmlTemplates'][$filename]) {
+			$filename = $GLOBALS['TBE_STYLES']['htmlTemplates'][$filename];
+		}
+		return ($filename ? t3lib_div::getURL($this->backPath.$filename) : '');
+	}
 }
 
 
-
 // ******************************
 // Extension classes of the template class.
 // These are meant to provide backend screens with different widths.
Index: typo3/alt_doc.php
===================================================================
--- typo3/alt_doc.php	(revision 2956)
+++ typo3/alt_doc.php	(working copy)
@@ -139,6 +139,7 @@
 	 * @var mediumDoc
 	 */
 	var $doc;
+	var $template;			// a static HTML template, usually in templates/alt_doc.html
 	var $content;			// Content accumulation
 
 	var $retUrl;			// Return URL script, processed. This contains the script (if any) that we should RETURN TO from the alt_doc.php script IF we press the close button. Thus this variable is normally passed along from the calling script so we can properly return if needed.
@@ -251,9 +252,8 @@
 	 *
 	 * @return	boolean		True, then save the document (data submitted)
 	 */
-	function doProcessData()	{
-		$out = $this->doSave || isset($_POST['_savedok_x']) || isset($_POST['_saveandclosedok_x']) || isset($_POST['_savedokview_x']) || isset($_POST['_savedoknew_x']);
-		return $out;
+	function doProcessData() {
+		return ($this->doSave || isset($_POST['_savedok_x']) || isset($_POST['_saveandclosedok_x']) || isset($_POST['_savedokview_x']) || isset($_POST['_savedoknew_x']));
 	}
 
 
@@ -443,6 +443,7 @@
 
 			// Create an instance of the document template object
 		$this->doc = t3lib_div::makeInstance('template');
+		$this->template = $this->doc->getHtmlTemplate('templates/alt_doc.html');
 		$this->doc->divClass = 'typo3-fullDoc';
 		$this->doc->backPath = $BACK_PATH;
 		$this->doc->docType = 'xhtml_trans';
@@ -515,8 +516,7 @@
 		global $BE_USER,$LANG;
 
 			// Starting content accumulation:
-		$this->content='';
-		$this->content.=$this->doc->startPage('TYPO3 Edit Document');
+		$this->content = $this->doc->startPage('TYPO3 Edit Document');
 
 			// Begin edit:
 		if (is_array($this->editconf))	{
@@ -546,6 +546,8 @@
 				// Creating the editing form, wrap it with buttons, document selector etc.
 			$editForm = $this->makeEditForm();
 
+
+
 			if ($editForm)	{
 				$this->firstEl = reset($this->elementsData);
 
@@ -556,7 +558,6 @@
 					$this->tceforms->printNeededJSFunctions_top().
 					$this->compileHeader().'
 	<div id="typo3-docbody">'.
-					$this->extraFormHeaders.
 					$this->compileForm($editForm).
 					$this->tceforms->printNeededJSFunctions().
 					$this->functionMenus().
@@ -817,7 +818,7 @@
 	 */
 	function getButtons()	{
 		global $TCA,$LANG;
-		$buttons = array();
+		$buttons = array('save' => '', 'save_view' => '', 'save_new' => '', 'save_close' => '', 'close' => '', 'delete' => '', 'undo' => '', 'history' => '', 'columns_only' => '');
 
 			// Render SAVE type buttons:
 			// The action of each button is decided by its name attribute. (See doProcessData())
@@ -882,6 +883,7 @@
 			}
 		}
 		$buttons['shortcut'] = $this->shortCutLink();
+		$buttons['open_in_new_window'] = $this->openInNewWindowLink();
 		return $buttons;
 	}
 
@@ -893,7 +895,7 @@
 	 * @return	string		HTML <select> element  (if applicable)
 	 */
 	function makeDocSel()	{
-		global $BE_USER,$LANG;
+		global $BE_USER, $LANG;
 
 		$docSel = '';
 			// Render the selector ONLY if it has not been disabled:
@@ -949,7 +951,8 @@
 
 
 	/**
-	 * Put together the various elements for the header
+	 * Put together the various elements for the header using a static HTML
+	 * template
 	 *
 	 * @return	string		Composite HTML
 	 */
@@ -957,37 +960,63 @@
 		global $LANG;
 
 		$btns = $this->getButtons();
-		$docSel = $this->makeDocSel();
-		$cMenu = $this->makeCmenu();
+		$content = t3lib_parsehtml::getSubpart($this->template, '###DOCHEADER###');
 
-		$content = '
-	<!-- Page header with buttons for saving & closing and path details -->
-	<div id="typo3-docheader">
-		<div id="typo3-docheader-row1">
-			<div class="buttonsleft">'.$btns['save'].$btns['save_view'].$btns['save_close'].$btns['save_new'].'</div>
-			<div class="buttonsright">'.$docSel.$cMenu.$btns['delete'].$btns['shortcut'].$btns['history'].$buttons['columns_only'].$btns['undo'].$btns['close'].'</div>
-		</div>
-		';
+		$markerArray = array();
+		$markerArray['DOCUMENT_SELECTOR'] = $this->makeDocSel();
+		$markerArray['CACHE_MENU'] = $this->makeCmenu();
+		$markerArray['PAGEPATH'] = $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path',1).': '.htmlspecialchars($this->generalPathOfForm);
 
-		if (is_array($this->tceforms->extraFormHeaders))	{
-			$this->extraFormHeaders = '<div id="typo3-docheader-rowextra">'.implode(chr(10), $this->tceforms->extraFormHeaders).'</div>';
+
+			// -- compiling buttons --
+			// get button template, then loop through the buttons and replace them in the template
+		$btnTmpl = t3lib_parsehtml::getSubpart($this->template, '###BUTTON_GROUPS###');
+		$btnTmpl = t3lib_parsehtml::substituteMarkerArray($btnTmpl, $btns, '###|###', true);
+
+			// getting the wrap for each group
+		$btnWrap = t3lib_parsehtml::getSubpart($this->template, '###BUTTON_GROUP_WRAP###');
+
+			// looping through the groups (max 6) and remove the empty groups
+		$grpId = 1;
+		for ($grpNum = 1; $grpNum < 6; $grpNum++) {
+			$btnMarker = '###BUTTON_GROUP'.$grpNum.'###';
+			$btnGroup = t3lib_parsehtml::getSubpart($btnTmpl, $btnMarker);
+			if (trim($btnGroup)) {
+				if ($btnWrap) {
+					$btnGroup = t3lib_parsehtml::substituteMarker($btnWrap, '###BUTTONS###', $btnGroup);
+				}
+				$btnTmpl = t3lib_parsehtml::substituteSubpart($btnTmpl, $btnMarker, trim($btnGroup));
+			}
 		}
 
+			// replace the marker with the template and remove all line breaks (for IE compat)
+		$markerArray['BUTTONLIST'] = str_replace("\n", '', $btnTmpl);
+			// -- end compiling buttons
 
-			// language switch/selector for editing
-			// show only when a single record is edited - multiple records are too confusing
+
+			// language switch/selector for editing, show only when a single record is edited
+			// - multiple records are too confusing
 		if (count($this->elementsData) == 1) {
-			$langSelector = '<div class="langselector">'.$this->languageSwitch($this->firstEl['table'], $this->firstEl['uid'], $this->firstEl['pid']).'</div>';
+			$langSelector = $this->languageSwitch($this->firstEl['table'], $this->firstEl['uid'], $this->firstEl['pid']);
 		}
+		if ($langSelector) {
+			$langTmpl = t3lib_parsehtml::getSubpart($this->template, '###DOCHEADER_LANGSELECTOR###');
+			$langTmpl = t3lib_parsehtml::substituteMarker($langTmpl, '###LANGSELECTOR###', $langSelector);
+			$markerArray['LANGSELECTOR'] = $langTmpl;
+		} else {
+			$markerArray['LANGSELECTOR'] = '';
+		}
 
-		
-		$content.='
-		<div id="typo3-docheader-row2">
-			<div class="pagepath">'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path',1).': '.htmlspecialchars($this->generalPathOfForm).'</div>
-			<div class="infooptions">'.$langSelector.'</div>
-		</div>
-	</div>';
-		return $content;
+		if (is_array($this->tceforms->extraFormHeaders)) {
+			$extraTmpl = t3lib_parsehtml::getSubpart($this->template, '###DOCHEADER_EXTRAHEADER###');
+			$extraTmpl = t3lib_parsehtml::substituteMarker($extraTmpl, '###EXTRAHEADER###', implode(chr(10), $this->tceforms->extraFormHeaders));
+			$markerArray['EXTRAHEADER'] = $extraTmpl;
+		} else {
+			$markerArray['EXTRAHEADER'] = '';
+		}
+
+			// replacing all markers with the finished markers and return the HTML content
+		return t3lib_parsehtml::substituteMarkerArray($content, $markerArray, '###|###');
 	}
 
 
@@ -1059,11 +1088,11 @@
 	 * @return	string
 	 */
 	function openInNewWindowLink()	{
-		global $BE_USER,$LANG;
+		global $BE_USER, $LANG;
 		if ($this->returnUrl == 'close.html') {
 			return '';
 		}
-		$aOnClick = 'vHWin=window.open(\''.t3lib_div::linkThisScript(array('returnUrl'=>'close.html')).'\',\''.md5($this->R_URI).'\',\''.($BE_USER->uc['edit_wideDocument']?'width=670,height=500':'width=600,height=400').',status=0,menubar=0,scrollbars=1,resizable=1\');vHWin.focus();return false;';
+		$aOnClick = 'vHWin=window.open(\''.t3lib_div::linkThisScript(array('returnUrl'=>'close.html')).'\',\''.md5($this->R_URI).'\',\'width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1\');vHWin.focus();return false;';
 		return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
 				'<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/open_in_new_window.gif','width="19" height="14"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.openInNewWindow',1).'" alt="" /></a>';
 	}
Index: typo3/stylesheet.css
===================================================================
--- typo3/stylesheet.css	(revision 2956)
+++ typo3/stylesheet.css	(working copy)
@@ -372,13 +372,14 @@
 div#typo3-docheader div.buttonsleft  { margin: 0 0 0 3px; line-height: 16px; float: left; }
 div#typo3-docheader div.buttonsright { margin: 0 3px 0 0; line-height: 16px; float: right; }
 div#typo3-docheader img, div#typo3-docheader input { margin: 2px 3px 0; vertical-align: top; }
-div#typo3-docheader img.typo3-csh-icon { margin: 2px 15px 0 2px; }
-div#typo3-docheader select { margin: 2px 0 0; }
+div#typo3-docheader img.typo3-csh-icon { margin: 2px 2px 0 2px; }
+div#typo3-docheader select { margin: 1px 0 0; }
 div#typo3-docheader div.pagepath { margin-left: 6px; float: left; }
 div#typo3-docheader div.infooptions { margin-right: 6px; float: right; }
 div#typo3-docbody { width: 98%; padding: 2% 0% 2% 2%; overflow: auto; top: 49px; bottom: 0; position: absolute; z-index: 2; }
 * html div#typo3-docbody { height: 90%; top: 49px; padding-top: 0; padding-bottom: 0; }
 * html div#typo3-docbody table.typo3-TCEforms { margin-top: 20px; }
+div#typo3-docheader div.buttongroup { height: 20px; float: left; padding-right: 20px; border-right: 1px dashed #ccc; margin-right: 5px; }
 
 /* Login Screen
 
Index: typo3/templates/alt_doc.html
===================================================================
--- typo3/templates/alt_doc.html	(revision 0)
+++ typo3/templates/alt_doc.html	(revision 0)
@@ -0,0 +1,37 @@
+<!-- ###DOCHEADER### -->
+	<!-- Page header with buttons for saving & closing and path details -->
+	<div id="typo3-docheader">
+		<div id="typo3-docheader-row1">
+			<div class="buttonsleft">###BUTTONLIST###</div>
+			<div class="buttonsright">###DOCUMENT_SELECTOR### ###CACHE_MENU###</div>
+		</div>
+		<div id="typo3-docheader-row2">
+			<div class="pagepath">###PAGEPATH###</div>
+			<div class="infooptions">###LANGSELECTOR###</div>
+		</div>
+		###EXTRAHEADER###
+	</div>
+<!-- ###DOCHEADER### -->
+
+<!-- ###DOCHEADER_EXTRAHEADER### -->
+		<div id="typo3-docheader-rowextra">###EXTRAHEADER###</div>
+<!-- ###DOCHEADER_EXTRAHEADER### -->
+
+<!-- ###DOCHEADER_LANGSELECTOR### -->
+<div class="langselector">###LANGSELECTOR###</div>
+<!-- ###DOCHEADER_LANGSELECTOR### -->
+
+
+<!-- Grouping the icons on top -->
+
+<!-- ###BUTTON_GROUP_WRAP### -->
+	<div class="buttongroup">###BUTTONS###</div>
+<!-- ###BUTTON_GROUP_WRAP### -->
+
+<!-- ###BUTTON_GROUPS### -->
+<!-- ###BUTTON_GROUP1### -->###CLOSE###<!-- ###BUTTON_GROUP1### -->
+<!-- ###BUTTON_GROUP2### -->###SAVE######SAVE_VIEW######SAVE_CLOSE######SAVE_NEW###<!-- ###BUTTON_GROUP2### -->
+<!-- ###BUTTON_GROUP3### -->###DELETE######UNDO######HISTORY###<!-- ###BUTTON_GROUP3### -->
+<!-- ###BUTTON_GROUP4### -->###SHORTCUT######COLUMNS_ONLY######OPEN_IN_NEW_WINDOW###<!-- ###BUTTON_GROUP4### -->
+<!-- ###BUTTON_GROUPS### -->
+
