var popup;

function Popup(popupId,displayAtDistanceX,displayAtDistanceY) {
	this.popupId = popupId;
	this.displayAtDistanceX=displayAtDistanceX;
	this.displayAtDistanceY=displayAtDistanceY; 
	this.display = PopupDisplay;
	this.hide = PopupHide;
	this.redisplay=PopupRedisplay;
}

function PopupDisplay(ev) {
	if(popup!=null) popup.style.display="none";
	var elem;
	var x;
	var y;
	if(document.all) {
		elem = window.event.srcElement;
		x=window.event.clientX;
		x+=PopupGetScrollingX();
		y=window.event.clientY;
		y+=PopupGetScrollingY();
	}
	else {
		elem = ev.target;
		x=ev.pageX;
		y=ev.pageY;
	}
	x+=this.displayAtDistanceX;
	y+=this.displayAtDistanceY;
	var height = WindowHeight;
	if(y > height - 350) {
		y = height - 350;
	}
	var popupElem = document.getElementById(this.popupId);
	if(popupElem.style.display!="block") {
		popupElem.style.display="block";
		popupElem.style.left=""+x+"px";
		popupElem.style.top=""+y+"px";
		popup = popupElem;
	}
}

function PopupHide() {
	var popupElem = document.getElementById(this.popupId);
	popupElem.style.display="none";
}

function PopupRedisplay() {
	var popupElem = document.getElementById(this.popupId);
	popupElem.style.display="block";
	popup = popupElem;
}

function PopupGetScrollingX() {
	var x = 0;
	if (document.body && document.body.scrollLeft && !isNaN(document.body.scrollLeft)) {
		x = document.body.scrollLeft;
	}
	return x;
}

function PopupGetScrollingY() {
	var y = 0;
	if (document.body && document.body.scrollTop && !isNaN(document.body.scrollTop)) {
		y = document.body.scrollTop;
	}
	return y;
}

function WindowHeight() {
	if (document.documentElement && document.documentElement.clientHeight) 
	{
		return document.documentElement.clientHeight;
	}
	if (window.self && self.innerHeight) 
	{
		return self.innerHeight;
	}
	return 0;
}
