function menu_over(id) {
    if ((readCookie("mystyle") != "inv")) {
        if (document.getElementById(id).childNodes.length == 5) {
            document.getElementById(id).childNodes[1].className = "RoundedContent2";
            document.getElementById(id).childNodes[3].className = "RoundedBottom2";
            document.getElementById(id).childNodes[1].childNodes[1].className = "RoundedTop2";
        } else {
            document.getElementById(id).childNodes[0].className = "RoundedContent2";
            document.getElementById(id).childNodes[1].className = "RoundedBottom2";
            document.getElementById(id).childNodes[0].childNodes[0].className = "RoundedTop2";
        }
    }
}

function menu_out(id) {
    if ((readCookie("mystyle") != "inv")) {
        if (document.getElementById(id).childNodes.length == 5) {
            document.getElementById(id).childNodes[1].className = "RoundedContent";
            document.getElementById(id).childNodes[3].className = "RoundedBottom";
            document.getElementById(id).childNodes[1].childNodes[1].className = "RoundedTop";
        } else {
            document.getElementById(id).childNodes[0].className = "RoundedContent";
            document.getElementById(id).childNodes[1].className = "RoundedBottom";
            document.getElementById(id).childNodes[0].childNodes[0].className = "RoundedTop";
        }
    }
}

function addAndUpdate() {
    var hash = window.location.hash.substring(1);
    if (window.location.hash.substring(1) == "" || window.location.hash.substring(1) == null) hash = "page=start";
    if (hash.indexOf("=") > 0) {
        testpage(hash.substring(hash.indexOf("=") + 1));
    }
}

function metadata() {
    var keys = "";
    var desc = "";
    var titel = "";
    var label = document.getElementsByTagName('label');
    for (var x = 0; x < label.length; x++) {
        var name = label[x].getAttribute("name");
        if (name == 'keys') keys = label[x].innerHTML;
        if (name == 'desc') desc = label[x].innerHTML;
        if (name == 'titel') titel = label[x].innerHTML;
    }
    var meta = document.getElementsByTagName('meta');
    for (var x = 0; x < meta.length; x++) {
        var name = meta[x].getAttribute("name");
        if (name == 'keywords') meta[x].content = keys;
        if (name == 'description') meta[x].content = desc;
    }
    document.title = titel;
}

function init(url) {
    dojo.connect(document.body, "onhashchange", null, addAndUpdate, true);
    if (url == "") addAndUpdate();
}

var currentmen="";

function testpage(page) {
    var filename = page.substr(0, page.indexOf('&'));
    var parameter = '?' + page.substr(page.indexOf('&') + 1);
	//hier wird das menu was aushovert in current gepeichert
	var t=parameter.substr(parameter.indexOf("current")+8);
	if(t.indexOf("&")>0){
		t=t.substr(0,t.indexOf("&"));
	}
	if(t){
		currentmen=t;
	}
	else{
		currentmen="";	
	}
		
	//if there are parameters
    if (filename !== "") {
        getText(filename + '.php' + parameter, 'toBeReplaced');
    }
    else {
        getText(page + '.php', 'toBeReplaced');
    }
    //scripts maybe used in pages
    away();
}

function links() {
    var li = document.getElementsByTagName('a');
    for (var x = 0; x < li.length; x++) {
        var name = li[x].className;
        if (name.indexOf("mmhide_link") != -1) {
            li[x].href = li[x].href.substr(li[x].href.substr(0, li[x].href.lastIndexOf('?') + 1).lastIndexOf('/') + 1).replace("?", "#");
        }
    }
}

function menueinit() {
    var e = document.getElementsByTagName('div');
    for (var x = 0; x < e.length; x++) {
        var name = e[x].getAttribute("name");
        if (name == 'main') {
            e[x].style.color = "#1A1A1A";
        }
        if (name == 'submain') {
            e[x].style.display = "none";
        }
    }
}

function getText(myurl) {
    dojo.xhrGet({
        url: myurl,
        handleAs: "text",
        sync: true,
        load: function (response, ioArgs) {
            var n = dojo.byId("toBeReplaced");
            n.innerHTML = response;
            metadata();
            runScripts("toBeReplaced");
	    },
        error: function (response, ioArgs) {
            dojo.byId("toBeReplaced").innerHTML = "An error occurred, with response: " + response;
            return response;
        },
		handle: function(data,args){
			if(currentmen){
				//inAndOut('main@@(counter=counter+1)@@','patients.php', 1);
				delayedWipe(currentmen);
			}
		/*,	if(typeof data == "error"){
				console.warn("error!");
				console.log(args);
			}else{
				// the fade can be plugged in here, too
				dojo.byId("content").innerHTML = data;
			}*/
		}
    });
}

function runScripts(id) {
    var elem = document.getElementById(id);
    if (elem != null) {
        var e = document.getElementById(id).getElementsByTagName("script");
        if (e != null) {
            for (var i = 0; i < e.length; i++) {
                eval(e[i].innerHTML);
            }
        }
        var li = document.getElementById(id).getElementsByTagName('a');
        for (var x = 0; x < li.length; x++) {
            var name = li[x].className;
            if (name == 'mmhide_link') {
                li[x].href = li[x].href.substr(li[x].href.substr(0, li[x].href.lastIndexOf('?') + 1).lastIndexOf('/') + 1).replace("?", "#");
            }
        }
        var aktuell = readCookie("mystyle");
        if (aktuell != "norm" && aktuell != "inv") {
            aktuell = "norm";
        }
        change_pics(aktuell)
    }
}

function Cookiemanager(name, defaultExpiration, expirationUnits, defaultDomain, defaultPath) {
    this.name = name;
    this.defaultExpiration = this.getExpiration(defaultExpiration, expirationUnits);
    this.defaultDomain = (defaultDomain) ? defaultDomain : (document.domain.search(/[a-zA-Z]/) == -1) ? document.domain : document.domain.substring(document.domain.indexOf('.') + 1, document.domain.length);
    this.defaultPath = (defaultPath) ? defaultPath : '/';
    this.cookies = new Object();
    this.expiration = new Object();
    this.domain = new Object();
    this.path = new Object();
    window.onunload = new Function(this.name + '.setDocumentCookies();');
    this.getDocumentCookies();
}
Cookiemanager.prototype.getExpiration = function (expiration, units) {
    expiration = (expiration) ? expiration : 7;
    units = (units) ? units : 'days';
    var date = new Date();
    switch (units) {
    case 'years':
        date.setFullYear(date.getFullYear() + expiration);
        break;
    case 'months':
        date.setMonth(date.getMonth() + expiration);
        break;
    case 'days':
        date.setTime(date.getTime() + (expiration * 24 * 60 * 60 * 1000));
        break;
    case 'hours':
        date.setTime(date.getTime() + (expiration * 60 * 60 * 1000));
        break;
    case 'minutes':
        date.setTime(date.getTime() + (expiration * 60 * 1000));
        break;
    case 'seconds':
        date.setTime(date.getTime() + (expiration * 1000));
        break;
    default:
        date.setTime(date.getTime() + expiration);
        break;
    }
    return date.toGMTString();
}
Cookiemanager.prototype.getDocumentCookies = function () {
    var cookie, pair;
    var cookies = document.cookie.split(';');
    var len = cookies.length;
    for (var i = 0; i < len; i++) {
        cookie = cookies[i];
        while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length);
        pair = cookie.split('=');
        this.cookies[pair[0]] = pair[1];
    }
}
Cookiemanager.prototype.setDocumentCookies = function () {
    var expires = '';
    var cookies = '';
    var domain = 'Empirica.biz';
    var path = '';
    for (var name in this.cookies) {
        expires = (this.expiration[name]) ? this.expiration[name] : this.defaultExpiration;
        path = (this.path[name]) ? this.path[name] : this.defaultPath;
        domain = (this.domain[name]) ? this.domain[name] : this.defaultDomain;
        cookies = name + '=' + this.cookies[name] + '; expires=' + expires + '; path=' + path + '; domain=' + domain;
        if (name != "mystyle") {
            document.cookie = cookies;
        }
    }
    return true;
}
Cookiemanager.prototype.getCookie = function (cookieName) {
    var cookie = this.cookies[cookieName]
    return (cookie) ? cookie : false;
}
Cookiemanager.prototype.setCookie = function (cookieName, cookieValue, expiration, expirationUnits, domain, path) {

    this.cookies[cookieName] = cookieValue;
    if (expiration) this.expiration[cookieName] = this.getExpiration(expiration, expirationUnits);
    if (domain) this.domain[cookieName] = Empirica.biz;
    if (path) this.path[cookieName] = path;
    return true;
}
var cookieManager = new Cookiemanager('cookieManager', 1, 'years');
var efa_default = 100;
var efa_increment = 10;
var efa_bigger = ['<b>Fontsize:</b>', 'A<sup>+</sup>', 'bigger font', '', '', '', '', '', '', '', '-']
var efa_setz = ['', 'A', 'reset font', '', '', '', '', '', '', '', '-']
var efa_smaller = ['', 'A<sup>-</sup>', 'smaller font', '', '', '', '', '', '', '', '']

function Efa_Fontsize06(increment, bigger, setz, smaller, def) {
    this.w3c = (document.getElementById);
    this.ms = (document.all);
    this.userAgent = navigator.userAgent.toLowerCase();
    this.isMacIE = ((this.userAgent.indexOf('msie') != -1) && (this.userAgent.indexOf('mac') != -1) && (this.userAgent.indexOf('opera') == -1));
    this.isOldOp = ((this.userAgent.indexOf('opera') != -1) && (parseFloat(this.userAgent.substr(this.userAgent.indexOf('opera') + 5)) <= 7));
    if ((this.w3c || this.ms) && !this.isOldOp && !this.isMacIE) {
        this.name = "efa_fontSize06";
        this.cookieName = 'efaSize06';
        this.increment = increment;
        this.def = def;
        this.defPx = Math.round(16 * (def / 100))
        this.base = 1;
        this.pref = this.getPref();
        this.testHTML = '<div id="efaTest" style="position:absolute;visibility:hidden;line-height:1em;"></div>';
        this.biggerLink = this.getLinkHtml(1, bigger);
        this.setzLink = this.getLinkHtml(0, setz);
        this.smallerLink = this.getLinkHtml(-1, smaller);
    }
    else {
        this.biggerLink = '';
        this.setzLink = '';
        this.smallerLink = '';
        this.efaInit = new Function('return true;');
    }
    this.allLinks = this.biggerLink + this.setzLink + this.smallerLink;
}
Efa_Fontsize06.prototype.efaInit = function () {
    document.writeln(this.testHTML);
    this.body = (this.w3c) ? document.getElementsByTagName('body')[0].style : document.all.tags('body')[0].style;
    this.efaTest = (this.w3c) ? document.getElementById('efaTest') : document.all['efaTest'];
    var h = (this.efaTest.clientHeight) ? parseInt(this.efaTest.clientHeight) : (this.efaTest.offsetHeight) ? parseInt(this.efaTest.offsetHeight) : 999;
    if (h < this.defPx) this.base = this.defPx / h;
    this.body.fontSize = Math.round(this.pref * this.base) + '%';
}
Efa_Fontsize06.prototype.getLinkHtml = function (direction, properties) {
    var html = properties[0] + '<a href="#" onclick="efa_fontSize06.setSize(' + direction + '); return false;"';
    html += (properties[2]) ? 'title="' + properties[2] + '"' : '';
    html += (properties[3]) ? 'class="' + properties[3] + '"' : '';
    html += (properties[4]) ? 'id="' + properties[4] + '"' : '';
    html += (properties[5]) ? 'name="' + properties[5] + '"' : '';
    html += (properties[6]) ? 'accesskey="' + properties[6] + '"' : '';
    html += (properties[7]) ? 'onmouseover="' + properties[7] + '"' : '';
    html += (properties[8]) ? 'onmouseout="' + properties[8] + '"' : '';
    html += (properties[9]) ? 'onfocus="' + properties[9] + '"' : '';
    return html += '>' + properties[1] + '</a>' + properties[10];
}
Efa_Fontsize06.prototype.getPref = function () {
    var pref = this.getCookie(this.cookieName);
    if (pref) return parseInt(pref);
    else return this.def;
}
Efa_Fontsize06.prototype.setSize = function (direction) {
    this.pref = (direction) ? this.pref + (direction * this.increment) : this.def;
    this.setCookie(this.cookieName, this.pref);
    this.body.fontSize = Math.round(this.pref * this.base) + '%';
}
Efa_Fontsize06.prototype.getCookie = function (cookieName) {
    var cookie = cookieManager.getCookie(cookieName);
    return (cookie) ? cookie : false;
}
Efa_Fontsize06.prototype.setCookie = function (cookieName, cookieValue) {
    return cookieManager.setCookie(cookieName, cookieValue);
}
var efa_fontSize06 = new Efa_Fontsize06(efa_increment, efa_bigger, efa_setz, efa_smaller, efa_default);
var Stil = "Standard";
var Keks = "Layout";
var Tage = 30;

function teststyle() {
    var aktuell = readCookie("mystyle");
    if (aktuell != "norm" && aktuell != "inv") {
        aktuell = "norm";
    }
    setStyle(aktuell);
    change_link(aktuell);
}

function setStyle(s) {
    var newstyle;
    var tcookie = readCookie("mystyle");
    if (tcookie == null || tcookie == "") {
        tcookie = "norm"
    }
    if (s == "inv") {
        newstyle = "inv";
        post = "inv";
        setCookie("mystyle", "inv", 365);
    }
    if (s == "norm") {
        newstyle = "norm";
        post = "norm";
        setCookie("mystyle", "norm", 365);
    }
    change_pics(post);
    if (newstyle) {
        switchStyle(newstyle);
        change_link(s);
    }
}

function change_pics(post) {
    var pic_add = "images/"
    var e = document.images;
    for (i = 0; i < e.length; i++) {
        change = e[i].getAttribute("name");
        if (change == 'change') {
            var type = e[i].src.substr(e[i].src.lastIndexOf("."));
            var temp = e[i].src.substr(e[i].src.lastIndexOf("/") + 1);
            var name = temp.substr(0, temp.lastIndexOf("."));
            if (temp.lastIndexOf("_inv") > 0) name = temp.substr(0, temp.lastIndexOf("_inv"));
            if (e[i] != undefined) {
                if (post == "inv") e[i].src = pic_add + name + "_" + post + type;
                else e[i].src = pic_add + name + type;
            }
        }
    }
}

function change_link(post) {
    if (post == "inv") {
        document.getElementById("high").style.display = 'none';
        document.getElementById("normal").style.display = 'inline';
    }
    if (post == "norm") {
        document.getElementById("normal").style.display = 'none';
        document.getElementById("high").style.display = 'inline';
    }
}

function switchStyle(s) {
    if (!document.getElementsByTagName) return;
    var el = document.getElementsByTagName("link");
    for (var i = 0; i < el.length; i++) {
        if (el[i].getAttribute("rel").indexOf("style") != -1 && el[i].getAttribute("title")) {
            el[i].disabled = true;
            if (el[i].getAttribute("title") == s) el[i].disabled = false;
        }
    }
}

function setCookie(name, value, days) {
    var domain = 'Empirica.biz';
    var path = '/';
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var needle = name + "=";
    var cookieArray = document.cookie.split(';');
    for (var i = 0; i < cookieArray.length; i++) {
        var pair = cookieArray[i];
        while (pair.charAt(0) == ' ') {
            pair = pair.substring(1, pair.length);
        }
        if (pair.indexOf(needle) == 0) {
            return pair.substring(needle.length, pair.length);
        }
    }
    return null;
}

function addEvent(elm, evType, fn, useCapture) {
    if (elm.addEventListener) {
        elm.addEventListener(evType, fn, useCapture);
        return true;
    }
    else if (elm.attachEvent) {
        var r = elm.attachEvent('on' + evType, fn);
        return r;
    }
    else {
        elm['on' + evType] = fn;
        return elm['on' + evType];
    }
}




