var cm = "", timer, actl;

function dget(a) {
	return document.getElementsByTagName(a)
}

function findXY(obj) {
	var cp = new Array()
	cp["x"] = cp["y"] = 0
	while (obj.offsetParent) {
		cp["x"] += obj.offsetLeft
		cp["y"] += obj.offsetTop
		obj = obj.offsetParent
	}
	return cp
}

function shdiv() {
	if ( actl == cm ) {
		return false
	}
	var x, t, z, c, opc = "", topy, lfty
	var pos = findXY(actl)

	rmdiv('iLinkBox')


	x = dce('DIV')
	z = actl.href.split("/")
	c = z[z.length-1];

	(actl.className == "ilinkg") ? x.className = "iLinkDefinition" : x.className = "iLinkMessage"

	if ( (document.body.clientWidth - pos["x"]) <= 302 ) {
		lfty = (pos["x"] - 263)
		opc = "class=\"floatright\""
		topy = (pos["y"] - 15)
	} else {
		lfty = (pos["x"] + 8)
		topy = (pos["y"] - 15)
	}
	x.style.left = lfty + "px"
	x.style.top = topy + "px"

	t = "<a href=\"\" onclick=\"rmdiv('iLinkBox'); return false;\" class=\"closeButtonLrg\"><span id=\"lrgButton\"></span></a><h1>" + names[c] + "</h1><p>" + msgs[c] + "</p>"
	if ( haslongdesc[c] ) {
		t += "<p><a href=\"" + c + "\" onClick=\"return makeGenNewWindow(\'";
		t += dhaACDBPath + "/Content/" + c + "?OpenDocument&amp;ShowViewLongDescLink=yes";
		t += "\', 400, 400)\">View long description</a></p>";
	}
	t += "<p><a href=\"\" onclick=\"rmdiv('iLinkBox'); return false;\" class=\"closeButton\">close window</a></p>"

	x.innerHTML = t;
	x.style.display = "block"
	dgei('iLinkBox').appendChild(x)

	if ( 
	     (pos["y"] + x.offsetHeight) >= ( document.body.scrollTop + document.body.clientHeight)
	     &&
             (pos["y"] - x.offsetHeight > 0)
	     &&
	     (x.offsetHeight < pos["y"] - document.body.scrollTop)
           ) 
        {
		topy = (pos["y"] - x.offsetHeight + 1)
		x.style.top = topy + "px"
	}

	checkSelectBoxes(topy, lfty, (topy + x.offsetHeight), (lfty + x.offsetWidth))
	cm = actl
	return false
}

function rmdiv(arg) {
	var s, i = 0, nd = dgei(arg).firstChild
	if (nd) {
		nd.style.backgroundColor = "#000000"
		nd.parentNode.removeChild(nd)
	}

	s = dget('select')
	while ( i < s.length ) {
		s[i].style.visibility = ""
		i++
	}

	cm = ""
	return false
};



function mkilnks() {
	var x = dget('A')
	var i = 0
	var z,c
	while ( i < x.length ) {
		if ( x[i].className == "ilinkg" || x[i].className == "ilinke" ) {
			z = x[i].href.split("/")
			c = z[z.length-1];
			if (!msgs[c] || msgs[c].length == 0) {
				x[i].parentNode.removeChild(x[i])
			} else {
				x[i].onmouseover = function () { disableOnClick(this); actl = this; timer = window.setTimeout(shdiv, 400) }
				x[i].onmouseout = function () { enableOnClick(this); actl = ""; if (timer) { window.clearTimeout(timer); } }
				// x[i].onclick = function () { return false; }
			}
		}
		i++
	}
	document.onclick = function () { rmdiv('iLinkBox') }
}

function enableOnClick(arg) {
	document.onclick = function () { rmdiv('iLinkBox') }
	arg.onclick = function () { return makeGenNewWindow(this.href, 400, 400) }
}

function disableOnClick(arg) {
	document.onclick = function () { return false; }
	arg.onclick = function () { return false; }
}

function checkSelectBoxes(t, l, b, r) {
	var s = dget('SELECT'), n = 0
	while ( n < s.length ) {
		var sp = findXY(s[n])
		var st = sp["y"], sl = sp["x"]
		var sr = sp["x"] + s[n].offsetWidth, sb = sp["y"] + s[n].offsetHeight
		if ((((l <= sl) && (r >= sl)) || ((l <= sr) && (r >= sr))) && (((t <= st) && (b >= st)) || ((t <= sb) && (b >= sb)))) {
			s[n].style.visibility = "hidden"
		}
		n++
	}
}

