/*
/*
  Code heavily modified by Zedcore Systems but based on script from
  From http://javascriptkit.com  (a site of free javascripts)
 */

if (window.addEventListener || window.attachEvent){
	document.write('<style type="text/css">\n');
	document.write('.tabcontent{display:none;}\n');
	document.write('</style>\n');
}


/*
var tabcollection= new Array; should probably generated elsewhere, see tabbedjs.php
*/

var linkshtml = new Array;
var linkshtml2 = new Array;
var tabscollect = new Array;
var tabsfootcollect = new Array;

function getElementsByClass(tag, classname, substring)
{
	var tagcollect=document.all? document.all.tags(tag): document.getElementsByTagName(tag); //IE5 workaround
	var filteredcollect=new Array();
	var inc=0;
	var srchlen=classname.length + 1;
	for (i=0;i<tagcollect.length;i++){
		if (tagcollect[i].className==classname)
		filteredcollect[inc++]=tagcollect[i];
		else if (substring && tagcollect[i].className.substr(0,srchlen)==classname+'_')
		filteredcollect[inc++]=tagcollect[i];
	}
	return filteredcollect;
}

function expandone(whichpage,prefix){
	var inc=1; 
	var agt=navigator.userAgent.toLowerCase();
	for (tab in tabcollection[prefix])
	{
		if (tab != 'extend' && junk != 'bind' && junk != 'bindAsEventListener')
		{
			for (element in tabcollection[prefix][tab]["elements"] )
			{
				if (IsNumeric(element))
				{	
					if(inc==whichpage)
					{
						if(tabcollection[prefix][tab]["tagsearchtype"]=='tr')
						{
							if(navigator.appName.indexOf("Microsoft") != -1)
							{
								if(agt.indexOf("opera") != -1)
								{
									tabcollection[prefix][tab]["elements"][element].style.display="table-row";
								} else {
									tabcollection[prefix][tab]["elements"][element].style.display="block";
								}
							} else {
								tabcollection[prefix][tab]["elements"][element].style.display="table-row";
							}
						} else {
							tabcollection[prefix][tab]["elements"][element].style.display="block";
						}
					} else {
						tabcollection[prefix][tab]["elements"][element].style.display="none";
					}
				}	
			}
			inc++;
		}	
	}
}
function highlightone(whichtab,prefix)
{
	var tabscollectsize=0;
	
	var inc=0;
	var currenttab=0;
	for(junk in tabscollect[prefix])
	{
		if (junk != 'extend' && junk != 'bind' && junk != 'bindAsEventListener')
		{
			tabscollectsize++;
		}	
	}
	for(tab in tabcollection[prefix])
	{
		if (tab != 'extend' && junk != 'bind' && junk != 'bindAsEventListener')
		{
			if(inc==whichtab)
				currenttab=tab;
			inc++;
		}	
	}
	for (i=0;i<tabscollectsize;i++)
	{
		if (tabcollection[prefix][tabkeys[prefix][i]] != undefined && tabcollection[prefix][ tabkeys[prefix][i] ]["headclass"] != undefined)
		{
			tabscollect[prefix][i].className=tabcollection[prefix][ tabkeys[prefix][i] ]["headclass"];
		}
		
		if (tabcollection[prefix][tabkeys[prefix][i]] != undefined && tabcollection[prefix][ tabkeys[prefix][i] ]["footclass"] != undefined)
		{
			tabsfootcollect[prefix][i].className=tabcollection[prefix][ tabkeys[prefix][i] ]["footclass"];
		}	
	}
	
	if (tabcollection[prefix][currenttab]["headhighlightedclass"] != undefined)
	{
		tabscollect[prefix][whichtab].className=tabcollection[prefix][currenttab]["headhighlightedclass"];
	}
	
	if (tabcollection[prefix][currenttab]["foothighlightedclass"] != undefined)
	{
		tabsfootcollect[prefix][whichtab].className=tabcollection[prefix][currenttab]["foothighlightedclass"];
	}
}
function generatetab()
{
	for(prefix in tabcollection)
	{
		numberoftabs=0;
		for (tab in tabcollection[prefix])
		{
			if (tabcollection[prefix][tab] != undefined && tabcollection[prefix][tab]["tagsearchtype"] != undefined)
			{
				tabcollection[prefix][tab]["elements"]=getElementsByClass(tabcollection[prefix][tab]["tagsearchtype"], tab,true);	
				numberoftabs++;
			
			}	
		}
		linkshtml="";
		linkshtml2="";
		var i=1;
		for (tab in tabcollection[prefix])
		{
			if (tabcollection[prefix][tab] != undefined && tabcollection[prefix][tab]["name"] != undefined)
			{
				if (tabcollection[prefix][tab]['headclass'] != undefined)
				{
					linkshtml+='<span class="'+prefix+'_tabstyle" onClick="expandone('+i+',\''+prefix+'\');highlightone('+(i-1)+',\''+prefix+'\')">'+tabcollection[prefix][tab]["name"]+'</span>';
				}
				
				if (tabcollection[prefix][tab]['footclass'] != undefined)
				{
					linkshtml2+='<span class="'+prefix+'_tabsfootstyle" onClick="expandone('+i+',\''+prefix+'\');highlightone('+(i-1)+',\''+prefix+'\')">'+tabcollection[prefix][tab]["name"]+'</span>';
				}
				i++;
			}	
		}
		
		if(document.getElementById(prefix+"_TopTabLinks")!=null)
		{
			document.getElementById(prefix+"_TopTabLinks").innerHTML=linkshtml;
			tabscollect[prefix]=getElementsByClass("span", prefix+"_tabstyle", false);
		}
		if(document.getElementById(prefix+"_BottomTabLinks")!=null)
		{
			document.getElementById(prefix+"_BottomTabLinks").innerHTML=linkshtml2;
			tabsfootcollect[prefix]=getElementsByClass("span", prefix+"_tabsfootstyle", false);
		}
		highlightone(0,prefix);
		expandone(1,prefix);
	}
}
