

  var now=new Date();
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);  // to expire in 1 year

  function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getAgenda(){
// get cookie content, post back to form, then redirect to agenda page
var cookieContent=getCookie("GEC");
document.forms[0].cookieContent.value=cookieContent;
return true;
}

function refreshAgenda(){
	
}


/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function addToAgenda(idEvent,dateText,fromDate,times){
  
  if (times==null)
	times=''
	
  var nextId=1;
  var cookieData=getCookie("GEC");
  if (cookieData==null)
	cookieData=nextId;	
  else{
    // the first item is a counter representing the unique id for the next item
	// the separator is ~
	var items=cookieData.split('~')
	nextId=parseInt(items[0])+1
	cookieData=nextId;
	// recompose cookie
	for (i=1;i<items.length;i++)
		cookieData+='~'+items[i];
  }
  // add the new item to the end of the cookie
  cookieData+='~'+nextId+':'+idEvent+':'+dateText+':'+fromDate.substring(0,10);
  if (times!='')cookieData+=":"+times;
  setCookie("GEC", cookieData,now);
  
  alert('Dit evenement werd toegevoegd aan jouw agenda!')
}
/*
removes this id from the agenda
*/
function remove(id){
  id=id+''
  var cookieData=getCookie("GEC");
  if (cookieData==null)
	return
  
    // the first item is a counter representing the unique id for the next item
	// the separator is ~
	var items=cookieData.split('~')
	// recompose the cookie without the selected id
	cookieData=items[0]
	for (i=1;i<items.length;i++){
		subItems=items[i].split(':');
		thisId=subItems[0];
		if (thisId!=id)
			cookieData+='~'+items[i];	
		//else
		//	alert('This entry has been removed from your agenda. Click the Agenda button to refresh');
	}
	setCookie("GEC", cookieData,now); 
	
	// now reload the agenda page:
	getAgenda(); // sets the hidden value
	document.forms[0].submit();
	
	
}
	

