
/* - toc.js - */
// http://www.tvceara.ce.gov.br/portal_javascripts/toc.js?original=1
function walkHeaders(node,func,data){if(!node){return false}
var valid=Array("h1","h2","h3","h4");if(node.hasChildNodes){var child=node.firstChild;while(child){walkHeaders(child,func,data);child=child.nextSibling}
var type=node.tagName;if(type){type=type.toLowerCase();for(var k=0;k<valid.length;k++){if(valid[k]==type){func(node,data);break}}}}}
function locationWithoutHash(){var loc=window.location.href;var hash=window.location.hash;if(!hash){return loc} else{return loc.substring(0,loc.lastIndexOf(hash))}}
function createTableOfContents(){var toc=cssQuery('dl.toc');if(toc.length==0){return}
toc=toc[0];var dest=cssQuery('dl.toc dd.portletItem');if(dest.length==0){return}
dest=dest[0];if(dest.hasChildNodes()){while(dest.childNodes.length>=1){dest.removeChild(dest.firstChild)}}
var content=getContentArea();if(!content){return}
var location=locationWithoutHash();var ols=[];var i=0;var func=function(node,data){if(hasClassName(node,"documentFirstHeading"))
return;var li=document.createElement('li');var link=document.createElement('a');link.appendChild(document.createTextNode(getInnerTextFast(node)));link.href=location+'#section-'+i;li.appendChild(link);var anchor=document.createElement('a');anchor.name='section-'+i;node.parentNode.insertBefore(anchor,node);var level=node.nodeName.substring(1)-1;while(ols.length<level){var ol=document.createElement('ol');if(ols.length>0){if(!ols[ols.length-1].lastChild){ols[ols.length-1].appendChild(document.createElement('li'))}
ols[ols.length-1].lastChild.appendChild(ol)}
ols.push(ol)}
while(ols.length>level){ols.pop()}
ols[ols.length-1].appendChild(li);i++}
walkHeaders(content,func);if(ols.length>0){toc.style.display="block";dest.appendChild(ols[0])}}
registerPloneFunction(createTableOfContents);
