// cj Wed, 22 Jun 2005 12:15:57 +0200

// ----------------------------------------------------
// this part is taken from http://de.selfhtml.org/javascript/
/* DHTML-Bibliothek */

var DHTML = false, DOM = false, MSIE4 = false, NS4 = false, OP = false;

if (document.getElementById) {
    DHTML = true;
    DOM = true;
} else {
    if (document.all) {
	DHTML = true;
	MSIE4 = true;
    } else {
	if (document.layers) {
	    DHTML = true;
	    NS4 = true;
	}
    }
}
if (window.opera) {
    OP = true;
}
function getElement (Mode, Identifier, ElementNumber) {
    var Element;
    if (DOM) {
	if (Mode.toLowerCase() == "id") {
	    if (typeof document.getElementById(Identifier) == "object") {
		Element = document.getElementById(Identifier);
	    } else {
		Element = false;
	    }
	    return Element;
	}
	if (Mode.toLowerCase() == "name") {
	    var ElementList = document.getElementsByName(Identifier);
	    if (typeof ElementList == "object" || (OP && typeof ElementList == "function")) {
		Element = ElementList[ElementNumber];
	    } else {
		Element = false;
	    }
	    return Element;
	}
	if (Mode.toLowerCase() == "tagname") {
	    var ElementList = document.getElementsByTagName(Identifier);
	    if (typeof ElementList == "object" || (OP && typeof ElementList == "function")) {
		Element = ElementList[ElementNumber];
	    } else {
		Element = false;
	    }
	    return Element;
	}
	return null;
    }
    if (MSIE4) {
	if (Mode.toLowerCase() == "id") {
	    if (typeof document.all[Identifier] == "object") {
		Element = document.all[Identifier];
	    } else {
		Element = false;
	    }
	    return Element;
	}
	if (Mode.toLowerCase() == "tagname") {
	    if (typeof document.all.tags(Identifier) == "object") {
		Element = document.all.tags(Identifier)[ElementNumber];
	    } else {
		Element = false;
	    }
	    return Element;
	}
	if (Mode.toLowerCase() == "name") {
	    if (typeof document[Identifier] == "object") {
		Element = document[Identifier];
	    } else {
		Element = false;
	    }
	    return Element;
	}
	return false;
    }
    if (NS4) {
	if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
	    if (typeof document[Identifier] == "object") {
		Element = document[Identifier];
	    } else {
		Element = false;
	    }
	    return Element;
	}
	if (Mode.toLowerCase() == "index") {
	    if (typeof document.layers[Identifier] == "object") {
		Element = document.layers[Identifier];
	    } else {
		Element = false;
	    }
	    return Element;
	}
	return false;
    }
    return false;
}


// ----------------------------------------------------
// this part is
// copyright 2005 by christian jaeger at ethlife ethz ch
// published under the mozilla license as long as you don't ask me for other conditions.

function fib(a,b,cont){
    return cont(b,a+b);
}
function FibNext() {
    var th=this;
    return fib(this.a,
	       this.b,
	       function(a,b){
	th.a=a;
	th.b=b;
	return b;
    });
}
function Fib() {
    this.a=1;
    this.b=1;
    this.next=FibNext;
}

function DigitsNext() {
    if (this.digits.length==0) {
	this.digits=this.fib.next()+"";
    }
    var ch= this.digits.charAt(0);
    this.digits=this.digits.substring(1);
    return ch;
}
function Digits() {
    this.digits="";
    this.fib=new Fib();
    this.next=DigitsNext;
}

var charcodeA="A".charCodeAt(0);
var charcodeZ="Z".charCodeAt(0);
var charcodea="a".charCodeAt(0);
var charcodez="z".charCodeAt(0);
function rot(ch,n) {
    var c=ch.charCodeAt(0);
    var base;
    if ((c>=charcodea)&&(c<=charcodez)){
	base=charcodea;
    } else if ((c>=charcodeA)&&(c<=charcodeZ)) {
	base=charcodeA;
    } else {
	return ch;
    }
    var c2=c-base;
    var c3=(c2+n)%26;
    return String.fromCharCode(c3+base);
}


function unscramble(str) {
    var d=new Digits();
    var len= str.length;
    var out="";
    for(i=0;i<len;i++) {
	var ch= str.charAt(i);
	var n= d.next();
	out=out + rot(ch, 2 * n);
    }
    return out;
}

function set_mailtolink(id,scrambled) {
    var Element = getElement("id", id, null);
    if (!Element) {
	return false;//?
    }
    var clear= unscramble(scrambled);
    Element.setAttribute("href","mailto:" + clear);
    if (MSIE4) {
	Element.innerHTML = clear;
	return true;
    }
    if (NS4) {
	Element.document.open();
	Element.document.write(clear); // TODO wohl mit a href drumh
	Element.document.close();
	return true;
    }
    if (DOM) {
	Element.innerHTML = clear;
	return true;
    }
    return false;
}

