var xhtml = false;
if (document.contentType && document.contentType == "application/xhtml+xml") {
	// document.documentElement.namespaceURI == "http://www.w3.org/1999/xhtml"
	xhtml = true;
}

/* ********************************************************************** */

function setCookie (name, value, domain, expires, path, secure) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date(today.getTime() + expires);
	var cookie = name + "=" + encodeURIComponent(value);
	if (expires)
		 cookie += "; expires=" + expires_date.toGMTString();
	if (path)
		cookie += "; path=" + path;
	if (domain)
		cookie += "; domain=" + domain;
	if (secure)
		cookie += ";secure";
	document.cookie = cookie;
}
function getCookie (name) {
	var name_index = document.cookie.indexOf(name + "=");
	if (name_index == -1)
		return null;
	var value_index = name_index + name.length + 1;
	var end = document.cookie.indexOf(";", value_index);
	if (end == -1)
		end = document.cookie.length;
	var value = decodeURIComponent(document.cookie.substring(value_index, end));
	return value;
}
function deleteCookie (name, domain, path) {
	if (getCookie(name)) {
		var cookie = name + "=";
		if (path)
			cookie += "; path=" + path;
		if (domain)
			cookie += "; domain=" + domain;
		cookie += "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
		document.cookie = cookie;
	}
}

/* ********************************************************************** */

function addClass (element, className) {
	if (!hasClass(element, className)) {
		if (element.className) element.className += " " + className;
		else element.className = className;
	}
}
function removeClass (element, className) {
	var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)");
	element.className = element.className.replace(regexp, "$2");
}
function hasClass (element, className) {
	var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)");
	return regexp.test(element.className);
}

/* ********************************************************************** */

function getElementsByClassName (startElement, tagName, className) {
	var elements = startElement.getElementsByTagName(tagName);
	var returnElements = [];
	className = className.replace(/\-/g, "\\-");
	for (var i = 0, element; element = elements[i]; i++) {
		if (hasClass(element, className)) {
			returnElements.push(element);
		}
	}
	return returnElements;
}

/* ********************************************************************** */

function getInnerText (element) {
	if (typeof element.innerText == "string") {
		return element.innerText;
	} else if (typeof element.textContent == "string") {
		return element.textContent;
	}
}


function schriftgroesse_setzen () {
	window.fontsize = Number(getCookie("fontsize"));
	if (window.fontsize && !xhtml) {
		document.write('<style type="text/css">body {font-size: ' + window.fontsize + '%;}</style>');
	} else {
		window.fontsize = 100.01;
	}
}
schriftgroesse_setzen();

function  schrift_verkleinern () {
	if (window.fontsize > 60)
		window.fontsize -= 10;
	document.body.style.fontSize = window.fontsize + "%";
	setCookie("fontsize", window.fontsize);
}
function schrift_vergroessern () {
	if (window.fontsize < 300)
		window.fontsize += 10;
	document.body.style.fontSize = window.fontsize + "%";
	setCookie("fontsize", window.fontsize);
}
function normal () {
	if (window.fontsize != 100.01)
		window.fontsize = 100.01;
	document.body.style.fontSize = window.fontsize + "%";
	setCookie("fontsize", window.fontsize);
}
function schriftgroessenwahl () {
	if (xhtml) {
		document.body.style.fontSize = window.fontsize + "%";
	}
	var container = document.createElement("div");
	if (!container)
		return;
	container.id = "schriftgroesse";
	container.appendChild(document.createTextNode("Schrift: "));
	var groesser_element = document.createElement("a");
	groesser_element.href = "javascript:schrift_vergroessern()";
	groesser_element.title = "Schrift vergrößern";
	groesser_element.appendChild(document.createTextNode("+ vergrößern"));
	container.appendChild(groesser_element);
	container.appendChild(document.createTextNode(" "));
	var kleiner_element = document.createElement("a");
	kleiner_element.appendChild(document.createTextNode("- verkleinern"));
	kleiner_element.href = "javascript:schrift_verkleinern()";
	kleiner_element.title = "Schrift verkleinern";
	container.appendChild(kleiner_element);
	var normal = document.createElement("a");
	normal.appendChild(document.createTextNode("normal"));
	normal.href = "javascript:normal()";
	normal.title = "normal";
	container.appendChild(normal);
}

/* ********************************************************************** */

window.onload = function () {
	if (!document.getElementById || !document.getElementsByTagName ||
		!document.createElement || !document.createTextNode) {
		return;
	}
	if (document.documentElement.tagName == "html")
		xhtml = true;

	schriftgroessenwahl();
};
