﻿function getPageSize() {
     var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,pageHeight];
}

var cX = 0; var cY = 0;

function UpdateCursorPosition(e)
{ 
    cX = e.pageX; 
    cY = e.pageY;
}
function UpdateCursorPositionDocAll(e)
{ 
    cX = event.clientX + document.documentElement.scrollLeft; 
    cY = event.clientY + document.documentElement.scrollTop;
}

if (document.all) 
    document.onmousemove = UpdateCursorPositionDocAll; 
else 
    document.onmousemove = UpdateCursorPosition; 

function showDiv(id) {
    var Popup = document.getElementById(id);
    if (Popup != null) {
        Popup.style.display = "block";
        Popup.style.position = "absolute";

        var arrayPageSize = getPageSize();
        var screenWidth = arrayPageSize[0];
        var screenHeight = arrayPageSize[1];

        Popup.style.left = (cX + 10) + "px";
        if (Popup.offsetLeft + Popup.clientWidth > screenWidth)
            Popup.style.left = (screenWidth - Popup.clientWidth - 20) + "px";

        Popup.style.top = (cY + 10) + "px";
        if (Popup.offsetTop + Popup.clientHeight > screenHeight)
            Popup.style.top = (cY - Popup.clientHeight - 20) + "px";
    }
}

function localHideDiv(id) {
    var Popup = document.getElementById(id);
    if (Popup != null) {
        Popup.style.display = "none";
    }
}

function hideDiv(id) {
    setTimeout("localHideDiv('" + id + "')", 500);
}

