function startJavascript()
{
    changeAllNospam('content-body');
}
addWindowOnload(startJavascript);

/* returns integers with leading zeros */
function zeroFill(i) {
    if (i < 10)
	return '0' + i;
    else
	return i;
}

/* format a date like YYYY-MM-DD */
function Date_toSimpleString()
{
    return this.getFullYear() 
	+ '-' + zeroFill(this.getMonth() + 1) 
	+ '-' + zeroFill(this.getDate());
}

/* create the date 'x' days in the future */
function Date_dayIncrement(x)
{
    this.setDate(this.getDate() + x);
    return this;
}

/* create the date 'x' months in the future */
function Date_monthIncrement(x)
{
    this.setMonth(this.getMonth() + x);
    return this;
}

/* create the date 'x' years in the future */
function Date_yearIncrement(x)
{
    this.setFullYear(this.getFullYear() + x);
    return this;
}

/* extend the builtin Date() class */
Date.prototype.toSimpleString = Date_toSimpleString;
Date.prototype.dayIncrement = Date_dayIncrement;
Date.prototype.monthIncrement = Date_monthIncrement;
Date.prototype.yearIncrement = Date_yearIncrement;

/* return true if 'c' is a blank/space charachter */
function isSpace(c)
{
    switch (c) {
    case ' ':
    case '\n':
    case '\r':
    case '\240': /* Opera 8.5 &nbsp; */
    case '\t':
	return true;
    default:
	return false;
    }
    return false;
}

/* remove leading and trailing spaces */
function String_trim()
{
    var b = 0;
    var e = this.length;

    while (isSpace(this.charAt(b)))
	++b;

    while (isSpace(this.charAt(--e)))
	;
    
    return this.substring(b, e + 1);
}
String.prototype.trim = String_trim;

/* take tag with conten on the form
 * name ';' user '(' at ')' domain
 * and change it to a linked version
 */
function createLinkedAdress(tag) {
    if (tag != null) {
	/* note: in Opera 8.5 &nbsp; is already replaced with char '\240' */
	var ep = tag.innerHTML.replace(/&nbsp;/gi, '\240');

	var name_end = ep.indexOf(';');
	var at_start = ep.indexOf('(');
	var at_end = ep.indexOf(')');
	var name = ep.substring(0, name_end).trim();
	var user = ep.substring(name_end + 1, at_start).trim();
	var domain = ep.substring(at_end + 1, ep.length).trim();

	if (name == "")
	    name = user + "&#x40;" + domain;
	
	tag.innerHTML = '<' + "a hr" + "ef=\"&#x6d;&#x61;&#10" 
	    + "5;&#108;&#x74;&#x6f;&#58;" 
	    + user + "&#x40;" + domain + "\">" + name + "</a>";
    }
}

/* repalce all tags with css class 'nospam' to a linked email adress */
function changeAllNospam(containerid)
{
    var container = document.getElementById(containerid);
    if (container != null) {
	var cells = container.getElementsByTagName('span');
	
	for (var i = 0; i < cells.length; ++i) {
	    if (cells[i].className == 'nospam')
		createLinkedAdress(cells[i]);
	}
    }
}

