var cookiePath="";
/*if (cookiePath=="" && location.pathname!="" && location.protocol.toLowerCase().substring(0,4)!="file") {
  cookiePath=location.pathname;
}
if(cookiePath!="") {
  cookiePath=cookiePath.substring(0,cookiePath.lastIndexOf("/")+1);
}
*/
cookiePath = '/';
var cookieDomain="";
if (cookieDomain=="" && location.hostname!="" && location.protocol.toLowerCase().substring(0,4)!="file") {
  cookieDomain=location.hostname;
}

function saveCookie(name,str,exp) {
  var strPath=cookiePath;
  var strDomain=cookieDomain;
  if(location.protocol.toLowerCase().substring(0,4)=="file") {
    strPath="";
    strDomain="";
  }
  var cookieStr="ET01"+str;       // set version number
//alert(name+':'+str);
var cookie=name+"="+escape(cookieStr);
  var expiration=new Date();
  if (exp==-1) {                  // onbeperkt houdbaar ;-)
    expiration.setYear(2100);
    expiration.setMonth(01);
    expiration.setDate(01);
  } else {                        // of opgegeven aantal dagen....
    var t=expiration.getTime();
    var msPerDay=24*60*60*1000;
    t+=(msPerDay*exp);
    expiration.setTime(t);
  }
  if(exp!=0) {
    cookie+='; expires='+expiration.toGMTString();
  } else {                        // duur 0, dus meteen weer verwijderen.....
    cookie=name+'=';
  }
  if(strPath!="") {
    cookie+='; path='+strPath;
  }
  if(strDomain.indexOf('.') > 0 ) { // localhosts uitsluiten...
    cookie+='; domain='+strDomain;
  }
  document.cookie=cookie;
//alert(cookie);
}

function getCookie(name) {
  var allCookies=document.cookie;
  var start=allCookies.indexOf('; '+name+"=ET01");             // & check version number
  if (allCookies.indexOf(name+"=ET01") == 0 ) { start = 0; }
  else if (start > 0 )                        { start+= 2; }
//  alert(typeof(allCookies)+"\n"+allCookies);
  if(start==-1) { return(""); }
  start+=name.length+1;
  var end=allCookies.indexOf(';',start);
  if(end==-1)   { end=allCookies.length; }
  var cookieStr=unescape(allCookies.substring(start,end));
  if(cookieStr.length<4) return("");
  cookieStr=cookieStr.substring(4,cookieStr.length);
  return(cookieStr);
}

