/* qspop v1.1
 * for popping up divs, oriented correctly within 
 * a browser.  originally for cjobs plan viewer.
 */
var hidestop = false;
var lastqs,focus;
document.onmouseup=hideqsnode;
document.onmousemove = getpos;
var DELAY = 300;
var lx,ly;
isIE=document.all; 

function hideqsnode(){
  var z = '_hideqsnode()';
  window.setTimeout(z, DELAY);
}
function _hideqsnode(e){
    if(lastqs == null)return;
	if(focus != null && focus.id == lastqs.id)return;
	if(hidestop)return;
	if(lastqs != null){lastqs.style.visibility = 'hidden';}
}
function showqsnode(qsid){
  var z = '_showqsnode(\''+qsid+'\')';
  window.setTimeout(z, DELAY);
}
function _showqsnode(qsid){
	if(lastqs != null)lastqs.style.visibility = 'hidden';
	lastqs = document.getElementById(qsid);
	if(lastqs.innerHTML == '')return;
	//sticking it at 0,0 first helps ensure offsetWidth will not be 0
	lastqs.style.left = 0;
	lastqs.style.top = 0;
	lastqs.style.visibility = 'visible';
	if(lastqs.offsetWidth > document.body.clientWidth-lx)
		lastqs.style.left = lx+document.body.scrollLeft-lastqs.offsetWidth-5;//left
	else
		lastqs.style.left = lx+document.body.scrollLeft+5;//right
	if(parseInt(lastqs.style.left) < document.body.scrollLeft)
		lastqs.style.left= document.body.scrollLeft;
	if(lastqs.offsetHeight > document.body.clientHeight-ly)
		lastqs.style.top = ly+document.body.scrollTop-lastqs.offsetHeight-5;//above
	else
		lastqs.style.top = ly+document.body.scrollTop+5;//below
	if(parseInt(lastqs.style.top) < document.body.scrollTop)
		lastqs.style.top = document.body.scrollTop;
	lastqs.style.visibility = 'visible';
}
function donthide(){hidestop = true;}
function dohide(){hidestop = false;}
function getpos(e){
	if(isIE){
		lx = event.clientX;
		ly = event.clientY;
	}else{
		lx = e.clientX;
		ly = e.clientY;
	}
	try{
	    node = e.target;
        while(node.id == null || node.id == ''){
	        node = node.parentNode;
            if(node == null)break;
	    }
	    focus = node;
	}catch(ee){}
}
