/*
-----------------------------------------------
Pfadi Vaduz Basic Javascripts
Author:   Robert Hilbe
Version:  3 Okt 2004
----------------------------------------------- */

/* changeClass: Aendert eine Klasse */

function changeClass(from,to) {
	if (document.getElementById && !document.all) {
		var elemente = document.getElementsByTagName("*");
		for (i = 0;i<elemente.length;i++) {
			if (elemente[i].className == from) {
				elemente[i].className = to;
 				}
			}
		}
	if (document.all) {
		for (i=0;i<document.all.length;i++) {
			if (document.all[i].className == from) {
				document.all[i].className = to;
				}
			}
		}
	}

/* switchClass: Wechselt wie ein Schalter zwei Klassen aus */

function switchClass(from,to) {
	var schalter = 0;
	if (document.getElementById && !document.all) {
		var elemente = document.getElementsByTagName("*");
		for (i=0;i<elemente.length;i++) {
			if (elemente[i].className == from) {
				elemente[i].className = to;
				var schalter = 1;
 				}
			if (schalter == 0) {
				if (elemente[i].className == to)
					{
					elemente[i].className = from;
					}
				}
			}
		}
	if (document.all) {
		for (i=0;i<document.all.length;i++) {
			if (document.all[i].className == from) {
				document.all[i].className = to;
				var schalter = 1;
				}
			if (schalter == 0) {
				if (document.all[i].className == to) {
					document.all[i].className = from;
					}
				}
			}
		}
	}

/* setClass: Weist einem Element mit Id eine Klasse zu */

function setClass(id,to) {
	if (document.getElementById) {
		document.getElementById(id).className = to;
		}

if (document.all && !document.getElementById) {
		for (i = 0;i<document.all.length;i++)	{
			if (document.all[i].id == id) {
				document.all[i].className = to;
				}
			}
		}
	}

/* showandhide: Zeigt und verbirgt ein Element */

function showandhide(Id) {
	if (document.getElementById) {
		target = document.getElementById(Id);
		if (target.style.display == "block" || target.style.display == "") {
			target.style.display = "none";
			}
		else {
			target.style.display = "block";
			}
		}
	}

/* show: Zeigt ein Element */

function show(Id) {
	if (document.getElementById) {
		target = document.getElementById(Id);
		target.style.display = "block";
		}
	}

/* hide: Verbirgt ein Element */

function hide(Id) {
	if (document.getElementById) {
		target = document.getElementById(Id);
		target.style.display = "none";
		}
	}

/* Suckerfish: Macht die Verwendung von :hover, :active, :focus und :target auch für IE moeglich (.hover neben :hover usw. in CSS-File definieren */

function suckerfish(type, tag, parentId) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			type(sfEls);
			});
		}
	}

hover = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover = function() {
			this.className+= " hover";
			}
		sfEls[i].onmouseout = function() {
			this.className = this.className.replace(new RegExp(" hover\\b"), "");
			}
		}
	}

/*
focus = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus = function() {
			this.className+= " focus";
			}
		sfEls[i].onblur = function() {
			this.className = this.className.replace(new RegExp(" focus\\b"), "");
			}
		}
	}
*/ 

active = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmousedown = function() {
			this.className+= " active";
			}
		sfEls[i].onmouseup = function() {
			this.className = this.className.replace(new RegExp(" active\\b"), "");
			}
		}
	}

target = function(sfEls) {
	var aEls = document.getElementsByTagName("A");
	document.lastTarget = null;
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id) {
			if (location.hash==("#" + sfEls[i].id)) {
				sfEls[i].className+= " target";
				document.lastTarget = sfEls[i];
				}
			for (var j=0; j<aEls.length; j++) {
				if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i];
				aEls[j].onclick = function() {
					if (document.lastTarget) document.lastTarget.className = document.lastTarget.className.replace(new RegExp(" target\\b"), "");
					if (this.targetEl) this.targetEl.className+= " target";
					document.lastTarget = this.targetEl;
					return true;
					}
				}
			}
		}
	}

suckerfish(hover, "li", "navigation");
suckerfish(hover, "input");
suckerfish(hover, "td");

/* getStyle: Gibt den Wert einer CSS-Eigenschaft eines Elements wieder (undefiniert für nicht spezifizierte Eigenschaften) */

function getStyle(id, property) {
	var object = getElementById(id);
	if(object!=null) {
		var styleObject = object.style;
		if(styleObject[property]) {
			return styleObject[property];
			}
		}
    else return;
	}

/* setStyle: Setzt den Wert einer CSS-Eigenschaft eines Elements, gibt false wieder, wenn nicht erfolgreich */

function setStyle(id, property, value) {
	var object = getElementById(id);
	if(object!=null) {
		var styleObject = object.style;
		if(styleObject[property]=value) return true;
		}
	else return false;
	}

/* move: Positioniert einen div neu */

function move(id,top,left) {
	styleObject = getElementById(id).style;
	if(styleObject) {
		styleObject.top = top;
		styleObject.left = left;
		}
	}

/* setActiveStyleSheet: CSS-Switcher */

function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
			}
		}
	}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
		}
	return null;
	}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
		&& a.getAttribute("rel").indexOf("alt") == -1
		&& a.getAttribute("title")
		) return a.getAttribute("title");
		}
	return null;
	}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires = "+date.toGMTString();
		}
	else expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
	}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
	return null;
	}

window.onload = function(e) {
	var cookie = readCookie("pfadivaduzstyle");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
	}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("pfadivaduzstyle", title, 365);
	}

var cookie = readCookie("pfadivaduzstyle");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);