// Toggles "on" and "off" images for main navigation images.
function ToggleNavImage(obj)
{
	if (obj.src.substr(obj.src.length - 6, 6) == "On.gif")
	{
		obj.src = obj.src.replace("On.gif","Off.gif");
	}
	else
	{
		obj.src = obj.src.replace("Off.gif","On.gif");
	}
}

// Resets the session timeout count.
function ResetIdleTimeout()
{
	if (typeof(IdleTime) != undefined)
	{
		IdleTime = 0;
	}
}

/* http://simon.incutio.com/archive/2004/05/26/addLoadEvent */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) {
			    oldonload();
			}
			func();
		}
	}
}

/* http://www.dustindiaz.com/getelementsbyclass/ */
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

/* by Jeremy Keith */
function insertAfter(newElement, targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	}
	else {
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
}

function reloadButtonStyle() {
	if (!document.getElementsByTagName) {
		return false
	}
	
	var buttons = getElementsByClass("red_button");
	/* loop through all buttons and attach a child div */
	for (i=0; i < buttons.length; i++) {
	    buttons[i].nextSibling.style.display = buttons[i].style.display;
	}

	var buttons1 = getElementsByClass("blue_button");
	/* loop through all buttons and attach a child div */
	/*
	for (i=0; i < buttons1.length; i++) {
	    buttons1[i].nextSibling.style.display = buttons1[i].style.display;
	}
	*/
}

function buttonEndings() {
	var browser = navigator.appName;
	if (browser == 'Opera') 
	{
		return false;
	}
	
	if (!document.getElementsByTagName) {
		return false
	}
	
	var buttons = getElementsByClass("red_button");
	/* loop through all buttons and attach a child div */
	for (i=0; i < buttons.length; i++) {
	    var div = document.createElement("div");
	    div.className = "red_buttonEnding";
	    div.style.display = buttons[i].style.display;
	    insertAfter(div, buttons[i]);
	}

	var buttons1 = getElementsByClass("blue_button");
	/* loop through all buttons and attach a child div */
	/*
	for (i=0; i < buttons1.length; i++) {
	    var div = document.createElement("div");
	    div.className = "blue_buttonEnding";
	    div.style.display = buttons1[i].style.display;
	    insertAfter(div, buttons1[i]);
	}
	*/
}

function goToUrl(url) 
{
   window.location.href = url; 
}

addLoadEvent(buttonEndings);
