/*
Content-Type: text/javascript
*/


// trim leading & trailing spaces
function trim(string) {
    var i = 0;
    var j = string.length;
    for (; i < j; i++) {
	switch (string.charAt(i)) {
	case ' ':
	case '\t':
	case '\r':
	case '\n':
	    continue;
	}
	break;
    }

    while (i < --j) {
	switch (string.charAt(j)) {
	case ' ':
	case '\t':
	case '\r':
	case '\n':
	    continue;
	}
	break;
    }
    j++;

    if (0 < i || j < string.length)
	string = string.substring(i, j);
    return string;
}


function cellDay(element) {
    if (element.className.indexOf("day") != 0)
	return "";
    if (element.firstChild == null)
	return "";
    if (element.firstChild.nodeType == 3) {
	return trim(element.firstChild.nodeValue);
    }
    return "";
}

function showToday() {
    var now = new Date();
    var dayofmonth = now.getDate().toString();
    var calendar = document.getElementById("calendar");
    if (calendar == null)
	return false;
    var cells = null;
    for (var i = 0; i < calendar.childNodes.length; i++) {
	var node = calendar.childNodes[i];
	if (node.nodeType == 1
	    && node.className == "cells")
	    cells = node;
    }
    if (cells == null)
	return false;
    for (var j = 0; j < cells.childNodes.length; j++) {
	var node = cells.childNodes[j];
	if (node.nodeType == 1 && node.nodeName == "LI") {
	    if (cellDay(node) == dayofmonth)
		node.className = node.className + " today";
	}
    }
    return false;
}

var name = window.location.pathname;
var slashAt = name.lastIndexOf('/');
if (slashAt >= 0)
    name = name.substring(slashAt + 1);
var now = new Date();
var monthNow = (now.getMonth() + 1).toString();
if (monthNow.length == 1)
    monthNow = "0" + monthNow;
if (name.length >= 7 && name.charAt(4) == '-'
    && now.getFullYear().toString() == name.substring(0, 4)
    && monthNow == name.substring(5, 7)) {
    var dayofmonth = now.getDate().toString();

    if (window.addEventListener) {
        window.addEventListener("load", showToday, true);
    } else if (window.attachEvent) {
        window.attachEvent("onload", showToday);
    }
};


