// By Ray Yates -- PCI Net

var pagetop = "http://www.pcinet-llc.com/docs/toolbelt_docs.shtml#";
var totop = "<a class='totop' href='toolbelt_docs.shtml#' target='_top'>top</a>";

if (window.addEventListener) {
    window.addEventListener("load", initLinks, false)
} else if (window.attachEvent) {
    window.attachEvent("onload", initLinks )
}

function initLinks() {
    //window.location = pagetop;
    var i = 0;
    var anchor = "";
    // add events to the category tree
    var nav = document.getElementById("categories");
    var els = nav.getElementsByTagName("li");
    for(i = 0; i < els.length; i++) {
    	if(els[i].className=="topcat"){
    		els[i].onmouseover=topnavover;
    	}else{
			els[i].onclick=navclick;
			els[i].onmouseover=navover;
        }		
		els[i].onmouseout=navout;
    }
	var els = nav.getElementsByTagName("span");
    for(i = 0; i < els.length; i++) {
		els[i].onclick=navclick;
    }

	// add anchors to the content h2 and h3 tags
    var content = document.getElementById("content");

    els = content.getElementsByTagName("h2");
    for(i = 1; i < els.length; i++) {
    	anchor = els[i].innerHTML.trim().replace(/ /g,"_").replace(/:/g,"");    	
        els[i].innerHTML = "<a target='_self' name='" + anchor + "'></a>" + totop + els[i].innerHTML;
    }
	els = content.getElementsByTagName("h3");
    for(i = 1; i < els.length; i++) {
    	anchor = els[i].innerHTML.trim().replace(/ /g,"_").replace(/:/g,"");    	
        els[i].innerHTML = "<a target='_self' name='" + anchor + "'></a>" + totop + els[i].innerHTML;
    }

	// add anchors to the content2 h2 and h3 tags
	var content = document.getElementById("content2");
	
    els = content.getElementsByTagName("h2");
    for(i = 0; i < els.length; i++) {
    	anchor = els[i].innerHTML.trim().replace(/ /g,"_").replace(/:/g,"");    	
        els[i].innerHTML = "<a target='_self' name='" + anchor + "'></a>" + totop + els[i].innerHTML;
    }
        els = content.getElementsByTagName("h3");
    for(i = 0; i < els.length; i++) {
    	anchor = els[i].innerHTML.trim().replace(/ /g,"_").replace(/:/g,"");    	
        els[i].innerHTML = "<a target='_self' name='" + anchor + "'></a>" + totop + els[i].innerHTML;
    }
}

function topnavover(){
	// bright blue
    this.style.color="#4060dc"; 
}
function navclick() {
	var anchor = this.innerHTML.trim().replace(/ /g,"_");
	window.location=pagetop + anchor;
}
function navover(){
	//red
    this.style.color="#d03040"; 
}
function navout(){
	//soft blue
    this.style.color="#406080"; 
}
function goto(bookmark){
    window.location.hash=bookmark;
}
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

