/**
 * @author robert
 */

 
 
// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ModalDialog_Show( whichDialog, isPrompty, isTransparent )
{
	contentIDs = $$( 'div#' + whichDialog );
	ModalDialog_Center( contentIDs[0] );
	/*
	if( isPrompty )
	{
		$( whichDialog ).setStyle( { display: 'block' } );
	}
	else
	{
		new Effect.Appear( whichDialog,{ duration: tmpDuration, to: tmpTo } );
	}
	*/
	if( isPrompty )		{ tmpDuration = 0	} else { tmpDuration = 1	}
	if( isTransparent )	{ tmpTo = 1	} else { tmpTo = 1			}
	
	new Effect.Appear( whichDialog,{ duration: tmpDuration, to: tmpTo } );
}


// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ModalDialog_Hide( whichDialog )
{
	new Effect.Fade( whichDialog, { duration: 0 } );
}

// ======= ======= ======= ======= ======= ======= ======= 
//
// ======= ======= ======= ======= ======= ======= ======= 
function ModalDialog_Center(element)
{
	/*
    try
    {
        element = $(elementID);
    }
    catch(e)
    {
        return;
    }
	*/

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' )
    {

        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }
    else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
    {

        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
    {

        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

	

	/*
    element.style.position = 'absolute';
    element.style.display  = 'block';
	*/

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop )
    {
        scrollY = document.documentElement.scrollTop;
    }
    else if ( document.body && document.body.scrollTop )
    {
        scrollY = document.body.scrollTop;
    }
    else if ( window.pageYOffset )
    {
        scrollY = window.pageYOffset;
    }
    else if ( window.scrollY )
    {
        scrollY = window.scrollY;
    }

	// var elementDimensions = Element.getDimensions(element);
	// fuer modale Dialoge kann angenommen werden:
	elementDimensions = { width: 800, height: 500 };

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

}