window.addEvent('domready',function(){
    
    var Box=$('MessageBox');
        Box.setStyle('position','absolute');
    
    var Title=document.getElements('#MessageBox table[id=BoxTitle]');
    var MyDrag= new Drag.Move(Box).detach();

    //$('MessageBox').setStyle('display','');
    
    Title.addEvents({
                     'mouseover':   function(){MyDrag.attach();},
                     'mouseout':    function(){MyDrag.detach();}
                    })   
    
  })
  function ShowBox()  
    {
    var Scroll  = getScroll();
    //alert('scroll x='+Scroll.fromLeft+'  y='+Scroll.fromTop);
    var WinSize = getWindowSize();
    //alert('WinSize x='+WinSize.width+'  y='+WinSize.height);

    var Layer=new Element('div',{'id':'MessageBoxLayer'});
		
    $(document.body).appendChild(Layer);
    $('MessageBoxLayer').setStyles({
                                   'border'           : '3px solid #000000',
                                   'z-index'          : 10,
                                   'position'         : 'absolute',
                                   'top'              : Scroll.fromTop,
                                   'left'             : Scroll.fromLeft,                                     
                                   'background-color' : '#000000',
                                   'opacity'          : 0.7,
                                   'width'            : WinSize.width,
                                   'height'           : WinSize.height
                                   });
    
    var Box=$('MessageBox');
    var BoxSize = Box.getSize();
    //alert('boxsize  x='+BoxSize.size.x+'   y='+BoxSize.size.y);

    
		$(document.documentElement).setStyle('overflow','hidden');



    var NewY= ( (WinSize.height - BoxSize.size.y) /2 ) + Scroll.fromTop;
    var NewX= ( (WinSize.width  - BoxSize.size.x) /2 ) + Scroll.fromLeft; 
    //alert( 'nuova posizione   x ='+NewX+'  y='+ NewY);

    Box.setStyles({
                  'display' : '',
                  'z-index' : 100,
                  'top'     : NewY,
                  'left'    : NewX
                  });

    }

function HiddenBox()
  {
  $(document.documentElement).setStyle('overflow','');
  $('MessageBox').setStyle('display','none');
  $('MessageBoxLayer').remove();
  }



function getWindowSize()
  {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) 
    {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    } 
  else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
    {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    } 
  else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
    {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    }
  return {width : myWidth, height: myHeight}
  }

function getScroll() 
  {
  var Out={};
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) 
    {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
    } 
  else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
    {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
    } 
  else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
    {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
    }
  
  return {fromTop: scrOfY, fromLeft: scrOfX};
  }
