var jsAreaShowTime = 50000;
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';
	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(e, areaId,w)
{
	var posx=0;
	var posy=0;
	var HT=document.getElementById(areaId).style.height;
	var divht=HT.substring(0,HT.length-2);
	if(w)
	{
		document.getElementById(areaId).style.width=w;
	}
	var WD=document.getElementById(areaId).style.width;
	var divwd=WD.substring(0,WD.length-2);
	
	posx=((document.body.clientWidth/2)-(divwd/2));
	posy=((document.body.clientHeight/2)-(divht/2)); //+(document.body.scrollTop+document.documentElement.scrollTop));
	var area = GetArea(areaId);
	area.popareaup(posx, posy);
}

// 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 n=50;
var dragok = false;
var sy,sx,dy,dx;

function up()
{
    dragok = false;
	document.onmousemove = null;
}

function jsMove(e,DivId)
{
	if (!e) e = window.event;
 	if (dragok)
	{
  		var d=document.getElementById(DivId);
  		//alert(areaId);
		d.style.left = dx + e.clientX - sx + "px";
  		d.style.top  = dy + e.clientY - sy + "px";
  		return false;
 	}
}

function jsDown(e,DivId)
{
if (!e) e = window.event;
	var temp=document.getElementById(DivId);
	//alert(temp);
	dragok = true;
 	//temp.style.zIndex = n++;
	dx = parseInt(temp.style.left+0);
 	dy = parseInt(temp.style.top+0);
 	sx = e.clientX;
	sy = e.clientY;
	document.onmousemove = jsMove;
 	return false;
}