// -->
//=========================================================================================
// Project: ERA eHealth
// Comment: The JavaScript Function Library of the Project
// Version: 1.6
//=========================================================================================


//==============================================================================
// Function : Zebra Tables
// Comment  : Horizontal stripes in tables 
// Arguments: -
//==============================================================================
  function hasClass(obj) {
     var result = false;
     if (obj.getAttributeNode("class") != null) {
         result = obj.getAttributeNode("class").value;
     }
     return result;
  }   

 function stripe(id) {

    var even = false;
  
    var evenColor = arguments[1] ? arguments[1] : "#fff";
    var oddColor = arguments[2] ? arguments[2] : "#EAF3FC";
  
    //var tables = document.getElementsByTagName("table");
    //if (! table) { return; }
    
    var tbodies = document.getElementsByTagName("tbody");

    for (var h = 0; h < tbodies.length; h++) {
    
      var trs = tbodies[h].getElementsByTagName("tr");
      
      for (var i = 0; i < trs.length; i++) {

	    if (!hasClass(trs[i]) && ! trs[i].style.backgroundColor) {
 
          var tds = trs[i].getElementsByTagName("td");
        
          for (var j = 0; j < tds.length; j++) {
        
            var mytd = tds[j];

	        if (! hasClass(mytd) && ! mytd.style.backgroundColor) {
        
		      mytd.style.backgroundColor = even ? evenColor : oddColor;

            
            }
          }
        }
        even =  ! even;
      }
    }
  }



//==============================================================================
// Function : Cookies Fontsize
// Comment  : Cooky used to store status of font resizing script 
// Arguments: -
//==============================================================================

// name = string equal to the name of the instance of the object
// defaultExpiration = number of units to make the default expiration date for the cookie
// expirationUnits = 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years' (default is 'days')
// defaultDomain = string, default domain for cookies; default is current domain minus the server name
// defaultPath = string, default path for cookies; default is '/'
function Cookiemanager(name,defaultExpiration,expirationUnits,defaultDomain,defaultPath) {
	// remember our name
	this.name = name;
	// get the default expiration
	this.defaultExpiration = this.getExpiration(defaultExpiration,expirationUnits);
	// set the default domain to defaultDomain if supplied; if not, set it to document.domain
	// if document.domain is numeric, otherwise strip off the server name and use the remainder
	this.defaultDomain = (defaultDomain)?defaultDomain:(document.domain.search(/[a-zA-Z]/) == -1)?document.domain:document.domain.substring(document.domain.indexOf('.') + 1,document.domain.length);
	// set the default path
	this.defaultPath = (defaultPath)?defaultPath:'/';
	// initialize an object to hold all the document's cookies
	this.cookies = new Object();
	// initialize an object to hold expiration dates for the doucment's cookies
	this.expiration = new Object();
	// initialize an object to hold domains for the doucment's cookies
	this.domain = new Object();
	// initialize an object to hold paths for the doucment's cookies
	this.path = new Object();
	// set an onlunload function to write the cookies
	window.onunload = new Function (this.name+'.setDocumentCookies();');
	// get the document's cookies
	this.getDocumentCookies();
	}
// gets an expiration date for a cookie as a GMT string
// expiration = integer expressing time in units (default is 7 days)
// units = 'miliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years' (default is 'days') 
Cookiemanager.prototype.getExpiration = function(expiration,units) {
	// set default expiration time if it wasn't supplied
	expiration = (expiration)?expiration:7;
	// supply default units if units weren't supplied
	units = (units)?units:'days';
	// new date object we'll use to get the expiration time
	var date = new Date();
	// set expiration time according to units supplied
	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 expiration as GMT string
	return date.toGMTString();
	}
// gets all document cookies and populates the .cookies property with them
Cookiemanager.prototype.getDocumentCookies = function() {
	var cookie,pair;
	// read the document's cookies into an array
	var cookies = document.cookie.split(';');
	// walk through each array element and extract the name and value into the cookies property
	var len = cookies.length;
	for(var i=0;i < len;i++) {
		cookie = cookies[i];
		// strip leading whitespace
		while (cookie.charAt(0)==' ') cookie = cookie.substring(1,cookie.length);
		// split name/value pair into an array
		pair = cookie.split('=');
		// use the cookie name as the property name and value as the value
		this.cookies[pair[0]] = pair[1];
		}
	}
// sets all document cookies
Cookiemanager.prototype.setDocumentCookies = function() {
	var expires = '';
	var cookies = '';
	var domain = 'Empirica.biz';
	var path = '';
	for(var name in this.cookies) {
		// see if there's a custom expiration for this cookie; if not use default
		expires = (this.expiration[name])?this.expiration[name]:this.defaultExpiration;
		// see if there's a custom path for this cookie; if not use default
		path = (this.path[name])?this.path[name]:this.defaultPath;
		// see if there's a custom domain for this cookie; if not use default
		domain = (this.domain[name])?this.domain[name]:this.defaultDomain;
		// add to cookie string
		cookies = name + '=' + this.cookies[name] + '; expires=' + expires + '; path=' + path + '; domain=' + domain;
		
		if(name!="mystyle"){ document.cookie = cookies;}
		
		}
	return true;
	}
// gets cookie value
// cookieName = string, cookie name
Cookiemanager.prototype.getCookie = function(cookieName) {
	var cookie = this.cookies[cookieName]
	return (cookie)?cookie:false;
	}
// stores cookie value, expiration, domain and path
// cookieName = string, cookie name
// cookieValue = string, cookie value
// expiration = number of units in which the cookie should expire
// expirationUnits = 'miliseconds' | 'seconds' | 'minutes' | 'hours' | 'days' | 'months' | 'years' (default is 'days')
// domain = string, domain for cookie
// path = string, path for cookie
Cookiemanager.prototype.setCookie = function(cookieName,cookieValue,expiration,expirationUnits,domain,path) {
	this.cookies[cookieName] = cookieValue;
	// set the expiration if it was supplied 
	if (expiration) this.expiration[cookieName] = this.getExpiration(expiration,expirationUnits);
	// set path if it was supplied
	if (domain) this.domain[cookieName] = Empirica.biz;
	if (path) this.path[cookieName] = path;
	return true;
	}

var cookieManager = new Cookiemanager('cookieManager',1,'years');



//==============================================================================
// Function : Fontsize Switch
// Comment  : Stepwise increase/decrease font size 
// Arguments: -
//==============================================================================

var efa_default = 100;
var efa_increment = 20;
var efa_bigger = ['Schriftgröße:',
	'A<sup>+</sup>',
	'Schrift grösser stellen',
	'mmhide_topmen-link',
	'',
	'',
	'',
	'',
	'',
	'',
	' &#8226; '
	]

var efa_setz = ['',
	'A',
	'Schrift zur&uuml;cksetzen',
	'mmhide_topmen-link',
	'',
	'',
	'',
	'',
	'',
	'',
	' &#8226; '
	]

var efa_smaller = ['',
	'A<sup>-</sup>',
	'Schrift kleiner stellen',
	'mmhide_topmen-link',
	'',
	'',
	'',
	'',
	'',
	'',
	''
	]

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;">&nbsp;</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 += '><span class="text-bold">'+ properties[1] + '</span><' + '/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);


//==============================================================================
// Function : Alternate Stylesheet Switch
// Comment  : Switches between alternate stylesheets
// Arguments: -
//=============================================================================





var Stil = "Standard";
var Keks = "Layout";
var Tage = 30;

// Style Switcher

//test
function test(){
	var aktuell = readCookie("mystyle");
	
	//erstes laden cookie = null
	if (aktuell!="emp_norm" && aktuell!="emp_inv") {
		aktuell="emp_norm";
	}
	setStyle(aktuell);
	//wechselt den link
	change_link(aktuell);
}

function setStyle(s) {
	var newstyle;
	var tcookie=readCookie("mystyle");
	//wenn kein keks existiert füge einen hinzu mit standardstyle
	if (tcookie==null || tcookie=="") {tcookie="emp_norm"}
	
	//wenn keks emp
	if(s=="emp_inv"){
		newstyle="emp_inv";
		post="inv";
		setCookie("mystyle", "emp_inv" , 365);
	}
	if( s=="emp_norm"){
		newstyle="emp_norm";	
		post="norm";
		setCookie("mystyle", "emp_norm" , 365);
	}
	change_pic(post, "print", "gif");
	change_pic(post, "banner_de", "gif");
	change_pic(post, "emp_logo", "gif");
	change_pic(post, "topmenu-ecke", "gif");
	if(newstyle){
		switchStyle(newstyle);
		change_link(s);
	}
}

function change_pic(post, name, type){
	var pic_add = "http://www.empirica.biz/images/"
	if (document.images[name]!=undefined){
		document.images[name].src= pic_add+""+name+"_"+post+"."+type;
	}
}

function change_link(post){
	if (post=="emp_inv") {
		document.getElementById("high").style.display = 'none';
		document.getElementById("normal").style.display = 'inline';
	}
	if (post=="emp_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;
    }
  }
}

// Set the cookie
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 = "";
	//alert("document.cookie = "+ name + '=' + value + '; expires=' + date + '; path=' + path + '; domain=' + domain);
//	document.cookie = name + '=' + value + expires +'; path=' + path + '; domain=' + domain;

	document.cookie = name+"="+value+expires+"; path=/";
}

// Read the cookie
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];
		}
}

/*
This style switcher enhancement was written by Ian Lloyd (http://lloydi.com/). 
The basis for this addition comes from Ethan Marcotte's style switcher as 
documented in the Wrox book professional CSS.

Feel free to use on your site but please leave comment as-is (adding your  
own comments regarding further modifications that you may choose to make.
*/

// VARIABLES - uncomment and customise to suit needs
var ContainerID = "center"; //Add the name of the container that you want the switcher tool to be written into here
var Position = "first"; // If you enable this, the switcher will be inserted as either the first item in the parent container, otherwise it'll add as last item
var PromptMessage = "Did you notice that you can change the display of this site using these links above? [This note will not be displayed after you hit refresh or visit another page]";
var promptTrigger = 20; //how many page views until the prompt to check out the other styles appears;
// End variables



function is_active(){
//	url bekommt die browserurlübergeben
	var url = document.URL;
	//für alle mit dem namen "link" das sollen nur die navigationslinks sein
	for (var i = 0; i < document.getElementsByName("link").length; ++i){
		//prüfe ob navilink in der URL enthalten ist
		var erg = url.indexOf(document.getElementsByName("link")[i]);

		if(erg!="-1"){
			document.getElementsByName("link")[i].className = "active";
		}
	}
}