function CElement(element,kindof,prop)
{
	this.obj;
	this.parentNode = false;
	this.nextNode = false;	
	
	this.IframeforIE = false;
	this.IframeforIEstatus == false;

	this.prop = new Array();
	this.NoDomObj = false;
	this.ObjType = false;
	
	//--- Create new Object or get Existing Node
	this.getObj = function(kindof)
	{	
		if(kindof)
		{
			this.ObjType = kindof;
			this.obj = document.createElement(kindof);		
			this.NoDomObj = true;
		}else{
			if(!element)
			{
				return false;
			}
			if(element == "body")
			{
				this.obj = document.getElementsByTagName('body')[0];
			}else{				
				if(element.nodeType)
				{
					this.obj = element;
				}else{					
					if(document.getElementById(element))
					{
						this.obj = document.getElementById(element);
					}else{						
						return false;
					}				
				}
			}			
			this.parentNode = this.obj.parentNode;
			this.nextNode = this.obj.nextSibling;
			if(!this.parentNode)
			{
				this.NoDomObj = true;
			}
			if(!prop)
			{
				this.getProp();
			}
		}
	}
		
	this.getProp = function()
	{		
		this.prop['display'] = this.getStyle("display");
		
		if(this.prop['display'] == "none")
		{
			this.obj.style.display = "";
		}
		
		this._setBorder()
		this._setLength();
		this._setPosition();
		
		this.setStyle("display",this.prop['display']);		
	}

	this._setLength = function()
	{
		this.prop['width'] = this.obj.offsetWidth;
		this.prop['height'] = this.obj.offsetHeight;
		this.prop['noborderwidth'] = this.prop['width'] - (parseFloat(this.prop['borderLeftWidth']) + parseFloat(this.prop['borderRightWidth']));
		this.prop['noborderheight'] = this.prop['height'] - (parseFloat(this.prop['borderTopWidth']) + parseFloat(this.prop['borderBottomWidth']));
		this.prop['abs_width'] = this.prop['width'];
		if(this.getStyle('marginLeft') && this.getStyle('marginLeft') != "auto")
		{
			this.prop['abs_width'] += parseFloat(this.getStyle('marginLeft'));
		}
		if(this.getStyle('marginRight') && this.getStyle('marginRight') != "auto")
		{
			this.prop['abs_width'] += parseFloat(this.getStyle('marginRight'));
		}
		this.prop['abs_height'] = this.prop['height'];
		if(this.getStyle('marginTop') && this.getStyle('marginTop') != "auto")
		{
			this.prop['abs_height'] += parseFloat(this.getStyle('marginTop'));
		}
		if(this.getStyle('marginBottom') && this.getStyle('marginBottom') != "auto")
		{
			this.prop['abs_height'] += parseFloat(this.getStyle('marginBottom'));
		}
	}

	this._setPosition = function()
	{
		if(!this.NoDomObj)
		{
			this.prop['abs_left'] = getX(this.obj);
			this.prop['abs_top'] = getY(this.obj);
		}
		this.prop['abs_right'] = this.prop['abs_left'] + this.prop['width'];
		this.prop['abs_bottom'] = this.prop['abs_top'] + this.prop['height'];		
		this.prop['left'] = this.obj.offsetLeft;
		this.prop['top'] = this.obj.offsetTop;		
		this.prop['right'] = this.prop['left'] + this.prop['width'];
		this.prop['bottom'] = this.prop['top'] + this.prop['height'];
	}

	this._setBorder = function()
	{
		this.prop['borderTopWidth'] = this.getStyle('borderTopWidth');
		if(isNaN(parseFloat(this.prop['borderTopWidth'])))
		{						
			this.prop['borderTopWidth'] = 0;
		}
		this.prop['borderTopStyle'] = this.getStyle('borderTopStyle');		
		this.prop['borderTopColor'] = ColorRGBToHex(this.getStyle('borderTopColor'));
		this.prop['borderTop'] = this.prop['borderTopWidth'] + " " + this.prop['borderTopStyle'] + " " + this.prop['borderTopColor'];
		this.prop['borderRightWidth'] = this.getStyle('borderRightWidth');
		if(isNaN(parseFloat(this.prop['borderRightWidth'])))
		{
			this.prop['borderRightWidth'] = 0;
		}
		this.prop['borderRightStyle'] = this.getStyle('borderRightStyle');
		this.prop['borderRightColor'] = ColorRGBToHex(this.getStyle('borderRightColor'));
		this.prop['borderRight'] = this.prop['borderRightWidth'] + " " + this.prop['borderRightStyle'] + " " + this.prop['borderRightColor'];
		this.prop['borderBottomWidth'] = this.getStyle('borderBottomWidth');
		if(isNaN(parseFloat(this.prop['borderBottomWidth'])))
		{
			this.prop['borderBottomWidth'] = 0;
		}
		this.prop['borderBottomStyle'] = this.getStyle('borderBottomStyle');
		this.prop['borderBottomColor'] = ColorRGBToHex(this.getStyle('borderBottomColor'));
		this.prop['borderBottom'] = this.prop['borderBottomWidth'] + " " + this.prop['borderBottomStyle'] + " " + this.prop['borderBottomColor'];
		this.prop['borderLeftWidth'] = this.getStyle('borderLeftWidth');
		if(isNaN(parseFloat(this.prop['borderLeftWidth'])))
		{
			this.prop['borderLeftWidth'] = 0;
		}
		this.prop['borderLeftStyle'] = this.getStyle('borderLeftStyle');
		this.prop['borderLeftColor'] = ColorRGBToHex(this.getStyle('borderLeftColor'));
		this.prop['borderLeft'] = this.prop['borderLeftWidth'] + " " + this.prop['borderLeftStyle'] + " " + this.prop['borderLeftColor'];

		//--- alle vier Seiten gleich?
		if(	this.prop['borderTop'] == this.prop['borderRight'] 
			&& this.prop['borderTop'] == this.prop['borderBottom']
			&& this.prop['borderTop'] == this.prop['borderLeft']
			)
		{
			this.prop['border'] = this.prop['borderTop'];
		}		
	}

	//--- zeigt keinen HTML Code an
	this.changeText = function(text,node,getProp)
	{				
		this.obj.firstChild.replaceData(0,text.length,text);
		if(!getProp)
		{
			this._setLength;
			this._setPosition;
		}
	}
	
	this.appendTextNode = function(text)
	{		
		var textNode = document.createTextNode(text);
		this.obj.appendChild(textNode);
		this.getProp();
	}

	this.appendNode = function(parentNode)
	{				
		if(!parentNode)
		{			
			document.getElementsByTagName('body')[0].appendChild(this.obj);
		}else{
			parentNode.appendChild(this.obj);
		}
		this.parentNode = this.obj.parentNode;
		this.getProp();
	}

	this.insertBefore = function(nextNode)
	{		
		nextNode.parentNode.insertBefore(this.obj,nextNode);
		this.parentNode = this.obj.parentNode;
		this.nextNode = this.obj.nextSibling;
		this.getProp();
	}

	this.deleteNode = function()
	{
		this.parentNode = this.obj.parentNode;
		this.nextNode = this.obj.nextSibling;
		this.parentNode.removeChild(this.obj);		
	}

	this.appendChild = function(childNode)
	{
		if(childNode)
		{
			this.obj.appendChild(childNode);
		}
		this.NoDomObj = false;
	}

	//--- Beim clonen müssen die ids - namen neu vergeben werden
	//--- etweige andere probleme beim kopieren beachten
	this.cloneNode = function()
	{
		var cloneNode = new CElement(this.obj.cloneNode(true))
//		var cloneNode = this.obj.cloneNode(true);		
		cloneNode.obj.id = cloneNode.obj.id + "_clone";
		cloneNode.obj.name = cloneNode.obj.name + "_clone";
		return cloneNode;
	}
	
	this.backToDOM = function()
	{
		if(this.nextNode)
		{
			this.insertBefore(this.parentNode,this.nextNode);
		}else{
			this.appendNode(this.parentNode);
		}
		this.NoDomObj = false;
	}

	
	this.attribut = function(attribut,wert)
	{
		eval("this.obj."+attribut+"=wert");
	}

	this.setStyle = function(eigenschaft,wert,newProp)
	{
		if(!isNaN(wert))
		{			
			wert = wert.toString();
		}		
		eigenschaft = getJSStyleName(eigenschaft);

		if(eigenschaft == "backgroundImage" && wert.indexOf("url(") < 0)
		{
			wert = "url('"+wert+"')";
		}

		if(eigenschaft == "float")
		{
			if(getBrowser("IE"))
			{
				eigenschaft = "StyleFloat";
			}else{
				eigenschaft = "cssFloat";
			}
		}

		if(eigenschaft == "opacity")
		{			
			oc = wert;
			if(oc > 100) { oc = 100;}
			if(oc < 0) { oc = 0;}		
			this.obj.style.filter = "Alpha(opacity="+oc+")";
			oc = oc/100;
			this.obj.style.opacity = oc;
			this.obj.style.MozOpacity = oc;
			this.obj.style.KHTMLOpacity = oc;
			return;
		}
		
		if(eigenschaft == "MarkText")
		{
			this.obj.style.unselectable = "";
			this.obj.style.MozUserSelect = "";
			this.obj.style.KhtmlUserSelect = "";
			return;
		}

		if(eigenschaft == "UnmarkText")
		{
			this.obj.style.unselectable = "on";
			this.obj.style.MozUserSelect = "none";
			this.obj.style.KhtmlUserSelect = "none";
			return;
		}
		
		if(wert.indexOf("px") < 0 && wert.indexOf("%") < 0 && wert != "auto" &&
				(
					eigenschaft.indexOf("padding") > -1 || eigenschaft.indexOf("margin") > -1 
				||	eigenschaft.indexOf("left") > -1 || eigenschaft.indexOf("top") > -1
				||	eigenschaft.indexOf("width") > -1 || eigenschaft.indexOf("height") > -1
				)
			)
		{
			wert += "px";
		}
		
		if(wert != "false")
		{
			this.obj.style[eigenschaft] = wert;
		}

		if(!newProp)
		{
			if(eigenschaft == "top" || eigenschaft == "left")
			{
				this._setPosition();		
			}else if(eigenschaft == "width" || eigenschaft == "height" )
			{		
				this._setLength();		
			}else if(eigenschaft.indexOf("border") > -1)
			{
				this._setBorder();
			}
		}
		
//		this.obj.style.display = 'none';
	}

	this.setClass = function(className,prop)
	{		
		this.obj.className = className;
		if(!prop)
		{
			this.getProp();
		}
	}
	
	this.getStyle = function(eigenschaft)
	{		

		if(!eigenschaft)
		{
			return false;
		}

		eigenschaft = getJSStyleName(eigenschaft);
		if(window.getComputedStyle)
		{	
			if(eigenschaft)
			{				
				return window.getComputedStyle(this.obj,"")[eigenschaft];
			}else{				
				return window.getComputedStyle(this.obj,"");
			}
		}else{
			if(this.NoDomObj)
			{
				return false;
			}else{
				return eval('this.obj.currentStyle.'+eigenschaft);
			}			
		}
	}

	this.moveOut = function()
	{		
		this.setStyle("left",0);				
		this.setStyle("top",(this.prop['abs_height'] + 100) * -1);
	}
	
	//--- Iframe zum überlagern von Selectboxen im IE 6
	this.moveIframe = function(status)
	{	
		if(getBrowser("IE"))
		{
			if(!this.IframeforIE)
			{
				this.IframeforIE = new CElement(false,"iframe");
				var body = new CElement("body");
				body.obj.appendChild(this.IframeforIE.obj);
				this.IframeforIE.setStyle("position","absolute");
				this.IframeforIE.setStyle("opacity",0);
				if(this.obj.style.zIndex)
				{
					this.IframeforIE.setStyle("zIndex",this.obj.style.zIndex-1);
				}else{
					this.IframeforIE.setStyle("zIndex",0);
					this.setStyle("zIndex",1);					
				}				
				this.IframeforIEstatus = "move";
			}
			
			if(status == "move" || this.IframeforIEstatus == "move")
			{
				this.IframeforIE.setStyle("left",this.prop['left']);
				this.IframeforIE.setStyle("top",this.prop['top']);
				this.IframeforIE.setStyle("width",this.obj.offsetWidth);
				this.IframeforIE.setStyle("height",this.obj.offsetHeight);
				this.IframeforIEstatus == false;
			}else{
				this.IframeforIE.getStyle("width",1500);
				this.IframeforIE.getStyle("height",1500);
				this.IframeforIE.getStyle("left",-1500);
				this.IframeforIE.getStyle("top",-1500);
				this.IframeforIEstatus == "move";
			}
		}
	}	
	
	this.addEvent = function(type, fn) 
	{
		addEvent (this.obj, type, fn);
	}
	
	this.getObj(kindof);
}

//			return document.getElementsByTagName('body')[0];

//--- wandelt die Parameterliste in ein Array um  -  kann auch nur den Wert eines Parameters zurückgeben falls vorhanden
function getSearch(baseSearch,parameter,unset)
{	
	var arSearch = new Array();
	var baseSearch = (baseSearch) ? baseSearch : window.location.search;	
	var search = "";
	
	//--- Wenn Fragezeichen vorhanden wegschneiden, sonstn hängt es im ersten namen drin
	if(baseSearch.indexOf("?") > -1)
	{	
		search = baseSearch.substr(baseSearch.indexOf("?")+1, baseSearch.length - baseSearch.indexOf("?")) 
	}else{
		search = baseSearch;
	}

	arSearch = strToArray(search,"=","&");

	if(parameter)
	{
		if(unset === true)
		{
			delete arSearch[parameter];
		}else if(arSearch[parameter]){			
			return arSearch[parameter];
		}else{
			return "";
		}
	}				
	
	return arSearch;
}

//--- Schneidet einen "namen" (Parameter) aus einer URL heraus und hängt sie mit angegebenen wert am Ende wieder an 
//--- Also eine ersetzug eines name -> wert paarung in einem url string
function rigUrl(baseUrl,name,wert,send)
{				
	var baseUrl = (baseUrl) ? baseUrl : window.location.href;		
	
	//--- Wenn kein Fragezeichen gefunden, dann anhängen -> wird an url und url_rest weitergegeben
	if(baseUrl.indexOf("?") == -1)
	{
		baseUrl = baseUrl + "?";
	}
	
	var url = baseUrl;
	var searchPattern;
	var pos = -1;
	
	var arSearchPattern = new Array("?" + name + "=", "&" + name + "=");
	for( i = 0; i < 2; i = i + 1 )
	{
		searchPattern = arSearchPattern[i];
		pos = url.indexOf(searchPattern);

		if( pos >= 0 )
		{
			url_rest = url.substr(pos + searchPattern.length);
			pos2 = url_rest.indexOf("&");
			if( pos2 == -1 )
			{
				url = url.substr(0, pos+1);
				url = url + name + "=" + wert;
				break;
			}
			else
			{
				url = url.substr(0, pos+1);
				url = url + name + "=" + wert + baseUrl.substr(pos + searchPattern.length + pos2);
				break;
			}
		}
	}
	
	if( pos == -1 )
	{
		url = url + "&" + name + "=" + wert;
	}
	
	if(send)
	{
		window.location.href = url;
	}else{
		return url;	
	}
}


//--- Decodiert einen String
function url_decode(decode)
{
	decode = decode.replace("%C4","Ä");
	decode = decode.replace("%DC","Ü");
	decode = decode.replace("%D6","Ö");
	
	decode = decode.replace("%E4","ä");
	decode = decode.replace("%FC","ü");	
	decode = decode.replace("%F6","ö");
	
	decode = decode.replace("%DF","ß");
	
	decode = decode.replace("%20"," ");

	return decode;
}

function CmouseoverStyle()
{	
	this.arObj = new Array();	
	this.changeStyle = function(e,arArray)
	{
		var mouseover = arArray[1];
		var clicker = arArray[2];		
		if(!this.arObj[clicker])
		{
			return false;
		}
		
		//--- mouseover	
		if(mouseover)
		{
			var status = "new";
		}else{
			var status = "old";
		}
		
		for(var eigenschaft in this.arObj[clicker][status])
		{
			if(eigenschaft == "class")
			{
				this.arObj[clicker]['handler'].setClass(this.arObj[clicker][status][eigenschaft]);
			}else{
				this.arObj[clicker]['handler'].setStyle(eigenschaft,this.arObj[clicker][status][eigenschaft]);
			}
		}		
	}
	
	//--- neues Object oder neue Eigenschaft hinzufügen
	this.add = function(clicker,handler,eigenschaft,wert)
	{
		if(!clicker || !eigenschaft || !wert)
		{
			return false;
		}		
		if(!handler)
		{
			handler = clicker;
		}
		
		if(!this.arObj[clicker])
		{
			this.arObj[clicker] = new Array();
			this.arObj[clicker]['clicker'] = new CElement(clicker);
			if(!this.arObj[clicker]['clicker'])
			{
				return false;
			}			
			this.arObj[clicker]['handler'] = new CElement(handler);
			if(!this.arObj[clicker]['handler'])
			{
				return false;
			}
			this.arObj[clicker]['old'] = new Array();
			this.arObj[clicker]['new'] = new Array();
			addEvent(this.arObj[clicker]['clicker'].obj,"mouseover",this.changeStyle.scope(this,true,clicker));
			addEvent(this.arObj[clicker]['clicker'].obj,"mouseout",this.changeStyle.scope(this,false,clicker));
		}			
		this.arObj[clicker]['new'][eigenschaft] = wert;
		if(eigenschaft == "class")
		{
			this.arObj[clicker]['old'][eigenschaft] = this.arObj[clicker]['handler'].obj.className;
		}else{
			this.arObj[clicker]['old'][eigenschaft] = this.arObj[clicker]['handler'].getStyle(eigenschaft);
		}
	}
}


function ColorRGBToHex(string)
{
	if(!string)
	{
		return false;
	}
	abschneiden = string.indexOf("rgb");
	string_anfang = string.substring(0,abschneiden);
	string_ende = string.substring(string.indexOf(")",abschneiden)+1);
	
	if(abschneiden > -1)
	{
		
		string = string.substring(abschneiden+4,string.length-1);
		string = string.split(",");
		for(var i = 0; i <= 2; i++)
		{
			var zahl2 = string[i] % 16;
			var zahl1 = (string[i]-zahl2) / 16;			
			switch (zahl1)
			{
				case 10:
					zahl1 = "A";
					break;
				case 11:
					zahl1 = "B";
					break;
				case 12:
					zahl1 = "C";
					break;
				case 13:
					zahl1 = "D";
					break;
				case 14:
					zahl1 = "E";
					break;
				case 15:
					zahl1 = "F";
					break;
				default:
					zahl1 = zahl1.toString();
					break;
			}
			
			switch (zahl2)
			{
				case 10:
					zahl2 = "A";
					break;
				case 11:
					zahl2 = "B";
					break;
				case 12:
					zahl2 = "C";
					break;
				case 13:
					zahl2 = "D";
					break;
				case 14:
					zahl2 = "E";
					break;
				case 15:
					zahl2 = "F";
					break;
				default:
					zahl2 = zahl2.toString();
					break;
			}	
			string[i] = zahl1+zahl2;
		}		
		string = string_anfang + "#" + string[0] + string[1] + string[2] + string_ende;
	}
	return string;
}

//--- gibt die absolute linke Position des Elements zurück, auch wenn es in einem absolute Positioniertem Element steckt
function getX(el)
{
   x = el.offsetLeft;
   if (!el.offsetParent)
	{
		return x;
	}else{
		return (x+getX(el.offsetParent));
	}
}

//--- Pendant zu getX
function getY (el) 
{
   y = el.offsetTop;
   if (!el.offsetParent)
	{	 
		return y;
	}else{
		return (y+getY(el.offsetParent));
	}
}

function getMouse(e,achse)
{
	if(achse != "X" && achse != "x" && achse != "Y" && achse != "y")
	{
		return false;
	}
	
	var wert = 0;
	if(achse == "x" || achse == "X")
	{
		wert = e.clientX;
	}else{
		wert = e.clientY;			
	}			
	if(wert)
	{
		return wert;
	}else{
		return 0;
	}
}

function getScroll(achse)
{
	if(achse != "X" && achse != "x" && achse != "Y" && achse != "y")
	{
		return false;
	}

	if(achse == "x" || achse == "X")
	{
		if (getBrowser("IE"))
		{
			if(getB_Status("noQuirk"))
			{
				return document.documentElement.scrollLeft;
			}else{
				return document.body.scrollLeft;
			}
		}else{
			return window.pageXOffset;
		} 
	}else{
		if (getBrowser("IE"))
		{
			if(getB_Status("noQuirk"))
			{
				return document.documentElement.scrollTop;
			}else{
				return document.body.scrollTop;
			}
		}else{
			return window.pageYOffset;
		}	
	}
}


//--- Gibt Browser zurück
//--- Abfrage:
//--- IE
//--- FF
//--- OP
//--- SA
//--- sonstig

function getBrowser(is_browser)
{
	var browser = false;
	if(navigator.appName.indexOf("Explorer") != -1)
	{
		browser = "IE";		
	}else{
		browser = "FF";	
	}
	
	if(is_browser)
	{
		if(is_browser == browser)
		{
			return true;
		}else{
			return false;
		}
	}
	
	return browser;
}

//--- Abfrage nach dem Doctype
//----- Wenn Doctype angegeben, wird false zurückgegeben, wenn doctype = quirksmodus
function getDocType(doctype)
{	
	if(document.compatMode == "CSS1Compat")		
	{
		if(doctype)
		{
			if(doctype == "quirks")
			{
				return false;
			}else{
				return true;
			}
		}
		return document.compatMode;
	}else{		
		if(doctype)
		{
			if(doctype == "quirks")
			{
				return true;
			}else{
				return false;
			}
		}
		return document.compatMode;
	}
}

function getIframeWindow(id,arIframeParameter)
{
	var Iframe = new CElement(id);	
	Iframe = Iframe.obj;
    var Iframe = Iframe.contentWindow || Iframe.contentDocument;
    if (Iframe.document) {
        Iframe = Iframe.document;
    }
	return Iframe;
}


//--- Gibt Status zurück
//--- Abfrage:
//--- Quirk
//--- noQuirk
function getB_Status(is_status)
{
	var status
	
	if(document.compatMode == "CSS1Compat")
	{
		status = "noQuirk";
	}else{
		status = "Quirk";	
	}
	
	if(is_status)
	{
		if(is_status == status)
		{
			return true;
		}else{
			return false;
		}
	}

	return status;
}

//--- Gibt ein Ereignis zurück
function getE(e)
{
	if (!e)
	{
		e = window.event;
	}
	
	if (!e)
	{
		return false;
	}
	return e;
}

function getETarget(e)
{
	if(getBrowser("IE"))
	{
		return e.srcElement;
	}else{
		return e.target;
	}

}

function StopEvent(e)
{
	if(e.stopPropagation)
	{
		e.stopPropagation();		
	}else{
		e.cancelBubble = true;
	}
}

//--- gibt Cursor Position eines Textarea zurück
function getCursor(idTextarea)
{	
	idTextarea = document.getElementById(idTextarea);
	if(!idTextarea) 
	{
		return false;
	}
	idTextarea.focus();
	
	if (document.selection) 
	{		
		var range = document.selection.createRange();
		var cloneRange = range.duplicate();
		cloneRange.moveToElementText(idTextarea);
		cloneRange.setEndPoint("EndToEnd", range);
		return cloneRange.text.length - range.text.length;			
	}else{
		return idTextarea.selectionStart;		
	}
}

function trim(s)
{
	if(!s || s.length == 0)
	{
 		return "";
	}
	
	if(s)
	{
		return s.replace (/^\s+/, '').replace (/\s+$/, '');
	}
}

//--- Markiert Wörter in einem Text mit einem <span>
function markWord(text,word,style)
{		
	var newText = "";
	var position = 0;
	var searchText = text;	
	var wortLaenge = word.length;
	word = word.replace(/\//, "\\\/");
	//---- Geht nicht per Regulärer Ausdruck, da Groß / Kleinschreibung beachtet werden soll
	while(searchText.search(eval("/"+word+"/i")) > -1)
	{		
		position = searchText.search(eval("/"+word+"/i"))
		newText += searchText.substr(0,position);
		newText += "<span style='"+style+"'>"+searchText.substr(position,wortLaenge)+"</span>";
		searchText = searchText.substr(position + wortLaenge,searchText.length - (position + wortLaenge));
	}
	
	if(newText)
	{
		return newText+searchText;
	}else{		
		return text;
	}
}

//--- alle Tags aus einem String (soll eigentlich nur die hinzugefügten <span> zum markieren von Wörtern rausschmeissen
function remarkWord(text)
{	
	var reg = /<[^>]*>/g	
	return text.replace(reg,"");
}

function selected(id,value)
{
	objSelect = document.getElementById(id)
	if(objSelect && value.length > 0)
	{
		objSelect.value = value;
	}	
}

function isset(variable_name)
{
	try
	{
		if (typeof(eval(variable_name)) != 'undefined')
		{
			if (eval(variable_name) != null)
			{
				return true;
			}
		}
	}catch(e){}
	return false;
}

//--- gibt nur den Dateinamen zurück
function basename(file)
{	
	if(!file)
	{
		file = window.location.pathname;
	}

	var firstSlash = file.lastIndexOf("/");
	if(firstSlash > -1)
	{
		firstSlash++;
	}else{
		firstSlash = 0;
	}
	var parameter = file.indexOf("?");
	if(parameter == -1)
	{
		parameter = file.length - firstSlash;
	}else{
		parameter = file.length - firstSlash - parameter;
	}	
	file = file.substr(firstSlash,parameter);
	return file;
}

function getJSStyleName(cssStyle)
{
	while(cssStyle.indexOf("-") > 0)
	{
		var pos = cssStyle.indexOf("-");
		Zeichen = cssStyle[pos+1].charCodeAt() - 32;		//--- kleines Zeichen Raussuchen und 32 abziehen
		Zeichen = String.fromCharCode(Zeichen);			//--- kleines Zeichen in großes Umwandeln
		//--- Trennzeichen und kleines Zeichen rausfiltern und großes Zeichen einfügen
		cssStyle = cssStyle.substring(0, cssStyle.indexOf("-")) + Zeichen + cssStyle.substring(cssStyle.indexOf("-")+2);
	}
	return cssStyle;
}

function firstElementStyle(obj_main,eigenschaft,wert)
{
	obj_main = document.getElementById(obj_main);
	obj = obj_main.firstChild;			
	while(obj && obj.nodeType && obj.nodeType != 1)
	{
		obj = obj.nextSibling;
	}
	if(obj && obj.nodeType == 1)
	{
		obj = new CElement(obj,false,true);
		obj.setStyle(eigenschaft,wert);
	}
}

function lastElementStyle(obj_main,eigenschaft,wert)
{	
	obj_main = document.getElementById(obj_main);
	obj = obj_main.lastChild;		
	while(obj && obj.nodeType && obj.nodeType != 1)
	{
		obj = obj.previousSibling;
	}	
	if(obj && obj.nodeType == 1)
	{
		obj = new CElement(obj,false,true);
		obj.setStyle(eigenschaft,wert);
	}
	
}


//--- Ajax 

function CAjax(datei,parameter,funktionReceive,funktionExecute)
{
	this.ajax = false;
	if(window.XMLHttpRequest)
	{
		this.ajax = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		this.ajax = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	this.LoadAjax = function(datei,funktionReceive,funktionExecute)
	{
		if(datei)
		{
			this.datei = datei; 
		}
		
		if(funktionReceive)
		{
			this.funktionReceive = funktionReceive
		}else{
			this.funktionReceive = this.Receive.scope(this);
		}

		if(funktionExecute)
		{
			this.funktionExecute = funktionExecute;
		}		
	}
	
	this.Send = function(parameter)
	{			
		if(this.datei)
		{
			if(this.ajax)
			{
				this.ajax.open("POST", this.datei, true);
				this.ajax.onreadystatechange = this.funktionReceive;
				this.ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
				this.ajax.send(parameter);
				return true;
			}
		}
		return false;		
	}

	this.Receive = function()
	{
		if(this.ajax.readyState == 4)
		{
			this.funktionExecute(this.ajax.responseText);			
		};	
	}	
	this.LoadAjax(datei,parameter,funktionReceive,funktionExecute);
}

function arrayToStr(arArray,trenner1,trenner2)
{	
	if ( typeof( arArray ) == "object") 
	{
		var strArray = "";
		trenner1 = (trenner1) ? trenner1 : "=";
		trenner2 = (trenner2) ? trenner2 : ";";
		for(var wert in arArray)
		{
			strArray += wert+trenner1+arArray[wert]+trenner2;
		}
		strArray = strArray.substr(0,strArray.length-1);		
		return strArray;
   }	
	return arArray;
}

function strToArray(strArray,trenner1,trenner2)
{	
	if ( typeof( strArray ) == "object") 
	{
		return strArray;
	}
	var arArray = new Array();	
	trenner1 = (trenner1) ? trenner1 : "=";
	trenner2 = (trenner2) ? trenner2 : ";";
	
	//--- wenn kein Trenner im String gefunden wurde kann man auch nix zerlegen -> Abbruch
	if(strArray.indexOf(trenner1) == -1 && strArray.indexOf(trenner2) == -1)
	{
		return arArray;
	}
	
	var tempArray = strArray.split(trenner2);	
	var tempArray2 = new Array();
	for(var wert in tempArray)
	{	
		tempArray2 = tempArray[wert].split(trenner1);				
		arArray[tempArray2[0]] = tempArray2[1];
	}
	return arArray;
}




function addEvent (obj, type, fn) 
{
	if(!obj)
	{
		return false;
	}
	
	if(obj.addEventListener) 
	{
		obj.addEventListener(type, fn, false);
	} else if (obj.attachEvent) 
	{
		obj.attachEvent('on' + type, function() {
		return fn.call(obj, window.event);
		});
	}
}

function removeEvent (obj, type, fn) 
{	
   if (obj.removeEventListener) {	
      obj.removeEventListener(type, fn, false);
   }    
}

//--- Gibt die X Position des Windows zurück - daruch kann mann ermitteln wo das Window steht
function windowX()
{	
	if(window.screenX)
	{		
		return window.screenX;
	}else if(window.screenLeft)
	{		
		return window.screenLeft;
	}else{
		return 0;
	}
	
}

//--- Gibt die Y Position des Windows zurück
function windowY()
{
	if(window.screenY)
	{
		return window.screenY;
	}else if(window.screenTop)
	{
		return window.screenTop;
	}else{
		return 0;
	}
}


//--- gibt die inner Breite des Fensters zurück
function getScreenWidth(obj)
{			
	if(!obj)
	{
		obj = window;
	}
	
	//---############# beim FF noch die Scrollleiste berücksichtigen!!
	if(getBrowser("IE"))
	{		
		if(getDocType("css"))
		{			
			var screenWidth = parseFloat(obj.document.documentElement.clientWidth); 
		}else{	
			var screenWidth = parseFloat(obj.document.body.clientWidth); 			
		}
	}else{
		var scrollbar = 0;
		if(window.scrollbars.visible)
		{
		//	scrollbar = 17;
		}
		
		var screenWidth = parseFloat(obj.innerWidth)-scrollbar;
	}
	return screenWidth;	
}

//--- gibt die inner Höhe des Fensters zurück
function getScreenHeight(obj)
{
	if(!obj)
	{
		obj = window;
	}
	//---############# beim FF noch die Scrollleiste berücksichtigen!!
	if(getBrowser("IE"))
	{		
		if(getDocType("css"))
		{			
			var screenHeight = parseFloat(obj.document.documentElement.clientHeight);
		}else{	
			var screenHeight = parseFloat(obj.document.body.clientHeight);
		}
	}else{
		var screenHeight = parseFloat(obj.innerHeight);
	}
	return screenHeight;
}

function documentWidth()
{
	var documentWidth = 0;
	return screenWidth;	
}

function documentHeight()
{
	var documentHeight = 0;
	return screenHeight;
}

//--- gibt einen String * sequenz aus (z.B. str_repeat("t",7) => "ttttttt"
function str_repeat(str,sequenz)
{ 
    return new Array(sequenz + 1).join(str);
}

//--- prüft ob es sich um ein array handelt
function is_array(arArray)
{
	return typeof(arArray) == "object" && (arArray instanceof Array);
}

function decho(arArray,isOnload)
{
	var aa = new cAlertArray(arArray,!isOnload);	
}

//--- baut informationen zu einem Array zusammen
function cAlertArray(string,isOnload)
{	
	if(!string)
	{
		return false;
	}

	this.string = string;
	this.tab = 0;
	
	this.__construct = function(isOnload)
	{
		if(isOnload)
		{
			this.builtAlert( false, new Array(false, this.string) );
		}else{
			addEvent(window,"load",this.builtAlert.scope(this,this.string));
		}		
	}
	
	this.builtAlert = function(e,arArray)
	{			
		this.tab += 3;		
		var string = arArray[1];		
		
		var alertStr = "";
		if(is_array(string))
		{			
			var counter  = 0;
			for(var name in string)
			{
				if(is_array(string[name]))
				{
					alertStr += str_repeat("&nbsp;",this.tab) + "[" + name + "] = Array (" + string[name].length + ")";
					alertStr += "<br />";
					alertStr += str_repeat("&nbsp;",this.tab) + "{";
					alertStr += "<br />";
					alertStr += this.builtAlert( true, new Array(false, string[name]) );
					alertStr += str_repeat("&nbsp;",this.tab) + "}<br />";
				}else{
					alertStr += str_repeat("&nbsp;",this.tab) + "[" + name + "] = [" + string[name] + "]<br />";
				}
				counter++;
			}
		}
		this.tab -= 3;
		
		//--- Wenn die id einfach nur true ist, handelt es sich um eine Rekursion und die wird einfach mittels return zurück gegeben
		if(e === true)
		{		
			return alertStr;
		}
		
		if(is_array(string))
		{
			alertStr = "Array (" + counter + ")<br />{<br />" + alertStr + "<br />}<br />";		
		}else{			
			alertStr = string;
		}
		var id = new CElement(false,"pre",true);
		var body = new CElement("body");
		if(body.obj.childNodes.length == 0)
		{		
			id.appendNode(false);		
		}else{						
			//--- such den nächsten nicht PRE knoten
			for(var i = 0; i <= body.obj.childNodes.length; i++)
			{
				childNode = body.obj.childNodes[i];				
				if((getBrowser("IE") && childNode.nodeName == "PRE") || childNode.nodeName != "PRE")
				{
					break;
				}
			}
			id.insertBefore(childNode);
		}
		id.setStyle("backgroundColor","#FFB6C1");
		id.obj.innerHTML = alertStr;		
	}

	this.__construct(isOnload);
}

//--- JS Fehler mitprotokollieren
/*		window.onerror = getError; 
		function getError(eMsg,file,row)
		{
//			alert(eMsg);
//			alert(file);
//			alert(row);
			objImg = document.createElement("img");		
			objImg.src = "test.php?eMsg=" + eMsg + "&file=" + file + "&row=" + row;
			document.getElementsByTagName('body')[0].appendChild(objImg);
		}
*/

//--- Scope austricksen 
//--- (Wenn eine Klassenmethode in einem anderen Scope benutzt werden soll, kann man kein "this" benutzen, da sonst nach einer Methode in dem Scope gesucht wird
//--- Lösung ein Manager, der this durch globale Variablen ersetzt oder eine Simulation des ganzen)
Function.prototype.alt_scope = function(obj) 
{
	var method = this,
	temp = function() 
	{
		return method.apply(obj, arguments);
	};  
	return temp;
}	

Function.prototype.scope = function(obj) 
{
	var args = arguments;
	var method = this;
	return function(event) 
	{		
		return method.apply(obj,[( event ||	window.event)].concat(args));
	};
}	