function WindowPopup( sUrl, iWidth, iHeight, sOptions, sName, iLeft, iTop )
{
    // Options=Defaultwerk
    // dependent        // close the parent, close the popup, omit if you want otherwise
    // resizable=no     // yes|no
    // menubar=no       // yes|no
    // toolbar=no       // yes|no
    // location=no      // yes|no
    // status=no        // yes|no
    // scrollbars=no    // yes|no
    // directories=no   // yes|no

	var iMaxWidth = screen.availWidth - 11;
	var iMaxHeight = screen.availHeight - 51;

	if ( !sOptions )
	    sOptions = '';

    if ( iWidth == -1 )
        iWidth = iMaxWidth;
    if ( iHeight == -1 )
        iHeight = iMaxHeight;

    // Scrollbar einschalten, wenn Fenster zu groß.
    if ( iLeft + iWidth > iMaxWidth || iTop + iHeight > iMaxHeight )
    {
        if ( sOptions.indexOf( 'scrollbars' ) == -1 )
        {
            if ( sOptions )
                sOptions = sOptions + ',';
            sOptions = sOptions + 'scrollbars=yes';
        }

        if ( iWidth + iLeft > iMaxWidth )
            iWidth = iMaxWidth - iLeft;
        if ( iHeight + iTop > iMaxHeight )
            iHeight = iMaxHeight - iTop;
    }

    // Fenster zentrieren.
    if ( !iLeft )
    {
        iLeft = parseInt( ( iMaxWidth - iWidth ) / 2 );
        if ( iLeft < 0 )
            iLeft = 0;
    }
    if ( !iTop )
    {
        iTop = parseInt( ( iMaxHeight - iHeight ) / 2 );
        if ( iTop < 0 )
            iTop = 0;
    }

    oWindow = window.open( sUrl, sName, 'width=' + iWidth + ',height=' + iHeight + ",left=" + iLeft + ',top=' + iTop + ',' + sOptions );
    if ( oWindow )
        oWindow.focus();

    return( oWindow );
}

function WindowWidth( oWindow )
{
    if( typeof( window.innerWidth ) == 'number' )
        //Non-IE
        return( window.innerWidth );
    else
        if ( document.documentElement && document.documentElement.clientWidth )
            //IE 6+ in 'standards compliant mode'
            return( document.documentElement.clientWidth );
        else
            if ( document.body && document.body.clientWidth )
                //IE 4 compatible
                return( document.body.clientWidth );
            else
                return( 1024 );
}

function WindowHeight( oWindow )
{
    if( typeof( window.innerHeight ) == 'number' )
        //Non-IE
        return( window.innerHeight );
    else
        if ( document.documentElement && document.documentElement.clientHeight )
            //IE 6+ in 'standards compliant mode'
            return( document.documentElement.clientHeight );
        else
            if ( document.body && document.body.clientHeight )
                //IE 4 compatible
                return( document.body.clientHeight );
            else
                return( 768 );
}

function WindowResize( oWindow, iWidth, iHeight, fCenter )
{
	var iMaxWidth = screen.availWidth;
	var iMaxHeight = screen.availHeight;

    if ( iWidth > iMaxWidth )
        iWidth = iMaxWidth;
    if ( iHeight > iMaxHeight )
        iHeight = iMaxHeight

    oWindow.resizeTo( iWidth, iHeight );

    if ( fCenter )
    {
        iLeft = parseInt( ( iMaxWidth - iWidth ) / 2 );
        iTop = parseInt( ( iMaxHeight - iHeight ) / 2 );
        WindowMove( oWindow, iLeft, iTop );
    }
}

function WindowMove( oWindow, iLeft, iTop )
{
    oWindow.moveTo( iLeft, iTop );
}

function WindowFrameCheck( sPath )
{
    if ( top == self )
    {
        if ( sPath )
        {
            sLocation = self.location.pathname;
            top.location = sPath + '?content=' + encodeURIComponent( sLocation + self.location.search );
        }
        else
        {
            sLocation = self.location.pathname;
            i = sLocation.lastIndexOf( '/' );
            top.location = sLocation.substring( 0, i + 1 ) + '?content=' + encodeURIComponent( sLocation.substring( i + 1 ) + self.location.search );
        }
    }
}

function WindowPrint( oWindow )
{
    if ( !oWindow )
        oWindow = self;

    sUrl = oWindow.location.protocol + '//';
    sUrl = sUrl + oWindow.location.host;
    sUrl = sUrl + oWindow.location.pathname;

    sSearch = oWindow.location.search;
    if ( sSearch.length == 0 )
        sSearch = '?';
    else
        sSearch = sSearch + '&';
    sSearch = sSearch + 'print=1';
    sUrl = sUrl + sSearch;

    WindowPopup( sUrl, 780, 550, 'menubar=yes,scrollbars,resizable=yes,status=yes', 'print' );
}

function WindowZoom( sName, sImage, iWidth, iHeight )
{
    var fInternetExplorer;
    var iWindowWidth;
    var iWindowHeight;
    var iOffsetLeft;
    var iOffsetTop;
    var iLeft;
    var iTop;
    var iProportionX;
    var iProportionY;

    fInternetExplorer = document.all ? true : false;

    iWindowWidth = WindowWidth( window );
    iWindowHeight = WindowHeight( window );

    if ( fInternetExplorer )
        iOffsetLeft = document.body.scrollLeft;
    else
        iOffsetLeft = window.pageXOffset;
    if ( fInternetExplorer )
        iOffsetTop = document.body.scrollTop;
    else
        iOffsetTop = window.pageYOffset;

	var oImage = document.getElementById( sName + '#zoomimage' );
	if ( oImage == null )
	{
		var oNewNode;
		oNewNode = document.createElement( 'IMG' );
		oNewNode.id = sName + '#zoomimage';
		oNewNode.style.position = 'absolute';
		oNewNode.style.zIndex = 1000;
		oNewNode.className = 'border';

        var oNode = document.getElementById( sName + '#zoom' );
		oImage = oNode.appendChild ( oNewNode );
	}

    // set image src
	oImage.src = sImage;

    // find bigger side
    iProportionX = 1;
    if ( MouseX - iOffsetLeft > iOffsetLeft + iWindowWidth - MouseX )
    {
        if ( MouseX - iOffsetLeft < iWidth + 50 )
            iProportionX = ( MouseX - iOffsetLeft - 25 ) / iWidth;
    }
    else
    {
        if ( iOffsetLeft + iWindowWidth - MouseX < iWidth + 50 )
            iProportionX = ( iOffsetLeft + iWindowWidth - MouseX - 25 ) / iWidth;
    }

    // find bigger side
    iProportionY = 1;
    if ( MouseY - iOffsetTop > iOffsetTop + iWindowHeight - MouseY )
    {
        if ( MouseY - iOffsetTop < iHeight + 50 )
            iProportionY = ( MouseY - iOffsetTop - 25 ) / iHeight;
    }
    else
    {
        if ( iOffsetTop + iWindowHeight - MouseY < iHeight + 50 )
            iProportionY = ( iOffsetTop + iWindowHeight - MouseY - 25 ) / iHeight;
    }

    // resize image
    if ( iProportionX < iProportionY )
    {
        iWidth = Math.round( iWidth * iProportionX );
        iHeight = Math.round( iHeight * iProportionX );
    }
    else
    {
        iWidth = Math.round( iWidth * iProportionY );
        iHeight = Math.round( iHeight * iProportionY );
    }

	// set width and height
	oImage.style.width = iWidth;
	oImage.style.height = iHeight;

    // set positions
    if ( MouseX + iWidth + 30 < iOffsetLeft + iWindowWidth )
        iLeft = MouseX + 10;
    else
        iLeft = MouseX - iWidth - 10;

    if ( MouseY + iHeight + 30 < iOffsetTop + iWindowHeight )
        iTop = MouseY + 10;
    else
        iTop = MouseY - iHeight - 10;

    oImage.style.left = iLeft;
    oImage.style.top = iTop;

    // show image
    oImage.style.visibility = 'visible';
}

function WindowZoomHide( sName )
{
	var oImage = document.getElementById( sName + '#zoomimage' );
	if ( oImage != null )
        oImage.style.visibility = 'hidden';
}
