function create_html_tags(node)
{
	var frag = document.createDocumentFragment();
	var children = node.childNodes;
	for (var i = 0; i < children.length; i++)
	{
		switch (children[i].nodeType)
		{
			//element
			case 1:
				var tag = document.createElement(children[i].nodeName);
				copy_attributes(tag, children[i]);
				if (children[i].hasChildNodes())
					tag.appendChild(create_html_tags(children[i]));
				frag.appendChild(tag);
				break;
			//text
			case 3:
				var text = document.createTextNode(children[i].nodeValue);
				frag.appendChild(text);
				break;
			//comment
			case 8:
				var comment = document.createComment(children[i].nodeValue);
				frag.appendChild(comment);
				break;
		}
	}
	return frag;
}

function copy_attributes(node_d, node_s)
{
	for (var i = 0; i < node_s.attributes.length; i++)
	{
		node_d.setAttribute(node_s.attributes[i].nodeName, node_s.attributes[i].nodeValue);
		if (node_s.attributes[i].nodeName == "class")
			node_d.className = node_s.attributes[i].nodeValue;
	}
}

function remove_children(node)
{
	var length = node.childNodes.length;
	for (var i = 0; i < length; i++)
		node.removeChild(node.firstChild);
}

