mixin weekcontrol(basedate, interval, last_week, next_week)
	#control
		table(width="100%")
			tr
				td(colspan=2, width="20%")
					a.litpanel_arrow(href="javascript: week_goto('#{last_week}');")
						span.glyphicon.glyphicon-step-backward
				td(colspan=2, style="text-align: center; width: 60%;")
					a(href="#", style="color: black;" data-toggle="modal", data-target="#daypickerDialog", data-date="#{basedate}")
						span.litpanel_day_mobile #{interval}
				td(colspan=2, style="text-align: right; width: 20%;")
					a.litpanel_arrow(href="javascript: week_goto('#{next_week}');")
						span.glyphicon.glyphicon-step-forward
		block

mixin week_complete_mobile(days)
	- var celebration_printed = false;
	table(width="100%")
		each day in days
			+week_day_mobile(day)

mixin week_day_mobile(day)
	- day.litinfo.celebration = day.litinfo.celebration.replace("\n", "<br/>");
	- day.litinfo.celebration_add = day.litinfo.celebration_add.replace("\n", "<br/>");
	- day.litinfo.infos = day.litinfo.infos.replace("\n","<br/>");
	- var red_class = day.litinfo.decoration_hint_red ? "litpanel_red" : "";
	- var celebration_class = "";
	- if(day.litinfo.decoration_hint == 2) celebration_class = "week_celebration_stage2";
	- if(day.litinfo.decoration_hint == 1) celebration_class = "week_celebration_stage1";
	- var the_date = day.date.weekday_short + ", " + day.date.day + ". " + day.date.month_short + " " + day.date.year;
	if( ! celebration_printed)
		tr.new_day_begins
			td.td_new_celebration(colspan=2, style="padding-right: 15px;")
				span(class=["week_celebration", celebration_class, red_class], style="white-space: nowrap;") !{the_date}
			td.td_new_celebration.td_last_column
				span(class=["week_celebration", celebration_class, red_class]) !{day.litinfo.celebration}
				if day.litinfo.celebration_add != ""
					p.litpanel_celebration_add !{day.litinfo.celebration_add}
				if day.litinfo.infos != ""
					p.litpanel_infos !{day.litinfo.infos}
	else
		tr.new_day_begins
			td(colspan=2, valign='top')
				span(class=["week_celebration", celebration_class, red_class], style="white-space: nowrap;") !{the_date}
			td
	each away in day.parishcal.away
		+week_away(away)
	each todo in day.parishcal.todo
		+week_todo(todo)
	each keep_in_mind in day.parishcal.keep_in_mind
		+week_keep_in_mind(keep_in_mind)
	each vu in day.parishcal.vehicle_use
		+week_vehicle_use(vu)
	each event in day.parishcal.events.today
		+week_event(event)
	if (day.parishcal.away.length + day.parishcal.todo.length + day.parishcal.keep_in_mind.length + day.parishcal.vehicle_use.length + day.parishcal.events.today.length + day.parishcal.events.tomorrow.length) === 0
		tr.tr_new_pcalentry
			td(style="width: 10%;")
			td(style="width: 5%;")
			td(valign='top').td_last_column
				i Keine Eintragungen an diesem Tag
	if(day.parishcal.tomorrow)
		tr
			td &nbsp;
			td &nbsp;
			td &nbsp;
		- celebration_printed = true;
		- day.parishcal.tomorrow.celebration = day.parishcal.tomorrow.celebration.replace("\n", "<br/>");
		- day.parishcal.tomorrow.celebration_add = day.parishcal.tomorrow.celebration_add.replace("\n", "<br/>");
		- day.parishcal.tomorrow.infos = day.parishcal.tomorrow.infos.replace("\n","<br/>");
		- var red_class_tomorrow = day.parishcal.tomorrow.decoration_hint_red ? "litpanel_red" : "";
		- var celebration_class_tomorrow = "";
		- if(day.parishcal.tomorrow.decoration_hint == 2) celebration_class_tomorrow = "week_celebration_stage2";
		- if(day.parishcal.tomorrow.decoration_hint == 1) celebration_class_tomorrow = "week_celebration_stage1";
		tr.new_day_begins
			td
			td
			td.td_new_celebration.td_last_column
				span(class=["week_celebration", celebration_class_tomorrow, red_class_tomorrow]) !{day.parishcal.tomorrow.celebration}
				if day.parishcal.tomorrow.celebration_add != ""
					p.litpanel_celebration_add !{day.parishcal.tomorrow.celebration_add}
				if day.parishcal.tomorrow.infos != ""
					p.litpanel_infos !{day.parishcal.tomorrow.infos}
		tr
			td(valign='top', colspan=2, style="border-bottom:1px solid #000000; padding-right: 15px; padding-top: 2px;")
				span(class=["week_celebration", celebration_class, red_class], style="font-size: 80%") !{the_date}
			td
		each event in day.parishcal.events.tomorrow
			+week_event(event)
	else
		- celebration_printed = false;
		tr
			td &nbsp;
			td &nbsp;
			td &nbsp;

mixin week_complete_desktop(days)
	- var celebration_printed = false;
	table(width="100%")
		each day in days
			- var red_class = day.litinfo.decoration_hint_red ? "litpanel_red" : "";
			- var celebration_class = "";
			- if(day.litinfo.decoration_hint == 2) celebration_class = "week_celebration_stage2";
			- if(day.litinfo.decoration_hint == 1) celebration_class = "week_celebration_stage1";
			- var the_date = day.date.weekday_short + ",&nbsp;" + day.date.day + ".&nbsp;" + day.date.month_short + "&nbsp;" + day.date.year;
			if( ! celebration_printed)
				tr
					td(valign='top', width="10%")
						span(class=["week_celebration", celebration_class, red_class]) !{the_date}
					td(width="8%")
					td
					td 
						span(class=["week_celebration", celebration_class, red_class]) #{day.litinfo.celebration}
						if day.litinfo.celebration_add != ""
							br
							span(class="litpanel_celebration_add") !{day.litinfo.celebration_add}
						if day.litinfo.infos != ""
							br
							span(class="litpanel_infos") !{day.litinfo.infos}
				- the_date = "";
			else if(celebration_printed && day.parishcal.events.today.length === 0)
				tr
					td(valign='top', width="10%")
						span(class=["week_celebration", celebration_class, red_class]) !{the_date}
					td
					td
					td
			each away in day.parishcal.away
				+week_away(away, the_date)
				- the_date = '';
			each todo in day.parishcal.todo
				+week_todo(todo, the_date)
				- the_date = '';
			each keep_in_mind in day.parishcal.keep_in_mind
				+week_keep_in_mind(keep_in_mind, the_date)
				- the_date = '';
			each vu in day.parishcal.vehicle_use
				+week_vehicle_use(vu, the_date)
				- the_date = '';
			each event in day.parishcal.events.today
				+week_event(event, the_date)
				- the_date = '';
			if(day.parishcal.tomorrow)
				tr
					td &nbsp;
					td &nbsp;
					td &nbsp;
					td &nbsp;
				- celebration_printed = true;
				- var red_class_tomorrow = day.parishcal.tomorrow.decoration_hint_red ? "litpanel_red" : "";
				- var celebration_class_tomorrow = "";
				- if(day.parishcal.tomorrow.decoration_hint == 2) celebration_class_tomorrow = "week_celebration_stage2";
				- if(day.parishcal.tomorrow.decoration_hint == 1) celebration_class_tomorrow = "week_celebration_stage1";
				tr
					td
					td
					td
					td 
						span(class=["week_celebration", celebration_class_tomorrow, red_class_tomorrow]) #{day.parishcal.tomorrow.celebration}
						if day.parishcal.tomorrow.celebration_add != ""
							br
							span(class="litpanel_celebration_add") !{day.parishcal.tomorrow.celebration_add}
						if day.parishcal.tomorrow.infos != ""
							br
							span(class="litpanel_infos") !{day.parishcal.tomorrow.infos}
				- var the_date = day.date.weekday_short + ",&nbsp;" + day.date.day + ".&nbsp;" + day.date.month_short + "&nbsp;" + day.date.year;
				each event in day.parishcal.events.tomorrow
					+week_event(event, the_date)
					- the_date = "";
			else
				- celebration_printed = false;
				tr
					td
					td
					td
					td

mixin week_event(event, the_date)
	- my_class = event.thereafter.length === 0 ? "tr_new_pcalentry" : "tr_new_pcalentry_without_bottomline"
	tr(class=my_class)
		if(typeof the_date != 'undefined')
			td(valign='top', width="10%") 
				span.week_celebration !{the_date}
		td.td_time.week_time_start #{event.pretty.start}
		td.td_locsign(style="background-color: " + event.pretty.punit_color + ";") 
			span.week_time_start #{event.pretty.sign}
			br
			div(style="width: 100%; line-height: 60%; background: " + event.pretty.involved_backgroundstripes + ";") &nbsp;
		td.td_last_column
			span.week_event_name #{event.name}
			span(style='font-size:  9pt;') #{event.pretty.name_secondary}
			if event.pretty.end.length > 0
				- var ca = (event.pretty.end_is_vague ? 'ca. ' : '')
				p.week_time_end bis #{ca}#{event.pretty.end}&nbsp;
			p.week_event_locations !{event.pretty.locations}
			p.week_event_involved  !{event.pretty.involved}
	-var cnt=0
	for tev in event.thereafter
		- cnt++
		- my_class_tev = cnt === event.thereafter.length ? "tr_thereafter_with_bottomline" : "";
		tr(class=my_class_tev)
			td.td_time.week_time_start Danach
			td.td_locsign(style="background-color: " + event.pretty.punit_color + ";")
				span.week_time_start #{tev.pretty.sign}
				br
				div(style="width: 100%; line-height: 60%; background: " + tev.pretty.involved_backgroundstripes + ";") &nbsp;
			td.td_last_column
				span.week_event_name #{tev.name}
				span(style='font-size:  9pt;') #{tev.pretty.name_secondary}
				if event.pretty.end.length > 0
					- var ca = (tev.pretty.end_is_vague ? 'ca. ' : '')
					p.week_time_end bis #{ca}#{tev.pretty.end}&nbsp;
				p.week_event_locations !{tev.pretty.locations}
				p.week_event_involved  !{tev.pretty.involved}
			
mixin week_away(away, the_date)
	tr.tr_new_pcalentry
		if(typeof the_date != 'undefined')
			td(valign='top', width="10%") 
				span.week_celebration !{the_date}&nbsp;
		td.td_time.week_pentrytitle(style="color: #FF5050;") Abwesend
		td.td_locsign
		td.td_last_column.week_event_name(style="color: #FF5050;") #{away.name}
			if away.reason.length > 0
				p.week_additional_info(style="color: #FF5050;") #{away.reason}
			
mixin week_todo(todo, the_date)
	tr.tr_new_pcalentry
		if(typeof the_date != 'undefined')
			td(valign='top', width="10%") 
				span.week_celebration !{the_date}&nbsp;
		td.td_time.week_pentrytitle(style="color: #5893FF;") Zu tun
		td.td_locsign
		td.td_last_column.week_event_name(style="color: #5893FF;") #{todo.name}
			if todo.pretty.involved.length > 0
				p.week_event_involved !{todo.pretty.involved}
			if todo.description.length > 0
				p.week_additional_info #{todo.description}
			
mixin week_keep_in_mind(kim, the_date)
	tr.tr_new_pcalentry
		if(typeof the_date != 'undefined')
			td(valign='top', width="10%") 
				span.week_celebration !{the_date}
		td.td_time.week_pentrytitle(style="color: #15D715;") Zu beachten
		td.td_locsign
		td.td_last_column.week_event_name(style="color: #15D715;") #{kim.name}
			if kim.description.length > 0
				p.week_additional_info(style="color: #15D715;") #{kim.description}
		
mixin week_vehicle_use(vu, the_date)
	tr.tr_new_pcalentry
		if(typeof the_date != 'undefined')
			td(valign='top', width="10%") 
				span.week_celebration !{the_date}
		td.td_time.week_pentrytitle(style="color: #FF8A3C;") Fahrzeug&shy;benutzung
		td.td_locsign
		td.td_last_column.week_event_name(style="color: #FF8A3C;") #{vu.pretty.vehicle}
			p.week_subheadline #{vu.name}
			if vu.pretty.involved.length > 0
				p.week_event_involved !{vu.pretty.involved}
			if vu.description.length > 0
				p.week_additional_info #{vu.description}
