// Hidden fields

function toggle(obj) { 
	var el = document.getElementById(obj); 
	if ( el.style.display != 'none' ) { 
		el.style.display = 'none'; 
	} 
	else { 
		el.style.display = ''; 
	} 
}

// Woordenlijst tooltip

// position of the tooltip relative to the mouse in pixel //
var offsetx = 50;
var offsety =  10;

function newelement(newid)
{ 
    if(document.createElement)
    { 
        var el = document.createElement('div'); 
        el.id = newid;     
        with(el.style)
        { 
            display = 'none';
            position = 'absolute';
        } 
        el.innerHTML = '&nbsp;'; 
        document.body.appendChild(el); 
    } 
} 

var ie5 = (document.getElementById && document.all); 
var ns6 = (document.getElementById && !document.all); 

function getmouseposition(e)
{
    if(document.getElementById)
    {
        mousex = (ie5)?event.x:(ns6)?clientX = e.clientX:false;
        mousey = (ie5)?event.y:(ns6)?clientY = e.clientY:false;
        var lixlpixel_tooltip = document.getElementById('tooltip');
        lixlpixel_tooltip.style.left = (mousex+offsetx) + 'px';
        lixlpixel_tooltip.style.top = (mousey+offsety) + 'px';
    }
}

function tooltip(tip)
{
    if(!document.getElementById('tooltip')) newelement('tooltip');
    var lixlpixel_tooltip = document.getElementById('tooltip');
    lixlpixel_tooltip.innerHTML = tip;
    lixlpixel_tooltip.style.display = 'block';
    document.onmousemove = getmouseposition;
}

function exit()
{
    document.getElementById('tooltip').style.display = 'none';
}

// non-persistent cookie

function Cookie(document,name,hours,path,domain,secure) {
  // any VAR in "this" that does not start with a "$" will
  // be written into the cookie (read from also)
  this.$doc  = document;
  this.$name = name;

  if (hours)  this.$expiration=new Date((new Date()).getTime()+hours*3600000);
  else this.$expiration = null;

  if (path)   this.$path   = path;
  else this.$path       = null;

  if (domain) this.$domain = domain;
  else this.$domain     = null;

  if (secure) this.$secure = true;
  else this.$secure     = false;
}

function CookieWrite() {
  var cookieval="";
  for(var prop in this) {
    if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function') || prop == '') continue;
	if (cookieval != "") cookieval += '&';
	cookieval+=prop+":"+escape(this[prop]);
  }
  var cookie=this.$name+"="+cookieval;
  if (this.$expiration) cookie+='; expires=' + this.$expiration.toGMTString();
  if (this.$path)       cookie+='; path='    + this.$path;
  if (this.$domain)     cookie+='; domain='  + this.$domain;
  if (this.$secure)     cookie+='; secure';
  this.$doc.cookie=cookie;
}

function CookieRead() {
  var allcookies=this.$doc.cookie;
  if (allcookies=="") {
    return false;
  }
  var start= allcookies.indexOf(this.$name+'=');
  if (start== -1) {
    return false;
  }
  start += this.$name.length+1;
  var end=allcookies.indexOf(';',start);
  if (end == -1) end=allcookies.length;
  var cookieval = allcookies.substring(start,end);
  var a = cookieval.split('&');
  for (var i=0;i < a.length;i++) a[i]=a[i].split(':');
  for (var i=0;i < a.length;i++) this[a[i][0]]=unescape(a[i][1]);
  return true;
}

function CookieDelete() {
  var cookie = this.$name+'=';
  if (this.$path)   cookie+='; path='+this.$path;
  if (this.$domain) cookie+='; domain='+this.$domain;
  cookie+='; expires=Fri, 02-Jan-1970 00:00:00 GMT';  // MAKE IT EXPIRE!
  this.$doc.cookie=cookie;
}

new Cookie();
Cookie.prototype.write = CookieWrite;
Cookie.prototype.del   = CookieDelete;
Cookie.prototype.read  = CookieRead;

// Styleswitcher

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

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;
}

window.onload = function(e) {
  var cookie = new Cookie(document,"fontsize",24,'/',0,0);
  var title;

  if (!cookie.read() || !cookie.style) { 
	title = getPreferredStyleSheet();
  }
  else {
	title = cookie.style;
  }

  setActiveStyleSheet(title);

  buttonNormal = document.getElementById('fontNormal');
  buttonLarger = document.getElementById('fontLarger');
  buttonLargest = document.getElementById('fontLargest');

  buttonNormal.onclick = function() {
  	setActiveStyleSheet(''); 
    cookie.style = ' ';
    cookie.write();
    return false;
  }
  buttonLarger.onclick = function() {
  	setActiveStyleSheet('groter'); 
    cookie.style = 'groter';
    cookie.write();
    return false;
  }
  buttonLargest.onclick = function() {
  	setActiveStyleSheet('grootst'); 
    cookie.style = 'grootst';
    cookie.write();
    return false;
  }


	// set hidden fields
  	var x = document.getElementsByTagName('div');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].className == 'hidden')
			x[i].style.display = 'none'
	}
}
