Prototype.VersionExtended		= '1.0.1';
Prototype.Browser.navigator		= navigator.userAgent.toLowerCase();
Prototype.Browser.isStrict		= document.compatMode == "CSS1Compat";
Prototype.Browser.isOpera		= Prototype.Browser.Opera;
Prototype.Browser.isOpera9_5	= Prototype.Browser.Opera && Prototype.Browser.navigator.indexOf("opera/9.5") > -1;
Prototype.Browser.isOpera9_6	= Prototype.Browser.Opera && Prototype.Browser.navigator.indexOf("opera/9.6") > -1;
Prototype.Browser.isSafari		= Prototype.Browser.WebKit && Prototype.Browser.navigator.indexOf("chrome") == -1;
Prototype.Browser.isChrome		= Prototype.Browser.WebKit && Prototype.Browser.navigator.indexOf("chrome") > -1;
Prototype.Browser.isIE			= Prototype.Browser.IE;
Prototype.Browser.isIE6			= Prototype.Browser.IE && Prototype.Browser.navigator.indexOf("msie 6") > - 1;
Prototype.Browser.isIE7			= Prototype.Browser.IE && Prototype.Browser.navigator.indexOf("msie 7") > - 1;
Prototype.Browser.isIE8			= Prototype.Browser.IE && Prototype.Browser.navigator.indexOf("msie 8") > - 1;
Prototype.Browser.isGecko		= Prototype.Browser.Gecko;
Prototype.Browser.isFF			= Prototype.Browser.isGecko;
Prototype.Browser.isKHTML		= navigator.userAgent.indexOf('KHTML') > -1;
Prototype.Browser.isBorderBox	= Prototype.Browser.isIE && !Prototype.Browser.isStrict;
Prototype.Browser.isWindows		= (Prototype.Browser.navigator.indexOf("windows") != -1 || Prototype.Browser.navigator.indexOf("win32") != -1);
Prototype.Browser.isMac			= (Prototype.Browser.navigator.indexOf("macintosh") != -1 || Prototype.Browser.navigator.indexOf("mac os x") != -1);
Prototype.Browser.isLinux		= (Prototype.Browser.navigator.indexOf("linux") != -1);
Prototype.Browser.isSecure		= window.location.href.toLowerCase().indexOf("https") === 0;

Element.DISPLAY = "display";
Element.VISIBLE = "visibility";
Element.borders = {l: "border-left-width", r: "border-right-width", t: "border-top-width", b: "border-bottom-width"};
Element.paddings = {l: "padding-left", r: "padding-right", t: "padding-top", b: "padding-bottom"};
Element.margins = {l: "margin-left", r: "margin-right", t: "margin-top", b: "margin-bottom"};
Element.isBorderBox = Prototype.Browser.isIE && !Prototype.Browser.isStrict;
Element.noBoxAdjust = Prototype.Browser.isStrict ? {select: 1} : {input:1, select:1, textarea:1};
if (Prototype.Browser.isIE || Prototype.Browser.isGecko) Element.noBoxAdjust['button'] = 1;

Element.addUnits = function(v, defaultUnit) {var pattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i;if (v === "" || v == "auto"){return v;}if (v === undefined){return '';}if (typeof v == "number" || !pattern.test(v)){return v + 'px';}return v;};
Element.adjustWidth = function(width) { if (typeof width == "number" && width < 0){width = 0;} return width; };
Element.adjustHeight = function(height) { if (typeof height == "number" && height < 0){height = 0;} return height; };

/**
 * da Opera 9.5 anders arbeitet als Opera < 9.5 müssen wir getDimensions anpassen
 **/
if (Prototype.Browser.isOpera9_5)
{
	document.viewport.getDimensions = function()
	{
		var dimensions = { };
		$w('width height').each(function(d) {
			var D = d.capitalize();
			dimensions[d] = (!document.evaluate) ? self['inner' + D] : document.documentElement['client' + D];
		});
		return dimensions;
		};
}

Object.extend(Array.prototype, {
	merge: function(array)
	{
		var result =  this.clone();
		if (Object.isArray(array))	array.each(function(entry) { result.push(entry); });
		else						result.push(array);

		return result;
	},

	spliceArray: function(array)
	{
		return Array.prototype.without.apply(this, array);
	}
});

if (Prototype.Browser.isIE) {
	// Down Fix für id suche
	Selector._matchElements = Selector.matchElements;
	Selector.matchElements = function(elements, expression)
	{
		if (expression.substring(0, 1) == "#")
			return elements.findAll(function(element){return element.id == expression.substring(1);});
		else
			return Selector._matchElements(elements, expression);
	};
}

Object.extend(Object,
{
	isBoolean: function(object)
	{
		return typeof object == "boolean";
	},

	toStyleString: function(object)
	{
		return Object.keys(object).inject("", function(style, key) { return style + (object[key] != "" ? key.underscore().dasherize() + ":" + object[key] + ";" : ""); });
	}
});


if (Prototype.Browser.isIE6)
{
	Element.addMethods(
	{
		setOpacity: function(element, value)
		{
			element.style.filter = 'alpha(opacity=' + Math.round(value * 100) + ')';
			return element;
		}
	});

	document.viewport.getScrollOffsets = function()
	{
		var result = [document.body.scrollLeft || document.documentElement.scrollLeft, document.body.scrollTop || document.documentElement.scrollTop];

		result.left = result[0];
		result.top	= result[1];

		return result;
	};

	document.viewport.getDimensions = function()
	{
		return {
			width:	document.body.clientWidth || document.documentElement.clientWidth,
			height:	document.body.clientHeight || document.documentElement.clientHeight
		};
	};
}

Element.addMethods("IFRAME",
{
	getTextContent: function(element)
	{
		element = $(element);

        try {
        	var doc = $(element.contentWindow ? element.contentWindow.document : element.contentDocument ? element.contentDocument : element.document);
        } catch (e) {
        	return null;
        }
        if (!doc || !doc.body) return null;

        if (Prototype.Browser.isIE) return doc.body.innerText;
        else						return doc.body.textContent;

        return null;
	}
});
Element.addMethods("OPTION",
{
	setValue: function(element, value)
	{
		element = $(element);

		element.value = value;
		return element;
	}
});
Element.addMethods("SELECT",
{
	empty: function(element)
	{
		$(element).select("option").each(function(option) { option.remove(); })

		return $(element);
	},

	remove: function(element)
	{
		return Element.remove(element);
	},

	setOptions: function(element, data)
	{
		result = $A();
		element = $(element);
		element.empty();

		if (Object.isArray(data))
		{
			result = $A(data).collect(function(entry, index)
			{
				return "<option value='" + index + "'>" + entry + "</option>";
			});
		}
		else
		{
			result = Object.keys(data).collect(function(key)
			{
				return "<option value='" + key + "'>" + data[key] + "</option>";
			});
		}

		if (result.length != 0)
		{
			result.join('').applyTo(element);
			element.selectedIndex = 0;
		}

		return element;
	}
});

Element.addMethods({
	addClass: function(element, className)
	{
		return element.addClassName(className);
	},

	addStyles: function(element, sides, styles)
	{
		var val = 0, v, w;
		for (var i = 0, len = sides.length; i < len; i++) {
			v = element.getStyle(styles[sides.charAt(i)]);
			if (v) {
				 w = parseInt(v, 10);
				 if (w) { val += (w >= 0 ? w : -1 * w); }
			}
		}
		return val;
	},

	appendAfter: function(element, destination)
	{
		Element.insert(destination, { after:element.remove() });

		return destination;
	},

	appendBefore: function(element, destination)
	{
		Element.insert(destination, {before:element.remove() });

		return destination;
	},

	appendBottom: function(element, destination)
	{
		Element.insert(destination, { bottom:element.remove() });

		return destination;
	},

	appendTo: function(element, destination)
	{
		if (element.parentNode) element = element.parentNode.removeChild(element);
		destination.appendChild(element);
		return element;
	},

	appendTop: function(element, destination)
	{
		Element.insert(destination, { top:element.remove() });

		return destination;
	},

	applyTo: function(element, content)
	{
		element = $(element);
		element.removeChildrens();
		element.innerHTML = "";
		Element.insert(element, { bottom:content });
		return element
	},

	// removes whitespace-only text node children
	cleanWhitespaceRecursive: function(element)
	{
		element = $(element);
		var node = element.firstChild;
		while (node)
		{
			var nextNode = node.nextSibling;
			if (node.nodeType == 3 && !/\S/.test(node.nodeValue) )
			{
				element.removeChild(node);
			}
			else
			{
				Element.cleanWhitespaceRecursive(node);
			}
			node = nextNode;
		}
		return element;
	},

	collectStyles: function(element)
	{
		// bie Safari als Array verwenden
		if (Prototype.Browser.isSafari)	styles = $A(element.style);
		else							styles = Object.keys(element.style);

		return styles.inject({}, function(acc, style)
		{
			if (typeof style == "undefined"					||
				style == "length"							||
				style == "cssText"							||
				typeof element.style[style] == "undefined"	||
				!element.style[style]						||
				!isNaN(Number(style))						||
				typeof element.style[style] != "string"
			) return acc;

			if (style == "cssFloat") acc["float"] = element.style[style];
			else acc[style] = element.style[style];

			return acc;
		});
	},

	clearStyle: function(element, style)
	{
		if (typeof style == "string")
		{
			element.clearStyle($w(style));
		}
		else
		{
			style.each(function(delStyle)
			{
				if (!Prototype.Browser.isIE)
					element.style[delStyle] = "";
				else if (typeof element.style[delStyle] == "boolean")
					element.style[delStyle] = false;
				else if (typeof element.style[delStyle] == "string" && (element.style[delStyle].toLowerCase() == "true" || element.style[delStyle].toLowerCase() == "false"))
					element.style[delStyle] = false;
				else
					element.style[delStyle] = "";
			});
		}

		return element;
	},

	displayMode: function(element, mode)
	{
		element._displayMode = mode;
		return element;
	},

	getBorderWidth: function(element, side)
	{
		return element.addStyles(side, Element.borders);
	},

	getBottom: function(element)
	{
		return element.getY() + element.getHeight();
	},

	getBox: function(element, contentBox)
	{
		var xy;

		xy = element.getXY();
		var w = element.offsetWidth, h = element.offsetHeight, bx;
		if (!contentBox) {
			bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
		} else {
			var l = element.getBorderWidth("l") + element.getPadding("l");
			var r = element.getBorderWidth("r") + element.getPadding("r");
			var t = element.getBorderWidth("t") + element.getPadding("t");
			var b = element.getBorderWidth("b") + element.getPadding("b");
			bx = {x: xy[0] + l, y: xy[1] + t, 0: xy[0] + l, 1: xy[1] + t, width: w - (l + r), height: h - (t + b)};
		}
		bx.right = bx.x + bx.width;
		bx.bottom = bx.y + bx.height;

		return bx;
	},

	getComputedHeight: function(element)
	{
		var h = Math.max(element.offsetHeight, element.clientHeight);
		if (!h) {
			h = parseInt(element.getStyle('height'), 10) || 0;
			if (!element.isBorderBox()) {
				h += element.getFrameWidth('tb');
			}
		}

		return h;
	},

	getComputedWidth: function(element)
	{
		var w = Math.max(element.offsetWidth, element.clientWidth);
		if (!w) {
			w = parseInt(element.getStyle('width'), 10) || 0;
			if (!element.isBorderBox()) w += element.getFrameWidth('lr');
		}

		return w;
	},

	getContentHeight: function(element)
	{
		var prev = null;

		return $A(element.cleanWhitespace().childNodes).inject(0, function(value, child, index)
		{
			if (child.nodeType != 1) {
				if (index == 0) prev = child;
				return value; // nur element nodes
			}

			child = $(child);

			if (prev) {
				value += child.offsetTop - element.offsetTop;
				prev = null;
			}

			return value + child.getHeight() + child.getMargins("tb");
		});
	},

	getContentWidth: function(element)
	{
		return $A(element.cleanWhitespace().childNodes).inject(0, function(value, child)
		{
			if (child.nodeType != 1) return value; // nur element nodes
			child = $(child);
			return value + child.getWidth() + child.getMargins("lr");
		});
	},

	getFrameWidth: function(element, sides, onlyContentBox)
	{
		return onlyContentBox && Element.isBorderBox ? 0 : (element.getPadding(sides) + element.getBorderWidth(sides));
	},

	getHeight: function(element, contentHeight)
	{
		var h = element.offsetHeight || 0;
		h = contentHeight !== true ? h : h - element.getBorderWidth("tb") - element.getPadding("tb");

		return h < 0 ? 0 : h;
	},

	getMargins: function(element, side)
	{
		if (!side){
			return {
				top:	parseInt(element.getStyle("margin-top"), 10) || 0,
				left:	parseInt(element.getStyle("margin-left"), 10) || 0,
				bottom:	parseInt(element.getStyle("margin-bottom"), 10) || 0,
				right:	parseInt(element.getStyle("margin-right"), 10) || 0
			};
		} else {
			return element.addStyles(side, Element.margins);
		}
	},

	getPadding: function(element, side)
	{
		return element.addStyles(side, Element.paddings);
	},

	getParents: function(element)
	{
		var result = [];

		while (element != document.body) {
			result.push($(element.parentNode));
			element = element.parentNode;
		}

		return $A(result);
	},

	getRight: function(element)
	{
		return element.getX() + element.getWidth();
	},

	getScroll: function(element)
	{
		var d = element, doc = document;
		if (d == doc || d == doc.body){
			var l, t;
			if (Prototype.Browser.isIE && Prototype.Browser.isStrict) {
				l = doc.documentElement.scrollLeft || (doc.body.scrollLeft || 0);
				t = doc.documentElement.scrollTop || (doc.body.scrollTop || 0);
			} else {
				l = window.pageXOffset || (doc.body.scrollLeft || 0);
				t = window.pageYOffset || (doc.body.scrollTop || 0);
			}
			return {left: l, top: t};
		} else {
			return {left: d.scrollLeft, top: d.scrollTop};
		}
	},

	getSize: function(element, contentSize)
	{
		return {width: element.getWidth(contentSize), height: element.getHeight(contentSize)};
	},

	getWidth: function(element, contentWidth)
	{
		var w = element.offsetWidth || 0;
		w = contentWidth !== true ? w : w - element.getBorderWidth("lr") - element.getPadding("lr");

		return w < 0 ? 0 : w;
	},

	getX: function(element)
	{
		return element.getXY()[0];
	},

	getXY: function(element)
	{
		var F,K,M,N,J = (document.body || document.documentElement);

		if (element == J) {
			return [0, 0];
		}

		if (element.getBoundingClientRect) {
			M = element.getBoundingClientRect();
			N = $(document.body).getScroll();
			return [M.left + N.left, M.top + N.top];
		}

		var O = 0, L = 0; F = element;
		var E = element.getStyle("position") == "absolute";

		while (F) {
			$(F);
			O += F.offsetLeft;
			L += F.offsetTop;
			if (!E && F.getStyle("position") == "absolute") { E = true; }
			if (Prototype.Browser.isGecko) {
				K = F;
				var P = parseInt(K.getStyle("borderTopWidth"), 10) || 0;
				var H = parseInt(K.getStyle("borderLeftWidth"), 10) || 0;
				O += H;
				L += P;
				if ( F != element && K.getStyle("overflow") != "visible") {
					O += H;
					L += P;
				}
			}
			F = F.offsetParent;
		}

		if (Prototype.Browser.isSafari && E) {
			O -= J.offsetLeft;
			L -= J.offsetTop
		}
		if (Prototype.Browser.isGecko && !E) {
			var I = $(J);
			O += parseInt(I.getStyle("borderLeftWidth"), 10) || 0;
			L += parseInt(I.getStyle("borderTopWidth"), 10) || 0;
		}
		F = element.parentNode;

		while (F && F != J) {
			if (!Prototype.Browser.isOpera || (F.tagName != "TR" && $(F).getStyle("display") != "inline")) {
				O -= F.scrollLeft;
				L -= F.scrollTop;
			}
			F = F.parentNode;
		}

		return [O, L];
	},

	getY: function(element)
	{
		return element.getXY()[1];
	},

	hide: function(element)
	{
		if (Object.isString(element)) element = $(element);
		var mode = (typeof element._displayMode == "undefined" ? (element.style["visibility"] ? "visibility" : "display" ) : element._displayMode);

		if (mode == Element.VISIBLE) element.setStyle({visibility: "hidden"});
		else element.setStyle({display: "none"});

		if (element.tagName.toLowerCase() == "input" && element.type == "submit") {
			element._hideDisabled = element.disabled;
			element.disable();
		}

		return element;
	},

	highlightError: function(element)
	{
		element = $(element);
		if (element && !Object.isUndefined(window.Scriptaculous))
		{
			return element.highlight(
			{
				duration:	2.0,
				startcolor:	"#FF5050",
				endcolor:	"#FFFFFF"
			});
		}

		return element;
	},

	insertAfter: function(element, content)
	{
		Element.insert(element, { after:content });
		return element;
	},

	insertBottom: function(element, content)
	{
		Element.insert(element, { bottom:content });
		return element;
	},

	insertTop: function(element, content)
	{
		Element.insert(element, { top:content });
		return element;
	},

	isBorderBox: function(element)
	{
		return Element.noBoxAdjust[element.tagName.toLowerCase()] || Element.isBorderBox;
	},

	isDisplayed: function(element)
	{
		return (element.getStyle("display") != "none");
	},

	isVisible: function(element)
	{
		return (element.getStyle("visibility") != "hidden");
	},

	on: function(element, eventName, handler, scope)
	{
		if (typeof eventName == "object")		Object.keys(eventName).each(function(key)
		{
			element.on(key, Object.isFunction(eventName[key]) ? eventName[key] : eventName[key].fn, !Object.isFunction(eventName[key]) ? eventName[key].scope : undefined);
		});
		else if (typeof scope == "undefined")	Event.observe(element, eventName, handler);
		else									Event.observe(element, eventName, handler.bindAsEventListener(scope));
		return element;
	},

	parent: function(element)
	{
		if (!element.parentNode) return null;

		return $(element.parentNode);
	},

	position: function(element, pos, zIndex, x, y)
	{
		if (!pos) {
		   if (element.getStyle('position') == 'static'){ element.setStyle('position', 'relative'); }
		} else {
			element.setStyle("position", pos);
		}

		if (zIndex){element.setStyle("z-index", zIndex);}
		if (x !== undefined && y !== undefined){element.setXY([x, y]);}
		else if (x !== undefined){element.setX(x);}
		else if (y !== undefined){element.setY(y);}

		return element;
	},

	removeClass: function(element, className)
	{
		if (Object.isString(className))
		{
			className = $w(className);
		}
		className.each(function(classNames)
		{
			element.removeClassName(classNames);
		});
		return element;
	},

	removeChildrens: function(element)
	{
		var childs = element.childElements();

		element.innerHTML = "";

		return childs;
	},

	set: function(element, attrib)
	{
		return element.writeAttribute(attrib);
	},

	setBottom: function(element, bottom)
	{
		return element.setHeight(bottom - element.getY());
	},

 	setBox: function(element, box)
	{
		return element.setSize(box.width, box.height).setXY([box.x, box.y]);
	},

	setHeight: function(element, height)
	{
		element.style.height = Element.addUnits(Element.adjustHeight(height));
		return element;
	},

	setLeft: function(element, left)
	{
		return element.setStyle("left", Element.addUnits(left));
	},

 	setRight: function(element, right)
	{
		return element.setWidth(right - element.getX());
	},

	setSize: function(element, width, height)
	{
		if (typeof width == "object") {
			height = width.height;
			width = width.width;
		}
		width = Element.adjustWidth(width);
		height = Element.adjustHeight(height);
		element.style.width = Element.addUnits(width);
		element.style.height = Element.addUnits(height);
		return element;
	},

	setTop: function(element, top)
	{
		return element.setStyle("top", Element.addUnits(top));
	},

	setVisible: function(element, visible)
	{
		return element.setStyle({visibility: (visible ? "visible": "hidden")});
	},

	setWidth: function(element, width)
	{
		element.style.width = Element.addUnits(Element.adjustWidth(width));
		return element;
	},

	setX: function(element, x)
	{
		return element.setXY([x, false]);
	},

	setXY: function(element, xy)
	{
		element.position();
		var G = element.translatePoints(xy);
		if (xy[0] !== false){element.style.left = Element.addUnits(G.left);}
		if (xy[1] !== false){element.style.top = Element.addUnits(G.top);}
		return element;
	},

	setY: function(element, y)
	{
		return element.setXY([false, y]);
	},

	show: function(element)
	{
		if (Object.isString(element)) element = $(element);
		var mode = (typeof element._displayMode == "undefined" ? (element.style["visibility"] ? "visibility" : "display" ) : element._displayMode);

		if (mode == Element.VISIBLE) element.setStyle({visibility: "visible"});
		else element.clearStyle("display");

		if (element.tagName.toLowerCase() == "input" && element.type == "submit" && typeof element._hideDisabled != "undefined") {
			if (element._hideDisabled)	element.disable();
			else						element.enable();
			element._hideDisabled = undefined;
		}

		return element;
	},

	/**
	 * wechselt die class names bei den Child elements von A nach B und respektiv umgekehrt
	 **/
	swapChildsCls: function(element, clsA, clsB)
	{
		var elementsA = element.select("." + clsA);
		var elementsB = element.select("." + clsB);

		elementsA.invoke("removeClass", clsA).invoke("addClass", clsB);
		elementsB.invoke("removeClass", clsB).invoke("addClass", clsA);
	},

	toggleDisplayed: function(element, parents)
	{
		if (arguments.length <= 1)
		{
			parents = element.recursivelyCollect('parentNode').findAll(function(parent) { return parent.getStyle("display") == "none"; });
			if (element.getStyle("display") == "none") parents.push(element);
			parents.each(function(parent)
			{
				var style = parent.readAttribute("style");
				parent._toggleDisplayed = (style != null && style.indexOf("display") != -1 ? parent.getStyle("display") : "");
				parent.show();
			});

			return parents;

		}
		else
		{
			parents.each(function(parent)
			{
				if (typeof parent._toggleDisplayed == "undefined") parent.hide();
				else parent.setStyle({display: parent._toggleDisplayed});
			});
//			parents.invoke("hide");
		}
	},

	translatePoints: function(element, x, y)
	{
		if (Object.isArray(x)) {
			y = x[1];
			x = x[0];
		} else if (typeof x == 'object') {
			y = x.y;
			x = x.x;
		}
		var p = element.getStyle('position');
		var o = element.getXY();

		var l = parseInt(element.getStyle('left'), 10);
		var t = parseInt(element.getStyle('top'), 10);

		if (isNaN(l)){l = (p == "relative") ? 0 : element.offsetLeft;}
		if (isNaN(t)){t = (p == "relative") ? 0 : element.offsetTop;}

		return {left: (x - o[0] + l), top: (y - o[1] + t)};
	},

	un: function(element, eventName, handler)
	{
		Event.stopObserving(element, eventName, handler);
	}
});

Object.extend(String.prototype, {
	applyTo: function(element)
	{
		element = $(element);
		if (!element) return element;
		element.innerHTML = "";
		Element.insert(element, { bottom:this });
		return element;
	},

	br2nl: function()
	{
		return this.replace(/[\r]|[\n]/g, '').replace(/<br*\s?\/?>/gi, '\n');
	},

	hex: function()
	{
		var str = "";
		for (var i = 0; i < this.length; i++)
			str = str + this.charCodeAt(i).hex();

		return str;
	},

	insertAfter: function(element)
	{
		Element.insert(element, { after:this });
		return content;
	},

	/**
	 * Prüft ob der zuprüfende Wert (String) einem korrekten Email-Format entspricht
	 */
	isEmail: (function()
	{
		var regExpression = new RegExp('^[_\.0-9a-zA-Z\-]+\@([_\.0-9a-zA-Z\-]+[\.]{1})+[a-zA-Z]{2,4}$');

		return function()
		{
			return regExpression.test(this);
		}
	})(),

	/**
	 * Prüft ob der zuprüfende Wert (string) vom Typ Integer ist
	 */
	isInt: function()
	{
		var intValue = parseInt(this);

		if(isNaN(intValue))
		{
			return false;
		}

		strValue = intValue.toString();
		if(this != strValue)
		{
			return false;
		}

		return true;
	},

	isNumber: function(decPoint, thousandsSep)
	{
		if (typeof decPoint == "undefined") decPoint = ".";
		if (typeof thousandsSep == "undefined") thousandsSep = ",";

		var regex = new RegExp("^[0-9]*([" + String.fromCharCode(92) + thousandsSep + "]{1}[0-9]{3})*[" + decPoint + "]{0,1}[0-9]*$");
		if(!regex.test(this)) return false;
		return !isNaN(Number(this.replace(eval('/' + String.fromCharCode(92) + thousandsSep + '/g'), "").replace(decPoint, ".")));
	},

	nl2br: function()
	{
		return this.replace(/\n/g, '<br />');
	},

	toNumber: function(decPoint, thousandsSep)
	{
		if (typeof decPoint == "undefined") decPoint = ".";
		if (typeof thousandsSep == "undefined") thousandsSep = ",";
		return Number(this.replace(eval('/' + String.fromCharCode(92) + thousandsSep + '/g'), "").replace(decPoint, ".").replace(/[^0-9\-\.]/g, ""));
	}
});

Object.extend(String,
{
	/**
     * Escapes the passed string for ' and \
     * @param {String} string The string to escape
     * @return {String} The escaped string
     * @static
     */
    escape : function(string)
    {
        return string.replace(/('|\\)/g, String.fromCharCode(92) + "$1" ); //'
    },

    /**
     * Allows you to define a tokenized string and pass an arbitrary number of arguments to replace the tokens.  Each
     * token must be unique, and must increment in the format {0}, {1}, etc.  Example usage:
     * <pre><code>
	 *		var cls = 'my-class', text = 'Some text';
	 *		var s = String.format('<div class="{0}">{1}</div>', cls, text);
	 *		// s now contains the string: '<div class="my-class">Some text</div>'
	 *		</code></pre>
     * @param {String} string The tokenized string to be formatted
     * @param {String} value1 The value to replace token {0}
     * @param {String} value2 Etc...
     * @return {String} The formatted string
     * @static
     */
    format : function(format)
    {
        var args = Array.prototype.slice.call(arguments, 1);
        return format.replace(/\{(\d+)\}/g, function(m, i)
        {
            return args[i];
        });
    },

    /**
     * Pads the left side of a string with a specified character.  This is especially useful
     * for normalizing number and date strings.  Example usage:
     * <pre><code>
	 *		var s = String.leftPad('123', 5, '0');
	 *		// s now contains the string: '00123'
	 *		</code></pre>
     * @param {String} string The original string
     * @param {Number} size The total length of the output string
     * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
     * @return {String} The padded string
     * @static
     */
    leftPad : function (val, size, ch)
    {
        var result = new String(val);
        if(!ch) ch = " ";
        while (result.length < size) result = ch + result;
        return result.toString();
    }
});

/**
 * Utility function that allows you to easily switch a string between two alternating values.  The passed value
 * is compared to the current string, and if they are equal, the other value that was passed in is returned.  If
 * they are already different, the first value passed in is returned.  Note that this method returns the new value
 * but does not change the current string.
 * <pre><code>
// alternate sort directions
sort = sort.toggle('ASC', 'DESC');

// instead of conditional logic:
sort = (sort == 'ASC' ? 'DESC' : 'ASC');
</code></pre>
 * @param {String} value The value to compare to the current string
 * @param {String} other The new value to use if the string already equals the first value passed in
 * @return {String} The new value
 */
String.prototype.toggle = function(value, other)
{
    return this == value ? other : value;
};

/**
 * Trims whitespace from either end of a string, leaving spaces within the string intact.  Example:
 * <pre><code>
var s = '  foo bar  ';
alert('-' + s + '-');         //alerts "- foo bar -"
alert('-' + s.trim() + '-');  //alerts "-foo bar-"
</code></pre>
 * @return {String} The trimmed string
 */
String.prototype.trim = function()
{
    var re = /^[\s\n\r]+|[\s\n\r]+$/g;
    return function(){ return this.replace(re, ""); };
}();

String.prototype.evalScripts = function()
{
	// korrektur von Extract Scripts
    return this.extractScripts().map(
    	function(script)
    	{
    		// remove leading char(9) and char(32)
    		script = script.strip();

    		// deletes <!-- and -->
    		if (script.substr(0, 4) == "<!--"){ script = script.substr(4, script.length - 4 - 3);}
    		// deletes <![CDATA[ and ]]>
    		else if( script.substr(0, 9) == "<![CDATA["){ script = script.substr(9, script.length - 9 - 3);}

    		return eval(script)
    	}
    );
};

Template.addMethods({
	append: function(element, options)
	{
		Element.insert(element, { bottom: this.evaluate(options)});
		element.cleanWhitespace();
		return $(element.childNodes[element.childNodes.length - 1]).cleanWhitespace();
	},

	insertAfter: function(element, options)
	{
		Element.insert(element, { after: this.evaluate(options)});
		element.cleanWhitespace();
		return $(element.nextSibling).cleanWhitespace();
	},

	insertBefore: function(element, options)
	{
		Element.insert(element, { before: this.evaluate(options)});
		element.cleanWhitespace();
		return $(element.previousSibling).cleanWhitespace();
	},

	insertFirst: function(element, options)
	{
		Element.insert(element, { top: this.evaluate(options)});
		element.cleanWhitespace();
		return $(element.firstCild).cleanWhitespace();
	},

	overwrite: function(element, options)
	{
		element.innerHTML = this.evaluate(options);
		element.cleanWhitespace();
		return $(element.firstChild).cleanWhitespace();
	}
});

Object.extend(Number.prototype, {
	between: function(min, max, exclusive)
	{
		if (min > max) {
			var s = min;
			min = max;
			max = s;
		}

		exclusive = exclusive || false;

		if (exclusive) return min < this && this < max;
		return min <= this && this <= max;
	},

	hex: function()
	{
		var hex = this.toString(16);

		return String.leftPad(hex, Math.ceil(hex.length / 2) * 2, "0");
	},

	numberFormat: function (decimals, dec_point, thousands_sep)
	{
		var number = this;
		var exponent = "";
		var numberstr = number.toString ();
		var eindex = numberstr.indexOf ("e");

		if (typeof decimals == "undefined"){decimals = 0;}
		if (typeof dec_point == "undefined"){dec_point = ",";}
		if (typeof thousands_sep == "undefined"){thousands_sep = ".";}

		if (eindex > -1) {
			exponent = numberstr.substring (eindex);
			number = parseFloat (numberstr.substring (0, eindex));
		}

		if (decimals != null){
			var temp = Math.pow (10, decimals);
			number = Math.round (number * temp) / temp;
		}
		var sign = number < 0 ? "-" : "";
		var integer = (number > 0 ? Math.floor (number) : Math.abs (Math.ceil (number))).toString();

		var fractional = number.toString().substring (integer.length + sign.length);
		dec_point = dec_point != null ? dec_point : ".";
		fractional = decimals != null && decimals > 0 || fractional.length > 1 ? (dec_point + fractional.substring (1)) : "";

		if (decimals != null && decimals > 0) {
			for (i = fractional.length - 1, z = decimals; i < z; ++i) { fractional += "0"; }
		}

		thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ? thousands_sep : null;
		if (thousands_sep != null && thousands_sep != "") {
			for (i = integer.length - 3; i > 0; i -= 3) { integer = integer.substring (0 , i) + thousands_sep + integer.substring (i); }
		}

		return sign + integer + fractional + exponent;
	},

	randMin: function( max )
	{
		var min		= this;
		var div		= (max - min) + 1;
		var randNum	= Math.random();

		for( var i = 0; i <= div - 1; i++ )
			if ( randNum >= i / div && randNum < (i + 1) / div )
		    	return i + min;

    	return min;
	},

	randMax: function( min )
	{
		return min.randMin( this );
	},

	timeString: function(isMilliseconds)
	{
		var time = this;
		var relMil		= 0;
		var relMin		= 0;
		var relSec		= 0;
		var relHour		= 0;
		var relDay		= "";
		var timNeg		= "";

		if (typeof isMilliseconds == "undefined") isMilliseconds = false;
		if (!isMilliseconds) time = time * 1000;

		if (time < 0) {
			timNeg = "-";
			time = Math.abs(time);
		}

		relMil		= time;

		relSec		= Math.floor(relMil / 1000);
		relMil		= relMil - (relSec * 1000);

		relMin		= Math.floor(relSec / 60);
		relSec		= relSec - (relMin * 60);

		relHour		= Math.floor(relMin / 60);
		relMin		= relMin - (relHour * 60);

		 if (relHour > 23) {
			relDay	= Math.floor(relHour / 24);
			relHour	= relHour - relDay * 24;

			relHour	= relHour.toPaddedString(2);
			relDay	= relDay + "d ";
		}

		return (timNeg + relDay + relHour + ":" + relMin.toPaddedString(2) + ":" + relSec.toPaddedString(2));

	}
});

document.getCSSRule = function(selector)
{
	for (var i = 0; i < this.styleSheets.length; i++)
	{
		var obj = (Prototype.Browser.isIE ? this.styleSheets[i].rules : this.styleSheets[i].cssRules);
		var result = $A(obj).find(function(rule){return (rule.selectorText == selector);});
		if (result) return result;
	}
};

document.createCSSRule = function(selector, declaration)
{
    // create the style node for all browsers
    var style_node = document.createElement("style");
    style_node.setAttribute("type", "text/css");
    style_node.setAttribute("media", "screen");

    if (!Object.isString(declaration))
    	declaration = Object.keys(declaration).inject('', function(decl, key) { return decl + key.underscore().dasherize() + ":" + declaration[key]; });

    // append a rule for good browsers
    if (!Prototype.Browser.isIE)
    	style_node.appendChild(document.createTextNode(selector + " {" + declaration + "}"));

    // append the style node
    document.getElementsByTagName("head")[0].appendChild(style_node);

    // use alternative methods for IE
    if (Prototype.Browser.isIE && document.styleSheets && document.styleSheets.length > 0) {
		var last_style_node = document.styleSheets[document.styleSheets.length - 1];
		if (typeof(last_style_node.addRule) == "object") last_style_node.addRule(selector, declaration);
    }
};

document.createCSSDeclaration = function(declaration)
{
	declaration.replace(/[\n\r]/gi , '').split("}").each(function(decl)
	{
		decl = decl.split("{");
		if (decl.length < 2 || decl[0].trim() == 0 || decl[1].trim() == 0) return;
		document.createCSSRule(decl[0].trim(), decl[1].trim());
	});
};

/**
 * create form
 **/
window.createForm = document.form = function(method, submit, url, parameters)
{
	if (submit && Object.keys(parameters).length == 0)
	{
		window.location.href = 	url;
		return;
	}

	var form = document.createElement("FORM");
	form.action = url;
	form.method = method;
	document.body.appendChild(form);

	Object.keys(parameters).each(function(key)
	{
		if (Object.isArray(parameters[key]))
		{
			parameters[key].each(function(item)
			{
				var input = document.createElement("input");
				input.type = "hidden";
				input.name = key;
				input.value = item;
				form.appendChild(input);
			});
		}
		else
		{
			var input = document.createElement("input");
			input.type = "hidden";
			input.name = key;
			input.value = parameters[key];
			form.appendChild(input);
		}
	});

	if (submit)
	{
		return form.submit();
	}
	return form;
};
window.post = document.post = window.createForm.curry("post", true);
window.get = document.get = window.createForm.curry("get", true);

/*
 * Ext JS Library 2.0.1
 * Copyright(c) 2006-2007, Ext JS, LLC.
 * licensing@extjs.com
 *
 * http://extjs.com/license
 */

/**
 * @class Date
 *
 * The date parsing and format syntax is a subset of
 * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
 * supported will provide results equivalent to their PHP versions.
 *
 * The following is a list of all currently supported formats:
 *<pre>
Format  Description                                                               Example returned values
------  -----------------------------------------------------------------------   -----------------------
  d     Day of the month, 2 digits with leading zeros                             01 to 31
  D     A short textual representation of the day of the week                     Mon to Sun
  j     Day of the month without leading zeros                                    1 to 31
  l     A full textual representation of the day of the week                      Sunday to Saturday
  N     ISO-8601 numeric representation of the day of the week                    1 (for Monday) through 7 (for Sunday)
  S     English ordinal suffix for the day of the month, 2 characters             st, nd, rd or th. Works well with j
  w     Numeric representation of the day of the week                             0 (for Sunday) to 6 (for Saturday)
  z     The day of the year (starting from 0)                                     0 to 364 (365 in leap years)
  W     ISO-8601 week number of year, weeks starting on Monday                    01 to 53
  F     A full textual representation of a month, such as January or March        January to December
  m     Numeric representation of a month, with leading zeros                     01 to 12
  M     A short textual representation of a month                                 Jan to Dec
  n     Numeric representation of a month, without leading zeros                  1 to 12
  t     Number of days in the given month                                         28 to 31
  L     Whether it's a leap year                                                  1 if it is a leap year, 0 otherwise.
  o     ISO-8601 year number (identical to (Y), but if the ISO week number (W)    Examples: 1998 or 2004
        belongs to the previous or next year, that year is used instead)
  Y     A full numeric representation of a year, 4 digits                         Examples: 1999 or 2003
  y     A two digit representation of a year                                      Examples: 99 or 03
  a     Lowercase Ante meridiem and Post meridiem                                 am or pm
  A     Uppercase Ante meridiem and Post meridiem                                 AM or PM
  g     12-hour format of an hour without leading zeros                           1 to 12
  G     24-hour format of an hour without leading zeros                           0 to 23
  h     12-hour format of an hour with leading zeros                              01 to 12
  H     24-hour format of an hour with leading zeros                              00 to 23
  i     Minutes, with leading zeros                                               00 to 59
  s     Seconds, with leading zeros                                               00 to 59
  u     Milliseconds, with leading zeros                                          001 to 999
  O     Difference to Greenwich time (GMT) in hours and minutes                   Example: +1030
  P     Difference to Greenwich time (GMT) with colon between hours and minutes   Example: -08:00
  T     Timezone abbreviation of the machine running the code                     Examples: EST, MDT, PDT ...
  Z     Timezone offset in seconds (negative if west of UTC, positive if east)    -43200 to 50400
  c     ISO 8601 date                                                             2007-04-17T15:19:21+08:00
  U     Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)                1193432466 or -2138434463
</pre>
 *
 * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
 * <pre><code>
// Sample date:
// 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'

var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
document.write(dt.format('Y-m-d'));                         // 2007-01-10
document.write(dt.format('F j, Y, g:i a'));                 // January 10, 2007, 3:05 pm
document.write(dt.format('l, \\t\\he jS of F Y h:i:s A'));  // Wednesday, the 10th of January 2007 03:05:01 PM
 </code></pre>
 *
 * Here are some standard date/time patterns that you might find helpful.  They
 * are not part of the source of Date.js, but to use them you can simply copy this
 * block of code into any script that is included after Date.js and they will also become
 * globally available on the Date object.  Feel free to add or remove patterns as needed in your code.
 * <pre><code>
Date.patterns = {
    German: "d.m.Y",
    ISO8601Long:"Y-m-d H:i:s",
    ISO8601Short:"Y-m-d",
    ShortDate: "n/j/Y",
    LongDate: "l, F d, Y",
    FullDateTime: "l, F d, Y g:i:s A",
    MonthDay: "F d",
    ShortTime: "g:i A",
    LongTime: "g:i:s A",
    SortableDateTime: "Y-m-d\\TH:i:s",
    UniversalSortableDateTime: "Y-m-d H:i:sO",
    YearMonth: "F, Y"
};
</code></pre>
 *
 * Example usage:
 * <pre><code>
var dt = new Date();
document.write(dt.format(Date.patterns.ShortDate));
 </code></pre>
 */

/*
 * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
 * They generate precompiled functions from date formats instead of parsing and
 * processing the pattern every time you format a date.  These functions are available
 * on every Date object (any javascript function).
 *
 * The original article and download are here:
 * http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
 *
 */

Date.patterns = {
//    ISO8601Long:"Y-m-d H:i:s",
//    ISO8601Short:"Y-m-d",
//    ShortDate: "n/j/Y",
//    LongDate: "l, F d, Y",
//    FullDateTime: "l, F d, Y g:i:s A",
//    MonthDay: "F d",
//    ShortTime: "g:i A",
//    LongTime: "g:i:s A",
//    SortableDateTime: "Y-m-d\\TH:i:s",
//    UniversalSortableDateTime: "Y-m-d H:i:sO",
//    YearMonth: "F, Y"
};
// private
Date.parseFunctions = {count:0};
// private
Date.parseRegexes = [];
// private
Date.formatFunctions = {count:0};

// private
Date.prototype.dateFormat = function(format)
{
    if (Date.formatFunctions[format] == null) Date.createNewFormat(format);
    return this[Date.formatFunctions[format]]();
};

/**
 * Formats a date given the supplied format string.
 * @param {String} format The format string.
 * @return {String} The formatted date.
 * @method
 */
Date.prototype.format = Date.prototype.dateFormat;

// private
Date.createNewFormat = function(format)
{
    var funcName = "format" + Date.formatFunctions.count++;
    var code = "Date.prototype." + funcName + " = function(){return ";
    var special = false;
    var ch = '';

    Date.formatFunctions[format] = funcName;
    for (var i = 0; i < format.length; ++i) {
        ch = format.charAt(i);

        if (!special && ch == String.fromCharCode(92))
            special = true;

        else if (special) {
            special = false;
            code += "'" + String.escape(ch) + "' + ";

        } else
            code += Date.getFormatCode(ch);
    }
    eval(code.substring(0, code.length - 3) + ";}");
};

// private
Date.getFormatCode = function(character)
{
    switch (character) {
    case "d":
        return "String.leftPad(this.getDate(), 2, '0') + ";
    case "D":
        return "Date.getShortDayName(this.getDay()) + "; // get L10n short day name
    case "j":
        return "this.getDate() + ";
    case "l":
        return "Date.dayNames[this.getDay()] + ";
    case "N":
        return "(this.getDay() ? this.getDay() : 7) + ";
    case "S":
        return "this.getSuffix() + ";
    case "w":
        return "this.getDay() + ";
    case "z":
        return "this.getDayOfYear() + ";
    case "W":
        return "String.leftPad(this.getWeekOfYear(), 2, '0') + ";
    case "F":
        return "Date.monthNames[this.getMonth()] + ";
    case "m":
        return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
    case "M":
        return "Date.getShortMonthName(this.getMonth()) + "; // get L10n short month name
    case "n":
        return "(this.getMonth() + 1) + ";
    case "t":
        return "this.getDaysInMonth() + ";
    case "L":
        return "(this.isLeapYear() ? 1 : 0) + ";
    case "o":
        return "(this.getFullYear() + (this.getWeekOfYear() == 1 && this.getMonth() > 0 ? +1 : (this.getWeekOfYear() >= 52 && this.getMonth() < 11 ? -1 : 0))) + ";
    case "Y":
        return "this.getFullYear() + ";
    case "y":
        return "('' + this.getFullYear()).substring(2, 4) + ";
    case "a":
        return "(this.getHours() < 12 ? 'am' : 'pm') + ";
    case "A":
        return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
    case "g":
        return "((this.getHours() % 12) ? this.getHours() % 12 : 12) + ";
    case "G":
        return "this.getHours() + ";
    case "h":
        return "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0') + ";
    case "H":
        return "String.leftPad(this.getHours(), 2, '0') + ";
    case "i":
        return "String.leftPad(this.getMinutes(), 2, '0') + ";
    case "s":
        return "String.leftPad(this.getSeconds(), 2, '0') + ";
    case "u":
        return "String.leftPad(this.getMilliseconds(), 3, '0') + ";
    case "O":
        return "this.getGMTOffset() + ";
    case "P":
        return "this.getGMTOffset(true) + ";
    case "T":
        return "this.getTimezone() + ";
    case "Z":
        return "(this.getTimezoneOffset() * -60) + ";
    case "c":
        for (var df = Date.getFormatCode, c = "Y-m-dTH:i:sP", code = "", i = 0, l = c.length; i < l; ++i) {
          var e = c.charAt(i);
          code += e == "T" ? "'T' + " : df(e); // treat T as a literal
        }
        return code;
    case "U":
        return "Math.round(this.getTime() / 1000) + ";
    default:
        return "'" + String.escape(character) + "' + ";
    }
};

/**
 * Parses the passed string using the specified format. Note that this function expects dates in normal calendar
 * format, meaning that months are 1-based (1 = January) and not zero-based like in JavaScript dates.  Any part of
 * the date format that is not specified will default to the current date value for that part.  Time parts can also
 * be specified, but default to 0.  Keep in mind that the input date string must precisely match the specified format
 * string or the parse operation will fail.
 * Example Usage:
<pre><code>
//dt = Fri May 25 2007 (current date)
var dt = new Date();

//dt = Thu May 25 2006 (today's month/day in 2006)
dt = Date.parseDate("2006", "Y");

//dt = Sun Jan 15 2006 (all date parts specified)
dt = Date.parseDate("2006-01-15", "Y-m-d");

//dt = Sun Jan 15 2006 15:20:01 GMT-0600 (CST)
dt = Date.parseDate("2006-01-15 3:20:01 PM", "Y-m-d h:i:s A" );
</code></pre>
 * @param {String} input The unparsed date as a string.
 * @param {String} format The format the date is in.
 * @return {Date} The parsed date.
 * @static
 */
Date.parseDate = function(input, format)
{
    if (Date.parseFunctions[format] == null) {
        Date.createParser(format);
    }
    var func = Date.parseFunctions[format];
    return Date[func](input);
};
Date.parseDate = Date.parseDate.wrap(function(proceed, input, format)
{
	var result;

	// millisekunden cutten
	if (typeof input == "string" && input.lastIndexOf(":") != -1 && input.lastIndexOf(":") < input.lastIndexOf("."))
		input = input.substr(0, input.lastIndexOf("."));

	if (Object.isUndefined(format)) {
		if (input == "")						return new Date(0);
		else if (!input.charAt().isNumber())	return new Date(input.charCodeAt());

		Object.keys(Date.patterns).find(function(patternKey)
		{
			var resultOne;
			try {
				resultOne = proceed(input, Date.patterns[patternKey]);
			} catch(e) {
				return false;
			}
			if (!resultOne) return false;
			result = resultOne;
			return true;
		});
		if (!result) result = new Date(0);
	} else
		result = proceed(input, format);

	return result;
});

/**
 * liefert die Datumskomponenten die in input enthalten sind
 * nichtenthaltende Komponenten sind undefined
 *
 * @param string input
 * @param string format (optional)
 * @access public
 * @return object
 **/
Date.componentDate = function(input, format)
{
	var result;

	if (Object.isUndefined(format)) {
		if (input == "")						return {};
		else if (!input.charAt().isNumber())	return {};

		Object.keys(Date.patterns).find(function(patternKey)
		{
			var resultOne;
			try {
				resultOne = Date.componentDate(input, Date.patterns[patternKey]);
			} catch(e) {
				return false;
			}
			if (!resultOne) return false;
			result = resultOne;
			return true;
		});
		if (!result) result = {};

	} else {
		if (Date.parseFunctions[format] == null) {
	        Date.createParser(format);
	    }

	    result = Date[Date.parseFunctions[format]](input, true);
	}

	return result;
};

/**
 * prüft ein Datum auf gültigkeit
 **/
Date.isValid = function(input, format)
{
	var date	= Date.parseDate(input, format);
	var comp	= Date.componentDate(input, format);

	if 		(Object.isUndefined(comp)) return false;
	if		(comp.year			&& date.getFullYear() != comp.year) return false;
	else if (comp.month			&& date.getMonth() + 1 != comp.month) return false;
	else if (comp.day			&& date.getDate() != comp.day) return false;
	else if (comp.hours			&& date.getHours() != comp.hours) return false;
	else if (comp.minutes		&& date.getMinutes() != comp.minutes) return false;
	else if (comp.secounds		&& date.getSeconds() != comp.secounds) return false;
	else if (comp.millisecounds	&& date.getMilliseconds() != comp.millisecounds) return false;

	return true;
};

// private
Date.createParser = function(format)
{
    var funcName = "parse" + Date.parseFunctions.count++;
    var regexNum = Date.parseRegexes.length;
    var currentGroup = 1;
    Date.parseFunctions[format] = funcName;
    Date.patterns[format] = format;

    var code = "Date." + funcName + " = function(input, values){\n"
        + "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, ms = -1, o, z, u, v;\n"
        + "var d = new Date();\n"
        + "y = d.getFullYear();\n"
        + "m = d.getMonth();\n"
        + "d = d.getDate();\n"
        + "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
        + "if (results && results.length > 0) {";
    var regex = "";

    var special = false;
    var ch = '';
    for (var i = 0; i < format.length; ++i) {
        ch = format.charAt(i);
        if (!special && ch == String.fromCharCode(92)) {
            special = true;
        }
        else if (special) {
            special = false;
            regex += String.escape(ch);
        }
        else {
            var obj = Date.formatCodeToRegex(ch, currentGroup);
            currentGroup += obj.g;
            regex += obj.s;
            if (obj.g && obj.c) {
                code += obj.c;
            }
        }
    }

    code += "if (values) return "
    		+ "{"
				+ "year: (y != -1 ? y : undefined),"
    			+ "month: (m != -1 ? m + 1 : undefined),"
    			+ "day: (d != -1 ? d : undefined),"
    			+ "hours: (h != -1 ? h : undefined),"
    			+ "minutes: (i != -1 ? i : undefined),"
    			+ "secounds: (s != -1 ? s : undefined),"
    			+ "millisecounds: (ms != -1 ? ms : undefined)"
    		+ "};"

    		+ "if (u)\n"
	        	+ "{v = new Date(u * 1000);}" // give top priority to UNIX time

	        + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0 && ms >= 0)\n"
	        	+ "{v = new Date(y, m, d, h, i, s, ms);}\n"

	        + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
	        	+ "{v = new Date(y, m, d, h, i, s);}\n"

	        + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
	        	+ "{v = new Date(y, m, d, h, i);}\n"

	        + "else if (y >= 0 && m >= 0 && d > 0 && h >= 0)\n"
	        	+ "{v = new Date(y, m, d, h);}\n"

	        + "else if (y >= 0 && m >= 0 && d > 0)\n"
	        	+ "{v = new Date(y, m, d);}\n"

	        + "else if (y >= 0 && m >= 0)\n"
	        	+ "{v = new Date(y, m);}\n"

	        + "else if (y >= 0)\n"
	        	+ "{v = new Date(y);}\n"

	        + "}"
	        +"return (v && (z || o))?\n" // favour UTC offset over GMT offset
	        + "    (z ? v.add(Date.SECOND, (v.getTimezoneOffset() * 60) + (z*1)) :\n" // reset to UTC, then add offset
	        + "        v.add(Date.HOUR, (v.getGMTOffset() / 100) + (o / -100))) : v\n" // reset to GMT, then add offset
	        + ";}";

    Date.parseRegexes[regexNum] = new RegExp("^" + regex + "$", "i");
    eval(code);
};

// private
Date.formatCodeToRegex = function(character, currentGroup)
{
    /*
     * currentGroup = position in regex result array
     * g = calculation group (0 or 1. only group 1 contributes to date calculations.)
     * c = calculation method (required for group 1. null for group 0.)
     * s = regex string
     */
    switch (character) {
    case "d":
        return {g:1,
            c:"d = parseInt(results[" + currentGroup + "], 10);\n",
            s:"(" + String.fromCharCode(92) + "d{2})"}; // day of month with leading zeroes (01 - 31)
    case "D":
        for (var a = [], i = 0; i < 7; a.push(Date.getShortDayName(i)), ++i); // get L10n short day names
        return {g:0,
            c:null,
            s:"(?:" + a.join("|") +")"};
    case "j":
        return {g:1,
            c:"d = parseInt(results[" + currentGroup + "], 10);\n",
            s:"(" + String.fromCharCode(92) + "d{1,2})"}; // day of month without leading zeroes (1 - 31)
    case "l":
        return {g:0,
            c:null,
            s:"(?:" + Date.dayNames.join("|") + ")"};
    case "N":
        return {g:0,
            c:null,
            s:"[1-7]"}; // ISO-8601 day number (1 (monday) - 7 (sunday))
    case "S":
        return {g:0,
            c:null,
            s:"(?:st|nd|rd|th)"};
    case "w":
        return {g:0,
            c:null,
            s:"[0-6]"}; // javascript day number (0 (sunday) - 6 (saturday))
    case "z":
        return {g:0,
            c:null,
            s:"(?:" + String.fromCharCode(92) + "d{1,3}"}; // day of the year (0 - 364 (365 in leap years))
    case "W":
        return {g:0,
            c:null,
            s:"(?:" + String.fromCharCode(92) + "d{2})"}; // ISO-8601 week number (with leading zero)
    case "F":
        return {g:1,
            c:"m = parseInt(Date.getMonthNumber(results[" + currentGroup + "]), 10);\n", // get L10n month number
            s:"(" + Date.monthNames.join("|") + ")"};
    case "m":
        return {g:1,
            c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
            s:"(" + String.fromCharCode(92) + "d{2})"}; // month number with leading zeros (01 - 12)
    case "M":
        for (var a = [], i = 0; i < 12; a.push(Date.getShortMonthName(i)), ++i); // get L10n short month names
        return {g:1,
            c:"m = parseInt(Date.getMonthNumber(results[" + currentGroup + "]), 10);\n", // get L10n month number
            s:"(" + a.join("|") + ")"};
    case "n":
        return {g:1,
            c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
            s:"(" + String.fromCharCode(92) + "d{1,2})"}; // month number without leading zeros (1 - 12)
    case "t":
        return {g:0,
            c:null,
            s:"(?:" + String.fromCharCode(92) + "d{2})"}; // no. of days in the month (28 - 31)
    case "L":
        return {g:0,
            c:null,
            s:"(?:1|0)"};
    case "o":
    case "Y":
        return {g:1,
            c:"y = parseInt(results[" + currentGroup + "], 10);\n",
            s:"(" + String.fromCharCode(92) + "d{4})"}; // 4-digit year
    case "y":
        return {g:1,
            c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
                + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
            s:"(" + String.fromCharCode(92) + "d{1,2})"}; // 2-digit year
    case "a":
        return {g:1,
            c:"if (results[" + currentGroup + "] == 'am') {\n"
                + "if (h == 12) { h = 0; }\n"
                + "} else { if (h < 12) { h += 12; }}",
            s:"(am|pm)"};
    case "A":
        return {g:1,
            c:"if (results[" + currentGroup + "] == 'AM') {\n"
                + "if (h == 12) { h = 0; }\n"
                + "} else { if (h < 12) { h += 12; }}",
            s:"(AM|PM)"};
    case "g":
    case "G":
        return {g:1,
            c:"h = parseInt(results[" + currentGroup + "], 10);\n",
            s:"(" + String.fromCharCode(92) + "d{1,2})"}; // 24-hr format of an hour without leading zeroes (0 - 23)
    case "h":
    case "H":
        return {g:1,
            c:"h = parseInt(results[" + currentGroup + "], 10);\n",
            s:"(" + String.fromCharCode(92) + "d{2})"}; //  24-hr format of an hour with leading zeroes (00 - 23)
    case "i":
        return {g:1,
            c:"i = parseInt(results[" + currentGroup + "], 10);\n",
            s:"(" + String.fromCharCode(92) + "d{2})"}; // minutes with leading zeros (00 - 59)
    case "s":
        return {g:1,
            c:"s = parseInt(results[" + currentGroup + "], 10);\n",
            s:"(" + String.fromCharCode(92) + "d{2})"}; // seconds with leading zeros (00 - 59)
    case "u":
        return {g:1,
            c:"ms = parseInt(results[" + currentGroup + "], 10);\n",
            s:"(" + String.fromCharCode(92) + "d{3})"}; // milliseconds with leading zeros (000 - 999)
    case "O":
        return {g:1,
            c:[
                "o = results[", currentGroup, "];\n",
                "var sn = o.substring(0,1);\n", // get + / - sign
                "var hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60);\n", // get hours (performs minutes-to-hour conversion also, just in case)
                "var mn = o.substring(3,5) % 60;\n", // get minutes
                "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs
                "    (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
            ].join(""),
            s: "([+\-]" + String.fromCharCode(92) + "d{4})"}; // GMT offset in hrs and mins
    case "P":
        return {g:1,
            c:[
                "o = results[", currentGroup, "];\n",
                "var sn = o.substring(0,1);\n", // get + / - sign
                "var hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60);\n", // get hours (performs minutes-to-hour conversion also, just in case)
                "var mn = o.substring(4,6) % 60;\n", // get minutes
                "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))?\n", // -12hrs <= GMT offset <= 14hrs
                "    (sn + String.leftPad(hr, 2, 0) + String.leftPad(mn, 2, 0)) : null;\n"
            ].join(""),
            s: "([+\-]" + String.fromCharCode(92) + "d{2}:" + String.fromCharCode(92) + "d{2})"}; // GMT offset in hrs and mins (with colon separator)
    case "T":
        return {g:0,
            c:null,
            s:"[A-Z]{1,4}"}; // timezone abbrev. may be between 1 - 4 chars
    case "Z":
        return {g:1,
            c:"z = results[" + currentGroup + "] * 1;\n" // -43200 <= UTC offset <= 50400
                  + "z = (-43200 <= z && z <= 50400)? z : null;\n",
            s:"([+\-]?" + String.fromCharCode(92) + "d{1,5})"}; // leading '+' sign is optional for UTC offset
    case "c":
        var df = Date.formatCodeToRegex, calc = [];
        var arr = [df("Y", 1), df("m", 2), df("d", 3), df("h", 4), df("i", 5), df("s", 6), df("P", 7)];
        for (var i = 0, l = arr.length; i < l; ++i) {
          calc.push(arr[i].c);
        }
        return {g:1,
            c:calc.join(""),
            s:arr[0].s + "-" + arr[1].s + "-" + arr[2].s + "T" + arr[3].s + ":" + arr[4].s + ":" + arr[5].s + arr[6].s};
    case "U":
        return {g:1,
            c:"u = parseInt(results[" + currentGroup + "], 10);\n",
            s:"(-?" + String.fromCharCode(92) + "d+)"}; // leading minus sign indicates seconds before UNIX epoch
    default:
        return {g:0,
            c:null,
            s:character.replace(/([.*+?^${}()|[\]\/\\])/g , String.fromCharCode(92) + "$1")};
    }
};

/**
 * prüft ob zwei datums gleich sind
 */
Date.prototype.isEqual = function(date)
{
	return 	(
				this.getDate()			== date.getDate()			&&
				this.getMonth()			== date.getMonth()			&&
				this.getYear()			== date.getYear()			&&
				this.getHours()			== date.getHours()			&&
				this.getMinutes()		== date.getMinutes()		&&
				this.getSeconds()		== date.getSeconds()		&&
				this.getMilliseconds()	== date.getMilliseconds()
			)
};

/**
 * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
 *
 * Note: The date string returned by the javascript Date object's toString() method varies
 * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
 * For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
 * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
 * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
 * from the GMT offset portion of the date string.
 * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
 */
Date.prototype.getTimezone = function()
{
    // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
    //
    // Opera  : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
    // Safari : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone (same as FF)
    // FF     : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
    // IE     : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
    // IE     : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
    //
    // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
    // step 1: (?:\((.*)\) -- find timezone in parentheses
    // step 2: ([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?) -- if nothing was found in step 1, find timezone from timezone offset portion of date string
    // step 3: remove all non uppercase characters found in step 1 and 2
    return this.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
};

/**
 * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
 * @param {Boolean} colon true to separate the hours and minutes with a colon (defaults to false).
 * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
 */
Date.prototype.getGMTOffset = function(colon)
{
    return (this.getTimezoneOffset() > 0 ? "-" : "+")
        + String.leftPad(Math.abs(Math.floor(this.getTimezoneOffset() / 60)), 2, "0")
        + (colon ? ":" : "")
        + String.leftPad(this.getTimezoneOffset() % 60, 2, "0");
};

/**
 * Get the numeric day number of the year, adjusted for leap year.
 * @return {Number} 0 to 364 (365 in leap years).
 */
Date.prototype.getDayOfYear = function()
{
    var num = 0;
    Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
    for (var i = 0; i < this.getMonth(); ++i) {
        num += Date.daysInMonth[i];
    }
    return num + this.getDate() - 1;
};

/**
 * Get the numeric ISO-8601 week number of the year.
 * (equivalent to the format specifier 'W', but without a leading zero).
 * @return {Number} 1 to 53
 */
Date.prototype.getWeekOfYear = function()
{
    // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
    var ms1d = 864e5; // milliseconds in a day
    var ms7d = 7 * ms1d; // milliseconds in a week
    var DC3 = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate() + 3) / ms1d; // an Absolute Day Number
    var AWN = Math.floor(DC3 / 7); // an Absolute Week Number
    var Wyr = new Date(AWN * ms7d).getUTCFullYear();
    return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
};

/**
 * Whether or not the current date is in a leap year.
 * @return {Boolean} True if the current date is in a leap year, else false.
 */
Date.prototype.isLeapYear = function()
{
    var year = this.getFullYear();
    return ((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
};

/**
 * liefert den ersten Tag des Jahres
 */
Date.prototype.getFirstDateOfYear = function()
{
	var date = this.clone();
	date.setMonth(0);
	date.setDate(1);
	return date;
}

/**
 * liefert den ersten Tag des Jahres
 */
Date.prototype.getLastDateOfYear = function()
{
	var date = this.clone();
	date.setMonth(11);
	date.setDate(31);
	return date;
}

/**
 * liefert den ersten Tag der Woche
 */
Date.prototype.getFirstDateOfWeek = function()
{
	var day = this.getDay() - Date.firstDayOfWeek;
	if (day < 0)
	{
		return this.sub(Date.DAY, 7 - Math.abs(day));
	}
	else if (day > 0)
	{
		return this.sub(Date.DAY, day);
	}

	return this.clone();
}

/**
 * liefert den letzen Tag der Woche
 */
Date.prototype.getLastDateOfWeek = function()
{
	return this.getFirstDateOfWeek().add(Date.DAY, 6);
}

/**
 * Get the first day of the current month, adjusted for leap year.  The returned value
 * is the numeric day index within the week (0-6) which can be used in conjunction with
 * the {@link #monthNames} array to retrieve the textual day name.
 * Example:
 *<pre><code>
var dt = new Date('1/10/2007');
document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
</code></pre>
 * @return {Number} The day number (0-6).
 */
Date.prototype.getFirstDayOfMonth = function()
{
    var day = (this.getDay() - (this.getDate() - 1)) % 7;
    return (day < 0) ? (day + 7) : day;
};

/**
 * Get the last day of the current month, adjusted for leap year.  The returned value
 * is the numeric day index within the week (0-6) which can be used in conjunction with
 * the {@link #monthNames} array to retrieve the textual day name.
 * Example:
 *<pre><code>
var dt = new Date('1/10/2007');
document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
</code></pre>
 * @return {Number} The day number (0-6).
 */
Date.prototype.getLastDayOfMonth = function()
{
    var day = (this.getDay() + (Date.daysInMonth[this.getMonth()] - this.getDate())) % 7;
    return (day < 0) ? (day + 7) : day;
};


/**
 * Get the date of the first day of the month in which this date resides.
 * @return {Date}
 */
Date.prototype.getFirstDateOfMonth = function()
{
    return new Date(this.getFullYear(), this.getMonth(), 1);
};

/**
 * Get the date of the last day of the month in which this date resides.
 * @return {Date}
 */
Date.prototype.getLastDateOfMonth = function()
{
    return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
};
/**
 * Get the number of days in the current month, adjusted for leap year.
 * @return {Number} The number of days in the month.
 */
Date.prototype.getDaysInMonth = function()
{
    Date.daysInMonth[1] = this.isLeapYear() ? 29 : 28;
    return Date.daysInMonth[this.getMonth()];
};

/**
 * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
 * @return {String} 'st, 'nd', 'rd' or 'th'.
 */
Date.prototype.getSuffix = function()
{
    switch (this.getDate()) {
        case 1:
        case 21:
        case 31:
            return "st";
        case 2:
        case 22:
            return "nd";
        case 3:
        case 23:
            return "rd";
        default:
            return "th";
    }
};

// private
Date.daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];

/**
 * An array of textual month names.
 * Override these values for international dates, for example...
 * Date.monthNames = ['JanInYourLang', 'FebInYourLang', ...];
 * @type Array
 * @static
 */
Date.monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

/**
 * Get the short month name for the given month number.
 * Override this function for international dates.
 * @param {Number} month A zero-based javascript month number.
 * @return {String} The short month name.
 * @static
 */
Date.getShortMonthName = function(month)
{
    return Date.monthNames[month].substring(0, 3);
};

/**
 * erste tag in einer Woche
 */
Date.firstDayOfWeek = 0;

/**
 * An array of textual day names.
 * Override these values for international dates, for example...
 * Date.dayNames = ['SundayInYourLang', 'MondayInYourLang', ...];
 * @type Array
 * @static
 */
Date.dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
/**
 * Get the short day name for the given day number.
 * Override this function for international dates.
 * @param {Number} day A zero-based javascript day number.
 * @return {String} The short day name.
 * @static
 */
Date.getShortDayName = function(day)
{
    return Date.dayNames[day].substring(0, 3);
};

// private
Date.y2kYear = 50;

/**
 * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
 * Override these values for international dates, for example...
 * Date.monthNumbers = {'ShortJanNameInYourLang':0, 'ShortFebNameInYourLang':1, ...};
 * @type Object
 * @static
 */
Date.monthNumbers = {
    Jan:0,
    Feb:1,
    Mar:2,
    Apr:3,
    May:4,
    Jun:5,
    Jul:6,
    Aug:7,
    Sep:8,
    Oct:9,
    Nov:10,
    Dec:11};

/**
 * Get the zero-based javascript month number for the given short/full month name.
 * Override this function for international dates.
 * @param {String} name The short/full month name.
 * @return {Number} The zero-based javascript month number.
 * @static
 */
Date.getMonthNumber = function(name)
{
    // handle camel casing for english month names (since the keys for the Date.monthNumbers hash are case sensitive)
    return Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
};

/**
 * Creates and returns a new Date instance with the exact same date value as the called instance.
 * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
 * variable will also be changed.  When the intention is to create a new variable that will not
 * modify the original instance, you should create a clone.
 *
 * Example of correctly cloning a date:
 * <pre><code>
//wrong way:
var orig = new Date('10/1/2006');
var copy = orig;
copy.setDate(5);
document.write(orig);  //returns 'Thu Oct 05 2006'!

//correct way:
var orig = new Date('10/1/2006');
var copy = orig.clone();
copy.setDate(5);
document.write(orig);  //returns 'Thu Oct 01 2006'
</code></pre>
 * @return {Date} The new Date instance.
 */
Date.prototype.clone = function()
{
  return new Date(this.getTime());
};

/**
 * Clears any time information from this date.
 @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
 @return {Date} this or the clone.
 */
Date.prototype.clearTime = function(clone)
{
    if(clone){
        return this.clone().clearTime();
    }
    this.setHours(0);
    this.setMinutes(0);
    this.setSeconds(0);
    this.setMilliseconds(0);
    return this;
};

// private
// safari setMonth is broken
if (Prototype.Browser.isSafari) {
    Date.brokenSetMonth = Date.prototype.setMonth;
  Date.prototype.setMonth = function(num)
  {
    if(num <= -1){
      var n = Math.ceil(-num);
      var back_year = Math.ceil(n/12);
      var month = (n % 12) ? 12 - n % 12 : 0 ;
      this.setFullYear(this.getFullYear() - back_year);
      return Date.brokenSetMonth.call(this, month);
    } else {
      return Date.brokenSetMonth.apply(this, arguments);
    }
  };
}

/** Date interval constant @static @type String */
Date.MILLI = "ms";
/** Date interval constant @static @type String */
Date.SECOND = "s";
/** Date interval constant @static @type String */
Date.MINUTE = "mi";
/** Date interval constant @static @type String */
Date.HOUR = "h";
/** Date interval constant @static @type String */
Date.DAY = "d";
/** Date interval constant @static @type String */
Date.MONTH = "mo";
/** Date interval constant @static @type String */
Date.YEAR = "y";

/**
 * Provides a convenient method of performing basic date arithmetic.  This method
 * does not modify the Date instance being called - it creates and returns
 * a new Date instance containing the resulting date value.
 *
 * Examples:
 * <pre><code>
//Basic usage:
var dt = new Date('10/29/2006').add(Date.DAY, 5);
document.write(dt); //returns 'Fri Oct 06 2006 00:00:00'

//Negative values will subtract correctly:
var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'

//You can even chain several calls together in one line!
var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
 </code></pre>
 *
 * @param {String} interval   A valid date interval enum value.
 * @param {Number} value      The amount to add to the current date.
 * @return {Date} The new Date instance.
 */
Date.prototype.add = function(interval, value)
{
  var d = this.clone();
  if (!interval || value === 0) return d;
  switch(interval.toLowerCase()){
    case Date.MILLI:
      d.setMilliseconds(this.getMilliseconds() + value);
      break;
    case Date.SECOND:
      d.setSeconds(this.getSeconds() + value);
      break;
    case Date.MINUTE:
      d.setMinutes(this.getMinutes() + value);
      break;
    case Date.HOUR:
      d.setHours(this.getHours() + value);
      break;
    case Date.DAY:
      d.setDate(this.getDate() + value);
      break;
    case Date.MONTH:
      var day = this.getDate();
      if(day > 28){
          day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
      }
      d.setDate(day);
      d.setMonth(this.getMonth() + value);
      break;
    case Date.YEAR:
      d.setFullYear(this.getFullYear() + value);
      break;
  }
  return d;
};

Date.prototype.add = Date.prototype.add.wrap(function(proceed, interval, value)
{
	if (Object.isUndefined(value) && Object.isString(interval)) {
		value = parseInt(interval);
		interval = interval.toLowerCase();
		if (interval.indexOf("millisecond") != -1)
			interval = Date.MILLI;

		else if (interval.indexOf("second") != -1)
			interval = Date.SECOND;

		else if (interval.indexOf("minute") != -1)
			interval = Date.MINUTE;

		else if (interval.indexOf("hour") != -1)
			interval = Date.HOUR;

		else if (interval.indexOf("day") != -1)
			interval = Date.DAY;

		else if (interval.indexOf("week") != -1) {
			interval = Date.DAY;
			value = value * 7;

		} else if (interval.indexOf("month") != -1)
			interval = Date.MONTH;

		else if (interval.indexOf("year") != -1)
			interval = Date.YEAR;
	}

	return proceed(interval, value);
});

Date.prototype.sub = function(interval, value)
{
	return this.add(interval, value * -1);
};
Date.prototype.succ = Date.prototype.add.curry(Date.DAY, 1);

/**
 * Checks if this date falls on or between the given start and end dates.
 * @param {Date} start Start date
 * @param {Date} end End date
 * @return {Boolean} true if this date falls on or between the given start and end dates.
 */
Date.prototype.between = function(start, end)
{
    var t = this.getTime();
    return start.getTime() <= t && t <= end.getTime();
};

Object.extend(Event, (function()
{
	var handlers = {
		resize:			$A([]),
		scroll:			$A([])
	};

	var pe = null;

	/**
	 * installiert den pe
	 **/
	function install()
	{
		if (pe) return;
		pe = new PeriodicalExecuter((function()
		{
			// resize prüfen
			handlers.resize.each(function(els)
			{
				var size = getSize(els.element);
				if (size.width != els.size.width || size.height != els.size.height) {
					els.size = Object.clone(size);
					fire(els.handlers, els.element, size);
				}
			});

			// scroll prüfen
			handlers.scroll.each(function(els)
			{
				var so = getScrollOffset(els.element);
				if (so.left != els.scrollOffset.left || so.top != els.scrollOffset.top) {
					els.scrollOffset = Object.clone(so);
					fire(els.handlers, els.element, so);
				}
			});
		}).bind(this), 0.05);
	}

	/**
	 * event fire
	 **/
	function fire(handlers, element, value)
	{
		handlers.each(function(handler) { handler(element, value); });
	}

	/**
	 * fügt ein neues element/neuen handler zur überwachnung hinzu
	 **/
	function append(dest, element, handler, size, so)
	{
		// such nach dem element
		var el = dest.find(function(els) { return els["element"] == element; });
		// nicht drin dann anlegen
		if (!el) {
			el =
			{
				"element":		element,
				"handlers":		$A([]),
				"scrollOffset":	so		|| {left: 0, top: 0},
				"size":			size	|| {width: 0, height: 0}
			};
			dest.push(el);
		}

		// suche nach der Handler funktion und wenn drin dann raus
		if (el.handlers.find(function(fn) { return fn == handler; })) return;

		// nicht drin dann anlegen
		el.handlers.push(handler);
	}

	/**
	 * liefert den ScrollOffset je nach element
	 **/
	function getScrollOffset(element)
	{
		if (element == document) return document.viewport.getScrollOffsets();

		return {
			left:	element.scrollLeft,
			top:	element.scrollTop
		};
	}

	/**
	 * liefert die size
	 **/
	function getSize(element)
	{
		if (element == document) return document.viewport.getDimensions();

		return Element.getSize(element);
	}

	return {
		/**
		 * feuert das entsprechende event
		 **/
		fireResize: function(element)
		{
			element = $(element);
			if (element != document && !Object.isElement(element)) return;

			var el = handlers.resize.find(function(els) { return els["element"] == element; });
			if (!el) return;

			fire.defer(el.handlers, element, el.size);
		},

		/**
		 * feuert das entsprechende event
		 **/
		fireScroll: function(element)
		{
			element = $(element);
			if (element != document && !Object.isElement(element)) return;

			var el = handlers.scroll.find(function(els) { return els["element"] == element; });
			if (!el) return;

			fire.defer(el.handlers, element, el.scrollOffset);
		},

		/**
		 * liefert die Key Number des Events wenn key pressed
		 *
		 */
		keyNumber: function(event)
		{
			if (window.event)
			{
				return window.event.keyCode;
			}
			else if (event)
			{
				return event.which;
			}

			return 0;
		},

		/**
		 * on resize überwachung
		 **/
		onResize: function(element, handler)
		{
			element = $(element);
			if (element != document && !Object.isElement(element)) return;
			if (pe == null) install();
			append(handlers.resize, element, handler, getSize(element), null);
		},

		/**
		 * on scroll überwachung
		 **/
		onScroll: function(element, handler)
		{
			element = $(element);
			if (element != document && !Object.isElement(element)) return;
			if (pe == null) install();
			append(handlers.scroll, element, handler, null, getScrollOffset(element));
		}
	};
})());
Event.observe = Event.observe.wrap(function(proceed, element, eventName, handler, useCapture)
{
	var lname = eventName.toLowerCase();
	if (lname == "resize")		Event.onResize(element, handler);
	else if (lname == "scroll")	Event.onScroll(element, handler);
	else						proceed(element, eventName, handler, useCapture);
});
Element.fire = Element.fire.wrap(function(proceed, element, eventName)
{
	var lname = eventName.toLowerCase();
	if (lname == "resize")		Event.fireResize(element);
	else if (lname == "scroll")	Event.fireScroll(element);
	else						return proceed(element, eventName);
});
Element.Methods.fire = Element.Methods.fire.wrap(function(proceed, element, eventName)
{
	var lname = eventName.toLowerCase();
	if (lname == "resize")		Event.fireResize(element);
	else if (lname == "scroll")	Event.fireScroll(element);
	else						return proceed(element, eventName);
});

Object.extend(PeriodicalExecuter.prototype,
{
	paused:	false,
	pause: function() { this.paused = true; return this; },
	resume: function() { this.paused = false; return this; }
});
PeriodicalExecuter.prototype.onTimerEvent = PeriodicalExecuter.prototype.onTimerEvent.wrap(function(proceed) { if (!this.paused) return proceed(); });

/**
 * MD5 Implementation an String
 *
 * functions
 *		md5()
 *		md5b64()
 *		md5str()
 *		md5hmac(key)
 *		md5hmacb64(key)
 *		md5hmacstr(key)
 **/
Object.extend(String.prototype, (function()
{
	/*
	 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
	 * Digest Algorithm, as defined in RFC 1321.
	 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
	 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
	 * Distributed under the BSD License
	 * See http://pajhome.org.uk/crypt/md5 for more info.
	 */

	/*
	 * Configurable variables. You may need to tweak these to be compatible with
	 * the server-side, but the defaults work in most cases.
	 */
	var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
	var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
	var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

	/*
	 * These are the functions you'll usually want to call
	 * They take string arguments and return either hex or base-64 encoded strings
	 */
	function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
	function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
	function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
	function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
	function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
	function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

	/*
	 * Calculate the MD5 of an array of little-endian words, and a bit length
	 */
	function core_md5(x, len)
	{
	  /* append padding */
	  x[len >> 5] |= 0x80 << ((len) % 32);
	  x[(((len + 64) >>> 9) << 4) + 14] = len;

	  var a =  1732584193;
	  var b = -271733879;
	  var c = -1732584194;
	  var d =  271733878;

	  for(var i = 0; i < x.length; i += 16)
	  {
	    var olda = a;
	    var oldb = b;
	    var oldc = c;
	    var oldd = d;

	    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
	    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
	    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
	    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
	    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
	    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
	    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
	    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
	    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
	    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
	    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
	    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
	    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
	    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
	    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
	    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

	    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
	    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
	    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
	    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
	    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
	    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
	    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
	    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
	    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
	    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
	    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
	    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
	    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
	    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
	    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
	    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

	    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
	    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
	    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
	    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
	    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
	    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
	    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
	    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
	    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
	    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
	    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
	    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
	    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
	    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
	    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
	    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

	    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
	    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
	    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
	    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
	    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
	    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
	    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
	    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
	    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
	    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
	    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
	    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
	    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
	    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
	    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
	    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

	    a = safe_add(a, olda);
	    b = safe_add(b, oldb);
	    c = safe_add(c, oldc);
	    d = safe_add(d, oldd);
	  }
	  return Array(a, b, c, d);

	}

	/*
	 * These functions implement the four basic operations the algorithm uses.
	 */
	function md5_cmn(q, a, b, x, s, t) { return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b); }
	function md5_ff(a, b, c, d, x, s, t) { return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t); }
	function md5_gg(a, b, c, d, x, s, t) { return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t); }
	function md5_hh(a, b, c, d, x, s, t) { return md5_cmn(b ^ c ^ d, a, b, x, s, t); }
	function md5_ii(a, b, c, d, x, s, t) { return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); }

	/*
	 * Bitwise rotate a 32-bit number to the left.
	 */
	function bit_rol(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); }

	/*
	 * Calculate the HMAC-MD5, of a key and some data
	 */
	function core_hmac_md5(key, data)
	{
	  var bkey = str2binl(key);
	  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

	  var ipad = Array(16), opad = Array(16);
	  for(var i = 0; i < 16; i++)
	  {
	    ipad[i] = bkey[i] ^ 0x36363636;
	    opad[i] = bkey[i] ^ 0x5C5C5C5C;
	  }

	  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
	  return core_md5(opad.concat(hash), 512 + 128);
	}

	/*
	 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
	 * to work around bugs in some JS interpreters.
	 */
	function safe_add(x, y)
	{
	  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
	  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
	  return (msw << 16) | (lsw & 0xFFFF);
	}

	/*
	 * Convert a string to an array of little-endian words
	 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
	 */
	function str2binl(str)
	{
	  var bin = Array();
	  var mask = (1 << chrsz) - 1;
	  for(var i = 0; i < str.length * chrsz; i += chrsz)
	    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
	  return bin;
	}

	/*
	 * Convert an array of little-endian words to a string
	 */
	function binl2str(bin)
	{
	  var str = "";
	  var mask = (1 << chrsz) - 1;
	  for(var i = 0; i < bin.length * 32; i += chrsz)
	    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
	  return str;
	}

	/*
	 * Convert an array of little-endian words to a hex string.
	 */
	function binl2hex(binarray)
	{
	  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
	  var str = "";
	  for(var i = 0; i < binarray.length * 4; i++)
	  {
	    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
	           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
	  }
	  return str;
	}

	/*
	 * Convert an array of little-endian words to a base-64 string
	 */
	function binl2b64(binarray)
	{
	  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
	  var str = "";
	  for(var i = 0; i < binarray.length * 4; i += 3)
	  {
	    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
	                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
	                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
	    for(var j = 0; j < 4; j++)
	    {
	      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
	      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
	    }
	  }
	  return str;
	}

	return {

		crc32:	function(crc)
		{
			str = this;
			var table = "00000000 77073096 EE0E612C 990951BA 076DC419 706AF48F E963A535 9E6495A3 0EDB8832 79DCB8A4 E0D5E91E 97D2D988 09B64C2B 7EB17CBD E7B82D07 90BF1D91 1DB71064 6AB020F2 F3B97148 84BE41DE 1ADAD47D 6DDDE4EB F4D4B551 83D385C7 136C9856 646BA8C0 FD62F97A 8A65C9EC 14015C4F 63066CD9 FA0F3D63 8D080DF5 3B6E20C8 4C69105E D56041E4 A2677172 3C03E4D1 4B04D447 D20D85FD A50AB56B 35B5A8FA 42B2986C DBBBC9D6 ACBCF940 32D86CE3 45DF5C75 DCD60DCF ABD13D59 26D930AC 51DE003A C8D75180 BFD06116 21B4F4B5 56B3C423 CFBA9599 B8BDA50F 2802B89E 5F058808 C60CD9B2 B10BE924 2F6F7C87 58684C11 C1611DAB B6662D3D 76DC4190 01DB7106 98D220BC EFD5102A 71B18589 06B6B51F 9FBFE4A5 E8B8D433 7807C9A2 0F00F934 9609A88E E10E9818 7F6A0DBB 086D3D2D 91646C97 E6635C01 6B6B51F4 1C6C6162 856530D8 F262004E 6C0695ED 1B01A57B 8208F4C1 F50FC457 65B0D9C6 12B7E950 8BBEB8EA FCB9887C 62DD1DDF 15DA2D49 8CD37CF3 FBD44C65 4DB26158 3AB551CE A3BC0074 D4BB30E2 4ADFA541 3DD895D7 A4D1C46D D3D6F4FB 4369E96A 346ED9FC AD678846 DA60B8D0 44042D73 33031DE5 AA0A4C5F DD0D7CC9 5005713C 270241AA BE0B1010 C90C2086 5768B525 206F85B3 B966D409 CE61E49F 5EDEF90E 29D9C998 B0D09822 C7D7A8B4 59B33D17 2EB40D81 B7BD5C3B C0BA6CAD EDB88320 9ABFB3B6 03B6E20C 74B1D29A EAD54739 9DD277AF 04DB2615 73DC1683 E3630B12 94643B84 0D6D6A3E 7A6A5AA8 E40ECF0B 9309FF9D 0A00AE27 7D079EB1 F00F9344 8708A3D2 1E01F268 6906C2FE F762575D 806567CB 196C3671 6E6B06E7 FED41B76 89D32BE0 10DA7A5A 67DD4ACC F9B9DF6F 8EBEEFF9 17B7BE43 60B08ED5 D6D6A3E8 A1D1937E 38D8C2C4 4FDFF252 D1BB67F1 A6BC5767 3FB506DD 48B2364B D80D2BDA AF0A1B4C 36034AF6 41047A60 DF60EFC3 A867DF55 316E8EEF 4669BE79 CB61B38C BC66831A 256FD2A0 5268E236 CC0C7795 BB0B4703 220216B9 5505262F C5BA3BBE B2BD0B28 2BB45A92 5CB36A04 C2D7FFA7 B5D0CF31 2CD99E8B 5BDEAE1D 9B64C2B0 EC63F226 756AA39C 026D930A 9C0906A9 EB0E363F 72076785 05005713 95BF4A82 E2B87A14 7BB12BAE 0CB61B38 92D28E9B E5D5BE0D 7CDCEFB7 0BDBDF21 86D3D2D4 F1D4E242 68DDB3F8 1FDA836E 81BE16CD F6B9265B 6FB077E1 18B74777 88085AE6 FF0F6A70 66063BCA 11010B5C 8F659EFF F862AE69 616BFFD3 166CCF45 A00AE278 D70DD2EE 4E048354 3903B3C2 A7672661 D06016F7 4969474D 3E6E77DB AED16A4A D9D65ADC 40DF0B66 37D83BF0 A9BCAE53 DEBB9EC5 47B2CF7F 30B5FFE9 BDBDF21C CABAC28A 53B39330 24B4A3A6 BAD03605 CDD70693 54DE5729 23D967BF B3667A2E C4614AB8 5D681B02 2A6F2B94 B40BBE37 C30C8EA1 5A05DF1B 2D02EF8D";
			if (crc == window.undefined)
			{
				crc = 0;
			}
			var n = 0; //a number between 0 and 255
			var x = 0; //an hex number

			crc = crc ^ (-1);
			for (var i = 0, iTop = str.length; i < iTop; i++)
			{
				n = ( crc ^ str.charCodeAt( i ) ) & 0xFF;
				x = "0x" + table.substr( n * 9, 8 );
				crc = ( crc >>> 8 ) ^ x;
			}

			return crc ^ (-1);
		},

		md5:		function() { return hex_md5(this); },
		md5b64:		function() { return b64_md5(this); },
		md5str:		function() { return str_md5(this); },
		md5hmac:	function(key) { return hex_hmac_md5(key, this); },
		md5hmacb64:	function(key) { return b64_hmac_md5(key, this); },
		md5hmacstr:	function(key) { return str_hmac_md5(key, this); }
	};
})());

//	/**
//	 *  Base64 encode / decode
//	 *  http://www.webtoolkit.info/
//	 *
//	 *
//	 **/
//	Object.extend(String.prototype, (function()
//	{
//		var _keyStr =  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
//
//		/**
//		 * private method for UTF-8 encoding
//		 *
//		 * @param string string
//		 * @access private
//		 * @return string
//		 **/
//		function _utf8_encode(string)
//		{
//			string = string.replace(/\r\n/g, "\n");
//			var utftext = "";
//
//			for (var n = 0; n < string.length; n++) {
//				var c = string.charCodeAt(n);
//
//				if (c < 128) {
//					utftext += String.fromCharCode(c);
//
//				} else if((c > 127) && (c < 2048)) {
//					utftext += String.fromCharCode((c >> 6) | 192);
//					utftext += String.fromCharCode((c & 63) | 128);
//
//				} else {
//					utftext += String.fromCharCode((c >> 12) | 224);
//					utftext += String.fromCharCode(((c >> 6) & 63) | 128);
//					utftext += String.fromCharCode((c & 63) | 128);
//				}
//			}
//
//			return utftext;
//		}
//
//		/**
//		 * private method for UTF-8 decoding
//		 *
//		 * @param string utftext
//		 * @access private
//		 * @return string
//		 **/
//		function _utf8_decode(utftext)
//		{
//			var string = "";
//			var i = 0;
//			var c = c1 = c2 = 0;
//
//			while ( i < utftext.length ) {
//				c = utftext.charCodeAt(i);
//
//				if (c < 128) {
//					string += String.fromCharCode(c);
//					i++;
//
//				} else if((c > 191) && (c < 224)) {
//					c2 = utftext.charCodeAt(i+1);
//					string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
//					i += 2;
//
//				} else {
//					c2 = utftext.charCodeAt(i+1);
//					c3 = utftext.charCodeAt(i+2);
//					string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
//					i += 3;
//				}
//			}
//
//			return string;
//		}
//
//		return {
//			/**
//			 * public method for encoding
//			 *
//			 * @access public
//			 * @return string
//			 **/
//			base64Encode: function()
//			{
//				var input = _utf8_encode(this);
//				var output = "";
//				var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
//				var i = 0;
//
//				while (i < input.length) {
//					chr1 = input.charCodeAt(i++);
//					chr2 = input.charCodeAt(i++);
//					chr3 = input.charCodeAt(i++);
//
//					enc1 = chr1 >> 2;
//					enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
//					enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
//					enc4 = chr3 & 63;
//
//					if (isNaN(chr2))		enc3 = enc4 = 64;
//					else if (isNaN(chr3))	enc4 = 64;
//
//					output = output + _keyStr.charAt(enc1) + _keyStr.charAt(enc2) + _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
//				}
//
//				return output;
//			},
//
//			/**
//			 * public method for decoding
//			 *
//			 * @access public
//			 * @return string
//			 **/
//			base64Decode: function ()
//			{
//				var input = this.replace("/[^A-Za-z0-9\+\/\=]/g", "");
//				var output = "";
//				var chr1, chr2, chr3;
//				var enc1, enc2, enc3, enc4;
//				var i = 0;
//
//				while (i < input.length) {
//					enc1 = _keyStr.indexOf(input.charAt(i++));
//					enc2 = _keyStr.indexOf(input.charAt(i++));
//					enc3 = _keyStr.indexOf(input.charAt(i++));
//					enc4 = _keyStr.indexOf(input.charAt(i++));
//
//					chr1 = (enc1 << 2) | (enc2 >> 4);
//					chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
//					chr3 = ((enc3 & 3) << 6) | enc4;
//
//					output = output + String.fromCharCode(chr1);
//
//					if (enc3 != 64) output = output + String.fromCharCode(chr2);
//					if (enc4 != 64) output = output + String.fromCharCode(chr3);
//				}
//
//				return _utf8_decode(output);
//			}
//		};
//	})());
//	Object.extend(Object,
//	{
//		base64Encode: function(obj)  { return Object.toJSON(obj).base64Encode(); },
//		base64Decode: function(data) { return data.base64Decode().evalJSON(); }
//	});
//	Object.extend(Array.prototype,	{base64Encode: function() { return Object.base64Encode(this); }});
//	Object.extend(Number.prototype,	{base64Encode: function() { return Object.base64Encode(this); }});
//	Object.extend(Array,			{base64Decode: function(data) { return Object.base64Decode(data); }});
//	Object.extend(Number,			{base64Decode: function(data) { return Object.base64Decode(data); }});
