addLoadEvent(prepareNavLinks);


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


function showDeptDescription(val) {

	//var val = selectBox.value;
	var div = "deptInfoDiv";
	var url = "/ajax/deptInfo.php?which=" + val;
	new Ajax.Updater(div, url, {asynchronous:true});

}


function disableSubmitButton() {
	//submit_payment_button
	
	var theButton = document.getElementById("submit_payment_button");
	theButton.value= "Processing...";
	theButton.disabled = true;
	return true;
}


function toggleOtherAmount(myField) {	
	var radios = document.forms[0].elements["amount"];
	
	if(myField.value == "") {
		for(var i=0; i < radios.length; i++) {
			if(radios[i].value == "other") {
				radios[i].checked = false;
			}
		}
	} else {
		for(var i=0; i < radios.length; i++) {
			if(radios[i].value == "other") {
				radios[i].checked = true;
			}
		}
	}
}


function addNewWindowToLinks() {
	var addLinks = document.getElementById("addLinks");
	var myLinks = addLinks.getElementsByTagName("a");
	
	for(var i=0; i <myLinks.length; i++) {
		myLinks[i].onclick = function() {
			winPopUp(this,'elastic','600','750');
			return false;
		}
	}
}

////////////////////////////////////////

function jumpTo(myListItem) {
	var myUrl = myListItem.firstChild.getAttribute("href");
	//alert(myUrl);
	location.href = myUrl;
}

////////////////////////////////////////

function prepareNavLinks() {

 var mainNav = document.getElementById("nav");
    var items = mainNav.getElementsByTagName("li");
    for (var i=0; i < items.length; i++) {
    	//var whereTo = items[i].firstChild.getAttribute("href");
    	items[i].onclick = function() {
    		return jumpTo(this);
    		//return alert(this);
    	}    	 
    }
}

////////////////////////////////////////

function hideText() {
	hide("bg");
	hide("usercontent");
	hide("hideText");
	show("showText");
}

////////////////////////////////////////

function showText() {
	show("bg");
	show("usercontent");
	show("hideText");
	hide("showText");
}


///////////////////////////////////////////

function showNews() {
	var news = document.getElementById("headline_news");
	var cal = document.getElementById("headline_cal");
	var sports = document.getElementById("headline_sports");
	
	show("headline_news_content");
	hide("headline_cal_content");
	hide("headline_sports_content");
	
	news.childNodes[1].firstChild.setAttribute("class", "active");
	news.childNodes[1].firstChild.setAttribute("className", "active");
	
	cal.childNodes[1].firstChild.setAttribute("class", "");
	cal.childNodes[1].firstChild.setAttribute("className", "");
	
	sports.childNodes[1].firstChild.setAttribute("class", "");
	sports.childNodes[1].firstChild.setAttribute("className", "");
}

function showCal() {
	var news = document.getElementById("headline_news");
	var cal = document.getElementById("headline_cal");
	var sports = document.getElementById("headline_sports");
	
	hide("headline_news_content");
	show("headline_cal_content");
	hide("headline_sports_content");
	
	news.childNodes[1].firstChild.setAttribute("class", "");
	news.childNodes[1].firstChild.className = "";
	
	cal.childNodes[1].firstChild.setAttribute("class", "active");
	cal.childNodes[1].firstChild.className = "active";
	
	sports.childNodes[1].firstChild.setAttribute("class", "");
	sports.childNodes[1].firstChild.setAttribute("className", "");
}

function showSports() {
	var news = document.getElementById("headline_news");
	var cal = document.getElementById("headline_cal");
	var sports = document.getElementById("headline_sports");
	
	hide("headline_news_content");
	hide("headline_cal_content");
	show("headline_sports_content");
	
	news.childNodes[1].firstChild.setAttribute("class", "");
	news.childNodes[1].firstChild.setAttribute("className", "");
	
	cal.childNodes[1].firstChild.setAttribute("class", "");
	cal.childNodes[1].firstChild.setAttribute("className", "");
	
	sports.childNodes[1].firstChild.setAttribute("class", "active");
	sports.childNodes[1].firstChild.setAttribute("className", "active");
}


///////////////////////////////////////////

function popWinChangeBodyClass() {
//change the class of the body element if the window is a popup

var windowName = window.name;
var bodyElement = document.getElementsByTagName("body");

	if(windowName == "popupWin") {	
		bodyElement[0].setAttribute("class", "popupWin");
		//alertSize();
		//alert(bodyElement[0].getAttribute("class"));
	}

}

////////////////////////////////////////////

function winPopUp(strURL,strType,strHeight,strWidth) {
var strOptions="";
if (strType=="slideshow") strOptions="height="+strHeight+",width="+strWidth+"top=150,left=70,scrollbars=no, status=no, resizable=yes";
if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth;
if (strType=="fixed") strOptions="status,scrollbars,resizable,height="+strHeight+",width="+strWidth;
if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
window.open(strURL, 'popupWin', strOptions);
}

////////////////////////////////////////////

function selectBoxJumpTo(selectBox) {

location.href = selectBox.value;

}

////////////////////////////////////////////

function hide(targetId) {
if (document.getElementById) {
	target = document.getElementById(targetId);

	target.style.display = "none";
	}
}

////////////////////////////////////////////

function show(targetId) {
if (document.getElementById) {
	target = document.getElementById(targetId);

	target.style.display = "block";

	// hack to fix safari's redraw bug 
        if (self.screenTop && self.screenY){
            window.resizeTo(self.outerWidth + 1, self.outerHeight);    
            window.resizeTo(self.outerWidth - 1, self.outerHeight);                
        }
	}
}

////////////////////////////////////////////

///////////////////////////////////////

function swap(targetId) {
if (document.getElementById) {
	target = document.getElementById(targetId);
		if (target.style.display == "none") {
			target.style.display = "block";
			} else {
			target.style.display = "none"
			}
		}
}

////////////////////////////////////////////

function show_inline(targetId) {
if (document.getElementById) {
	target = document.getElementById(targetId);
		if (target.style.display == "none") {
			target.style.display = "inline";
			} else {
			target.style.display = "none"
			}
		}
}

////////////////////////////////////////////

function doubleswap(targetId,targetId2) {
if (document.getElementById) {
	target = document.getElementById(targetId);
		if (target.style.display == "none") {
			target.style.display = "block";
			} else {
			target.style.display = "none"
			}

		target2 = document.getElementById(targetId2);

		if (target2.style.display == "none") {
			target2.style.display = "block";
			} else {
			target2.style.display = "none"
			}
		}
}