/*	Script to break a single page into sections,
	will not work in NS or IE<4

	by David Boultbee
	david@gtwebmarque.com
	
	(c)2002 GT webMarque Ltd
	http://www.gtwebmarque.com		*/

function fCreateList(oForm)
{	if (isNS()) return; //NS can't recognise sections
	if ((!document.all.region)||(!document.all.region.length)||(document.all.region.length<=1))return; //the document is not broken down
	
	oForm.innerHTML+='Select an area: ';  //add a caption
	var oList=document.createElement('<select name="oRegionSelect" style="width:200px" onchange="fShowSection(this.selectedIndex);this.scrollIntoView(true)">');  //create the list box
	var oHR=document.createElement('<HR>');
    oForm.appendChild(oList);
    oForm.appendChild(oHR);
	fFillSelection(oList);
	fShowSection(0);
	oList.scrollIntoView(true);
}

function fFillSelection(oList)
{	if (isNS()) return;
	var aLinks=new Array();
	var aLinks=document.all.region; //all the markers
	for (var i=0;i<aLinks.length;i++)
	{	with (oList)
		{	if (aLinks[i].name=='end') continue;  //this marks the end of all the sections, don't include it in the list
			options[i]=new Option(aLinks[i].name); //create an option
			options[i].value=aLinks[i].name; //give it a name
}	}	}

function fShowSection(iSectionNumber)
{	var oLink1=document.all.region[iSectionNumber];
	var oLink2=document.all.region[iSectionNumber+1];
	var iLow=fCalcTop(oLink1);
	var iHigh=fCalcTop(oLink2);
	var iDifference=iHigh-iLow;
	oDiv.style.height=iDifference;
	oLink1.scrollIntoView(true);
}

function fShowDivision(oList)
{	var iSectionNumber=oList.selectedIndex;
	for (var i=0; i<oList.aDivisions.length; i++)
    {	with (oList.aDivisions[i])
    		if (i==iSectionNumber) style.setAttribute('display','inline');
        	else style.setAttribute('display','none');	
}	}

function fShowAll()
{	for (var i=0; i<oList.aDivisions.length; i++)
		style.setAttribute('display','inline');
}

function fCreateList()
{	var oTable=document.createElement('<table id=gtwp_division_table>');
	var oCell=oTable.insertRow(-1).insertCell(-1);
    var oList=document.createElement('<select id=gtwp_division_list onclick="fShowDivision(this)">');
    //oList.options[oList.options.length]=new Option('Show All');
    //oList.options[oList.options.length]=new Option('');
    oCell.appendChild(oList);
    return oTable;
}

function fParentBlockElement(oElement)
{		var oPE=oElement;																		 	 			 								// initiate with the current tag
		while (oPE.parentElement.currentStyle.display!='block')											// until its parent a block element
					oPE=oPE.parentElement;																								// move to the next parent element	
		return oPE.parentElement;																										// return the parent of the current tag.  Note that this is correct;
					 																																			// oPE points to the current element eg that passed but its *parent* is examined
																																								// therefore its parent must be returned
}

function fMarkSplits(sTagName, oContainer)								 			 								// mark up the tags which are direct descendants of the container
{		var iNoTags=0;						 																									// this to avoid incorrect splits eg. inside tables, lists etc
		for (var i=0; i<oContainer.all.tags(sTagName).length; i++)									// for each tag
		{		if (fParentBlockElement(oContainer.all.tags(sTagName)[i])==oContainer)	// if its parent block element is the container...
				{	 oContainer.all.tags(sTagName)[i].id='gtwp_division_tag';							// ... mark it up as one on which to split
					 iNoTags++;																														// ... and count how many there are
		}		}
		return iNoTags;																															// return the number of tags created
}

function fSpanByHeading(sTagName, oContainer)
{ 	if (fNavVersion<4) return false;
		if ((!oContainer.all.tags(sTagName))||(oContainer.all.tags(sTagName).length<2)) return false;  // if nothing to split on or if only one split would exist, return  
		if (fMarkSplits(sTagName,oContainer)<2) return false;												// mark up the splits, if there are less than 2, quit for reasons above
		
		var oP=oContainer.all.tags(sTagName)[0].insertAdjacentElement('beforeBegin',document.createElement('<P>'));
    var oContainerTable=oP.insertAdjacentElement('beforeEnd',fCreateList()); 		//create the drop down list 
    var oList=oContainerTable.rows[0].cells[0].children[0];
    var i=0;
    
    while (oContainer.all[i].id!='gtwp_division_tag') i++;			 									 		// skip to the first tag to split on
    
    while (i<oContainer.all.length)
    {		oList.options[oList.options.length]= new Option(oContainer.all[i].innerText);  			// add an option to the list based on the content of the tag
        i++;																																		// adding the option adds an element above the tag which we were on.  i therefore points to the new element.  Increment i to point to the original element
        var oSpanObj=document.createElement('<SPAN id=gtwp_division style="display:none">');  	// create a span to copy all of the content into      	
        oSpan=oContainer.all[i].insertAdjacentElement('beforeBegin',oSpanObj);	// insert the span into the page above the current element
        i++;																																		// see previous i++ comment
         		
        do																							 		 										// copy in all the content
    		{		if (!oSpan.contains(oContainer.all[i]))															// Although the position of the object has changed in the heirachy, its reference has not.  When parsing through nodes, this can cause child objects to be moved, then moved again to after the parent node.  
    					 oSpan.insertAdjacentElement('beforeEnd',oContainer.all[i]);			// therefore don't copy the object if its already inside the SPAN. The insertAdjacentElement function moves an element if it already exists within a page
    				i++;																																// move to the next element
    		}				
    		while ((i<oContainer.all.length)&&(oContainer.all[i].id!='gtwp_division_tag'))// copy up to the next tag to split on
    }
    oList.aDivisions=oContainer.all.gtwp_division;
    oContainer.all.gtwp_division[0].style.setAttribute('display','inline');			// show the fisrt division
}

register('divider.js v.1903041046');
