/* 
http://dean.edwards.name/weblog/2005/09/busted/
This script is used to create an event for DomContentLoaded, which executes PRIOR to the page onLoad event.  It is ideal to run this initialization javascript on the DomContentLoaded (refered to in this script as the Init() function) because it minimizes the possibility of browser flicker.  

There is an issue with IE though, which is why we check the page protocol.  For HTTPS pages, an external script is included to get around the issue that javascript:void(); executes an HTTP request, giving a "Page contains unsecure items" warning.  By including the external script, we get around this issue.  We only do this when needed though, which is on the HTTPS pages, since this method has the potential to introduce page flicker due to the time needed to load an external script.
*/

/* DO NOT DELETE THIS BLOCK!!! */
/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32) {
	var loc = document.location.toString();
	var index = loc.indexOf(":");
	var protocol = loc.substring(0,index);
	if (protocol == "https") {
		document.write("<script defer src=../scripts/corporate_ie_sslInit.js><\/script>");
	}
	else {
		document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
		var script = document.getElementById("__ie_onload");
		script.onreadystatechange = function() {
			if (this.readyState == "complete") {
				init(); // call the onload handler
			}
		}
	}
};
/*@end @*/

/* for Mozilla/Opera9 */
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init, false);
}

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
	var _timer = setInterval(function() {
		if (/loaded|complete/.test(document.readyState)) {
			init(); // call the onload handler
		}
	}, 10);
}

/* for other browsers */
window.onload = init;

function init() {
	// quit if this function has already been called
	if (arguments.callee.done) return;

	// flag this function so we don't do the same thing twice
	arguments.callee.done = true;

	// kill the timer
	if (_timer) clearInterval(_timer);

	// do stuff
	prep();
};

function prep() {
	if (window.tabsInit) {
		tabsInit();
	}
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function toggleByElement(elementId) {
	for ( var i=0; i < arguments.length; i++ ) {
		$get(elementId).style.display = ($get(elementId).style.display != 'none' ? 'none' : '' );
	}
}

function toggle() {
	for ( var i=0; i < arguments.length; i++ ) {
		$(arguments[i]).style.display = ($(arguments[i]).style.display != 'none' ? 'none' : '' );
	}
}
function toggleNews(elementId) {
	$get(elementId).style.display = ($get(elementId).style.display != 'none' ? 'none' : '' );
	
}

function toggleFAQMarker() {
	for ( var i=0; i < arguments.length; i++ ) {
		$(arguments[i]).className = ($(arguments[i]).className != 'questionAnswerNotShown' ? 'questionAnswerNotShown' : 'questionAnswerShown' );
		$(arguments[i]).style.backgroundImage = ($(arguments[i]).className != 'questionAnswerNotShown' ? 'url(../images/common/CC2_arrowDown.gif)' : 'url(../images/common/CC2_arrowRight.gif)' );
	}
}

function toggleListMarker(elementId) {
	for ( var i=0; i < arguments.length; i++ ) {
		$get(elementId).className = ($get(elementId).className != 'newsNotShown' ? 'newsNotShown' : 'newsShown' );
	}
}

function hide() {
	for ( var i=0; i < arguments.length; i++ ) {
	    try
	    {
		    $get(arguments[i]).style.display = 'none';
		}
		catch(ex){  }
	}
}

function show() {
	for ( var i=0; i < arguments.length; i++ ) {
	    try
	    {
		    $get(arguments[i]).style.display = '';
		}
		catch(ex){  }
	}
}

function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
  	foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

function findChild(id, obj) {
	var foundObj = null;
	if (!obj) {
		foundObj = findObj(id);
	}
	if (!foundObj && obj && obj.childNodes) {
		var myList = obj.childNodes;
		for (var i=0; i<myList.length; i++) {
			if (myList[i] && myList[i].id && myList[i].id == id) {
				foundObj = myList[i];
				break;
			}
			else {
				if (myList[i].childNodes)
					foundObj = findChild(id, myList[i]);
			}
		}
	}
	return foundObj;
}

function doFixSecondaryNav()
{
	var hasSecondaryNav = false;
	var objSecondaryNav = findObj("secondaryNav");
	var objNavContainerOuter = null;

	if (objSecondaryNav != null && objSecondaryNav.childNodes) {
		var children = objSecondaryNav.childNodes;
		var i=0;
		
		
		while (children.length > 0 && i < children.length) {
			var childNode = children[i];
			var str = "";
			
			if (childNode.nodeType == 1) {
				
				if (childNode.className && childNode.className == "navContainerOuter") {
					objNavContainerOuter = childNode;
				}
				
				if (childNode.className && childNode.className == "navlist") {
					hasSecondaryNav = true;
					break;
				}

				i=0;
				children = childNode.childNodes;
			}
			else {
				i++;
			}
		}
	}
	
	if (!hasSecondaryNav && objNavContainerOuter && objNavContainerOuter.style) {
		objNavContainerOuter.style.display = "none";
	}
	
}

function doBackgroundSwap() {
	var objOuterWrapper = findObj("outerWrapper");
	var objBackgroundHolder = findObj("backgroundHolder");
	
	if (objOuterWrapper && objBackgroundHolder
		&& objBackgroundHolder.style)
	{
		var strImage = objBackgroundHolder.style.backgroundImage;
		strImage = strImage.replace(/\s/g, "");
		
		if (strImage && strImage != "url()")
		{
			objOuterWrapper.style.backgroundImage = objBackgroundHolder.style.backgroundImage;
		}
	}
}


