
var xmlDoc = null;


function getObject (id) {
        if (document.getElementById) {
                return document.getElementById(id);
        }

        if (document.all) {
                return document.all[id];
        }

        if (document.layers) {
                return document.layers[id];
        }

        return null;
}



function updateHover(src, text) {
        var obj = getObject('hoverbox');
        if (null === obj) {
                return;
        }

	// get the Y position to use, with min/max boundaries
        var posY = findPosY(src);

        var stat = getObject('static-top');
        var minY = findPosY(stat) + 15;
	stat = getObject('static-bottom');
	var maxY = findPosY(stat) - 75;

        if (posY < minY)
                posY = minY;

	if (posY > maxY)
		posY = maxY;

        obj.style.top = posY;

	// set the width
	stat = getObject('left-navbar');
	var width = stat.clientWidth;
	obj.style.width = width;

	// finally, set the text
        obj.innerHTML = text;
}


function resetHover() {
        var obj = getObject('hoverbox');
        updateHover(obj, "");
}


function findPosY(obj)
{
        var curtop = 0;
        var printstring = '';
        if (obj.offsetParent)
        {
                while (obj.offsetParent)
                {
//                        printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
                        curtop += obj.offsetTop;
                        obj = obj.offsetParent;
                }
        }
        else if (obj.y)
                curtop += obj.y;
//        window.status = printstring;
        return curtop;
}


function loadComments(id) {
	var xmlDoc;
	if (window.XMLHttpRequest) {
		xmlDoc = new XMLHttpRequest();
	} else {
		xmlDoc = new ActiveXObject("Microsoft.XMLHTTP");
	}

	var obj_id = "comments_" + id;
	if (null !== xmlDoc) {
		xmlDoc.onreadystatechange = function() {
				processComments(xmlDoc, obj_id);
			};
		var url = "get-posts.cgi?id=" + id;
		xmlDoc.open("GET", url, true);
		xmlDoc.send(null);
	} else {
		getObject(obj_id).innerHTML = "Browser cannot load comments.";
	}
}


function processComments(xmlDoc, obj_id) {
	if (xmlDoc.readyState != 4) {
		return;
	}

	getObject(obj_id).innerHTML = xmlDoc.responseText;
}
