// JavaScript Document
var isWinIE	= (navigator.appName == "Microsoft Internet Explorer" && window.print);
var isBrowserDOM = (document.getElementById && document.getElementsByTagName && document.createElement);

//Helps out with the primary navigation
BindNavGoodness = function() 
{
	if (isBrowserDOM) 
	{
		var navRoot = document.getElementById("nav");
		if (navRoot != null)
		{
			for (i=0; i<navRoot.childNodes.length; i++) 
			{
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI")
				{
					//sets mouseover states on all navitems for IE only
					if (isWinIE)
					{
						node.onmouseover=function() {this.className+=" over";SI_toggleSelects('hidden');}
						node.onmouseout=function() {this.className=this.className.replace(" over", "");SI_toggleSelects('visible');}
					}
					//now dig deeper to get to the subnav LIs
					subnavs = node.getElementsByTagName("UL");
					for(k=0; k<subnavs.length; k++)
					{
						subnavs[k].onmouseover=function(){SetNavParent(this, true);}
						subnavs[k].onmouseout=function(){SetNavParent(this, false);}
					}
				}
			}
		}
	}
}

//Nice function to hide Select input boxes when in IE
//Thank you Sean Inman
function SI_toggleSelects(state) 
{
	if (isWinIE) 
	{
		for (var i=0; (sel=document.getElementsByTagName('select')[i]); i++)
		{
			if (sel.className != "mainsearchdropdown")
				sel.style.visibility = state;
		}
	}
}

function SetNavParent(subnavitem, isSelected)
{
	//get the parent LI tag
	navItem = subnavitem.parentNode;
	//now get the a
	for (i=0; i<navItem.childNodes.length; i++)
	{
		child = navItem.childNodes[i];
		if (child.nodeName=="A")
		{
			child.className=child.className.replace(" over", "");
			
			if (isSelected)
				child.className+=" over";
		}
	}
}

function OpenDialog(url, width, height, name)
{
	url = window.open(url, name, "width=" + width + ",height=" + height + ",scrollbars=1,resizable=1");
}

function SetFormFieldValue(context, id, value)
{
	var evalString = "";
	evalString += "var o = " + context + ".document.getElementById('" + id + "');\n";
	evalString += "if (o)\n";
	evalString += "    o.value = '" + value + "';";
	eval (evalString);
}

function Query_KeyUp(sender, event)
{
	if (event.keyCode == 13)
	{
		SearchButton_Click(sender.form);
		event.cancelBubble = true;
        if (event.stopPropagation)
			event.stopPropagation();
         return false;
	}
}

function SearchButton_Click(form)
{
	if (form.Query.value.length > 0)
	{
		location.href = form.Target.value + "?Query=" + form.Query.value + "&Source=" + form.Source.options[form.Source.options.selectedIndex].value + "&Form=" + form.name;
	}
	return false;
}

function BindSearchValues(formName, sourceValue, query)
{
	var form = document.forms[formName];
	if (!form)
		return;
	
	form.Query.value = query;
	if (sourceValue.length > 0)
	{
		for (i=0; i<form.Source.options.length; i++)
			if (form.Source.options[i].value == sourceValue)
				form.Source.options[i].selected = true;
	}
}

//Determines the number of pixels the specified 
//html element is from the left of the window
function GetLeftPosition(object)
{
	x = 0;
	while (object)
	{
		x += object.offsetLeft;
		object = (typeof(object.offsetParent) != "undefined") ? object.offsetParent : null;
	}
	return x;
}

//Determines the number of pixels the specified 
//html element is from the top of the window
function GetTopPosition(object)
{
	x = 0;
	while (object)
	{
		x += object.offsetTop;
		object = (typeof(object.offsetParent) != "undefined") ? object.offsetParent : null;
	}
	return x;
}

//Register Event Handlers with Client
window.onload=BindNavGoodness;