// Div Popups

function getPixels(str)
{
	return str != "" ? parseInt(str.substr(0, str.length-2)) : 0;
}

function getObjectHeight(obj)
// return the height of given object according to the style sheet
{
	var height;
	height = getPixels(obj.style.height);
	
	height += getPixels(obj.style.paddingTop) + getPixels(obj.style.paddingBottom);
	height += getPixels(obj.style.marginTop) + getPixels(obj.style.marginBottom);
	height += getPixels(obj.style.borderTopWidth) + getPixels(obj.style.borderBottomWidth);

	return height;
}

function getObjectWidth(obj)
// return the height of given object according to the style sheet
{
	var width;
	width = getPixels(obj.style.width);
	
	width += getPixels(obj.style.paddingLeft) + getPixels(obj.style.paddingRight);
	width += getPixels(obj.style.marginLeft) + getPixels(obj.style.marginRight);
	width += getPixels(obj.style.borderLeftWidth) + getPixels(obj.style.borderRightWidth);
	
	return width;
}

function hideDivPopup(id)
{
	var obj = document.getElementById(id);
	
	obj.style.display = "none";
}

function divPopup(id, x, y)
{
	var obj = document.getElementById(id);
	
	// make sure div stays inside screen
	var height = getObjectHeight(obj);
	
	var availHeight = document.body.offsetHeight-10;
	if (y-document.body.scrollTop + height > availHeight)
		y = availHeight + document.body.scrollTop - height; 
		
	var width = getObjectWidth(obj);
	var availWidth = document.body.offsetWidth-10;
	if (x-document.body.scrollLeft + width > availWidth)
		x = availWidth + document.body.scrollLeft - width;

	obj.style.top = y;
	obj.style.left = x;
	
	obj.style.display = "";
}

function getScreenX(event)
{
	return event.layerX ? event.layerX : event.screenX + document.body.scrollLeft;
}

function getScreenY(event)
{
	return event.layerY ? event.layerY : event.clientY + document.body.scrollTop;
}
