/* 
 * domTab 
 * version 2.2
 * written by Chris Heilmann
 * more info: http://www.onlinetools.org/tools/domtab.php
*/

// Global variables
var currentTab,currentLink;

// Change if you want to use another class for highlighting
var tabHighlightClass='tabon'; 

function initTabs()
{
// change if you have another main navigation ids for tabbed or normal element id
	var navElement='mainnav';
	var navElementTabbedId='mainnavtabbed';
	
// pattern to check against to identify "back to menu" links
	var backToMenu=/#top/;

	var n,as,id,i,cid,linklength,lastlink,re;
	if(document.getElementById && document.createTextNode)
	{
		cid=window.location.toString().match(/#(\w.+)/);
		if (cid && cid[1])
		{
			cid=cid[1];
		}
		var n=document.getElementById(navElement);
		n.id=navElementTabbedId;
		n=document.getElementById(navElementTabbedId)
		var as=n.getElementsByTagName('a');
		for (i=0;i<as.length;i++)
		{
			as[i].onclick=function(){showTab(this);return false}
			//as[i].onkeypress=function(){showTab(this);return false}
			id=as[i].href.match(/#(\w.+)/)[1];
			if(!cid && i==0)
			{
				currentTab=id;
				currentLink=as[i];
			} else if(id==cid)
			{
				currentTab=id;
				currentLink=as[i];
			}
			if(document.getElementById(id))
			{
				linklength=document.getElementById(id).getElementsByTagName('a').length;
				if(linklength>0)
				{
					lastlink=document.getElementById(id).getElementsByTagName('a')[linklength-1]
					if(backToMenu.test(lastlink.href))
					{
						lastlink.parentNode.removeChild(lastlink);
					}
				}
				document.getElementById(id).style.display='none';
			}
			if(cid){window.location.hash='top';}
		}		


		if(document.getElementById(currentTab))
		{
			document.getElementById(currentTab).style.display='block';
		}
		re=new RegExp('\\b'+tabHighlightClass+'\\b');
		if(!re.test(currentLink.className))
		{
			currentLink.className=currentLink.className+' '+tabHighlightClass
		}
	}
}  
function showTab(o)
{
	var id;
	if(currentTab)
	{
		if(document.getElementById(currentTab))
		{
			document.getElementById(currentTab).style.display='none';
		}
		currentLink.className=currentLink.className.replace(tabHighlightClass,'')
	}
	var id=o.href.match(/#(\w.+)/)[1];
	currentTab=id;
	currentLink=o;
	if(document.getElementById(id))
	{
		document.getElementById(id).style.display='block';
	}
	var re=new RegExp('\\b'+tabHighlightClass+'\\b');
	if(!re.test(o.className))
	{
		o.className=o.className+' '+tabHighlightClass
	}
}


/* 
 * SafeOnload 
 * more info: http://javascript.about.com/library/scripts/blsafeonload.htm
*/
// Browser Detection
isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

// Body onload utility (supports multiple onload functions)
var gSafeOnload = new Array();
	function SafeAddOnload(f)
	{
		if (IEmac && IE4)  // IE 4.5 blows out on testing window.onload
		{
			window.onload = SafeOnload;
			gSafeOnload[gSafeOnload.length] = f;
		}
		else if  (window.onload)
		{
			if (window.onload != SafeOnload)
			{
				gSafeOnload[0] = window.onload;
				window.onload = SafeOnload;
			}		
			gSafeOnload[gSafeOnload.length] = f;
		}
		else
			window.onload = f;
	}
	function SafeOnload()
	{
		for (var i=0;i<gSafeOnload.length;i++)
			gSafeOnload[i]();
	}

// Call the following with your function as the argument
SafeAddOnload(initTabs);
SafeAddOnload(initDHTMLAPI);
SafeAddOnload(initMapDHTML);
SafeAddOnload(initMap);
