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=''
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
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]=domain
if(path)this.path[cookieName]=path
return true}
var cookieManager=new Cookiemanager('cookieManager',1,'years')
// efa_fontsize.js von www.einfach-fuer-alle.de
//
// letzer Aufruf in efaInit und setSize sind hinzugefügt.

var efa_default=78
var efa_increment=10
var efa_bigger=['<p><span id="fontsizehead" class="navhead">Schrift: </span>',
'gr&ouml;sser',
'Schrift gr&ouml;sser stellen',
'',
'',
'',
'',
'',
'',
'',
' '
]
var efa_reset=['',
'zur&uuml;cksetzen',
'Schriftgr&ouml;&szlig;e normal',
'',
'',
'',
'',
'',
'',
'',
' '
]
var efa_smaller=['',
'kleiner',
'Schrift kleiner stellen',
'',
'',
'',
'',
'',
'',
'',
'<'+'/p>'
]

function Efa_Fontsize(increment,bigger,reset,smaller,def){
this.w3c=(document.getElementById)
this.ms=(document.all)
this.userAgent=navigator.userAgent.toLowerCase()
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_fontSize"
this.cookieName='efaSize'
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.resetLink=this.getLinkHtml(0,reset)
this.smallerLink=this.getLinkHtml(-1,smaller)
}else{
this.biggerLink=''
this.resetLink=''
this.smallerLink=''
this.efaInit=new Function('return true;')}
this.allLinks=this.biggerLink+this.resetLink+this.smallerLink}

Efa_Fontsize.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)+'%'
this.test=ekgHI_Styleswitch()}

Efa_Fontsize.prototype.getLinkHtml=function(direction,properties){
var html=properties[0]+'<a href="#" onclick="efa_fontSize.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_Fontsize.prototype.getPref=function(){
var pref=this.getCookie(this.cookieName)
if(pref)return parseInt(pref)
else return this.def}

Efa_Fontsize.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)+'%'
this.test=ekgHI_Styleswitch()}

Efa_Fontsize.prototype.getCookie=function(cookieName){
var cookie=cookieManager.getCookie(cookieName)
return(cookie)?cookie:false}
Efa_Fontsize.prototype.setCookie=function(cookieName,cookieValue){
return cookieManager.setCookie(cookieName,cookieValue)}
var efa_fontSize=new Efa_Fontsize(efa_increment,efa_bigger,efa_reset,efa_smaller,efa_default)
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel") && a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) {
	a.disabled = false;
	cookieManager.setCookie("style", title, 365);
      }
    }
  }
}

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;
}

var cookie = cookieManager.getCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
//Determines switchpoints: Number of ems that must fit into the window to make a specific layout allowed.
var ekgHI_XL=90;
var ekgHI_L=74;

// switch stylesheets depending on font size AND window dimensions 
// adapted from Kevin Hale's Dynamic Resolution Dependent Layouts on Particletree.com

function ekgHI_Styleswitch(){
                
                var browserWidth= getBrowserWidth();
                var pageWidthXL= Math.round(efa_fontSize.pref*efa_fontSize.base/100*ekgHI_XL*16);
                var pageWidthL= Math.round(efa_fontSize.pref*efa_fontSize.base/100*ekgHI_L*16);
//                alert (browserWidth + " " + pageWidthXL + " " + pageWidthL);                
                
                if (browserWidth > pageWidthXL) {
                            changeLayout("wider");
             
                }

                if ((browserWidth >= pageWidthL) && (browserWidth<= pageWidthXL)) {
                            changeLayout("wide");
                }             
                
                if (browserWidth < pageWidthL) {
                            changeLayout("thin");
                }
}


function resize() {
             if (efa_fontSize) {
             test=ekgHI_Styleswitch();}
}


// getBrowserWidth is taken from The Man in Blue Resolution Dependent Layout Script
// http://www.themaninblue.com/experiment/ResolutionLayout/
	function getBrowserWidth(){
		if (window.innerWidth){
			return window.innerWidth;}	
		else if (document.documentElement && document.documentElement.clientWidth != 0){
			return document.documentElement.clientWidth;	}
		else if (document.body){return document.body.clientWidth;}		
			return 0;
	}


// changeLayout is based on setActiveStyleSheet function by Paul Sowdon 
// http://www.alistapart.com/articles/alternate/
function changeLayout(description){
   var i, a;
   for(i=0; (a = document.getElementsByTagName("link")[i]); i++){
	   if ((a.getAttribute("rel") == "alternate stylesheet")||(a.getAttribute("rel") == "stylesheet")) {
                          if (a.getAttribute("title") == description){a.disabled = false;}
	                  else if (!a.getAttribute("title")) {}
                          else {a.disabled = true;}
                          }
            }
   }

//addEvent() by John Resig
           function addEvent( obj, type, fn ){ 
	   if (obj.addEventListener){ 
	      obj.addEventListener( type, fn, false );
	   }
	   else if (obj.attachEvent){ 
	      obj["e"+type+fn] = fn; 
	      obj[type+fn] = function(){ obj["e"+type+fn]( window.event ); } 
	      obj.attachEvent( "on"+type, obj[type+fn] ); 
	   } 
	} 
	


//Run dynamicLayout function when page loads and when it resizes.
addEvent(window, 'resize', resize);

/* http://www.kryogenix.org/code/browser/searchhi/ */
/* Modified 20021006 to fix query string parsing and add case insensitivity */
function highlightWord(node,word) {
	// Iterate into this nodes childNodes
	if (node.hasChildNodes) {
		var hi_cn;
		for (hi_cn=0;hi_cn<node.childNodes.length;hi_cn++) {
			highlightWord(node.childNodes[hi_cn],word);
		}
	}
	
	// And do this node itself
	if (node.nodeType == 3) { // text node
		tempNodeVal = node.nodeValue.toLowerCase();
		tempWordVal = word.toLowerCase();
		if (tempNodeVal.indexOf(tempWordVal) != -1) {
			pn = node.parentNode;
			if (pn.className != "searchword") {
				// word has not already been highlighted!
				nv = node.nodeValue;
				ni = tempNodeVal.indexOf(tempWordVal);
				// Create a load of replacement nodes
				before = document.createTextNode(nv.substr(0,ni));
				docWordVal = nv.substr(ni,word.length);
				after = document.createTextNode(nv.substr(ni+word.length));
				hiwordtext = document.createTextNode(docWordVal);
				hiword = document.createElement("span");
				hiword.className = "searchword";
				hiword.appendChild(hiwordtext);
				pn.insertBefore(before,node);
				pn.insertBefore(hiword,node);
				pn.insertBefore(after,node);
				pn.removeChild(node);
			}
		}
	}
}

function googleSearchHighlight() {
	if (!document.createElement) return;
	ref = document.referrer;
	if (ref.indexOf('?') == -1) return;
	qs = ref.substr(ref.indexOf('?')+1);
	qsa = qs.split('&');
	for (i=0;i<qsa.length;i++) {
		qsip = qsa[i].split('=');
	        if (qsip.length == 1) continue;
        	if (qsip[0] == 'q' || qsip[0] == 'p') { // q= for Google, p= for Yahoo
			words = unescape(qsip[1].replace(/\+/g,' ')).split(/\s+/);
	                for (w=0;w<words.length;w++) {
				highlightWord(document.getElementsByTagName("body")[0],words[w]);
                	}
	        }
	}
}

window.onload = googleSearchHighlight;

