var Dialog = {
	show: function(modality)
	{
		MenuManager.keyboardShortcutsEnabled = false;
		
		var dlgBox = $('dlgBox');
		var dlgShim = $('dlgShim');
		var outer = $('outerContainerTop');
		var content = $('pageContent');
		
		if(outer === null)
		{
			outer = document.body;
		}
			
		if(content === null)
		{
			content = outer;
		}
		
		var outerPos = Position.cumulativeOffset(outer);
		var contentPos = Position.cumulativeOffset(content);
		
		var top, left, width, height;
		
		dlgBox.setOpacity(0).show();
		
		top = (getViewportHeight() - dlgBox.offsetHeight) / 2;
		if(top < 0) { top = 0; }
		
		left = (content.offsetWidth - dlgBox.offsetWidth) / 2;
		left += contentPos[0];
		if(left < 0) { left = 0; }
			
		dlgBox.style.top = '' + top + 'px';
		dlgBox.style.left = '' + left + 'px';
			
		switch(modality)
		{
			case 'none':
				top    = parseInt(dlgBox.style.top, 10);
				left   = parseInt(dlgBox.style.left, 10);
				width  = parseInt(dlgBox.offsetWidth, 10);
				height = parseInt(dlgBox.offsetHeight, 10);
				break;
				
			case 'content':
//				top    = contentPos[1];
//				left   = outerPos[0];
//				width  = parseInt(outer.offsetWidth);
//				height =  getDocumentHeight() - top;
					
				width = dlgBox.offsetWidth;
				height = dlgBox.offsetHeight;
				
//				if(parseInt(dlgBox.style.top) < (top + 10))
//					dlgBox.style.top = '' + (top + 10) + 'px';
					
				break;
				
			case 'page':
				top    = outerPos[1];
				left   = outerPos[0];
				width  = parseInt(outer.offsetWidth,10);
				height = getDocumentHeight() - top;	
				break;	
				
			default:
				top    = outerPos[1];
				left   = outerPos[0];
				width  = parseInt(outer.offsetWidth,10);
				height = getDocumentHeight() - top;	
				break;			
		}
	
		dlgShim.style.left = '' + left + 'px';
		dlgShim.style.top = '' + top + 'px';
		dlgShim.style.width = '' + width + 'px';
		dlgShim.style.height = '' + height + 'px';

		dlgShim.show();
		dlgBox.setOpacity(1);
	},
	
	hide: function()
	{
		$('dlgBox').hide();
		$('dlgShim').hide();
		
		MenuManager.keyboardShortcutsEnabled = true;
	},
	
	setTitle: function(caption)
	{
		var captionElement = $$('#dlgBox .caption').first();
		if(captionElement !== null)
		{
			captionElement.innerHTML = caption;
		}
	},
		
	showUrl: function(caption, url, width, height, modality)
	{
		$('dlgBox').setStyle( {width: width} );
		var iframeElement = $$('#dlgBox iframe').first();
		if(iframeElement !== null)
		{
			iframeElement.src = url + "&n=" + Math.random();
			iframeElement.setStyle( {height: height} );
		}
		Dialog.setTitle(caption);
		Dialog.show(modality);
	},
	
	hideUrl: function()
	{		    	    
		Dialog.hide();
	},

    cleanup: function()
    {
        if( this.onOk )
        {
            this.onOk = null;
        }
        if( this.onCancel )
        {
            this.onCancel = null;
        }
        if( this.parameters )
        {
           this.parameters = null;
        }
    }
};