// Function to add a DOM node to a page function addPageElement(parent,tagName,attributes,text) { // Are we adding a simple text node or something more complex? if (tagName=='text') { var curElement = document.createTextNode(text); } else { // Create our new node var curElement = document.createElement(tagName); // Go through each of our attributes for(property in attributes) { // Work-around for adding event handlers, styles, and classes for IE if (curElement.attachEvent) { if (property.substring(0,2)=='on') { //eval('curElement.attachEvent(\''+property.toLowerCase()+'\','+attributes[property].replace('()','')+')'); eval('curElement.'+property+'=function (){'+attributes[property]+'}'); } else if (property=='style') curElement.style.cssText=attributes[property]; else if (property=='class') curElement.setAttribute('className',attributes[property]); else curElement.setAttribute(property,attributes[property]); } else curElement.setAttribute(property,attributes[property]); } // Do we want to add some text while we are at it? if (text!='') { var eleText = document.createTextNode(text); curElement.appendChild(eleText); } } // Add the node parent.appendChild(curElement); // Return our created node return curElement; } // Function to completely clear a node of child elements function emptyElement(element) { // Go through each child and erase it while (element.firstChild) element.removeChild(element.firstChild); } // Function to completly destroy an element and all of its children function removeElement(element) { // Get the parent of this element, then remove the element from it var parent; parent=element.parentNode; parent.removeChild(element); } // Function to move a node around under its parent node function moveElement(element,destination,parent) { // Are we moving to a different parent? if (parent=='') parent=element.parentNode; // Get our current location within this parent for(var x=0; x=0) parent.insertBefore(element,parent.childNodes[index-count]); } else if ((destination.substring(0,1)=='+' || destination=='down') && parent==element.parentNode) // We want to move down, only works with same parent { // First get how many we want to move var count; if (destination=='down') count=1; else count=parseInt(destination.replace('+','')); // Make sure we won't go over the end, since we are appending afterward if we need to be the last node we need a special case if (index+count