if (window.addEventListener || window.attachEvent){
	document.write('<style type="text/css">\n')
	document.write('.dropcontent{display:none;}\n')
	document.write('</style>\n')
}

/*---- CapeSoft version modified 11 August 2005 ----*/
// This version has been modified to be specific to CapeSoft's requirements
// and reformatted to be more easily editable.

// Original Content Tabs script - By JavaScriptKit.com (http://www.javascriptkit.com)
// Last updated: July 25th, '05, licensed under the GPL.

/*--------------------------------------------------*/
var initialTab = 1						// tab to select at the start
var showrecords = 1 					// specify number of contents to show per tab
var tabhighlightcolor = "white" 		// specify tab color when selected
var taboriginalcolor = "#DDDDDD" 		// specify default tab color. Should echo your CSS file definition.

document.getElementsByClass = function(tag, classname)
{
	var tagcollect = document.all? document.all.tags(tag): document.getElementsByTagName(tag) //IE5 workaround
	var filteredcollect = new Array()
	var inc = 0
	for (i=0; i<tagcollect.length; i++)
	{
		if (tagcollect[i].className == classname)
			filteredcollect[inc++] = tagcollect[i]
	}
	return filteredcollect
}


function contractall(){
	var inc=0
	while (contentcollect[inc]) 
	{
		contentcollect[inc].style.display = "none"
		inc++
	}
}

function expandone(whichpage)
{
	var lowerbound = (whichpage-1)*showrecords
	var upperbound = (tabstocreate == whichpage) ? contentcollect.length-1 : lowerbound+showrecords-1
	contractall()

	for (i = lowerbound; i <= upperbound; i++)
		contentcollect[i].style.display = "block"
}

function highlightone(whichtab)
{
	for (i=0;i<tabscollect.length;i++)
	{
		tabscollect[i].style.backgroundColor = taboriginalcolor
		tabscollect[i].style.borderRightColor = "white"
		tabsfootcollect[i].style.backgroundColor = "white"
	}
	
	tabscollect[whichtab].style.backgroundColor = tabhighlightcolor
	tabscollect[whichtab].style.borderRightColor = "gray"
	tabsfootcollect[whichtab].style.backgroundColor = "#E8E8E8"
}

function generatetab()
{
    // load the cookie and check if the search tab should be selected instead of the contents tab
    var cookies = document.cookie;   
    
    var p = cookies.indexOf("search=");  
    if (p != -1) 
    {
        var start = p + 7;
        var end = cookies.indexOf(";", start);     
        if (end == -1)
            end = cookies.length;

        var isSearch = cookies.substring(start, end);
        isSearch = unescape(isSearch);
        
        if (isSearch == "1")
            initialTab = 2;            
    }    
    // reset to default, so when the page loads the Contents tab is default
    // when the page loads from a search the the Search tab is selected
    document.cookie = "search=0";      
   
    contentcollect = document.getElementsByClass("div", "dropcontent")
	tabstocreate = Math.ceil(contentcollect.length/showrecords)
	linkshtml = ""
	linkshtml2 = ""
	
	for (i=1; i<=tabstocreate; i++)
	{
		if (i == 1)
			linkshtml += '<span class="tabstyle" onClick="expandone('+i+');highlightone('+(i-1)+')"><b>Contents</b></span>'
		else if (i == 2)
			linkshtml += '<span class="tabstyle" onClick="expandone('+i+');highlightone('+(i-1)+')"><b>Search</b></span>'
		else
			linkshtml += '<span class="tabstyle" onClick="expandone('+i+');highlightone('+(i-1)+')"><b>Page '+i+'</b></span>'

		//linkshtml2+='<a href="#" class="tabsfootstyle" onClick="expandone('+i+');highlightone('+(i-1)+');return false">Page '+i+'</a> '
		// the same as above but without the actual link, i.e. the footer is invisible.
		linkshtml2 += '<a href="#" class="tabsfootstyle" onClick="expandone('+i+');highlightone('+(i-1)+');return false"></a> '
	}
	
	document.getElementById("cyclelinks").innerHTML=linkshtml
	document.getElementById("cyclelinks2").innerHTML=linkshtml2
	
	tabscollect = document.getElementsByClass("span", "tabstyle")
	tabsfootcollect = document.getElementsByClass("a", "tabsfootstyle")
	highlightone(initialTab-1)
	expandone(initialTab)
}

if (window.addEventListener)
	window.addEventListener("load", generatetab, false)
else if (window.attachEvent)
	window.attachEvent("onload", generatetab)