window.onload = generateInhoudsopgave;

function generateInhoudsopgave()
{
	var h3s = document.getElementsByTagName("h3");
	var titels = Array();
	
	for(var i = 0; i < h3s.length; i++)
	{
		h3s[i].setAttribute("id", "sub" + i);
		titels.push(h3s[i].firstChild.nodeValue);
	}
	
	if(titels.length <= 0) return;

	var inhoudsopgave = document.getElementById("inhoudsopgave");
	
	var h3 = document.createElement("h3");
	h3.appendChild(document.createTextNode("Inhoudsopgave"));
	inhoudsopgave.appendChild(h3);
	
	var ol = document.createElement("ol");
	inhoudsopgave.appendChild(ol);
	
	for(var i = 0; i < titels.length; i++)
	{
		var li = document.createElement("li");
		var a = document.createElement("a");
		a.setAttribute("href", "#sub" + i);
		a.appendChild(document.createTextNode(titels[i]));
		li.appendChild(a);
		ol.appendChild(li);
	}
}