 function rem(b) {
    var FF = b.replace("a", "gato");
	return FF;
  }
/*
 * Dynamic Table of Contents script
 * by Matt Whitlock <http://www.whitsoftdev.com/>
 */

function createLink(href, innerHTML) {
	var a = document.createElement('span');
	a.setAttribute("href", href);
	a.innerHTML = innerHTML;
	return a;
}

function createLink2(href, innerHTML) {
	var a = document.createElement('a');
	a.setAttribute("href", href);
	a.innerHTML = innerHTML;
	return a;
}

function stripHTML(cadena)
      {
          var GG = cadena.replace(/<[^>]+>/g,'');
		  return GG;
      }
	  
function generateTOC(toc, toc2) {
	var i2 = 0, i3 = 0, i4 = 0;
	toc = toc.appendChild(document.createElement("ul"));
	for (var i = 0; i < document.getElementById('aaa').childNodes.length; ++i) {
		var node = document.getElementById('aaa').childNodes[i];
		var tagName = node.nodeName.toLowerCase();
		if (tagName == "h4") {
			++i4;
			if (i4 == 1) toc.lastChild.lastChild.lastChild.appendChild(document.createElement("ul"));
			var section = i2 + "." + i3 + "." + i4;
			node.insertBefore(document.createTextNode(section + ". "), node.firstChild);
			node.id = "section" + section;
			var textoD =  stripHTML(node.innerHTML);
			toc.lastChild.lastChild.lastChild.lastChild.appendChild(document.createElement("li")).appendChild(createLink("#section" + section, textoD));
		}
		else if (tagName == "h3") {
			++i3, i4 = 0;
			if (i3 == 1) toc.lastChild.appendChild(document.createElement("ul"));
			var section = i2 + "." + i3;
			node.insertBefore(document.createTextNode(section + ". "), node.firstChild);
			node.id = "section" + section;
			var textoD =  stripHTML(node.innerHTML);
			toc.lastChild.lastChild.appendChild(document.createElement("li")).appendChild(createLink("#section" + section, textoD));
		}
		else if (tagName == "h2") {
			++i2, i3 = 0, i4 = 0;
			var section = i2;
			node.insertBefore(document.createTextNode(section + ". "), node.firstChild);
			node.id = "section" + section;
			var textoD =  stripHTML(node.innerHTML);
			toc.appendChild(h2item =document.createElement("li")).appendChild(createLink2("#section" + section, textoD));
		}
	}
}

