﻿var jsAreaShowTime = 4000;
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() {
    if (activeAreaId != null)
        jsAreaClose(activeAreaId);

    var divLayer = this.ContentArea();
    divLayer.style.position = 'absolute';
    divLayer.style.display = 'block';
    //divLayer.style.left = x; now use style to position 
    //divLayer.style.top = y;
    divLayer.onmouseover = JsAreaMouseOver;
    divLayer.onmouseout = jsAreaMouseOut;
    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(areaId) {

    var area = GetArea(areaId);
    
    area.popareaup(0, 0);
    objfloatObj(areaId, 2, 2).floatObj();
}

function getElementTop(Elem) {
    if (document.getElementById) {
        var elem = document.getElementById(Elem);
    } else if (document.all) {
        var elem = document.all[Elem];
    }

    var yPos = elem.offsetTop;
    tempEl = elem.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos + 'px';

}

// Function to hide the DIV Layer
function jsAreaClose(areaId) {
    GetArea(areaId).hide();
    activeAreaId = divHangTimer = null;
}

var divHangTimer = null;

// Function to keep the Div Layer
// showing for a "period" of time
// after that period, if the mouse
// has been outside the DIV Layer, 
// it will be hidden automatically
function KeepArea(areaId) {
    if (areaId == activeAreaId && divHangTimer != null) {
        clearTimeout(divHangTimer);
        divHangTimer = null;
    }
}

// Function to release the DIV Layer
function RelArea(areaId) {
    if (areaId == activeAreaId && divHangTimer == null)
        divHangTimer = setTimeout('jsAreaClose(\'' + areaId + '\')', jsAreaShowTime);
}

// Function fired when mouse is over the 
// DIV Layer, used to keep the layer showing
function JsAreaMouseOver(e) {
    if (!e)
        var e = window.event;
    var targ = e.target ? e.target : e.srcElement;
    KeepArea(activeAreaId);
}

// Function that fires when mouse is out of
// the scope of the DIV Layer
function jsAreaMouseOut(e) {
    if (!e)
        var e = window.event;
    var targ = e.relatedTarget ? e.relatedTarget : e.toElement;
    var activeAreaView = document.getElementById(activeAreaId);
    if (activeAreaView != null && !jsAreaContains(activeAreaView, targ))
        RelArea(activeAreaId);
}
function jsAreaContains(parent, child) {
    while (child)
        if (parent == child) return true;
    else
        child = child.parentNode;

    return false;
}

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;

function objfloatObj(id, sx, sy) {
    var el = d.getElementById ? d.getElementById(id) : d.all ? d.all[id] : d.layers[id];
    var px = document.layers ? "" : "px";
    window[id + "_obj"] = el;
    if (d.layers) el.style = el;
    el.cx = el.sx = sx; el.cy = el.sy = sy;
    el.sP = function(x, y) { this.style.left = x + px; this.style.top = y + px; };

    el.floatObj = function() {
        var pX, pY;
        pX = (this.sx >= 0) ? 0 : ns ? innerWidth :
		document.documentElement && document.documentElement.clientWidth ?
		document.documentElement.clientWidth : document.body.clientWidth;
        pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ?
		document.documentElement.scrollTop : document.body.scrollTop;
        if (this.sy < 0)
            pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ?
		document.documentElement.clientHeight : document.body.clientHeight;
        this.cx += (pX + this.sx - this.cx) / 8; this.cy += (pY + this.sy - this.cy) / 8;
        this.sP(this.cx, this.cy);
        setTimeout(this.id + "_obj.floatObj()", 40);
    }
    return el;

}
