function submitForm(formId) {
	document.getElementById(formId).submit();
}

function clearquery(id,text) {
	if(!document.getElementById(id)) return false;
	if (document.getElementById(id).value == text) {
		document.getElementById(id).value = "";
	}
	//alert(text);
}

/* 
function clearquery(id) {
	if(!document.getElementById(id)) return false;
	if (document.getElementById(id).value == "Search Virginia Tech") {
		document.getElementById(id).value = "";
	}
}
*/

function quicklinksHover() {
if (!document.getElementById) return false;
if(!document.getElementById("quick-links")) return false;
var quicklinks = document.getElementById("quick-links");
var li = quicklinks.getElementsByTagName("LI");
li[0].onclick = function() {
	if (this.className.search(/over/) == -1) {
		if (this.className == "") {
			this.className = "over";
		}
		else {
			this.className += " over";
		}
		this.style.zIndex = 99;
	}
	else {
		this.className = this.className.replace(/over/i, "");
	}
	return true;
	}
return true;
}

function showTab(obj) {
	if(!document.getElementsByTagName) return false;
	var tab = obj.parentNode;
	if (tab.className.search(/selected/) != -1 || tab.className.search(/first-selected/) != -1 || tab.className.search(/last-selected/) != -1) return false;
	var tabs = obj.parentNode.parentNode;
	var tab_content = obj.parentNode.parentNode.parentNode;
	
	
	var content_number = 0;
	
	tabs = tabs.getElementsByTagName("li");
	
	for ( var i = 0; i < tabs.length; i++ )
	{
		
		if (tabs[i].className.search(/first-selected/) != -1)
		{
			if (tabs[i].className == "first-selected")
			{
				tabs[i].className = tabs[i].className.replace(/first-selected/i, "");
			}
			else {
				tabs[i].className = tabs[i].className.replace(/first-selected/i, "");
			}
		}
		if (tabs[i].className.search(/last-selected/) != -1)
		{
			if (tabs[i].className == "last-selected")
			{
				tabs[i].className = tabs[i].className.replace(/last-selected/i, "");
			}
			else {
				tabs[i].className = tabs[i].className.replace(/ last-selected/i, "");
			}
		}
		if (tabs[i].className.search(/selected/) != -1)
		{
			if (tabs[i].className == "selected")
			{
				tabs[i].className = tabs[i].className.replace(/selected/i, "");
			}
			else {
				tabs[i].className = tabs[i].className.replace(/ selected/i, "");
			}
		}
		
		if (tabs[i] == tab )
		{
			content_number = i;
		}
	}
	
	tab_content = tab_content.getElementsByTagName("div");
	
	var contentArray = new Array();
	var content_counter = 0;
	
	for (var i = 0; i < tab_content.length; i++)
	{
		
		if ( tab_content[i].className.search(/tab-content/) != -1 )
		{
		
			if (tab_content[i].className == "tab-content")
			{
				tab_content[i].className = tab_content[i].className.replace(/selected/i, "");
			}
			else {
				tab_content[i].className = tab_content[i].className.replace(/ selected/i, "");
			}
			
			contentArray[content_counter] = i;
			
			content_counter++;
		}
	}
	
	
	if (tab_content[contentArray[content_number]].className == "selected")
	{	
		tab_content[contentArray[content_number]].className = "selected";
	}
	else {
		tab_content[contentArray[content_number]].className += " selected";	
	}
	
	
	if (tab.className.search(/first/) != -1 )
	{
		if (tab.className == "")
		{
			tab.className == "first-selected";	
		}
		else {
			tab.className += " first-selected";
		}
	}
	else if ( tab.className.search(/last/) != -1)
	{
		if (tab.className == "")
		{
			tab.className == "last-selected";	
		}
		else {
			tab.className += " last-selected";
		}
	}
	else
	{
		if (tab.className == "")
		{
			tab.className == "selected";	
		}
		else {
			tab.className += " selected";
		}
	}
}

function  tagChild() {
	if(!document.getElementsByTagName) return false;
	var ul = document.getElementsByTagName("ul");
	for (var i = 0; i < ul.length; i++ )
	{
		var li = ul[i].getElementsByTagName("li");
		if (!li.length) continue;
		li[0].className += " first";
		li[li.length-1].className += " last";
	}
	
	var ol = document.getElementsByTagName("ol");
	for (var i = 0; i < ol.length; i++ )
	{
		var li = ol[i].getElementsByTagName("li");
		if (!li.length) continue;
		li[0].className += " first";
		li[li.length-1].className += " last";
	}
}

/*===================================================

  THIS FUNCTION MAKES IT SO THAT IF ANY ANCHOR HAS
  THE CLASS OF "off-site" IT WILL OPEN A NEW WINDOW.
  IF JAVASCRIPT IS NOT ENABLED THEN IT WILL JUST
  FOLLOW THE LINK.

*/

function offsite() {
	if (!document.getElementsByTagName) return false;
	
	var links = document.getElementsByTagName("A");
	
	for ( var i = 0; i < links.length; i++ )
	{
		if (links[i].className.search(/off-site/) != -1)
		{
			links[i].onclick = function() {
				if(!document.getElementById) return true;
				//open a new window with the anchors url
				window.open(this.getAttribute("href"));
				return false;
			}
		}
	}
}

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

addLoadEvent(tagChild);
addLoadEvent(offsite);
addLoadEvent(quicklinksHover);
