//popup a rectangle with text

var offsetx=-60; //Customize x offset of popup
var offsety=20; //Customize y offset of popup
var ie=document.all;
var ns6=document.getElementById && !document.all;
var pop=false;
var popobj;
var maxLen=80; // max text length in popon

function popon(thetext, thecolor){
var i, newNode, line, maxBox=false;
if (!document.getElementById("htmlpop")) {
newNode = document.createElement("div");
newNode.setAttribute("id", "htmlpop");
document.body.appendChild(newNode);
}
popobj=document.getElementById("htmlpop");
lines = thetext.split("<br />") //split on <br /> ?
for (i in lines) {
	if (lines[i].replace(/(<([^>]+)>)/ig,"").length > maxLen) maxBox = true;
}
popobj.style.width=((maxBox) ? (5 * maxLen) + "px" : "auto");
if (typeof thecolor!="undefined" && thecolor!="") popobj.style.backgroundColor=thecolor;
popobj.innerHTML=thetext;
pop=true;
return false;
}

function popoff(){
popobj.style.visibility="hidden";
pop=false;
}

function positionpop(e){
if (pop){
var curX=(ns6)?e.pageX : event.clientX+document.documentElement.scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+document.documentElement.scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? document.documentElement.clientWidth-event.clientX-offsetx : window.innerWidth-e.clientX-offsetx-20
var bottomedge=ie&&!window.opera? document.documentElement.clientHeight-event.clientY-offsety : window.innerHeight-e.clientY-offsety-20

var leftedge=(offsetx<0)? offsetx*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<popobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
popobj.style.left=ie? document.documentElement.scrollLeft+event.clientX-popobj.offsetWidth+"px" : window.pageXOffset+e.clientX-popobj.offsetWidth+"px"
else if (curX<leftedge)
popobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
popobj.style.left=curX+offsetx+"px"

//same concept with the vertical position
if (bottomedge<popobj.offsetHeight)
popobj.style.top=ie? document.documentElement.scrollTop+event.clientY-popobj.offsetHeight-offsety+"px" : window.pageYOffset+e.clientY-popobj.offsetHeight-offsety+"px"
else
popobj.style.top=curY+offsety+"px"
popobj.style.visibility="visible"
}
}

document.onmousemove=positionpop
