function Helper () {
}


/* move element with id 'obj_id' to given coordinates */
Helper.prototype.moveTo = function (obj_id, coord_x, coord_y, use_right, use_bottom) {
	try {
		var obj;
		if (document.getElementById(obj_id))
			obj = document.getElementById(obj_id);
		else
			obj = obj_id;
		if (!obj && !obj.style)
			return;
		if (coord_x != null)  {
			if ((typeof coord_x) == "number" || (coord_x.indexOf("px") < 0 || coord_x.indexOf("em") < 0 || coord_x.indexOf("pt") < 0))
				coord_x += "px";
			if (use_right) {
				obj.style.left	= "";
				obj.style.right	= coord_x;
			} else {
				obj.style.left	= coord_x;
				obj.style.right	= "";
			}
		}
		if	(coord_y != null) {
			if ((typeof coord_y) == "number" || (coord_y.indexOf("px") < 0 || coord_y.indexOf("em") < 0 || coord_y.indexOf("pt") < 0))
				coord_y += "px";
			if (use_bottom) {
				obj.style.top		= "";
				obj.style.bottom	= coord_y;
			} else {
				obj.style.top		= coord_y;
				obj.style.bottom	= "";
			}
		}
	}catch(e) {}
}


/* move element with id 'obj_id' to given coordinates starting from its current position*/
Helper.prototype.moveBy = function (obj_id, coord_x, coord_y, use_right, use_bottom) {
	var obj;
	var self = new Helper();
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (!obj)
		return;
	
	var pos = self.getRealCoordinates(obj);
	
	if (coord_x != null)  {
		//if ((typeof coord_x) == "number" || (coord_x.indexOf("px") < 0 || coord_x.indexOf("em") < 0 || coord_x.indexOf("pt") < 0)) {
		if (coord_y.replace) {
			coord_x.replace(/px/, "");
			coord_x.replace(/em/, "");
			coord_x.replace(/pt/, "");
			coord_x = parseInt(coord_x);
		}
		coord_x += pos[0];
		if (use_right) {
			obj.style.left	= "";
			obj.style.right	= coord_x+"px";
		} else {
			obj.style.left	= coord_x+"px";
			obj.style.right	= "";
		}
	}
	if	(coord_y != null) {
		//if ((typeof coord_y) == "number" || (coord_y.indexOf("px") < 0 || coord_y.indexOf("em") < 0 || coord_y.indexOf("pt") < 0))
		if (coord_y.replace) {
			coord_y.replace(/px/, "");
			coord_y.replace(/em/, "");
			coord_y.replace(/pt/, "");
			coord_y = parseInt(coord_y);
		}
		coord_y += pos[1];
		if (use_bottom) {
			obj.style.top		= "";
			obj.style.bottom	= coord_y+"px";
		} else {
			obj.style.top		= coord_y+"px";
			obj.style.bottom	= "";
		}
	}
}




Helper.prototype.resizeTo = function (obj_id, width, height) {
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (!obj)
		return;
	if (width != null) {
		if ((typeof width) == "number" || (width.indexOf("px") < 0 || width.indexOf("em") < 0 || width.indexOf("pt") < 0))
			width += "px";
		try {
			obj.style.width	= width;
		} catch (e) {
			obj.style.width = "0px";
		}
	}
	if	(height != null) { 
		if ((typeof height) == "number" || (height.indexOf("px") < 0 || height.indexOf("em") < 0 || height.indexOf("pt") < 0))
			height += "px";
		try {
			obj.style.height = height;	
		} catch (e) {
			obj.style.height = "0px";
		}
	}
}




/* returns an array with (x,y)-coordinates of given element with id 'obj_id'
 * if 'with_unit' is true, the coordinate units will be returned, too */
Helper.prototype.getCoordinates = function (obj_id, with_unit) {
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (!obj)
		return new Array (0, 0);
	var left	= obj.style.left;
	var top		= obj.style.top;
	if (with_unit)
		return new Array (left, top);
	return new Array (parseFloat(left.substring(0, left.length-2)), parseFloat(top.substring(0, top.length-2)));
}


/* returns an array with (x,y)-coordinates of given element with id 'obj_id'
 * if 'with_unit' is true, the coordinate units will be returned, too */
Helper.prototype.getRealCoordinates = function (obj_id) {
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (!obj)
		return new Array (0, 0);
	var left	= obj.offsetLeft;
	var top		= obj.offsetTop;
	return new Array (left, top);
}




/* returns an array with the real (x,y)-coordinates of given element with id 'obj_id' */
/*Helper.prototype.getRealCoordinates = function (obj_id) {
	return new Array (document.getElementById(obj_id).offsetLeft, document.getElementById(obj_id).offsetTop);
}*/

/* returns an array with the real (x,y)-coordinates of given element with id 'obj_id' absolute to the page */
Helper.prototype.getAbsoluteCoordinates = function (obj_id, depth) {
	var obj;
	var self = new Helper();
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (!obj)
		return null;
	return new Array (self.abs_left(obj, depth, 0), self.abs_top(obj, depth, 0));
}


Helper.prototype.abs_top = function (obj, depth, current) {
	var self = new Helper();
	if (depth) {
		if (depth == current) {
			return obj.offsetTop;
		} else {
			current++;
			return obj.offsetTop+self.abs_top(obj.offsetParent, depth, current)
		}
	}
	return (obj.offsetParent) ? obj.offsetTop+self.abs_top(obj.offsetParent, depth, current) : obj.offsetTop; 
}

Helper.prototype.abs_left = function (obj, depth, current) {
	var self = new Helper();
	if (depth) {
		if (depth == current) {
			return obj.offsetLeft;
		} else {
			current++;
			return obj.offsetLeft+self.abs_left(obj.offsetParent, depth, current)
		}
	}
	return (obj.offsetParent) ? obj.offsetLeft+self.abs_left(obj.offsetParent, depth, current) : obj.offsetLeft; 
}




/* returns an array with the dimension (width, height) of given element with id 'obj_id'
 * if 'with_unit' is true, the coordinate units will be returned, too */
Helper.prototype.getDimension = function (obj_id, with_unit) {
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	var width	= obj.style.width;
	var height	= obj.style.height;
	if (with_unit)
		return new Array (width, height);
	return new Array (parseFloat(width.substring(0, width.length-2)), parseFloat(height.substring(0, height.length-2)));
}


/* returns an array with the real dimension (width, height) of given element with id 'obj_id' */
Helper.prototype.getRealDimension = function (obj_id) {
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	return new Array (obj.offsetWidth, obj.offsetHeight);
}


/* returns an array with the dimension (width, height) of the client area including scrolling offset */
Helper.prototype.getScrollDimension = function () {
	var self = new Helper();
	var x,y;
	var test1		= document.body.scrollHeight;
	var test2		= document.body.offsetHeight;
	var dimension	= self.getInnerDimension();
	if (test1 > test2) {
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	} else {
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}
	if (x < dimension[0])
		x = dimension[0];
	if (y < dimension[1])
		y = dimension[1];
	return new Array (x, y);
}


Helper.prototype.getRealScrollDimension = function (obj_id) {
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (obj.scrollHeight) {
		return new Array (obj.scrollWidth, obj.scrollHeight);
	} else if (obj.offsetHeight) {
		return new Array (obj.offsetWidth, obj.offsetHeight);
	} else
		return new Array (0, 0);
}

/* returns an array with the dimension (width, height) of the client area (without any offsets) */
Helper.prototype.getInnerDimension = function () {
	var x,y;
	if (window.innerHeight) {
		x = window.innerWidth;
		y = window.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	} else if (document.body) {
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	return new Array (x, y);
}


/* returns true, if browser is Internet Explorer 6 */
Helper.prototype.isIE = function () {
	if ((document.all) && (window.offscreenBuffering)) {
		if (!window.XMLHttpRequest)
			return true;
	}
	return false;
}

/* returns true, if browser is Internet Explorer 7 */
Helper.prototype.isIE7 = function () {
	if ((document.all) && (window.offscreenBuffering)) {
		if (window.XMLHttpRequest)
			return true;
	}
	return false;
}

/* returns true, if browser is Safari */
Helper.prototype.isSafari = function () {
	return (navigator.userAgent.toLowerCase().indexOf('safari') != -1);
}


/* returns true, if browser is Netscape */
Helper.prototype.isNetscape = function () {
	if(navigator.appName.indexOf("Netscape") != -1)
		return true;
	return false;
}

/* returns true, if browser is Opera */
Helper.prototype.isOpera = function () {
	return (navigator.userAgent.toLowerCase().indexOf("opera") != -1);
}



/* increases the transparency of given ID 'obj_id' by 'value' */
Helper.prototype.incOpacity = function (obj_id, value) {
	var self = new Helper();
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (self.isIE() || self.isIE7()) {
		var newVal = (parseFloat(obj.filters.alpha.opacity/100) + value)*100;
		obj.filters.alpha.opacity = newVal;
	} else {
		var newVal = parseFloat(obj.style.opacity) + value;
		obj.style.opacity = newVal;
		if (obj.style.MozOpacity != newVal) {
			newVal = parseFloat(obj.style.MozOpacity) + value;
			obj.style.MozOpacity = newVal;
		}
	}
}



/* set the transparency of given ID 'obj_id' to 'value' */
Helper.prototype.setOpacity = function (obj_id, value) {
	var self = new Helper();
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (self.isIE() || self.isIE7()) {
		var newVal = value*100;
		//obj.filters.alpha.opacity = newVal;
		obj.style.filter	= "alpha(opacity="+newVal+")";
	} else {
		obj.style.opacity = value;
		if (obj.style.MozOpacity != value) {
			obj.style.MozOpacity = value;
		}
	}
}



/* switches the image of element with ID 'obj_id' to 'url' */
Helper.prototype.switchImage = function (obj_id, url)	{
	document.getElementById(obj_id).src = url;
}


/* add an event listener for 'event_type' to given object 'obj' and bind function 'event_func' to it */
/*Helper.prototype.addEvent = function (obj_id, event_type, event_func, use_caption) {
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if(!obj) return false;
	if (obj.addEventListener) {
		obj.addEventListener(event_type, event_func, use_caption);
		return true;
	} else if (obj.attachEvent) {
		return obj.attachEvent("on"+event_type, event_func);
	} else {
		return false;
	}
}

Helper.prototype.removeEvent = function (obj_id, event_type, fn ) {
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if(!obj) return false;
	if ( obj.detachEvent ) {
		obj.detachEvent( 'on'+event_type, obj[event_type+fn] );
		obj[type+fn] = null;
	} else
		obj.removeEventListener( event_type, fn, false );
} */

Helper.prototype.addEvent = function ( obj_id, type, fn, use_caption ) {
	var obj;
	var self = new Helper();
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (!obj) return false;	
	if (self.isIE() || self.isIE7()) {
		Event.observe(obj, type, fn, use_caption);
		return true;
	}
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
	} else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
	return true;
}

Helper.prototype.removeEvent = function ( obj_id, type, fn, use_caption ) {
	var obj;
	var self = new Helper();
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (!obj) return false;
	if (self.isIE() || self.isIE7()) {
		Event.stopObserving(obj, type, fn);
		return true;
	}
	if (obj.removeEventListener) {
		obj.removeEventListener( type, fn, false );
	} else if (obj.detachEvent) {
		obj.detachEvent( "on"+type, obj[type+fn] );
		obj[type+fn] = null;
		obj["e"+type+fn] = null;
	}
	return true;
}


Helper.prototype.getBodyScrollPosition = function () {
	var scrollPosX, scrollPosY;
	if (typeof window.pageYOffset != 'undefined') {
		scrollPosX = window.pageXOffset;
		scrollPosY = window.pageYOffset;
	} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
		scrollPosX = document.documentElement.scrollLeft;
		scrollPosY = document.documentElement.scrollTop;
	} else if (typeof document.body != 'undefined') {
		scrollPosX = document.body.scrollLeft;
		scrollPosY = document.body.scrollTop;
	}
	return new Array (scrollPosX, scrollPosY);
}

Helper.prototype.getScrollPosition = function (obj_id) {
	var obj;
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if(!obj) return new Array (0, 0);
	var x,y;
	if (obj.pageXOffset) {	
		x = obj.pageXOffset;
		y = obj.pageYOffset;
	} else {
		x = obj.scrollLeft;
		y = obj.scrollTop;
	}
	return new Array (x, y);
}

Helper.prototype.scrollToBottom = function (obj_id, parent_id) {
	var self = new Helper();
	dim_obj			= self.getRealDimension(obj_id)[1];
	dim_parent		= self.getRealDimension(parent_id)[1];
	coord_obj		= self.getCoordinates(obj_id)[1];
	coord_parent	= self.getCoordinates(parent_id)[1];

	if (dim_obj < dim_parent) {
		self.moveTo(obj_id, null, 0);
	} else {
		self.moveTo(obj_id, null, dim_parent-dim_obj);
	}
}


Helper.prototype.replace = function (string, search, replacetxt) {
	output = "" + string;
	while (output.indexOf(search) >- 1) {
		pos= output.indexOf(search);
		output = "" + (output.substring(0, pos) + replacetxt + output.substring((pos + search.length), output.length));
	}
	return output;
}


Helper.prototype.findImageSources = function (html) {
	if (!html) return new Array ();
	imgs	= new Array ();
	html	= html.toLowerCase().split('<img ');
	for (var i=0; i < html.length; i++) {
		var start = html[i].indexOf('src="')+5;
		var end	  = html[i].indexOf('"', start);
		if (html[i].substring(start, end).length > 4)
			imgs.push(html[i].substring(start, end));
	}
	return imgs;
}


Helper.prototype.preloadImages = function (stringarray) {
	if (!document.pics) document.pics = new Array();
	completed = true;
	for (i in stringarray) {
		if (!document.pics[i]) {
			document.pics[i] = new Image();
			document.pics[i].src = stringarray[i];
		}
		if (!document.pics[i].complete)
			completed = false;
	}
	if (completed)
		document.pics = null;
	return completed;
}


Helper.prototype.hexToDec = function (hex) {
	hex = parseInt (hex, 16);
	return (isNaN(hex)) ? false: hex;
}


Helper.prototype.decToHex = function (dec) {
	hex="0123456789ABCDEF";
	olddec = dec;
	dec = parseInt(dec);
	out = "";
	if (isNaN(dec))
		return false;
	if (dec == 0)
		return "00";
	while (dec != 0) {
		out = hex.charAt (dec%16) + out;
		dec = dec >> 4;
	}
	if (out.length%2 != 0)
			out = "0"+out;
	return out;
}


Helper.prototype.toHexColor = function (col) {
	var self = new Helper();
	if (typeof col == "Array" && col.length == 3) {
		return self.decToHex(col[0]) + self.decToHex(col[1]) + self.decToHex(col[2]);
	} else 	if ( (col.substring(0,1) == "#" && (col.length==7 || col.length == 4)) || 
			(col.length == 7)) {
				col = col.replace("#", "");
				return col;
	}else if (col.substring(0,4) == "rgb(") {
		col = col.replace(/rgb\(/, "");
		col = col.replace(")", "");
		col = col.replace(" ", "");
		col = col.split(",", 3);
		return self.decToHex(col[0]) + self.decToHex(col[1]) + self.decToHex(col[2]);
	}
	
	return "0";
}


Helper.prototype.fadeIn = function (obj_id, onFinish_func, step) {
	var obj;
	var self = new Helper();
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (!step || step == 0) {
		step = 0;
		self.setOpacity(obj_id, 0);
		obj.style.display		= "";
		obj.style.visibility	= "visible";
	}
	if (step < 9) {
		step++;
		self.incOpacity(obj_id, 0.1);
		var self = this;
		setTimeout(function(){self.fadeIn(obj_id, onFinish_func, step);}, 10);
	} else {
		self.incOpacity(obj_id, 0.1);
		if (onFinish_func)
			onFinish_func();
	}
}

Helper.prototype.fadeOut = function (obj_id, displayNone, onFinish_func, step) {
	var obj;
	var self = new Helper();
	if (document.getElementById(obj_id))
		obj = document.getElementById(obj_id);
	else
		obj = obj_id;
	if (!step || step == 0) {
		step = 0;
		self.setOpacity(obj_id, 1);
	}
	if (step < 9) {
		step++;
		self.incOpacity(obj_id, -0.1);
		var self = this;
		setTimeout(function(){self.fadeOut(obj_id, displayNone, onFinish_func, step);}, 10);
	} else {
		self.setOpacity(obj_id, 0);
		if (displayNone == true)
			obj.style.display = "none";
		obj.style.visibility	= "hidden";
		if (onFinish_func) {
			onFinish_func();
		}
	}
}


Helper.prototype.waitForBody = function (callback_func, params) {
	var self = this;

	if (document.body && document.body_loaded && document.body_loaded == 1) {
		callback_func(params);
		return;
	} else {
		setTimeout(function(){self.waitForBody(callback_func, params);}, 100);
		return;
	}
	
	if (callback_func) {
		if (!document.helper_waiting_objects)
			document.helper_waiting_objects = new Array();
		document.helper_waiting_objects.push(new Array (callback_func, params));
	}
	
	
	if (document.body && document.body_loaded && document.body_loaded == 1) {
		if (callback_func)
			callback_func(params);alert(document.helper_waiting_objects);
		while (document.helper_waiting_objects.length > 0) {
			if (document.helper_waiting_objects[0][0])
				document.helper_waiting_objects[0][0](document.helper_waiting_objects[0][1]);
			document.helper_waiting_objects.shift();
		}
	} else {
		setTimeout(function(){self.waitForBody(null, null);}, 100);
	}
}


Helper.prototype.execJS2 = function (node) {
 /* Element auf Javascript überprüfen, und falls nötig ausführen */
 var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
 var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
 var bMoz = (navigator.appName == 'Netscape');
 var st = node.getElementsByTagName('script'); var strExec;
   
 for(var i=0;i<st.length; i++) { if (bSaf) { strExec = st[i].innerHTML; } else if (bOpera) { strExec = st[i].text; }
   else if (bMoz) { strExec = st[i].textContent; } else { strExec = st[i].text; } try { eval(strExec); } catch(e) { alert(e);}}
}


Helper.prototype.execJS = function (obj) {
	var scripts = obj.getElementsByTagName("script");

	for (i=0; i < scripts.length; i++) {
		if (scripts[i].getAttribute("type", false) == "text/javascript") {
			eval(scripts[i].innerHTML);
		}
	}
}

	
Helper.prototype.serialize = function (elem) {
	if (elem == null || elem == undefined || elem.constructor == Function) return 'N;';
	var self = new Helper();
	switch (elem.constructor) {
		case String:  return 's:' + elem.length + ':"' + elem + '";';
		case Number:  return (elem % 1 ? 'd:' : 'i:') + elem + ';';
		case Boolean: return 'b:' + (elem ? '1' : '0') + ';';     
		case Date:    return self.serialize(elem.getTime());
		case RegExp:  return self.serialize(elem.toSource());
		case Error:   return self.serialize(elem.message);
		case Array:
		case Object:
			var content = '', i = 0;
			for (var j in elem) { 
				content += self.serialize(j) + self.serialize(elem[j]);
				i++; 
			}
			return 'a:' + i + ':{' + content + '}';
		default:
			return self.serialize(elem.toString());
	}
}


String.prototype.trim = function () {
	var self = new Helper();
    return (self.replace(/\s+$/,"").replace(/^\s+/,""));
};



document.helper = new Helper();