﻿function GetPosition(e)
{
	e = e || window.event;
	var cursor = {x:0, y:0};

	if (e.pageX || e.pageY)
	{
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	}
	else
	{
		cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
		cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}
	return cursor;
}

function DisplayPopup(e, bShow, strDivPopup, strDivContent, strContent, nCompanyID, offsetx, offsety)
{
	var elemPopup = document.getElementById(strDivPopup);
	var elemContent = null;
	var elemInputCopy = null;
	var elemInputPrint = null;
	var cursor = GetPosition(e);
	offsetx = (offsetx == null ? 0 : offsetx);
	offsety = (offsety == null ? 0 : offsety);

	elemPopup.style.left = cursor.x + offsetx + "px";  // Append "px" for compatibility with Firefox
	elemPopup.style.top = cursor.y + offsety + "px";
	if (bShow)
	{
		elemContent = document.getElementById(strDivContent);
		elemContent.innerHTML = strContent;
		
		if (nCompanyID > 0)  // If company ID is passed in, display copy and print buttons
		{
			elemInputCopy = document.getElementById("divCopyResult");
			if (elemInputCopy != null)
			{
				elemInputCopy.innerHTML = "";
			}
			elemInputPrint = document.getElementById("btnPrint");
			if (elemInputPrint != null)
			{
				elemInputPrint.onclick = function() { window.open("Print.aspx?page=contact&ID=" + nCompanyID); };
			}
		}
		elemPopup.style.display = "";
	}
	else
	{
		elemPopup.style.display = "none";
	}
}

