function addLoadEvent (func) {
				var oldonload = window.onload;
				if (typeof window.onload != 'function') {
					window.onload = func;
				} else {
					window.onload = function() {
						oldonload();
						func();
					}
				}
		}
		
		
function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement,targetElement.nextSibling);
	}
}

			
		function setupETFGrid() {
				var browserCheck = browserTest();
				if (browserCheck == "Safari") return false;
			if (!document.getElementsByTagName) return false;
			if (!document.getElementById) return false;
			if (!document.getElementById("etfgridbox")) return false;
			if (!document.createAttribute("onclick")) return false;
			
			var gridbox = document.getElementById("etfgridbox");
			
			// Turning on the tabs 
			var arrUL = gridbox.getElementsByTagName("ul");	
			arrUL[0].style.display="block";
			
			// Turning off the captions 
			var arrCaption = gridbox.getElementsByTagName("caption");	
			for (var i=0; i < arrCaption.length; i++) 
			{
				arrCaption[i].setAttribute("class","hiddenbox");
				arrCaption[i].className = "hiddenbox"; // forced concession for IE6
			}
			
			// Setting onClick attributes on the Tab links 
			var arrLI = gridbox.getElementsByTagName("li");
			var arrLinks = arrUL[0].getElementsByTagName("a");
			
			for (var i=0; i < arrLinks.length; i++) 
			{
				var sClickFunc = document.createAttribute("onclick");
				sClickFunc.value = "displayTab('"+ arrLI[i].className + "');"
				arrLinks[i].setAttributeNode(sClickFunc);
				arrLinks[i].href = "javascript:"+sClickFunc.value; // forced concession for IE6
			}

			// Setting the default view to Gainers
			displayTab("Gain");
		}

		function displayTab(visible) {
			//Adding strings to the variable that will display the corrent hightlighted tab and box.
			var sVisibleTab = visible + "grid";
			var sVisibleBox = "divHave" + visible + "Data";
			
			// Setting the class on the UL for the stylesheet to mark as the active tab.
			var gridbox = document.getElementById("etfgridbox");	
			var arrUL = gridbox.getElementsByTagName("ul"); 
			arrUL[0].className = sVisibleTab;
			
			// Setting the class on all DIVs to hidden, then resetting the proper DIV to visible
			var gridbox = document.getElementById("etfgridbox");	
			var arrDIV = gridbox.getElementsByTagName("div"); 

			for (i=0; i < arrDIV.length; i++) 
				{
					if(arrDIV[i].id != ("divHaveData" || "divNoData"))
					{
						arrDIV[i].className = "hiddenbox";
					}
				}
				
			var highlightDIV = document.getElementById(sVisibleBox);
			highlightDIV.setAttribute("class","visiblebox");
			highlightDIV.className = "visiblebox";
			
			}


// CHECK DOCTYPE
// If the page has a DOCTYPE, make the appropriate changes.
function checkDocType() {
	// Provide outs for browsers that don't get it.
	if (!document.compatMode) return false;
	
	// Find the doctype.
	var doctypeTag = document.compatMode;
	return doctypeTag;
}

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;
	
function browserTest() {
	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if (checkIt('safari')) browser = "Safari"
	else if (checkIt('omniweb')) browser = "OmniWeb"
	else if (checkIt('opera')) browser = "Opera"
	else if (checkIt('webtv')) browser = "WebTV";
	else if (checkIt('icab')) browser = "iCab"
	else if (checkIt('msie')) browser = "Internet Explorer"
	else if (!checkIt('compatible'))
	{
		browser = "Netscape Navigator"
		version = detect.charAt(8);
	}
	else browser = "An unknown browser";

	if (!version) version = detect.charAt(place + thestring.length);

	if (!OS)
	{
		if (checkIt('linux')) OS = "Linux";
		else if (checkIt('x11')) OS = "Unix";
		else if (checkIt('mac')) OS = "Mac"
		else if (checkIt('win')) OS = "Windows"
		else OS = "an unknown operating system";
	return browser;
	}
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

// Run setupETFGrid on page load
addLoadEvent(setupETFGrid);
	
	