var interfaces = new Array(); Template = function(where,templateid,myInterfaces,id) { var now = new Date(); this.id=now.getTime().toString()+Math.random().toString(); if(myInterfaces) { this.myInterfaces = myInterfaces; if(id) { this.extraid = id; this.myInterfaces[this.extraid] = this; } else myInterfaces[this.id] = this; } interfaces[this.id] = this; var newnode = document.getElementById(templateid).cloneNode(true); this.node = newnode; newnode.setAttribute("interfaceId",this.id); this.template = new Array(); fetchTemplateChilds(this.node,this.template); if(typeof(where)=='object') where.appendChild(newnode); else if(document.getElementById(where)) document.getElementById(where).appendChild(newnode); this.remove = function() { removeNode(this.node); if(this.myInterfaces) { if(this.extraid) delete this.myInterfaces[this.extraid]; else delete this.myInterfaces[this.id]; } delete interfaces[this.id]; } function fetchTemplateChilds(root,a) { if(root.getAttribute&&root.getAttribute("template")) a[root.getAttribute("template")] = root; if(!root.getAttribute||!root.getAttribute("stop")) for(var i=0,childs=root.childNodes;i=this.where.childNodes.length) this.where.appendChild(moveThis); else this.where.insertBefore(moveThis,this.where.childNodes[newPos]); } } /* helper for interface event methods, returns the appropiate interface */ function getInterface(el) { do { if (el.getAttribute&&el.getAttribute("interfaceid")) return interfaces[el.getAttribute("interfaceid")]; el=el.parentNode; } while (el.nodeType!=9); return null; } function removeNode(node) { if(node.parentNode) node.parentNode.removeChild(node); } function removeNulls(array) { if(typeof(array.splice)=='undefined') return; var i=0; for(var j=0;i