+ {\r
+ oNewNode = oEditor.FCK.InsertElement( nodeName ) ;\r
+ }\r
+ }\r
+\r
+ // Set the basic attributes\r
+ for( var attName in oAttributes )\r
+ oNewNode.setAttribute( attName, oAttributes[attName], 0 ) ; // 0 : Case Insensitive\r
+\r
+ return oNewNode ;\r
+}\r
+\r
+// Copy all the attributes from one node to the other, kinda like a clone\r
+// But oSkipAttributes is an object with the attributes that must NOT be copied\r
+function CopyAttributes( oSource, oDest, oSkipAttributes )\r
+{\r
+ var aAttributes = oSource.attributes ;\r
+\r
+ for ( var n = 0 ; n < aAttributes.length ; n++ )\r
+ {\r
+ var oAttribute = aAttributes[n] ;\r
+\r
+ if ( oAttribute.specified )\r
+ {\r
+ var sAttName = oAttribute.nodeName ;\r
+ // We can set the type only once, so do it with the proper value, not copying it.\r
+ if ( sAttName in oSkipAttributes )\r
+ continue ;\r
+\r
+ var sAttValue = oSource.getAttribute( sAttName, 2 ) ;\r
+ if ( sAttValue == null )\r
+ sAttValue = oAttribute.nodeValue ;\r
+\r
+ oDest.setAttribute( sAttName, sAttValue, 0 ) ; // 0 : Case Insensitive\r
+ }\r
+ }\r
+ // The style:\r
+ if ( oSource.style.cssText !== '' )\r
+ oDest.style.cssText = oSource.style.cssText ;\r
+}\r
+\r
+/**\r
+* Replaces a tag with another one, keeping its contents:\r
+* for example TD --> TH, and TH --> TD.\r
+* input: the original node, and the new tag name\r
+* http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-renameNode\r
+*/\r
+function RenameNode( oNode , newTag )\r
+{\r
+ // TODO: if the browser natively supports document.renameNode call it.\r
+ // does any browser currently support it in order to test?\r
+\r
+ // Only rename element nodes.\r
+ if ( oNode.nodeType != 1 )\r
+ return null ;\r
+\r
+ // If it's already correct exit here.\r
+ if ( oNode.nodeName == newTag )\r
+ return oNode ;\r
+\r
+ var oDoc = oNode.ownerDocument ;\r
+ // Create the new node\r
+ var newNode = oDoc.createElement( newTag ) ;\r
+\r
+ // Copy all attributes\r
+ CopyAttributes( oNode, newNode, {} ) ;\r
+\r
+ // Move children to the new node\r
+ FCKDomTools.MoveChildren( oNode, newNode ) ;\r
+\r
+ // Finally replace the node and return the new one\r
+ oNode.parentNode.replaceChild( newNode, oNode ) ;\r
+\r
+ return newNode ;\r
+}\r