function maandenARR(){
  return new Array('Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December');
}
function maakTabel(eerste,aantal,jaar,maand) { 
  var txt="<table cellpadding=0 cellspacing=0 id=calendar>";
  txt+='<tr><td class=header>ma</td><td class=header>di</td><td class=header>wo</td><td class=header>do</td><td class=header>vr</td><td class=header>za</td><td class="header nobo">zo</td></tr>';
  var teller=eerste-1; if (teller<0) teller=6
  if (teller>0) { txt+="<tr>"; for (i=0;i<teller;i++) txt+="<td ><span>&nbsp;</span></td>"; }
  for (i=1;i<=aantal;i++) {
    if (teller==0) txt+="<tr>"
	txt+="<td "+(teller==6?"class=nobo":"")+"><a href='/agenda"
	if (document.agendaCat) txt+="/categorie/"+document.agendaCat+"/"+document.agendaStrip
	txt+="/datum="+jaar+":"+(maand+1)+":"+i+"' class='"
	if (jaar+":"+maand+":"+(i-1)==document.vandaag) txt+="Vandaag";
	if (jaar+":"+maand+":"+(i-1)==document.gekozen) txt+="Gekozen";
	txt+="'>"+i+"</a></td>"
	teller++; if (teller==7) { txt+="</tr>"; teller=0; }
    }  
  if (teller>0) { for (i=teller;i<7;i++) txt+="<td "+(i==6?"class=nobo":"")+"><span>&nbsp;</span></td>"; txt+="</tr>"; }
  txt+="</table>"; 
  return txt
}
function initCalendar(jaarV,maandV,dagV,jaarG,maandG,dagG){
 if (jaarG) { document.jaar=jaarG; document.maand=maandG; }
   else  { document.jaar=jaarV; document.maand=maandV; }
 document.vandaag=jaarV+":"+maandV+":"+dagV; 
 document.gekozen=jaarG+":"+maandG+":"+dagG; 
 if (jaarG) setCalendar(jaarG,maandG)
 else setCalendar(jaarV,maandV)
}
function schrikkel(jaar) { 
  if (Math.floor(jaar/4)*4!=jaar) return false
  if (Math.floor(jaar/400)*400==jaar) return true
  if (Math.floor(jaar/100)*100==jaar) return false
  return true
}
function setCalendar(jaar,maand) { 
  var dagenMaand,dagenInMaand=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var maanden=maandenARR();
  var dezeMaand= new Date(jaar, maand, 1);
  var volgendeMaand= new Date(jaar, maand+1, 1);
  var eersteDag = dezeMaand.getDay();
  if (maand==1&&schrikkel(jaar)) dagenMaand=29;
  else  dagenMaand = dagenInMaand[maand] //Math.floor((volgendeMaand.getTime() - dezeMaand.getTime() )  / (1000 * 60 * 60 * 24));
  var strMJ=maanden[maand]+"&nbsp;"+jaar
  var strCal=maakTabel(eersteDag,dagenMaand,jaar,maand)
  document.getElementById('maandDiv').innerHTML=strMJ
  document.getElementById('calendarDiv').innerHTML=strCal
 }
function nextMonth(){ if (!(document.maand||document.maand==0)) return
  document.maand++; if (document.maand>11) {document.maand=0; document.jaar++; }
  setCalendar(document.jaar,document.maand,-1);
}
function prevMonth(){ if (!(document.maand||document.maand==0)) return
  document.maand--; if (document.maand<0) {document.maand=11; document.jaar--; }
  setCalendar(document.jaar,document.maand,-1);
}
function favoSwitch(cat,cstrip,period,datum,aan){
  var t='agenda'+(cat>10?'/categorie/'+cat+'/'+cstrip:'')+(period?'/period='+period:'')+(datum?'/datum='+datum:'')
  if (aan) window.location=t+'/favo_on=1'
  else window.location=t+'/favo_off=1'
}
function agendaKeep(id,ch){
    if (ch||ch==1) ch=1; else ch=0;
    if (document.xmlHttp) {
       try {
		 if (document.xmlHttp.readyState==0||document.xmlHttp.readyState==4){
		   document.xmlHttp.open("GET","/art/add_to_agenda.php?id="+id+"&ch="+ch,true)
	       document.xmlHttp.send(null);
		   }
		   else setTimeout("agendaKeep("+id+","+ch+")",500)
	  }
   catch (e) {}
  }
  else alert('browser does not allow http-request')
}
