<?xml version='1.0' encoding='UTF-8' ?>
<Module>
<ModulePrefs
title='__MSG_title__'
title_url='__MSG_title_url__'
directory_title='__MSG_directory_title__'
description='__MSG_description__'
screenshot='http://www.procontext.com/gg/calendar/calendar_screenshot_n.png'
thumbnail='http://www.procontext.com/gg/calendar/calendar_thumbnail.png'
author='Jan Buchwald'
author_affiliation='ProContext GmbH'
author_location='Cologne, Germany'
author_email='jan.buchwald@procontext.com'
category='communication'
category2='tools'
height="157"
width="275"
>
<Locale messages="http://www.procontext.com/gg/calendar/en_ALL.xml"/>
<Locale lang="de" messages="http://www.procontext.com/gg/calendar/de_ALL.xml"/>
<Locale lang="en" messages="http://www.procontext.com/gg/calendar/en_ALL.xml"/>
</ModulePrefs>
<UserPref name='days' display_name='__MSG_mark_days__:' />
<UserPref name="weekstart" display_name="__MSG_start_week__:" datatype="enum" default_value="Monday">
	<EnumValue value="Monday" display_value="__MSG_monday__"/>
	<EnumValue value="Sunday" display_value="__MSG_sunday__"/>
</UserPref>
<UserPref name="sasu_color" display_name="__MSG_sasu_color__:" datatype="enum" default_value="grey">
	<EnumValue value="grey" display_value="__MSG_grey__"/>
	<EnumValue value="black" display_value="__MSG_black__"/>
</UserPref>
<UserPref name="showclock" display_name="__MSG_show_clock__:" default_value="true" datatype="bool"/>
<UserPref name="clockformat" display_name="__MSG_clock_type__:" datatype="enum" default_value="12">
	<EnumValue value="12" display_value="__MSG_clock_12__"/>
	<EnumValue value="24" display_value="__MSG_clock_24__"/>
</UserPref>
<!--
<UserPref name="dateformat" display_name="__MSG_date_format__:" datatype="enum" default_value="1">
	<EnumValue value="1" display_value="__MSG_date_format_1__"/>
	<EnumValue value="2" display_value="__MSG_date_format_2__"/>
</UserPref>
-->
<Content type='html'>
<![CDATA[
<script>
/*
Simple calendar showing two months,
starting with Monday and indicating calendar weeks.
Allows highlighting of individual days.
*/

/*this gadget is based on the calendar gadget by Mark Johnson, markjson@gmail.com */

var days = null;
var now = new Date(); // initially start with today's date

function kalenderwocheNeu(j,m,t) {
var Datum=new Date(j,m-1,t);
var DoDat=donnerstag(Datum);
var kwjahr=DoDat.getFullYear();
var DoKW1=donnerstag(new Date(kwjahr,0,4));
return Math.floor(1.5+(DoDat.getTime()-DoKW1.getTime())/86400000/7)
}

function donnerstag(datum) {
var Do=new Date();
Do.setTime(datum.getTime() + (3-((datum.getDay()+6) % 7)) * 86400000);
return Do;
}

function run() {
var prefs = new _IG_Prefs(__MODULE_ID__);
days = "," + prefs.getString("days") + ",";
days =days.replace(/\.0/g,".");
days =days.replace(/\,0/g,",");
days =days.replace(/ /g,"");
weekstart = prefs.getString("weekstart");
showclock = prefs.getBool("showclock");
clockformat = prefs.getString("clockformat");
sasu_color = prefs.getString("sasu_color");
//dateformat = prefs.getString("dateformat");
dateformat = 2;
buildDisplay();

// Start the clock
if (showclock){
	updateClock();
	setInterval(updateClock, 1000);
}
}

function gel(id) {
return "_gel" in window ? _gel(id) : document.getElementById(id);
}

function calendar(date, type, cal) {
var year = date.getFullYear();
var month = date.getMonth();
var months = new Array("__MSG_jan__", "__MSG_feb__", "__MSG_mar__", "__MSG_apr__", "__MSG_may__","__MSG_jun__", "__MSG_jul__", "__MSG_aug__", "__MSG_sep__", "__MSG_oct__", "__MSG_nov__", "__MSG_dec__");
var html = "<table border=0 cellspacing=0 cellpadding=1 width='125px'>";
var sunday_pos = 0; // used to store the position of the sunday column, 
var sasu_header = "days";
html += "<tr align=center>";
if (cal==1){
html += "<th class='browse' align=center><div onclick='adjust(-1)'>&nbsp;<a href='#'>&lt;&lt;</a></div>";
html += "<th class='month' colspan=6 width='100%'>" + months[month] + "&nbsp;" + year + "<th class='month'></th>";
} else {
html += "<th class='month'></th><th class='month' colspan=6 width='100%'>" + months[month] + "&nbsp;" + year;
html += "<th class='browse' align=center><div onclick='adjust(1)'><a href='#'>&gt;&gt;</a>&nbsp;</div>";
}
html += "<tr align=center>";

if (sasu_color=="grey"){ // set style of sa/su headers
sasu_header="days_s";	
}

if (weekstart=="Monday"){
	sunday_pos = 5; 
	html += "<th><th class=days>__MSG_mo__<th class=days>__MSG_tu__<th class=days>__MSG_we__<th class=days>__MSG_th__<th class=days>__MSG_fr__<th class=" + sasu_header + ">__MSG_sa__<th class=" + sasu_header + ">__MSG_su__";
} else {
	sunday_pos = 0; 
	html += "<th><th class=" + sasu_header + ">__MSG_su__<th class=days>__MSG_mo__<th class=days>__MSG_tu__<th class=days>__MSG_we__<th class=days>__MSG_th__<th class=days>__MSG_fr__<th class=" + sasu_header + ">__MSG_sa__";
}
// create the body of the calendar
var d = new Date(year, month, 1);
if (weekstart=="Monday"){
	var first = d.getDay() - 1;
} else {
	var first = d.getDay();
}
if (first ==-1) first=6;
var today = new Date();
for (var i = 0; i < 42; i++) {
if ((i % 7) == 0) {
if (d.getMonth() == month) {
var cw = kalenderwocheNeu(year,month+1,i+1);

html += "<tr align=center><td class='cw'>" + cw + "</td>";
} else {
html += "<tr align=center><td>&nbsp;</td>";
}
}
html += "<td class='" + type + "'>";
var css_class="n";
if (i >= first && d.getMonth() == month) {
var content = d.getDate();
// mark sun- and saturdays
if (sasu_color=="grey"){
	if (((i % 7) == sunday_pos) || ((i % 7) == 6)){
	var css_class="grey";
}
}
// scan for marked letter days
var md = "," + d.getDate() + "." + (month + 1) + ",";
if (days.indexOf(md)!=-1) {
// handle a marked-letter day with a span
var css_class="marked";
}
if (dateMatch(d, today)) {
// handle today with a span
var css_class="today";
}
html += "<span class='" + css_class + "'>" + content + "</span>";
d = new Date(year, d.getMonth(), d.getDate() + 1);
} else {
html += "&nbsp;";
}
}

html += "</table>";
return html;
}

function dateMatch(d1, d2) {
return d1.getMonth() == d2.getMonth() && d1.getDate() == d2.getDate();
}

// increment the given date d by inc months
function incMonth(d, inc) {
return new Date(d.getFullYear(), d.getMonth() + inc);
}

function buildDisplay() {
gel("thisMonth").innerHTML = calendar(now, "main",1);
gel("postMonth").innerHTML = calendar(incMonth(now, 1), "main",2);
}

function adjust(inc) {
now = incMonth(now, inc);
buildDisplay();
}

/*clock functions*/
function updateClock() {
    var clock_now = new Date();    
    updateTimeDisplay(clock_now);
       
}
function updateTimeDisplay(clock_now) {
    var hours = clock_now.getHours();
    var year = clock_now.getFullYear();
	var month = clock_now.getMonth();
	var day = clock_now.getDay();
	var daydate = clock_now.getDate();
	var days = new Array("__MSG_sunday__", "__MSG_monday__", "__MSG_tuesday__", "__MSG_wednesday__", "__MSG_thursday__", "__MSG_friday__","__MSG_saturday__");
	var months = new Array("__MSG_jan__", "__MSG_feb__", "__MSG_mar__", "__MSG_apr__", "__MSG_may__","__MSG_jun__", "__MSG_jul__", "__MSG_aug__", "__MSG_sep__", "__MSG_oct__", "__MSG_nov__", "__MSG_dec__");
	
	gel("time").innerHTML = ", " + formatHours(hours) + ":" + formatMinutes(clock_now.getMinutes()) + formatAmPm(hours);
	if (dateformat=="1"){
    	gel("date").innerHTML = days[day] + ", " + months[month] + " " + daydate + ", " + year;
	} else {
		gel("date").innerHTML = days[day] + ", " + daydate + ". " + months[month] + " " + year;
	}
}

function formatHours(hours) {
    if (clockformat == "24") {
        return (hours < 10) ? ("0" + hours) : hours;
    } else {
        if (hours == 0) {
            return 12;
        } else if (hours <= 12) {
            return (hours < 10) ? ("0" + hours) : hours;
        } else {
            hours = hours - 12;
			return (hours < 10) ? ("0" + hours) : hours;
        }
    }
}

function formatMinutes(minutes) {
    return (minutes < 10) ? ("0" + minutes) : minutes;
}

function formatAmPm(hours) {
    if (clockformat == "12") {
        return (hours >= 12) ? " pm" : " am";
    } else {
        return "h";
    }
}


</script>
<style>

a {
text-decoration:none;
color: black;
}

table {
font-family: sans-serif;
font-size: 8pt;
border:0px;
}


th.month {
background-color: #e1e1e1;
color: black;
font-size: 9pt;
}

th.browse {
background-color: #e1e1e1;
color: black;
font-size: 7pt;
font-weight:bold;
}

th.days {
background-color: white;
color: black;
font-size: 8pt;
border-bottom: 1px solid black;
width:12%;
}

th.days_s {
background-color: white;
color: #949494;
font-size: 8pt;
border-bottom: 1px solid black;
width:12%;
}

span.grey {
color:#939393;
}

span.today {
border: 1px solid #ffcc00;
background-color: #ffeea8;
font-size: 9pt;
font-weight:bold;
}

span.n {
border: 1px solid white;
}

#datetime {
margin-left:5px;
margin-top:10px;
font-size: 9pt;

}

span.marked {
background-color: #e1e1e1;
border: 1px solid #e1e1e1;
color: black;
}
table.sub {
background-color: #CCFFFF;
}

.cw {
background-color: white;
color: black;
font-size: 7pt;
font-weight:bold;
border-right: 1px solid black;
width:12%;
}

</style>
<center>
<table cellspacing=0 cellpadding=1 border=0 width=265px>
<tr valign=top>
<td><div id=thisMonth></div>
<td><div style="width:15px"></div>
<td><div id=postMonth></div>
</table>
</center>
<div id="datetime">
<span id="date"></span><b><span id="time"></span></b>
</div>
<script> run(); </script>
]]>
</Content>
</Module>



