/* functions to handle cookies */
function setCookie(key,val,expire) {
  var value = escape(val);
  if (expire) {
    var a = new Date();
    a = new Date(a.getTime() + expire);
    cookieValue = key+'='+value+'; expires='+a.toGMTString()+';';
  } else {
    cookieValue = key+'='+value+';';  
  }
  document.cookie = cookieValue;
}

function getCookie(key) {
 a = document.cookie;
 res = '';
 while(a != '' && res == '') {
  cookiename = trim (a.substring(0,a.search('=')));
  cookiewert = a.substring(a.search('=')+1,a.search(';'));
  if(cookiewert == '') {
    cookiewert = a.substring(a.search('=')+1,a.length);
  }

  if(key == cookiename) {
    res = cookiewert;
  }

  i = a.search(';')+1;
  if(i == 0) { 
    i = a.length
  }
  a = a.substring(i,a.length);
 }
 
 return(res)
}

function delCookie(key) {
 document.cookie = key+'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
} 

function trim (zeichenkette) {
  return zeichenkette.replace (/^\s+/, '').replace (/\s+$/, '');
}