	//defining position of javascript source code and loading
	/*
	 * 0) insideWSC							:Im WSC und nicht deployed
	 * Es gibt 3 verschiedene Modi im WSC:
	 * 1) locParams.gloPre							:Ansicht in Designauswahl
	 * 2) !locParams.gloPre && !locParams.ediWin	:Vorschau im Editor inline
	 * 3) locParams.ediWin							:Vorschau im Editor neues Fenster
	 
	 * 4) veröffentlicht
	 */
	
	/*here everythng is defined to decide where the sources and the context the page is shown*/
	var locParams = function() {
	}
	
	/*here everythng is defined needed for the html elements*/
	var elemParams = function() {
	}
	elemParams.CONTENTIFRAME	= "myiframe";
	elemParams.OBJECTMENU		= "objFlashMenue";
	elemParams.divList			= new Array();
	elemParams.totalWidth		= 760;

	elemParams.menueHeight      = 500;
	elemParams.menueOffsetTop   = 50;
	elemParams.mainbuttonHeight = 25;
	elemParams.subbuttonHeight  = 25;
	elemParams.scrollContent	= -1;

	/*this values are choosen in the design selection context, when no user sitetree is choosen for content*/
	elemParams.n_main           = 4;
	elemParams.n_sub            = 4;

	if (typeof(decodeURIComponent) == "undefined") {
		elemParams.decodeURIComponent = function(s) {
			return unescape(s);
		}
	} else {
		elemParams.decodeURIComponent = decodeURIComponent;
	}
	
	elemParams.jdecode = function(s) {
		var re = /\+/g;
		s = s.replace(re, "%20");
		return elemParams.decodeURIComponent(s);
	}
	
	locParams.insWSC	= document.location.href.indexOf("/servlet/CMServeRES") >= 0;
	locParams.gloPre	= document.location.href.indexOf("globalPreview") >= 0;
	locParams.ediWin	= parent.document.location.href.indexOf(jencode("/servlet/Show")) >= 0;
	locParams.url		= new URL(document.location.href);
	
	locParams.prefix	= locParams.insWSC ? "/servlet/CMServeRES/" : "";
	locParams.prefixSrc	= locParams.gloPre ? jdecode(locParams.url.getParameter("srcPrefix")) : "";
	locParams.dataSrc	= locParams.gloPre ? locParams.prefixSrc+".js" : locParams.prefix + "include/sitetree.js";
	
	locParams.stdImgDir	= "";
	locParams.palDir	= "";
	locParams.imgDir	= locParams.prefix;
	
	/*
	 * in sitetree.js ist der sitetree und neuerdings auch einige Template-Eigenschaften definiert
	 */
	document.write('<SCRIPT src="' + locParams.dataSrc + '"></' + 'SCRIPT>');
	
	if (locParams.gloPre) {
		var idx = document.location.href.indexOf("?");
		var orig = document.location.href.substring(0, idx)
		idx = orig.lastIndexOf("/");
		orig = orig.substring(idx+1);
	}
	
	/*********************************************************************************/
	function setLocParams() {
		locParams.stdImgDir	= "./templates/" + theTemplate.name +"/img/";
		locParams.palDir	= "./" + theSitetree.paletteFamily + "/";
		locParams.imgDir	+= locParams.stdImgDir + locParams.palDir;
	}
	
	function setSizeParams(totalWidth) {
		elemParams.totalWidth		= totalWidth;
	}
	
	function setSitetreeParams(top, mainbutton, subbutton) {
		elemParams.menueOffsetTop   = top;
		elemParams.mainbuttonHeight = mainbutton;
		elemParams.subbuttonHeight  = subbutton;

		elemParams.n_main           = theSitetree.length;
		for (var i = 0; i < theSitetree.length; i++) {
			if (theSitetree[i][POS_CHILDS].length > elemParams.n_sub) {
				elemParams.n_sub = theSitetree[i][POS_CHILDS].length;
			}
		}
		
		elemParams.menueHeight = elemParams.menueOffsetTop + elemParams.mainbuttonHeight * elemParams.n_main + elemParams.subbuttonHeight * elemParams.n_sub;
	}
	
	function getTotalWidth() {
		return elemParams.totalWidth;
	}
	
	function getCompanyName() {
		if(locParams.insWSC){
			if (window.top.user && !locParams.ediWin)
				return window.top.user.getCompanyname();
			else if(window.top.opener && window.top.opener.top.user)
				return window.top.opener.top.user.getCompanyname();
		}
		return (typeof(companyName)!="undefined" ? companyName : "");
	}
	
	function writeHTMLTitle() {
		var _htmlTitle = "design layout";
		if (locParams.insWSC) {
			_htmlTitle = (typeof window.top.user != "undefined" ? window.top.user.getHtmlTitle() : window.top.opener.top.user.getHtmlTitle());
		} else if (typeof htmlTitle != "undefined") {
			_htmlTitle = elemParams.jdecode(htmlTitle);
		} 
		document.title = _htmlTitle;
	}
			
	function writeMetaTags() {
		var _metaKeywords = "";
		var _metaContents = "";
		if (locParams.insWSC) {
			_metaKeywords = (typeof window.top.user != "undefined" ? window.top.user.getMetaKeywords() : window.top.opener.top.user.getMetaKeywords());
			_metaContents = (typeof window.top.user != "undefined" ? window.top.user.getMetaContents() : window.top.opener.top.user.getMetaContents());
		} else {
			if (typeof(metaKeywords) != "undefined") {
				_metaKeywords = elemParams.jdecode(metaKeywords);
			} 
			if (typeof(metaContents) != "undefined") {
				_metaContents = elemParams.jdecode(metaContents);
			} 
		}
		
		if (_metaKeywords != "") {
			document.write("<META name='keywords' content='" + _metaKeywords + "'>");
		}
		if (_metaContents != "") {
			document.write("<META name='description' content='" + _metaContents + "'>");
			document.write("<META name='abstract' content='" + _metaContents + "'>");
		}
	}
			
	/*
	 * showPage wechselt den Content im IFRAME
	 * Allerdings nur in der deployten Variante
	 */
	function showPage(href, id) {
		if (locParams.gloPre) {
			return;
		}
		if (locParams.insWSC) {
			href = "/servlet/Show?show=Preview1&document=" + id;
		} else {
			href = "." + href;
		}
		window.frames.main.document.location.href=href;
	}
	
	/*
	 * Startseite anzeigen
	 */
	function showMain() {
		var mainSrc;
		var src;
		if (locParams.gloPre) {
			mainSrc = locParams.prefixSrc + ".html";
		} else if ((src = locParams.url.getParameter("src"))) {
			mainSrc  = jdecode(src);
		} else {
			mainSrc = "." + theSitetree[0][POS_HREF];
		}
		window.frames.main.document.location.href = mainSrc;
	}
	
	/*
	 * Diese Methode wird vom Totop-Anchor aufgerufen
	 */
	function scrollBack() {
		if (elemParams.scrollContent > 0) {
			/*the content iframe is scrolled*/
			iFrameScrollBack();
		} else {
			/*the page is scrolled complete*/
			window.document.body.scrollTop = 0;
		}
	}
	
    function iFrameScrollBack() {
        var elem = window.document.getElementById(elemParams.CONTENTIFRAME);
        if (elem) {
                var wnd = elem.contentWindow;
                if (wnd) {
                        wnd.document.body.scrollTop = 0;
                }
        }
    }
    /*
	 * Diese Methode wird vom FlashMenu aufgerufen
	 */
	function handleFlashMenu(main, sub) {
			elemParams.currentPage = 0;
		
		if (locParams.gloPre)
			return;
		main = main-1;
		for (var i = 0; i < theSitetree.length && i <= main; i++) {
			if (theSitetree[i][POS_ISNAVIGATION] == 'false')
				main++;
		}
		if (theSitetree && main < theSitetree.length) {

			elemParams.currentPage = main;

		
			if (sub == 0) {
				// Kein Untermenu ausgewaehlt
				showPage(theSitetree[main][POS_HREF], theSitetree[main][POS_ID]);
			} else {
				sub = sub-1;
				var childpages = theSitetree[main][POS_CHILDS];
				for (var j = 0; j < childpages.length && j <= sub; j++) {
					if (childpages[j][POS_ISNAVIGATION] == 'false')
						sub++;
				}
					showPage(childpages[sub][POS_HREF], childpages[sub][POS_ID]);
			}
		}
	}
	
	/*
	 * onLoad-Handler
	 */
	function initMain(bgcolor) {
	
		if (elemParams.scrollContent < 0) {
			document.body.scroll="auto";
		} else {
			document.body.style.overflow = "hidden";
		}

		if (typeof(bgcolor) == "undefined") {
			bgcolor = ((typeof(theTemplate) != 'undefined' && theTemplate.body_bg_color) ? theTemplate.body_bg_color : "FFFFFF");
		}
		/*this is temporary**********/
		bgcolor = theSitetree.contentBGColor;
		/****************************/
		document.body.style.backgroundColor = bgcolor;
	
		var divList = document.getElementsByTagName("DIV");
		for (var i = 0; i < divList.length; i++) {
			var elem = divList[i];
			if (elem.style && elem.style.position == "absolute") {
				elem.initialLeft = parseInt(elem.style.left);
				elemParams.divList.push(elem);
			}
		}
		if (typeof(initMainTemplate)=="function") {
			initMainTemplate();
		}
		showMain();
	}
	
	/*
	 * Das ist eine Hilfsfunktion, um ein Flash zu plazieren
	*/
	function insertObjectFlash(src,strID,iWidth,iHeight,sScale,sSalign) {
		src = locParams.imgDir + src;
		_insertObjectFlash(src,strID,iWidth,iHeight,sScale,sSalign);
	}
				
	function _insertObjectFlash(src,strID,iWidth,iHeight,sScale,sSalign) {
		var strOut="";
		strOut 	= "<OBJECT "
				+ " style='z-index:2;'"
				+ "	id='"+strID+"'"
				+ "	width='"+iWidth+"'"
				+ "	height='"+iHeight+"'"
				+ "	style='cursor:default; vertical-align:top;'"
				+ " type='application/x-shockwave-flash'"
				+ "	swlivecontent='true'"
				+ "	data='" + src + "'";
		if (window.top.g_clientCheck && window.top.g_clientCheck.isIE4up)
			strOut+= " codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,42,0'";
		else if(window.top.g_clientCheck && window.top.g_clientCheck.isMoz1up)
			strOut += " pluginspage='https://www.macromedia.com/go/getflashplayer'";
		strOut +=">";
		strOut 	+= "<PARAM name='wmode' value='Transparent'></PARAM>"
				+ "<PARAM name='movie' value='" + src + "' ></PARAM>"
				+ "<PARAM name='menu' value='false' ></PARAM>";
		if (sScale) strOut+= "<PARAM name='scale' value='"+sScale+"'></PARAM>";
		if (sSalign) strOut+="<PARAM name='salign' value='"+sSalign+"'></PARAM>";
		strOut  += "<PARAM name='bgcolor' value='#" + theSitetree.contentBGColor + "'></PARAM>"
				+ "</OBJECT>";
		document.write(strOut);
	}
				
	/*
	 * Das ist eine Hilfsfunktion, um ein Image zu plazieren
	 */
	function writeImg(src,xSize,ySize) {
		var s="";
		src = locParams.imgDir + src;
		s+="<IMG border='0' src='" + src+"'";
		if (xSize) s += " width='"+xSize+"'";
		if (ySize) s += " height='"+ySize+"'";
		s+=">";
		document.write(s);
	}
	
	function writeSpacer(xSize, ySize) {
		writeImg("spacer.gif",xSize, ySize);
	}
	/*
	 * Das ist eine Hilfsfunktion, um ein TD mit BackgroundImage zu plazieren (offenes TD)
	 */
	function writeBackgroundTd(src,tdWidth,tdHeight,params,col,row,align,userAttrib) {
		if (typeof(params)=="undefined") {
			params = {};
		}
		src = locParams.imgDir + src;
		
		var s="";
		s	+= "<TD background='"+src+"'"
			+  (tdWidth ? " width='"+tdWidth+"'" : "")
			+  (tdHeight ? " height='"+tdHeight+"'" : "")
			+ (params.cols ? " colspan='"+params.cols+"'" : "")
			+ (params.rows ? " rowspan='"+params.rows+"'" : "")
			+ (params.align ? " valign='"+params.align+"'" : "")
			+ (params.userAttrib ? params.userAttrib : "")
			+ ">"
		;
		document.write(s);
	}
				
	/*
	 * Das ist eine Hilfsfunktion, um das Logo zu plazieren
	 */
	function insertLogo(xSize,ySize) {
		var s="";
		var	src = locParams.imgDir + "logo.gif";
		if (locParams.insWSC) 
			src="/servlet/CMGetDyn/logo_name?foo=" + Math.random();
		else if (typeof(theTemplate.hasCustomLogo) != 'undefined' && theTemplate.hasCustomLogo == 'true') {
			src = locParams.stdImgDir + "logo.gif";
		}
	
		s+="<IMG border='0' src='" + src+"'";
		if (xSize) s += " width='"+xSize+"'";
		if (ySize) s += " height='"+ySize+"'";
		s+=">";
		document.write(s);
	}
				
	/*
	 * Das ist eine Hilfsfunktion, um das Flashmenu zu plazieren
	 */
	function insertMenue(xSize) {
		var src= locParams.prefix + "flash/menu.swf";
		
		if (src.indexOf("/servlet/CMServeRES") > -1)
			src += "?foo=" + Math.random();
		
		if (locParams.gloPre)
			src = locParams.prefixSrc + ".swf";
		_insertObjectFlash(src,elemParams.OBJECTMENU,xSize,elemParams.menueHeight,"noscale","t");
	}
	
	/*
	 * Das ist eine Hilfsfunktion, um das image mit Company name zu plazieren
	*/
	function insertCompanyName(xSize,ySize) {
		if (locParams.insWSC)
			var src = locParams.imgDir + "company_name.gif";
		else
			var src = locParams.stdImgDir + "company_name.gif";
		
		document.write("<IMG src='" + src + "' width='"+xSize+"' height='"+ySize+"'>");
	}
	
	/*
	 * Das ist eine Hilfsfunktion, um den contentIFrame zu plazieren
	 */
	function insertContentIFrame(width) {
		if (typeof(width)=="undefined") {
			width = "100%";
		}

		var s = "";
		s += "<IFRAME"
		  +  (elemParams.scrollContent < 0 ? " scrolling='no' " : "")
		  +  " name='main' frameborder='0'"
		  +  " id='" + elemParams.CONTENTIFRAME + "'"
		  +  " style='background-color:transparent;"
		  +  (elemParams.scrollContent < 0 ? "overflow:hidden;" : "")
		  +  "width:" + width + ";height:" + elemParams.menueHeight + "px;'" 
		  +  " allowtransparency "
		  +  " src='" +(locParams.insWSC ? "/res/common/" : "include/") + "blank.html'"
		  +  (elemParams.scrollContent < 0 ? " onload='resizeMe(this);'" : "")
		  +  ">"
		  +  "</IFRAME>"
		;
		document.write(s);
	}
	
	/*
	 * Das ist eine Hilfsfunktion, um den scrollback anchor samt image zu plazieren
	 */
	function insertTotop(xSize,ySize,params) {
		if (typeof(params)=="undefined") {
			params = {};
		}
		var image = params.image ? params.image : "totop.gif";	
		var str = "";
	
		str += "<A href='javascript:;'"
			+  " onclick='" + (params.onClick ? params.onClick : "scrollBack()")+"'"
			+  " onfocus='this.blur()'>"
		;	
		document.write(str);
		writeImg(image,xSize,ySize);
		document.write("</A>");
	}
	
	/*
	 * Diese function resized den iframe beim wechsel des content
	 */
	function resizeMe(elem) {
		//var menue  = document.getElementById(elemParams.OBJECTMENU);
		elem.style.height = elemParams.menueHeight + "px";
		var newHeight = Math.max(elem.contentWindow.document.body.scrollHeight, elemParams.menueHeight);	
		elem.style.height = newHeight + "px";
		var newWidth = elem.contentWindow.document.body.scrollWidth;
		if (newWidth)
			elem.style.width = newWidth;
		//if (menue) {
			//menue.height = elemParams.menueHeight;//newHeight;
		//}
	}

	/*
	 * Diese function resized den iframe, falls dieser den scrollbalken haben soll (elemParams.scrollContent > -1) 
	 */
	function resizeMainFrame() {
		var isIE = navigator.userAgent.toLowerCase().indexOf("msie") > -1;
		var iframe = document.getElementById(elemParams.CONTENTIFRAME);
		var bodyHeight = (isIE ? document.body.clientHeight : window.innerHeight);
		var newHeight = bodyHeight - (elemParams.scrollContent < 0 ? 0 : elemParams.scrollContent);	
		
		iframe.style.height = newHeight + "px";
	}

	/*not in use yet*/
	function scrollMenue() {
		var div = document.getElementById("LayerMenueFlash");
		div.style.top = Math.max(118,document.body.scrollTop + 21) + "px";
	}
	
	
	/*
	 * onload und onresize handler 
	 */
	function doPosition() {
		if (!(elemParams.scrollContent < 0)){
			resizeMainFrame();
		}

		if (locParams.gloPre) return;
		
		var elem = document.body;
		var x = Math.floor((elem.offsetWidth - elemParams.totalWidth)/2);
		if (elem.offsetWidth < elemParams.totalWidth)
			x = 0;
		for (var i = 0; i < elemParams.divList.length; i++) {
			var divElem = elemParams.divList[i];
			divElem.style.left = divElem.initialLeft + x;
		}
	}
	
	function helperInit(xMax, top, mainbutton, subbutton, scroll) {

		//window.onscroll = function(){scrollMenue();}
		
		if (typeof(scroll) != "undefined"){
			elemParams.scrollContent = scroll;
		}
		setSizeParams(xMax);
		setLocParams();
		setSitetreeParams(top, mainbutton, subbutton);
		writeHTMLTitle();
		writeMetaTags();
	}
