//
// global variables
//
var isMozilla;
var objDiv = null;
var originalDivHTML = "";
var DivID = "";
var over = false;

// do not call this until page is loaded.
// returns page scroll offsets in arr( left, top )
function getScrollOffset() 
{
	var xScrollOffset, yScrollOffset;
	
	if ( window.pageXOffset && window.pageYOffset) { // firefox, MS6
		xScrollOffset = window.pageXOffset;
		yScrollOffset = window.pageYOffset
	}
	else { // IE
		xScrollOffset = document.body.scrollLeft;
		yScrollOffset = document.body.scrollTop;
	}

	var arrScrollOffset = new Array( xScrollOffset, yScrollOffset );     

	// alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );     
	return arrScrollOffset; 

}

// do not call this until page is loaded.
// returns page size in arr( left, top )
function getPageSizeWithScroll() 
{  
	var xWithScroll, yWithScroll;
	   
	if (window.innerHeight && window.scrollMaxY) { // Firefox         
		yWithScroll = window.innerHeight + window.scrollMaxY;         
		xWithScroll = window.innerWidth + window.scrollMaxX;     
	}
	else if ((document.body.scrollHeight && document.body.offsetHeight ) && (document.body.scrollHeight > document.body.offsetHeight)) { // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;         
		xWithScroll = document.body.scrollWidth;  
	}
	else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari         
		yWithScroll = document.body.offsetHeight;         
		xWithScroll = document.body.offsetWidth;       
	}
	var arrPageSizeWithScroll = new Array( xWithScroll, yWithScroll );

	// alert( 'The height is ' + yWithScroll + ' and the width is ' + xWithScroll );     
	return arrPageSizeWithScroll; 
} 	

//
// dynamically add a div to dim all the page
//
function buildDimmerDiv()
{
	document.write('<div id="dimmer" class="dimmer" style="width:'+ window.screen.width + 'px; height:' + window.screen.height +'px"></div>');
	// alert( 'Width: ' + (window.innerWidth + window.scrollMaxX) + '   Height: ' + (window.innerHeight + window.scrollMaxY) );
}

//
//
//
function displayFloatingDiv(divId, title, width, height, left, top) 
{
	var arr = new Array;
	arr = getPageSizeWithScroll();	// get size of page including non-visible scroll areas.
	
	DivID = divId;

	document.getElementById('dimmer').style.visibility = "visible";
	document.getElementById('dimmer').style.display = "inline";
	document.getElementById('dimmer').style.width = arr[0];
	document.getElementById('dimmer').style.height = arr[1];

	document.getElementById(divId).style.width = width + 'px';
	document.getElementById(divId).style.height = height + 'px';
	document.getElementById(divId).style.left = left + 'px';
	document.getElementById(divId).style.top = top + 'px';
	
	var addHeader;
	
	if (originalDivHTML == "")
		originalDivHTML = document.getElementById(divId).innerHTML;
	
		addHeader = '<table style="width:' + width + 'px" class="floatingHeader">' +
	            '<tr><td ondblclick="void(0);" onmouseover="over=true;" onmouseout="over=false;" style="cursor:move;height:18px">' + title + '</td>' + 
	            '<td style="width:18px" align="right"><a href="javascript:hideFloatingDiv(\'' + divId + '\');void(0);">' + 
	            '<img alt="Close..." title="Close..." src="/art/closebutton_xp.gif" border="0"></a></td></tr></table>';

	// add to your div an header	
	document.getElementById(divId).innerHTML = addHeader + originalDivHTML;
	
	document.getElementById(divId).className = 'dimming';
	document.getElementById(divId).style.visibility = "visible";
	document.getElementById(divId).style.display = "inline";
}


//
//
//
function hideFloatingDiv( divId ) 
{
	document.getElementById(divId).innerHTML = originalDivHTML;

	document.getElementById(divId).style.visibility='hidden';
	document.getElementById(divId).style.display='none';

	document.getElementById('dimmer').style.visibility = 'hidden';
	document.getElementById('dimmer').style.display = 'none';
	
	DivID = "";
}

//
//
//
function MouseDown(e) 
{
	if (over)
	{
		if (isMozilla) {
			objDiv = document.getElementById(DivID);
			X = e.layerX;
			Y = e.layerY;
			return false;
		}
		else {
			objDiv = document.getElementById(DivID);
			objDiv = objDiv.style;
			X = event.offsetX;
			Y = event.offsetY;
        }
    }
}

//
//
//
function MouseMove(e) 
{
	if (objDiv) {
		if (isMozilla) {
			objDiv.style.top = (e.pageY-Y) + 'px';
			objDiv.style.left = (e.pageX-X) + 'px';
			return false;
        }
		else 
		{
			objDiv.pixelLeft = event.clientX-X + document.body.scrollLeft;
			objDiv.pixelTop = event.clientY-Y + document.body.scrollTop;
			return false;
		}
	}
}

//
//
//
function MouseUp() 
{
	objDiv = null;
}

//
//
//
function init()
{
	// check browser
	isMozilla = (document.all) ? 0 : 1;

	if (isMozilla) 
	{
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
	}

	document.onmousedown = MouseDown;
	document.onmousemove = MouseMove;
	document.onmouseup = MouseUp;

	// add the div used to dim the page
	buildDimmerDiv();
}

// call init
init();


