/*
 * Function that can be often needed, also in
 * other projects are listet here
 */

	/**
	 * @class Browser
	 * After the initiation of this class, the two
	 * properties "Type" and "Version" contains
	 * the Browsername and the Browser version
	 */
	function Browser()
	{
		var useragent 	= navigator.userAgent;
		var BrowserName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName;
		this.Type	  	= '';
		this.Version  	= '';

		var pos = useragent.indexOf('MSIE');
		if (pos > -1) 
		{
			BrowserVersion 	= useragent.substring(pos + 5);
			var pos 		= BrowserVersion.indexOf(';');
			this.Version 	= BrowserVersion.substring(0,pos);
			this.Type	 	= 'MSIE';
		}
		
		var pos = useragent.indexOf('Opera');
		if (pos > -1)
		{
			BrowserVersion 	= useragent.substring(pos + 6);
			var pos 		= BrowserVersion.indexOf(' ');
			this.Version 	= BrowserVersion.substring(0,pos);
			this.Type	 	= 'Opera';
		}
		
		if (BrowserName == "Netscape") 
		{
			BrowserVersion 	= useragent.substring(8);
			var pos 		= BrowserVersion.indexOf(' ');
			this.Version 	= BrowserVersion.substring(0,pos);
			this.Type	 	= 'Netscape';
		}
		
		if (BrowserName == "Netscape" & parseInt(navigator.appVersion) >= 5) 
		{
			var pos 		= useragent.lastIndexOf('/');
			this.Version 	= useragent.substring(pos + 1);
			this.Type	 	= 'Netscape';
		}
	}
	
	
	
	/**  
	 * Because of attaching events to object are different de different browsers, 
	 * the addEventhandler function can be used to attach an event to an object. 
	 * This function can be used by all Browser types.
	 *
	 * @param #1		: <object>		Object, which will be connected to  the event
	 * @param #2		: <event>		without on "click"
	 * @param #3		: <function>	The function that handles the event
	 */	 
	function addEventHandler (element, event, handler)
	{
		var tmp, event;
		
		if (!element || !event) return false;
		
		if (element.addEventListener)
			element.addEventListener(event, handler, false);
		else {
			sOnEvent = "on"+event;
			if (element.attachEvent) // IE
				element.attachEvent(sOnEvent, handler);
			else {					// older Browser
				tmp = element[sOnEvent];
				element[sOnEvent] = typeof tmp == 'function' ? (function() { tmp(); handler();}) : handler;
			}
		}
	}
	
	/** 
	 * halts the propagation of events in the DOM Hierarachy
	 * @param #1		: <event>
	 */
	function stopPropagation(event)
	{
		if (typeof event.target == "undefined") window.event.cancelBubble = true;
		else if (event.stopPropagation) event.stopPropagation();
	}
	
	/** 
	 * Removes Left & Right White Spaces
	 */
	  String.prototype.trim = function () {
	    return (this.replace(/\s+$/,"").replace(/^\s+/,""));
	  };


	/**
	 * Helper function which checks if an element is
	 * in an array. Use myArray.inArray(element)
	 * 
	 * @param { variant }	Element in array
	 * @return { boolean }	true if element is in array
	 */
	Array.prototype.inArray = function (elem)
	{
	  for (var i = 0; i < this.length; i++)
	  {
	    if (this[i] == elem) return true;
	  }
	
	  return false;
	};
