	/***********************************************************************************
	    Liebelt Oktober 2008 - 2010
	    www.jens-liebelt.de
	    CoreScript für die Polaris Webkomponenten 4.1
	    Diese Scripte sind grundsätzlicher Bestandteil der Ausgabeseiten.
	    Bei Programmupdates wird diese Datei möglicherweise überschrieben.
	    
	    Benutzerdefinierte Erweiterungen und Anpassungen sind der Datei
	    pwk_user.js zu platzieren.
	
	***********************************************************************************/
	var getit = false;
	var browser = new Object;
	var pwk_teaser_collapse = false;
	var pwk_growSelfTable_init = false;
	var pwk_growSelf_init = false;	
	var pwk_pictureMouseOver = false;
	var pwk_VarTimerRegPreview = 0;
	var pwk_pictureMaxSize = 550;

	window.onload = function(){
		startUP();
	}
		
	/***********************************************************************************
	 Anweisungen die beim Laden der Seite ausgeführt werden sollen                                                      	
	***********************************************************************************/	
	function startUP(){
		initAjaxStatus();
		// Sorttable Stu Evens - MIT Lizenz
		//sorttable.init();
		//pwk_comments('user_comments');
		pwk_ImageClass();
	}
	/***********************************************************************************
	Element löschen                                                     	
	***********************************************************************************/	
	function pwk_objRemove(obj){
		if(!obj.parentNode)
			return;
		obj.parentNode.removeChild(obj);
	}
	/***********************************************************************************
	Element ausblenden                                                     	
	***********************************************************************************/	
	function pwk_objHide(obj){
		if(!obj.parentNode)
			return;
		obj.style.display = "none";
	}
	/***********************************************************************************
	Element einblenden                                                     	
	***********************************************************************************/	
	function pwk_objShow(obj){
		if(!obj.parentNode)
			return;
		obj.style.display = "";
	}
	/***********************************************************************************
	 PWK AJAX LOADER  Init                                                	
	***********************************************************************************/	
	function initAjaxStatus(){
		var ajax_loader = document.createElement('img');
			ajax_loader.id = "ajaxStatus";
			ajax_loader.style.display = "none";
			ajax_loader.style.position = "absolute";
			ajax_loader.style.zIndex = "100000";
			ajax_loader.style.height = "100px";
			ajax_loader.style.width = "100px";
			ajax_loader.src = "ajax-loader.gif";
			document.getElementsByTagName('BODY')[0].appendChild(ajax_loader);
	}
	/***********************************************************************************
	 PWK AJAX LOADER anzeigen                                                	
	***********************************************************************************/		
	function ajaxLoaderShow(){
		var loader = document.getElementById('ajaxStatus');
		var array = centerWindow("100px","100px");
		loader.style.top = array[0] +"px";
		loader.style.left = array[1] +"px";
		loader.style.display = "block";
	}
	/***********************************************************************************
	 PWK AJAX LOADER anzeigen                                                	
	***********************************************************************************/		
	function ajaxLoaderPWK(){
 		var loader = document.getElementById('ajaxStatus');
		if(document.all)
			loader.style.top = Math.ceil(document.body.clientHeight / 2) - Math.ceil(getNumFromStyleProperty(loader.style.height)/2) + document.body.scrollTop +"px";
			loader.style.left = Math.ceil(document.body.clientWidth / 2) - Math.ceil(getNumFromStyleProperty(loader.style.width)/2) + "px";
		
		if(!document.all){
			loader.style.top = Math.ceil(window.innerHeight / 2) - Math.ceil(getNumFromStyleProperty(loader.style.height)/2) + pageYOffset +"px";
			loader.style.left = Math.ceil(window.innerWidth / 2) - Math.ceil(getNumFromStyleProperty(loader.style.width)/2) + "px";
		}
	}
	/***********************************************************************************
	 PWK AJAX LOADER ausblenden                                                    	
	***********************************************************************************/		
	function ajaxLoaderHide(){
		var loader = document.getElementById('ajaxStatus');
		loader.style.display = "none";
	}
	/***********************************************************************************
	  AJAX Status Anzeige während der Ausführung
	***********************************************************************************/	
	function whenLoading(){
		if(document.getElementById('ajaxStatus')){
			document.getElementById('ajaxStatus').style.display = "block";
			ajaxLoaderPWK();
		}
	}
	/***********************************************************************************
	  AJAX Status Anzeige wenn der Ladevorgang beendet wurde
	***********************************************************************************/		
	function whenLoaded(){
		if(document.getElementById('ajaxStatus')){
		document.getElementById('ajaxStatus').style.display = "none";
		}
	}
	/***********************************************************************************
	  AJAX Status Anzeige wenn die Funktion 
	***********************************************************************************/	
	function whenInteractive(){
		if(document.getElementById('ajaxStatus'))
		document.getElementById('ajaxStatus').style.display = "none";
	}	
	/***********************************************************************************
	   Definition der Ajax Funktionen                                                                   	
	***********************************************************************************/	
	var ajaxDump = "Designer/designer_db/functions.php";
	var container_ajaxObjects = new Array();
	/***********************************************************************************
	  AJAX Status 
	***********************************************************************************/	
	function pwk_postFields(obj){
		foo = obj;
		do{
			foo = foo.parentNode;
		}while(foo.tagName != "FORM")
		
		var postFields = new Array()
	
		for(var x = 0; x < foo.elements.length; x++){
			postFields[x] = new pwk_post();
			switch (foo.elements[x].tagName){
				case "INPUT":
					switch(foo.elements[x].type){
						case "button":
							postFields[x].name = foo.elements[x].name;
							postFields[x].value = foo.elements[x].value;							
							break;
						case "text":
							postFields[x].name = foo.elements[x].name;
							postFields[x].value = foo.elements[x].value;
							break;
						case "radio":
							postFields[x].name = foo.elements[x].name;
							postFields[x].value = foo.elements[x].value;						
							break;
						case "checkbox":
							postFields[x].name = foo.elements[x].name;
							postFields[x].value = foo.elements[x].value;						
							break;
						case "hidden":
							postFields[x].name = foo.elements[x].name;
							postFields[x].value = foo.elements[x].value;
							break;							
					}
					break;
				case "TEXTAREA":
						postFields[x].name = foo.elements[x].name;
						postFields[x].value = foo.elements[x].value;				
					break;
				case "SELECT":
						postFields[x].name = foo.elements[x].name;
						postFields[x].value = foo.elements[x].options[foo.elements[x].selectedIndex].text;
					break;
			}
		}
		return postFields;
	}
	function pwk_webbase(obj){	
		postFields = pwk_postFields(obj);
		var ajaxIndex = container_ajaxObjects.length;
		container_ajaxObjects[ajaxIndex] = new sack();	
		container_ajaxObjects[ajaxIndex].requestFile = ajaxDump
		container_ajaxObjects[ajaxIndex].method = "POST";
		container_ajaxObjects[ajaxIndex].setVar("caller", obj.name);
		container_ajaxObjects[ajaxIndex].setVar("url", pwk_getURL());
		for(var x = 0; x < postFields.length; x++)
			container_ajaxObjects[ajaxIndex].setVar(postFields[x].name, postFields[x].value);	

		container_ajaxObjects[ajaxIndex].onCompletion = function(){ foo.innerHTML = container_ajaxObjects[ajaxIndex].response;switchCaller(obj.name,postFields)};
		container_ajaxObjects[ajaxIndex].runAJAX();
	}

	function pwk_comments(obj){
		if(document.getElementById(obj)){
			obj = document.getElementById(obj);
			var ajaxIndex = container_ajaxObjects.length;
			container_ajaxObjects[ajaxIndex] = new sack();	
			container_ajaxObjects[ajaxIndex].requestFile = ajaxDump
			container_ajaxObjects[ajaxIndex].method = "POST";
			container_ajaxObjects[ajaxIndex].setVar("caller", obj.id);
			container_ajaxObjects[ajaxIndex].setVar("url", pwk_getURL());
			container_ajaxObjects[ajaxIndex].onCompletion = function(){ obj.innerHTML = container_ajaxObjects[ajaxIndex].response;};																
			container_ajaxObjects[ajaxIndex].runAJAX();			
		}
	}

	function pwk_seek(obj){
			postFields = pwk_postFields(obj);
			var response = document.getElementById("body-center");
			var ajaxIndex = container_ajaxObjects.length;
			container_ajaxObjects[ajaxIndex] = new sack();	
			container_ajaxObjects[ajaxIndex].requestFile = ajaxDump
			container_ajaxObjects[ajaxIndex].method = "POST";
			container_ajaxObjects[ajaxIndex].setVar("caller", obj.id);
			container_ajaxObjects[ajaxIndex].setVar("url", pwk_getURL());
			for(var x = 0; x < postFields.length; x++)
				container_ajaxObjects[ajaxIndex].setVar(postFields[x].name, postFields[x].value);
				
			container_ajaxObjects[ajaxIndex].onCompletion = function(){
					if(container_ajaxObjects[ajaxIndex].response != "leer")
						response.innerHTML = container_ajaxObjects[ajaxIndex].response;
				};	
			container_ajaxObjects[ajaxIndex].onLoading = whenLoading;
			container_ajaxObjects[ajaxIndex].onLoaded = whenLoaded;
			container_ajaxObjects[ajaxIndex].onInteractive = whenInteractive;		
			container_ajaxObjects[ajaxIndex].runAJAX();				
	}
	function pwk_seek_(obj){
			postFields = pwk_postFields(obj);
			var response = document.getElementById("suchergebnis");
			var ajaxIndex = container_ajaxObjects.length;
			container_ajaxObjects[ajaxIndex] = new sack();	
			container_ajaxObjects[ajaxIndex].requestFile = ajaxDump
			container_ajaxObjects[ajaxIndex].method = "POST";
			container_ajaxObjects[ajaxIndex].setVar("caller", obj.id);
			container_ajaxObjects[ajaxIndex].setVar("url", pwk_getURL());
			for(var x = 0; x < postFields.length; x++)
				container_ajaxObjects[ajaxIndex].setVar(postFields[x].name, postFields[x].value);
				
			container_ajaxObjects[ajaxIndex].onCompletion = function(){
					if(container_ajaxObjects[ajaxIndex].response != "leer")
						response.innerHTML = container_ajaxObjects[ajaxIndex].response;
				};	
			container_ajaxObjects[ajaxIndex].onLoading = whenLoading;
			container_ajaxObjects[ajaxIndex].onLoaded = whenLoaded;
			container_ajaxObjects[ajaxIndex].onInteractive = whenInteractive;		
			container_ajaxObjects[ajaxIndex].runAJAX();				
	}
	
	/***********************************************************************************
	 Aktionen die nach dem Aufruf einer Caller Funktion ausgeführt werden sollen                                                                 	
	***********************************************************************************/	
	function switchCaller(caller,postFields){
			switch(caller){
				case "kommentar-erstellen":
					pwk_comments('user_comments');
				break;
			}	
	}
	/***********************************************************************************
	 Bild anzeigen                                                                 	
	***********************************************************************************/	
	function enlarge(obj){
		var maxsize = obj.src.split("&");
		var newSource = getReplaceOnce(maxsize[maxsize.length-1],'maxsize=450',obj.src);
		createSimpleWindow(newSource,obj);
	}
	/***********************************************************************************
	 Fenster mit Bild erstellen                                                                   	
	***********************************************************************************/	
	function createSimpleWindow(newSource,obj){
		array = new Array();
		array = centerWindow("450px","450px");
		
		newItem = document.createElement('div');
		newItem.style.cssText="position:absolute;display:block;border:1px solid black;z-index:200;";
		newItem.style.top = array[0]+"px";
		newItem.style.left = array[1]+"px";
		newItem.style.backgroundColor = "transparent";

		newItem.setAttribute('id','tempWindow');
		regEvent(newItem,'click',function (){document.getElementsByTagName('body')[0].removeChild(document.getElementById('tempWindow'))},false);
		
		newHead = document.createElement('div');
		newHead.style.cssText="position:relative;display:block;height15px;top:0px;left:0px;background-color:#d2d2d2;font-size:12px;";
		newHead.innerHTML = "&nbsp;Bild: " + obj.alt;
		
		newItem.appendChild(newHead);
		
		newBody = document.createElement('div');
		newBody.style.cssText="position:relative;top:0px;margin:0px auto;";
	
		newImg = document.createElement('img');
		newImg.src = newSource;
		newBody.appendChild(newImg);
		
		newItem.appendChild(newBody);
		
		document.getElementsByTagName('body')[0].appendChild(newItem);
		
	}
	/***********************************************************************************
	 Fenster auf den Bildschirm zentrieren                                                                      	
	***********************************************************************************/	
	function centerWindow(wH,wW){
		var pageX = (document.all)?parent.document.documentElement.clientWidth:parent.window.innerWidth;
		var pageY = (document.all)?parent.document.documentElement.clientHeight:parent.window.innerHeight;
		var pageY_offset = (document.all)?document.documentElement.scrollTop:parent.window.pageYOffset; 		
		wT  = Math.ceil((pageY/2)-(getNumFromStyleProperty(wH)/2) + (pageY_offset));
		wL = Math.ceil((pageX/2)-(getNumFromStyleProperty(wW)/2));

		array = new Array();
		array[0] = wT;
		array[1] = wL;
		return array;
	}
		
	/***********************************************************************************
		Findet einen Elementtyp relativ aufwärts
	***********************************************************************************/
	function pwk_findNodeUp(obj,find_type){
		do{
			obj = obj.previousSibling;
		}while(obj.tagName != find_type.toUpperCase())
		
		return obj;
	}
	/***********************************************************************************
		Findet einen Elementtyp relativ abwärts
	***********************************************************************************/
	function pwk_findNodeDown(obj,find_type){
		do{
			obj = obj.nextSibling;
		}while(obj.tagName != find_type.toUpperCase())
		
		return obj;
	}
	/***********************************************************************************
		Findet ein Elternelement
	***********************************************************************************/
	function pwk_findParentNode(obj,find_type){
		do{
			obj = obj.parentNode;
		}while(obj.tagName != find_type.toUpperCase())
		
		return obj;
	}
	/***********************************************************************************
		Liefert die URL der Seite
	***********************************************************************************/
	function pwk_getURL(){
		return "http://" + window.location.hostname + window.location.pathname;
	}
	/***********************************************************************************
		Erstetzt innerhalb eines String einen Ausdruck durch einen anderen * erster Vorkommen
	***********************************************************************************/
	function getReplaceOnce(matchThis,replaceWidth,source){
		var ausdruck = new RegExp(matchThis);
		var new_Value = source.replace(ausdruck, replaceWidth);
		return new_Value;
	}
	/***********************************************************************************
		Erstetzt innerhalb eines String einen Ausdruck durch einen anderen * alle Vorkommen
	***********************************************************************************/
	function getReplace(matchThis,replaceWidth,source){		
		var ausdruck = new RegExp(matchThis, "g");
		var new_Value = source.replace(ausdruck, replaceWidth);
		return new_Value;
	}	
	/***********************************************************************************
		Vergleicht nach der Ersetzung ob der alte und der neue String gleich sind
	***********************************************************************************/	
	function getFindInString(matchThis,replaceWidth,source){
		var ausdruck = source.indexOf(matchThis);
		if(ausdruck > -1){return true;}else{return false;}	
	}	
	/***********************************************************************************
	    Nur den Wert einer Eigenschaft liefern                                                                   	
	***********************************************************************************/
	function getNumFromStyleProperty(property) {
		var num = property.split("px");
		return num[0]*1;
	}
	/***********************************************************************************
	   Cancel Event                                                                     	
	***********************************************************************************/
	function cancelEvent(event){
		if( document.addEventListener ) {
			event.stopPropagation();
		} else {
			event.cancelBubble = true;
		}
	}
	/***********************************************************************************
	   Event registrieren                                                                  	
	***********************************************************************************/
	function regEvent(obj,e_handler,e_funktion,e_parameter){
		if( document.addEventListener ) {
			obj.addEventListener( e_handler,e_funktion,e_parameter);
		} else {
			var e_handler = "on" + e_handler;
			obj.attachEvent( e_handler, e_funktion );
		}
	}
	/***********************************************************************************
	    Nur den Wert einer Eigenschaft liefern                                                                   	
	***********************************************************************************/	
	function getNumFromStyleProperty(property) {
		var num = property.split("px");
		return num[0]*1;
	}
	/***********************************************************************************
	    Liefert einen Zeitstempel                                                           	
	***********************************************************************************/
	function getTimeStamp(){
		var jetzt = new Date()		
		return jetzt.getTime();
	}
	/***********************************************************************************
	    Allgemeine Elementklasse für PostFields                                                         	
	***********************************************************************************/
	function pwk_post(){
		var self = this;
		var name = "";
		var value = "";
	}
	/***********************************************************************************
	 PWK Bildklassen belegen                                                     	
	***********************************************************************************/	
	function pwk_ImageClass(){
		var children = document.getElementsByTagName('img'); 
		var elements = new Array(); var i = 0;
		var child; var classNames; var j = 0;
		for (i=0;i<children.length;i++) {
			child = children[i];
			classNames = child.className.split(' ');
			for (var j = 0; j < classNames.length; j++) {
				switch (classNames[j]){
					case "pwk_img":
						pwk_growLeft(child);
						break;
					case "pwk_growSelf":
						if(child.parentNode.tagName == "TD")
							pwk_growSelfTable(child);
						if(child.parentNode.tagName != "TD")	
							pwk_growSelf(child);
						break;
				}
			}
		}
	
	}
	/***********************************************************************************
	 Vergrößerung der Bilder in der Seitenleiste rechts                                                      	
	***********************************************************************************/	
	function pwk_growLeft(canvas){
		if(!document.all){
			canvas.onmouseover = function(){
									var pageY_offset = (document.all)?document.documentElement.scrollTop:parent.window.pageYOffset;
									var obj = this.parentNode.cloneNode(true);
									obj.style.position = "absolute";
									obj.className = "";
									//obj.style.backgroundColor = "rgb(83, 82, 81)";
									//obj.style.backgroundColor = "#d2d2d2";
									var client = this.parentNode.getBoundingClientRect();
									var o_top = client.top //+ this.offsetTop //+ pageY_offset;
									var o_left = client.left - 340;
									obj.style.top = Math.abs(o_top) + "px";
									obj.style.left = Math.abs(o_left) + "px";											
									obj.style.height = "230px";
									obj.style.width ="320px";
									obj.firstChild.style.height = "230px";
									obj.firstChild.style.width ="320px";
									
									this.style.opacity ="0.5";
									this.parentNode.style.backgroundColor = "transparent";
									if(document.getElementById("temp_pic"))
											pwk_objRemove(document.getElementById("temp_pic"));									

									var container = document.createElement('div')
									container.id = "temp_pic";
									container.appendChild(obj);
									document.getElementsByTagName('BODY')[0].appendChild(container);
									}
									
			canvas.onmouseout = function(){
									if(document.getElementById('temp_pic'))
									document.getElementsByTagName('BODY')[0].removeChild(document.getElementById('temp_pic'));
									this.style.opacity ="1";
									//this.parentNode.style.backgroundColor = "rgb(83, 82, 81)";
									//this.parentNode.style.backgroundColor = "#d2d2d2";
									}											
		}

		if(document.all){
			canvas.onmouseover = function(evt){
									this.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=50)";
									var pageY_offset = (document.all)?document.documentElement.scrollTop:parent.window.pageYOffset;
									var obj = this.parentNode.cloneNode(true);
									obj.style.position = "absolute";
									obj.className = "";
									//obj.style.backgroundColor = "rgb(83, 82, 81)";
									//obj.style.backgroundColor = "#d2d2d2";
									var client = event.srcElement.getBoundingClientRect();
									var o_top = client.top + pageY_offset;
									var o_left = client.left - 360;
									obj.style.top = Math.abs(o_top) + "px";
									obj.style.left = Math.abs(o_left) + "px";											
									obj.style.height = "230px";
									obj.style.width ="320px";									
									obj.style.filter = "";
									obj.firstChild.style.filter = "";
									obj.firstChild.style.height = "230px";
									obj.firstChild.style.width ="320px";

									this.parentNode.style.backgroundColor = "transparent";									
									if(document.getElementById("temp_pic"))
										pwk_objRemove(document.getElementById("temp_pic"));

									var container = document.createElement('div')
									container.id = "temp_pic";
									container.appendChild(obj);
									document.getElementsByTagName('BODY')[0].appendChild(container);									

									}

			canvas.onmouseout = function(evt){
									if(document.getElementById("temp_pic"))
									document.getElementsByTagName('BODY')[0].removeChild(document.getElementById('temp_pic'));
									this.style.filter = "";
									//this.parentNode.style.backgroundColor = "rgb(83, 82, 81)";
									//this.parentNode.style.backgroundColor = "#d2d2d2";
									}
		}	
	}	
	

