// ****************************JavaScript****************************************+
//  The primary purpose of this script is to create a popup page on command.
//		The popup page will be centered and placed either above or below the 
//		link depending on the location of the page
//
//  This script has multiple functions:
//    	iecompattest() - determines the type of browser and compatability 
//                        with the functions being performed
//		hidemenu() - removes the popup page from the screen
//		delayhidemenu() - allows popup to stay on screen for a period of 
//						  time after the mouse is no longer over the link
//						  The delay parameter is configurable for each popup 
//						  is desired or can be set using "delaystdtime"
//		clearhidemenu() - does some cleanup if old popup is still open
//		showpopup(e,whichpage) - this is the main function that displays the page
//							     e - event, whichpage - is the popup page number
//	*****************************************************************************+
//

var ie5=document.all && !window.opera;
var ns6=document.getElementById;
var delaystdtime=200;

function iecompattest(){
	return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body
}
function hidemenu(){
	var thediv=ie5? document.all.displaybox : document.getElementById("displaybox");
		thediv.style.display="none";
}

function delayhidemenu(delaytime){
	dtime=(typeof delaytime!="undefined")? delaytime : delaystdtime;
	delayhide=setTimeout("hidemenu()",dtime)
}

function clearhidemenu(){
	if (window.delayhide) {
		clearTimeout(delayhide)
	}
}

function showpopup(e,whichpage){
	var wdth=0;
	
	clearhidemenu()
	this.standardbody=(document.compatMode=="CSS1Compat")? document.documentElement : document.body

  	var thediv=ie5? document.all.displaybox : document.getElementById("displaybox");
	var lftrtpos=0;
	if (this.standardbody.clientWidth > 851) {
		wdth = this.standardbody.clientWidth - 851;
		wdth = wdth/2;
		lftrtpos=wdth+215;
		}
	
	if (this.standardbody.clientWidth == 851) {
		lftrtpos=215;
		}

	if (this.standardbody.clientWidth < 851) {
		wdth = this.standardbody.clientWidth/2 - 270;
		lftrtpos=wdth;
		}
	if(whichpage != null){
 		thediv.style.display = "";
		thediv.innerHTML = whichpage;
	}
	
	thediv.contentheight=thediv.offsetHeight
	eventY=ie5? event.clientY : e.clientY
	
	//Find out how close the mouse is to the corner of the window
	var bottomedge=ie5? iecompattest().clientHeight-eventY : window.innerHeight-eventY
	
	//same concept with the vertical position iecompattest().scrollTop+window.pageYOffset+
	if (bottomedge<thediv.contentheight) {
		thediv.style.top=ie5? (eventY-thediv.contentheight+bottomedge)+"px" : (eventY+bottomedge-thediv.contentheight)+"px";
		var bottomtop=ie5? (eventY-thediv.contentheight+bottomedge) : (eventY+bottomedge-thediv.contentheight);
		if(bottomtop<ie5? event.clientY : eventY) {thediv.style.top=ie5? (event.clientY-thediv.contentheight-18)+"px" : (eventY-thediv.contentheight-18)+"px";}
	}
	else {
		thediv.style.top=ie5? (18+event.clientY)+"px" : (18+eventY)+"px";
	}
	thediv.style.left = lftrtpos+'px' ;
	return false;
}
