var DEBUG = 0;

function debug(sMessage, iLevel) {
	if (DEBUG <= iLevel) {
		alert(sMessage);
	}
}


/**
 * Adds a function to the window.onload-function
 */
function addLoadEvent(oFunction) {
	var oOldFunction = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = oFunction;
	} else {
		window.onload = function() {
			if (oOldFunction) {
				oOldFunction();
			}
			oFunction();
		}
	}
}

/**
 * @param sID
 *            The ID of the element to be returned
 * @return The element with the given sID or null if the document does not
 *         contain such an element
 */
function $(sID) {
	if(sID == "body"){
		var oBody =  document.getElementById(sID);
		if(!oBody){
			 oBody = document.getElementsByName('body')[0];
		}
		return oBody;
	} else {
		return document.getElementById(sID);
	}
}

function cancelEventPropagation(oEvent) {
	oEvent.cancelBubble = true;
	if (oEvent.stopPropagation) {
		oEvent.stopPropagation();
	}
}

/**
 * Changes the value of an attribute of the element with the given ID
 * 
 * @param sID
 *            The ID of the element which attribute is to be changed
 * @param sName
 *            The name of the attribute to be changed/added
 * @param sValue
 *            The value of the attribute
 */
function changeAttribut(oElement, sName, sValue) {
	if (sName != null && sName != "" && sValue != null && sValue != "") {
		oElement.setAttribute(sName, sValue);
	}
}

/**
 * Sets the classname of the element with the given ID
 * 
 * @param sID
 *            The ID of the element which classname is to be set
 * @param sClassName
 *            The classname
 */
function setClassName(oElement, sClassName) {
	oElement.className = sClassName;
}

/**
 * Sets the classname of the element with the given ID
 * 
 * @param sID
 *            The ID of the element which classname is to be set
 * @param sClassName
 *            The classname
 */
function replaceClass(oElement, sOldClass, sNewClass) {
	if (new RegExp('\\b' + sOldClass + '\\b').test(oElement.className)) {
		oElement.className = oElement.className.replace(sOldClass, sNewClass);
	}
}

/**
 * Adds the classname to the element with the given ID
 * 
 * @param sID
 *            The ID of the element which classname is to be added
 * @param sClassName
 *            The classname
 */
function addClass(oElement, sClassName) {
	if (!new RegExp('\\b' + sClassName + '\\b').test(oElement.className)) {
		oElement.className = oElement.className + " " + sClassName;
	}
}

/**
 * Creates a new script element with the given script as the content
 * 
 * @param sScript
 *            the text/javascript to be inserted into the new script element
 */
function addJavaScript(sScript) {
	if (sScript != null && sScript != "") {
		var oElement = document.createElement("script");
		oElement.setAttribute("type", "text/javascript");
		oElement.innerHTML = sScript;
		document.getElementsByTagName("head")[0].appendChild(oElement);
	}
}

/**
 * @param oElement
 *            The element to be added
 * @param sParentElementID
 *            The ID of the element the new element should be appended
 * @param sPreSiblingID
 *            The ID of the parent-element's sibling that will be the
 *            pre-sibling of the new element
 */
function replaceElement(oElement, oReplaceElement) {
	if (oReplaceElement) {
		oReplaceElement.parentNode.replaceChild(oElement, oReplaceElement);
	} else {
		addElement(oElement);
	}
}
/**
 * @param oElement
 *            The element to be added
 * @param sPreSiblingID
 *            The ID of the parent-element's sibling that will be the
 *            pre-sibling of the new element
 */
function addAfterElement(oElement, oPreSibling) {
	var oPostSibling = oPreSibling.nextSibling;

	if (oPostSibling != null) {
		var oParent = oPostSibling.parentNode;
		oParent.insertBefore(oElement, oPostSibling);
	} else {
		oPreSibling.parentNode.appendChild(oElement);
	}
}

/**
 * @param oElement
 *            The element to be added
 * @param sPostSiblingID
 *            The ID of the parent-element's sibling that will be the following
 *            sibling of the new element
 */
function addBeforeElement(oElement, oPostSibling) {
	var oParent = oPostSibling.parentNode;

	oParent.insertBefore(oElement, oPostSibling);
}

function myEncodeURIComponent(sString){
	 if (typeof encodeURIComponent == "function"){
		return encodeURIComponent(sString);
	}

	var sReturn = '';
	asChars = sString.split('');
	asEncoded = {' ':'%20', '"':'%22', '#':'%23', '$':'%24', '%':'%25', '&':'%26', '+':'%2B', ',':'%2C', '/':'%2F', ':':'%3A', ';':'%3B', '<':'%3C', '=':'%3D', '>':'%3E', '?':'%3F', '@':'%40', '[':'%5B', '\\':'%5C', ']':'%5D', '^':'%5E', '`':'%60', '{':'%7B', '|':'%7C', '}':'%7D', '¢':'%C2%A2', '£':'%C2%A3', '¤':'%C2%A4', '¥':'%C2%A5', '¦':'%C2%A6', '§':'%C2%A7', '¨':'%C2%A8', '©':'%C2%A9', 'ª':'%C2%AA', '«':'%C2%AB', '¬':'%C2%AC', '­':'%C2%AD', '®':'%C2%AE', '¯':'%C2%AF', '°':'%C2%B0', '±':'%C2%B1', '²':'%C2%B2', '³':'%C2%B3', '´':'%C2%B4', 'µ':'%C2%B5', '¶':'%C2%B6', '·':'%C2%B7', '¸':'%C2%B8', '¹':'%C2%B9', 'º':'%C2%BA', '»':'%C2%BB', '¼':'%C2%BC', '½':'%C2%BD', '¾':'%C2%BE', '¿':'%C2%BF', 'À':'%C3%80', 'Á':'%C3%81', 'Â':'%C3%82', 'Ã':'%C3%83', 'Ä':'%C3%84', 'Å':'%C3%85', 'Æ':'%C3%86', 'Ç':'%C3%87', 'È':'%C3%88', 'É':'%C3%89', 'Ê':'%C3%8A', 'Ë':'%C3%8B', 'Ì':'%C3%8C', 'Í':'%C3%8D', 'Î':'%C3%8E', 'Ï':'%C3%8F', 'Ð':'%C3%90', 'Ñ':'%C3%91', 'Ò':'%C3%92', 'Ó':'%C3%93', 'Ô':'%C3%94', 'Õ':'%C3%95', 'Ö':'%C3%96', '×':'%C3%97', 'Ø':'%C3%98', 'Ù':'%C3%99', 'Ú':'%C3%9A', 'Û':'%C3%9B', 'Ü':'%C3%9C', 'Ý':'%C3%9D', 'Þ':'%C3%9E', 'ß':'%C3%9F', 'à':'%C3%A0', 'á':'%C3%A1', 'â':'%C3%A2', 'ã':'%C3%A3', 'ä':'%C3%A4', 'å':'%C3%A5', 'æ':'%C3%A6', 'ç':'%C3%A7', 'è':'%C3%A8', 'é':'%C3%A9', 'ê':'%C3%AA', 'ë':'%C3%AB', 'ì':'%C3%AC', 'í':'%C3%AD', 'î':'%C3%AE', 'ï':'%C3%AF', 'ð':'%C3%B0', 'ñ':'%C3%B1', 'ò':'%C3%B2', 'ó':'%C3%B3', 'ô':'%C3%B4', 'õ':'%C3%B5', 'ö':'%C3%B6', '÷':'%C3%B7', 'ø':'%C3%B8', 'ù':'%C3%B9', 'ú':'%C3%BA', 'û':'%C3%BB', 'ü':'%C3%BC', 'ý':'%C3%BD', 'þ':'%C3%BE', 'ÿ':'%C3%BF', 'Ā':'%C4%80', 'ā':'%C4%81', 'Ă':'%C4%82', 'ă':'%C4%83', 'Ą':'%C4%84', 'ą':'%C4%85', 'Ć':'%C4%86', 'ć':'%C4%87', 'Ĉ':'%C4%88', 'ĉ':'%C4%89', 'Ċ':'%C4%8A', 'ċ':'%C4%8B', 'Č':'%C4%8C', 'č':'%C4%8D', 'Ď':'%C4%8E', 'ď':'%C4%8F', 'Đ':'%C4%90', 'đ':'%C4%91', 'Ē':'%C4%92', 'ē':'%C4%93', 'Ĕ':'%C4%94', 'ĕ':'%C4%95', 'Ė':'%C4%96', 'ė':'%C4%97', 'Ę':'%C4%98', 'ę':'%C4%99', 'Ě':'%C4%9A', 'ě':'%C4%9B', 'Ĝ':'%C4%9C', 'ĝ':'%C4%9D', 'Ğ':'%C4%9E', 'ğ':'%C4%9F', 'Ġ':'%C4%A0', 'ġ':'%C4%A1', 'Ģ':'%C4%A2', 'ģ':'%C4%A3', 'Ĥ':'%C4%A4', 'ĥ':'%C4%A5', 'Ħ':'%C4%A6', 'ħ':'%C4%A7', 'Ĩ':'%C4%A8', 'ĩ':'%C4%A9', 'Ī':'%C4%AA', 'ī':'%C4%AB', 'Ĭ':'%C4%AC', 'ĭ':'%C4%AD', 'Į':'%C4%AE', 'į':'%C4%AF', 'İ':'%C4%B0', 'ı':'%C4%B1', 'Ĳ':'%C4%B2', 'ĳ':'%C4%B3', 'Ĵ':'%C4%B4', 'ĵ':'%C4%B5', 'Ķ':'%C4%B6', 'ķ':'%C4%B7', 'ĸ':'%C4%B8', 'Ĺ':'%C4%B9', 'ĺ':'%C4%BA', 'Ļ':'%C4%BB', 'ļ':'%C4%BC', 'Ľ':'%C4%BD', 'ľ':'%C4%BE', 'Ŀ':'%C4%BF', 'ŀ':'%C5%80', 'Ł':'%C5%81', 'ł':'%C5%82', 'Ń':'%C5%83', 'ń':'%C5%84', 'Ņ':'%C5%85', 'ņ':'%C5%86', 'Ň':'%C5%87', 'ň':'%C5%88', 'ŉ':'%C5%89', 'Ŋ':'%C5%8A', 'ŋ':'%C5%8B', 'Ō':'%C5%8C', 'ō':'%C5%8D', 'Ŏ':'%C5%8E', 'ŏ':'%C5%8F', 'Ő':'%C5%90', 'ő':'%C5%91', 'Œ':'%C5%92', 'œ':'%C5%93', 'Ŕ':'%C5%94', 'ŕ':'%C5%95', 'Ŗ':'%C5%96', 'ŗ':'%C5%97', 'Ř':'%C5%98', 'ř':'%C5%99', 'Ś':'%C5%9A', 'ś':'%C5%9B', 'Ŝ':'%C5%9C', 'ŝ':'%C5%9D', 'Ş':'%C5%9E', 'ş':'%C5%9F', 'Š':'%C5%A0', 'š':'%C5%A1', 'Ţ':'%C5%A2', 'ţ':'%C5%A3', 'Ť':'%C5%A4', 'ť':'%C5%A5', 'Ŧ':'%C5%A6', 'ŧ':'%C5%A7', 'Ũ':'%C5%A8', 'ũ':'%C5%A9', 'Ū':'%C5%AA', 'ū':'%C5%AB', 'Ŭ':'%C5%AC', 'ŭ':'%C5%AD', 'Ů':'%C5%AE', 'ů':'%C5%AF', 'Ű':'%C5%B0', 'ű':'%C5%B1', 'Ų':'%C5%B2', 'ų':'%C5%B3', 'Ŵ':'%C5%B4', 'ŵ':'%C5%B5', 'Ŷ':'%C5%B6', 'ŷ':'%C5%B7', 'Ÿ':'%C5%B8', 'Ź':'%C5%B9', 'ź':'%C5%BA', 'Ż':'%C5%BB', 'ż':'%C5%BC', 'Ž':'%C5%BD', 'ž':'%C5%BE' };
	for(i in asChars){
		if(asEncoded[asChars[i]]){
			sReturn += asEncoded[asChars[i]];
		} else {
			sReturn += asChars[i];
		}
	}
	return sReturn;
}

/**
 * Adds the given element to the body-div
 * 
 * @param oElement
 *            The element to be added to the body
 */
function addElement(oElement) {
	appendElement(oElement, "content");
}

/**
 * @param oElement
 *            The element to be added
 * @param sParentElementID
 *            The ID of the element the new element is to be appended to
 */
function appendElement(oElement, oParent) {
	if (oElement != null && $(oElement.id) != null) {
		removeElement($(oElement.id));
	}

	oParent.appendChild(oElement);
}

/**
 * @param oElement
 *            The element to be added
 * @param sParentElementID
 *            The ID of the element the new element is to be appended to
 */
function appendElementAsFirstChild(oElement, oParent) {

	if (oElement != null && $(oElement.id) != null) {
		removeElement($(oElement.id));
	}

	var aoChildren = oParent.childNodes;

	if (aoChildren.length > 0) {
		oParent.insertBefore(oElement, aoChildren[0]); // equals
														// AddBeforeElement
	} else {
		oParent.appendChild(oElement);
	}
}

/**
 * @param sElementID
 *            The ID of the element to be removed
 */
function removeElement(oElement) {
	if (oElement != null) {
		oElement.parentNode.removeChild(oElement);
	}
}

/**
 * Toggles the visibility of the element with the given ID
 */
function toggleVisibility(element) {
	if (element.style.display == "none") {
		element.style.display = "";
	} else {
		element.style.display = "none";
	}
}

/**
 * Sets the element invisible
 */
function hide(oElement) {
	oElement.style.display = "none";
}

/**
 * Sets the element visible
 */
function show(oElement) {
	oElement.style.display = "";
}

function gotoElement(oElement) {
	javascript:location.hash = '#'+oElement.id;
}

function disable(oElement) {
	oElement.setAttribute("disabled", "disabled");
}

function enable(oElement) {
	oElement.setAttribute("disabled", "");
}

/**
 * Stes the innerHTMl of the element with the given sID
 */
function setInnerHTML(oElement, sInnerHTML) {
	switch (oElement.type) {
	case "text":
	case "password":
		oElement.value = sInnerHTML;
		break;
	default:
		oElement.innerHTML = sInnerHTML;
		break;
	}
}
/**
 * Redirects the window to the given URL
 * 
 * @param sURL
 *            the URL to be redirected to
 */
function redirect(sURL) {
	window.location.href = sURL;
}

/**
 * getPageSize() Returns array with page width, height and window width, height
 * Core code from - quirksmode.org Edit for Firefox by pHaez
 */
function getPageSize() {

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) { // all
																			// but
																			// Explorer
																			// Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla
				// and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) { // all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement
			&& document.documentElement.offsetHeight) { // Explorer 6 Strict
														// Mode
		windowWidth = document.documentElement.offsetWidth;
		windowHeight = document.documentElement.offsetHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.offsetWidth;
		windowHeight = document.body.offsetHeight;
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight) {
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth) {
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	
	// search vor big lightboxes (position: absolute
	var aoLightBoxes = getLightBoxes();
	for( i in aoLightBoxes ){
		oElement = aoLightBoxes[i];
		
		if(oElement.offsetHeight+oElement.offsetTop>pageHeight){
			pageHeight = oElement.offsetHeight + oElement.offsetTop;
		}
	}
	arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowHeight);
	return arrayPageSize;
}


function getPosition(oElement){
    var oPos = { y: 0, x: 0 };

    if(oElement) {
         var oParent=oElement;
         while(oParent && oParent.tagName.toUpperCase() != 'BODY')
         {
              oPos.y += oParent.offsetTop;
              oPos.x += oParent.offsetLeft;
              oParent = oParent.offsetParent;
         }
    }
    return oPos;
} 



/**
 * Returns array with x,y page scroll values. Core code from - quirksmode.org
 */
function getPageScroll(){
        var xScroll, yScroll;

        if (self.pageYOffset) {
                yScroll = self.pageYOffset;
        } else if (document.documentElement && document.documentElement.scrollTop){      // Explorer 6 Strict
                yScroll = document.documentElement.scrollTop;
        } else if (document.body) {// all other Explorers
                yScroll = document.body.scrollTop;
        }
        
        if (self.pageXOffset) {
                xScroll = self.pageXOffset;
        } else if (document.documentElement && document.documentElement.scrollLeft){      // Explorer 6 Strict
                xScroll = document.documentElement.scrollTop;
        } else if (document.body) {// all other Explorers
                xScroll = document.body.scrollLeft;
        }

        arrayPageScroll = new Array(xScroll,yScroll)
        return arrayPageScroll;
}

function getElementsByClassName(class_name) {
	var all_obj, ret_obj = new Array(), j = 0, teststr;

	if (document.all)
		all_obj = document.all;
	else if (document.getElementsByTagName && !document.all)
		all_obj = document.getElementsByTagName("*");

	for (i = 0; i < all_obj.length; i++) {
		if (all_obj[i].className.indexOf(class_name) != -1) {
			teststr = "," + all_obj[i].className.split(" ").join(",") + ",";
			if (teststr.indexOf("," + class_name + ",") != -1) {
				ret_obj[j] = all_obj[i];
				j++;
			}
		}
	}
	return ret_obj;
}

function getElementPosition(oElement) {
	var iX = 0;
	var iY = 0;
	while (oElement) {
		iX += oElement.offsetLeft;
		iY += oElement.offsetTop;
		oElement = oElement.offsetParent;
	}
	return {'x' :iX, 'y' :iY }
}


document.getElementsByClassName = function(sClassName) {
	var aoFoundElements = [];
	var oClass = new RegExp('\\b'+sClassName+'\\b');
	var oElement = this.getElementsByTagName('*');
	for (var i = 0; i < oElement.length; i++) {
		var classes = oElement[i].className;
		if (oClass.test(classes)) aoFoundElements.push(oElement[i]);
	}
	return aoFoundElements;
}; 


function valDate (strDate) {
   var parsedDate = strDate.split (".");
   if (parsedDate.length != 3) return false;
   var day, month, year;
   day = parsedDate[0];
   month = parsedDate[1]-1;
   year = parsedDate[2];
   
   var objDate = new Date (year, month, day);
   if (month != objDate.getMonth()) return false;
   if (day != objDate.getDate()) return false;
   if (year != objDate.getFullYear()) return false;

   return objDate;
}
// /////////////////////////////////////
function Calendar(oElement, firstDay, lastDay) {
	this.oElement = oElement;

	this.firstDay = valDate(firstDay);
	this.lastDay = valDate(lastDay);
	
	if (oElement.oCalendar) {
		oElement.oCalendar.remove();
	}

	this.aiElementPosition = getElementPosition(oElement);
	this.aiElementPosition.y += oElement.offsetHeight;
	this.id = 'Calendar_' + oElement.id;
	this.iMonth = this.iYear = 0;

	this.asMonthNames = [ "Jan.", "Feb.", "Mär.", "Apr.", "Mai", "Jun.",
			"Jul.", "Aug.", "Sep.", "Okt.", "Nov.", "Dez." ];
	this.aiMonthLengths = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];

	this.getMonthLength = function(iMonth) {
		iYear = this.iYear;
		if (iMonth != 2)
			return this.aiMonthLengths[iMonth - 1];
		else
			return (iYear % 4 ? 28 : (iYear % 100 ? 29
					: (iYear % 400 ? 28 : 29)));
	}
	
	this.oElement.onSelectionChanged = function(){
		if (this.getAttribute('onSelectionChanged')!= null){
			eval(this.getAttribute('onSelectionChanged'));
		}
	}

	this.setMonth = function(iMonth, iYear) {
		while (iMonth > 12) {
			iMonth -= 12;
			iYear++;
		}
		while (iMonth < 1) {
			iMonth += 12;
			iYear--;
		}

		this.iMonth = iMonth;
		this.iYear = iYear;
		var oDate = new Date(iYear, iMonth - 1, 1);
		var iWeekday = (oDate.getDay() + 6) % 7;

		this.oMonthCell.firstChild.nodeValue = this.asMonthNames[iMonth - 1]
				+ ' ' + iYear;

		iMonthLength = this.getMonthLength(this.iMonth);
		iLastMonthLength = this.iMonth > 1 ? this.getMonthLength(this.iMonth-1) : this.getMonthLength(12);
		for (iCell = 0; iCell < 42; iCell++) {
			if ((iCell + 1) > iWeekday && (iCell - iWeekday) < iMonthLength) {
				this.aoDayCells[iCell].firstChild.nodeValue = ((iCell + 1) - iWeekday);
				oDate = new Date(iYear, iMonth - 1, (iCell + 1) - iWeekday);

				if ((!this.firstDay || oDate >= this.firstDay) && (!this.lastDay || oDate <= this.lastDay)) {
					this.aoDayCells[iCell].onclick = function() {
						var sDay = this.firstChild.nodeValue;
						if(sDay<10){
							sDay = '0'+sDay;
						}
						var sMonth = iMonth;
						if(iMonth<10){
							sMonth = '0'+sMonth;
						}
						this.oCalendar.oElement.value = sDay+ '.' + sMonth + '.' + iYear;
						this.oCalendar.oElement.onSelectionChanged();
						this.oCalendar.remove();
					}
					this.aoDayCells[iCell].className = ((iCell % 7) < 5 ? 'Weekday'
							: 'Weekend')
							+ ' Available'
							+ (oDate == this.oCurrentDate ? ' Today' : '');

				} else {
					this.aoDayCells[iCell].onclick = null;
					this.aoDayCells[iCell].className = ((iCell % 7) < 5 ? 'Weekday'
							: 'Weekend') + ' Unavailable';
				}
			} else {
				
				if((iCell - iWeekday) < iMonthLength){
					this.aoDayCells[iCell].firstChild.nodeValue = ((iCell + 1) - iWeekday + iLastMonthLength);
				} else {
					this.aoDayCells[iCell].firstChild.nodeValue = ((iCell + 1) - iWeekday - iMonthLength);
				}
				this.aoDayCells[iCell].className = "Unavailable";
			}
		}
	}

	this.nextMonth = function() {
		this.setMonth(this.iMonth + 1, this.iYear);
	}

	this.previousMonth = function() {
		this.setMonth(this.iMonth - 1, this.iYear);
	}

	this.nextYear = function() {
		this.setMonth(this.iMonth, this.iYear + 1);
	}

	this.previousYear = function() {
		this.setMonth(this.iMonth, this.iYear - 1);
	}

	this.rTimeout = false;

	this.remove = function() {
		this.oElement.oCalendar = null;
		this.oCalendarElement.parentNode.removeChild(this.oCalendarElement);
	}

	this.createCalendarElement = CreateCalendarElement;
	this.createCalendarElement();
	// this.oCalendarElement.onclick = function() {
	// this.oCalendar.stopRemoval(); }

	this.oCurrentDate = new Date();
	// TODO Create a date with the current date, not the current time
	this.oCurrentDate = new Date(this.oCurrentDate.getFullYear(),
			this.oCurrentDate.getMonth(), this.oCurrentDate.getDate());
	this.setMonth(this.oCurrentDate.getMonth() + 1, this.oCurrentDate
			.getFullYear());

	asDate = this.oElement.value.split('.');
	if (asDate.length == 3) {
		var oDate = new Date(asDate[2], asDate[1] - 1, asDate[0]);
		this.setMonth(oDate.getMonth() + 1, oDate.getFullYear());
	}

	// Check if the calendar is inside a lightbox	
	while (oElement) {
		if (oElement.id == 'body'|| (oElement.className != undefined && oElement.className.match(/lightboxContainer/))) {
			if (oElement.aoDependentElements != undefined) {
				oElement.aoDependentElements.push(this.oCalendarElement);
			} else {
				oElement.aoDependentElements = new Array(this.oCalendarElement);
			}
			break;
		}
		oElement = oElement.parentNode;
	}
}

function CreateCalendarElement() {
	this.oCalendarElement = document.createElement('div');
	this.oCalendarElement.oCalendar = this;
	this.oCalendarElement.className = 'Calendar';
	this.oCalendarElement.id = this.id;
	this.oCalendarElement.style.position = 'absolute';
	this.oCalendarElement.style.zIndex = 256;
	this.oCalendarElement.style.left = this.aiElementPosition.x + 'px';
	this.oCalendarElement.style.top = this.aiElementPosition.y + 'px';

	var oTable = document.createElement('table');
	var oTableBody = document.createElement('tbody');
	var oTitleRow = document.createElement('tr');
	var oTitleCell;

	oTitleCell = document.createElement('th');
	oTitleCell.appendChild(document.createTextNode('«')); // « or << or ⇐
	oTitleCell.className = 'PrevNext';
	oTitleCell.oCalendar = this;
	oTitleCell.onclick = function() {
		this.oCalendar.previousYear();
	}
	oTitleRow.appendChild(oTitleCell);

	oTitleCell = document.createElement('th');
	oTitleCell.appendChild(document.createTextNode('‹')); // < or ‹ or ←
	oTitleCell.className = 'PrevNext';
	oTitleCell.oCalendar = this;
	oTitleCell.onclick = function() {
		this.oCalendar.previousMonth();
	}
	oTitleRow.appendChild(oTitleCell);

	this.oMonthCell = document.createElement('th');
	this.oMonthCell.colSpan = 3;
	this.oMonthCell.appendChild(document.createTextNode('x'));
	oTitleRow.appendChild(this.oMonthCell);

	oTitleCell = document.createElement('th');
	oTitleCell.appendChild(document.createTextNode('›')); // > or → or ›
	oTitleCell.className = 'PrevNext';
	oTitleCell.oCalendar = this;
	oTitleCell.onclick = function() {
		this.oCalendar.nextMonth();
	}
	oTitleRow.appendChild(oTitleCell);

	oTitleCell = document.createElement('th');
	oTitleCell.appendChild(document.createTextNode('»')); // » or >> or ⇒
	oTitleCell.className = 'PrevNext';
	oTitleCell.oCalendar = this;
	oTitleCell.onclick = function() {
		this.oCalendar.nextYear();
	}
	oTitleRow.appendChild(oTitleCell);

	oTableBody.appendChild(oTitleRow);

	this.aoDayCells = new Array();

	for (iRow = 0; iRow < 6; iRow++) {
		var oRow = document.createElement('tr');
		for (iCol = 0; iCol < 7; iCol++) {
			var oCell = document.createElement('td');
			oCell.className = (iCol < 5 ? 'Weekday' : 'Weekend');

			oCell.appendChild(document.createTextNode('x'));
			this.aoDayCells.push(oCell);
			oCell.oCalendar = this;

			oCell.id = this.id + '_' + iRow + '_' + iCol;

			oRow.appendChild(oCell);
		}
		oTableBody.appendChild(oRow);
	}

	oRow = document.createElement('tr');
	oCell = document.createElement('td');
	oCell.className = 'CloseLink';
	oCell.appendChild(document.createTextNode('[Schließen]'));
	oCell.oCalendar = this;
	oCell.colSpan = 7;
	oCell.onclick = function() {
		this.oCalendar.remove();
	}
	oRow.appendChild(oCell);
	oTableBody.appendChild(oRow);

	oTable.appendChild(oTableBody);
	this.oCalendarElement.appendChild(oTable);
	document.getElementsByTagName('body')[0].appendChild(this.oCalendarElement);
}

function closeGlobalDependentElements() {
	oEl = $('body');
	// Remove dependent elements such as autocompletion windows or calendars
	if (oEl.aoDependentElements) {
		for (iIndex = oEl.aoDependentElements.length - 1; iIndex >= 0; iIndex--) {
			if (oEl.aoDependentElements[iIndex].parentNode) {
				oEl.aoDependentElements[iIndex].parentNode.removeChild(oEl.aoDependentElements[iIndex]);
			}
		}
	}
}
