//When the itemLoaded Fuction is called by the onload it checks the itemCurret value.
//Set the itemCurrent=='' to the required Item Title and input the desired script.
//Add additional else checks for other Items as required.

function itemLoaded(itemCurrent)
{	
	if(itemCurrent.indexOf('Help')>-1)
	{
		indexBuild();
	}
	else if(itemCurrent.indexOf('Questions')>-1)
	{
		qBuild();
	}  
} 

var indMarStart=20;
var indMarStep=10;
var allIndexNodes=new Array();
var ind1Num=0;
var ind2Num=0;
var ind3Num=0;
var ind4Num=0;
var indLev=0;
function indexBuild()
{
  var allDivNodes=document.getElementsByTagName("div");
  for(var i = 0;i < allDivNodes.length;i++)
  {
    var divClass=allDivNodes[i].className;
    splitClass=divClass.split("index");
    if(splitClass.length>1&&splitClass[1])
    {
      allIndexNodes.push(allDivNodes[i]);
    }
  }
  for(var i = 0;i < allIndexNodes.length; i++)
  {
    var divClass=allIndexNodes[i].className;
    splitClass=divClass.split("index");
    if(splitClass.length>1&&splitClass[1])
    {
      indLev=splitClass[1];
      if(indLev==1)
      {
        ind1Num++;
        disNum=ind1Num;
				ind2Num=0;
      }
      else if(indLev==2)
      {
        ind2Num++;
        disNum=ind1Num+"."+ind2Num;
				ind3Num=0;
				ind4Num=0;
      }
      else if(indLev==3)
      {
        ind3Num++;
        disNum=ind1Num+"."+ind2Num+"."+ind3Num;
				ind4Num=0;
      }
      else if(indLev==4)
      {
        ind4Num++;
        disNum=ind1Num+"."+ind2Num+"."+ind3Num+"."+ind4Num;
      }
      if(indLev>0)
      {
        nodeVal=allIndexNodes[i].firstChild.nodeValue;
        aVal=allIndexNodes[i].id;
        indexApp(indLev,disNum,nodeVal,aVal);
      }
    }
    indLev=0;
  }
}
function indexApp(indLev,disNum,nodeVal,aVal)
{
  indNode=document.getElementById("index");
  indMar=indMarStart+indLev*indMarStep;
  newDivNode=document.createElement("div");
  newDivNode.style.marginLeft=indMar+"px";
	newDivNode.style.marginBottom="2px";
  newTextNode=document.createTextNode(disNum+". ");
  newDivNode.appendChild(newTextNode);
  newANode = document.createElement("a");
  newANode.setAttribute("href","#"+aVal);
  newTextNode = document.createTextNode(nodeVal);
  newANode.appendChild(newTextNode);
  newDivNode.appendChild(newANode);
  indNode.appendChild(newDivNode);
}
function indexWrite()
{
  window.document.write("<p class='smallcenter'><a href='#index'>Index</a></p>");
}


function qBuild()
{
  var qNum=0;
	
	var allDivNodes=document.getElementsByTagName("div");
	var qsNode=document.getElementById("qs");
	var addDivNode=document.createElement("div");
  var divNum=allDivNodes.length;
	for(var i = 0;i < divNum;i++)
  {
		  if(allDivNodes[i].className=="q")
      {
      qNum++;
			allDivNodes[i].id=qNum;
			
			tVal=allDivNodes[i].firstChild.nodeValue;
      aVal=allDivNodes[i].id;
			 
			var newDivNode=document.createElement("div");
      newDivNode.style.marginLeft="20px";
	    newDivNode.style.marginBottom="2px";
      var newTextNode=document.createTextNode(qNum+". ");
      newDivNode.appendChild(newTextNode);
      var newANode = document.createElement("a");
      newANode.setAttribute("href","#"+aVal);
      newTextNode = document.createTextNode(tVal);
      newANode.appendChild(newTextNode);
      newDivNode.appendChild(newANode);
			addDivNode.appendChild(newDivNode);
	  }	
	}
	qsNode.appendChild(addDivNode);
}

function topWrite()
{
  window.document.write("<p class='smallcenter'><a href='#top'>Top of Page</a></p>");
}

function compGth(indSt,indPer)
{
 var curDate = new Date(); 
 var curMs = Date.parse(curDate);
 var fromMs = Date.parse("1 Jan, 1995");
 
 var difMs=curMs-fromMs;
 var difDays=difMs/1000/60/60/24;
 var difYears=difDays/365;
 var indCur=indSt*Math.pow((1+(indPer/100)),difYears);
 indCur=Math.round(indCur);
 window.document.write(indCur);
}
function todayIs()
{
 var d=new Date();
 dayYearIs=d.toString().slice(0,10)+" "+d.getFullYear();
 window.document.write(dayYearIs);
}
function compForm()
{
  window.document.write('<form>If the Index was <input type="text" style="size:6;width:50px;text-align: right;" id="indSt" value="4000" onchange="javascript:formInd()"/> at Jan 1 <input type="text" style="size:6;width:50px;text-align: right;" id="indAt" value="1995" onchange="javascript:formInd()"/> with <input type="text" style="size:4;width:30px;text-align: right;" id="indPer" value="6.0" onchange="javascript:formInd()"/> % compound earnings growth today <b>');
  todayIs();
  window.document.write('</b> it would be <b><span id="indNow"></span></b>.</form>');
	formInd();
}
function formInd()
{
 	var indSt=document.getElementById('indSt').value;
	var indAt="1 Jan "+document.getElementById('indAt').value;
	var indPer=document.getElementById('indPer').value;
	
	var curDate = new Date(); 
  var curMs = Date.parse(curDate);
  var fromMs = Date.parse(indAt);
  var difMs=curMs-fromMs;
  var difDays=difMs/1000/60/60/24;
  var difYears=difDays/365;
  var indCur=indSt*Math.pow((1+(indPer/100)),difYears);
  indCur=Math.round(indCur);
	
	if(document.getElementById('indNow').firstChild)
	{
	  var removeNode=document.getElementById('indNow').firstChild;
    removeNode.parentNode.removeChild(removeNode);
	}
	
	newTextNode = document.createTextNode(indCur);
  document.getElementById('indNow').appendChild(newTextNode);
	
}