﻿/*!
 * cc_core JavaScript Library v1.1.1
 *
 * Copyright 2011, concept-computer GmbH
 *
 * Date: 2011.05.17 
 */

function jsCC_Class() {
	this.debug = false;
	this.lastZInd = 4879;
    this.modules = new Array();
	this.modulesSettings = new Array();
	this.m = new Object(); // Alle modules ueber js_cc.m deklarieren
	this.ExplorerTerms = new Array();
	this.path="";
	this.thema="default";
	this.terms="de";
	// AJAX
	this.responseXML = null;
	this.responseArray = new Array();
}

jsCC_Class.prototype =
{
	init:function(settings)
	{
		if(typeof(settings.thema)!="undefined")
		 js_cc.thema = settings.thema;
		if(typeof(settings.terms)!="undefined")
		{
			if(settings.terms != "") js_cc.terms = settings.terms;
		}
		if(typeof(settings.modules)!="undefined")
		 js_cc.modules = settings.modules;
		if(typeof(settings.debug)!="undefined")
		 js_cc.debug = settings.debug;
		 
		js_cc.initModules();
		
		if(js_cc.debug)
 			js_cc.addEvent(window,"error",js_cc.showErrorMsg);
	},
	
	initPath:function(scriptname)
	{
		var src = document.location.href;
		if(src.indexOf('?')!=-1) src = src.substring(0,src.indexOf('?'));
		src = src.substring(0,src.lastIndexOf('/'));

		if (typeof(scriptname) != "undefined")
		{
			var elements = js_cc.elementsByTagName(document,'script');
			for(i = 0; i < elements.length; i++)
			{
				if(elements[i].src && elements[i].src.indexOf(scriptname) > 0)
				{
					if (elements[i].src.indexOf("://") != -1) src = elements[i].src.substring(0,elements[i].src.lastIndexOf('/'));
					else if (elements[i].src.indexOf("../") != -1)
					{
						var src2 = elements[i].src;
						do
						{
							src = src.substring(0, src.lastIndexOf("/"));
							src2 = src2.substring(3,src2.length);
						}
						while (src2.indexOf("../") != -1);
						src = src + "/"+src2;
						src = src.substring(0,src.lastIndexOf('/'));
					}
					else
					{
						src += "/" + elements[i].src.substring(0,elements[i].src.lastIndexOf('/'));
					}
					break;
				}
			}
		}
		return src;
	},
	
	elementsByTagName:function(parent,tagname)
	{
		var elements = new Array();
		if (document.getElementsByTagName) { elements = parent.getElementsByTagName(tagname); }
		else if (document.all) { elements=parent.all(tagname); }
		return elements;
	},
	
	initModules:function()
	{
		for(var i=0;i<js_cc.modules.length;i++)
		{
			js_cc.loadModule(js_cc.modules[i]);
		}
	},
	
	checkModule:function(name)
	{
			// check contextmenu
		if (!js_cc.in_array("contextmenu",js_cc.modules))
		{
			js_cc.modules.push("contextmenu");
			js_cc.loadModule("contextmenu");
		}
	},
	
	loadModule:function(name)
	{
		js_cc.loadScript(js_cc.path + name+"/cc_"+name+".js");
	},
	
	initTerms:function(modul)
	{
		if(typeof(modul)=="undefined") modul="";
	    var url = js_cc.path+"terms/"+js_cc.terms+((modul=="")?"":("_"+modul))+".xml";

	    js_cc.loadFile({
		url:url,
		rf:"js_cc.initTermsReadXML('"+modul+"');"
		});
	},
	
	initTermsReadXML:function(modul)
	{
		var modul_index= "core";
		if(modul!="")
			modul_index = modul;
		js_cc.ExplorerTerms[modul_index]=new Array();
	
		try 
		{
			var arr = js_cc.XML_Parse();
			if(typeof(arr.items.item)!="undefined" && arr.items.item.length>0)
			{
				for(var i=0;i<arr.items.item.length;i++)
				{
					//alert(arr.items.item[i].attributes["name"] + " = "+arr.items.item[i].value);
					js_cc.ExplorerTerms[modul_index][arr.items.item[i].attributes["name"]] = arr.items.item[i].value;
				}
			}
		}
		catch(e) 
		{
		}
	},
	
	/**
	 * Selection disable/enable
	 */
	disableSelection:function(target,disable)
	{
		if (typeof(disable) == "undefined") disable = true;
		if (typeof(target.onselectstart)!="undefined")
		{
			if(disable) this.addEvent(target,"selectstart",js_cc.cancelEvent);
			else this.removeEvent(target,"selectstart",js_cc.cancelEvent);
		}
		else if (typeof target.style.MozUserSelect!="undefined")
		{
			if(disable) target.style.MozUserSelect="none";
			else target.style.MozUserSelect="";
		}
		else
		{
			if(disable) this.addEvent(target,"mousedown",js_cc.cancelEvent);
			else this.removeEvent(target,"mousedown",js_cc.cancelEvent);
		}
		if(disable) target.style.cursor = "default";
		else target.style.cursor = "";
	},
	
	/**
	 * Liefert Objekt
	 */
	getElement:function(id,create)
	{
		if (typeof(create) == "undefined") create = false;
		if (!document.getElementById) return;
		if (document.getElementById(id)) return document.getElementById(id);
		else if (create)
		{
			var g = document.createElement("div");
			var ind = js_cc.lastZInd;
			js_cc.lastZInd++;
			g.style.cssText='display:none;position:absolute;z-index:' + ind.toString() + ';';
			g.id = id;
			if (document.getElementsByTagName)
				document.getElementsByTagName("body")[0].appendChild(g);
			else if (document.all)
				document.all("body").parentNode.appendChild(g);
			return g;
		}
		else return false;
	},
	
	getAttrib:function(selEl, nm, default_value)
	{
		if(typeof(default_value) == "undefined") default_value = "";
		var v = default_value;
		if (selEl.getAttribute)
		{
			if (selEl.getAttribute(nm,0) != null) v = selEl.getAttribute(nm,0);
		}
		else if (selEl.attributes)
		{
			var oAttrColl = selEl.attributes;
			var oAttr = oAttrColl.getNamedItem(nm);
			if(oAttr != null) v = oAttr.value;
		}
		if (nm == "noWrap") v = selEl.noWrap;
		if (nm == "class") v = selEl.className;
		return '' + v;
	},
	
	/**
	 * Liefert body-object
	 */
	 getRoot:function()
	 {
		 if (typeof(document.body.id) == "undefined") document.body.id = "";
		 if (document.body.id == "") document.body.id = "ccCoreBodyElement";
		 return this.getElement("ccCoreBodyElement");
	 },
	
	/**
	*Liefert Dokument vom Frame
	*@var    string aID - FrameID
	*@return object ifr - Dokument
	*/
	getIFrameDocument:function(aID)
	{
		var ifr;
		if (document.getElementById(aID).contentDocument) ifr = document.getElementById(aID).contentDocument;
		else if (document.frames) ifr = document.frames[aID];
		else if (window.frames) ifr = window.frames[aID];
		else return null;

		if (ifr.document) ifr = ifr.document;
		return ifr;
	},

	/**
	*Liefert Window vom Frame
	*@var    string aID - FrameID
	*@return object ifr - Window
	*/
	getIFrameWindow:function(aID)
	{
		var ifr;
		if (document.getElementById(aID).contentWindow)
		ifr = document.getElementById(aID).contentWindow;
		else if (document.frames)  ifr = document.frames[aID];
		else if (window.frames) ifr = window.frames[aID];
		else return null;

		if (ifr.window) ifr = ifr.window;
		return ifr;
	},
	
	/**
	* Window Position
	*/
	getWindowPosition:function(scrollbars)
	{
		if(typeof(scrollbars) == "undefined") scrollbars = true;
		var x = 0;
		var y = 0;
		if (typeof window.pageXOffset != 'undefined')
		{
			x = window.pageXOffset;
			y = window.pageYOffset;
		}
		else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')
		{
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		}
		else if (typeof document.body != 'undefined')
		{
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}
		
		var h = 0, w = 0;
		if (scrollbars)
		{
			if (document.documentElement) h = parseInt(document.documentElement.scrollHeight);
			if (document.body.scrollHeight > h) h = parseInt(document.body.scrollHeight);
			if (document.body.clientHeight > h) h = parseInt(document.body.clientHeight);
			//if (h > 0) if (!document.all) h += 20; 
			if (document.documentElement) w = parseInt(document.documentElement.scrollWidth);
			if (document.body.scrollWidth > w) w = parseInt(document.body.scrollWidth);
			if (document.body.clientWidth > w) w = parseInt(document.body.clientWidth);
		}
		else
		{
			if (window.innerWidth) w = window.innerWidth;
			else if(document.body && document.body.offsetWidth)
			{
				if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')  w = document.documentElement.offsetWidth;
				else w = document.body.offsetWidth;
			}
			else w = document.body.clientWidth;
			
			if (window.innerHeight) h = window.innerHeight;
			else if (document.body && document.body.offsetHeight)
			{
				if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat')  h = document.documentElement.offsetHeight;
				else h = document.body.offsetHeight;
			} 
			else h = document.body.clientHeight;
		}
		
		return {x:x,y:y,width:w,height:h};
	},
	
	getEventPosition:function(e)
	{
		var sb = js_cc.getWindowPosition();
		var y = (e ? ((typeof(e.pageY) != "undefined") ? e.pageY : (e.clientY + (window.pageYOffset || sb.y))) : 0);
		var x = (e ? ((typeof(e.pageX) != "undefined") ? e.pageX : (e.clientX + (window.pageXOffset || sb.x))) : 0);
		return {x:x,y:y};
	},
	
	/**
	 * HTML-Object erstellen
	 */
	createObject:function(tag,where,attrib)
	{
		if (typeof(where) == "undefined") where = "body";
		if (typeof(where) == "string")
		{
			if (document.getElementsByTagName) where = document.getElementsByTagName(where)[0];
			else if (document.all) where = document.all(where).parentNode;
		}
		var g = document.createElement(tag);
		
		if (typeof(attrib) != "undefined")
		{
			for(var a in attrib)
			{
				this.setAttrib(g,a,attrib[a]);
			}
		}
		
		where.appendChild(g);
		return g;
	},
	setAttrib:function(selEl, nm, val)
	{
		if (val == "0%" || val == "%") val = "";
		if(nm == "style") selEl.style.cssText = val;
		else if(nm == "class") selEl.className = val;
		else if (nm == "noWrap") selEl.noWrap = (val == "false" || !val) ? false : true;
		else if (val != null && val != "" && val != -1) selEl.setAttribute(nm,val);
		else selEl.removeAttribute(nm);
	},
	
	/*#### EVENTS ######################################################################################*/
	
	/**
	 * Fuegt Event fuer Objekt ein
	 **/
	addEvent:function(o,n,h)
	{
		try
		{
			if (o == window && n == "load") { if(document) { if(typeof(document.readyState) != "undefined" && document.readyState == "complete") { window.setTimeout(h,0); } } }
			if(o.attachEvent) o.attachEvent("on"+n,h);
			else if (o.addEventListener) o.addEventListener(n,h,false);
		}
		catch(ext)
		{
			
		}
	},

	/**
	 * Luescht Event fuer Objekt
	 **/
	removeEvent:function(o,n,h)
	{
		try
		{	
			if(o.detachEvent) o.detachEvent("on"+n,h);
			else if (o.removeEventListener) o.removeEventListener(n,h,false);
		}
		catch(ext)
		{
			
		}
	},

	/**
	 * Brecht ausfuehrung des Eventes ab
	 * 
	 * @param event e
	 **/
	cancelEvent:function (e)
	{
		try
		{
			if (e.stopPropagation)
				e.stopPropagation();
			else
				e.cancelBubble = true;

			if (e.preventDefault)
				e.preventDefault();
			else
				e.returnValue = false;

			return false;
		}
		catch(ext)
		{
			return true;
		}
	},

	cancelEvent2:function(e)
	{
		js_cc.cancelEvent(e);
	},
	
	/**
	 * Fehlerbehandlung 
	 */
	showErrorMsg:function (msg, filename, line) 
	{
	//	prompt(msg, filename);
		alert("concept-computer GmbH meldet JavaScript-Fehler:\n" + msg + "\n\nDatei: " + filename + "\nZeile: " + line);
		return true;
	},
	
	/*#### AJAX ######################################################################################*/
	// Array mit Parameter
	loadFileParams : [],
	/**
	 * Parameter hinzufuegen
	 */
	addLoadFileParameter:function(name,value)
	{
		if(typeof(value) == "boolean") value = value ? "1" : "0";
		if(typeof(value) == "number") value = value.toString();
		if(typeof(value) == "string") js_cc.loadFileParams[js_cc.loadFileParams.length] = new Object({name:name,value:value});
		else if(typeof(value) == "object")
		{
			for (var i in value)
			{
				js_cc.addLoadFileParameter(name+"["+i+"]",value[i]);
			}
		}
	},

	postValue:function(key, val, boundary)
	{
		var br = "\r\n";
		var POSTDATA = "--" + boundary + br;
		POSTDATA += "Content-Disposition: form-data; name=\""+key+"\""+br;
		POSTDATA += br + encodeURIComponent(val) + br;
		POSTDATA += "--" + boundary + br;
		return POSTDATA;
	},
	/**
	 * Parameter uebernehmen
	 */
	setLoadFileParameter:function(method, boundary)
	{
		// Parameter listen
		var parameter = "";
		for (var i = 0; i < js_cc.loadFileParams.length; i++)
		{
			if (js_cc.loadFileParams[i].name != "")
			{
				if (method == "POST")
				{
					parameter += js_cc.postValue(jsGeneral.loadFileParams[i].name, js_cc.loadFileParams[i].value, boundary);
				}
				else
				{
					if (parameter != "") parameter += "&";
					parameter += js_cc.loadFileParams[i].name + "=" + encodeURIComponent(js_cc.loadFileParams[i].value);
				}
			}

		}

		return parameter;
	},
	
	/**
	 * Datei laden
	 */
	loadFile:function(settings)
	{
		if (typeof(settings) == "undefined") return false;
		if (typeof(settings.url) == "undefined") return false;
		else var url = settings.url;
		var modus = (typeof(settings.modus) == "undefined") ? 'GET' : settings.modus;
		var request = false;
		//var parameter = js_cc.setLoadFileParameter(modus.toUpperCase());
		var today = new Date();
		url += (url.indexOf("?") == -1 ? "?" : "&") + "tmLsmas="+today.getTime().toString();
		var contentType = (typeof(settings.contentType) == "undefined") ? 'text/xml' : settings.contentType;
		parameter = null;
		if (js_cc.loadFileParams.length > 0)
		{
			if (modus.toUpperCase() == "GET")
			{
				url += (url.indexOf("?") == -1 ? "?" : "&") + js_cc.setLoadFileParameter(modus.toUpperCase());
			}
			else
			{
				var boundary = Math.round(Math.random()*10000000000000);
				boundary = boundary.toString(16);
				boundary = "--------" + boundary.toUpperCase();
				var br = "\r\n";
				contentType = "multipart/form-data; boundary="+boundary;
				parameter = js_cc.setLoadFileParameter(modus.toUpperCase(),boundary);
			}
		}

		if (typeof(settings.parameter) != "undefined")  url += (url.indexOf("?") == -1 ? "?" : "&")+settings.parameter;
		js_cc.responseXML = null;

		if (window.XMLHttpRequest)
		{
		   request = new XMLHttpRequest();
		   if (request.overrideMimeType) request.overrideMimeType('text/xml');
		}
		else if (window.ActiveXObject)
		{
		   try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } 
		   catch (e) {request = false;} }
		}
		if (!request) { alert('Fehler: keine Instanz'); return false;}

		request.onreadystatechange = function()
		{
			if (request.readyState == 4 && request.status == 200)
			{
				if (request.responseXML != null)
				{
					js_cc.responseXML = request.responseXML;
					if (typeof(settings.rf) != "undefined")
					{
						eval(settings.rf);
					}
				}
				else alert('Fehler: Document-Syntax');
			}
		};
		js_cc.loadFileParams = new Array();
		
		request.open(modus, url, true);
		request.setRequestHeader("content-type", contentType);
		if(parameter != null)request.setRequestHeader("Content-length", parameter.length);
		request.setRequestHeader("Connection", "close");
		request.send(parameter);
		
		return true;
	},

	/**
	 * XML Parser
	 *
	 *
	 * Beispiel:
	 * XML:
	 * <ConfigsData>
	 *  <Node DefaultName="Tables">
	 *   <Config ID="1" Name="Konfiguration_1" DefaultKey="1">
	 *     <Field ExportName="border">2</Flied>
	 *     <Field ExportName="cellpadding">3</Field>
	 *     <Field ExportName="cellspacing">1</Field>
	 *     <Field ExportName="background-color">#444444</Field>
	 *   </Config>
	 *   <Config ID="2" Name="Konfiguration_2" DefaultKey="0">
	 *     <Field ExportName="border">1</Flied>
	 *     <Field ExportName="cellpadding">1</Field>
	 *     <Field ExportName="cellspacing">2</Field>
	 *     <Field ExportName="background-color">#888888</Field>
	 *   </Config>
	 *  </Node>
	 * <ConfigsData>
	 *
	 * var arr = js_cc.XML_Parse();
	 * // arr.ConfigsData.Node.Config[0].attributes["Name"] ist "Konfiguration_1"
	 *	for (var i = 0; i < arr.ConfigsData.Node.Config[0].Field.length; i++)
	 * {
	 * 	alert(arr.ConfigsData.Node.Config[0].Field[i].name); // Field
	 * 	alert(arr.ConfigsData.Node.Config[0].Field[i].value); // 2
	 * 	alert(arr.ConfigsData.Node.Config[0].Field[i].attributes["ExportName"]); // border
	 *    ....
	 * }
	 */
	XML_Parse:function(obj)
	{
		if (typeof(obj) == "undefined") obj = js_cc.responseXML;
		if (obj == null) obj = js_cc.responseXML;
			
		var sObj = new Array(), names = new Array(), tmp_arr = new Array(), counter;
		if (obj == null) return sObj;
		for (var n = 0; n < obj.childNodes.length; n++)
		{
			if(obj.childNodes[n].nodeType != 3 && typeof(obj.childNodes[n].tagName) != "undefined")
			{
				if (!js_cc.in_array(obj.childNodes[n].tagName,names)) names.push(obj.childNodes[n].tagName);
				var val = "";
				if (obj.childNodes[n].firstChild)
				{
					val = obj.childNodes[n].firstChild.nodeValue;
					val = js_cc.str_replace(val, String.fromCharCode(153), "&#153;","gi");
					val = js_cc.str_replace(val, String.fromCharCode(8482), "&#153;","gi");
					val = js_cc.str_replace(val, String.fromCharCode(128), "&#128;","gi");
					val = js_cc.str_replace(val, String.fromCharCode(8364), "&#128;","gi");
				}
				
				var Elm = new Object({"name" : obj.childNodes[n].tagName, "value":val,"attributes" : [] });
				if (obj.childNodes[n].attributes.length > 0)
				{
					for (var a = 0; a < obj.childNodes[n].attributes.length; a++)
					{
						var arrt = new Object({"name":obj.childNodes[n].attributes[a].nodeName,"value":obj.childNodes[n].attributes[a].nodeValue});
						Elm.attributes[obj.childNodes[n].attributes[a].nodeName] = obj.childNodes[n].attributes[a].nodeValue;
					}
				}
				counter = 0;
				if (obj.childNodes[n].childNodes.length > 0)
				{
					var childObj = js_cc.XML_Parse(obj.childNodes[n]);
					for (var kw in childObj)
					{
						counter++; break;
					}
					if (counter > 0)
					{
						for (var kw in childObj) Elm[kw] = childObj[kw];
					}
				}
				if (typeof(tmp_arr[obj.childNodes[n].tagName]) == "undefined") tmp_arr[obj.childNodes[n].tagName] = new Array();
				tmp_arr[obj.childNodes[n].tagName].push(Elm);
			}
		}
		for (var keys in names)
		{
			if  (tmp_arr[names[keys]].length == 1) 
			{
				sObj[names[keys]] = tmp_arr[names[keys]][0];
			}
			else
			{
				sObj[names[keys]] = tmp_arr[names[keys]];
			}
		}

		return sObj;
	},
	
	/*#### POSITION ######################################################################################*/
	
	/**
	 * Width festlegen
	 **/
	getWidth:function (obj)
	{
		var Width=obj.clientWidth;
		if(obj.offsetWidth && obj.offsetWidth > Width && (Width == 0 || /msie/i.test(navigator.userAgent))) Width=obj.offsetWidth;//für IE
		return Width;
	},

	/**
	 * Height festlegen
	 **/
	getHeight:function (obj)
	{
		var Height=obj.clientHeight;
		if(obj.offsetHeight && obj.offsetHeight > Height&& (Height == 0 || /msie/i.test(navigator.userAgent))) Height=obj.offsetHeight;//für IE
		return Height;
	},

	/**
	 * X-Position festlegen
	 **/
	getX:function (obj,relative)
	{
		var x=0;
		if (typeof(relative) == "undefined") relative = false;
		if(typeof(obj)=="object" && document.getElementById)
		{
			x=obj.offsetLeft;
			if(obj.offsetParent && !relative)
			{
				x += js_cc.getX(obj.offsetParent);
			}
			return x;
		}
		else return false;
	},

	/**
	 * Y-Position festlegen
	 **/
	getY:function(obj,relative)
	{
		var y=0;
		if (typeof(relative) == "undefined") relative = false;
		if(typeof(obj)=="object" && document.getElementById)
		{
			y=obj.offsetTop;
			if(obj.offsetParent && !relative)
			{
				y += js_cc.getY(obj.offsetParent);
			}
			return y;
		} else return false;
	},
	
	getScroll:function(obj)
	{
		var st = 0, sl = 0;
		var parEl = obj.parentNode;
		while (parEl != null)
		{
			if (parEl == document.body) break;
			if (parEl.scrollTop) st += parEl.scrollTop;
			if (parEl.scrollLeft) sl += parEl.scrollLeft;
			parEl = parEl.parentNode;
		}
		return {scrollTop : st, scrollLeft: sl};
	},

	/**
	 * X- und Y-Position festlegen
	 **/
	getElementPosition:function(obj)
	{
		var scroll = js_cc.getScroll(obj);
		var x = js_cc.getX(obj);
		var y = js_cc.getY(obj);
		var width = js_cc.getWidth(obj);
		var height = js_cc.getHeight(obj);
		return {x:x, y:y, width:width,height:height,scrollTop:scroll.scrollTop,scrollLeft:scroll.scrollLeft};
	},
	
	/*#### LOADING ######################################################################################*/
	
	/**
	 * JavaScript-Datei laden
	 **/
	loadScript:function(url)
	{
		try
		{
			if (document.createElementNS)
				var se=document.createElementNS('http://www.w3.org/1999/xhtml','script');
			else if (document.createElement)
				var se=document.createElement('script');
		}
		catch(e)
		{
			//window.setTimeout(function() { js_cc.loadScript(url,200); });
			return;
		}

		if (typeof (se) != "undefined")
		{
			se.setAttribute('language','javascript');
			se.setAttribute('type','text/javascript');
			se.setAttribute('src', url );

			if (document.getElementsByTagName)
				document.getElementsByTagName("head")[0].appendChild(se);
			else if (document.all)
				document.all("head").parentNode.appendChild(se);

			return true;
		}
		else return false;
	},

	/**
	 * CSS-Datei laden
	 **/
	loadCSS:function(url,doc, media)
	{
		if(typeof(doc)=="undefined") doc = document;
		if(typeof(url)=="undefined") url = "";
		if(typeof(media)=="undefined") media = "all";

		if(url != "")
			var ce = doc.createElement('link');
		else return false;

		if (typeof (ce) != "undefined")
		{
			ce.setAttribute('type','text/css');
			ce.setAttribute('rel','stylesheet');
			ce.setAttribute('media',media);
			ce.setAttribute('href', url );
			try{
			if (document.getElementsByTagName)
				doc.getElementsByTagName("head")[0].appendChild(ce);
			else if (document.all)
				doc.all("HEAD").parentNode.appendChild(ce);
			}
			catch(e) {
				//alert(url + " kann nicht geladen werden!");
			}
			return true;
		}
		else return false;
	},
	
	/**
	 * CSS-Style hinzufuegen
	 */
	addCSS:function(css)
	{
		var g = this.createObject("style","head",{"type":"text/css"});
		if (typeof(g.styleSheet) != "undefined") g.styleSheet.cssText = css;
		else
		{
			try
			{
				g.innerHTML = css;
			}
			catch(ext)
			{
				try{
					var text = document.createTextNode(css);
					g.appendChild(text);
				}
				catch(ext2){}
			}
		}
	},
	
	/*#### TOOLS ###################################################################################*/
	
	/**
	 * Liefert Wert einer Variable aus URL
	 *@var    string nm - Name der Variable
	 *@var    string ps - URL ( wenn nicht definiert URL vom Window )  
	 *@return string 
	 **/
	getParam:function(nm,ps)
	{
		var cons = nm + '=';
		if (typeof(ps) == "undefined") ps = window.location.search;
		if (ps.length > 0)
		{
			var start = ps.indexOf(cons);
			if (start != -1)
			{
				start += cons.length;
				var end = ps.indexOf('&',start);
				if (end == -1) end = ps.length;
				return unescape(ps.substring(start,end));
			}
		}
		return null;
	},
	/**
	 * Prueft, ob ein Wert in einem Array existiert
	 */
	in_array:function(needle, arr)
	{
		var CurStr = new String("," + arr + ",");
		if (CurStr.indexOf("," + needle + ",") == -1) return false;
		else return true;
	},

	/**
	 * Ersetzt alle Vorkommen eines Strings in einem anderen String
	 */
	str_replace:function(in_str,reg_exp,replace_str,opts)
	{
		if(in_str==null) return in_str;
		in_str = in_str.toString();
		if(typeof(opts)=="undefined") opts='g';
		var re=new RegExp(reg_exp,opts);
		return in_str.replace(re,replace_str);
	},
	
	htmlentities:function(str)
	{
		str = this.str_replace(str,"<","&lt;");
		str = this.str_replace(str,"<","&lt;");
		str = this.str_replace(str,'"',"&quot;");
		return str;
	},

	/**
	 * Entfernt Whitespaces (oder andere Zeichen) am Anfang und Ende eines Strings
	 */
	trim:function(str)
	{
		var pos1 = 0, pos2 = str.length, i;
		if (str != "")
		{
			for (i = 0; i < str.length; i++)
			{
				pos1 = i;
				if(str.charCodeAt(i) == 0 || str.charCodeAt(i) == 9 || str.charCodeAt(i) == 10 || str.charCodeAt(i) == 11 || str.charCodeAt(i) == 13 || str.charCodeAt(i) == 32)
				{

				}
				else break;
			}
		}

		if (str != "" && (str.length - 1) > pos1)
		{
			for (i = str.length-1; i >= 0; i--)
			{
				if(str.charCodeAt(i) == 0 || str.charCodeAt(i) == 9 || str.charCodeAt(i) == 10 || str.charCodeAt(i) == 11 || str.charCodeAt(i) == 13 || str.charCodeAt(i) == 32)
				{
					pos2 = i;
				}
				else break;
			}
		}

		if(str != "") str = str.substring(pos1, pos2);
		return str;
	},
	
	/**
	* Kodiert eine Zeichenkette für weitergabe in URL als Wert einer Variable 
	*/
	escape:function(val)
	{
		val = encodeURIComponent(val);
		//val = val.replace(/\+/g,"%2B");
		return val;
	},

	/**
	* Formatiert einer Zahl
	*/
	number_format:function( number, decimals, dec_point, thousands_sep )
	{
	    var n = number, prec = decimals;
	    var toFixedFix = function (n,prec) {
	        var k = Math.pow(10,prec);
	        return (Math.round(n*k)/k).toString();
	    };
	    n = !isFinite(+n) ? 0 : +n;
	    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
	    var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
	    var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
	    var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec);
	    var abs = toFixedFix(Math.abs(n), prec);
	    var _, i;

	    if (abs >= 1000) {
	        _ = abs.split(/\D/);
	        i = _[0].length % 3 || 3;

	        _[0] = s.slice(0,i + (n < 0)) +
	              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
	        s = _.join(dec);
	    } else {
	        s = s.replace('.', dec);
	    }
	    if (s.indexOf(dec) === -1 && prec > 1) {
	        s += dec+new Array(prec).join(0)+'0';
	    }
	    return s;
	},
	
	/**
	* Fügt Zeichenketten vor und nach dem markierten Text in Zielobjekt vom Typ 'input' 
	* @var object input - Zielobjekt
	* @var string aTag  - Zeichenkette, die vor dem markierten Text eingefügt wird
	* @var string eTag  - Zeichenkette, die nach dem markierten Text eingefügt wird
	*/
	inputInsert:function(input, aTag, eTag)
	{
	    input.focus();
	    if(!aTag) return;
	    if(!eTag) eTag = '';

	    if(typeof document.selection != 'undefined')
	    {
	         var range = document.selection.createRange();
	         var insText = range.text;
	         if(!insText && eTag) return alert('Bitte markieren Sie Text!');
	         range.text = aTag + insText + eTag;
	         range = document.selection.createRange();
	         if (insText.length == 0)  range.move('character', -eTag.length);
	         else  range.moveStart('character', aTag.length + insText.length + eTag.length);
	         range.select();
	    }
	    else if(typeof input.selectionStart != 'undefined')
	    {
	         var start = input.selectionStart;
	         var end = input.selectionEnd;
	         var insText = input.value.substring(start, end);
	         if(!insText && eTag) return alert('Bitte markieren Sie Text!');
	         input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);
	         var pos;
	         if (insText.length == 0)  pos = start + aTag.length;
	         else pos = start + aTag.length + insText.length + eTag.length;
	         input.selectionStart = pos;
	         input.selectionEnd = pos;
	    }
	},
	
	/**
	 * Liefert Browserinformation
	 */
	getBrowserInfo:function()
	{
		var info = new Array();

		info["agent"] = navigator.userAgent;
		info["isFirefox"] = /firefox/i.test(navigator.userAgent);
		info["isIE"] = /msie/i.test(navigator.userAgent);
		info["isSafari"] = /safari/i.test(navigator.userAgent);
		info["isOpera"] = (window.opera && opera.buildNumber) ? true : false;
		info["isWebKit"] = /WebKit/.test(navigator.userAgent);
		info["mobile"] = (navigator.platform == "iPhone") ? true : false;
		info["tablet"] = (navigator.platform == "iPad") ? true : false;
		info["isTouchable"] = ('ontouchstart' in window) ? true : false;
		return info;
	},

	/**
	 * Flash-Version
	 */
	_usedFlash: function()
	{
		var FV="";
		var n = navigator;
		if (n.plugins && n.plugins.length)
		{
			for (var i = 0; i < n.plugins.length; i++)
		 	{
				if (n.plugins[i].name.indexOf('Shockwave Flash') != -1)
				{
					FV = n.plugins[i].description.split('Shockwave Flash ')[1];
					break;
				}
			}
		}
		else if (window.ActiveXObject)
		{
			for (var i=16;i>=2;i--)
			{
				try
				{
					var isflash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash."+i+"');");
					if (isflash)
					{
						FV = i.toString()+".0";
						break;
					}
				}
				catch(e) {}
			}
		}
		return FV;
	}
};
js_cc = new jsCC_Class();
js_cc.path = js_cc.initPath("cc_core.js")+"/";
 
if(typeof($)=="undefined")
{
	function $(id)
	{
		return js_cc.getElement(id);
	}
}

var HTMLElements = {
	extend: function(name, fn)
	{
		if ( (!document.all) || (window.opera)  )
		{
			HTMLElement.prototype[name] = fn;
		}
		else
		{
			//override document.createElement
			var _createElement = document.createElement;
			document.createElement = function(tag)
			{
				try
				{
					var _elem = _createElement(tag);
					_elem[name] = fn;
					return _elem;
				} catch(ext) { document.createElement = _createElement; return document.createElement(tag); }
			};
			//override document.getElementById
			var _getElementById = document.getElementById;
			document.getElementById = function(id)
			{
				try
				{
					var _elem = _getElementById(id);
					if (_elem)
					{
						_elem[name] = fn;
						return _elem;
					}
				} catch(ext){ document.getElementById = _getElementById; return document.getElementById(id); }
			};
			
			// override	document.getElementsByTagName
			var _getElementsByTagName = document.getElementsByTagName;
			document.getElementsByTagName = function(tag)
			{
				try
				{
					var _arr = _getElementsByTagName(tag);
					for( var _elem = 0; _elem < _arr.length; _elem++)
					{
						_arr[_elem][name] = fn;
					}
					return _arr;
				}
				catch(ext) { document.getElementsByTagName = _getElementsByTagName; return document.getElementsByTagName(tag); }
			};
		}
	}
};
HTMLElements.extend(
	'add', 
	function (obj)
	{
		if (typeof(obj.type) == "undefined") obj.type = "";
		if (obj.type == "") return;
		obj.add(this);
	}
);
HTMLElements.extend(
	'addEvent', 
	function (n,h)
	{
		js_cc.addEvent(this,n,h);
	}
);
HTMLElements.extend(
	'removeEvent', 
	function (n,h)
	{
		js_cc.removeEvent(this,n,h);
	}
);
window.addEvent = function(n,h){
	js_cc.addEvent(this,n,h);
};
window.removeEvent = function(n,h){
	js_cc.removeEvent(this,n,h);
};
document.addEvent = function(n,h){
	js_cc.addEvent(this,n,h);
};
document.removeEvent = function(n,h){
	js_cc.removeEvent(this,n,h);
};
