//RRK 2005 - commonly used HTML/DOM functions
//This function should help with browser compatibility
function FindElement (ID)
{
	if (document.all)
	{
		//IE specific
		return document.all[ID];
	}
	if (document.layers)
	{
		//NN specific
		return document.layers[ID];
	}
	if (document.getElementById)
	{
		//W3C standard
		if (document.getElementsByName(ID).length == 0)
		{
			return document.getElementById(ID);
		}
		else
		{
			//RRK - difference in IE/Firefox
			//  Aside from IE confusing name and ID fields, its return values for
			//  getElementsByName are different.  IE will return just the object if
			//  only one is found and an array for multiples.  Firefox, however,
			//  always returns an array.  So this hack forces it to emulate IE for
			//  now, because all of my code was written on IE-only assumptions.
			//return document.getElementsByName(ID);
			switch (document.getElementsByName(ID).length)
			{
			    case 0: return null;
			    case 1: return document.getElementsByName(ID)[0];
			    default: return document.getElementsByName(ID);
			}
		}
	}
	return null;
}
function GetBrowserID ()
{
	//Well, this is a kludge.  IE is the only browser to support a
	//a modal dialog.  So, in order to make this workable on other
	//browsers (Opera, Netscape, Firefox), there's got to be a user
	//agent check.  That's fraught with peril, on account of lying
	//browsers.  Hopefully this will work, who knows for how long.
	var UserAgent = navigator.userAgent;
	var LastChunk = UserAgent.substring(UserAgent.lastIndexOf(")") + 1, UserAgent.length).replace(" ", "");
	//What I did up there is find the last occurence of ).  Why?
	//The modern user agent usually looks alot like this:
	//Mozilla/version (compatible; MSIE version; OS; language; .NET;) browser/version
	if (LastChunk == "" && UserAgent.indexOf("MSIE") != -1)
	{
		return "Internet Explorer";
	}
	else
	{
		if (LastChunk.indexOf("Netscape") != -1)
		{
			return "Netscape Navigator";
		}
		if (LastChunk.indexOf("Opera") != -1 || UserAgent.indexOf("Opera") == 0)
		{
			return "Opera";
		}
		if (LastChunk.indexOf("Firefox") != -1)
		{
			return "Firefox";
		}
		if (LastChunk.indexOf("Gecko") != -1 && UserAgent.indexOf("Mozilla") == 0 && LastChunk.indexOf("Firebird") == -1 && LastChunk.indexOf("Phoenix") == -1 && LastChunk.indexOf("KHTML") == -1)
		{
			return "Mozilla";		//Unsure Of Test
		}
		if (LastChunk.indexOf("KHTML") != -1 && UserAgent.indexOf("Konqueror") != -1)
		{
			return "Konqueror";		//No Windows Version
		}
		if (LastChunk.indexOf("Safari") != -1)
		{
			return "Safari";		//Apple OSX Only
		}
		return UserAgent + "?";
	}
}
function HookupExplorerEvents ()
{
    if (GetBrowserID() != "Internet Explorer")
    {
        var ToExecute = "";
        ToExecute += ("Event.prototype.keyCode getter = function ()\n");
        ToExecute += ("{\n");
        ToExecute += ("return this.charCode;\n");
        ToExecute += ("}\n");
        ToExecute += ("Event.prototype.keyCode setter = function (value)\n");
        ToExecute += ("{\n");
        ToExecute += ("if(value==0)\n");
        ToExecute += ("{\n");
        ToExecute += ("this.preventDefault();\n");
        ToExecute += ("this.stopPropagation();\n");
        ToExecute += ("return false;\n");
        ToExecute += ("}\n");
        ToExecute += ("}\n");
        eval(ToExecute);
        window.addEventListener('keypress', new Function("event", "window.event=event;"), true);
    }
}
