
//Browser Checks
var browser = navigator.userAgent.toLowerCase();
isGecko = (browser .indexOf("gecko") != -1);
isSafari = (browser .indexOf("safari") != -1);
isKonqueror = (browser.indexOf("konqueror") != -1);

//Main two checks used
var isIE	= (navigator.appName == "Microsoft Internet Explorer" && window.print);
var isBrowserDOM = (document.getElementById && document.getElementsByTagName);



//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
					node.onmouseover=function() 
					{
						if (isIE)
						{
							this.className+=" over"; 						
						}
					}
					
					node.onmouseout=function()
					{
						if (isIE)
						{
							this.className=this.className.replace(" over", "");						
						}
					}
					  
					
					var links = node.getElementsByTagName("A");
					
					for (k=0; k<links.length; k++)
					{
						if (!(links[k].className && links[k].className == "navlink"))
						{
							links[k].onmouseover=function(){SetNavParent(this, true);}
							links[k].onmouseout=function(){SetNavParent(this, false);}
						}
					}
				}
			}
		}
	}
}



function SetNavParent(subnavitem, isSelected)
{
	if(isIE) return;
	//get the parent LI tag
	nav = subnavitem.parentNode.parentNode.parentNode;
	//alert(nav.nodeName);
	
	if (nav.nodeName == "LI")
	{
		nav.className = (isSelected) ? "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;
	}
}

//helper function to make sure document.getElementById exists
//be nice and give a fallback to older IEs
function GetElementById (id){
	if (document.getElementById)
		return document.getElementById(id);
	else if (document.all)
		return document.all[id];
	else
		return null;
}
