
//21:12 9/19/2007 don't need to wait for all elements to finish downloading;
//window.onload=function(){_table_of_content();};

_table_of_content();

function _table_of_content()
{
	var xTd1=document.getElementById('ID_Td1'), xTd2=document.getElementById('ID_Td2');
	xTd1.style.border='0'; xTd2.style.border='0';

	xTd2.setAttribute('width', '25%');
	xTd1.style.paddingRight='1em';

	var xOutline=document.createElement('div'); xTd2.appendChild(xOutline);

	xOutline.style.border='2px dotted gray';
	xOutline.style.padding='0 1em 2em 1em';

	var xHead=document.createElement('h2'); xHead.innerHTML='Table of Contents';
	xOutline.appendChild(xHead);

	var vH2=_get_child_nodes(xTd1, 'h2');
	for(var j=0; j<vH2.length; ++j){
		var xH2=vH2[j];

		var xFollow=xH2, sTag;
		do{
			xFollow=xFollow.nextSibling;
			sTag=xFollow ? xFollow.nodeName.toLowerCase() : '';
		}while(sTag!='div' && sTag!='ul' && sTag!='ol');

		var sAnchor=xH2.id; if(!sAnchor){sAnchor='H2_'+Math.round(Math.random()*10000); xH2.id=sAnchor;}

		if(!xFollow) alert('Invalid page structure');

		var xLink=document.createElement('div'); xLink.style.marginBottom='0.5em';
		var xHref=document.createElement('a'); xHref.innerHTML=xH2.innerHTML; //xH2 shouldn't contain child elements;
		xHref.setAttribute('href', '#'+sAnchor);
		xLink.appendChild(xHref); xOutline.appendChild(xLink);

		var vH3=_get_child_nodes(xFollow, 'h3');
		if(vH3.length>0){
			var xUl=document.createElement('ul'); xOutline.appendChild(xUl);
			for(var i=0; i<vH3.length; i++){
				var xH3=vH3[i], sAnchor=xH3.id; if(!sAnchor){sAnchor='H3_'+Math.round(Math.random()*10000); xH3.id=sAnchor;}
				var xSub=document.createElement('li'); xUl.appendChild(xSub);

				xSub.innerHTML='<a href="#'+sAnchor+'">'+xH3.innerHTML+'</a>';
				xSub.style.marginBottom='0.6em'

				//xH3.setAttribute('style', 'background-color: #eeeeee;');
			}
		}
		
	}

}

function _get_child_nodes(xElm, sTag)
{
	var vRes=[]; sTag=sTag.toLowerCase();
	var vChildren=xElm.childNodes;
	for(var i=0; i<vChildren.length; ++i){
		var xChild=vChildren[i];
		if(xChild.nodeName.toLowerCase()==sTag || !sTag){
			vRes[vRes.length]=xChild;
		}
		vRes=vRes.concat(_get_child_nodes(xChild, sTag));
	}
	return vRes;
}

