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 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 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 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, i, failCount;
	
	if (IEVersion() > 0)
		var el = event.srcElement;
	else
		var el = event.target;
		
	curForm = el;
	i = 0; failCount = 15;
	while (i++ < failCount && curForm && curForm.tagName != 'FORM') curForm = curForm.parentNode;
	
	if (i==failCount)
	{
		/* something went wrong, and it looks like this is going to end up looping infinitely.
		 * bail before that happens. this should only happen with legacy or very non-standard 
		 * browsers (if at all) */
		 if (el) el.value = "Search"; //better state to be in then "Clear"
		 return ;
	}
	
	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";
					tags[i].onclick = null;
				}
			}
		}
	}
}


function ToggleVisibility(id)
{
	var divParent;
		
	divParent = document.getElementById(id);
	
	if (divParent.className.indexOf('greyed') >= 0)
	{//hidden
		RollDown(id);
	} else {
		RollUp(id);
	}
}


function ValidateEnroll(event)
{
	var el;
	el = event.srcElement;
	if (!el) el = event.target;
	
	var tags = el.getElementsByTagName("INPUT");
	for (var i = 0; i < tags.length; i++)
		tags[i].style.backgroundColor = "#ffffff";
			
	if (el.company && !el.company.value)
	{
		alert("Please enter a company name.");
		//alert(el.company);
		if (el.company.style) el.company.style.backgroundColor = "#FFCCCC";
		return false;
	} 
	
	if (!el.studentName.value)
	{
		alert("Please enter a student name.");
		el.studentName.style.backgroundColor = "#FFCCCC";
		return false;
	} 
	
	if (!el.emailAddress.value)
	{
		alert("Please enter an e-mail address.");
		el.emailAddress.style.backgroundColor = "#FFCCCC";
		return false;
	} 
	
	if (el.paymentType.value == 0)
	{
		alert("Please select a payment type.");
		el.paymentType.style.backgroundColor = "#FFCCCC";
		return false;
	}
	
	
	
	return true;
}

function SubmitOnEnter(event)
{
	var keycode;
	var el;

	keycode = event.keyCode;

	if (event.srcElement)
		el = event.srcElement;
	else
		el = event.target;

	if (keycode == 13) {
		el.form.submit();
	}
}

function ClearTitleField(event)
{
	var el;
	
	if (event.srcElement)
		el = event.srcElement;
	else
		el = event.target;
		
	el.form.title.value = "";
	el.form.submit();
		
}

function PopupTypeDesc(event, type)
{
	var div, cursor, moreInfoPage;
	div = document.createElement('DIV');
	div.className = "typeDescription";
	div.style.position = "absolute";
	cursor = getPosition(event);
	div.style.left = cursor.x + "px";
	div.style.top = cursor.y + "px";
	
	if (type == "ILT")
	{
		div.innerHTML 	= "<p>Instructor-Led classes are classes in which the instructor is physically present "
					  	+ "with the students.  These are offered both at our locations, and at your company's office "
						+ "(by request). </p>" ;
		moreInfoPage = "types_ilt.php";
	} else if (type == "E-ILT")
	{
		div.innerHTML 	= "<p>An Instructor-Led class delivered over the internet.  A live instructor lectures " 
						+ " to the students via streaming video.  Students are able to ask questions, and get hands-on "
						+ " help with exercises via VoIP and remote access software.</p>";
		moreInfoPage = "types_eilt.php";
	} else if (type == "ML")
	{
		div.innerHTML 	= "<p>Students preform hands-on labs and watch recorded lectures.  "
						+ "An experienced mentor is available to assist the student as necessary.</p>";
		moreInfoPage = "types_odt.php";
	} else if (type == "CCL")
	{
		div.innerHTML = "<p>Students work with a live instructor projected on a large screen in the front of the classroom.  As with any instructor-led class, students are able to ask questions and get hands-on help from the remote instructor.</p>";
		moreInfoPage = "types_ccl.php";
	}

	div.innerHTML 	+= "<p><a href='" + moreInfoPage + "'>More Info</a>" 
					+ "<a style='margin-left: 10px;' href='javascript: void(0);' onclick='ClosePopup(event);'>Close</a></p>";

	document.body.appendChild(div);
	
}

/** This works beautifully if the link is 2 elements above the div (e.g. <div><p><a></a></p></div>)) 
 ** something more flexible and sophisticated may be needed later **/
function ClosePopup(event)
{
	var el;
	
	if (! (el = event.srcElement))
		el = event.target;
	
	//magic!
	el.parentNode.parentNode.parentNode.removeChild(el.parentNode.parentNode);

}
function getPosition(e) 
{
    var cursor = {x:0, y:0};

	cursor.x = mouseX(e);
	cursor.y = mouseY(e);
	
	return cursor;
}

/** 
 * Grabbed from:
 http://javascript.about.com/library/blmousepos.htm
 No need to re-invent the wheel here...
**/
function mouseX(evt) 
{
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
	   return evt.clientX + (document.documentElement.scrollLeft ?
	   document.documentElement.scrollLeft :
	   document.body.scrollLeft);
	else return null;
}

function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
	   return evt.clientY + (document.documentElement.scrollTop ?
	   document.documentElement.scrollTop :
	   document.body.scrollTop);
	else return null;
}

/** If Course Type Changes to E-Bridge, set location to one that supports e-bridge**/
function CourseTypeChange(event)
{
	var el;
	
	if (el = event.srcElement);
	else el = event.target;


	if (el.value == 3)
	{//E-Bridge
		/*if (el.form.location.value.indexOf("VIRT") < 0)
		{//if not virt location, set to web based
			el.form.location.value = 13; //web based
		}*/
	} else if (el.value == 2) 
	{//ILT class -- make sure user doesn't have "Web Based" as the location
		if (el.form.location.value == 13)
		{
			alert('You have selected Instructor-Led Training as the desired training type, ' +
				  'but Web Based as the desired location.  ' +
				  'ILT classes run only at physical locations, so you will need to change the location to see any classes.');  
		}
	}
}

function rollover(event, rollImage)
{
	var el;
	
	if (el = event.srcElement);
	else el = event.target;
	
	el.src = rollImage;
}

function rollover_end(event, defaultImage)
{
	var el;
	
	if (el = event.srcElement);
	else el = event.target;
	
	el.src = defaultImage;
}