// Function to display tooltips on mouseover
var oPopup = window.createPopup();
function showToolTip(toolTip)
{
	// for some reason, the retrieval of width and height must be done
	// before lefter and topper. Otherwise, the tooltip does not display
	// above the link, but at the top of the page.
    var width = toolTip.width;
    var height = toolTip.height;
	var lefter = event.screenY-height-15;	// displays above the cursor
    var topper = event.screenX-width/3;
    oPopup.document.body.innerHTML = toolTip.innerHTML; 
	oPopup.document.body.style.backgroundColor = "#ffffcc";
	oPopup.document.body.style.fontFamily = "Verdana";
	oPopup.document.body.style.fontSize = 11;
	oPopup.document.body.style.margin = "3,3,3,3";
	oPopup.document.body.style.border = "solid black 1px";
    oPopup.show(topper, lefter, width, height);
}

// Function to generate a table of contents from h2 headings
function buildTOC() {
    var coll = document.all;
    var level;
    var id;
    for (i=document.body.sourceIndex+1; i<coll.length; i++) {
        switch (coll[i].tagName) {
        case "H2":
            level = 1;
            break;
        case "H3":
            level = 2;
            break;
        default:
            level = -1;
        }
        if (level!=-1) {
            id = i;
            setAnchor(coll[i], id);
            i++;
            setLink(coll[i], id, level);
            i+=2;
        }
    }
}

// Function to bookmark the specified element
function setAnchor(el, id) {
    el.insertAdjacentHTML("BeforeBegin", "<A NAME=\"" + id + "\">");
    el.insertAdjacentHTML("AfterEnd", "</A>");
}

// Function to create a link to a bookmarked element
function setLink(el, id, level) {
	if (level == 2){
		MyTOC.insertAdjacentHTML("BeforeEnd", "&nbsp;&nbsp;&nbsp;&nbsp;");
	}
	MyTOC.insertAdjacentHTML("BeforeEnd", "<A HREF=" + document.location.pathname + "#" + id + ">" + el.innerText + "<br>");
}

// Function to display information in a small popup window
var newWindow;
function showSmallWindow(url)
{
	newWindow = window.open(url,"Information",'height=600,width=600,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes',true);
	newWindow.focus();
}
