
var hoverLine = function() { this.className = this.className.addClass('hover'); };
var unHoverLine = function() { this.className = this.className.removeClass('hover'); };

var linkLine = function (tr) {
    var theLink = tr.getElementsByTagName('a')[0];
    if (!theLink) return;
    tr.style.cursor = 'pointer';
    tr.onmouseover  = hoverLine;
    tr.onmouseout   = unHoverLine;
    tr.onclick      = function() { location.href = theLink.href; };
}

var linkCompleteLines = function (tableElement) {
    var TRs = [];
    if (tableElement.childNodes.length>0) {
        for (var i=0; i<tableElement.childNodes.length; i++) {
            // HTML parser inserts tbody element
            if (tableElement.childNodes[i].tagName.toLowerCase()=='tbody') {
                for (var c=0; c<tableElement.childNodes[i].childNodes.length; c++) {
                    TRs = TRs.concat(tableElement.childNodes[i].childNodes[c]);
                }
            }
        }
    }
    for (var i=0; i<TRs.length; i++) {
        linkLine(TRs[i]);
    }
}

Rules['.uebungsplan'] = linkCompleteLines;



/* Add a class to a string */
String.prototype.addClass = function(theClass)
{
	if (this != "")
	{
		if (!this.classExists(theClass))
		{
			return this + " " + theClass;
		}
	}
	else
	{
		return theClass;
	}
	
	return this;
}

/* Check if a class exists in a string */
String.prototype.classExists = function(theClass)
{
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	
	if (regExpression.test(this))
	{
		return true;
	}
	
	return false;
}

/* Remove a class from a string */
String.prototype.removeClass = function(theClass)
{
	var regString = "(^| )" + theClass + "\W*";
	var regExpression = new RegExp(regString);
	
	return this.replace(regExpression, "");
}