// popup function code is based on code by:
// (c) 1998 Andrew Castles. - andrewc@arrakis.es
// All rights reserved.     - http://www.arrakis.es/~andrewc/

var isNav4 = document.layers?1:0;

	function popupon(text, e) { 
		if (view == "timescatter") {
			text = scatterPopupOn(text,e);
		} else {
			if (view == "WF" && text.lastIndexOf("<br>0.000") != -1) 
				text = text.replace("<br>0.000","<br>&lt;0.015");
		
			if (text.indexOf(" <br>") == 0) return;
			var tary = text.split("<br>");
			if (tary[0] == "stack") {
				var per = Math.round(tary[4] * 100)/100;  //this is to convert the percentage to 2 decimal places
				text = tary[1] + "<br>" + findlbl(tary[2]) + "<br>" + tary[3] + " -- " + per + "%"
			} else if (tary[0] == "dbscatter") 
				text = tary[1] + "<br>" + tary[2] + "<br>" + findLoc(tary[1],tary[2]);
		}
				
		tary = text.split("<br>");
		text = ""
		newtxt = ""
		for (str in tary) {
			str = tary[str];
			while (str.length > 60) {
				newtxt += str.substring(0,60) + "<br>";
				str = str.substring(60, str.length);
			}
			text += newtxt + str;
			newtxt = "<br>";
		}
		
		var popup;
		if (isNav4) popup = document.layers["popup"];
		else popup = document.getElementById("popup");
		
		xOffset=3;
		yOffset=3;

		var table = "";
		var bigTable = ""; // Workaround for Netscape
		
		if (isNav4) {
			table += "<table cellpadding=3 border=1 cellspacing=0 bgcolor='#000000' class='black-1'>";
			bigTable += "<table width=" + (document.width - e.pageX - 30)+"cellpadding=3 border=1 cellspacing=0 bgcolor='#000000' class='black-1'>";
			table += "<tr><td bgcolor='#ffffcc'>" + text + "</td></tr></table>";
			bigTable += "<tr><td bgcolor='#ffffcc'>" + text + "</td></tr></table>";
		} else {	// If IE4+
			table += "<table bgcolor= '#000000' border= 0 cellpadding= 3 cellspacing=1 class='black-1'>";
			table += "<tr bgcolor='#ffffcc'><td nowrap>" + text + "</td></tr>";
			table += "</table>"
		}
		
		if (tary[0].indexOf("Error") != -1) {
			table = table.replace(/000000/g,"cc0000");
			bigTable = bigTable.replace(/000000/g,"cc0000");
		}
			
		if (isNav4) {

			popup.document.open();
			popup.document.write(table);
			popup.document.close();

			if ((popup.document.width + e.pageX) > document.width)	{ 
				// If the layer runs off the right hand side
				popup.document.open();
				popup.document.write(bigTable);
				popup.document.close();
			}

			popup.left = e.pageX + xOffset;
			popup.top  = e.pageY + yOffset;
			popup.visibility = "visible";
					
		} else {

			popup.innerHTML = table;
			var left = e.clientX + document.body.scrollLeft;
			if (left + popup.offsetWidth > document.body.offsetWidth) 
				left = document.body.offsetWidth - popup.offsetWidth - 30;
			popup.style.left = left + 10;
			popup.style.top = e.clientY + document.body.scrollTop + 10;
			popup.style.visibility = "visible";
		
		}
	}


	function popupoff() 	{ 
		
		var popup;
		if (isNav4) popup = document.layers["popup"];
		else popup = document.getElementById("popup");
		popup.style.visibility = "hidden";
		
	}
	
	/************************************************************
										functions for annotations
	************************************************************/
	
	function over(e) {
		
		if (isNav4) {
			text = eval(e.target.name.replace("icon","note"));
			table = "<table cellpadding=3 border=1 cellspacing=0 bgcolor='#000000'>";
			table +=  text + "</table>";
			document.layers["annotation"].document.open();
			document.layers["annotation"].document.write(table);
			document.layers["annotation"].document.close();
			
			if ((document.layers["annotation"].document.width + e.pageX) > document.width)	{ 
				bigTable = "<table width=" + (document.width - e.pageX - 30)+"cellpadding=3 border=1 cellspacing=0 bgcolor='#000000'>";
				bigTable += text + "</table>";			
				document.layers["annotation"].document.open();
				document.layers["annotation"].document.write(bigTable);
				document.layers["annotation"].document.close();
				
			}			
			document.layers["annotation"].top = e.pageY;
			document.layers["annotation"].left = e.pageX;
			document.layers["annotation"].visibility = "show";
		} else {
			e = window.event;
			text = eval(e.srcElement.name.replace("icon","note"));
			table = "<table cellpadding=3 border=0 cellspacing=1 bgcolor='#000000'>";
			table +=  text + "</table>";
			document.getElementById("annotation").innerHTML = table;			
			document.getElementById("annotation").style.pixelTop = e.clientY + document.body.scrollTop;
			document.getElementById("annotation").style.pixelLeft = e.clientX + document.body.scrollLeft;
			document.getElementById("annotation").style.visibility = "visible";
		}
	}
	
	
	function out(e) {
		if (isNav4) {
			document.layers["annotation"].visibility = "hide";
		} else {
			document.getElementById("annotation").style.visibility = "hidden";
		}
	}
		
	function addHandler(o) {
		o.onmouseover = over;
		o.onmouseout = out;	
	}
	

