function oops_error (msg, url, ln) {
	var status = msg + " on line #" + ln + " in " + url;
//	window.status = status;
//	window.defaultStatus = status;
	return true;
}

window.onerror = oops_error;

var isie = (navigator.appName == "Microsoft Internet Explorer");
var isnetscape = (navigator.appName == "Netscape");
var browserversion = parseFloat (navigator.appVersion);

var FOCUS_FIRST = -1; // Set the focus at the first visible field.
var FOCUS_EMPTY = -2; // Set the focust at the first empty field.
var FOCUS_DISABLE = 0; // Don't set the focus.
var setfocus = FOCUS_FIRST; // Set to a positive number to set the focus at a certain field #.

// Search for and set focus to a form field.
function input_focus() {
	var gotit = false;
	var pos = [0,0];
	var count = 0;
	if (document.forms.length && setfocus) { // Test if there is a form.
		if (setfocus > 0) count = setfocus - 1; // Count fields and stop at # ext_setfocus.
		for (var i = 0; i < document.forms[0].elements.length; i++) { // Search for a visible field.
			if (document.forms[0].elements[i].type != "hidden") { // Found one.
				// Looking for field # ext_setfocus.
				if (count > 0) {
					--count;
					gotit = false;
				// Looking for first empty field.
				} else { if (document.forms[0].elements[i].value.length > 0 && setfocus == FOCUS_EMPTY) {
					gotit = false;
				// Functionality for IE only..
				} else { if (isie) {
					// Test if window is inactive or focus is already set.
					if (document.activeElement.name || !document.hasFocus()) break;
					// Test if field is off the visible area.
					pos = get_position(document.forms[0].elements[i]);
					with (document.body) {
						gotit = pos[0] > scrollLeft && pos[0] < scrollLeft + clientWidth &&
						pos[1] > scrollTop && pos[1] < scrollTop + clientHeight;
					}
				// Just set the focus.
				} else {
					gotit = true;
			}}}}
			if (gotit) { // Set the focus and exit.
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
}

// Gets the absolute position of an item.
// Returns x,y coordinate in an array.
// Works for IE 4 and up.
function get_position (itm) {
	var x = 0;
	var y = 0;
	var x0 = x; // These record last value for comparison
	var y0 = y; // to avoid duplication problems.
	while (itm != null) {
		if (itm.offsetLeft | itm.offsetTop) {
			if (x0 != itm.offsetLeft) {
				x0 = itm.offsetLeft;
				x += x0;
			}
			if (y0 != itm.offsetTop) {
				y0 = itm.offsetTop;
				y += y0;
			}
		}
		itm = itm.parentElement;
	}
	return [x, y];
}

function randomItem(an_array)
// Returns a random member of the array "an_array".
{
	return (an_array[Math.floor(Math.random() * an_array.length)]);
}

function emailAddress()
// Obfuscated e-mail address to confound spammers.
{
	var atsign = "@";
	return "greg" + atsign + "gregsearle.com";
}

function substURL (URL)
// Attempts to substitute the URL in a hyperlink.
{
	var openIt = true;
	if (isie)
	{
		if (browserversion >= 4)
		{
			window.event.returnValue = false; // Cancel the click event.
		} else {
			openIt = false; // Can't cancel the click.  Let it go.
		}
	}
	if (openIt) document.location = URL;
}

function define(definition)
// Pops up a separate window with the definition.
{
	alert (definition);
}

// Mouse-over functions for hyperlinks.

var originalColor;

function aMouseOver(obj, overColor)
{
	if (isie)
	{
		if (arguments.length < 2) overColor = "#99CCFF";
		if (obj.overColor) overColor = obj.overColor;
		originalColor = obj.style.color;
		obj.style.color = overColor;
	}
}

function aMouseOut(obj)
{
	if (isie)
	{
		obj.style.color = originalColor;
	}
}

/* TheCounter.com Counter Code
   Their code has some flaws and incompatabilites with older browsers.
   Here I encapsulate and clean it up, yet retain its functionality
   requirements, both for myself and TheCounter.com. */

var s, c, j, f, gotIt;

function counter_init()
// This function must be called outside of any forms.
{
	s = "na";
	c = "na";
	j = "na";
	f = "" + escape(document.referrer);
	gotIt = false;
}

function counter_getdata()
// JavaScript 1.2 or greater
{
	s = screen.width;
	v = navigator.appName;
	if (v != "Netscape")
		c = screen.colorDepth;
	else
		c = screen.pixelDepth;
	j = navigator.javaEnabled();
}

function pr(n)
{
	document.write(n,"\n");
}

function counter_show1()
// JavaScript 1.2 or greater
{
	var NS2Ch = 0;

	// Netscape 2 doesn't script well.
	if (navigator.appName == "Netscape" && navigator.appVersion.charAt(0) == "2") NS2Ch = 1;

	// Avoid counting internal or staged pages.
	if (f.search("gregsearle.tripod.com") != -1 || f.search("%3A") == 2 || f.search("file%3A") != -1 || f == "") NS2Ch = 1;

	if (NS2Ch == 0)
	{
		r = '&size=' + s + '&colors=' + c + '&referer=' + f + '&java=' + j + '';
		pr('<A HREF=\"http://www.TheCounter.com\" TARGET=\"_blank\"><IMG ' +
			'BORDER=\"0\" SRC=\"http://c3.thecounter.com/id=2372794' + r +
			'\" alt=\"Counter Added September 2001\"><\/A>');
		gotIt = true;
	}
}

function counter_show2()
{
	if (!gotIt)
	{
		document.writeln('<A HREF=\"http://www.TheCounter.com\" TARGET=\"_blank\"><IMG');
		document.writeln('SRC=\"http://c3.thecounter.com/id=2372794\"');
		document.writeln('ALT=\"Counter Added September 2001\" WIDTH=88 HEIGHT=31 BORDER=0><\/A>');
	}
}

