// Collection of scripts for Left Nav of Core Template
// by Eric Shepherd
// October, 2005

/*
function trackLinks() 
// handles the calling of trackInterstitial()
// if a link has a "track" attribute, we get its value
//then we assume the parameter is 'Section' unless otherwise specified by a 'param' attribute on the link
//finally we look in the meta tags for the page type identity, like 'homepage'
//then we call trackInterstitial with the supplied information
	Revision History
		12/28/06	TCW	Added the ability to set the type parameter for the trackInterstitial() method using the 
						elements "trackType" parameter if existing for the purpose of overriding this value
						as by nature it will be one value for the entire page.
		1/31/07		EBS		This function is obsolete, as the tracking call and events are being handled by the 
						two individual webtrends scripts.

{ 
	if (this.getAttribute('track')) {
		var trackName = this.getAttribute('track');
		var theParam = (this.getAttribute('param')) ? this.getAttribute('param') : 'Section';
		var metas = document.getElementsByTagName('meta');
		var theType = null;
		
		if (metas.length > 0) {
			for (i=0; i<metas.length; i++) {
				if (metas[i].getAttribute('name') != null) {
					if (metas[i].getAttribute('name').match(/wttype/gi)) {
						theType = metas[i].getAttribute('content');
					}
				}
			}
		}
		
		if (this.getAttribute('trackType') != null) {
			theType = this.getAttribute('trackType');
		}
		
		// Object detection to determine whether we have new or old tracking script available
		if (typeof WT == 'function') {
			document.wt.trackInterstitial(theType, theParam, trackName);
		} else if (typeof TrackInterstitial == 'function') {
			TrackInterstitial(theType, theParam, trackName);	
		}
	}
}		
*/		
		
function ieNavHovers() 
// this initializes and sets the event listeners for the top-level flyouts for IE only
// the function cycles through the <li>s, checks for the classname of category_li
// and assigns mouseover and mouseout events to the matching <li>s
{
	theNav = document.getElementById('left_nav');
	theLis = theNav.getElementsByTagName('li');
	for (i=0; i<theLis.length; i++) {
		if (theLis[i].className.match(/category_li/g)) {
			EventHelper.AddEvent(theLis[i], 'mouseover', iePopOut, false);
			EventHelper.AddEvent(theLis[i], 'mouseout', iePopIn, false);
		}
	}
}

function iePopOut()
// this handles the mouseover event on the flyout menus for IE by setting a CSS class of 'on' to the <li> item
// it also sets the class of 'firstchild' on the first <li> item of the flyout <ul>, which allows the top border 
// to be written to the flyout box despite IE's lack of support for the :first-child pseudo-class
{
	if(this.className.match('do_flyout')) this.className += ' on';
	if (this.getElementsByTagName('ul').length > 0) {
		var theChild = this.getElementsByTagName('ul')[0].childNodes[0];
		theChild.className += ' firstchild';
	}
}

function iePopIn()
// this handles the mouseout event from the flyout menus for IE by replacing the CSS 'on' class with null
// it also cancels the class of 'firstchild' on the first <li> item in the flyout menu
{
	if(this.className.match('do_flyout')) this.className = this.className.replace(' on', '');
	if (this.getElementsByTagName('ul').length > 0) {
		var theChild = this.getElementsByTagName('ul')[0].childNodes[0];
		theChild.className = theChild.className.replace(' firstchild', '');
	}
}
		
function openAdv(e) {
	window.open('/'+sSite+'/adv.asp', 'adv', 'width=200,height=6,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no');
	EventHelper.CancelDefault(e);
}
			
function searchFocus() {
	document.getElementById('keyword_box').value = "";
}

function searchSubmit() {
	keywordValue(sSite);
}


function switchActive() {
	theNav = document.getElementById('left_nav');
	theLis = theNav.getElementsByTagName('li');
	for (i=0; i<theLis.length; i++) {
		if (theLis[i].className.match(/category_li/g)) {
			if (theLis[i].className.match(/no_flyout/g)) {
				theLis[i].className = theLis[i].className.replace('no_flyout', 'do_flyout');
			} else {
				theLis[i].className = theLis[i].className.replace('do_flyout', 'no_flyout');
			}
		}
	}
}


function addNavListeners() {
	var adv = document.getElementById('advertisement');
	var keywords = document.getElementById('keyword_box');
	var keywordsearch = document.getElementById('keywordsearch');
	
	var theLinks = document.getElementsByTagName('a');
	
	for (i=0; i<theLinks.length; i++) { // add listeners to all links on page for tracking purposes
	//	if (theLinks[i].getAttribute('track')) EventHelper.AddEvent(theLinks[i], 'click', trackLinks, false);
	}
	if (SupportTest.isSafari) adv.onclick = EventHelper.CancelClickSafari;
	EventHelper.AddEvent(adv, 'click', openAdv, false); // open advertisement
	EventHelper.AddEvent(keywordsearch, 'submit', searchSubmit, false); // submit
	EventHelper.AddEvent(keywords, 'focus', searchFocus, false); // clear search text when focused
}

EventHelper.AddEvent(window, 'load', addNavListeners, false);
//EventHelper.ELO.functionsToCallOnload.push("addNavListeners()");
//initialize all event listeners

if (typeof(window.ActiveXObject) == "function") 
// check for IE before running the ieNavHovers function
{ 
	EventHelper.AddEvent(window, 'load', ieNavHovers, false);
	//EventHelper.ELO.functionsToCallOnload.push("ieNavHovers()");
}

//this code uses dynamicCSS.js to hide the left nav initially, and show it after the body has loaded.
//this allows the non-JavaScript version to be displayed, but keeps it from showing as a "flash"
//before the JavaScript/CSS/images version shows.

if (document.getElementById) {
	//createStyleRule("#leftnav", "display: none;"); //hides leftnav until window loads
	//EventHelper.ELO.functionsToCallOnload.push("showElement()");
	//EventHelper.AddEvent(window, 'load', showElement, false);
}
function showElement() {
	//setElementStyleById("leftnav", "display", "none"); // fallback for IE5/Mac
	//setElementStyleById("leftnav", "display", "block"); //shows leftnav when page finishes loading
	//return false;
}