%D \module
%D   [     file=t-pocketdiary,
%D      version=2011.04.25,
%D        title=\CONTEXT\ User Module,
%D     subtitle=PocketDiary,
%D       author=Willi Egger,
%D         date=\currentdate,
%D    copyright=Willi Egger,
%D        email=w.egger@boede.nl,
%D      license=Public Domain]

\startmodule[pocketdiary]

%D \subsubject{Introduction}
%D 
%D It is already some time ago, that my brother Heinz asked me to prepare him a 
%D special page-arrangement scheme.
%D This scheme is suitable to form a section with a single-sided printed sheet of paper. 
%D He wanted to use it for special kind of greeting-cards. By coincidence I 
%D detected an article by U. Ziegenhagen in de \TEX nische 
%D Kommödie nr. 3/2010. This article deals with the preparation of a PocketMod, 
%D which is a personal organizer 
%D based on the mentioned arranging scheme. In the article there is also a link mentioned to an online 
%D version of the PocketMod. (http://www.pocketmod.com/). 
%D -- After reading the article and visiting the web-site I got
%D intrigued by the fact, that \CONTEXT\ has built in arranging capabilities and 
%D due to the \LUATEX\ engine it
%D should be possible to build such a personal organizer in \CONTEXT.
%D 
%D The result is contained in this module. I would like to thank Hans Hagen 
%D and Taco Hoekwater for the great
%D \LUATEX\ machinery and Wolfgang Schuster for supporting me in tackling the multi-lingual interface.

%D \subject{Lua-file}
%D All calculations for dates are performed with LUA functions. The functions are contained in 
%D \type{t-calendar.lua}

\ctxloadluafile{t-calendar}{}

%D \subsubject{International interface}
%D
%D The PocketDiary is aware of different languages. The language to be used is 
%D selected with \type{\mainlanguage[en]}. The following interfaces are available
%D 
%D \startitemize[2,packed]
%D    \item Englisch interface
%D    \item Dutch interface
%D    \item German interface
%D    \item Italian interface
%D    \item French interface
%D \stopitemize 

\setuplabeltext[en][weekagenda=Week calendar]
\setuplabeltext[en][week=Week]
\setuplabeltext[en][contact=Contact]
\setuplabeltext[en][name=Name]
\setuplabeltext[en][address=Address]
\setuplabeltext[en][zip=Zip]
\setuplabeltext[en][place=Place]
\setuplabeltext[en][country=Country]
\setuplabeltext[en][phone=Phone]
\setuplabeltext[en][mail=e-mail]
\setuplabeltext[en][notes=Notes]
\setuplabeltext[en][todo=Todo]
\setuplabeltext[en][found={If found\textcomma\ please return to:}]

\setuplabeltext[en][nyd=New Year's Day]
\setuplabeltext[en][ashw={Ash Wednesday}]
\setuplabeltext[en][palms={Palm Sunday} ]
\setuplabeltext[en][gfri={Good Friday} ]
\setuplabeltext[en][esun={Easter Sunday}]
\setuplabeltext[en][esmo={Easter Monday}]
\setuplabeltext[en][ascd={Ascension Day}]
\setuplabeltext[en][pcst=Pentecost]
\setuplabeltext[en][pcstmo=Pentecost Monday]
\setuplabeltext[en][xmas=Christmas]
\setuplabeltext[en][bxd={Boxing Day}]
\setuplabeltext[en][mon=Mon]
\setuplabeltext[en][tue=Tue]
\setuplabeltext[en][wed=Wed]
\setuplabeltext[en][thu=Thu]
\setuplabeltext[en][fri=Fri]
\setuplabeltext[en][sat=Sat]
\setuplabeltext[en][sun=Sun]

\setuplabeltext[en][january=January]
\setuplabeltext[en][february=February]
\setuplabeltext[en][march=March]
\setuplabeltext[en][april=April]
\setuplabeltext[en][may=May]
\setuplabeltext[en][june=June]
\setuplabeltext[en][july=July]
\setuplabeltext[en][august=August]
\setuplabeltext[en][september=September]
\setuplabeltext[en][october=October]
\setuplabeltext[en][november=November]
\setuplabeltext[en][december=December]

% German interface
\setuplabeltext[de][weekagenda=Wochenagenda]
\setuplabeltext[de][week=Woche]
\setuplabeltext[de][contact=Kontakt]
\setuplabeltext[de][name=Name]
\setuplabeltext[de][address=Adresse]
\setuplabeltext[de][zip=Postleitzahl]
\setuplabeltext[de][place=Ort]
\setuplabeltext[de][country=Land]
\setuplabeltext[de][phone=Telefon]
\setuplabeltext[de][mail=e-Mail]
\setuplabeltext[de][notes=Notizen]
\setuplabeltext[en][todo={Zu erledigen}]
\setuplabeltext[de][found={Wenn gefunden\textcomma\ bitte retournieren an:}]

\setuplabeltext[de][nyd=Neujahr]
\setuplabeltext[de][ashw=Aschermittwoch]
\setuplabeltext[de][palms=Palmsonntag]
\setuplabeltext[de][gfri=Karfreitag]
\setuplabeltext[de][esun=Ostern]
\setuplabeltext[de][esmo=Ostermontag]
\setuplabeltext[de][ascd=Himmelfahrt]
\setuplabeltext[de][pcst=Pfingsten]
\setuplabeltext[de][pcstmo=Pfingstmontag]
\setuplabeltext[de][xmas=Weihnachten]
\setuplabeltext[de][bxd=Stephanstag]
\setuplabeltext[de][mon=Mo]
\setuplabeltext[de][tue=Di]
\setuplabeltext[de][wed=Mi]
\setuplabeltext[de][thu=Do]
\setuplabeltext[de][fri=Fr]
\setuplabeltext[de][sat=Sa]
\setuplabeltext[de][sun=So]

\setuplabeltext[de][january=Januar]
\setuplabeltext[de][february=Februar]
\setuplabeltext[de][march=März]
\setuplabeltext[de][april=April]
\setuplabeltext[de][may=Mai]
\setuplabeltext[de][june=Juni]
\setuplabeltext[de][july=Juli]
\setuplabeltext[de][august=August]
\setuplabeltext[de][september=September]
\setuplabeltext[de][october=Oktober]
\setuplabeltext[de][november=November]
\setuplabeltext[de][december=Dezember]

% Dutch interface
\setuplabeltext[nl][weekagenda=Weekagenda]
\setuplabeltext[nl][week=Week]

\setuplabeltext[nl][contact=Kontakt]
\setuplabeltext[nl][name=Naam]
\setuplabeltext[nl][address=Adres]
\setuplabeltext[nl][zip=Postcode]
\setuplabeltext[nl][place=Plaats]
\setuplabeltext[nl][country=Land]
\setuplabeltext[nl][phone=Tel.]
\setuplabeltext[nl][mail=e-mail]
\setuplabeltext[nl][notes=Notities]
\setuplabeltext[en][todo=Todo]
\setuplabeltext[nl][found={Wanneer gevonden\textcomma\ aub sturen naar:}]

\setuplabeltext[nl][nyd={Nieuw jaar}]
\setuplabeltext[nl][ashw=Aswoensdag]
\setuplabeltext[nl][palms=Palmpasen]
\setuplabeltext[nl][gfri=Goede vrijdag]
\setuplabeltext[nl][esun=Pasen]
\setuplabeltext[nl][esmo={2\high{de} Paasdag}]
\setuplabeltext[nl][ascd=Hemelvaart]
\setuplabeltext[nl][pcst=Pinksteren]
\setuplabeltext[nl][pcstmo={2\high{de} Pinksterdag}]
\setuplabeltext[nl][xmas=Kerst]
\setuplabeltext[nl][bxd={2\high{de} Kerstdag}]
\setuplabeltext[nl][mon=Ma]
\setuplabeltext[nl][tue=Di]
\setuplabeltext[nl][wed=Woe]
\setuplabeltext[nl][thu=Do]
\setuplabeltext[nl][fri=Fr]
\setuplabeltext[nl][sat=Za]
\setuplabeltext[nl][sun=Zo]

\setuplabeltext[nl][janary=Januari]
\setuplabeltext[nl][february=Febrari]
\setuplabeltext[nl][march=Maart]
\setuplabeltext[nl][april=April]
\setuplabeltext[nl][may=Mei]
\setuplabeltext[nl][june=Juni]
\setuplabeltext[nl][july=Juli]
\setuplabeltext[nl][august=Augustus]
\setuplabeltext[nl][september=September]
\setuplabeltext[nl][october=October]
\setuplabeltext[nl][november=November]
\setuplabeltext[nl][december=December]

% French interface
\setuplabeltext[fr][weekagenda={Cal. de la semaine}]
\setuplabeltext[fr][week=Sem.]
\setuplabeltext[fr][contact=Contact]
\setuplabeltext[fr][name=Nom]
\setuplabeltext[fr][address=Adresse]
\setuplabeltext[fr][zip=CP]
\setuplabeltext[fr][place=Lieu]
\setuplabeltext[fr][country=Pays]
\setuplabeltext[fr][phone=Tél.]
\setuplabeltext[fr][mail=e-mail]
\setuplabeltext[fr][notes=Observations]
\setuplabeltext[fr][todo=Tâches]
\setuplabeltext[fr][found={Si trouvé\textcomma\ retourner s.v.p. à: }]
           
\setuplabeltext[fr][nyd={Jour de l'an}]
\setuplabeltext[fr][ashw={Mercredi des Cendres}]
\setuplabeltext[fr][palms={Dimanche des Rameaux}]
\setuplabeltext[fr][gfri={Vendredi saint}]
\setuplabeltext[fr][esun={Pâques}]
\setuplabeltext[fr][esmo={Lundi de Pâques}]
\setuplabeltext[fr][ascd={Jour de l'ascension}]
\setuplabeltext[fr][pcst=Pentecôte]
\setuplabeltext[fr][pcstmo={Lundi de Pentecôte}]
\setuplabeltext[fr][xmas=Noël]
\setuplabeltext[fr][bxd=]
\setuplabeltext[fr][mon=Lun]
\setuplabeltext[fr][tue=Mar]
\setuplabeltext[fr][wed=Mer]
\setuplabeltext[fr][thu=Jeu]
\setuplabeltext[fr][fri=Ven]
\setuplabeltext[fr][sat=Sam]
\setuplabeltext[fr][sun=Dim]

\setuplabeltext[fr][january=Janvier]
\setuplabeltext[fr][february=Février]
\setuplabeltext[fr][march=Mars]
\setuplabeltext[fr][april=Avril]
\setuplabeltext[fr][may=Mai]
\setuplabeltext[fr][june=Juin]
\setuplabeltext[fr][july=Juillet]
\setuplabeltext[fr][august=Août]
\setuplabeltext[fr][september=Septembre]
\setuplabeltext[fr][october=Octobre]
\setuplabeltext[fr][november=Novembre]
\setuplabeltext[fr][december=Décembre]

% Italian interface
\setuplabeltext[it][weekagenda=Cal. d. settimana]
\setuplabeltext[it][week=Settimana]
\setuplabeltext[it][contact=Contatto]
\setuplabeltext[it][name=Nome]
\setuplabeltext[it][address=Indirizzo]
\setuplabeltext[it][zip=C.A.P.]
\setuplabeltext[it][place=Luogo]
\setuplabeltext[it][country=Paese]
\setuplabeltext[it][phone=Tel.]
\setuplabeltext[it][mail=e-mail]
\setuplabeltext[it][notes=Osservazioni]
\setuplabeltext[it][todo=Compiti]
\setuplabeltext[it][found={Se trovato\textcomma\ prego speditelo à:}]
                
\setuplabeltext[it][nyd=Capodanno]
\setuplabeltext[it][ashw={Giorno delle Ceneri}]
\setuplabeltext[it][palms={Domenica delle Palme} ]
\setuplabeltext[it][gfri={Venerdi santo}]
\setuplabeltext[it][esun=Pasqua]
\setuplabeltext[it][esmo={Lunedì dell'Angelo}]
\setuplabeltext[it][ascd=Ascensione]
\setuplabeltext[it][pcst=Pentecoste]
\setuplabeltext[it][pcstmo={Lunedì di Pentecoste}]
\setuplabeltext[it][xmas=Natale]
\setuplabeltext[it][bxd={Giorno di S. Stefano}]
\setuplabeltext[it][mon=lun.]
\setuplabeltext[it][tue=mar.]
\setuplabeltext[it][wed=mer.]
\setuplabeltext[it][thu=gio.]
\setuplabeltext[it][fri=ven.]
\setuplabeltext[it][sat=sab.]
\setuplabeltext[it][sun=dom.]

\setuplabeltext[it][january=gennaio]
\setuplabeltext[it][february=febbraio]
\setuplabeltext[it][march=marzo]
\setuplabeltext[it][april=aprile]
\setuplabeltext[it][may=maggio]
\setuplabeltext[it][june=giugno]
\setuplabeltext[it][july=luglio]
\setuplabeltext[it][august=agosto]
\setuplabeltext[it][september=settembre]
\setuplabeltext[it][october=ottobre]
\setuplabeltext[it][november=novembre]
\setuplabeltext[it][december=dicembre]

\writestatus{loading}{ConTeXt User Module / PocketDiary}

%D \subject{PocketDiary layout}
%D
%D This module uses different page templates, whereof one uses a symbol out of the set 2 of 
%D the Martin Vogel collection. So we load these symbols:
%D  
%D \starttyping
%D    \usesymbols[mvs]
%D    \setupsymbolset[martinvogel 2]
%D \stoptyping
%D

\usesymbols[mvs]
\setupsymbolset[martinvogel 2]

%D The document should start with the definition of the main language used, 
%D this is important if you use a different language than English. The placement 
%D of the pagenumber is switched off for the moment.
%D 
%D \starttyping
%D    \mainlanguage[nl]
%D    \setuppagenumbering[location=]
%D \stoptyping
%D
 
\mainlanguage[nl]
\setuppagenumbering[location=]

%D Because we will place 8 pages on an A4 landscape, we define our own pagesize
%D 
%D \starttyping
%D    \definepapersize[Arrangingformat][width=7.42cm, height=10.5cm]
%D    \setuppapersize[Arrangingformat][A4,landscape]
%D \stoptyping
%D
 
\definepapersize[Arrangingformat][width=7.42cm, height=10.5cm]
\setuppapersize[Arrangingformat][A4,landscape]

%D In the templates a light gray color for (grid)lines is used. Separator lines can have 
%D an  individual color too. The color for the (grid)lines must later on be set inside 
%D the setups for the PocketDiary, otherwise the color is not adjusted to the required value! 
%D We enable the use of colors.
%D 
%D \starttyping
%D    \definecolor[Grid][s=.75]
%D    \definecolor[Separatorline][\getvariable{PocketDiaryColors}{Separatorline}]
%D    \setupcolors[state=start]
%D \stoptyping
%D 

\definecolor[Grid][s=.75]
\definecolor[Separatorline][\getvariable{PocketDiaryColors}{Separatorline}]
\setupcolors[state=start]

%D The page of the PocketDiary has a fairly simple layout. We use a header- and a footer-space. 
%D The header has a rule beneath and the footer one on top.
%D 
%D \starttyping
%D \setuplayout
%D    [topspace=.6cm,
%D     backspace=.6cm,
%D     header=2\bodyfontsize,
%D     headerdistance=.5\bodyfontsize,
%D     footer=1.2\bodyfontsize,
%D     footerdistance=.5\bodyfontsize,
%D     margin=0pt,
%D     height=middle,
%D     width=middle]
%D \setupbackgrounds
%D    [header]
%D    [text]
%D    [state=start,
%D     frame=off,
%D     bottomframe=on,
%D     framecolor=\getvariable{PocketDiaryColors}{Separatorline}]
%D \setupbackgrounds
%D    [footer]
%D    [text]
%D    [state=start,
%D     frame=off,
%D     topframe=on,
%D     framecolor=\getvariable{PocketDiaryColors}{Separatorline}]
%D \stoptyping

\setuplayout
	[topspace=.6cm,
	backspace=.6cm,
	header=2\bodyfontsize,
	headerdistance=.5\bodyfontsize,
	footer=1.2\bodyfontsize,
	footerdistance=.5\bodyfontsize,
	margin=0pt,
	height=middle,
	width=middle]

\setupbackgrounds
    [header]
    [text]
    [state=start,
     frame=off,
     bottomframe=on,
     framecolor=\getvariable{PocketDiaryColors}{Separatorline}]

\setupbackgrounds
    [footer]
    [text]
    [state=start,
     frame=off,
     topframe=on,
     framecolor=\getvariable{PocketDiaryColors}{Separatorline}]

%D For the pages with (grid)lines we use a layer which will contain the graphic.
%D
%D \starttyping
%D    \definelayer[textarea][width=\textwidth,height=\textheight,preset=lefttop]
%D \stoptyping

\definelayer[textarea][width=\textwidth,height=\textheight,preset=lefttop]

%D \subject{Implementation}
%D \subsubject{\METAPOST\ drawings}
%D There are three templates which are made up in \METAPOST. The code is made up in such a way, that the
%D drawings are automatically adapted to the size of the typsetting area.
%D
%D \starttyping
%D \startuniqueMPgraphic{Caro}
%D    numeric w; w:= floor(\overlaywidth/4mm);
%D    numeric h; h:= floor(\overlayheight/4mm);
%D    path p,q;
%D    p := unitsquare xscaled (4mm*w) yscaled (4mm*h);
%D    q:= ulcorner p -- llcorner p;
%D       for i = 0 upto w : 
%D         draw q shifted (i*4mm,0) withpen pencircle scaled .5pt withcolor \MPcolor{Grid};
%D       endfor;
%D    q:= llcorner p -- lrcorner p;
%D    for i = 0 upto h :
%D       draw q  shifted (0,i*4mm) withpen pencircle scaled .5pt withcolor \MPcolor{Grid};
%D    endfor;
%D \stopuniqueMPgraphic
%D 
%D \startuniqueMPgraphic{Lines}
%D    numeric w; w:= \overlaywidth;
%D    numeric h; h:= floor(\overlayheight/7mm);
%D    path p,q;
%D    p := unitsquare xscaled \overlaywidth yscaled (7mm*h);
%D    q:= ulcorner p -- urcorner p;
%D    for i = 0 upto h :
%D       if i = 0:
%D         draw q  shifted (0,-i*7mm) withpen pencircle scaled .5pt withcolor white;
%D       else :
%D         draw q  shifted (0,-i*7mm) withpen pencircle scaled .5pt withcolor \MPcolor{Grid};
%D       fi;
%D    endfor; 
%D \stopuniqueMPgraphic
%D 
%D \startuniqueMPgraphic{Todo}
%D    numeric w; w:= \overlaywidth;
%D    numeric h; h:= floor(\overlayheight/7.5mm);
%D    path p,q;
%D    p := unitsquare xscaled \overlaywidth yscaled \overlayheight;
%D    q:= llcorner p -- lrcorner p;
%D    for i = 0 upto h :
%D       draw q shifted (0,i*7mm)  withpen pencircle scaled .5pt withcolor \MPcolor{Grid};
%D       label.top(textext("\tfd \symbol[HollowBox]"), point 0 of q shifted (1mm,i*7mm));
%D    endfor; 
%D \stopuniqueMPgraphic
%D \stoptyping

\startuniqueMPgraphic{Caro}
    numeric w; w:= floor(\overlaywidth/4mm);
    numeric h; h:= floor(\overlayheight/4mm);
	path p,q;
    p := unitsquare xscaled (4mm*w) yscaled (4mm*h);
	q:= ulcorner p -- llcorner p;
    for i = 0 upto w : 
	    draw q shifted (i*4mm,0) withpen pencircle scaled .5pt withcolor \MPcolor{Grid};
	endfor;
	q:= llcorner p -- lrcorner p;
	for i = 0 upto h :
	 	draw q  shifted (0,i*4mm) withpen pencircle scaled .5pt withcolor \MPcolor{Grid};
	endfor;
\stopuniqueMPgraphic

\startuniqueMPgraphic{Lines}
    numeric w; w:= \overlaywidth;
    numeric h; h:= floor(\overlayheight/7mm);

	path p,q;
    p := unitsquare xscaled \overlaywidth yscaled (7mm*h);
	q:= ulcorner p -- urcorner p;
	for i = 0 upto h :
		if i = 0:
			draw q  shifted (0,-i*7mm) withpen pencircle scaled .5pt withcolor white;
		else :
	 		draw q  shifted (0,-i*7mm) withpen pencircle scaled .5pt withcolor \MPcolor{Grid};
		fi;
	endfor; 
\stopuniqueMPgraphic

\startuniqueMPgraphic{Todo}
    numeric w; w:= \overlaywidth;
    numeric h; h:= floor(\overlayheight/7.5mm);
	path p,q;
    p := unitsquare xscaled \overlaywidth yscaled \overlayheight;
	q:= llcorner p -- lrcorner p;
	for i = 0 upto h :
	 	draw q shifted (0,i*7mm)  withpen pencircle scaled .5pt withcolor \MPcolor{Grid};
		label.top(textext("\tfd \symbol[HollowBox]"), point 0 of q shifted (1mm,i*7mm));
	endfor; 
\stopuniqueMPgraphic

%D \subject{The set of macros for the calculations}
%D
%D The LUA functions run in a namespace assigned to this module. All calls to the LUA functions
%D are prepended by \type{thirddata.wegger.calendar}. This prepending string is represented by 
%D \dots in the following list of macros.
%D
%D \starttyping
%D \def\Daytest{\getvariable{PocketDiary}{Day}}
%D 
%D \def\Monthtable#1#2{\ctxlua{...monthtableH(#1,#2)}}
%D \def\Monthname#1#2{\ctxlua{...monthname(#1,#2)}}
%D \def\Yearcalendar#1{\ctxlua{...endar(#1)}}
%D \def\Nxtwknrdetermination#1#2{\ctxlua{...nextweeknumberdetermination(#1,#2)}}
%D 
%D \def\ThisWeektable#1#2{\ctxlua{...thisweek(#1,#2)}}
%D \def\NextWeektable#1#2{\ctxlua{...nextweek(#1,#2)}}
%D 
%D \def\Daynameofweek#1#2#3{\ctxlua{...select_dayname(#1,#2,#3)}} 
%D \def\Fulldateofweek#1#2#3{\ctxlua{...select_fulldate(#1,#2,#3)}}
%D \def\Dayofmonth#1#2#3{\ctxlua{...select_dayofmonth(#1,#2,#3)}}
%D \def\Monthofweek#1#2#3{\ctxlua{...select_month(#1,#2,#3)}}
%D \def\Monthnameofweek#1#2#3{\ctxlua{...select_monthname(#1,#2,#3)}}
%D \def\Fullyearofweek#1#2#3{\ctxlua{...select_fullyear(#1,#2,#3)}}
%D \def\Yearofweek#1#2#3{\ctxlua{...select_year(#1,#2,#3)}}
%D \def\Checkchristianfeast#1#2#3{\ctxlua{...checkchristianfeast(#1,#2,#3)}}
%D \stoptyping
%D

\def\Daytest{\getvariable{PocketDiary}{Day}}

\def\Monthtable#1#2{\ctxlua{thirddata.wegger.calendar.monthtableH(#1,#2)}}
\def\Monthname#1#2{\ctxlua{thirddata.wegger.calendar.monthname(#1,#2)}}
\def\Yearcalendar#1{\ctxlua{thirddata.wegger.calendar.yearcalendar(#1)}}
\def\Nxtwknrdetermination#1#2{\ctxlua{thirddata.wegger.calendar.nextweeknumberdetermination(#1,#2)}}

\def\ThisWeektable#1#2{\ctxlua{thirddata.wegger.calendar.thisweek(#1,#2)}}
\def\NextWeektable#1#2{\ctxlua{thirddata.wegger.calendar.nextweek(#1,#2)}}

\def\Daynameofweek#1#2#3{\ctxlua{thirddata.wegger.calendar.select_dayname(#1,#2,#3)}} 
\def\Fulldateofweek#1#2#3{\ctxlua{thirddata.wegger.calendar.select_fulldate(#1,#2,#3)}}
\def\Dayofmonth#1#2#3{\ctxlua{thirddata.wegger.calendar.select_dayofmonth(#1,#2,#3)}}
\def\Monthofweek#1#2#3{\ctxlua{thirddata.wegger.calendar.select_month(#1,#2,#3)}}
\def\Monthnameofweek#1#2#3{\ctxlua{thirddata.wegger.calendar.select_monthname(#1,#2,#3)}}
\def\Fullyearofweek#1#2#3{\ctxlua{thirddata.wegger.calendar.select_fullyear(#1,#2,#3)}}
\def\Yearofweek#1#2#3{\ctxlua{thirddata.wegger.calendar.select_year(#1,#2,#3)}}
\def\Checkchristianfeast#1#2#3{\ctxlua{thirddata.wegger.calendar.getfeastname(#1,#2,#3)}}

%D \subject{The variable sets}
%D
%D The module uses five sets of variables. The first set contains the information on the
%D calendars to be calculated.
%D First of all it has to be stated, that the whole idea behind this module is to prepare a 
%D personal organizer with as few parameters as possible. After the initial setup of the variables
%D it is sufficient to adapt the values in the first set only.
%D 
%D \subsubject{Variable set \bf PocketDiary}
%D
%D \starttabulate[|l|l|p|]
%D 	\NC Variable \NC Value \NC Comment \NC\NR
%D 	\NC Year     \NC number \NC Year numbers in the range 1900 and 4099. 
%D 		The lower limit is computerdependent (OS-timestamp), the upper limit is 
%D 		dependent on the Easter Sunday calculation 
%D      (http://www.assa.org.au/edm.html, R.W. Mallen, 1985).\NC\NR
%D 	\NC Week     \NC number \NC Values between 1 and 53 \NC\NR
%D 	\NC Day      \NC number \NC Values between 1 and 7. If this variable contains
%D 	a value, then the PocketDiary will be made up aaccording to the variable specifications
%D 	given in the PocketDiaryLayout section. If this variable is empty, then a PocketDiary 
%D 	with one page per day is made up. The content of pages 1 and 8 can be chosen in the section 
%D 	PocketDiaryLayout \NC\NR
%D 	\NC Month    \NC number \NC Values between 1 and 12 \NC\NR
%D 	\NC Nextyear \NC yes/no \NC The testing is done on \quote{yes}. If set to \quote{yes} the next year instead of the current year is used for the calculation of the year calendar. \NC\NR
%D \stoptabulate
%D 
%D \starttyping
%D \setvariables
%D   [PocketDiary]
%D   [Year=2011,
%D   Week=17,
%D   Day=7,              
%D   Month=5,
%D   Nextyear=yes]
%D \stoptyping


\setvariables
	[PocketDiary]
	[Year=2011,
	Week=17,
	Day=7,              
	Month=5,
	Nextyear=yes]

%D \subsubject{Variable set \bf PocketDiaryLayout}
%D
%D The PocketDiary can be given a layout according to your own ideas.
%D There are 8 variables (Page1 upto Page8) which can be given different values.
%D 
%D \starttabulate[|l|p|]
%D 	\NC Variable     \NC Comment \NC\NR
%D 	\NC Day          \NC The weekday indicated in the variable \quote{Day} 
%D 		in the previous section is used to make a PocketDiary page. \NC\NR
%D 	\NC Week         \NC A week calendar based on the variable \quote{Week} in the
%D 		 previous section is used for the presentation of a week table. \NC\NR
%D	\NC Weeknext     \NC A week calendar based on the variable \quote{Week} $+$ 1 in the previous section is used for the presentation of the nexts week's table. \NC\NR
%D 	\NC Monthcurrent \NC A monthtable based on the value in the variable \quote{Month}
%D 		of the previous section is typeset. \NC\NR
%D 	\NC Monthnext    \NC 	A monthtable of the next month based on the value 
%D 		in the variable \quote{Month} of the previous section is typeset. \NC\NR
%D 	\NC Yearcalendar \NC A complete year calendar is typset. If the \quote{Nextyear} 
%D 		variable is not \quote{yes}, the year calendar for the year indicated in
%D 		variable \quote{Year} of the previous section is used. Otherwise that variable 
%D 		is increased by 1 to typeset the year calendar. \NC\NR
%D 	\NC Lost-Return  \NC By means of the values in the variables of the section 
%D 		PocketDiaryAddress a lost and return page is composed. \NC\NR
%D 	\NC Blank        \NC This page carries a header and a footer but is empty for the rest. \NC\NR
%D 	\NC Todo         \NC A todo-list template is typeset. \NC\NR
%D 	\NC Caro         \NC A page with full-grid-paper is tyepset. \NC\NR
%D 	\NC Lines        \NC A page with grid lines is typeset. \NC\NR
%D 	\NC Contact      \NC A form with two sets of preprinted fields for marking down 
%D 		contact information is typset. \NC\NR
%D \stoptabulate
%D 
%D \starttyping
%D \setvariables
%D    [PocketDiaryLayout]
%D    [Page1=Lost-Return,  
%D    Page2=Week,
%D    Page3=Day,
%D    Page4=Monthcurrent,
%D    Page5=Blank,
%D    Page6=Contact,
%D    Page7=Caro,
%D    Page8=Lines]
%D \stoptyping

\setvariables
	[PocketDiaryLayout]
	[Page1=Lost-Return,  
	Page2=Week,
	Page3=Day,
	Page4=Monthcurrent,
	Page5=Blank,
	Page6=Contact,
	Page7=Caro,
	Page8=Lines]

%D \subsubject{Variable set \bf PocketDiaryAddress}
%D
%D The third section of variables contains information used for the footer and the lost-return form.
%D 
%D \starttyping
%D \setvariables
%D    [PocketDiaryAddress]
%D    [Familyname=Egger,
%D    Forename=Willi,
%D    Street=Townstreet 3B,
%D    Zipcode=5000,
%D    City=New CONTEXT,
%D    Country=TEX-world,
%D    Phone=+22 444 55 88 66,
%D    Mobile=+22 6 19 19 1717,
%D    E-mail=info at pocketdiary.org,
%D    Web=www.pocketdiary.org]
%D \stoptyping
	
\setvariables
	[PocketDiaryAddress]
	[Familyname=Egger,
	Forename=Willi,
	Street=Townstreet 3B,
	Zipcode=5000,
	City=New CONTEXT,
	Country=TEX-world,
	Phone=+22 444 55 88 66,
	Mobile=+22 6 19 19 1717,
	E-mail=info at pocketdiary.org,
	Web=www.pocketdiary.org]

%D \subsubject{Variable set \bf PocketDiaryColors}
%D
%D The PocketDiary uses some color. The header and footer separator lines can be given a color. 
%D Standard color is blue. For those who want gridlines other than light gray can set a 
%D color for the gridlines also.
%D 
%D \starttyping
%D \setvariables
%D    [PocketDiaryColors]
%D    [Separatorline=blue,
%D    Gridline={s=.75}]
%D \stoptyping

\setvariables
	[PocketDiaryColors]
	[Separatorline=blue,
	Gridline={s=.75}]

%D \subsubject{Variable set \bf PocketDiaryFooter}
%D
%D The footer is filled with three fields. These fields may contain the contents
%D of variables or \TEX\ commands. The setup of the footer is done with a setup in 
%D order to be able to call it later on.
%D 
%D \starttyping
%D \setvariables
%D    [PocketDiaryFooter]
%D    [Lefttext=PocketDiary,
%D     Centertext=\pagenumber,
%D     Righttext={\getvariable{PocketDiaryAddress}{Forename},~{\currentdate[year]}}]
%D \stoptyping 
%D
%D \subsubject{Footer setup}
%D
%D \starttyping
%D \startsetups Footertext
%D    \setupfootertexts[%
%D       \tfx
%D       \getvariable{PocketDiaryFooter}{Lefttext}
%D       \hfill
%D       \getvariable{PocketDiaryFooter}{Centertext}
%D       \hfill
%D       \getvariable{PocketDiaryFooter}{Righttext}]
%D \stopsetups
%D \stoptyping

\setvariables
	[PocketDiaryFooter]
	[Lefttext=PocketDiary,
	 Centertext=\pagenumber,
	 Righttext={\getvariable{PocketDiaryAddress}{Forename},~{\currentdate[year]}}]

\startsetups Footertext
	\setupfootertexts[%
		\tfx
		\getvariable{PocketDiaryFooter}{Lefttext}
		\hfill
		\getvariable{PocketDiaryFooter}{Centertext}
		\hfill
		\getvariable{PocketDiaryFooter}{Righttext}]
\stopsetups

%D \subject{The various calendar pages}
%D \subsubject{Day}

\startbuffer[Day]
	\setupheadertexts[%
		{\framed[align=flushleft,width=\textwidth,frame=off]
			{{\bfb\Dayofmonth{\getvariable{PocketDiary}{Week}}
							 {\getvariable{PocketDiary}{Year}}
						 	 {\getvariable{PocketDiary}{Day}}}
			~
			{\bfa\Daynameofweek{\getvariable{PocketDiary}{Week}}
						       {\getvariable{PocketDiary}{Year}}
						   	   {\getvariable{PocketDiary}{Day}}}
			~
			{\tfxx \Checkchristianfeast
				{\Dayofmonth{\getvariable{PocketDiary}{Week}}
					 		{\getvariable{PocketDiary}{Year}}
					  		{\getvariable{PocketDiary}{Day}}}
				{\Monthofweek{\getvariable{PocketDiary}{Week}}
						     {\getvariable{PocketDiary}{Year}}
					  	     {\getvariable{PocketDiary}{Day}}}
							 {\getvariable{PocketDiary}{Year}}}
			\hfill
			{\Monthnameofweek{\getvariable{PocketDiary}{Week}}
							 {\getvariable{PocketDiary}{Year}}
							 {\getvariable{PocketDiary}{Day}}}
			~
			\Fullyearofweek
							{\getvariable{PocketDiary}{Week}}
						  	{\getvariable{PocketDiary}{Year}}
	  					  	{\getvariable{PocketDiary}{Day}}}}]
	\setups{Footertext}
	\strut\page
\stopbuffer

%D The day calendar looks as in \in{figure}[fig:Day].
%D 
%D \placefigure
%D 	[middle,none]
%D 	[fig:Day]
%D 	{Example Day-calendar}
%D  {\externalfigure[documentation-figures][page=1,width=.4\textwidth]}

\startbuffer[Weekend]
	\setupheadertexts[%
		{\framed[align=flushleft,width=\textwidth,frame=off]
			{{\bfb\Dayofmonth
				{\getvariable{PocketDiary}{Week}}
				{\getvariable{PocketDiary}{Year}}
				{6}}
			~
			{\bfa\Daynameofweek
				{\getvariable{PocketDiary}{Week}}
				{\getvariable{PocketDiary}{Year}}
				{6}}
			~{\tfxx \Checkchristianfeast
				{\Dayofmonth
					{\getvariable{PocketDiary}{Week}}
					{\getvariable{PocketDiary}{Year}}
					{6}}
				{\Monthofweek
					{\getvariable{PocketDiary}{Week}}
					{\getvariable{PocketDiary}{Year}}
					{6}}
					{\getvariable{PocketDiary}{Year}}}
			\hfill
			{\Monthnameofweek
				{\getvariable{PocketDiary}{Week}}
				{\getvariable{PocketDiary}{Year}}
			    {6}}
			~
			\Fullyearofweek
				{\getvariable{PocketDiary}{Week}}
			    {\getvariable{PocketDiary}{Year}}
			    {6}}}]
	\strut\godown[.45\textheight]
	\framed
		[align=flushleft,
		width=\textwidth,
		frame=off,
		bottomframe=on,
		framecolor=\getvariable{PocketDiaryColors}{Separatorline}]
		{\color[red]
			{{\bfb
				\Dayofmonth
		  			{\getvariable{PocketDiary}{Week}}
		  			{\getvariable{PocketDiary}{Year}}
		  			{7}}
			~
			{\bfa\Daynameofweek
				{\getvariable{PocketDiary}{Week}}
	  			{\getvariable{PocketDiary}{Year}}
				{7}}}
		~
		{\tfxx\Checkchristianfeast
			{\Dayofmonth
				{\getvariable{PocketDiary}{Week}}
				{\getvariable{PocketDiary}{Year}}
				{7}}
			{\Monthofweek
				{\getvariable{PocketDiary}{Week}}
				{\getvariable{PocketDiary}{Year}}
				{7}}
				{\getvariable{PocketDiary}{Year}}}
		\hfill
		{\Monthnameofweek
		   {\getvariable{PocketDiary}{Week}}
		   {\getvariable{PocketDiary}{Year}}
		   {7}}
		 ~
		\Fullyearofweek
			{\getvariable{PocketDiary}{Week}}
		    {\getvariable{PocketDiary}{Year}}
		    {7}}
	\page
\stopbuffer

%D \subsubject{Weekend}
%D The weekend calendar shows saturday and sunday on one page (see \in{figure}[fig:Weekend]).
%D 
%D \placefigure
%D 	[middle,here]
%D 	[fig:Weekend]
%D 	{Example Weekend-calendar}
%D  {\externalfigure[documentation-figures][page=2,width=.4\textwidth]}

\startbuffer[Week]
	\setupheadertexts[%
		{{\bfb \labeltext{weekagenda}}
		\hfill
		{\labeltext{week}
		~
		\getvariable{PocketDiary}{Week}}
		\quad
		\Fullyearofweek
			{\getvariable{PocketDiary}{Week}}
		    {\getvariable{PocketDiary}{Year}}
		    {\getvariable{PocketDiary}{Day}}}]
	\ThisWeektable{\getvariable{PocketDiary}{Week}}{\getvariable{PocketDiary}{Year}}
	\page
\stopbuffer

%D \subsubject{Week}
%D The week calendar is a one-column table for working days. 
%D Saturday and sunday are placed next to each other in the last table row. An example is given
%D in \in{figure}[fig:Week].
%D 
%D \placefigure
%D 	[middle,here]
%D 	[fig:Week]
%D 	{Example Week-calendar}
%D  {\externalfigure[documentation-figures][page=3,width=.4\textwidth]}

\startbuffer[Weeknext]
	\setupheadertexts[%
		{{\bfb \labeltext{weekagenda}}
		\hfill
		{\labeltext{week}
		\Nxtwknrdetermination{\getvariable{PocketDiary}{Week}}{\getvariable{PocketDiary}{Year}}}}]
	\NextWeektable{\getvariable{PocketDiary}{Week}}{\getvariable{PocketDiary}{Year}}
	\page
\stopbuffer

\startsetups table:week
	\setupTABLE[r][each][height=.165\textheight,align=flushleft]
	\setupTABLE[r][even][background=color,backgroundcolor=.5s]
	\setupTABLE[c][1][width=.5\textwidth]
	\setupTABLE[c][2][width=.5\textwidth]
\stopsetups

\startsetups table:month
	\setupTABLE[column][each][width=.143\textwidth,align=flushright,offset=3pt]
	\setupTABLE[column][7][style=\red]
\stopsetups

\startsetups table:year
	\setupTABLE[column][each][width=.032\textwidth,align=flushright,offset=1pt,frame=off]
	\setupTABLE[column][1][width=.052\textwidth,align=flushleft]
	\setupTABLE[row][each][offset=1pt,height=1.5\bodyfontsize]
\stopsetups

\startsetups table:contacts
	\setupTABLE[r][each][frame=off,bottomframe=on,height=2\lineheight]
	\setupTABLE[c][1][width=.3\textwidth]
	\setupTABLE[c][2][width=.5\textwidth]
	\setupTABLE[c][3][width=.2\textwidth]
\stopsetups 

\startsetups table:returnto
	\setupTABLE[r][each][frame=off]
	\setupTABLE[c][each][width=\textwidth]
\stopsetups


\startbuffer[Monthcurrent]
	\setupheadertexts[%
		\bfa
		{\Monthname{\getvariable{PocketDiary}{Month}}{\getvariable{PocketDiary}{Year}}
		\hfill
		{\getvariable{PocketDiary}{Year}}}]
	\Monthtable{\getvariable{PocketDiary}{Month}}{\getvariable{PocketDiary}{Year}}
	\page
\stopbuffer

%D \subsubject{Month}
%D The month calendar looks as in \in{figure}[fig:Month].
%D 
%D \placefigure
%D 	[middle,here]
%D 	[fig:Month]
%D 	{Example Month-calendar}
%D  {\externalfigure[documentation-figures][page=4,width=.4\textwidth]}

\startbuffer[Monthnext]
	\setupheadertexts[
		\bfa
		\Monthname{\getvariable{PocketDiary}{Month}+1}{\getvariable{PocketDiary}{Year}}
	   \hfill 
	   \doifelse{\getvariable{PocketDiary}{Month}}{12}
			{\directlua{tex.print{\getvariable{PocketDiary}{Year}+1}}}
			{\directlua{tex.print{\getvariable{PocketDiary}{Year}}}}]
	\Monthtable{\getvariable{PocketDiary}{Month}+1}{\getvariable{PocketDiary}{Year}}
	\page
\stopbuffer

% \setupbodyfontenvironment[default][tiny=.45]

\startbuffer[Yearcalendar]
	\setupheadertexts[%
		{\bfa\doifelse
			{\getvariable{PocketDiary}{Nextyear}}{yes}
			{\directlua{tex.print{\getvariable{PocketDiary}{Year}+1}}}
			{\getvariable{PocketDiary}{Year}}}]
	\setupcombinations[distance=1mm]
	\start\switchtobodyfont[4pt]
	\doifelse
		{\getvariable{PocketDiary}{Nextyear}}{yes}
			{\Yearcalendar{\getvariable{PocketDiary}{Year}+1}}
			{\Yearcalendar{\getvariable{PocketDiary}{Year}}}
	\stop
	\page
\stopbuffer

%D \subsubject{Year}
%D The year calendar looks as in \in{figure}[fig:Year].
%D 
%D \placefigure
%D 	[middle]
%D 	[fig:Year]
%D 	{Example Year-calendar}
%D  {\externalfigure[documentation-figures][page=5,width=.4\textwidth]}

\startbuffer[Contact]
	\setupheadertexts[{\bfb \labeltext{contact}\hfill}] 
	\switchtobodyfont[6pt]
	\dorecurse{2}{\bTABLE[setups=table:contacts]
		\bTR
			\bTD \labeltext{name}: \eTD
			\bTD \eTD
			\bTD \eTD
		\eTR
		\bTR
			\bTD \labeltext{address}:\eTD
			\bTD \eTD
			\bTD \eTD
		\eTR
		\bTR
			\bTD \strut\eTD
			\bTD \eTD
			\bTD \eTD
		\eTR
		\bTR
			\bTD \labeltext{zip}:\eTD
			\bTD \labeltext{place}:\eTD
			\bTD \labeltext{country}:\eTD
		\eTR
		\bTR
			\bTD \labeltext{phone}:\eTD
			\bTD \eTD
			\bTD \eTD
		\eTR
		\bTR
			\bTD \labeltext{mail}:\eTD
			\bTD \eTD
			\bTD \eTD
		\eTR
	\eTABLE
	\blank}
	\page
\stopbuffer

\startbuffer[Caro]
	\setupheadertexts[{\bfb \labeltext{notes}\hfill}]
	\setlayer
		[textarea]
		[x=1mm,y=1mm]
		{\useMPgraphic{Caro}}
	\flushlayer[textarea]
	\page
\stopbuffer

\startbuffer[Lines]
   	\setupheadertexts[{\bfb \labeltext{notes}\hfill}]
	\setlayer
		[textarea]
		[x=0cm,y=0cm]
		{\useMPgraphic{Lines}}
	\flushlayer[textarea]
	\page
\stopbuffer

\startbuffer[Todo]
	\setupheadertexts[\bfb \labeltext{todo}\hfill]
	\setlayer
		[textarea]
		[x=0cm,y=2mm]
		{\useMPgraphic{Todo}}
	\flushlayer[textarea]
	\page	
\stopbuffer

\startbuffer[Blank]
	\setupheadertexts[{\bfb \labeltext{notes}\hfill}]
	\strut\page
\stopbuffer

\startbuffer[Lost-Returnto]
\start
 	\setupheadertexts[\bfa PocketDiary]
	\setupfootertexts[]
	\strut\blank[2*line]
		\framed[width=\textwidth,
				frame=off,
				bottomframe=on,
				align=flushleft,
				rulethickness=2pt,
				foregroundcolor=\getvariable{PocketDiaryColors}{Separatorline},
				framecolor=\getvariable{PocketDiaryColors}{Separatorline}]
				{\labeltext{found}}
	\bTABLE[setups=table:returnto]
		\bTR
			\bTD \getvariable{PocketDiaryAddress}{Forename}~\getvariable{PocketDiaryAddress}{Familyname} \eTD
		\eTR
		\bTR
			\bTD \getvariable{PocketDiaryAddress}{Street} \eTD
		\eTR
		\bTR
			\bTD \getvariable{PocketDiaryAddress}{Zipcode}
			 	{\addff{smcp}\getvariable{PocketDiaryAddress}{City}}\eTD
		\eTR
		\bTR
			\bTD Tel: \getvariable{PocketDiaryAddress}{Phone}\eTD
		\eTR    
		\bTR    
			\bTD Mob: \getvariable{PocketDiaryAddress}{Mobile}\eTD
		\eTR    
		\bTR    
			\bTD E-mail: \getvariable{PocketDiaryAddress}{E-mail} \eTD
		\eTR    
		\bTR    
			\bTD Web: \getvariable{PocketDiaryAddress}{Web} \eTD
		\eTR
	\eTABLE
\stop
	\page
\stopbuffer

%D \subsubject{Templates}
%D The PocketDiary comes with a couple of templates for writing down information:
%D 
%D \placefigure
%D    [middle,here]
%D    []
%D    {The set of available templates}
%D    {\startcombination[3*2]
%D    {\externalfigure[documentation-figures][page=6,width=.25\textwidth]}{The blank page}
%D    {\externalfigure[documentation-figures][page=7,width=.25\textwidth]}{Caro paper}
%D    {\externalfigure[documentation-figures][page=8,width=.25\textwidth]}{Lines}
%D    {\externalfigure[documentation-figures][page=9,width=.25\textwidth]}{Todo}
%D    {\externalfigure[documentation-figures][page=10,width=.25\textwidth]}{Contact information}
%D    {}{}
%D    \stopcombination}
%D
%D \subject{The setup of the PocketDiary}
%D
%D \starttyping
%D \startsetups PocketDiary
%D \definecolor[Grid][\getvariable{PocketDiaryColors}{Gridline}]
%D \strut
%D \setups{Footertext}
%D \doifelse\Daytest\empty
%D   {\setvariables[PocketDiary][Day=1]
%D   \getbuffer[\getvariable{PocketDiaryLayout}{Page1}]
%D   \dorecurse
%D      {5}
%D      {\setupheadertexts
%D            [{\framed[align=flushleft,
%D            width=\textwidth,
%D            frame=off]
%D            {{\bfb\Dayofmonth%
%D            	{\getvariable{PocketDiary}{Week}}
%D                {\getvariable{PocketDiary}{Year}}
%D                {\recurselevel}
%D             }
%D            ~{\bfa\Daynameofweek
%D            	{\getvariable{PocketDiary}{Week}}
%D                {\getvariable{PocketDiary}{Year}}
%D                {\recurselevel}}
%D            ~{\tfxx \Checkchristianfeast
%D            	{\Dayofmonth
%D            	   {\getvariable{PocketDiary}{Week}}
%D            	   {\getvariable{PocketDiary}{Year}}
%D            	   {\recurselevel}}
%D            	{\Monthofweek
%D            	   {\getvariable{PocketDiary}{Week}}
%D            	   {\getvariable{PocketDiary}{Year}}
%D            	   {\getvariable{PocketDiary}{Day}}}
%D                {\getvariable{PocketDiary}{Year}}}  
%D            \hfill
%D            {\Monthnameofweek
%D               {\getvariable{PocketDiary}{Week}}
%D               {\getvariable{PocketDiary}{Year}}
%D               {1}}
%D             ~\Fullyearofweek
%D            	{\getvariable{PocketDiary}{Week}}
%D                {\getvariable{PocketDiary}{Year}}
%D                {\recurselevel}
%D            }}]
%D         \strut\page
%D      }
%D   \getbuffer[Weekend]
%D      \getbuffer[\getvariable{PocketDiaryLayout}{Page8}]
%D   }
%D      {\getbuffer[\getvariable{PocketDiaryLayout}{Page1}]
%D   \getbuffer[\getvariable{PocketDiaryLayout}{Page2}]	
%D   \getbuffer[\getvariable{PocketDiaryLayout}{Page3}]
%D   \getbuffer[\getvariable{PocketDiaryLayout}{Page4}]
%D   \getbuffer[\getvariable{PocketDiaryLayout}{Page5}]
%D   \getbuffer[\getvariable{PocketDiaryLayout}{Page6}]
%D   \getbuffer[\getvariable{PocketDiaryLayout}{Page7}]
%D   \getbuffer[\getvariable{PocketDiaryLayout}{Page8}]} 
%D \stopsetups
%D \stoptyping

\startsetups PocketDiary
\definecolor[Grid][\getvariable{PocketDiaryColors}{Gridline}]
\strut
\setups{Footertext}
\doifelse\Daytest\empty
	{\setvariables[PocketDiary][Day=1]
	\getbuffer[\getvariable{PocketDiaryLayout}{Page1}]
	\dorecurse
		{5}
		{\setupheadertexts[{\framed[align=flushleft,
							width=\textwidth,
							frame=off]
							{{\bfb\Dayofmonth%
								{\getvariable{PocketDiary}{Week}}
							    {\getvariable{PocketDiary}{Year}}
							    {\recurselevel}
							 }
							~{\bfa\Daynameofweek
								{\getvariable{PocketDiary}{Week}}
							    {\getvariable{PocketDiary}{Year}}
							    {\recurselevel}}
							~{\tfxx \Checkchristianfeast
								{\Dayofmonth
								   {\getvariable{PocketDiary}{Week}}
								   {\getvariable{PocketDiary}{Year}}
								   {\recurselevel}}
								{\Monthofweek
								   {\getvariable{PocketDiary}{Week}}
								   {\getvariable{PocketDiary}{Year}}
								   {\getvariable{PocketDiary}{Day}}}
							    {\getvariable{PocketDiary}{Year}}}  
							\hfill
							{\Monthnameofweek
							   {\getvariable{PocketDiary}{Week}}
							   {\getvariable{PocketDiary}{Year}}
							   {\recurselevel}}
							 ~\Fullyearofweek
								{\getvariable{PocketDiary}{Week}}
							    {\getvariable{PocketDiary}{Year}}
							    {\recurselevel}
							}}]
			\strut\page
		}
	\getbuffer[Weekend]
    \getbuffer[\getvariable{PocketDiaryLayout}{Page8}]
	}
    {\getbuffer[\getvariable{PocketDiaryLayout}{Page1}]
	\getbuffer[\getvariable{PocketDiaryLayout}{Page2}]	
	\getbuffer[\getvariable{PocketDiaryLayout}{Page3}]
	\getbuffer[\getvariable{PocketDiaryLayout}{Page4}]
	\getbuffer[\getvariable{PocketDiaryLayout}{Page5}]
	\getbuffer[\getvariable{PocketDiaryLayout}{Page6}]
	\getbuffer[\getvariable{PocketDiaryLayout}{Page7}]
	\getbuffer[\getvariable{PocketDiaryLayout}{Page8}]} 
\stopsetups

%D \subject{Arranging the pages}
%D
%D For the arrangement of the 8 pages on the paper we need a
%D special arranging scheme, which is included in the distribution. 
%D Invoking the scheme is performed with
%D \starttyping
%D    \setuparranging[1*8]
%D \stoptyping

\setuparranging[1*8]


%D \subject{How to fold the PocketDiary}
%D 
%D The eight printed pages are folded in such a way, that the PocketDiary presents itself as a small booklet. 
%D There are no empty pages visible.
%D 
%D \placefigure
%D 	[middle]
%D 	[fig:schemeA]
%D 	{The basic folding scheme}
%D 	{\externalfigure[documentation-figures][page=12,width=.6\textwidth]}
%D 	
%D First make two mountain-folds as indicated with the straight lines in \in{figure}[fig:schemeA].
%D Unfold the paper and turn it face up and 90\Degrees to the left. Make a valley-fold with the lower part 
%D of the scheet on the previously made mountain-fold. Unfold and turn the sheet 180\Degrees. 
%D Make another valley-fold as described before. Unfold the sheet.
%D 
%D Take a sharp knife and a ruler. Slit the paper open between Cuttingpoint A and B (see \in{figure}[fig:schemeA]).
%D 
%D Now we kan fold the booklet. First fold the paper again in the length. Then hold the double folded paper 
%D with the mountain-fold up. Push from both sides towards the center in order to get a form similar 
%D to \in{figure}[fig:schemeB]. Fold then the upper double-page in direction B, the lower double-page 
%D in direction C and finally the lefthand double-sided page in direction D.
%D 
%D \placefigure
%D 	[middle]
%D 	[fig:schemeB]
%D 	{The basic folding scheme}
%D 	{\externalfigure[documentation-figures][page=13,width=.6\textwidth]}
%D 
%D Before creasing the booklet at the spine it is worthwhile to put the section on table and adjust 
%D folds where needed. Finally the spine is creased with preference with a bone-folder. 
%D 

\stopmodule