// Modified from Bill Dortch's Cookie Functions (hidaho.com) 
// (found in JavaScript Bible)
function setCookie(name,value,days,path,domain,secure) {
  var expires, date;
  if (typeof days == "number") {
    date = new Date();
    date.setTime( date.getTime() + (days*60*60*1000) );
		expires = date.toGMTString();
  }
  document.cookie = name + "=" + escape(value) +
    ((expires) ? "; expires=" + expires : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

// Modified from Jesse Chisholm or Scott Andrew Lepera ?
// (found at both www.dansteinman.com/dynapi/ and www.scottandrew.com/junkyard/js/)
function getCookie(name) {
  var nameq = name + "=";
  var c_ar = document.cookie.split(';');
  for (var i=0; i<c_ar.length; i++) {
    var c = c_ar[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameq) == 0) return unescape( c.substring(nameq.length, c.length) );
  }
  return null;
}

// from Bill Dortch's Cookie Functions (hidaho.com) 
function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

var fontSizer = {
  // sizeUnit and defaultSize for body.style.fontSize
  sizeUnit: "%",
  defaultSize: 100,
  // numbers (same unit as sizeUnit)
  maxSize:     250,
  minSize:     80,

  init: function() {
    if ( !document.body || !document.getElementById ) return;
    var size = window.location.search? window.location.search.slice(1): getCookie("fontSize");
    //var size = document.getElementById('fontsize').value;
	size = !isNaN( parseFloat(size) )? parseFloat(size): this.defaultSize;
    // in case default unit changed or size passed in url out of range
    if ( size > this.maxSize || size < this.minSize ) size = this.defaultSize;
   
    document.body.style.fontSize = size + this.sizeUnit;
  },
  
  adjust: function(inc) {
    var size = parseFloat( document.body.style.fontSize );
    /* !!!!! Änderung  Anfang !!!! */
    size = !isNaN( parseFloat(size) )? parseFloat(size): this.defaultSize;
    /* !!!!! Änderung Ende  !!!! */
    size += inc;
    // Test against max and min sizes 
    if (inc > 0) size = Math.min(size, this.maxSize);
    else if(inc < 0) size = Math.max(size, this.minSize);
	else size = 100;
	//document.getElementById('fontsize').value = size;
    setCookie( "fontSize", size, 180, "/" );
    document.body.style.fontSize = size + this.sizeUnit;
  },

  reset: function() {
    document.body.style.fontSize = this.defaultSize + this.sizeUnit;
    deleteCookie("fontSize", "/");
	//document.getElementById('fontsize').value = 100;
  }
  
}


