var _BASE_INCLUDED_;

if (_BASE_INCLUDED_ === undefined)
{

_BASE_INCLUDED_ = true;

function array_remove(arr, value)
{
	var length = arr.length;
	var count = 0;
	for(i=0; i < length; i++)
		if (arr[i] === value) {
			arr[i] = arr[length-1];
			arr.pop();
			count++;
		}
	return count;
}

function in_array(arr, value)
{
	var length = arr.length;
	for(i=0; i < length; i++) {
		if (arr[i] == value) {
			return i;
		}
	}
	return -1;
}

function in_arrayEx(arr, value)
{
	var length = arr.length;
	for(i=0; i < length; i++)
		if (arr[i] === value)
			return i;
	return -1;
}

function is_object(obj)
{
	return (obj != null && typeof(obj) == "object");
}
function is_array(arr)
{	
	return (arr != null && typeof(arr) == "object" && instanceOf(arr, Array));
}
function is_function(func)
{
	return (func != null && typeof(func) == "function");
}

function instanceOf(obj, constructor)
{
	if (Object.isPrototypeOf) {
		return constructor.prototype.isPrototypeOf(obj);
	} else { // bug?
		if (obj.constructor == constructor)
			return true;
		else if (obj.prototype != null)
			return instanceOf(obj.prototype, constructor);
		else
			return false;
	}
}

function getElement(id)
{
	if (is_object(id))
		return id;
	else
		return document.getElementById(id);
}

function getPosition(obj)
{
	obj2 = obj.offsetParent;
	var pos = [0, 0];
	
	if (obj.offsetParent) {
		while (obj.offsetParent)
		{
			if (!(obj.scrollTop === undefined)) {
				pos[0] += obj.offsetLeft - obj.scrollLeft;
				pos[1] += obj.offsetTop - obj.scrollTop;
			} else {
				pos[0] += obj.offsetLeft;
				pos[1] += obj.offsetTop;
			}
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		pos[0] += obj.x;
		pos[1] += obj.y;
	}
	return pos;
}

function event_getPosition(e)
{
	if (!e) e = window.event;
	if (e.clientX) {
		return [e.clientX, e.clientY];
	} else if (e.pageX) {
		return [e.pageX, e.pageY];
	} else {
		return [0,0];
	}
}

function event_getType(e)
{
	if (!e)
		return window.event.type;
	else
		return e.type;
}

function event_getSource(e)
{
	if (!e)	e = window.event;
	if (e.target)
		return e.target;
	else if (e.srcElement)
		return e.srcElement;
	else
		return this;
}
function event_consume(e)
{
	if (!e) e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function getURIpath()
{
	var index = location.href.lastIndexOf("/");
	if (index <= 0)
		index = location.href.lastIndexOf("\\");
	if (index == -1)
		index = location.href.length - 1;
	return location.href.slice(0, index+1);
}

function ensure_jscript_compatibility()
{
	if (!Array.push)
	{
		Array.prototype.push =
			function() {
				var length = arguments.length;
				var arrlen = this.length;
				for (var i=0; i < length; i++)
					this[arrlen + i] = arguments[i];
			};
	}
	if (!Array.pop)
	{
		Array.prototype.pop =
			function() {
				var arrlen = this.length;
				if (arrlen > 0) {
					var temp = this[arrlen-1];
					delete this[arrlen-1];
					return temp;
				}
			};
	}
	if (!document.getElementById && document.all)
			document.getElementById = function(id) { return document.all[id] };
}

function getCookie()
{
	if (document.cookie) {
		var arr = document.cookie.split("; ");
		var arrCookie = new Array();
		for (var i in arr) {
			var arr2 = arr[i].split("=");
			arrCookie[arr2[0]] = arr2[1];
		}
		return arrCookie;
	} else {
		return new Array();
	}
}

function setCookieVar(name, value, expire)
{
	var d = null;
	if (expire) {
		d = new Date();
		var t = d.getTime() + (expire * 1000);
		d.setTime(t);
	}
	document.cookie = name+"="+value+(d != null ? "; expire=" + d.toGMTString() : "");
}

function getCookieVar(name)
{
	return getCookie()[name];
}

ensure_jscript_compatibility();	// IE4 IE5.0

var URIpath = getURIpath();

} //_BASE_INCLUDED_



// class Behavior

if (_BEHAVIOR_INCLUDED_ === undefined)
{

var _BEHAVIOR_INCLUDED_ = true;

function Behavior(name)
{
	this.name = name;
	this.eventType = [];
	this.eventCode = [];
	this.eventFunc = [];
	this.withoutOnPrefix = [];
	this.initFunction = null;
}

function Behavior_clone(newName)
{
	var b = new Behavior();
	var anzahl = this.eventType.length;
	for (var i=0; i < anzahl; i++)
		b.addEventListener(this.eventType[i], this.eventCode[i]);
	b.initFunction = this.initFunction;
	b.name = newName || this.name;
	return b;
}

function Behavior_addEventListener(eType, eCode, withoutOnPrefix)
{
	var i = in_array(this.eventType, eType);
	if (i == -1) {
		this.eventType.push(eType);
		this.eventCode.push(eCode);
		this.eventFunc.push(null);
		this.withoutOnPrefix.push(withoutOnPrefix || false);
	} else {
		this.eventCode[i] = eCode;
		this.eventFunc[i] = null;
		if (withoutOnPrefix)
			this.withoutOnPrefix[i] = withoutOnPrefix;
	}
	return this;
}

function Behavior_addCode(eType, eCode, before)
{
	var i = in_array(this.eventType, eType);
	if (before == true)
		this.eventCode[i] = eCode + ";" + this.eventCode[i];
	else
		this.eventCode[i] = this.eventCode[i] + ";" + eCode;
	this.eventFunc[i] = null;
	return this;
}

function Behavior_setFunction(eType, eFunc, withoutOnPrefix)
{
	var i = in_array(this.eventType, eType);
	this.eventFunc[i] = eFunc;
	this.eventCode[i] = "";
	if (withoutOnPrefix)
		this.withoutOnPrefix[i] = withoutOnPrefix;
	return this;
}

function Behavior_setInitFunction(initFunc)
{
	this.initFunction = initFunc;
	return this;
}

function attachBehavior(element, behavior)
{
	element = getElement(element);
	var anzahl = behavior.eventType.length;
	for (var i=0; i < anzahl; i++) {
		if (behavior.eventFunc[i] == null)
			behavior.eventFunc[i] = new Function(behavior.eventParamName, behavior.eventCode[i]);
		element[(behavior.withoutOnPrefix[i] ? "" : "on") + behavior.eventType[i]] = behavior.eventFunc[i];
	}
	if (behavior.initFunction != null) {
		element.__initBehavior__ = behavior.initFunction;
		element.__initBehavior__();
	}
}

function attachFormBehavior(formname, fieldname, behavior) //alternative: (form, behavior)
{
	attachBehavior(document.forms[formname].elements[fieldname], behavior);
}

function attachBehaviorAll(arr, behavior)
{
	var anzahl = arr.length;
	for (var i=0; i < anzahl; i++)
		attachBehavior(arr[i], behavior);
}

Behavior.prototype.clone = Behavior_clone;
Behavior.prototype.add = Behavior_addEventListener;
Behavior.prototype.change = Behavior_addEventListener;
Behavior.prototype.modify = Behavior_addCode;
Behavior.prototype.setFunction = Behavior_setFunction;
Behavior.prototype.setInitFunction = Behavior_setInitFunction;
Behavior.prototype.eventParamName = "e";

} //_BEHAVIOR_INCLUDED_