function DocSize()
{
    var b=document.body,e=document.documentElement;esw=0,eow=0,bsw=0,bow=0,esh=0,eoh=0,bsh=0,boh=0;
    if(e){esw=e.scrollWidth;eow=e.offsetWidth;esh=e.scrollHeight;eoh=e.offsetHeight;}
    if(b){bsw = b.scrollWidth;bow = b.offsetWidth;bsh = b.scrollHeight;boh = b.offsetHeight;}
    return{w:Math.max(esw,eow,bsw,bow),h:Math.max(esh,eoh,bsh,boh)};
}

function PageGrey( i, c, o, h )
{
    var d = $j("#pagegrey");
    if( d.length < 1 ) 
    {
        $j(document.body).append("<div id=\"pagegrey\">pagegrey</div>");
        d = $j("#pagegrey");
    }
    d.css( 
    {
        'position':'absolute',
        'z-index':i,
        'background-color':c,
        'color':c,
        'left':'0px',
        'top':'0px',
        'opacity':o,
        'filter':'alpha(opacity='+o*100+')',
        'width':$j(document).width()+'px',
        'height':$j(document).height()+'px'
    });
    $j(window).resize( function()
    {
        d.css(
        {
            'width':$j(document).width()+'px',
            'height':$j(document).height()+'px'
        });
    });
    
    this.show = function() {d.show();}
    this.hide = function() {d.hide();}
    if (h) this.hide();
    else this.show();
}

// In association with a pagegrey.
function WaitMsg( msg, zIndex, className, imgUrl )
{
    var _container=document.createElement("div");
    document.getElementsByTagName("body")[0].appendChild(_container);
    _container.style.position="absolute";
    _container.style.zIndex=zIndex;
    _container.className=className;
    var _waitMsg=document.createElement("div");
    _container.appendChild(_waitMsg);
    if( imgUrl )
    {
        var _img=document.createElement('img');
        _container.appendChild(_img);
        _img.src = imgUrl;
        _img.style.position="absolute";
    }
    _waitMsg.style.position="absolute";
    _waitMsg.innerHTML=msg;
    Move();
    xAddEventListener(window, "resize", function(e){Move();});
    
    function Move( w, h )
    {
        var d={w:xClientWidth(),h:xClientHeight()};
        var w=xWidth(_container);
        var h=xHeight(_container);
        var t=(d.h-h)/2+xScrollTop();
        var l=(d.w-w)/2+xScrollLeft();
        xTop(_container,(t<=0)?10:t);
        xLeft(_container,(l<=0)?10:l);
        if( imgUrl )
        {
            il=(w-2-xWidth(_img))/2;
            xTop(_img,xHeight(_waitMsg));
            xLeft(_img,il);
        }
    }
}

