
/* JavaScript library */

/******************************************************************/
/*																						*/
/*		Author: Daniel Fuchs. 													*/
/*																						*/
/*		This software is free according to the terms of the 			*/
/*		GNU General Public License Version 3.								*/
/*																						*/
/*		http://www.fsf.org/licensing/licenses/gpl.html					*/
/*																						*/
/******************************************************************/

//---------------------------------------------------------------------------


/* Public Variables */

//---------------------------------------------------------------------------

var PUBLIC_domain_name = "baumfuchs.de";
/* The domain without the "www." prefix. Is needed in order to decide which
URLs are internal ones. */

var PUBLIC_contents_folder = "inhalt"; 
/* Folder for all pages that appear in the "contents" frame 
and can be edited by non-programmers. 
Must be located in the base folder of the web site. */

var PUBLIC_stylesheet_folder = "css";
/* Folder that keeps all stylesheets. */

var PUBLIC_font_size = 11;
/* Base font size in pt. */

var PUBLIC_menu_bullet_image = "../_symbole/bullet.png";
/* URL of an image to show as a bullet to the selected menu item.
URL is relative to the folder where the menu file resides.
If "" is given, the menu will use 'disc' list bullets. */

var PUBLIC_menu_selected_color = "#ffffff";
/* Text color for the selected menu item. */

var PUBLIC_menu_color = "#004000";
/* Text color for non-selected menu items. Must be given here 
additionally to the stylesheet. */ 

var PUBLIC_selected_background_color = "#007700";
/* Background color for selected menu items. */

var PUBLIC_background_color = "#fdffd0";
/* The background color of the menu area. */

var PUBLIC_min_menu_width = 200;
/* The minimum width of the navigation bar. */

var PUBLIC_max_menu_width = 800;
/* The maximum width of the navigation bar. */

var PUBLIC_start_page = "inhalt/start/_seite.htm";
/* Location of the start page relative to the base folder of the webspace. */

var PUBLIC_start_page_name = "Wissenswertes über Alleen";
/* Location string for the start page when no menu item has been clicked yet. */
 
var PUBLIC_location_separator = " > ";
/* A string to concatenate the parts of the current location when displayed. */

var PUBLIC_internal_link_symbol = "_symbole/weiter.png";
/* A symbol image that is to be put in front of each internal link.
Give "" in order to disable this feature. */

var PUBLIC_preview_links = true;
/* Sets whether preview images for internal links should be displayed.
For each page an image named "_icon.png" should be given in the same folder. */ 

var PUBLIC_preview_width = 100;
/* The default width of a link preview image. Must be given for correct
positioning. */

var PUBLIC_preview_height = 100;
/* The default height of a link preview image. Must be given for correct
positioning. */

//---------------------------------------------------------------------------


/* Private Variables */

//---------------------------------------------------------------------------

var PRIVATE_browser_engine = "";

var PRIVATE_info_opacity = 100;

var PRIVATE_resizing_table = false;

var PRIVATE_last_mouse_x = 0;

var PRIVATE_mouse_x = 0;

var PRIVATE_selected_paragraph = null;

var PRIVATE_hide_preview_timeout = null;

var PRIVATE_check_preview_interval = null;

//---------------------------------------------------------------------------


/* Script code */

/* DO NOT MODIFY */

//---------------------------------------------------------------------------


/* Adaptation of the web site to browser and platform */

//---------------------------------------------------------------------------

function badBrowser() 
/* Returns True if Microsoft Internet Explorer is being used. */
	{
	if(PRIVATE_browser_engine == "trident")
		{
		return true;
		}
	else
		{
		return false;
		}
	}	 	

//---------------------------------------------------------------------------

function strangeBrowser()
/* Returns True for Opera and Konqueror. */
	{
	if((PRIVATE_browser_engine == "khtml") || (PRIVATE_browser_engine == "presto"))
		{
		return true;
		}
	else
		{
		return false;
		}
	}
	
//---------------------------------------------------------------------------

function badOS()
/* Returns True if Microsoft Windows is being used. */
	{
	var os = navigator.platform.toLowerCase();
	if(os.indexOf("win") >= 0)
		{
		return true;
		}
	else
		{
		return false;
		}
	}		

//---------------------------------------------------------------------------


/* Cookie operations */

//---------------------------------------------------------------------------

function getCookies(doc)
/* Returns the cookies associated with the given document as a string array. */
	{
	var cookie = doc.cookie;
	var cookies;
	cookies = cookie.split(";")
	for(var i = 0; i < cookies.length; i++)
		{
		cookies[i] = trimString(cookies[i]);
		}
	return cookies;
	}
			
//---------------------------------------------------------------------------

function getCookieValue(doc, name)
/* Returns the value of a cookie of the given name or "" if there is no such 
cookie associated with the document. */
	{
	var cookies = getCookies(doc);
	for(var i = 0; i < cookies.length; i++)
		{
		var items = cookies[i].split("=");
		if(trimString(items[0]) == name)
			{
			if(items.length > 1)
				{
				return trimString(items[1])
				}
			else
				{
				return "";
				}
			}
		}
	return "";
	}	
	
//---------------------------------------------------------------------------

function setCookie(doc, name, value, expire_days) 
/* Sets a cookie according to the given parameters. If expire_days equals 0,
the cookie will be session-wide only. Thanks to Peter-Paul Koch
of www.quirksmode.org ! */
	{
	var expires;
	if (expire_days != 0) 
		{
		var date = new Date();
		date.setTime(date.getTime() + (expire_days * 24 * 60 * 60 * 1000));
		expires = "; expires=" + date.toGMTString();
		}
	else 
		{
		expires = "";
		}
	doc.cookie = name + "=" + value + expires + "; path=/";
	}

//---------------------------------------------------------------------------

function deleteCookie(doc, name)
/* Deletes the cookie of the given name for the given document. */
	{
	setCookie(doc, name, "", -1);
	}

//---------------------------------------------------------------------------

function saveFontSize()
/* Tries to save PUBLIC_font_size to a cookie.*/
	{
	if(navigator.cookieEnabled)
		{
		setCookie(top.document, "FONT_SIZE", String(PUBLIC_font_size), 0);
		}
	}

//---------------------------------------------------------------------------

function getSavedFontSize()
/* Tries to read the base font size from a cookie. The default value
if no cookie is set is that of PUBLIC_font_size. */
	{
	var font_size_str = getCookieValue(top.document, "FONT_SIZE");
	if(font_size_str != "")
		{	
		try
			{	
			return parseInt(font_size_str);
			}
		catch(err1)
			{}
		}
	return PUBLIC_font_size;
	}
	
//---------------------------------------------------------------------------

function getSavedLocation()
	{
	return getCookieValue(top.document, "LOCATION");
	}

//---------------------------------------------------------------------------


function initWebsite()
/* Initializes the browser engine variable. */
	{
	var app_name = navigator.appName.toLowerCase();
	var app_version = navigator.appVersion.toLowerCase();
	if(app_name.indexOf("microsoft") >= 0)
		{
		PRIVATE_browser_engine = "trident";
		}
	else if(app_name.indexOf("konqueror") >= 0)
		{
		PRIVATE_browser_engine = "khtml";
		}
	else if(app_name.indexOf("opera") >= 0)
		{
		PRIVATE_browser_engine = "presto";
		}
	else if(app_version.indexOf("chrome") >= 0)
		{
		PRIVATE_browser_engine = "webkit_chrome";
		}
	else if(app_version.indexOf("safari") >= 0)
		{
		PRIVATE_browser_engine = "webkit_safari";
		}
	else
		{
		PRIVATE_browser_engine = "gecko";
		}
	PUBLIC_font_size = getSavedFontSize();
	}

//---------------------------------------------------------------------------

function getGlobalFontSizeString()
	{
	return String(PUBLIC_font_size) + "pt";
	}
	
//---------------------------------------------------------------------------

function prepareWebsite()
/* Initializes global event handling. */
	{
	var location = getSavedLocation();
	if(location != "")
		{
		top.contents.location.href = location;
		deleteCookie(top.document, "LOCATION");
		}
	if(0==0) //!badBrowser())
		{
		if(top.document.captureEvents)
			{
			top.document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
			}
		top.document.onmousemove = getMouseX;
		top.document.onmouseup = stopResizeTable;
		if(top.captureEvents)
			{
			top.captureEvents(Event.RESIZE | Event.FOCUS);
			}
		top.onresize = resizeWindow;
		top.onfocus = resetLayout;
		}
	if(badBrowser())
		{
		top.document.body.onresize = resizeWindow; // IE does not fire a resize event when the window size changes. This workaround is not standard-compliant because body.onresize is not allowed, strictly spoken!
		}
	resetLayout();
	updateToolButtons();
	if(strangeBrowser())
		{
		top.document.getElementById("resize_handle").style.cursor = "e-resize";
		top.document.getElementById("menu_frame").style.paddingBottom = "32px";
		top.document.getElementById("contents_frame").style.paddingBottom = "32px";
		}	
	if(badBrowser())
		{
		PUBLIC_menu_bullet_image = "";
		}
	if(!badBrowser())
		{
		var navigation_width = String(Math.round(top.innerWidth * 0.3)) + "px"; // Firefox does not correctly calculate the style.width: 30% declaration.
		top.document.getElementById("navigation").style.width = navigation_width;
		}
	if(PRIVATE_browser_engine == "webkit_chrome")
		{
		top.document.getElementById("no_support").style.display = "block";
		}
	else
		{
		top.setTimeout("showWebsite()", 10);
		}
	}

//---------------------------------------------------------------------------

function checkPreview()
	{
	var preview = top.document.getElementById("page_preview");
	var pane = top.document.getElementById("preview_pane");
	if((pane.style.display != "none") && (preview.offsetWidth < 10))
		{
		doHidePreview();
		}
	}

//---------------------------------------------------------------------------
	
function showWebsite()
	{
	top.document.getElementById("window_div").style.display = "block";
	top.setTimeout("resizeWindow()", 100);
	}
	
//---------------------------------------------------------------------------
	
function resetLayout()
	{
/*	top.document.getElementsByTagName("body")[0].style.fontSize = getGlobalFontSizeString();
	try
		{
		ZoomManager.prototype.getInstance().reset();
		}
	catch(err1)
		{} */
	}
	
//---------------------------------------------------------------------------

function showInfo()
	{
//	top.document.getElementById("info").style.visibility = "visible";
//	top.setTimeout("hideInfo()", 8000);
	}

//---------------------------------------------------------------------------

/* function fadeInfo()
	{
	if(PRIVATE_info_opacity >= 0)
		{
		if(badBrowser())
			{
			top.document.getElementById("info").filters.alpha.opacity = PRIVATE_info_opacity; // -->runtime error
			}
		else
			{
			top.document.getElementById("info").style.opacity = PRIVATE_info_opacity / 100;
			}
		PRIVATE_info_opacity -= 5;
		top.setTimeout("fadeInfo()", 100);
		}
	else
		{
		hideInfo();
		PRIVATE_info_opacity = 100;
		}
	} */
	
//---------------------------------------------------------------------------
	
function hideInfo()
	{
	if(badBrowser())
		{
//		top.document.getElementById("info").filters.alpha.opacity = 0;
		}
	else
		{
//		top.document.getElementById("info").style.opacity = 0;
		}
//	top.document.getElementById("info").style.visibility = "hidden";
	}

//---------------------------------------------------------------------------

function resizeWindow()
	{
	if(PRIVATE_browser_engine == "khtml")
		{
		adaptMenuHeight();
		}
	if(!top.document.getElementById("top_row"))
		{
		return
		}
	var image_string = "url(" + getTitleBackgroundURL() + ")"; 
	var cells = top.document.getElementById("top_row").getElementsByTagName("td");
	for(var i = 0; i < cells.length; i++)
		{
		cells[i].style.backgroundImage = image_string;
		}
	}

//---------------------------------------------------------------------------

function updateToolButtons()
	{
	var ext = "png";	
	if(badBrowser())
		{
		ext = "gif";
		}
//	top.document.getElementById("bookmark").src = "img/bookmark." + ext;
	if(PUBLIC_font_size < 6)
		{
		top.document.getElementById("decrease").disabled = true;
		top.document.getElementById("decrease").src = "img/zoom-out-disabled." + ext;
		top.document.getElementById("decrease").blur();
		return;
		}
	if(PUBLIC_font_size > 16)
		{
		top.document.getElementById("increase").disabled = true;
		top.document.getElementById("increase").src = "img/zoom-in-disabled." + ext;
		top.document.getElementById("increase").blur();
		return;
		}
	top.document.getElementById("decrease").disabled = false;
	top.document.getElementById("decrease").src = "img/zoom-out." + ext;
	top.document.getElementById("increase").disabled = false;
	top.document.getElementById("increase").src = "img/zoom-in." + ext;
	}

//---------------------------------------------------------------------------
	
function decreaseFontSize()
	{
	if(top.document.getElementById("decrease").disabled)
		{
		return;
		}
	PUBLIC_font_size -= 1;
	saveFontSize();
	if(!badBrowser())
		{
		//hideMenu();
		}
	top.menu.document.getElementsByTagName("body")[0].style.fontSize = getGlobalFontSizeString();
//	tuneStyles(top.contents.document, PUBLIC_stylesheet_folder + "/normal/" + "contents.css");
	top.contents.document.getElementsByTagName("body")[0].style.fontSize = getGlobalFontSizeString();
	updateToolButtons();
	}
	
//---------------------------------------------------------------------------

function increaseFontSize()
	{
	if(top.document.getElementById("increase").disabled)
		{
		return;
		}
	PUBLIC_font_size += 1;
	saveFontSize();
	if(!badBrowser())
		{
		//hideMenu();
		}
	top.menu.document.getElementsByTagName("body")[0].style.fontSize = getGlobalFontSizeString();
//	tuneStyles(top.contents.document, PUBLIC_stylesheet_folder + "/normal/" + "contents.css");
	top.contents.document.getElementsByTagName("body")[0].style.fontSize = getGlobalFontSizeString();
	updateToolButtons();
	}
	
//---------------------------------------------------------------------------

function setBookmark()
	{
/*	var title = top.contents.document.title; 
	var url = top.contents.document.URL;
	if(badBrowser())
		{
		window.external.AddFavorite(url, title);
		}
	else // if(PRIVATE_browser_engine == "gecko")
		{
		window.sidebar.addPanel(title, url, "");
		} */
	}

//---------------------------------------------------------------------------

function editSettings()
	{
	top.showModalDialog("inhalt/einstellungen/_seite.htm", "", "center:yes; dialogHeight:300; dialogWidth:500; status:no;");
//	top.contents.location.href = "inhalt/einstellungen/_seite.htm";
	}
	
//---------------------------------------------------------------------------


/* String functions */

//---------------------------------------------------------------------------

function trimString(text)
/* Removes leading and trailing space characters from a string and returns 
the result. */
	{
	var new_text = text;
	while(new_text.substr(0, 1) == " ")
		{
		new_text = new_text.substr(1);
		}
	while(new_text.substr(new_text.length - 1, 1) == " ")
		{
		new_text = new_text.substr(0, new_text.length - 1);
		}
	return new_text;
	}
	
//---------------------------------------------------------------------------
	
function parseText(text) 
/* Turns multiple spaces, line breaks and tabs in a string into single spaces
like a web browser would do. Does not remove single leading or trailing 
whitespace characters! */
	{
	var new_text = "";
	var state = 0;
	var code, i;
	for(i = 0; i < text.length; i++)
		{
		code = text.charCodeAt(i);
		if (code == 9 || code == 10 || code == 13 || code == 32)
			{
			if(state === 0)
				{
				new_text = new_text + " ";
				state = 1;
				}
			}
		else
			{
			new_text = new_text + text.charAt(i);
			state = 0;
			}
		}
	return new_text;
	}

//---------------------------------------------------------------------------

function usesBackslash(url)
/* Returns true if the given URL contains backslashes which is indicating 
that the web site is run on a windows platform. */
	{
	var index = url.indexOf("\\");
	if(index != -1)
		{
		return true;
		}
	else
		{
		return false;
		}
	}

//---------------------------------------------------------------------------


/* URL navigation */

//---------------------------------------------------------------------------

function getLevel(doc) 
/* Returns the level of a document in the hierarchy of contents. 
A document located in the PUBLIC_contents_folder directory will have level 0.
The base folder of the web space has level -1. */
	{
	var level = -1;
	var index = doc.URL.indexOf(PUBLIC_contents_folder);
	if(index != -1)
		{
		while(index < doc.URL.length)
			{
			if (usesBackslash(doc.URL))
				{
				index = doc.URL.indexOf("\\", index);
				}
			else
				{
				index = doc.URL.indexOf("/", index);
				}
			if(index == -1) 
				{
				break;
				}
			level = level + 1;
			index = index + 1;
			}
		}
	return level;
	}

//---------------------------------------------------------------------------

function systemURL(url)
/* Converts the given URL to Windows syntax if Windows is used. */
	{
	if(isExternal(url))
		{
		return url;
		}
	var new_url = url;
	if(badOS() && !usesBackslash(url) && (url.indexOf("http:") == -1))
		{
		new_url = new_url.replace(/\//g, "\\");
		new_url = new_url.replace("file:\\\\\\", "file://");
		} 
	return new_url;
	}

//---------------------------------------------------------------------------

function navigateUpwards(url) 
/* Returns the parent directory of a URL with a trailing slash appended. */
	{
	var new_url = url;
	var index;
	if(usesBackslash(new_url))
		{
		index = new_url.lastIndexOf("\\", new_url.length - 2);
		}
	else
		{
		index = new_url.lastIndexOf("/", new_url.length - 2);
		}
	if(index != -1)
		{
		new_url = new_url.substring(0, index + 1);
		}
	if(new_url == url)
		{
		return "";
		}
	else
		{
		return new_url;
		}
	}

//---------------------------------------------------------------------------

function isHTML(url)
/* Returns true if the given URL points to a HTML file. */
	{
	var new_url = url.toLowerCase();
	if((new_url.substr(new_url.length - 4) == "html") || (new_url.substr(new_url.length - 3) == "htm") || (new_url.indexOf("#") >= 0))
		{
		return true;
		}
	else
		{
		return false;
		}
	}
	
//---------------------------------------------------------------------------

/*function isExternal(url) 
Returns true if the given URL points to an external web site.
	{
	if((url.indexOf("www.")) >= 0 || (url.indexOf("http:") >= 0))
		{
		if(url.indexOf(PUBLIC_domain_name) == -1)
			{
			return true;
			}
		else
			{
			return false;
			}
		}
	else
		{
		return false;
		}
	} */

function isExternal(url) 
/* Returns true if the given URL points to an external web site. */
	{
	if(top.document.domain === "")
		{
		if(url.indexOf("http:") == 0)
			{
			return true;
			}
		else
			{
			return false;
			}
		}
	else
		{
		if(url.indexOf("http:") >= 0)
			{
			if(url.indexOf(top.document.domain) == -1)
				{
				return true;
				}
			else
				{
				return false;
				}
			}
		else
			{
			return false;
			}
		}
	}


//---------------------------------------------------------------------------

function baseURL(url)
/* Returns the given URL without the fragment part, if any. */
	 {
	 var fragment_start = url.indexOf("#");
	 if(fragment_start == -1)
	 	{
	 	return url;
	 	}
	 else
	 	{
	 	return url.substr(0, fragment_start);
	 	}
	 }
	
//---------------------------------------------------------------------------

function fragmentURL(url)
/* Returns the fragment part of the given URL, or null, if there is no 
fragment part. */
	 {
	 var fragment_start = url.indexOf("#");
	 if(fragment_start == -1)
	 	{
	 	return null;
	 	}
	 else
	 	{
	 	return url.substr(fragment_start + 1);
	 	}
	 }
 
//---------------------------------------------------------------------------

function absoluteURL(doc, href) 
/* Returns the absolute URL of a link in any document 
up from level 1 - see getLevel(). */
	{
	if(isExternal(href))
		{
		return href;
		}
	var new_href = href;
	if((new_href.indexOf("file:") == -1) && (new_href.indexOf("http:") == -1))
		{
		var new_url = navigateUpwards(doc.URL);
		if(new_href.substr(0, 2) == "./")
			{
			new_href = new_href.substr(2);
			}
		while(new_href.substr(0, 3) == "../")
			{
			new_url = navigateUpwards(new_url);
			new_href = new_href.substr(3);
			}
		new_href = new_url + new_href;
		}
	return new_href;
	}

//---------------------------------------------------------------------------

function getTitleBackgroundURL()
/* Returns the URL of a suitable background image for the title bar. */
	{
	var row_height = top.document.getElementById("top_row").offsetHeight;
	var base_url = "img/backgrounds/%.png";
	var url;
	for(var i = 24; i <= 120; i = i + 8)
		{
		if(row_height <= i)
			{
			url = base_url.replace("%", String(i));
			return url;
			}
		}
	url = base_url.replace("%", "128");
	return url;
	}

//---------------------------------------------------------------------------

function getMenuBackgroundURL(paragraph)
/* Returns the URL of a suitable background image for the selected menu item. */
	{
	var height = paragraph.offsetHeight;
	var base_url = "../../img/backgrounds/%.png";
	for(var i = 24; i <= 120; i = i + 8)
		{
		if(height <= i)
			{
			url = base_url.replace("%", String(i));
			return url;
			}
		}
	url = base_url.replace("%", "128");
	return url;
	}
	
//---------------------------------------------------------------------------


/* General element construction and navigation */

//---------------------------------------------------------------------------

function parentElement(element, tagname) 
/* Returns the parent element of the given tag name to the given element
or null if there is no such element. */
	{
	if(!element.parentNode)
		{
		return null;
		}
	var new_element = element;
	do
		{
		new_element = new_element.parentNode;
		if (new_element.nodeName.toLowerCase() == "body")
			{
			return null;
			} 
		}
	while(new_element.nodeName.toLowerCase() != tagname.toLowerCase());
	return new_element;
	}

//---------------------------------------------------------------------------
	
function parentDocument(element) 
/* Returns the parent document to the given element. */
	{
	if(!element.parentNode)
		{
		return null;
		}
	var new_element = element;
	do
		{
		new_element = new_element.parentNode;
		}
	while(new_element.nodeType != 9);
	return new_element;
	}

//---------------------------------------------------------------------------

function childElement(element, tagname) 
/* Returns the first child element of the given tag name to the given element
or null if there is no such element. If "#text" is given as a tag name, will 
return the first next non-empty text child node, ignoring whitespace.*/
	{
	if(tagname == "#text")
		{
		var children = element.childNodes;
		for(var i = 0; i < children.length; i++)
			{
			if(children[i].nodeType == 3)
				{
				if(parseText(children[i].nodeValue) != " ")
					{
					return children[i];
					}
				}
			}
		return null;
		}
	else
		{
		var children = element.getElementsByTagName(tagname);
		if(children.length == 0)
			{
			return null;
			}
		else
			{
			return children[0];
			}
		}
	}

//---------------------------------------------------------------------------

function nextElement(element, tagname)
/* Returns the next sibling element of the given tag name to the given element
or null if there is no such element. If "#text" is given as a tag name, will 
return the next non-empty text node, ignoring whitespace. */
	{
	var next_element = element.nextSibling;
	if(!next_element)
		{
		return null;
		}
	if(tagname == "#text")
		{
		do
			{
			if(next_element.nodeType == 3)
				{
				if(parseText(next_element.nodeValue) != " ")
					{
					return next_element;
					}
				}
			next_element = next_element.nextSibling;
			}
		while(next_element);
		return null;
		}
	else
		{
		while(next_element.nodeName.toLowerCase() != tagname.toLowerCase())
			{
			if(!next_element.nextSibling)
				{
				return null;
				}
			next_element = next_element.nextSibling;
			}
		}
	return next_element;
	}
	
//---------------------------------------------------------------------------
	
function getMetaTag(doc, name)
/* Returns the contents of a meta tag or "" if the tag does not exist. */  
	{
	var meta_tags = doc.getElementsByTagName("meta");
	for(var i = 0; i < meta_tags.length; i++)
		{		
		if(meta_tags[i].name.toLowerCase() == name.toLowerCase())
			{
			return meta_tags[i].content;
			}
		}
	return "";
	}	

//---------------------------------------------------------------------------

function setEvent(doc, element, event, action)
/* Sets an event attribute to the given element. 
Must distinct between IE and other web browsers. */
	{
	if(badBrowser())
		{
		element.setAttribute(event, new Function(action));
		}
	else
		{
		var new_event = doc.createAttribute(event);
		new_event.nodeValue = action;
		element.setAttributeNode(new_event);
		}
	}

//---------------------------------------------------------------------------


/* Menu construction and navigation */

//---------------------------------------------------------------------------

function mainMenu()
/* Returns the main menu as a <ul> element. */
	{
	var doc = top.menu.document;
	return doc.getElementsByTagName("ul")[0];
	}

//---------------------------------------------------------------------------

	
//---------------------------------------------------------------------------

function selectMenu()
/* Updates the selection when hovering the menu. */
	{
	if(PRIVATE_selected_paragraph)
		{
		highlightParagraph();
		}
	var paragraphs = top.menu.document.getElementsByTagName("p");
	for(i = 0; i < paragraphs.length; i++)
		{
		if(paragraphs[i] !== PRIVATE_selected_paragraph)
			{
			resetParagraph(paragraphs[i])
			}
		}
	}
	
//---------------------------------------------------------------------------

function selectParagraph(paragraph)
/* Selects a menu paragraph or none if null is given. Must work with some delay
in order to suppress mouseover effects between a paragraph and its internal
link. */ 
	{
	PRIVATE_selected_paragraph = paragraph;
	self.setTimeout("selectMenu()", 10);	
	}
	
//---------------------------------------------------------------------------
	
function highlightParagraph()
/* This function actually highlights the selected paragraph. */ 
	{
	var paragraph = PRIVATE_selected_paragraph;
	paragraph.style.backgroundColor = PUBLIC_selected_background_color;
	paragraph.style.backgroundImage = "url(" + getMenuBackgroundURL(paragraph) + ")";
	paragraph.style.borderLeftColor = "#aaaaaa";
	paragraph.style.borderRightColor = "#000000";
	var links = paragraph.getElementsByTagName("a");
	if(links.length > 0)
		{
		links[0].style.color = PUBLIC_menu_selected_color;
		}
	}
	
//---------------------------------------------------------------------------

function resetParagraph(paragraph)
/* Removes highlighting from the selected paragraph. */ 
	{
	var links = paragraph.getElementsByTagName("a");
	if(links.length > 0)
		{
		links[0].style.color = PUBLIC_menu_color;
		}
	paragraph.style.backgroundImage = "none";
	paragraph.style.borderLeftColor = PUBLIC_background_color;
	paragraph.style.borderRightColor = PUBLIC_background_color;
	paragraph.style.backgroundColor = PUBLIC_background_color;
	}

//---------------------------------------------------------------------------

function scrollContentsIntoView()
/* Scrolls the contents down (out of the titlebar shadow). */ 
	{
	top.contents.scrollBy(0, -30);
	}

//---------------------------------------------------------------------------
	
function clickLink(event, link)
/* Mimics a mouse click on an internal link and cancels the genuine click
event given as a parameter. This is to unify the handling of events
from different sources. */
	{
	top.contents.location.href = link.href;
	if(link.href.indexOf("#") >= 0)
		{
		top.setTimeout("scrollContentsIntoView()", 1);
		}
	if(!badBrowser())
		{
		event.preventDefault();
		}
	return false;
	}
	
//---------------------------------------------------------------------------
	
//---------------------------------------------------------------------------

function tuneMenu(menu, level) 
/* Assigns proper class names to the given "menu" list 
and all its list items and makes the entire list item paragraphs
work as links when clicked. Works recursively on all submenus. */
	{
	var doc = top.menu.document;
	menu.className = "menu" + String(level);
	var children = menu.childNodes;
	var i, j, submenus, paragraphs, links;
	for(i = 0; i < children.length; i++)
		{
		if(children[i].nodeName.toLowerCase() == "li")
			{
			children[i].className = "menu" + String(level);	
			paragraphs = children[i].getElementsByTagName("p");
			if(paragraphs.length > 0)
				{
				setEvent(doc, paragraphs[0], "onmouseover", "selectParagraph(this); showPagePreview(event, this.firstChild)");
				setEvent(doc, paragraphs[0], "onmouseout", "selectParagraph(null); hidePagePreview(this)");
				setEvent(doc, paragraphs[0], "onclick", "clickLink(event, this.firstChild)");
				links = paragraphs[0].getElementsByTagName("a");
				if(links.length > 0)
					{
					setEvent(doc, links[0], "onmouseover", "selectParagraph(this.parentNode)");
					setEvent(doc, links[0], "onfocus", "selectParagraph(this.parentNode)");
					setEvent(doc, links[0], "onclick", "clickLink(event, this)");
//					setEvent(doc, links[0], "onblur", "resetParagraph(this.parentNode)");
					}
				}
			submenus = children[i].getElementsByTagName("ul");
			if(submenus.length > 0)
				{
				j = i;
				tuneMenu(submenus[0], Number(level + 1));
				i = j;
				}
			}
		}
	}

//---------------------------------------------------------------------------

function currentLink()
/* Returns the menu link that has opened the currently loaded document
or null if the document was loaded by a link outside the menu. */
	{
	try
		{
		var doc_url = systemURL(baseURL(top.contents.document.URL));
		}
	catch(err1)
		{
		return null;
		}
	var menu_url;
	var menu_links = mainMenu().getElementsByTagName("a");
	for(var i = 0; i < menu_links.length; i++)
		{
		menu_url = systemURL(absoluteURL(top.menu.document, baseURL(menu_links[i].getAttribute("href"))));
		if(menu_url == doc_url)
			{
			return menu_links[i];
			}
		}
	return null;
	}

//---------------------------------------------------------------------------

function currentItem() 
/* Returns the <li> element belonging to currentLink(). */
	{
	var element = currentLink();
		if (!element)
		{
		return null;
		}
	do
		{
		element = element.parentNode;
		}
	while (element.nodeName.toLowerCase() != "li");
	return element;
	}

//---------------------------------------------------------------------------

function getItemText(item)
/* Returns the text that is displayed with the given menu item. */
	{
	try
		{
		var paragraph = item.getElementsByTagName("p")[0];
		var link = paragraph.getElementsByTagName("a")[0];
		var text = link.firstChild.nodeValue;
		}
	catch(err1)
		{
		return "";
		}
	return text;
	}

//---------------------------------------------------------------------------

function currentItems() 
/* Returns an array of all <li> elements in the menu that have led to 
opening the current page. */
	{
	var items = new Array();
	var element = currentItem();
	if (!element)
		{
		return items;
		}
	items.unshift(element);
	do
		{
		element = parentElement(element, "li");
		if (element !== null)
			{
			items.unshift(element);
			}
		}
	while (element !== null);
	return items;
	}

//---------------------------------------------------------------------------

function currentMenus() 
/* Returns an array of all <ul> elements that have led to 
opening the current page. */
	{
	var menus = new Array();
	var element = currentItem();
	if (!element)
		{
		return menus;
		}
	do
		{
		element = parentElement(element, "ul");
		if (element !== null)
			{
			menus.unshift(element);
			}
		}
	while (element !== null);
	return menus;
	}
	
//---------------------------------------------------------------------------

function nextSubmenu() 
/* Returns the menu (an <ul> element) that can be opened 
as a submenu to the link that loaded the current page. */
	{
	var current_item = currentItem();
	if(current_item)
		{
		var submenus = current_item.getElementsByTagName("ul");
		if(submenus.length > 0)
			{
			return submenus[0];
			}
		else
			{
			return null;
			}
		}
	else
		{
		return null;
		}
	}

//---------------------------------------------------------------------------

function collapseMenu(menu)
/* Hides all submenus of the given menu list, hides all bullets.
Works recursively.*/
	{
	var items = menu.getElementsByTagName("li");
	for(var i = 0; i < items.length; i++)
		{
		items[i].style.listStyleType = "none";
		items[i].style.listStyleImage = "none";
		}
	var menus = menu.getElementsByTagName("ul");
	for(var j = 0; j < menus.length; j++)
		{
		menus[j].style.display = "none";
		collapseMenu(menus[j]);
		}
	}

//---------------------------------------------------------------------------

function pageSubmenu(doc) 
/* Returns an <ul> list representing a submenu 
as defined by named anchors in the given document. 
Returns null if the document doesn't define any menu entries. */
	{
	var menu_doc = top.menu.document;
	var new_menu = null;
	var markers = doc.anchors;
	if(markers.length > 0)
		{
		new_menu = menu_doc.createElement("ul");
		var new_paragraph, new_item, new_link, new_href, new_target, text, new_italic;
		for(var i = 0; i < markers.length; i++)
			{
			if(!markers[i].href)
				{
				text = markers[i].name;
				if((text.substr(0, 4).toLowerCase() == "menu") || (text.indexOf("|outline") >= 0))
					{
					text = markers[i].nextSibling.nodeValue;
					new_paragraph = menu_doc.createElement("p");
					new_item = menu_doc.createElement("li");
					new_link = menu_doc.createElement("a");
					new_link.href = baseURL(doc.URL) + "#" + markers[i].name;
					new_link.target = "contents";
					new_italic = menu_doc.createElement("i");
					new_italic.appendChild(menu_doc.createTextNode(text));
					new_link.appendChild(new_italic);
					new_paragraph.appendChild(new_link);
					new_item.appendChild(new_paragraph);
					new_menu.appendChild(new_item);
					}
				}
			}
		tuneMenu(new_menu, Number(getLevel(doc) + 1));
		} 
	return new_menu;
	}

//---------------------------------------------------------------------------
		
function adaptMenuHeight()
/* Tries to adapt the height of the menu table cell to the available space 
in order to make Konqueror display scrollbars if needed.
This is necessary because this browser cannot handle dynamic changes in 
iframe contents. Opera is even worse; no use in trying there. */
	{
	try
		{
		menu_body = top.menu.document.getElementsByTagName("body")[0];
		}
	catch(err1)
		{
		return;
		}
	var menu_height = menu_body.scrollHeight;
	var avail_height = top.innerHeight - top.document.getElementById("navigation_cell_2-1").offsetTop;
	if(menu_height > avail_height)
		{
		top.document.getElementById("navigation_row_2").style.height = String(avail_height) + "px";
		top.document.getElementById("navigation_cell_2-1").style.height = String(avail_height) + "px";
		}
	}

//---------------------------------------------------------------------------

function updateMenu()
/* Makes the menu collapse, then tries to expand and highlight the branch
corresponding to the current page. */
	{
/*	try
		{ 
		currentLink().blur();
		}
	catch(err1)
		{} */
	if(badBrowser())
		{
		PUBLIC_menu_bullet_image = "";
		}
	collapseMenu(mainMenu());
	if(!top.contents.document)
		{
		return;
		}
	var submenu = pageSubmenu(top.contents.document);
	if(submenu)
		{
		try
			{
			var old_menus = currentItem().getElementsByTagName("ul");
			for(var i = 0; i < old_menus.length; i++)
				{
				currentItem().removeChild(old_menus[i]);
				}
			currentItem().appendChild(submenu);
			}
		catch(err)
			{}
		}
	var menus = currentMenus();
	for(var j = 0; j < menus.length; j++)
	{
	menus[j].style.display = "block";
	}
	if(nextSubmenu())
		{
		nextSubmenu().style.display = "block";
		}
	if(currentItem())
		{
		if(strangeBrowser() || (PUBLIC_menu_bullet_image == ""))
			{
			currentItem().style.listStyleType = "disc";
			}
		else
			{
			currentItem().style.listStyleImage = "url(" + PUBLIC_menu_bullet_image + ")";
			}
		}
	}

//---------------------------------------------------------------------------

function getLocationString()
	{
	var items = currentItems();
	if(items.length > 0)
		{
		var texts = new Array();
		for(var i = 0; i < items.length; i++)
			{
			texts.push(getItemText(items[i]));
			}
		return texts.join(PUBLIC_location_separator); 
		}
	else
		{
		var links = top.document.links;
		for(var i = 0; i < links.length; i++)
			{
			if(links[i].nodeName.toLowerCase() != "map")
				{
				var url = absoluteURL(top.document, links[i].href);
				if(url == baseURL(top.contents.location.href))
					{
					if(links[i].href.indexOf(PUBLIC_start_page) != -1)
						{
						return PUBLIC_start_page_name;
						}
					else
						{
						return childElement(links[i], "#text").nodeValue;
						}
					}
				}
			}
		return top.contents.document.getElementsByTagName("title")[0].innerHTML;
		}
	}
	
//---------------------------------------------------------------------------


/* Visibility */

//---------------------------------------------------------------------------

function hideMenu()
	{
	top.document.getElementById("menu_frame").style.visibility = "hidden";
	}

//---------------------------------------------------------------------------

function showMenu()
	{
	top.document.getElementById("menu_frame").style.visibility = "visible";
	if(badBrowser())
		{
		var first_link = top.menu.document.getElementsByTagName("a")[0];
		try
			{
			first_link.focus(); //IE sometimes show the first menu item only, this forces complete display.
			}
		catch(err1)
			{}
		}
	}

//---------------------------------------------------------------------------

function hideContents()
	{
	top.document.title = top.contents.document.title;
	top.document.getElementById("contents_frame").style.visibility = "hidden";
	}
	
//---------------------------------------------------------------------------

function showContents()
	{
	top.document.title = top.contents.document.title;
	top.document.getElementById("contents_frame").style.visibility = "visible";
	if(badBrowser())
		{
		var range = top.contents.document.body.createTextRange();
		range.collapse();
		range.select(); // IE sometimes just doesn't display all of the document. This forces immediate display.
		}
	doHidePreview();
	}
		
//---------------------------------------------------------------------------


/* Navigation bar resizing.  */
			
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------

function getMouseX(event)
	{
	if(!event)
		{
		event = window.event;
		}
	try
		{
		PRIVATE_mouse_x = event.screenX;
		}
	catch(err1)
		{
		}
	} 
	
//---------------------------------------------------------------------------
	
function startResizeTable(event)
	{
	if(badBrowser())
		{
		return;
		}
	PRIVATE_last_mouse_x = PRIVATE_mouse_x;
	PRIVATE_resizing_table = true;
	top.setTimeout("doResizeTable()", 1);
	if(event.preventDefault)
		{
		event.preventDefault();
		}
	return false;
	}
	
//---------------------------------------------------------------------------
	
function doResizeTable()
	{
	if(!PRIVATE_resizing_table)
		{
		return;
		}
	var old_width = Number(top.document.getElementById("navigation").offsetWidth);
	var new_width = old_width + PRIVATE_mouse_x - PRIVATE_last_mouse_x;
	if(new_width >= PUBLIC_min_menu_width && new_width <= PUBLIC_max_menu_width)
		{
		PRIVATE_last_mouse_x = PRIVATE_mouse_x;
		top.document.getElementById("navigation").style.width = String(new_width) + "px";
		}	
	top.setTimeout("doResizeTable()", 20);
	}
	
//---------------------------------------------------------------------------
	
function stopResizeTable()
	{
	PRIVATE_resizing_table = false;
	}
	
//---------------------------------------------------------------------------


/* Functions to tune HTML files created by OpenOffice 
to the needs of the web site */

//---------------------------------------------------------------------------

function getStyleFloat(element)
	{
	if(badBrowser())
		{
		return element.style.styleFloat;
		}
	else
		{
//		alert(element.innerHTML + "\n\n" + element.style.cssFloat);
		return element.style.cssFloat;
		}
	}

//---------------------------------------------------------------------------

function setStyleFloat(element, value)
	{
	if(badBrowser())
		{
		element.style.styleFloat = value;
		}
	else
		{
		element.style.cssFloat = value;
		}
	}

//---------------------------------------------------------------------------

function tuneStyles(doc, stylesheet) 
/* Removes all "style" elements from the head of a document 
and applies a global stylesheet instead. The stylesheet must be
specified by an URL relative to the base folder of the web site. */
	{
	var head = doc.getElementsByTagName("head")[0];
	var styles = head.getElementsByTagName("style");
	for(i = 0; i < styles.length; i++)
		{
		head.removeChild(styles[i]);
		}
	var level = getLevel(doc);
	var moves = "";
	for(var i = 0; i <= level; i++)
		{
		if(usesBackslash(doc.URL))
			{
			moves = moves + "..\\";
			}
		else
			{
			moves = moves + "../";
			}
		}	
	var url = moves + stylesheet;
	var new_link = doc.createElement("link");
	new_link.rel = "stylesheet";
	new_link.type = "text/css";
	new_link.href = url;
	head.appendChild(new_link);
	}

//---------------------------------------------------------------------------

function tuneScripts(doc, scriptfile) 
/* Adds a reference to a script file to the head of a document. 
Similar to tuneStyles. */
	{
	var level = getLevel(doc);
	var moves = "";
	var i;
	for(i = 0; i <= level; i++)
		{
		if(usesBackslash(doc.URL))
			{
			moves = moves + "..\\";
			}
		else
			{
			moves = moves + "../";
			}
		}	
	var url = moves + scriptfile;
	var new_script = doc.createElement("script");
	new_script.type = "text/javascript";
	new_script.src = url;
	doc.getElementsByTagName("head")[0].appendChild(new_script);
	}

//---------------------------------------------------------------------------

function getOffsetX(element)
/* Returns the x offset of an element relative to its window's (or frame's)
left origin. */
	{
	var x = element.offsetLeft;
	var parent = element.offsetParent;
	while(parent)
		{
		x = x + parent.offsetLeft;
		parent = parent.offsetParent;
		}
	return x;
	}
	
//---------------------------------------------------------------------------

function getOffsetY(element)
/* Returns the y offset of an element relative to its window's (or frame's)
top origin. */
	{
	var y = element.offsetTop;
	var parent = element.offsetParent;
	while(parent)
		{
		y = y + parent.offsetTop;
		parent = parent.offsetParent;
		}
	return y;
	}

//---------------------------------------------------------------------------

function setPreviewCoordinates(event, link)
/* Moves the page_preview element, its shadow and pane to a suitable
position so as to show a preview image for the given link. The mouseover
event that triggered the preview must also be passed. */ 
	{
	var doc = parentDocument(link);
	var frame, frame_element, offset_x, offset_y, width, height;
	if(doc == top.menu.document)
		{
		frame_element = top.document.getElementById("menu_frame");
		x = getOffsetX(frame_element) + frame_element.offsetWidth - PUBLIC_preview_width;
		y = top.document.getElementById("top_row").offsetHeight + 40;
		}
	else
		{
		switch(doc)
			{
			case top.menu.document:
	/*			frame = top.menu;
				frame_element = top.document.getElementById("menu_frame");
				offset_x = getOffsetX(frame_element);
				offset_y = getOffsetY(frame_element);
				width = frame_element.offsetWidth;
				height = frame_element.offsetHeight; */
				
				break;
			case top.contents.document:
				frame = top.contents;
				frame_element = top.document.getElementById("contents_frame");
				offset_x = getOffsetX(frame_element);
				offset_y = getOffsetY(frame_element);
				width = frame_element.offsetWidth;
				height = frame_element.offsetHeight;
				break;
			default:
				frame = top;
				offset_x = 0;
				offset_y = 0;
				width = top.innerWidth;
				height = top.innerHeight;
			}
		if(0 == 1) // strangeBrowser() Doesn't work either, seems to be a bug in Konqueror.
			{			
			var x = event.clientX;
			var y = event.clientY;
			}
		else
			{
			var x = event.pageX - frame.scrollX;
			var y = event.pageY - frame.scrollY;
			}
		if(x > width - PUBLIC_preview_width)
			{
			x = x - PUBLIC_preview_width - 8;
			}
		else
			{
			x = x + 8;
			}
		if(y > height - PUBLIC_preview_height)
			{
			y = getOffsetY(link) - frame.scrollY - PUBLIC_preview_height - 8;
			}
		else
			{
			y = getOffsetY(link) - frame.scrollY + link.offsetHeight + 8;
			}
		x = x + offset_x;
		y = y + offset_y;
		}
	var preview = top.document.getElementById("page_preview");
	var shadow = top.document.getElementById("preview_shadow");
	var pane = top.document.getElementById("preview_pane");
	preview.style.top = String(y) + "px";
	preview.style.left = String(x) + "px";
	shadow.style.top = String(y + 15) + "px";
	shadow.style.left = String(x + 10) + "px";
	pane.style.top = String(y + 2) + "px";
	pane.style.left = String(x + 2) + "px";
	}
	
//---------------------------------------------------------------------------

function showPagePreview(event, link)
/* Initiates display of a page preview image for the given link. 
The image is not shown until it is sure that it has been successfully loaded. */
	{
	if(badBrowser() || !PUBLIC_preview_links)
		{
		return;
		}
	top.clearTimeout(PRIVATE_hide_preview_timeout);
	var image_url;
	var fragment = fragmentURL(link.href);
	var base = baseURL(link.href);
	if(fragment)
		{
		if(fragment.substr(0, 5).toLowerCase() == "icon_")
			{
			image_url = navigateUpwards(base) + fragment.replace("icon_", "") + ".png";
			}
		else
			{
			image_url = navigateUpwards(base) + "_icon.png";
			}
		}
	else
		{
		image_url = navigateUpwards(base) + "_icon.png";
		}
/*	if(url == "") // || (url == top.contents.document.URL && url != link.href))
		{
		doHidePreview();
		return;
		} */
	var preview = top.document.getElementById("page_preview");
	var shadow = top.document.getElementById("preview_shadow");
	preview.src = image_url;
	if(preview.style.display === "none")
		{
		setPreviewCoordinates(event, link);
		top.setTimeout("doShowPreview()", 1);
		}
	else
		{
		}
	}
	
//---------------------------------------------------------------------------
	
function imageLoaded(img)
/* Returns True if the image has been successfully loaded. */
	{
	if(img.complete) 
		{
	 	if(img.naturalWidth !== null)
			{
			if(img.naturalWidth < 10)
				{
	      	return false;
	      	}
	      else
	      	{
	      	return true;
	      	}
	      }
	   else
	     	{
	     	return true;
	     	}
	   }
	}

//---------------------------------------------------------------------------

function doShowPreview()
/* Actually shows the page preview initiated by showPagePreview() if the image
has been loaded. If not, tries again later. */
	{
	var preview = top.document.getElementById("page_preview");
	if(imageLoaded(preview))
		{
		preview.style.borderWidth = 2;
		top.document.getElementById("preview_pane").style.display = "block";
		preview.style.display = "block";
		top.document.getElementById("preview_shadow").style.display = "block";
		top.setTimeout("checkPreview()", 200);
		}
	else
		{
		top.setTimeout("doShowPreview()", 50); 
		}
	}
	
//---------------------------------------------------------------------------

function doHidePreview()
/* Actually hides the current page preview, if any. */
	{
	var preview = top.document.getElementById("page_preview");
	preview.style.display = "none";
	preview.style.borderWidth = 0;
	preview.src = "";
	top.document.getElementById("preview_shadow").style.display = "none";
	top.document.getElementById("preview_pane").style.display = "none";
	}

//---------------------------------------------------------------------------
		
function hidePagePreview(link)
/* Makes the current page preview disappear. Must work with some delay
as moving the mouse within a link sometimes causes mouseout events in some
browsers. */
	{
	PRIVATE_hide_preview_timeout = top.setTimeout("doHidePreview()", 20);
	}
	
//---------------------------------------------------------------------------
	
function tuneLinks(doc, target, symbol) 
/* First: Sets the "target" attribute of all internal HTML links in a document 
to the given value and that of all external links or links to files 
other than HTML to "_blank". 
Second: Merges adjacent links that have the same target and are separated by 
whitespace only. This is helpful because OpenOffice creates several links 
for text that contains embedded (inline) images.
Third: Inserts a symbol image in front of each internal link if an URL
relative to PUBLIC_contents_folder is given. */ 
	{
	var links = doc.links;
	if(symbol != "")
		{
		var new_img = doc.createElement("img");
		var level = getLevel(doc);
		var moves = "";
		for(var i = 0; i < level; i++)
			{
			if(usesBackslash(doc.URL))
				{
				moves = moves + "..\\";
				}
			else
				{
				moves = moves + "../";
				}
			}	
		new_img.src = moves + symbol;
		new_img.align = "middle";
		}	
	for(var i = 0; i < links.length; i++)
		{
		if(links[i].nodeName.toLowerCase() != "map")
			{
			if(isExternal(links[i].href) || !isHTML(links[i].href))
				{
				links[i].target = "_blank";
				}
			else
				{
				links[i].target = target;
				}
			next_link = links[i].nextSibling;
			if(next_link) 
				{
				if(next_link.nodeType == 3)
					{
					if(parseText(next_link.nodeValue) == " ")
						{
						next_link = next_link.nextSibling;
						}
					else
						{
						next_link = null;
						}
					}
				if(next_link)
					{
					if(next_link.nodeName.toLowerCase() == "a")
						{
						var link2_children = next_link.childNodes;
						for(var j = 0; j < link2_children.length; j++)
							{
							links[i].appendChild(link2_children[j].cloneNode(true));
							}
						next_link.parentNode.removeChild(next_link);
						}
					}
				}
			setEvent(doc, links[i], "onclick", "top.setTimeout(\"scrollContentsIntoView()\", 1)");
			if(!isExternal(links[i].href) && !parentElement(links[i], "span") && !parentElement(links[i], "blockquote"))
				{
				if((symbol != "") && !parentElement(links[i], "h1"))
					{
					links[i].insertBefore(new_img.cloneNode(true), links[i].firstChild);
					}
				setEvent(doc, links[i], "onmouseover", "showPagePreview(event, this)");
				setEvent(doc, links[i], "onmouseout", "hidePagePreview(this)");
				}
			}
		}
	}


//---------------------------------------------------------------------------

function tuneImages(doc)
	{
	var img = doc.images;
	for(var i = 0; i < img.length; i++)
		{
		if(!parentElement(img, "span"))
			{
			if(badBrowser() && (img[i].src.substr(img[i].src.length - 3) == "png"))
				{
				img[i].src = img[i].src.replace("png", "gif");
				}
			if(img[i].name.toLowerCase().indexOf("grafik") !== 0)
				{
				img[i].alt = img[i].name;
				img[i].title = img[i].name;
				}
			img[i].removeAttribute("border");
			switch(img[i].align.toLowerCase())
				{
				case "left":
					img[i].className = "align_left";
					break;
				case "right":
					img[i].className = "align_right";
					break;
				case "middle":
					img[i].className = "scaled_icon";
					img[i].removeAttribute("align");
					img[i].removeAttribute("height");
					img[i].removeAttribute("width");
					var next_node = img[i].nextSibling;
					if(next_node)
						{
						var new_node;
						if(next_node.nodeType == 3) // Text node
							{
							var text = parseText(next_node.nodeValue);
							var first_letter = text.substr(0, 1);
							next_node.nodeValue = text.replace(first_letter, "");
							new_node = doc.createTextNode(first_letter);
							}
						else
							{
							new_node = next_node;
							next_node.parentNode.removeChild(next_node);
							}
						var new_span = doc.createElement("span");
						new_span.id = "auto_created";
						new_span.style.whiteSpace = "nowrap";
						new_span.appendChild(img[i].cloneNode(true));
						new_span.appendChild(new_node);
						img[i].parentNode.replaceChild(new_span, img[i]);
						}
					break;
				case "bottom":
					img[i].className = "icon";
					img[i].removeAttribute("align");
					break;
				default:
				}
			if(img[i].hspace)
				{
				if(img[i].hspace > 0)
					{
					img[i].style.marginLeft = img[i].hspace;
					img[i].style.marginRight = img[i].hspace;
					img[i].removeAttribute("hspace");
					}
				}
			if(img[i].vspace)
				{
				if(img[i].vspace > 0)
					{
					img[i].style.marginTop = img[i].vspace;
					img[i].style.marginBottom = img[i].vspace;
					img[i].removeAttribute("vspace");
					}
				}
			}
		}
	}
		
//---------------------------------------------------------------------------

function tuneTables(doc)
	{
	var tables = doc.getElementsByTagName("table");
	var parent;
	for(var i = 0; i < tables.length; i++)
		{
		if(tables[i].width.indexOf("%") == -1)
			{
			parent = parentElement(tables[i], "div");
			if(parent)
				{
				if(parent.align == "right")
					{
					tables[i].className = "align_right";
					}
				}
			else
				{
				tables[i].className = "align_left";
				}
			}
		}
	}
	
//---------------------------------------------------------------------------

function tuneBreaks(doc)
/* Replaces all occurences of three <br> elements in a row by one
<br clear="all">. Three breaks are written by OpenOfice when inserting a
line break at the end of a paragraph; this is taken as a request for a
line feed to the bottom of the image, if any. */ 
	{
	var breaks = doc.getElementsByTagName("br");
	var new_space = doc.createTextNode(" ");
	for(var i = 0; i < breaks.length; i++)
		{
		var next = breaks[i].nextSibling;
		if(!next)
			{
			continue;
			}
		if(next.nodeType == 3)
			{
			if(parseText(next.nodeValue) == " ")
				{
				next = next.nextSibling;
				}
			}
		if(!next)
			{
			continue;
			}
		var after_next = next.nextSibling;
		if(!after_next)
			{
			continue;
			}
		if(after_next.nodeType == 3)
			{
			if(parseText(after_next.nodeValue) == " ")
				{
				after_next = after_next.nextSibling;
				}
			}
		if(!after_next)
			{
			continue;
			}
		if((next.nodeName.toLowerCase() == "br") && (after_next.nodeName.toLowerCase() == "br"))
			{
			next.parentNode.removeChild(next);
			after_next.parentNode.removeChild(after_next);
			breaks[i].style.clear = "both";
			breaks[i].parentNode.appendChild(new_space.cloneNode(true));
			}
		}
	}
	
//---------------------------------------------------------------------------

function tuneTextFrames(doc)
/* Assigns proper class names to all <span> elements which represent text frames anchored to 
paragraphs in OpenOffice.
Must fix an OpenOffice bug: OOo encloses the contents of such a text frame in a <p> element
which is not valid HTML because an inline element cannot contain a block element.
Many browsers get stuck with this (Firefox doesn't, Safari and IE do) but respond differently. 
That's why the procedure is rather complicated. */ 
	{
	var spans = doc.getElementsByTagName("span");
	var paragraph, following_text, following_paragraph, new_paragraph, children, j;
	for(var i = 0; i < spans.length; i++)
		{
		if(spans[i].id == "auto_created")
			{
			continue;
			}
		paragraph = childElement(spans[i], "p");
		if(!paragraph)
			{
			paragraph = nextElement(spans[i].parentNode, "p");
			following_text = nextElement(paragraph, "#text");
			}
		else
			{
			following_text = nextElement(spans[i], "#text");
			}
		if(following_text)
			{
			following_paragraph = nextElement(following_text, "p");
			if(following_paragraph)
				{
				if(following_paragraph.innerHTML == "")
					{
					following_paragraph.parentNode.removeChild(following_paragraph);
					}
				}
			new_paragraph = doc.createElement("p");
			new_paragraph.appendChild(following_text.cloneNode(true));
			following_text.parentNode.insertBefore(new_paragraph, following_text);
			following_text.parentNode.removeChild(following_text);
			}
		children = paragraph.childNodes;
		for(j = 0; j < children.length; j++)
			{
			spans[i].appendChild(children[j].cloneNode(true));
			}
		paragraph.parentNode.removeChild(paragraph);
		switch(getStyleFloat(spans[i]))
			{
			case "left":
				spans[i].className = "align_left";
				break;
			case "right":
				spans[i].className = "align_right";
				break;
			default:
			}
		spans[i].removeAttribute("style");
		}
	}

//---------------------------------------------------------------------------

function tuneHeadlines(doc)
	{
	var headline = childElement(doc.body, "h1");
	if(headline)
		{
		var text_node = headline.firstChild;
		var new_link = doc.createElement("a");
		new_link.href = doc.URL;
		new_link.appendChild(text_node.cloneNode(true));
		headline.insertBefore(new_link, text_node);
		headline.removeChild(text_node);
		}
	}
	
//---------------------------------------------------------------------------


/* Main functions. These are invoked by the base HTML file. */
			
//---------------------------------------------------------------------------

function prepareMenu() 
/* Prepares the menu document before being shown. */
	{
	var doc = top.menu.document;
	tuneScripts(doc, "control.js");
	setEvent(doc, doc.getElementsByTagName("body")[0], "onunload", "hideMenu()");
	tuneLinks(doc, "contents", "", false);
	if(doc.captureEvents)
		{
		doc.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
		}
	doc.onmousemove = getMouseX;
	doc.onmouseup = stopResizeTable;
	var menu = mainMenu();
	tuneMenu(menu, 1);
	tuneStyles(doc, PUBLIC_stylesheet_folder + "/normal/" + "menu.css");
	doc.getElementsByTagName("body")[0].style.fontSize = getGlobalFontSizeString();
	updateMenu();
	top.setTimeout("showMenu()", 1);
	}

//---------------------------------------------------------------------------

function prepareDocument(doc)
/* Prepares a document before being shown */
	{
	if(doc.captureEvents)
		{
		doc.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
		}
	doc.onmousemove = getMouseX;
	doc.onmouseup = stopResizeTable;
	tuneScripts(doc, "control.js");
	var body = doc.getElementsByTagName("body")[0];
	setEvent(doc, body, "onunload", "hideContents()");
	if(getMetaTag(doc, "process").toLowerCase().indexOf("none") == -1)
		{
		var link_symbol = "";
		if(getMetaTag(doc, "process").toLowerCase().indexOf("no-link-symbols") == -1)
			{
			link_symbol = PUBLIC_internal_link_symbol;
			}
		tuneBreaks(doc);
		tuneTextFrames(doc);
		tuneHeadlines(doc);
		tuneLinks(doc, "_self", link_symbol);
		var stylesheet = getMetaTag(doc, "stylesheet");
		if(stylesheet == "")
			{
			stylesheet = PUBLIC_stylesheet_folder + "/normal/" + "contents.css"
			}
		tuneStyles(doc, stylesheet);
		doc.getElementsByTagName("body")[0].style.fontSize = getGlobalFontSizeString();
		tuneImages(doc);
		tuneTables(doc);
		}
	}
	
//---------------------------------------------------------------------------

function preparePage() 
/* Prepares the current content page before being shown. */
	{
	var url;
	try
		{
		url = top.contents.location.href;
		}
	catch(err1) // Firefox under Windows, when trying to reload the document, denies access to top.contents.location and top.contents.document if the URL contains a fragment part. The only workaround is to reload any other page, in this case, the start page.
		{
		showMenu();
		top.document.getElementById("contents_frame").src = PUBLIC_start_page;
		return;
		}
	if(!isHTML(url))
		{
		top.document.getElementById("contents_frame").style.visibility = "visible";
		return;
		}
	prepareDocument(top.contents.document);
	if(mainMenu())
		{
		updateMenu();
		if(strangeBrowser())
			{
			adaptMenuHeight();
			}	
		childElement(top.document.getElementById("location"), "#text").nodeValue = getLocationString();
		resizeWindow();
		}
	top.setTimeout("showContents()", 300);
	}
	
//---------------------------------------------------------------------------


