﻿//============================================================
//Version:  1.0.0
//============================================================
var cursorPosX = 0;
var cursorPosY = 0;
	      
function CursorPositionUpdate(e)
{
	cursorPosX = e.pageX;
	cursorPosY = e.pageY;
}

function CursorPositionUpdateDocAll(e)
{
	cursorPosX = event.clientX;
	cursorPosY = event.clientY;
}

function DisplayElmRelToCursorPos(elm, topOffset, leftOffset)
{
    //Display an element based on the user's cursor position
    if (topOffset == null)
    {
        topOffset = 0;
    }
    if (leftOffset == null)
    {
        leftOffset = 0;
    }
	if (document.all)
	{
	    var rX = 0;
	    var rY = 0;
    	
	    if (self.pageYOffset)
	    {
		    rX = self.pageXOffset;
		    rY = self.pageYOffset;
	    }
	    else if (document.documentElement && document.documentElement.scrollTop)
	    {
		    rX = document.documentElement.scrollLeft;
		    rY = document.documentElement.scrollTop;
	    }
	    else if (document.body)
	    {
		    rX = document.body.scrollLeft;
		    rY = document.body.scrollTop;
	    }	    
		cursorPosX += rX;
		cursorPosY += rY;
	}
	elm.style.left = (cursorPosX + leftOffset + 10).toString() + "px";
	elm.style.top = (cursorPosY + topOffset + 10).toString() + "px";
}

function DisplayElmRelToElm(dispElmName, srcPosDim, display, align, vAlign, leftOffSet, topOffSet)
{
    //Display an element based on the position of another specified element
	var dispElm = document.getElementById(dispElmName);
	
	if (dispElm != null)
	{
		var left, top;
		
		if (leftOffSet == null)
		{
			leftOffSet = 0;
		}
		if (topOffSet == null)
		{
			topOffSet = 0;
		}
		if (align == "right")
		{
			dispElm.style.left = (srcPosDim.Right + leftOffSet).toString() + "px";
		}
		else
		{
		    //left to left
			dispElm.style.left = (srcPosDim.Left + leftOffSet).toString() + "px";
		}
		if (vAlign == "top")
		{
			dispElm.style.top = (srcPosDim.Top + topOffSet).toString() + "px";
		}
		else
		{
			dispElm.style.top = (srcPosDim.Bottom + topOffSet).toString() + "px";
		}
		if (display)
		{
			dispElm.style.display = "block";
		}
	}
}

function ElementPosDim(elmName)
{
    //Object that will retrieve and store an element's position and dimension attributes
	//Properties
	this.Element = document.getElementById(elmName);
	this.Bottom = 0;
	this.Height = 0;
	this.Left = 0;
	this.Right = 0;
	this.Top = 0;
	this.Width = 0;
	//Constructor
	this.PosDim = 
		function() {
			var element = document.getElementById(elmName);
								
			if (element != null)
			{
				this.Height = element.offsetHeight;
				this.Width = element.offsetWidth;
				while (element != null)
				{
					this.Left += element.offsetLeft;
					this.Top += element.offsetTop;			
					element = element.offsetParent;
				}
				this.Bottom = this.Top + this.Height;
				this.Right = this.Left + this.Width;
			}
		}
	//Call constructor
	this.PosDim();
}

function PrintPage(){  
	if (window.print)
	{
    	window.print() ;  
	}
	else
	{
		document.body.insertAdjacentHTML("beforeEnd", "<OBJECT ID=\"WebBrowser1\" WIDTH=\"0\" HEIGHT=\"0\" CLASSID=\"CLSID:8856F961-340A-11D0-A96B-00C04FD705A2\"></OBJECT>");
    	WebBrowser1.ExecWB(6, 2);
	}
}

if (document.all)
{
	document.onmousemove = CursorPositionUpdateDocAll;
}
else
{
	document.onmousemove = CursorPositionUpdate;
}