﻿var jsAreaShowTime = 1000;
var JsAreas = new Object();

function GetArea(id) {
    return JsAreas[id] ? JsAreas[id] : (JsAreas[id] = new JsArea(id));
}

// A single popup window
function JsArea(id) {
    this.AreaId = id;
}

// Function to return the DIV Layer
JsArea.prototype.ContentArea = function() {
    var divArea = document.getElementById(this.AreaId);
    if (divArea != null) {
        return divArea;
    }
    return null;
}

var activeAreaId = null;

// Function to show the DIV Layer
JsArea.prototype.popareaup = function(x, y) {
    if (activeAreaId != null)
        jsAreaClose(activeAreaId);

    var divLayer = this.ContentArea();
    divLayer.style.position = 'absolute';
    divLayer.style.display = 'block';
    divLayer.style.left = x + 'px';
    divLayer.style.top = y + 'px';
    activeAreaId = this.AreaId;
    return false;
}

// Function to hide the DIV Layer
JsArea.prototype.hide = function() {
    var divLayer = this.ContentArea();
    if (divLayer != null)
        divLayer.style.display = 'none';

    return false;
}

// Function to be called
// by Web forms to show the Popup Window
function PopupArea(evt, areaId) {
    var left=0;
    var top = 0;
    if (evt.pageX) {
        left = evt.pageX;
        top = evt.pageY;
        top = top - 220;
    } else if (evt.clientX) {
        left = evt.clientX + document.body.scrollLeft - document.body.clientLeft;
        top = evt.clientY + document.body.scrollTop - document.body.clientTop;
        // include html element space, if applicable
        if (document.body.parentElement) {
            var bodParent = document.body.parentElement;
            left += bodParent.scrollLeft - bodParent.clientLeft;
			top += bodParent.scrollTop - bodParent.clientTop-220;
        }
    }

    var area = GetArea(areaId);
    area.popareaup(left, top);
}

// Function to hide the DIV Layer
function jsAreaClose(areaId) {
    GetArea(areaId).hide();
    activeAreaId =  null;
}


