
var oMyPage = null;
var oMyPageLayout = new myLayout ();
xAddEventListener (window, 'load', initializePage, false);
xAddEventListener (window, 'resize', resizePage, false);


function loadElement ( oElement, sElementID )
{
    oElement=xGetElementById(sElementID);
    if (oElement==null) { alert ("Fehler beim Laden des Elements \"" + sElementID + "\"."); return null; };
    return oElement;
}

// ******************************************************************************************************************

// Page Layout Definition
function myLayout () {
    this.sBaseURL = "/framework/";
    this.iPageHeaderHeight  = 0;
    this.iPageFooterHeight  = 0;
    this.iPageLeftBarWidth  = 0;
    this.iPageRightBarWidth = 0;
    this.iPageContentWidth  = 0;
    
    this.sLayout       = "001"     ; // 001 - 999 !check if layout is available!
    this.sPageHAlign   = "center"  ; // center | left | right
    this.sHeaderStyle  = "dynamic" ; // fixed | dynamic
    this.sFooterStyle  = "fixed"   ; // fixed | dynamic
    
    this.sPageHeaderBGcolor = "";
    this.sPageLeftBarBGcolor = "";
    this.sPageContentBGcolor = "";
    this.sPageRightBarBGcolor = "";
    this.sPageFooterBGcolor = "";
    
    this.displayWidth        = layoutDisplayWidth ;
    this.headerHeight        = layoutHeaderHeight ;
    this.footerHeight        = layoutFooterHeight ;
    this.leftBarWidth        = layoutLeftBarWidth ;
    this.rightBarWidth       = layoutRightBarWidth ;
    this.rightBarXoffset     = layoutRightBarXoffset ;
    this.contentWidth        = layoutContentWidth ;
    this.styleSheetBase      = styleSheetBase ;
    this.styleSheetPositions = styleSheetPositions ;
}


function layoutDisplayWidth () {
    var iWidth = 0;
    if ( this.iPageContentWidth > 0 ) { iWidth = iWidth + this.iPageContentWidth ; };
    if ( this.iPageLeftBarWidth > 0 ) { iWidth = iWidth + this.iPageLeftBarWidth ; };
    if ( this.iPageRightBarWidth > 0 ) { iWidth = iWidth + this.iPageRightBarWidth ; };
    return iWidth;
}

function layoutHeaderHeight () {
    var iHeight = 0;
    if ( this.iPageHeaderHeight > 0 ) { iHeight = this.iPageHeaderHeight ; };
    return iHeight;
}

function layoutFooterHeight () {
    var iHeight = 0;
    if ( this.iPageFooterHeight > 0 ) { iHeight = this.iPageFooterHeight ; };
    return iHeight;
}

function layoutLeftBarWidth () {
    var iXoffset = 0;
    if ( this.iPageLeftBarWidth > 0 ) { iXoffset = this.iPageLeftBarWidth ; };
    return iXoffset;
}

function layoutRightBarWidth () {
    var iXoffset = 0;
    if ( this.iPageRightBarWidth > 0 ) { iXoffset = this.iPageRightBarWidth ; };
    return iXoffset;
}

function layoutRightBarXoffset () {
    var iXoffset = 0;
    if ( this.iPageLeftBarWidth > 0 ) { iXoffset = iXoffset + this.iPageLeftBarWidth ; };
    if ( this.iPageContentWidth > 0 ) { iXoffset = iXoffset + this.iPageContentWidth ; };
    return iXoffset;
}

function layoutContentWidth () {
    var iWidth = 0;
    if ( this.iPageContentWidth > 0 ) { iWidth = this.iPageContentWidth ; };
    return iWidth;
}

function styleSheetBase () {
    var sStyleSheet = this.sBaseURL;
    sStyleSheet = sStyleSheet + "styles/layout_common_base";
    sStyleSheet = sStyleSheet + ".css";
    return sStyleSheet;
}

function styleSheetPositions () {
    var sStyleSheet = this.sBaseURL;
    sStyleSheet = sStyleSheet + "styles/layout_" + this.sLayout + "_";
    switch (this.sHeaderStyle){
	case "fixed":
	    sStyleSheet = sStyleSheet + "f";
	    break;
	default:
	    sStyleSheet = sStyleSheet + "d";
	    break;
    }
    switch (this.sFooterStyle){
	case "fixed":
	    sStyleSheet = sStyleSheet + "f";
	    break;
	default:
	    sStyleSheet = sStyleSheet + "d";
	    break;
    }
    sStyleSheet = sStyleSheet + ".css";
    return sStyleSheet;
}


// ************************************************************************************************************************

// Layout Element Object
function singleLayoutElement( sID ) {
    this.isloaded = false;
    this.sElementID = "";
    this.oElement = null;
    this.iLeft   = 0;
    this.iTop    = 0;
    this.iWidth  = 0;
    this.iHeight = 0;
    this.iZIndex = 0;
    this.sDisplay = "";
    this.sBackgroundColor = "";
    this.oStyles = new Array();
    this.oChangeList = new Array();
    
    this.markChange   = singleLayoutElementMarkChange ;
    this.applyChanges = singleLayoutElementApplyChanges ;
    this.addStyle     = singleLayoutElementAddStyle ;
    this.moveTo       = singleLayoutElementMoveTo ;
    this.setWidth     = singleLayoutElementSetWidth ;
    this.setHeight    = singleLayoutElementSetHeight ;
    this.setZIndex    = singleLayoutElementSetZIndex ;
    this.setDisplay   = singleLayoutElementSetDisplay ;
    this.getHeight    = singleLayoutElementGetHeight ;
    this.setVisibilityNow = singleLayoutElementSetVisibilityNow ;
    
    if ( ! sID ) { return false; };
    var sIDcheck = typeof sID;
    if ( sIDcheck != "string" ) { return false; };
    this.sElementID = sID
    this.oElement = xGetElementById(this.sElementID);
//    if (this.oElement==null) { return false; };
    if (this.oElement==null) { alert ("Fehler beim Laden des Elements \"" + this.sElementID + "\".") ;return false; };
    this.isloaded = true;
}

function singleLayoutElementApplyChanges () {
    if ( this.oChangeList.length < 1 ) { return false; };
    for ( var iX=0;iX < this.oChangeList.length; ++iX ) {
	switch (this.oChangeList[iX]){
	    case "left":
		break;
	    case "moveto":
		xMoveTo (this.oElement , this.iLeft , this.iTop );
		break;
	    case "width":
	        xWidth  ( this.oElement , this.iWidth);
		break;
	    case "height":
	        xHeight ( this.oElement , this.iHeight);
	        break;
	    case "zindex":
	        xZIndex( this.oElement , this.iZIndex );
		break;
	    case "display":
	        xDisplay ( this.oElement , this.sDisplay );
	        break;
	    case "style":
	        for (var sStyle in this.oStyles) {
	            xStyle ( sStyle , this.oStyles[sStyle] , this.oElement );
	        }
		break;
	    default:
		alert ("Unbekannter Aenderungstyp \"" + this.oChangeList[iX] + "\" in Aenderungsliste des Elementes \"" + this.sElementID + "\".");
		break;
	}
    }
}

function singleLayoutElementMarkChange ( sName ) {
    var sTypoCheck = typeof sName ;
    if ( sTypoCheck != "string" ) { return false; };
    if ( sName == "" ) { return false; };
    sName = sName.toLowerCase();
    if ( this.oChangeList.length == 0 ) {
	this.oChangeList[0] = sName;    
    } else {
	var bIsAllreadyMarked = false;
	for ( var iX=0;iX < this.oChangeList.length; ++iX ) {
	    if ( this.oChangeList[iX] == sName ) {
		bIsAllreadyMarked = true;
		iX = this.oChangeList.length;
	    }
	}
	if ( ! bIsAllreadyMarked ) { this.oChangeList[this.oChangeList.length] = sName; }
    }
    return true;
}

function singleLayoutElementAddStyle ( sName, sValue ) {
    var sTypoCheck = typeof sName ;
    if ( sTypoCheck != "string" ) { return false; };
    sTypoCheck = typeof sValue ;
    if ( sTypoCheck != "string" ) { return false; };
    if ( sName == "" ) { return false; };
    this.oStyles[sName] = sValue;
    this.markChange("style");
    return true;
}

function singleLayoutElementMoveTo ( iNewLeft, iNewTop) {
    var sTypoCheck = typeof iNewLeft ;
    if ( sTypoCheck != "number" ) { return false; };
    sTypoCheck = typeof iNewTop ;
    if ( sTypoCheck != "number" ) { return false; };
    if ( iNewLeft < 0 ) { iNewLeft = 0 ; };
    if ( iNewTop < 0 ) { iNewTop = 0 ; };
    this.iLeft = iNewLeft;
    this.iTop = iNewTop;
    this.markChange("moveto");
    return true;
}

function singleLayoutElementSetWidth( iNewWidth) {
    var sTypoCheck = typeof iNewWidth ;
    if ( sTypoCheck != "number" ) { return false; };
    if ( iNewWidth < 0 ) { iNewWidth = 0 ; };
    this.iWidth = iNewWidth;
    this.markChange("width");
    return true;
}

function singleLayoutElementSetHeight( iNewHeight ) {
    var sTypoCheck = typeof iNewHeight ;
    if ( sTypoCheck != "number" ) { return false; };
    if ( iNewHeight < 0 ) { iNewHeight = 0 ; };
    this.iHeight = iNewHeight;
    this.markChange("height");
    return true;
}

function singleLayoutElementSetZIndex( iNewZIndex) {
    var sTypoCheck = typeof iNewZIndex ;
    if ( sTypoCheck != "number" ) { return false; };
    if ( iNewZIndex < 0 ) { iNewZIndex = 0 ; };
    this.iZIndex = iNewZIndex;
    this.markChange("zindex");
    return true;
}

function singleLayoutElementSetDisplay( sNewDisplay) {
    var sTypoCheck = typeof sNewDisplay ;
    if ( sTypoCheck != "string" ) { return false; };
    this.sDisplay = sNewDisplay;
    this.markChange("display");
    return true;
}

function singleLayoutElementGetHeight() {
    var iHeight = -1;
    iHeight = xHeight ( this.oElement );
    return iHeight;
}

function singleLayoutElementSetVisibilityNow ( bNewVisibility ) {
    var sTypoCheck = typeof bNewVisibility ;
    if ( sTypoCheck != "boolean" ) { return false; };
    if ( bNewVisibility ) { 
	xVisibility (this.oElement , true);
    } else {
	xVisibility (this.oElement , false);
    }
}


// ************************************************************************************************************************

// Page Objects
function myPage () {
    this.isloaded = true;
    this.sElementsList = new Array ();
    this.oElements = new Array ();


    this.sElementsList["PreloaderDisplay"]         = "PreloaderDisplay";
    this.sElementsList["Header"]                   = "PageHeader";
    this.sElementsList["LeftBarHeaderWhitespace"]  = "PageLeftBarHeaderWhitespace";
    this.sElementsList["LeftBar"]                  = "PageLeftBar";
    this.sElementsList["LeftBarFooterWhitespace"]  = "PageLeftBarFooterWhitespace";
    this.sElementsList["ContentHeaderWhitespace"]  = "PageContentHeaderWhitespace";
    this.sElementsList["Content"]                  = "PageContent";
    this.sElementsList["ContentFooterWhitespace"]  = "PageContentFooterWhitespace";
    this.sElementsList["RightBarHeaderWhitespace"] = "PageRightBarHeaderWhitespace";
    this.sElementsList["RightBar"]                 = "PageRightBar";
    this.sElementsList["RightBarFooterWhitespace"] = "PageRightBarFooterWhitespace";
    this.sElementsList["Footer"]                   = "PageFooter";
    
    for (var sElement in this.sElementsList) {
	this.oElements[sElement] = new singleLayoutElement ( this.sElementsList[sElement] );
	if ( !this.oElements[sElement].isloaded ) { this.isloaded = false ; };
    }


    
    this.clearPreloaderDisplay  = pageClearPreloaderDisplay;
}

function pageClearPreloaderDisplay () {
    this.oElements["PreloaderDisplay"].setVisibilityNow (false);

}

// ************************************************************************************************************************

function layout001calculate () {
    var iNewPageDisplayLeftPos = 0;
    var iNewPageDisplayTopPos = 0;
    var iNewPageDisplayWidth = 0;
    var iNewPageDisplayHeight = 0;
    var iCurrentWindowHeight = xClientHeight();
    var iCurrentWindowWidth = xClientWidth();
    iNewPageDisplayWidth = oMyPageLayout.displayWidth();


    switch (oMyPageLayout.sPageHAlign){
	case "center":
	    iNewPageDisplayLeftPos=(iCurrentWindowWidth-iNewPageDisplayWidth)/2;
	    break;
	case "right":
	    iNewPageDisplayLeftPos=(iCurrentWindowWidth-iNewPageDisplayWidth);
	    break;
	default:
	    iNewPageDisplayLeftPos = 0;
	    iNewPageDisplayTopPos = 0;
	    break;
    }
    if ( iNewPageDisplayWidth > iCurrentWindowWidth ) { iNewPageDisplayLeftPos = 0; };


    if ( oMyPageLayout.headerHeight() > 0 ) {
	oMyPage.oElements["Header"].moveTo ( iNewPageDisplayLeftPos, iNewPageDisplayTopPos ) ;
	oMyPage.oElements["Header"].setWidth ( iNewPageDisplayWidth ) ;
	oMyPage.oElements["Header"].setHeight ( oMyPageLayout.headerHeight() ) ;
	oMyPage.oElements["Header"].setZIndex ( 3 ) ;
	oMyPage.oElements["Header"].sDisplay = "" ;
	oMyPage.oElements["Header"].addStyle("backgroundColor", oMyPageLayout.sPageHeaderBGcolor) ;
        oMyPage.oElements["Header"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["Header"].setDisplay ( "none" ) ;
    }


    // Zuerst die Whitespaces auf 0 setzen um korrekte Hoehe des Contents zu ermitteln
    // um die sich daraus ergebende Hoehe des FooterWhitespaces zu setzen
    xHeight ( oMyPage.oElements["ContentHeaderWhitespace"].oElement , 0);
    xHeight ( oMyPage.oElements["ContentFooterWhitespace"].oElement , 0);
    var iContentMinHeight = iCurrentWindowHeight - oMyPageLayout.headerHeight() - oMyPageLayout.footerHeight();
    var iContentHeight = oMyPage.oElements["Content"].getHeight();
    var iFooterWhitespaceHeight = iContentMinHeight - iContentHeight;
    if (iFooterWhitespaceHeight < 0) { iFooterWhitespaceHeight = oMyPageLayout.footerHeight() ; } else { iFooterWhitespaceHeight += oMyPageLayout.footerHeight()  };
    

    oMyPage.oElements["ContentHeaderWhitespace"].setHeight ( oMyPageLayout.headerHeight() );
    oMyPage.oElements["Content"].moveTo (iNewPageDisplayLeftPos + oMyPageLayout.leftBarWidth(), iNewPageDisplayTopPos);
    oMyPage.oElements["Content"].setWidth ( oMyPageLayout.contentWidth() );
    oMyPage.oElements["Content"].setZIndex ( 0 );
    oMyPage.oElements["ContentFooterWhitespace"].setHeight ( iFooterWhitespaceHeight );
    oMyPage.oElements["Content"].addStyle("backgroundColor", oMyPageLayout.sPageContentBGcolor) ;
    oMyPage.oElements["Content"].addStyle("overflow", "hidden") ;

//
    if ( oMyPageLayout.leftBarWidth() > 0 ) {
	oMyPage.oElements["LeftBarHeaderWhitespace"].setHeight ( oMyPageLayout.headerHeight() ) ;
	oMyPage.oElements["LeftBar"].moveTo ( iNewPageDisplayLeftPos , iNewPageDisplayTopPos ) ;
	oMyPage.oElements["LeftBar"].setWidth ( oMyPageLayout.leftBarWidth() ) ;
	oMyPage.oElements["LeftBar"].setHeight ( oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight ) ;
	oMyPage.oElements["LeftBar"].setZIndex ( 1 ) ;
	oMyPage.oElements["LeftBarFooterWhitespace"].setHeight ( iFooterWhitespaceHeight ) ;
	oMyPage.oElements["LeftBar"].sDisplay = "" ;
	oMyPage.oElements["LeftBar"].addStyle("backgroundColor", oMyPageLayout.sPageLeftBarBGcolor) ;
        oMyPage.oElements["LeftBar"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["LeftBar"].setDisplay ( "none" ) ;
    }

    if ( oMyPageLayout.rightBarWidth() > 0 ) {
	oMyPage.oElements["RightBarHeaderWhitespace"].setHeight ( oMyPageLayout.headerHeight() ) ;
	oMyPage.oElements["RightBar"].moveTo ( iNewPageDisplayLeftPos + oMyPageLayout.rightBarXoffset() , iNewPageDisplayTopPos ) ;
	oMyPage.oElements["RightBar"].setWidth ( oMyPageLayout.rightBarWidth() ) ;
	oMyPage.oElements["RightBar"].setHeight ( oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight ) ;
	oMyPage.oElements["RightBar"].setZIndex ( 1 ) ;
	oMyPage.oElements["RightBarFooterWhitespace"].setHeight ( iFooterWhitespaceHeight ) ;
	oMyPage.oElements["RightBar"].sDisplay = "" ;
	oMyPage.oElements["RightBar"].addStyle("backgroundColor", oMyPageLayout.sPageRightBarBGcolor) ;
        oMyPage.oElements["RightBar"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["RightBar"].setDisplay ( "none" ) ;
    }

    if ( oMyPageLayout.footerHeight() > 0 ) {
	switch (oMyPageLayout.sFooterStyle){
	    case "fixed":
		oMyPage.oElements["Footer"].moveTo ( iNewPageDisplayLeftPos , iCurrentWindowHeight - oMyPageLayout.footerHeight() ) ;
		break;
	    default: //dynamic
		oMyPage.oElements["Footer"].moveTo ( iNewPageDisplayLeftPos , oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight - oMyPageLayout.footerHeight() ) ;
		break;
	}
	oMyPage.oElements["Footer"].setWidth ( iNewPageDisplayWidth ) ;
	oMyPage.oElements["Footer"].setHeight ( oMyPageLayout.footerHeight() ) ;
	oMyPage.oElements["Footer"].setZIndex ( 2 ) ;
	oMyPage.oElements["Footer"].sDisplay = "" ;
	oMyPage.oElements["Footer"].addStyle("backgroundColor", oMyPageLayout.sPageFooterBGcolor) ;
        oMyPage.oElements["Footer"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["Footer"].setDisplay ( "none" ) ;
    }

}


// ************************************************************************************************************************

function layout002calculate () {
    var iNewPageDisplayLeftPos = 0;
    var iNewPageDisplayTopPos = 0;
    var iNewPageDisplayWidth = 0;
    var iNewPageDisplayHeight = 0;
    var iCurrentWindowHeight = xClientHeight();
    var iCurrentWindowWidth = xClientWidth();
    iNewPageDisplayWidth = oMyPageLayout.displayWidth();


    switch (oMyPageLayout.sPageHAlign){
	case "center":
	    iNewPageDisplayLeftPos=(iCurrentWindowWidth-iNewPageDisplayWidth)/2;
	    break;
	case "right":
	    iNewPageDisplayLeftPos=(iCurrentWindowWidth-iNewPageDisplayWidth);
	    break;
	default:
	    iNewPageDisplayLeftPos = 0;
	    iNewPageDisplayTopPos = 0;
	    break;
    }
    if ( iNewPageDisplayWidth > iCurrentWindowWidth ) { iNewPageDisplayLeftPos = 0; };


    if ( oMyPageLayout.headerHeight() > 0 ) {
	oMyPage.oElements["Header"].moveTo ( iNewPageDisplayLeftPos + oMyPageLayout.leftBarWidth(), iNewPageDisplayTopPos ) ;
	oMyPage.oElements["Header"].setWidth ( iNewPageDisplayWidth - oMyPageLayout.leftBarWidth() - oMyPageLayout.rightBarWidth()) ;
	oMyPage.oElements["Header"].setHeight ( oMyPageLayout.headerHeight() ) ;
	oMyPage.oElements["Header"].setZIndex ( 3 ) ;
	oMyPage.oElements["Header"].sDisplay = "" ;
	oMyPage.oElements["Header"].addStyle("backgroundColor", oMyPageLayout.sPageHeaderBGcolor) ;
        oMyPage.oElements["Header"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["Header"].setDisplay ( "none" ) ;
    }


    // Zuerst die Whitespaces auf 0 setzen um korrekte Hoehe des Contents zu ermitteln
    // um die sich daraus ergebende Hoehe des FooterWhitespaces zu setzen
    xHeight ( oMyPage.oElements["ContentHeaderWhitespace"].oElement , 0);
    xHeight ( oMyPage.oElements["ContentFooterWhitespace"].oElement , 0);
    var iContentMinHeight = iCurrentWindowHeight - oMyPageLayout.headerHeight() - oMyPageLayout.footerHeight();
    var iContentHeight = oMyPage.oElements["Content"].getHeight();
    var iFooterWhitespaceHeight = iContentMinHeight - iContentHeight;
    if (iFooterWhitespaceHeight < 0) { iFooterWhitespaceHeight = oMyPageLayout.footerHeight() ; } else { iFooterWhitespaceHeight += oMyPageLayout.footerHeight()  };
    

    oMyPage.oElements["ContentHeaderWhitespace"].setHeight ( oMyPageLayout.headerHeight() );
    oMyPage.oElements["Content"].moveTo (iNewPageDisplayLeftPos + oMyPageLayout.leftBarWidth(), iNewPageDisplayTopPos);
    oMyPage.oElements["Content"].setWidth ( oMyPageLayout.contentWidth() );
    oMyPage.oElements["Content"].setZIndex ( 0 );
    oMyPage.oElements["ContentFooterWhitespace"].setHeight ( 0 );
    oMyPage.oElements["Content"].addStyle("backgroundColor", oMyPageLayout.sPageContentBGcolor) ;
    oMyPage.oElements["Content"].addStyle("overflow", "hidden") ;

//
    if ( oMyPageLayout.leftBarWidth() > 0 ) {
	oMyPage.oElements["LeftBarHeaderWhitespace"].setHeight ( 0 ) ;
	oMyPage.oElements["LeftBar"].moveTo ( iNewPageDisplayLeftPos , iNewPageDisplayTopPos ) ;
	oMyPage.oElements["LeftBar"].setWidth ( oMyPageLayout.leftBarWidth() ) ;
	oMyPage.oElements["LeftBar"].setHeight ( oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight ) ;
	oMyPage.oElements["LeftBar"].setZIndex ( 1 ) ;
	oMyPage.oElements["LeftBarFooterWhitespace"].setHeight ( 0 ) ;
	oMyPage.oElements["LeftBar"].sDisplay = "" ;
	oMyPage.oElements["LeftBar"].addStyle("backgroundColor", oMyPageLayout.sPageLeftBarBGcolor) ;
        oMyPage.oElements["LeftBar"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["LeftBar"].setDisplay ( "none" ) ;
    }

    if ( oMyPageLayout.rightBarWidth() > 0 ) {
	oMyPage.oElements["RightBarHeaderWhitespace"].setHeight ( 0 ) ;
	oMyPage.oElements["RightBar"].moveTo ( iNewPageDisplayLeftPos + oMyPageLayout.rightBarXoffset() , iNewPageDisplayTopPos ) ;
	oMyPage.oElements["RightBar"].setWidth ( oMyPageLayout.rightBarWidth() ) ;
	oMyPage.oElements["RightBar"].setHeight ( oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight ) ;
	oMyPage.oElements["RightBar"].setZIndex ( 1 ) ;
	oMyPage.oElements["RightBarFooterWhitespace"].setHeight ( iFooterWhitespaceHeight ) ;
	oMyPage.oElements["RightBar"].sDisplay = "" ;
	oMyPage.oElements["RightBar"].addStyle("backgroundColor", oMyPageLayout.sPageRightBarBGcolor) ;
        oMyPage.oElements["RightBar"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["RightBar"].setDisplay ( "none" ) ;
    }

    if ( oMyPageLayout.footerHeight() > 0 ) {
	switch (oMyPageLayout.sFooterStyle){
	    case "fixed":
		oMyPage.oElements["Footer"].moveTo ( iNewPageDisplayLeftPos  + oMyPageLayout.leftBarWidth(), iCurrentWindowHeight - oMyPageLayout.footerHeight() ) ;
		break;
	    default: //dynamic
		oMyPage.oElements["Footer"].moveTo ( iNewPageDisplayLeftPos  + oMyPageLayout.leftBarWidth(), oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight - oMyPageLayout.footerHeight() ) ;
		break;
	}
	oMyPage.oElements["Footer"].setWidth ( iNewPageDisplayWidth - oMyPageLayout.leftBarWidth() - oMyPageLayout.rightBarWidth()) ;
	oMyPage.oElements["Footer"].setHeight ( oMyPageLayout.footerHeight() ) ;
	oMyPage.oElements["Footer"].setZIndex ( 2 ) ;
	oMyPage.oElements["Footer"].sDisplay = "" ;
	oMyPage.oElements["Footer"].addStyle("backgroundColor", oMyPageLayout.sPageFooterBGcolor) ;
        oMyPage.oElements["Footer"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["Footer"].setDisplay ( "none" ) ;
    }

}

// ************************************************************************************************************************

function layout003calculate () {
    var iNewPageDisplayLeftPos = 0;
    var iNewPageDisplayTopPos = 0;
    var iNewPageDisplayWidth = 0;
    var iNewPageDisplayHeight = 0;
    var iCurrentWindowHeight = xClientHeight();
    var iCurrentWindowWidth = xClientWidth();
    iNewPageDisplayWidth = oMyPageLayout.displayWidth();


    switch (oMyPageLayout.sPageHAlign){
	case "center":
	    iNewPageDisplayLeftPos=(iCurrentWindowWidth-iNewPageDisplayWidth)/2;
	    break;
	case "right":
	    iNewPageDisplayLeftPos=(iCurrentWindowWidth-iNewPageDisplayWidth);
	    break;
	default:
	    iNewPageDisplayLeftPos = 0;
	    iNewPageDisplayTopPos = 0;
	    break;
    }
    if ( iNewPageDisplayWidth > iCurrentWindowWidth ) { iNewPageDisplayLeftPos = 0; };


    if ( oMyPageLayout.headerHeight() > 0 ) {
	oMyPage.oElements["Header"].moveTo ( iNewPageDisplayLeftPos, iNewPageDisplayTopPos ) ;
	oMyPage.oElements["Header"].setWidth ( iNewPageDisplayWidth - oMyPageLayout.rightBarWidth()) ;
	oMyPage.oElements["Header"].setHeight ( oMyPageLayout.headerHeight() ) ;
	oMyPage.oElements["Header"].setZIndex ( 3 ) ;
	oMyPage.oElements["Header"].sDisplay = "" ;
	oMyPage.oElements["Header"].addStyle("backgroundColor", oMyPageLayout.sPageHeaderBGcolor) ;
        oMyPage.oElements["Header"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["Header"].setDisplay ( "none" ) ;
    }


    // Zuerst die Whitespaces auf 0 setzen um korrekte Hoehe des Contents zu ermitteln
    // um die sich daraus ergebende Hoehe des FooterWhitespaces zu setzen
    xHeight ( oMyPage.oElements["ContentHeaderWhitespace"].oElement , 0);
    xHeight ( oMyPage.oElements["ContentFooterWhitespace"].oElement , 0);
    var iContentMinHeight = iCurrentWindowHeight - oMyPageLayout.headerHeight() - oMyPageLayout.footerHeight();
    var iContentHeight = oMyPage.oElements["Content"].getHeight();
    var iFooterWhitespaceHeight = iContentMinHeight - iContentHeight;
    if (iFooterWhitespaceHeight < 0) { iFooterWhitespaceHeight = oMyPageLayout.footerHeight() ; } else { iFooterWhitespaceHeight += oMyPageLayout.footerHeight()  };
    

    oMyPage.oElements["ContentHeaderWhitespace"].setHeight ( oMyPageLayout.headerHeight() );
    oMyPage.oElements["Content"].moveTo (iNewPageDisplayLeftPos + oMyPageLayout.leftBarWidth(), iNewPageDisplayTopPos);
    oMyPage.oElements["Content"].setWidth ( oMyPageLayout.contentWidth() );
    oMyPage.oElements["Content"].setZIndex ( 0 );
    oMyPage.oElements["ContentFooterWhitespace"].setHeight ( iFooterWhitespaceHeight );
    oMyPage.oElements["Content"].addStyle("backgroundColor", oMyPageLayout.sPageContentBGcolor) ;
    oMyPage.oElements["Content"].addStyle("overflow", "hidden") ;

//
    if ( oMyPageLayout.leftBarWidth() > 0 ) {
	oMyPage.oElements["LeftBarHeaderWhitespace"].setHeight ( oMyPageLayout.headerHeight() ) ;
	oMyPage.oElements["LeftBar"].moveTo ( iNewPageDisplayLeftPos , iNewPageDisplayTopPos ) ;
	oMyPage.oElements["LeftBar"].setWidth ( oMyPageLayout.leftBarWidth() ) ;
	oMyPage.oElements["LeftBar"].setHeight ( oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight ) ;
	oMyPage.oElements["LeftBar"].setZIndex ( 1 ) ;
	oMyPage.oElements["LeftBarFooterWhitespace"].setHeight ( iFooterWhitespaceHeight ) ;
	oMyPage.oElements["LeftBar"].sDisplay = "" ;
	oMyPage.oElements["LeftBar"].addStyle("backgroundColor", oMyPageLayout.sPageLeftBarBGcolor) ;
        oMyPage.oElements["LeftBar"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["LeftBar"].setDisplay ( "none" ) ;
    }

    if ( oMyPageLayout.rightBarWidth() > 0 ) {
	oMyPage.oElements["RightBarHeaderWhitespace"].setHeight( 0 ) ;
	oMyPage.oElements["RightBar"].moveTo ( iNewPageDisplayLeftPos + oMyPageLayout.rightBarXoffset() , iNewPageDisplayTopPos ) ;
	oMyPage.oElements["RightBar"].setWidth ( oMyPageLayout.rightBarWidth() ) ;
	oMyPage.oElements["RightBar"].setHeight ( oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight ) ;
	oMyPage.oElements["RightBar"].setZIndex ( 1 ) ;
	oMyPage.oElements["RightBarFooterWhitespace"].setHeight ( iFooterWhitespaceHeight ) ;
	oMyPage.oElements["RightBar"].sDisplay = "" ;
	oMyPage.oElements["RightBar"].addStyle("backgroundColor", oMyPageLayout.sPageRightBarBGcolor) ;
        oMyPage.oElements["RightBar"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["RightBar"].setDisplay ( "none" ) ;
    }

    if ( oMyPageLayout.footerHeight() > 0 ) {
	switch (oMyPageLayout.sFooterStyle){
	    case "fixed":
		oMyPage.oElements["Footer"].moveTo ( iNewPageDisplayLeftPos , iCurrentWindowHeight - oMyPageLayout.footerHeight() ) ;
		break;
	    default: //dynamic
		oMyPage.oElements["Footer"].moveTo ( iNewPageDisplayLeftPos , oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight - oMyPageLayout.footerHeight() ) ;
		break;
	}
	oMyPage.oElements["Footer"].setWidth ( iNewPageDisplayWidth ) ;
	oMyPage.oElements["Footer"].setHeight ( oMyPageLayout.footerHeight() ) ;
	oMyPage.oElements["Footer"].setZIndex ( 2 ) ;
	oMyPage.oElements["Footer"].sDisplay = "" ;
	oMyPage.oElements["Footer"].addStyle("backgroundColor", oMyPageLayout.sPageFooterBGcolor) ;
        oMyPage.oElements["Footer"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["Footer"].setDisplay ( "none" ) ;
    }

}




// ************************************************************************************************************************

function layout004calculate () {
    var iNewPageDisplayLeftPos = 0;
    var iNewPageDisplayTopPos = 0;
    var iNewPageDisplayWidth = 0;
    var iNewPageDisplayHeight = 0;
    var iCurrentWindowHeight = xClientHeight();
    var iCurrentWindowWidth = xClientWidth();
    iNewPageDisplayWidth = oMyPageLayout.displayWidth();

    switch (oMyPageLayout.sPageHAlign){
	case "center":
	    iNewPageDisplayLeftPos=(iCurrentWindowWidth-iNewPageDisplayWidth)/2;
	    break;
	case "right":
	    iNewPageDisplayLeftPos=(iCurrentWindowWidth-iNewPageDisplayWidth);
	    break;
	default:
	    iNewPageDisplayLeftPos = 0;
	    iNewPageDisplayTopPos = 0;
	    break;
    }
    if ( iNewPageDisplayWidth > iCurrentWindowWidth ) { iNewPageDisplayLeftPos = 0; };


    if ( oMyPageLayout.headerHeight() > 0 ) {
	oMyPage.oElements["Header"].moveTo ( iNewPageDisplayLeftPos + oMyPageLayout.leftBarWidth(), iNewPageDisplayTopPos ) ;
	oMyPage.oElements["Header"].setWidth ( iNewPageDisplayWidth - oMyPageLayout.leftBarWidth() - oMyPageLayout.rightBarWidth()) ;
	oMyPage.oElements["Header"].setHeight ( oMyPageLayout.headerHeight() ) ;
	oMyPage.oElements["Header"].setZIndex ( 3 ) ;
	oMyPage.oElements["Header"].sDisplay = "" ;
	oMyPage.oElements["Header"].addStyle("backgroundColor", oMyPageLayout.sPageHeaderBGcolor) ;
        oMyPage.oElements["Header"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["Header"].setDisplay ( "none" ) ;
    }


    // Zuerst die Whitespaces auf 0 setzen um korrekte Hoehe des Contents zu ermitteln
    // um die sich daraus ergebende Hoehe des FooterWhitespaces zu setzen
    xHeight ( oMyPage.oElements["ContentHeaderWhitespace"].oElement , 0);
    xHeight ( oMyPage.oElements["ContentFooterWhitespace"].oElement , 0);
    var iContentMinHeight = iCurrentWindowHeight - oMyPageLayout.headerHeight() - oMyPageLayout.footerHeight();
    var iContentHeight = oMyPage.oElements["Content"].getHeight();
    var iFooterWhitespaceHeight = iContentMinHeight - iContentHeight;
    if (iFooterWhitespaceHeight < 0) { iFooterWhitespaceHeight = oMyPageLayout.footerHeight() ; } else { iFooterWhitespaceHeight += oMyPageLayout.footerHeight()  };
    

    oMyPage.oElements["ContentHeaderWhitespace"].setHeight ( oMyPageLayout.headerHeight() );
    oMyPage.oElements["Content"].moveTo (iNewPageDisplayLeftPos + oMyPageLayout.leftBarWidth(), iNewPageDisplayTopPos);
    oMyPage.oElements["Content"].setWidth ( oMyPageLayout.contentWidth() );
    oMyPage.oElements["Content"].setZIndex ( 0 );
    oMyPage.oElements["ContentFooterWhitespace"].setHeight ( iFooterWhitespaceHeight );
    oMyPage.oElements["Content"].addStyle("backgroundColor", oMyPageLayout.sPageContentBGcolor) ;
    oMyPage.oElements["Content"].addStyle("overflow", "hidden") ;

//
    if ( oMyPageLayout.leftBarWidth() > 0 ) {
	oMyPage.oElements["LeftBarHeaderWhitespace"].setHeight ( 0 ) ;
	oMyPage.oElements["LeftBar"].moveTo ( iNewPageDisplayLeftPos , iNewPageDisplayTopPos ) ;
	oMyPage.oElements["LeftBar"].setWidth ( oMyPageLayout.leftBarWidth() ) ;
	oMyPage.oElements["LeftBar"].setHeight ( oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight ) ;
	oMyPage.oElements["LeftBar"].setZIndex ( 1 ) ;
	oMyPage.oElements["LeftBarFooterWhitespace"].setHeight ( iFooterWhitespaceHeight ) ;
	oMyPage.oElements["LeftBar"].sDisplay = "" ;
	oMyPage.oElements["LeftBar"].addStyle("backgroundColor", oMyPageLayout.sPageLeftBarBGcolor) ;
        oMyPage.oElements["LeftBar"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["LeftBar"].setDisplay ( "none" ) ;
    }

    if ( oMyPageLayout.rightBarWidth() > 0 ) {
	oMyPage.oElements["RightBarHeaderWhitespace"].setHeight( 0 ) ;
	oMyPage.oElements["RightBar"].moveTo ( iNewPageDisplayLeftPos + oMyPageLayout.rightBarXoffset() , iNewPageDisplayTopPos ) ;
	oMyPage.oElements["RightBar"].setWidth ( oMyPageLayout.rightBarWidth() ) ;
	oMyPage.oElements["RightBar"].setHeight ( oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight ) ;
	oMyPage.oElements["RightBar"].setZIndex ( 1 ) ;
	oMyPage.oElements["RightBarFooterWhitespace"].setHeight ( iFooterWhitespaceHeight ) ;
	oMyPage.oElements["RightBar"].sDisplay = "" ;
	oMyPage.oElements["RightBar"].addStyle("backgroundColor", oMyPageLayout.sPageRightBarBGcolor) ;
        oMyPage.oElements["RightBar"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["RightBar"].setDisplay ( "none" ) ;
    }

    if ( oMyPageLayout.footerHeight() > 0 ) {
	switch (oMyPageLayout.sFooterStyle){
	    case "fixed":
		oMyPage.oElements["Footer"].moveTo ( iNewPageDisplayLeftPos , iCurrentWindowHeight - oMyPageLayout.footerHeight() ) ;
		break;
	    default: //dynamic
		oMyPage.oElements["Footer"].moveTo ( iNewPageDisplayLeftPos , oMyPageLayout.headerHeight() + iContentHeight + iFooterWhitespaceHeight - oMyPageLayout.footerHeight() ) ;
		break;
	}
	oMyPage.oElements["Footer"].setWidth ( iNewPageDisplayWidth ) ;
	oMyPage.oElements["Footer"].setHeight ( oMyPageLayout.footerHeight() ) ;
	oMyPage.oElements["Footer"].setZIndex ( 2 ) ;
	oMyPage.oElements["Footer"].sDisplay = "" ;
	oMyPage.oElements["Footer"].addStyle("backgroundColor", oMyPageLayout.sPageFooterBGcolor) ;
        oMyPage.oElements["Footer"].addStyle("overflow", "hidden") ;
    } else {
	oMyPage.oElements["Footer"].setDisplay ( "none" ) ;
    }

}




// ******************************************************************************************************************


function resizePage ()
{
// alert(oMyPageLayout.sLayout);
    switch (oMyPageLayout.sLayout){
	case "002":
	    layout002calculate();
	    break;
	case "003":
	    layout003calculate();
	    break;
	case "004":
	    layout004calculate();
	    break;
	default:
	    layout001calculate();
	    break;
    }

    for (var sElement in oMyPage.sElementsList) {
	oMyPage.oElements[sElement].applyChanges();
    }
}


// ******************************************************************************************************************


function initializePage ()
{
    oMyPage = new myPage ();
    if (! oMyPage.isloaded) { alert ("Die Seite kann aufgrund fehlender Datenobjekte nicht dargestellt werden."); return false; };
    if (! oMyPageLayout ) { alert ("Das Datenobjekt fuer das Layout der Seite fehlt."); return false;};
//    alert ("now clearing preloader message");
    oMyPage.clearPreloaderDisplay();
    xLoadLink (oMyPageLayout.styleSheetBase());
    xLoadLink (oMyPageLayout.styleSheetPositions());
    resizePage();
//    oMyPage.clearPreloaderDisplay();
}

