var theDialogDiv;
var dialogBkgdDiv;
var isDialogDisplayed = false;

function toggleDialogBox(theId) {

	isDialogDisplayed = !isDialogDisplayed;
	
	theDialogDiv = document.getElementById(theId);
	dialogBkgdDiv = document.getElementById("dialogBackgroundDiv");
	
	// need to know if there is an iframe in the dialog, because we have to do some special things...
	var numIframes = theDialogDiv.getElementsByTagName("iframe").length;
		
        toggleDialogBkgd();
        var viz = isDialogDisplayed ? "visible" : "hidden";
        
        if (viz=="visible")  setDialogPosition();
        
        theDialogDiv.style.visibility = viz;
        
}

function setDialogPosition() {
	if (!isDialogDisplayed) { return;}
	var base;
	var theTop;
	var theLeft;
	var dialogWidth;
	var dialogHeight;
	
	dialogWidth = theDialogDiv.offsetWidth;
	dialogHeight = theDialogDiv.offsetHeight;	 

		
	base = document.body;
		
	var ch;
	var cw;
	var sh = base.scrollHeight;
	var sw = base.scrollWidth;
	
	if (navigator.appName=="Netscape") {
		cw = window.innerWidth;
		ch = window.innerHeight;
	 } else {
		cw = base.offsetWidth;
		ch = base.offsetHeight;	 
	 }
	
			
	if ( (ch - dialogHeight) < 0 )
	{
		theTop = base.scrollTop;
	} else {
		theTop = parseInt((ch - dialogHeight)/2) + base.scrollTop;
	}
    

	if ( (cw - dialogWidth) < 0 )
	{
		theLeft = base.scrollLeft;
	} else {
		theLeft = parseInt((cw - dialogWidth)/2) + base.scrollLeft;
	}
	 

	theDialogDiv.style.top = theTop + "px";
	theDialogDiv.style.left = theLeft + "px";
	
	
	
	var winH;
	var winW;
	
	 if (navigator.appName.indexOf("Microsoft")!=-1) {
	  winW = document.body.offsetWidth;
	  winH = document.body.offsetHeight;
	 }

	
}

function toggleDialogBkgd()
{
	dialogBkgdDiv.style.visibility = isDialogDisplayed ? "visible" : "hidden";
	if (!isDialogDisplayed) { return;}
//	dialogBkgdDiv.style.height =  document.body.clientHeight+ "px";
//	dialogBkgdDiv.style.width = document.body.clientWidth+ "px"; 


	dialogBkgdDiv.style.height =  window.screen.height+ "px";
	if (document.body.clientWidth>window.screen.width)
		dialogBkgdDiv.style.width = document.body.clientWidth+ "px"; 
	else
		dialogBkgdDiv.style.width = window.screen.width+ "px"; 
}

function onWindowSizeChange()
{
	if (!isDialogDisplayed) { return;}
		toggleDialogBkgd();
		setDialogPosition();
}