exports.do_day_renderparams_from_result = function(result, session) {
	var d = new Date(result.date.date);
	d.setHours(10); // neccessary, so that in March the next day after the last sunday is really the next day and not today (Sommerzeit-Umstellung!?)
	d.setDate(d.getDate()+1);
	var tomorrow = d.toISOString().slice(0,10);
	d.setDate(d.getDate()-2);
	var yesterday = d.toISOString().slice(0,10);
	d.setDate(d.getDate()+8);
	var next_week = d.toISOString().slice(0,10);
	d.setDate(d.getDate()-14);
	var last_week = d.toISOString().slice(0,10);

	console.log(result.date.date);
	console.log(tomorrow);
	console.log(next_week);

	var messages = [];

	if(result.result === "OK_invalid_date") {
		messages.push({	type: "danger",
						title: "Eingabefehler:",
						message: "Das angegeben Datum konnte nicht interpretiert werden! Es wird auf 'heute' ausgewichen!"
					});
	}

	messages = messages.concat(session.messages);
	session.messages = [];

	return  { 	date : result.date,
				last_week : last_week,
				yesterday : yesterday,
				tomorrow  : tomorrow,
				next_week : next_week,
				litinfo : result.litinfo,
				parishcal: result.parishcal,
				messages: messages,
				sessionuuid : session.sessionuuid
			};
}

exports.do_week_renderparams_from_result = function(result, session) {
	var d = new Date(result.basedate);
	d.setDate(d.getDate()+7);
	var next_week = d.toISOString().slice(0,10);
	d.setDate(d.getDate()-14);
	var last_week = d.toISOString().slice(0,10);

	var messages = [];

	if(result.result === "OK_invalid_date") {
		messages.push({	type: "danger",
						title: "Eingabefehler:",
						message: "Das angegeben Datum konnte nicht interpretiert werden! Es wird auf die aktuelle Woche ausgewichen!"
					});
	}

	messages = messages.concat(session.messages);
	session.messages = [];

	return { 	interval  : result.interval,
				basedate  : result.basedate,
				days      : result.days,
				last_week : last_week,
				next_week : next_week,
				messages: messages
		};
}

exports.redirect_after_editing = function(req, res) {
	switch(req.query.pcalview) {
		case 'timeline': {
			res.redirect("/timeline/" + req.params.day);
			break;
		}
		default: {
			res.redirect("/day/" + req.params.day + "?back=false");
		}
	}
}

exports.create_empty_away = function(uuid) {
	var away = { uuid: uuid, punit : { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" }, name: '', involveddb_id: '', reason: ''};
	return away;
}

exports.create_empty_keep_in_mind = function(uuid) {
	var keep_in_mind = { uuid: uuid, punit : { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" }, name: '', description: ''};
	return keep_in_mind;
}

exports.create_empty_todo = function(uuid) {
	var todo = { uuid: uuid, punit : { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" }, name: '', description: '', involved: []};
	return todo;
}

exports.create_empty_vehicle_use = function(uuid) {
	var todo = { uuid: uuid, punit : { name : "Rödental St. Hedwig", dn : "eb_bamberg/d_coburg/sb_cosl/p_roedental" }, name: '', description: '', involved: [], vehicle_id: "r_pfarrbus"};
	return todo;
}
