function Resize()
{
	//if (this.clientWidth > 200) this.style.width = "200px";
}
/* Call All body[onload] Scripts */
function LoadScripts()
{
	//SetContainerHeight();
	var ie = IEVersion();
	if (ie > 0 && ie < 7) SetHover("topMenu");
}

/* Call All body[onresize] Scripts */
function ResizeScripts()
{
	SetContainerHeight();
}


function SetContainerHeight()
{
  	mainCon = document.getElementById("container");


	//I Forget why this is necessary at this point, but it is
	mainCon.style.height = mainCon.clientHeight + "px";
	
	//set it
	if (mainCon.clientHeight < WindowHeight() ) 
	{
    	 mainCon.style.height = (WindowHeight()) + "px";
	}
	
	/* weird code to set #left and #content to #container.clientHeight - #header.clientHeight */
	/* i'm not sure which is more flakey -- doing this via css hacks or this way */
	/* ... tired of css hacks for now */

	var header = document.getElementById("header");
	var footer = document.getElementById("footer");
	var menu = document.getElementById("menu");
	
	for (var i = 0; i < mainCon.childNodes.length ; i++)
	{
		if (	mainCon.childNodes[i].nodeName == "DIV" &&
				mainCon.childNodes[i].attributes.getNamedItem("id").value != "header" &&
				mainCon.childNodes[i].attributes.getNamedItem("id").value != "menu" &&
				mainCon.childNodes[i].attributes.getNamedItem("id").value != "footer" ) 
		{
			mainCon.childNodes[i].style.height = mainCon.offsetHeight - header.offsetHeight - footer.offsetHeight - 
													menu.offsetHeight + "px"; 
		}
	}
 	return;
}

function SetHover(id)
{
	var curClass;
	var el = document.getElementById(id);
	if (el)
	{
		for (var i = 0; i < el.childNodes.length ; i++)
		{
			if (el.childNodes[i].tagName == "LI")
			{
				var node = el.childNodes[i];
				node.onmouseover=function() {
					this.className="hover " + this.className;
				}
				node.onmouseout=function() {
					this.className=this.className.replace("hover", "");
				}
			}
		}
	}
}
function IEVersion()
{
	if (navigator.appVersion.indexOf("MSIE") ==  -1) return -1;
	
	temp=navigator.appVersion.split("MSIE");
	version=parseFloat(temp[1]);

	return version;
}

function SubmitForm(event)
{
	var curForm;
	
	if (IEVersion() > 0)
		var el = event.srcElement;
	else
		var el = event.target;
	
	curForm = el;
	while (curForm && curForm.tagName != 'FORM') curForm = curForm.parentNode;

	if (curForm)
		curForm.submit();
}
/* 
Grabbed from:
http://blog.agileware.net/index.php/archives/2006/02/21/make-a-page-at-least-100-of-your-browser-height/
*/
function WindowHeight() {
  var height = 0;

	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		height = window.innerHeight;
	} else if( document.documentElement && document.documentElement.clientHeight ) {
		//IE 6+ in 'standards compliant mode'
		height = document.documentElement.clientHeight;
  } else if( document.body && document.body.clientHeight ) {
		//IE 4 compatible
		height = document.body.clientHeight;   
	}
  
	return parseInt(height);
}

/* hide div (later: shrink content div?) */
function HideDiv(id, shrink)
{
	var targetDiv = document.getElementById(id);
	var targetHeight = targetDiv.offsetHeight; //for some reason in IE clientHeight == 0

	targetDiv.style.display = "none";
	
	if (shrink) //only shrink on request
	{		
		var container = document.getElementById('container');
		var content = document.getElementById('content');
		var left = document.getElementById('left');
	
		content.style.height = left.style.height = left.clientHeight - targetHeight + "px";
		container.style.height = container.clientHeight - targetHeight + "px";
	}
}

/* show a hidden div in the #content area and expand things downward as necessary */
function ShowHiddenDiv(id)
{
	var targetDiv = document.getElementById(id);
	var contentDiv = document.getElementById('content');
	var containerDiv = document.getElementById('container');
	var leftDiv = document.getElementById('left');
	
	targetDiv.style.display = 'block';
	var targetHeight = targetDiv.offsetHeight;	//for some reason in IE clientHeight == 0
	
	containerDiv.style.height = containerDiv.clientHeight + targetHeight + "px";
	leftDiv.style.height = contentDiv.style.height = 
		contentDiv.clientHeight + targetHeight + "px";	
}

/** "Roll's Up" a div by hiding all ps **/
function RollUp(id)
{
	var top, bottom;
	var el = document.getElementById(id);
	if (el.className.indexOf('greyed') < 0) el.className += " greyed";
	top = bottom = null;
	
	/* Identify top and bottom p's -- there are faster ways to do this */
	for (var i = 0; i < el.childNodes.length ; i++)
	{
		if (el.childNodes[i].tagName == "P")
		{
			if (top == null) top = el.childNodes[i];
			bottom = el.childNodes[i];
		}
	}
	
	/* Shrink main div */
	height = (bottom.offsetTop + bottom.offsetHeight) - top.offsetTop;
	
	var containerEl = document.getElementById('container');
	var contentEl = document.getElementById('content');
	contentEl.style.height = contentEl.offsetHeight - height + "px";
	containerEl.style.height = containerEl.offsetHeight - height + "px";
	
	/* Now hide all the p's */
	for (var i = 0; i < el.childNodes.length ; i++)
	{
		if (el.childNodes[i].tagName == "P")
		{
			el.childNodes[i].style.display = "none";	
		}
	}
	
	/* Now hide the "hide" link and show the show link  */
	tags = el.getElementsByTagName('A');
	for (var i = 0 ; i < tags.length ; i++)
	{
			if (tags[i].className.indexOf('hideLink') >= 0)
			{
				tags[i].style.display = "none";
			} else if (tags[i].className.indexOf('showLink') >= 0)
			{
				tags[i].style.display = "inline";
			}
	}
	
//	SetContainerHeight();
}

/** "Roll's Down" a div by hiding all ps **/
function RollDown(id)
{
	var offset = 0;
	var top, bottom, height;
	top = bottom = null;
	
	var el = document.getElementById(id);
	offset = el.className.indexOf('greyed');
	if ( offset > -1)
	{
		//6 is length of the word "greyed"
		el.className = el.className.substring(0,offset) + el.className.substring(offset+6);
	}
	for (var i = 0; i < el.childNodes.length ; i++)
	{
		if (el.childNodes[i].tagName == "P")
		{
			if (top == null) top = el.childNodes[i];
			bottom = el.childNodes[i];
			el.childNodes[i].style.display = "block";
		}
	}

	height = ((bottom.offsetTop + bottom.offsetHeight) - top.offsetTop) + 30;

	var containerEl = document.getElementById('container');
	containerEl.style.height = containerEl.offsetHeight + height + "px";
	
	/* Now hide the "hide" link and show the show link  */
	tags = el.getElementsByTagName('A');
	for (var i = 0 ; i < tags.length ; i++)
	{
			if (tags[i].className.indexOf('hideLink') >= 0 )
			{
				tags[i].style.display = "inline";
			} else if (tags[i].className.indexOf('showLink') >= 0)
			{
				tags[i].style.display = "none";
			}
	}
	
	
	SetContainerHeight();
}


/* Finds all first generation children of certian class and applies background color to them
 * if I had time i could make this a lot more generic */
function ApplyColorToClass(rootID, className, bColor)
{
	var rootEl = document.getElementById(rootID);
	
	for (var i = 0 ; i < rootEl.childNodes.length; i++)
	{
		//if (rootEl.childNodes[i].tagName == "DIV") alert(rootEl.childNodes[i].className + 'XX');
		//if (i < 3) alert(rootEl.childNodes[i].tagName);

		if (rootEl.childNodes[i].tagName == "DIV" &&
				rootEl.childNodes[i].className.indexOf(className) >= 0)
		{
			//alert(rootEl.childNodes[i].bgColor);
			rootEl.childNodes[i].style.backgroundColor = bColor;
		}
	}
}

function HighlightCertCat(id)
{
	ApplyColorToClass('content','certDiv',''); //reset any existing highlighting
	ApplyColorToClass('content', id, '#FFCC99') //highlight target
}

function SchedLocationPrompt()
{
		var tags = document.getElementsByTagName('SELECT');
		var i;

		for (i = 0; i < tags.length ; i++)
		{
			if (tags[i].getAttribute('name') == 'location')
			{
				tags[i].focus();
				tags[i].style.backgroundColor = "#FFFFCC";
			}
		}
		
}

/* Straing From The Mozilla Website */
function SimulateClick(el) 
{
	var evt = document.createEvent("MouseEvents");
	evt.initMouseEvent(	"click", true, true, window,
    					0, 0, 0, 0, 0, false, false, false, false, 0, null);
 	el.dispatchEvent(evt);
}

/* When the Search Box Is Empty, Toggle Search Submit To Say Clear */
function ClearSearchToggle(event)
{
	var curForm;
	
	if (IEVersion() > 0)
		var el = event.srcElement;
	else
		var el = event.target;
		
	curForm = el;
	while (curForm && curForm.tagName != 'FORM') curForm = curForm.parentNode;
	
	if (curForm)
	{
		var tags = curForm.getElementsByTagName('INPUT');
		
		for (var i = 0; i < tags.length ; i++)
		{
			if (tags[i].className == 'search')
			{
				if (el.value == "") tags[i].value = "Clear";
				else tags[i].value = "Search";
			}
		}
	}
}


function ToggleVisibility(id)
{
	var divParent;
		
	divParent = document.getElementById(id);
	
	if (divParent.className.indexOf('greyed') >= 0)
	{//hidden
		RollDown(id);
	} else {
		RollUp(id);
	}
}
