function addBodyLoadEventHandler(fn) { //spg: warning - if this function is used in the head to //add a handler then be aware that also using the onload attribute in the //body tag will cause all registered handlers to be wipped clean if (typeof fn == 'string') { fn = new Function(fn); } var oldHandler = window.onload; if (!oldHandler) { window.onload = fn; return; } if (typeof oldHandler == 'string') { oldHandler = new Function(oldHandler); } window.onload = function() { if(oldHandler) { oldHandler(); } fn(); }; return; } function getChildElements (el) { //return a collection containing references to all element child nodes //optionally if an extra arg is passed it is treated as an element tag name selector var childElements = []; var j = 0; var childItem; var tag = ""; if (arguments.length > 1) { tag = arguments[1].toUpperCase(); } for (var i = 0; i < el.childNodes.length; i++) { childItem = el.childNodes[i]; if (childItem.nodeType == 1 && ((tag == "") ? childItem.tagName.toUpperCase() : tag) == childItem.tagName.toUpperCase()) {//ELEMENT_NODE = 1 childElements[j] = childItem; j++; } } return childElements; } /* * getNodesByType.js - Retreives nodes based on node type and filter function criteria * * Parameters: * type: an integer (preferably a mnemonic constant from the W3C DOM Node class) * representing the node's type. * filter: a function returning a boolean indicating whether or not the node should * be included in the results * * The following example gets all nodes in a document having a "class" attribute with * the value of "foo": * * var nodes = document.getNodesByType(Node.ELEMENT_NODE, function(n) { * return (n.className == "foo"); * }); * * Written by Dave Lindquist (http://www.gazingus.org) * 6 April 2003 */ function getElementsByFilter(element, filter) { return getNodesByType(element,1,filter); } function getNodesByType(element,type, filter) { var nodes = new Array(); var context = element; var next; if (element.nodeType == null) return nodes; if (typeof filter != "function") filter = function() { return true; } while (context != null) { if (context.hasChildNodes()) { context = context.firstChild; } else if (context != element && null != (next = context.nextSibling)) { context = next; } else { next = null; for ( ; context != element; context = context.parentNode) { next = context.nextSibling; if (next != null) break; } context = next; } if (context != null && context.nodeType == type && filter(context)) { nodes[nodes.length] = context; } } return nodes; } /* not sure this works in ie?? if (Node && Node.prototype) Node.prototype.getNodesByType = getNodesByType; else Object.prototype.getNodesByType = getNodesByType; */