/*JONAS*/

GlobalInformation = new function() {
    this.RegistredConfirmations = new Array();
}

info = new function() {
    this.File = null;
    this.FilePath = "//index.php";
    this.GET = "";
    this.UseExternelIframe = false;
    this.UseExternelLoaded = false;
    this.UseExternel = function() {
    	document.domain = window.location.host;
    	info.UseExternelIframe = true;
    };
};

/**
 *	Last-Modifyed: 	01.09.08
 *	Author:			Jan Guth
 **/
(function() {
    var cwOffice = window.cwOffice = {};
    //
	cwOffice.lib = new function() {
		var isLoading = false;
		var options = {
			protocol: window.location.protocol,
			host: window.location.host,
			root: "JavaScript/cwOffice"
		};
		this.setOptions = function(root, host, protocol) {
			var ishost = host;
			var root = root || options.root;
			var host = host || options.host;
			options.protocol = protocol || options.protocol;
			options.host = host.replace(new RegExp("^("+options.protocol+"//)"), "");
			if((new RegExp("^("+options.protocol.replace(/:$/, '')+"s?://)")).test(root))
				options.root = root.replace(new RegExp("^(?:"+options.protocol.replace(/:$/, '')+"s?://)?[^/]+/?"), "");
			else
				options.root = root;
			
			if(!ishost) {
				options.host = root.match((new RegExp("^(?:"+options.protocol+"//)?([^/]+)/?")))[1];
			}
		};
		this.load = function(lib, dyn, src) {
			isLoading = true;
			if (!dyn) {
				if(/\.css$/.test(lib))
				{
					document.write('<link rel="stylesheet" type="text/css" href="'+options.protocol+'//' + options.host + "/" + options.root + "/" + lib +'" />');
				}
				else
				{
					document.write('<script type="text/javascript" src="'+options.protocol+'//' + options.host + "/" + options.root + "/" + lib +'"></script>');
				}
			}
			else {
				var e;
				if(/\.css$/.test(lib))
				{
					e = document.createElement('link');
					e.rel = 'stylesheet';
					e.type = 'text/css';
					e.href = options.protocol+"//" + options.host + "/" + (src?lib:options.root + "/" + lib);
				}
				else {
					e = document.createElement("script");
					e.src = options.protocol+"//" + options.host + "/" + (src?lib:options.root + "/" + lib);
					//console.info(e.src);
					e.type = "text/javascript";
				}
				document.getElementsByTagName("head")[0].appendChild(e);
				e = null;
			}
//			var erg = /.*cwOffice\.([^\.]+)\.js$/.exec(lib);
//			if(erg) {
//				var i = 0;
//				while(isLoading) {
//					i++;
//					if(i > 999) break;
//				}
//			}
		};
		this.loaded = function() {
			isLoading = false;
		}
	}

    /**
     *	Core functions start ... (old jSconup.js)
     **/
    jS = cwOffice.jS = window.jS = new function() {
    	this.events = new function() {
    		var _events = {};
    		this.add = function(type, func) {
    			if(!_events[type]) _events[type] = [];
    			_events[type][_events[type].length] = func;
    		};
    		this.remove = function(type, func) {
    			var vRet = null
    			if(!_events[type]) return false;
    			
    			for(var i=0;i<_events[type].length;i++) {
    				if(_events[type][i] === func) {
    					delete _events[type][i];
    				}
    			}
    			return true;
    		};
    		this.fire = function(type) {
    			var vRet = null;  
    			if(!_events[type]) return vRet;
	
    			for(var i=0;i<_events[type].length;i++) {
    				vRet = _events[type][i].apply(cwOffice, arguments);
    			}
    			return vRet;
    		};
    	};
        this.session = new function() {
            var sessionObject = {};

            var prefs = this.preferences = {
                autoFlush: true,
                toJson: cwOffice.toJSONString
            };

			function init() {
				try {
					eval('sessionObject = ' + top.name);
					if (!sessionObject) {
						sessionObject = {};
					}
				}
				catch (e) {
					sessionObject = {};
				}

//				var f = function() {
//					if (prefs.autoFlush) {
//						cwOffice.jS.session.flush();
//					}
//				};
//
//				if (window["addEventListener"]) {
//					addEventListener("unload", f, false);
//				}
//				else if (window["attachEvent"]) {
//					window.attachEvent("onunload", f);
//				}
//				else {
//					prefs.autoFlush = false;
//				}
			}
            this.flush = function() {
                var jsonStr = prefs.toJson(sessionObject);
                top.name = jsonStr;
            };
            this.clear = function() {
                sessionObject = {};
                cwOffice.jS.session.flush();
            };
            this.set = function(key, value) {
                sessionObject[key] = value;
            };
            this.get = function(key) {
                return sessionObject[key];
            };

			init();
        };

        this.hashListener = new function() {
            var sto = null;
            var frameName = null;
            this.run = function(hash, interval) {
                if (window.location.hash == hash) {
                    sto = setTimeout(function() {
                        cwOffice.jS.hashListener.run(hash, interval);
                    }, interval);
                }
                else {
                    //cwOffice.jS.req(window.location.hash.substr(1));
					cwOffice.jS.hashListener.parse();
                }
            };
            this.set = function(hashValue) {

                // TODO: logic edotr iframe -- IE (Access dinied..)
                var key = (new Date()).getTime();//parseInt(Math.random() * 999999999999999);
                var oldKey = top.location.hash.substr(1);

                var cwoHistory = cwOffice.jS.session.get('cwoHistory') || {};
				for(var cwoKey in cwoHistory) {
					if(oldKey < cwoKey) delete cwoHistory[cwoKey];
				}
                cwoHistory[key] = hashValue;
                cwOffice.jS.session.set('cwoHistory', cwoHistory);
				cwOffice.jS.session.flush();

                top.location.hash = key;

                if ('\v' == 'v' && !document.getElementById(frameName)) {
                    cwOffice.jS.hashListener.init();
                }
            };
            this.start = function(interval) {
                var interval = interval || 1000;

                cwOffice.jS.hashListener.stop();
                cwOffice.jS.hashListener.run(window.location.hash, interval);
            };
            this.stop = function() {
                clearTimeout(sto);
                sto = null;
            };
            /**
             * IE workaround for history object
             * @param {String} pFrame
             */
            this.init = function(pFrame) {
                frameName = pFrame || 'cwoHistoryFrameIE';
                var frame = document.getElementById(frameName);
                if (!frame && '\v' == 'v') {
                    frame = window.document.getElementsByTagName('body')[0].appendChild(document.createElement('iframe'));
                    frame.setAttribute('id', frameName);
                    frame.src = '/JavaScript/cwOffice/cwoHistoryIE.html?' + window.location.hash.substr(1);
                    frame.style.visibility = 'hidden';
                    frame.style.position = 'absolute';
                }
                frame = null;
				//alert(frame);
            };
            this.issetHashObject = function() {
                var key = top.location.hash.substr(1);
                if (key) {
					var cwoHistory = cwOffice.jS.session.get('cwoHistory');
                    return (cwoHistory && cwoHistory[key] ? true : false);
                }
                return false;
            };
            this.parse = function() {
                var key = top.location.hash.substr(1);
                if (key) {
					var cwoHistory = cwOffice.jS.session.get('cwoHistory');
                    var jsonStr = cwoHistory[key];
                    if (jsonStr) {
                        cwOffice.jS.req(jsonStr);
						//delete cwoHistory[key];
						cwOffice.jS.session.set('cwoHistory', cwoHistory);
                        return true;
                    }
                }
				else {
					// Reload if there is no hash code
					//window.location.reload();
				}
                return false;
            };
        };
        this.showErrorBox = function(message, stack) {
            if(CW2ErrorBox)
            {
				CW2ErrorBox.Error(message, stack.replace(/</g, "&lt;"))	
            }
            else
            {
	            var body = document.getElementsByTagName("body")[0]; 
	            var div = document.createElement("div");
	            div.id = "xhrError";

	            div.innerHTML = "<div>" +
	            "<h4 id='xhrErrorTitle'>An Error Occured:</h4>" +
	            "<textarea>" +
	            message +
	            "\nStack:\n" +
	            stack.replace(/</g, "&lt;") +
	            "</textarea>" +
	            "<br /><br /></div>" +
	            "<div id='xhrErrorBackground'>&nbsp;</div>";
	            var a = document.createElement("a");
	            a.onclick = function() {
	                body.removeChild(div);
	                div = null;
    				body = null;
	            }
	            a.innerHTML = "<b><h1>[ CLOSE ERROR WINDOW ]</h1></b>";
	            div.childNodes[0].appendChild(a);
	            body.appendChild(div);
				a = null;
			}
        }; 
        this.xhr = new function() {
            this.isExec = false;
            this.ispA = false;
            this.ispB = false;
            this.ispC = false;
            this.obj = new function() {
            	if (window.XMLHttpRequest && ! (/MSIE (\d+\.\d+);/.test(navigator.userAgent) && (new Number(RegExp.$1)) == 9))
                    return new window.XMLHttpRequest();
                else
                    try {
                        return new window.ActiveXObject("MSXML2.XMLHTTP");
                    }
                    catch (ex) {
                        try {
                            return new window.ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (ex) {
                            alert("Faild to generate a new XMLHTTPREQUEST");
                        }
                    }
            };
            this.cfg = new function() {
                this.async = true;
                this.method = "POST";
            };
        };
        this.queue = new function() {
        	this.lowprio = false;
            this.pA = new function() {
                var items = [];
                this.set = function(item) {
                	if(jS.queue.lowprio === true) {
                		jS.queue.pB.set(item);
                		jS.queue.lowprio = false;
                		return;
                	}

    				var time = (new Date()).getTime();
    				var event = item.e || item.event;
    				var name = item.c || item.getControls;
    				name = (name && name.length > 0)?name[0]['n']||name[0]['name']:'default';
    				name = name || 'default';
    				if(event == 'click') {
    					if(jS.clickDelay[name] == null || (time-jS.clickDelay[name]) > 300) {
    						jS.clickDelay[name] = time;
    					}
    					else {
    						jS.clickDelay[name] = null;
    						return;
    					}
    				}
					
					// 15.09.11 - Verschoben
					// Bugfix Falls ein RepeaterEvent ausgefuehrt wird sollem alle anderen Repeater geloescht werden
					if(/cwAutoRepControl/i.test(cwName(item))) {
						this.clear(true);
					}

                    items.push(item); 
					if ('v' == '\v' ) { //&& $cw(item).getRawValue
						// WAIT FOR FORMAT IE -- change event order
						setTimeout(function() {
							jS.req();
						}, 1);
					}
					else {
						jS.req();
					}
                };
                this.get = function() {
			      return items;
                };
                this.clear = function(onlyRepeaterEvents) {
	//alert('here');
					// Bugfix Falls ein RepeaterEvent ausgefuehrt wird sollem alle anderen Repeater geloescht werden
					var onlyRepeaterEvents = onlyRepeaterEvents || false;
					if( ! onlyRepeaterEvents) {
						items = [];
					}
					else {
						for(var i=0;i<items.length;i++) {
							if(/cwAutoRepControl/i.test(cwName(items[i])))
								delete items[i];
						}
					}
                };
            };
            this.pB = new function() {
                var items = [];
                this.set = function(item) {
                    items.push(item);
                    jS.req();
                };
                this.get = function() {
                    return items;
                };
                this.clear = function() {
                    items = [];
                };
            };
            this.pC = new function() {
                var items = [];
                this.set = function(item) {
                    items.push(item);
                    jS.req();
                };
                this.get = function() {
                    return items;
                };
                this.clear = function() {
                    items = [];
                };
            };
            this.check = function() {
                if (jS.queue.pA.get().length > 10) {
                    //location.reload();
                }
                if (jS.queue.pB.get().length > 20) {
                    jS.queue.pB.clear();
                }
                if (jS.queue.pC.get().length > 30) {
                    jS.queue.pC.clear();
                }
                var vRet = false;
                if (jS.queue.pA.get().length != 0) {
                    jS.xhr.ispA = true;

//console.info( jS.queue.pA.get().length)
//for(var foo in jS.queue.pA.get()) console.warn(foo);
                    vRet = jS.queue.pA.get().shift();
//console.info(vRet);
                }
                else if (jS.queue.pB.length != 0) {
                    jS.xhr.ispB = true;
                    vRet = jS.queue.pB.get().shift();
                }
                else if (jS.queue.pC.get().length != 0) {
                    this.ispC = true;
                    vRet = jS.queue.pC.get().shift();
                }
               
                var cal = jS.events.fire('GetNextRequest', vRet);
                if(cal === false) return false;
     
                if(cal !== null && (typeof(cal) == 'object' || cal === false)) {
                	//console.warn(cal);
                	vRet = cal; // 
                }
                return vRet;
            };
        };
        this.execRequestsParse = false;
        this.RepeaterPrototype = null;
        this.clickDelay = {};
        this.req = function(base64string) { //exec_times
            //window.jS.hashListener.stop();
			//console.info(jS.queue.pA.get());
        	if(info.UseExternelIframe === true && info.UseExternelLoaded === false) return;
        	
            var base64string = base64string || false;
            if (!base64string) {

                if (jS.xhr.isExec) {
                    if (!jS.xhr.ispA) {
                        if (jS.xhr.ispB || jS.xhr.ispC) {
                            jS.xhr.ispB = false;
                            jS.xhr.ispC = false;
                            try {
                                jS.xhr.obj.abort();
                            }
                            catch (e) { 
                            }
                        }
                        else {
                            return false;
                        }
                    }
                    else {
        				/*exec_times = exec_times || 0;
                    	if(exec_times > 5) {
        					jS.xhr.ispA = false;
        					jS.req();
        					return false;
        				}                            
        		
        				setTimeout(function(){ jS.req(false, ++exec_times); }, 200);*/
        				cwOffice.debug.out('Exit. A request is already running... retry in 200mils');
                        return false;
                    }
                }
                jS.xhr.isExec = true;

                var obj = jS.queue.check();                             
				obj = jS.convertToShortVars(obj);
			
				cwOffice.debug.out('Get next queue obj ...');
			//	console.warn(obj);
                if (!obj) {
                    jS.xhr.isExec = false;
                    jS.xhr.ispA = false;
                    jS.xhr.ispB = false;
                    jS.xhr.ispC = false;
                    //window.jS.hashListener.start();
                    cwOffice.util.loading.hide();
                    cwOffice.debug.out('queue obj undefined return false!');
                    return false;
                }

                var element = $c(cwName(obj));
                //alert(element);
               //if(element) alert(element.getAttribute('cwoDisable')+ "as");
               //if(element && element.cwoDisable) console.info(element.cwoDisable[obj.e]);
				if (element && ( element.getAttribute('cwoDisable') === obj.e || (element.cwoDisable && element.cwoDisable[obj.e] == true) || element.cwoDisable && element.cwoDisable.event === obj.e))
                {
                	// Ueberpruefen ob cwoDisable ein Attribut ist oder eine Variable
					// Entfehrnung des Events
                    if(element.cwoDisable && element.cwoDisable[obj.e] == true) {
                    	delete element.cwoDisable[obj.e];
                    }
                    else {
	                	element.cwoDisable = false;
	                    element.removeAttribute('cwoDisable');
                    }
                    //window.jS.hashListener.start();
                    cwOffice.util.loading.hide();
                    jS.xhr.isExec = false;
                    jS.xhr.ispA = false;
                    jS.xhr.ispB = false;
                    jS.xhr.ispC = false;
                    jS.req();
                    
                    return false;
                }

            }
                 var sendObj = null;
       		if(info.UseExternelIframe === false) { 
//console.info(jS.xhr.obj);
            jS.xhr.obj.open(jS.xhr.cfg.method, (info.File!=null?info.File:window.location.pathname) + (info.File!=null&&/\?[^\?]+$/.test(info.File)?"&":"?") + (new Date()).getTime() + "&" + (info.GET != "" ? "&" + info.GET : location.search.replace(/^\??(.*)$/, "$1")), jS.xhr.cfg.async);
            jS.xhr.obj.onreadystatechange = function() {
                // try {
                if(jS.xhr.obj.aborted) // Wg. Fehler im IE (http://www.enkeladress.com/article.php/internetexplorer9jscripterror)
                { 
					// IE Bugfix -> reset aborted
					jS.xhr.obj.aborted = false;
					cwOffice.util.loading.hide();
					jS.xhr.isExec = false;
					jS.xhr.ispA = false;
					jS.xhr.ispB = false;
					jS.xhr.ispC = false;
					jS.req();
					return;
                }
				cwOffice.debug.out('onreadystatechange ['+jS.xhr.obj.readyState+']');
                if (jS.xhr.obj.readyState == 4) {
			 	//if(console)console.timeEnd('request send');
                	if('v' == '\v') { 
                	 	if(jS.xhr.obj.status == 12030) {   // Sollte man evtl auch noch folgende Fehlercodes abfangen? 12029, 12031, 12152, 12159
						 		try {
									cwOffice.debug.out('resend request (IE) ['+jS.xhr.obj.status+']');
						 			jS.xhr.obj.send(null);
							   		jS.xhr.obj.send(sendObj);
						 		} catch(e) {}
						 		return;
                	 	}
                	}
                	if(jS.xhr.obj.status !== 200 &&
                	 jS.xhr.obj.status !== 0)
                	  jS.showErrorBox(ServerVars.Language.ErrorBoxMessage, ServerVars.Language.ErrorBoxMessage_ServerError+"\nHTTP Status Code:" + jS.xhr.obj.status);
                    
                	if (jS.xhr.obj.responseText != "" && jS.xhr.obj.responseText != "0") {
                    	var foo;
                        if (!obj || obj.n != "Ignore") {
                        	parseResponseTxt(jS.xhr.obj.responseText);
                        	if(typeof(cwOffice.CwAutoCompletion) != 'undefined') {
                        		cwOffice.CwAutoCompletion.refreshInstances();
                        	}
                        }
                        else {
                            $c("cwAutoControl[GlobalRequest]").innerHTML = "";
                        }
                        foo = null;
                    }
                    obj = null;
                    
                    cwOffice.util.loading.hide();
                    jS.xhr.isExec = false;
                    jS.xhr.ispA = false;
                    jS.xhr.ispB = false;
                    jS.xhr.ispC = false;
                    jS.req();
                }
                //                }
                //                catch (e) {
                //                }
            };
	
	        jS.xhr.obj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			if('v' != '\v')
            	jS.xhr.obj.setRequestHeader("Connection", "close");
			//jS.xhr.obj.overrideMimeType("text/html; charset=ISO-8859-1");
       }
            if (!base64string) {
                var sendObj = "ajaxObject=" + encodeURIComponent(toJson(obj).replace(/\\/g, "\\"));
            }
            else {
            	sendObj = base64string;
            }
			cwOffice.debug.out('send request...');
			if(info.UseExternelIframe === true) {
				document.getElementById('webapp.portal.cw2').contentWindow.core.send(sendObj);  
			}
			else {
				//console.warn(sendObj);
				//alert(sendObj);    
				
				jS.xhr.obj.send(sendObj);
			}
		
            if(cwOffice.keybind) {
            	cwOffice.keybind.parse(obj, sendObj);
            }
            
            sendObj = null;
            base64string = null;
            /*if (obj && obj.e == 'click') {
                //window.jS.hashListener.set(Base64.encode(sendObj));
				//window.jS.hashListener.set(cwOffice.toJSONString(sendObj));
            }
            window.jS.hashListener.start();*/
        };
        this.func = null;

		var patterns = {
			"name":"n",
			"Name":"n",
			"RepeaterName":"r",
			"RepeaterRepID":"i",
			"setAttributes":"s",
			"getAttributes":"a",
			"attributes":"a",
			"php":"p",
			"event":"e",
			"getControls":"c",
			"value":"v",
			"IsChecked":"c"
		};
		this.convertToShortVars = function(tthis) {
			
			if(/(string|number|boolean|undefined)/i.test(typeof(tthis)) || !tthis) return tthis;
			var tmp = null;
     
	        if (tthis.length) {     
				tmp = [];
				for (var i = 0; i < tthis.length; i++) {
					tmp[i] = jS.convertToShortVars(tthis[i]);
				}
			}
			else {
				tmp = {};
				for (var a in tthis) {  
					if(tthis.hasOwnProperty(a)) {
						if (patterns[a]) {        
							tmp[patterns[a]] = jS.convertToShortVars(tthis[a]);
						}
						else {                                 
							tmp[a] = tthis[a];
						}
					}
				}
			}                   
	        try { 
	        	return tmp;
	        } 
	        finally { tmp = null; }
		}
    };
    cwOffice.externel = {};
    parseResponseTxt = cwOffice.externel.parseResponseTxt = function(txt) {
    	//setTimeout(function() {
    	//console.warn(jScc);
    		var doParse = true;
    		if(txt.length > 60000) doParse = false;
    		if(jS.execRequestsParse === true) {
    			setTimeout(function() {
    				parseResponseTxt(txt);
    			}, 20);
    			return;
    		}
    		jS.execRequestsParse = true;
    		var foo = txt;
    		try {
        		eval("txt = " + txt);
        	}
            catch (e) {
				foo = false;
				jS.showErrorBox(ServerVars.Language.ErrorBoxMessage, ServerVars.Language.ErrorBoxMessage_InvalidJSON+"\n"+jS.xhr.obj.responseText);
            }
	    	if (txt != false) {
				cwOffice.debug.out('parse response');
				
	        	jScc.parse(txt, doParse);
	        }
	    	
	        if (jS.func != null) {
	            jS.func(txt);
	            jS.func = null;
	        }
	        txt = null;
	        
	        jS.execRequestsParse = false;
    	//}, 1);
    }
    //cwOffice.externel.parseResponseTxt = parseResponseTxt;

    jScc = window.jScc = cwOffice.jScc = new function() {
        //        this.pA = [];
        //        this.pB = [];
        //        this.pC = [];

        this.parse = function(json, doParse) {
            if (typeof(json) == 'string') {
                json = cwOffice.parseJSON(json);
            }
            each(json["c"], function(value) {
            	createControl(value, doParse);
                value = null;
            });
            each(json["m"], function(value, key) {
            	createMedia(value);
                value = null;
            });
            json = null;
        };
    };
    function $typeof(type) {
        switch (typeof(type)) {
            case 'string':
            return String;
            case 'number':
            return Number;
            case 'array':
            return Array;
            case 'object':
            return Object;
            case 'boolean':
            return Boolean;
            default:
            return false;
        }
    }
    function each(tthis, handler) {
        if (typeof(tthis) === "array") {
            for (var i = 0; i < tthis.length; i++) {
                handler(tthis[i], i);
            }
        }
        else if (typeof(tthis) == "object") {
            if (typeof(handler) === "function") {
                for (attr in tthis) {
                    if ($typeof(tthis[attr]) && !$typeof(tthis[attr]).prototype[attr]) {
                        handler(tthis[attr], attr);
                    }
                }
            }
        }
        handler = null;
    }

    function clone(tthis) {
        var tmp = tthis.constructor();
        if (tthis.length)
            for (var i = 0; i < tthis.length; i++)
                tmp[i] = tthis[i];
        else
            for (var a in tthis)
                tmp[a] = tthis[a];
        
        try {
        	return tmp;
        } finally { tmp = null; }
    }
    toJson = window.toJson = cwOffice.toJson = function(tthis) {
		cwOffice.debug.out('get controls of obj');
///		console.warn(tthis);
        var vRet;
        var php = tthis.php;
        var obj = tthis;
        var AdditionalCode = '';
		var bodyInnerHTML = "";
		var RepeaterName = "";

		var ignoreControl = [];
			//console.warn(obj.c);
   // console.info(obj);
        if(jS.RepeaterPrototype && obj.r != '')
        {//console.info(obj);
        	var getPrototypeControls = jS.RepeaterPrototype[obj.n];
        	if(getPrototypeControls)
        	{
        		var getControls = [];
        		getControls[getControls.length] = {n:obj.n,r:obj.r,i:obj.i,a:{v:true,IsChecked:true}};
				each(getPrototypeControls.c, function(key, value){
					if(key != obj.n) {
						getControls[getControls.length] = {n:key,r:obj.r,i:obj.i,a:{v:true,IsChecked:true}};
					}
				});
				obj.c = getControls;
				getControls = null;
        	}
        }
		//if(console)console.time("GlobalInformation.RegistredConfirmations");
        if (obj.c != null && GlobalInformation.RegistredConfirmations != null) {
            var ActualConfirmationCounter = 0;
            for (var i = 0; i < GlobalInformation.RegistredConfirmations.length; i++) {
                if (GlobalInformation.RegistredConfirmations[i][1] == obj.c[0].n &&
                "on" + obj.e == GlobalInformation.RegistredConfirmations[i][2]) {
                    var check = confirm(GlobalInformation.RegistredConfirmations[i][0]);
                    check = (check) ? "TRUE" : "FALSE";
                    if (ActualConfirmationCounter != 0) {
                        // add the prefix when not in first repetition
                        AdditionalCode += ",{";
                    }
                    var RepInfo = "";
                    // add repeater info if needed
                    if (obj.c[0].r != "") {
                        RepInfo = "_" + obj.c[0].i;
                    }
                    AdditionalCode += "\"n\":\"CONF" + GlobalInformation.RegistredConfirmations[i][3] + RepInfo + "\",\"a\" :{\"v\":\"" + check + "\"}}";
                    ActualConfirmationCounter++;
                }
            }
        }
	//	if(console)console.timeEnd("GlobalInformation.RegistredConfirmations");
        vRet = '{"p":' + cwOffice.toJSONString(obj.p) + ',"e":' + (obj.e ? cwOffice.toJSONString(obj.e) : 'null') + ',"c":[{'; 
        if (obj.c && typeof(obj.c) != "string") {
        	
			var pushlist = [];
			for (var i = 0; i < obj.c.length; i++) {
                if (obj.c[i] != null) {
                    if (obj.c[i].n.substr(0, 9) == "_GRABALL_") {
                        obj.c[i].n = obj.c[i].n.substr(9);
                        obj.c[i].r = "";
                        obj.c[i].i = "";
                    }
                    // this is a workaround if a control from a repeater tries to grab a outter repeater control
                    if (document.getElementsByName(cwName(obj.c[i]))[0] == null && obj.c[i].r != "") {
                        obj.c[i].r = "";
                        obj.c[i].i = "";
                    }
                    
                    if (document.getElementsByName(cwName(obj.c[i]))[0] == null && obj.c[i].n != null) {

                        //alert(this.getControls[i].cwName());
                        var CopyObject = clone(obj.c[i]);

                        // First delete all the controls with this name who have repeater information with them
                        // to make sure that no control is added twice
                        for (var c = obj.c.length - 1; c > 0; c--) {
                            if (obj.c[c] != null && obj.c[i] != null) {
                                if (obj.c[c].n == obj.c[i].n && obj.c[c].r != null && obj.c[c].r != "") {
                                    obj.c[c] = null;
                                }
                            }
                        }

						if (obj.c[i] != null && (obj.c[i]['a']['v'] == true || obj.c[i]['a']['value'] == true)) {

							if(bodyInnerHTML == "") {
								bodyInnerHTML = document.body.innerHTML;
							}
							var Exp = new RegExp('cwAutoRepControl\\[\\_([a-zA-Z0-9=]+)\\_([0-9]+)\\_(' + obj.c[i].n + ')\\]', 'i');
							var erg = Exp.exec(bodyInnerHTML);
							if (erg) { 
								var RepeaterName = erg[1];
								if (RepeaterName != "") {
									var t = 0;
									var control = null;

									while (control = document.getElementById("cwAutoRepControl[_" + RepeaterName + "_" + t + "_" + obj.c[i].n + "]")) {
										CopyObject.r = RepeaterName;
										CopyObject.i = t++;
										// only push if not existing
										pushlist[pushlist.length] = clone(CopyObject);
										control = null;
									}
									ignoreControl[i] = true;
								}
							}
						}
                    }
                }
            }
            obj.c = obj.c.length?obj.c.concat(pushlist):pushlist;
            pushlist = null;
			if(obj.c && obj.c[0] && obj.c[0].r != '' && obj.c[0].i != '' && document.getElementsByName(cwName(obj.c[0]))[0] != null) {
						var t = 0;
						while (document.getElementById("cwAutoRepControl[_" + obj.c[0].r + "_" + t + "_" + obj.c[0].n + "]")) {
							t++;
						}
						obj.c.push({'n':'CwRepetitionCount','a':{'v':t}});
			}
			
            for (var i = 0; i < obj.c.length; i++) {
                if (/(object|array)/i.test(typeof(obj.c[i])) && obj.c[i] != null && ignoreControl[i] !== true) {
					//if($c(cwName(obj.c[i]), obj.eventHolder) == undefined) continue;

                    vRet += '"n":' + cwOffice.toJSONString(obj.c[i]["n"]) + ',';
                    if (obj.c[i]["r"] && obj.c[i]["r"] != "") {
                        vRet += '"r":' + cwOffice.toJSONString(obj.c[i]["r"]) + ',';
                        vRet += '"i":' + cwOffice.toJSONString(obj.c[i]["i"]) + ',';
                    }

                    vRet += '"a":{';
                    var el = $c(cwName(obj.c[i]), obj.eventHolder);
					var attr = jS.convertToShortVars(obj.c[i]["a"]);
					var value = null;
					if (el && typeof(el.getRawValue) == 'function') {
						value = el.getRawValue();
					}
					else {
						var AttrName = (el?getAttr("value", el):null);
						if(el && el.tagName.toUpperCase() == 'SELECT' && el.multiple)
						{
							value = [];
							var values = 0;
							for(var oc = 0; oc < el.options.length; oc++)
							{
								if(el.options[oc].selected)
									value.push(el.options[oc].value);
									//value += (values++ != 0 ? '|' : '') + el.options[oc].value;
							}
							values = null;
							oc = null;	
						}
						else
						{
							value = (el && AttrName ? (typeof(el[AttrName]) != 'undefined' ? el[AttrName] : el.getAttribute(AttrName)) : false);
						}
					}
					if ((el && value) && (attr && attr["v"] === true)) { 
						vRet += '"v":' + cwOffice.toJSONString( ( typeof(value) == 'string' ? value.replace('€', 'EUR') : value ) ) + ','; 
					}
					else
						if (attr && attr["v"] && attr["v"] !== true) {
							vRet += '"v":' + cwOffice.toJSONString(attr["v"]) + ',';
						}

					if (el && el[getAttr("IsChecked", el)]) {
						vRet += '"c":' + cwOffice.toJSONString(el[getAttr("IsChecked", el)]) + ',';
					}

					if(obj.vars) {
						for(key in obj.vars) {
							vRet += '"'+key+'":' + cwOffice.toJSONString(obj.vars[key]) + ',';
						}
					}

                    vRet = rtrim(vRet, ',') + '}},{';
                    el = null;
                    attr = null;
                }
            }
        }
        bodyInnerHTML = null;
        obj = null;
        php = null;
        ignoreControl = null;

        if (AdditionalCode != "") {
            vRet += AdditionalCode;
        }
        vRet = rtrim(vRet, '{', ',') + ']}';


        if (tthis.$cs) {
            vRet = rtrim(vRet, "}") + ',"cs":' + tthis.$cs + '}';
        }

		cwOffice.debug.out('get controls of obj -> finished');
        return vRet;
    };
    function getAttr(attr, obj) {
        if (/(div|span)/i.test(obj.tagName)) {
            switch (attr.toLowerCase()) {
				case 'v':
                case 'value':
                return 'innerHTML';
                    break;
                default:
                return attr;
            }
        }
        else if (/(input)/i.test(obj.tagName)) {
            switch (attr.toLowerCase()) {
				case 'v':
                case 'value':
                if (obj.type.toLowerCase() != "checkbox") {
                    if (obj.type == 'hidden') {
                        if (typeof(FCKeditorAPI) != "undefined") {
							//console.info(obj);
                            var oEditor = FCKeditorAPI.GetInstance(obj.name);
                            var fcktxt = oEditor.GetHTML(true);
                            obj.FCK = fcktxt;
                        }
                        return "FCK";
                    }
					else if (obj.type.toLowerCase() == "file") {
						return "tmpname";
					}

                    return 'value';
                }
                else {
                    return (obj.checked) ? 'value' : '';
                }

                    break;
				case 'c':
                case 'ischecked':
                return 'checked';
                    break;
                default:
                return attr;
            }
        }
        else if(/(textarea)/i.test(obj.tagName)) {
            if(typeof(window.CKEDITOR) != 'undefined' && cwOffice.ckeditor) {
            	var inst = CKEDITOR.instances[obj.name];
            	if(inst){
            		obj.FCK = inst.getData();
            		return 'FCK';
            	}
            }
        }
        return attr;
    };
    cwName = window.cwName = function(tthis) {
        return (tthis.r && tthis.r != "") ? "cwAutoRepControl[_" + tthis.r + "_" + tthis.i + "_" + tthis.n + "]" : "cwAutoControl[" + tthis.n + "]";
    };
    
/**
 * EXPERIMENTAL
 */
function DeleteChildren(node){
	if(node){
		for(var x = node.childNodes.length - 1; x >= 0; x--){
			var childNode = node.childNodes[x];
			if(childNode.hasChildNodes()){
				DeleteChildren(childNode);
			}
			node.removeChild(childNode);
			if(childNode.outerHTML){
				childNode.outerHTML = '';
			}
			childNode=null;
		}
		node=null;
	}
}
function replaceHtml(el, html) {
	var oldEl = typeof el === "string" ? document.getElementById(el) : el;
//	/*@cc_on // Pure innerHTML is slightly faster in IE - Only IE 6 ??
//		oldEl.innerHTML = html;
//		return oldEl;
//	@*/
	if(html === '' || oldEl.innerHTML === '') { 
		oldEl.innerHTML = html;
		return oldEl;
	}
	
	var cw2format = oldEl.cw2format;
	
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	/* Since we just removed the old element from the DOM, return a reference
	to the new element, which can be used to restore variable references. */
	// Reset Events;
	try{  // Hier evtl. noch ne Loesung finden! (Fehler im IE: "Mitglied nicht gefunden")
		if(cwOffice.registeredEvents[newEl.id]) {
			for(eventobj in cwOffice.registeredEvents[newEl.id]) {
				var tthis = cwOffice.registeredEvents[newEl.id][eventobj];
				if(tthis && tthis["type"] == "util")
				{ //console.info(tthis["nested"]);
					cwOffice.util.event.add(newEl, eventobj, tthis["func"], tthis["bubble"]);// }, 300);
					if(tthis["nested"] && typeof(tthis["nested"]) == 'function') {
						tthis["nested"](newEl);
					}
				}
				else {
					newEl.getCwOfficeObject = function() {
			   			return tthis;
				   }
		           setCw(tthis);
				}
			}
		}
		
		// format plugin
		if(cwOffice.format && cw2format && cw2format.length == 2) {
			cwOffice.format.init(cw2format[0], cw2format[1], newEl);
		}
	}
	catch(e){}
	try {
		return newEl;
	}
	finally {
		newEl = null;
	}
};

function createControl(tthis, doParse) {
    	//var obj = tthis;
    	
        if (tthis.s) {
            var el = $c(cwName(tthis));

            if (el == null) {
                tthis.r = "";
                el = $c(cwName(tthis));
            }

            if (el == undefined) {
            	
            	var bodyInnerHTML = '';
            	if(bodyInnerHTML == "") {
					bodyInnerHTML = document.body.innerHTML;
				}

				var Exp = new RegExp('cwAutoRepControl\\[\\_([a-zA-Z0-9=]+)\\_([0-9]+)\\_(' + tthis.n + ')\\]', 'i');
				var erg = Exp.exec(bodyInnerHTML);
				if (erg) {
					var RepeaterName = erg[1];
					if (RepeaterName != "") {
						var t = 0;
						var control = null;
						//console.info(RepeaterName);
						while (control = document.getElementById("cwAutoRepControl[_" + RepeaterName + "_" + t + "_" + tthis.n + "]")) {
							var CopyObject = clone(tthis);
							CopyObject.r = RepeaterName;
							CopyObject.i = t++;
							createControl(CopyObject);
							control = null;
						}
					}
				}
				bodyInnerHTML = null;
				tthis = null;
				return;
           }
           // obj = null;
            //el = null;
            //return;
		   // gets the cwoffice object (send response php)\
            each(tthis.s, function(value, key) {
            	// convert numbers to string (e.g. number crashes on .indexOf)
            	if(value && value !== '' && value.toString) value = value.toString();
                switch (key.toLowerCase()) {
					case 'v':
                    case 'value':
						try {
							if (!el.getFormatType && tthis.s['FormatDisplay'] != null) {
								//console.info(value);
								cwOffice.format.init(tthis.s['FormatDisplay'], tthis.s['FormatIO'], el);
								value = cwOffice.format.io(tthis.s['FormatDisplay'], tthis.s['FormatIO'], value, el);
							}
							else if(el.getFormatType) {
								//console.info('a');
								//console.info(value);
								value = el.setValue(value);
								//break;
							}
						} catch(e) {}
	                    if (el && /(div|span)/i.test(el.tagName)) {
	                        if (isset(tthis.s.AttachValue)) {
	                            if (tthis.s.AttachValue == 'top') {
	                                el.innerHTML = value + el.innerHTML;
	                            }
	                            else if (tthis.s.AttachValue == 'bottom') {
	                                el.innerHTML = el.innerHTML + value;
	                                if (tthis.s.Scroll) {
	                                    el.scrollTo(el.pageYOffset, 0);
	                                }
	                            }
	                            else if (tthis.s.AttachValue != 'nothing' && value != null) {
	                                el.innerHTML = value;
	                            }
	                        }
	                        else {
                        		el = replaceHtml(el, value);
	                        }
							var re = /<script\sexec\b[\s\S]*?>([\s\S]*?)<\//ig;
							var match;
							while (match = re.exec(value)) {
									eval(match[1]);
							}
							match = null;
	                    }
	                    else if (el && /(input|textarea)/i.test(el.tagName)) {
	                   
                    		if(typeof(window.CKEDITOR) != 'undefined' && cwOffice.ckeditor && CKEDITOR.instances[el.name]) {
            					var inst = CKEDITOR.instances[el.name]; //cwOffice.ckeditor(cwName(obj));
            					if(inst){
            						inst.setData(value);
            					}
            				}
	                        else if (el.type == 'hidden') { 
	                            if (typeof(FCKeditorAPI) != "undefined") {
	                                var oEditor = FCKeditorAPI.GetInstance(el.name);
	                                //console.info(el);
	                                oEditor.SetHTML(value);
	                            }
	                            break;
	                        }
							else if (el.type == "file") {
								el.setAttribute('tmpname', value);
							}
	                        else if (el && el.type == "checkbox") {
	                            if (el.value == value) {
	                                el.checked = true;
	                            }
	                            else {
	                                el.checked = false;
	                            }
	                        }
	                        else {
	                            if (isset(tthis.s.AttachValue)) {
	                                if (tthis.s.AttachValue == 'top') {
	                                    el.value = value + el.value;
	                                }
	                                else if (tthis.s.AttachValue == 'bottom') {
	                                    el.value = el.value + value;
	                                    if (tthis.s.Scroll) {
	                                        el.scrollTo(el.pageYOffset, 0);
	                                    }
	                                }
	                                else if (tthis.s.AttachValue != 'nothing' && value != null) {
	                                    el.value = value;
	                                }
	                            }
	                            else {     	
	                                el.value = value; //.replace(/>/g, '&gt;');
	                            }
	                            //el.value = value;
	                        }
	                    }
	                    else if (el && /(select)/i.test(el.tagName)) {
	                        if (value != "") {

	                            // syntax value1~readablevalue1|value2~readablevalue2
	                            if (value.indexOf("|") != -1 || value.indexOf("~") != -1) {

	                                var options = value.split("|");
	                                if (isset(tthis.s.AttachValue)) {
	                                    if (tthis.s.AttachValue == 'top') {

	                                    }
	                                    else if (tthis.s.AttachValue == 'bottom') {

	                                    }
	                                    else if (tthis.s.AttachValue != 'nothing' && value != null) {
	                                        el.options.length = 0;
	                                    }
	                                }
	                                else {
	                                    el.options.length = 0;
	                                }

	                                if (options.length > 0) {

	                                    for (var f = 0; f < options.length; f++) {
	                                        // now get the values
	                                        var values = options[f].split("~");
	                                
	                                        if (values.length > 0) {
	                                            // clear the list first
                                        		var ta=document.createElement("textarea");
												ta.innerHTML = values[1].replace(/</g,"&lt;").replace(/>/g,"&gt;");
	                                            //optionsCache.push(new Option(values[1], values[0], false, (values[2] == "true")));
	                                            el.options[el.options.length] = new Option(ta.value, values[0], false, (values[2] == "true"));
	                                            ta = null;
	                                        }
	                                    }
	                                }
	                            }
	                            else {

	                                // try to set value
	                                for (var f = 0; f < el.options.length; f++) {
	                                    if (el.options[f].value == value) {
	                                        el.options[f].selected = true;
	                                    }
	                                }
	                            }
	                        }
	                        else {
	                            el.options.length = 0;
	                        }

	                    }

                        break;
                    default:
                    	if(el) el[getAttr(key, el)] = value;

                }
                value = null;
            });
			el = null;
        }
        
        // Short Keys
        if(tthis['k'] && tthis['k'] !== '') {
        	//{key: 'a', modifier: 'shift', fn: 'alert("a pressed!")', os: 'mac'}
        	cwOffice.keybind.bind(cwName(tthis), tthis['k']);
        }
		//alert('test');
		/**
		 * SET EVENTS
		 */
       // console.info(tthis.e);
        //console.warn($c(cwName(tthis)));
		if(tthis.e && tthis.p[0] === "JavaScript") {
			setTimeout(function() {
				setEvent(cwName(tthis), tthis.e, function(e) { cwOffice.MediaLibrary[tthis.p[1]]["Add"](tthis); }, true);
			}, 200 );
		}
		else if(tthis.e)
		{
			window.setTimeout(function() {//console.info(cwName(tthis));
				var el = $c(cwName(tthis));//console.warn(el);
                if(el) {
				   el.getCwOfficeObject = function() {
				   		return tthis;
				   }
                }
                setCw(tthis);
				el = null;
				//obj = null;
            }, 300);
		}
		
		//obj = null;
        
    }
    
    ticker = function(tthis) {
        tthis.ticker = new function() {
            this.start = function() {
                var t = tthis;
                this.pointer = setInterval(function() {
                    set(jS.queue.pB, t);
                }, t.interval);
            };
            this.stop = function() {
                var t = tthis;
                claerInterval(t.pointer);
            };
            this.pointer = null;
        };
        tthis.ticker._this = tthis;
    };
    rtrim = window.rtrim = function(tthis, ch) {
        var vRet = tthis;
        for (var i = 1; i < arguments.length; i++) {
            vRet = vRet.replace(new RegExp(arguments[i] + "$", ""), "");
        }
        return vRet;
    };
    ltrim = window.ltrim = function(tthis, ch) {
        var vRet = tthis;
        for (var i = 1; i < arguments.length; i++) {
            vRet = vRet.replace(new RegExp("^" + arguments[i], ""), "");
        }
        return vRet;
    };
    addslashes = window.addslashes = function(tthis) {
        return tthis.replace(/(["'])/g, '\\"');//'
    };
    cc = window.cc = function(tthis, String) {
        for (var i = 0; i < String.split("").length; i++) {
            tthis.push(String.split("")[i]);
        }
    };
    /**
     * EXPERIMENTAL
     */
    function createMedia(tthis) {
    	each(tthis, function(value, key) {
            if (cwOffice.MediaLibrary && cwOffice.MediaLibrary[key]) {
                cwOffice.MediaLibrary[key].Add(value);
            }
        });
    }

    /**
     * data: misc.js
     */
    com = new function() {
        this.innerWidth = function() {
            if (Stuff.Browser.isIE) {
                return document.body.offsetWidth;
            }
            else {
                return window.innerWidth;
            }
        }
        this.innerHeight = function() {
            if (Stuff.Browser.isIE) {
                return document.body.offsetHeight;
            }
            else {
                return window.innerHeight;
            }
        }
    }

    function $e(element) {
        return document.getElementById(element);
    }
    function $t(tag) {
        return document.getElementsByTagName(tag);
    }
    function $n(name) {
        return document.getElementsByName(name);
    }

    cwOffice.registeredEvents = {};
    function setCw(obj) {
		obj = jS.convertToShortVars(obj);
        var el = $c(cwName(obj));
 //   	console.info(obj);
//    	console.warn(el);
        if (el) {
			// AJAX UPLOAD
			//	console.info(obj);
			
			// Bugfix Autocompletion OnEnter
			// Falls OnEnter + OnLoad auf dem Element liegen konnte es sein das OnEnter von OnLoad ueberschrieben wurde
        	if(obj.e !== 'load') el.rawCwObject = obj; //else console.info(obj);
        	var cwObjectName = cwName(obj);
			if (el.type && el.type == "file" && obj.e == "upload") {    
				cwOffice.upload.prepare($c(cwName(obj)), {restore: (obj.rc?obj.rc:0), url: (info && info.File && info.File != '' ? info.File.replace(/\?.*$/, '') : window.location.pathname), onComplete: function(fi, ControlInfo) {
					if(ControlInfo)
					{                 
						obj.c[0].r = ControlInfo.r;
						obj.c[0].i = ControlInfo.i;
						obj.r = ControlInfo.r;
						obj.i = ControlInfo.i;
					} 
					var element = $c(cwName(obj));
					var p = element.getAttribute('upload');     
					element.setAttribute('tmpname', fi['tmp_name']);
					obj.vars = fi;
					if(p) {
						jS.func = function(){
							setTimeout(function() {  
								var o = cwOffice.util.extend({}, obj, {php:p.toString().split(','),event:'change'});   
								cwOffice.util.extend(o['c'], element['uploadControls']);   
								cwOffice.util.loading.show();
							
								jS.queue.pA.set(o);
								element = null;
							}, 200);
						}
					}
					cwOffice.util.loading.show();
				 
					jS.queue.pA.set(obj);
				}});
				
				//obj = null;
				try {
					return el;
				}
				finally { el = null; }
			}
			else if (el.type && el.type == "file" && obj.e == "change") {
				el.setAttribute('upload', obj['p']);
				el['uploadControls'] = obj['c'];
			}
			else if(obj.e == 'enter') {
				setEvent(cwName(obj), 'keyup', function(e){ 
					var e = e || window.event;
					if(e.keyCode == 13) {
						var element = $c(cwObjectName);
						if(element) {
							cwOffice.debug.out('Start Event ...');
							cwOffice.util.loading.show();
							jS.queue.pA.set(element.rawCwObject);
						}
						element = null;
					}
				}, false);
				
				obj = null;
				try {
					return el;
				}
				finally { el = null; }
			}
			else {
				//console.info(obj);
				var nested = null;//if(cwOffice.registeredEvents[cwName(obj)]) console.warn(cwOffice.registeredEvents[cwName(obj)][obj.e]);
				if(!cwOffice.registeredEvents[cwName(obj)]) cwOffice.registeredEvents[cwName(obj)] = {};
				else if(cwOffice.registeredEvents[cwName(obj)][obj.e] && cwOffice.registeredEvents[cwName(obj)][obj.e]['nested']) {
					nested = cwOffice.registeredEvents[cwName(obj)][obj.e]['nested'];
				}
				cwOffice.registeredEvents[cwName(obj)][obj.e] = obj;
				cwOffice.registeredEvents[cwName(obj)][obj.e]['nested'] = nested;
				setEvent(cwName(obj), obj.e, function(){
					var element = $c(cwName(obj));
					if(element) {
						cwOffice.debug.out('Start Event ...');
						cwOffice.util.loading.show();
						jS.queue.pA.set(obj);//element.rawCwObject);
					}
					element = null;
				}, false);
				
				//obj = null;
				try {
					return el;
				}
				finally { el = null; }
			}
        }
        else {
            return null;
        }
    }
    function $c(ident, cEvent) {

        if (cEvent != undefined && typeof(cEvent) == "number") {
            //var el = isNull($e(ident)) ? $n(ident)[0] : $e(ident);

            /*if(Stuff.Browser.isIE) {
             var mu = document.getElementsByTagName(el.tagName);

             var x = 0;
             for(var i=0;i<mu.length;i++) {
             if(mu[i].name == ident) {
             if(cEvent == x) {
             return mu[i];
             }
             else x++;
             }
             }
             }
             else {*/
            return $n(ident)[cEvent];
            //}
        }
        else {
            return isNull($e(ident)) ? $n(ident)[0] : $e(ident);
        }
    }
    function $cw(element) {
        return !isNull($e('cwAutoControl[' + element + ']')) ? $c('cwAutoControl[' + element + ']') : isset($n('cwAutoControl[' + element + ']')[0]) ? $c('cwAutoControl[' + element + ']') : $c('cwAutoRepControl[' + element + ']');
    }
    function $a() {
        var foo = new Array;
        for (i = 0; i < arguments.length; i++)
            foo.push(arguments[i]);
        return foo;
    }
    function $evT(event) {
        return event.target ? event.target : event.srcElement;
    }
    function $ev(event) {
        return event ? event : window.event;
    }
    function $evPx(event) {
        return event.pageX ? event.pageX : event.clientX;
    }
    function $evPy(event) {
        return event.pageY ? event.pageY : event.clientY;
    }
    function $evLx(event) {
        return event.layerX ? event.layerX : event.x;
    }
    function $evLy(event) {
        return event.layerY ? event.layerY : event.y;
    }

    function isset() {
        var vRet = arguments.length != 0 ? true : false;
        for (var i = 0; i < arguments.length; i++) {
            vRet = typeof(arguments[i]) === "undefined" ? false : true;
        }
        return vRet;
    }
    function isNull() {
        var isNull = arguments.length != 0 ? true : false;
        for (var i = 0; i < arguments.length; i++) {
            isNull = arguments[i] !== null ? false : isNull;
        }
        return isNull;
    }

    setEvent = function(tthis, eventN, handler, bubble) {
        //alert(isset($e(this)) + " this = " + this + " !! " + $e(this) + ' !! ' + handler);
        //alert(this);
        if (tthis != 'window' && tthis != 'document') {
            var element = $c(tthis);
            if (element == null)
                return;
            //if(element.innerHTML == "Test") handler = function() { alert("test"); } ;
            var bubble = bubble ? bubble : false;
            try {
                element.addEventListener(eventN, handler, bubble);
            }
            catch (e) {
                try {
                    element.attachEvent("on" + eventN, handler);
                }
                catch (e) { /*alert(this + ".setEvent Error!");*/
                }
            }
        }
        else {
            eval(tthis + '.on' + eventN + ' = '.handler + ';');
        }
    }
    /*function setEvent(eventN, handler, bubble, obj) {
     var bubble = bubble ? bubble : false;
     try {
     obj.addEventListener(eventN, handler, bubble);
     }
     catch (e) {
     try {
     obj.attachEvent("on" + eventN, handler);
     }
     catch (e) {
     }
     }
     }
    ' */
    Stuff = new function() {
        this.Loading = new function() {
            this.Active = true;
            this.Center = true;
            this.IgnoreEvents = ['keyup', 'ticker', 'blur'];

            this.Show = function(EventType) {
                if (!isNull($e('Loading')) && Stuff.Loading.Active /*&& Stuff.Loading.CheckEventType(EventType)*/) {
                    if (Stuff.Loading.Center) {
                        //	var left = ((com.innerWidth()/2)>90)?(com.innerWidth()/2) - 90:1;
                        //	var top = ((com.innerHeight()/2)>42)?(com.innerHeight()/2) - 42:1;

                        //	left = (Math.round(left) + 'px');
                        //	top = (Math.round(top) + 'px');
                        //alert("top:" + top + " !! " + "left:" + left + " !! " + com.innerWidth());
                        //	$e('Loading').style.left = left;
                        //	$e('Loading').style.top = top;
                    }
                    //$e('Loading').style.display = 'block';
                    if (document.getElementById('sys_winy') != null) {
                        if (getCoord("y") != null) {
                            // call function from berke editor
							var LoadingIcon = $e('Loading');
							if(LoadingIcon)
							{
								if(LoadingIcon.style.left)
									LoadingIcon.style.left = getCoord("x") + 15;
								if(LoadingIcon.style.top)
									LoadingIcon.style.top = getCoord("y");
								LoadingIcon.style.position = "absolute";
								LoadingIcon.style.zIndex = 10;
								LoadingIcon.style.display = 'block';
							}
                        }
                    }
                }
            }
            this.Hide = function() {
                if (!isNull($e('Loading')) && Stuff.Loading.Active) {
                    $e('Loading').style.display = 'none';
                }
            }
            this.CheckEventType = function(EventType) {
                for (var i = 0; i < Stuff.Loading.IgnoreEvents.length; i++) {
                    if (Stuff.Loading.IgnoreEvents[i] == EventType) {
                        //break -----
                        return false;
                    }
                }
                return true;
            }
        }
        this.Browser = new function() {
            this.isIE = navigator.appName == "Microsoft Internet Explorer" ? true : false;
            this.isFF = navigator.appName == "Netscape" ? true : false;
            this.appName = navigator.appName;
            this.appVersion = navigator.appVersion;
        }
    }

})();

