function getRealPos(el) {
    var has_border = /^td$/i.test(el.tagName) || /^body$/i.test(el.tagName);
    var SL=0;
    var ST=0;
    if (has_border)
    {
        // alert("Tag: " + el.tagName + "; Border Left: " + el.currentStyle.borderLeftWidth);
        SL -= this.ParseWidth(el.currentStyle.borderLeftWidth);
        ST -= this.ParseWidth(el.currentStyle.borderTopWidth);
    }

    var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
    if (el.offsetParent)
    {
        var tmp = this.GetAbsolutePos(el.offsetParent);
        r.x += tmp.x;
        r.y += tmp.y;
    }
    return r;
}

var divBlocks = new Array();
function DivBlocks()
{
	var name;
	var left;
	var top;
}

function SavePosition(module, leftPosition, topPosition)
{
	var instance = new DivOffset();
	instance.name 	= module;
	instance.left 	= leftPosition;
	instance.top 	= topPosition;
	//return instance;
	divBlocks[divBlocks.length] = instance;
	return divBlocks.length - 1;
}


function GetSaved(module) {

	var num = -1;

	for(var i=0; i<divBlocks.length; i++) { 
		if (divBlocks[i].name == module) {
			num = i;	
		}
	}
	return num;
}
/******************************************************************************/
function ParseWidth(val)
{
	var width = parseInt(val);
	return isNaN(width) ? 0 : width;
}

function GetAbsolutePos(el)
{
	var SL = 0, ST = 0;
	var is_div = /^div$/i.test(el.tagName);
	if (is_div && el.scrollLeft)
		SL = el.scrollLeft;
	if (is_div && el.scrollTop)
		ST = el.scrollTop;
	var has_border = /^td$/i.test(el.tagName) || /^body$/i.test(el.tagName);
	if (has_border)
	{
		// alert("Tag: " + el.tagName + "; Border Left: " + el.currentStyle.borderLeftWidth);
	SL -= ParseWidth(el.currentStyle.borderLeftWidth);
	ST -= ParseWidth(el.currentStyle.borderTopWidth);
	}
	var r = { x: el.offsetLeft - SL, y: el.offsetTop - ST };
	if (el.offsetParent)
	{
		var tmp = GetAbsolutePos(el.offsetParent);
		r.x += tmp.x;
		r.y += tmp.y;
	}
	return r;
}
/******************************************************************************/
function ShowDivEx(alink, module) {
	var div = document.getElementById(module); 
	var r = getRealPos(alink);
	div.style.left = r.x;
	div.style.top= r.y;// + alink.offsetHeight;
	div.style.display = "block";
	div.style.visibility = "visible";
}
function HideDiv(module) 
{
	var div = document.getElementById(module); 
	div.style.display = "none";
	div.style.visibility = "hidden";
}
function ShowDivCenter(module)
{
	var div = document.getElementById(module); 
	//320=div.width/2
	div.style.left = Math.round(document.body.clientWidth/2)-320;
	//620 is work area height - 370 is ~height of diw /2 
	div.style.top = 320 - 370/2;

	div.style.display = "block";
	div.style.visibility = "visible";
	//window.status += ' '+event.clientY+'='+div.style.offsetTop;
}
function ShowDivThis(module)
{
	var div = document.getElementById(module); 
	div.style.left = event.clientX-245;
	div.style.top = event.clientY-15;

	div.style.display = "block";
	div.style.visibility = "visible";
	//window.status += ' '+event.clientY+'='+div.style.offsetTop;
}
