/***********************************************************************
 * Several scripts may want to have window.onload event handlers.
 * The following script allows them all to have their handlers work.
 ***********************************************************************/
var onLoadHandlers = new Array();
function registerOnLoadHandler(f) {
	if( f == null ) return;
	onLoadHandlers[onLoadHandlers.length] = f; // push not supported on IE5
}
var onLoadStarted = false;
function onLoadChain() {
	if( onLoadStarted ) return; // sometimes this gets called more than once
	onLoadStarted = true;
	for(var i = 0; i < onLoadHandlers.length; i++)
		onLoadHandlers[i]();
}
window.onload = onLoadChain;


/***********************************************************************
 * Common utility functions
 ***********************************************************************/

// getElementsByTagName returns all descendant nodes,
// but this method returns only those nodes that are immediate children.
function getImmediateChildrenByTagName(element, tagName)
{
	var list = new Array();
	if(element){
		list = element.getElementsByTagName(tagName);
	}
	// Keep elements that are immediate children 
	// of supplied element.
	var finalList = new Array();
	var finalIdx = 0;
	for( var i = 0; i < list.length; i++ )
		if( list[i].parentNode == element )
			finalList[finalIdx++] = list[i];
	return finalList;
}

/* The next several utility functions are utilized by our index generation javascript */
var defaultEmptyOK = false
var whitespace = " \t\n\r";
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function stripCharsInBag (s, bag)
{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}

function stripWhitespace (s)
{   return stripCharsInBag (s, whitespace)
}

function isAlphanumeric (s)
{   var i;

    if (isEmpty(s)) 
       if (isAlphanumeric.arguments.length == 1) return defaultEmptyOK;
       else return (isAlphanumeric.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-alphanumeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number or letter.
        var c = s.charAt(i);

        if (! (isLetter(c) || isDigit(c) ) )
        return false;
    }

    // All characters are numbers or letters.
    return true;
}