// JavaScript Utility functions

var ie4=document.all

function winPopup( topic, cx, cy, name, features, top, left )
{
	if( !name ) name = 'subwin';
	if( !features || !features.length ) features = 'toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no';

	if( !cx ) cx = 460;
	if( !cy ) cy = 425;

	if( !top ) top = (screen.height) ? (screen.height-cy)/2 : 0;
	if( !left) left = (screen.width) ? (screen.width-cx)/2 : 0;

	if( top >= 0 ) features += ',top=' + top;
	if( left >= 0 ) features += ',left=' + left;

	features += ',width=' + cx + ',height=' + cy;
	var myWin = window.open( topic, name, features );
	if( myWin.focus ) myWin.focus();
}

function winPopupDlg( topic, cx, cy, name, top, left )
{
	winPopup( topic, cx, cy, name, 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no', top, left );
}

function getIEDocumentBody()
{
	return( (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body );
}
function getInsideWindowHeight()
{
	return( (ie4 && !window.opera) ? getIEDocumentBody().clientHeight : window.innerHeight );
}
function getInsideWindowWidth()
{
	return( (ie4 && !window.opera) ? getIEDocumentBody().clientWidth : window.innerWidth );
}
function ensureVisible( obj )
{
	var yObj = parseInt(obj.style.top);
	var cyObj = obj.offsetHeight;
	var scrollYOffset = (ie4 && !window.opera) ? getIEDocumentBody().scrollTop : window.pageYOffset;
	var cyWindow = getInsideWindowHeight();
	if( (yObj + cyObj) > (cyWindow + scrollYOffset) )
	{
		yObj = cyWindow + scrollYOffset - cyObj - ((ie4 && !window.opera) ? 2 : 20);
		if( yObj < scrollYOffset )
		{
			yObj = scrollYOffset + 2;
		}
		obj.style.top = yObj + "px";
	}

	var scrollXOffset = (ie4 && !window.opera) ? getIEDocumentBody().scrollLeft : window.pageXOffset;
	var xObj = parseInt(obj.style.left);
	var cxObj = obj.offsetWidth;
	var cxWindow = getInsideWindowWidth();
	if( (xObj + cxObj) > (cxWindow + scrollXOffset) )
	{
		xObj = cxWindow + scrollXOffset - cxObj - ((ie4 && !window.opera) ? 2 : 20);
		if( xObj < scrollXOffset )
		{
			xObj = scrollXOffset + 2;
		}
		obj.style.left = xObj + "px";
	}
}

function getYPosition(overlay,overlayOffset)
{
	var totaloffset=overlay.offsetTop + 20;
	var parentEl=overlay.offsetParent;
	while( parentEl!=null )
	{
		totaloffset = totaloffset+parentEl.offsetTop;
		parentEl = parentEl.offsetParent;
	}
	return( totaloffset );
}

function getXPosition(overlay,overlayOffset)
{
	var totaloffset=overlay.offsetLeft;
	var parentEl=overlay.offsetParent;
	while( parentEl!=null )
	{
		totaloffset = totaloffset+parentEl.offsetLeft;
		parentEl = parentEl.offsetParent;
	}
	return( totaloffset );
}

function overlay(oPopupAnchor, szPopupId)
{
	if( document.getElementById )
	{
		var oPopup=document.getElementById(szPopupId);
		oPopup.style.visibility="hidden";
		oPopup.style.display="block";
		oPopup.style.left = getXPosition(oPopupAnchor)+"px";
		oPopup.style.top = getYPosition(oPopupAnchor)+"px";
		ensureVisible(oPopup);
		oPopup.style.visibility="visible";
		return false;
	}
	return true;
}
function overlayclose(subobj)
{
	document.getElementById(subobj).style.display="none";
}
