/* 
	this chunk of code checks for other onload functions established in the <body> tag
	it then appends our startup function (pageInit) to the list.
*/
if (typeof window.onload == 'function'){
	prevFunction = window.onload;
	window.onload = function (){
		prevFunction();
		pageInit();
	}
}else{
	window.onload = pageInit;
}



/*
this function runs automatically on load for any pages that call global.js
*/
function pageInit(){
	if (document.getElementById) {	//if this is a DOM supporting Browser
		if (document.getElementById("pageCategories")){	//If it has a 'pageCategories' List
			//init the tabs, hide the divs
			tabTarget = 'tab1';
			url = window.location;
			anchorRegex = /^.*#(.*)$/;
			match = anchorRegex.exec(url);
			if(match != null && match.length > 1)	{
				anchorRef = match[1];
				if(document.getElementById('tab-'+anchorRef)){
					tabTarget = anchorRef;
				}
			}
			tabClick(tabTarget,document.getElementById('tab-'+tabTarget).getElementsByTagName("a")[0]);
			/*for non-tab1 values the screen will usually scroll to the bottom of the page. Let's avoid that.*/
			window.scroll(0,0);
		}
		
		/* Put any other functions you want to load on DOM supporting browsers here */
	}
	
	/* Put any other functions you want to run on all browsers here */
}



/*
This function sets a div visible, and highlights that tab.
It is designed to fail on browsers that don't support the DOM.
If the browser doesn't support the DOM all the divs will be 
Listed down the page, and the tabs will link to anchors within each one.
*/
function tabClick(tName,oCaller){
	if (document.getElementById){	//don't run this if it's not a newer browser
		aDivs = document.getElementsByTagName("DIV");
		for(var i=0; i<aDivs.length; i++){
			if (aDivs[i].className == 'dynDisplay'){	//only operate on our dyndisplay divs
				if (aDivs[i].style.display != 'none'){
					aDivs[i].style.display = 'none';
				}
			}
		}//end for
		document.getElementById(tName).style.display = "block";

		if (oCaller){	//caller will be null if this is an init run.
			aLi = document.getElementsByTagName("LI");
			for(var i=0; i<aLi.length; i++){
				if (aLi[i].className == 'activeCategory'){	//only operate on our active tab
					aLi[i].className = '';
				}
			}//end for
			oCaller.parentNode.className = 'activeCategory';
		}
		
		return false;	//turn off our backup function using anchors
	}else{
		return true;	//return true, so the link will run and the anchor will run.
	}
}

function doProductJump(theSelectTag){

	var theNewLocation = theSelectTag.options[theSelectTag.selectedIndex].value;
	if (theNewLocation != ""){
		window.location = theNewLocation;
	}
}
