// Author: Johari Lanng / Web Development Group / 16.6.2005

// This function is used to generate a collection of links that connect to <h2> elements within a page.
function generateBookmarks()
{
	var h2Collection = document.getElementsByTagName("h2"); // collect <h2> elements
	if(h2Collection.length > 1)	// if there are more than 1 ...
	{
        var newUL = document.createElement("ul");	// make a temp <ul> element
        document.getElementById("bookmarks").appendChild(newUL); //	append <ul> to hard-coded <div id="bookmarks">.
    
		for(x=0; x<h2Collection.length; x++)	// loop through them ...
		{
			h2Collection[x].setAttribute("id","h2_"+x);	// create ID attribute for each <h2>
			var newLI = document.createElement("li");	// make a temp <li> element
			var newLink = document.createElement("a");	// make a temp <a> element
			newLink.setAttribute("href","#h2_"+x);	// make the <a> link down to the <h2> via the ID.
			newLink.setAttribute("className","bookmarks");	// make the <a> link down to the <h2> via the ID.
            
            // --------------------------------------------------------------------------------------
            // the following part of the script has been modified to accomodate elements within the <h2> tags, such as an <a>.
            if(h2Collection[x].childNodes)
            {            
                var y = h2Collection[x].childNodes.length-1;
            } else {
                var y = 0;
            }	
            var newLIText = document.createTextNode(h2Collection[x].childNodes[y].nodeValue);	// make a new textnode with the name of the <h2> element.
            // --------------------------------------------------------------------------------------
            
            		
            newLink.appendChild(newLIText);	// append textnode to <a>
			newLI.appendChild(newLink);		// append <a> to <li>
			newUL.appendChild(newLI); //	append <li> to hard-coded <ul>.
		}
	}

}

//Highlights the Search text box
var highlightcolor="#E9E9AF"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}