function pageload() {
	document.f.target = search_target;
	/* change external link targets */
	if (external_link !="_self") {
		for (var i=0; i<document.links.length; i++) {
			var href = document.links[i].href.toLowerCase();
			if (href.substring(0,4)=="http" && href.indexOf("www.faganfinder.com/")==-1 && href.indexOf("sitemeter")==-1 && href.indexOf("w3.org")==-1) {
				 document.links[i].target = external_link;
				}
			}
		}
	/* show 'site info' links */
	if (external_siteinfo=="true") {
		siteInfo();
		}
	document.f.t.focus();
	}

function siteInfo() {
	var con_node = document;
	var a_nodes = con_node.getElementsByTagName("A");
	var temp_nodes = new Array();
	for(var i=0; i<a_nodes.length; i++) {
		temp_nodes[temp_nodes.length] = a_nodes[i];
		}
	for(var i=0; i<temp_nodes.length; i++) {
		var a_node = temp_nodes[i];
		if (a_node.href.toLowerCase().substring(0,4)!="http") { continue; }
		var exclude_url= "http://www.faganfinder.com/";
		if (exclude_url == a_node.href.substr(0,exclude_url.length)) { continue; }
		exclude_url= "http://sm1.sitemeter.com/";
		if (exclude_url == a_node.href.substr(0,exclude_url.length)) { continue; }
		exclude_url= "http://jigsaw.w3.org/";
		if (exclude_url == a_node.href.substr(0,exclude_url.length)) { continue; }
		var new_div_node = document.createElement('SPAN');
		a_node.parentNode.replaceChild(new_div_node,a_node);
		var new_node = document.createElement('A');
		new_div_node.appendChild(a_node.cloneNode(true));
		new_div_node.appendChild(new_node);
		new_node.className = "siteinfo";
		new_node.href = "http://www.faganfinder.com/misc/site.shtml?" + a_node.href;
		new_node.target = "_blank";
		new_node.appendChild(document.createTextNode("i"));
		new_node.title = "see more about this page using Fagan Finder&#8217;s Page Info Viewer";
		}
	}

function trim(z) {
	//leading spaces
	while (z.charAt(0) == " ") {
		z = z.substring(1, z.length);
		}
	//trailing spaces
	while (z.charAt(z.length-1) == " ") {
		z = z.substring(0, z.length-1);
		}
	return z;
	}

function submitform() {
	var z = trim(document.f.t.value);
	document.f.t.value = z;
	if (!z) {
		alert("Please enter something to search for");
		document.f.t.focus();
		}
	else {
		document.f.submit();
		}

	}
	
function clearform() {
	document.f.t.value = "";
	document.f.t.focus();
	}


////////////////////////
//holdover garbage
////////////////////////

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
		}
	else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
	}

//read in cookies and set default values
var search_target = getCookie("search_target");
if (!search_target) { search_target = "_self"; }
var external_link = getCookie("external_link");
if (!external_link) { external_link = "_self"; }
var external_siteinfo = getCookie("external_siteinfo");
if (!external_siteinfo) { external_siteinfo = "false"; }
var spellcheck = getCookie("spellcheck");
if (!spellcheck) { spellcheck = "false"; }
var keyboard = getCookie("keyboard");
if (!keyboard) { keyboard = "false"; }
var autosearch = getCookie("autosearch");
if (!autosearch) { autosearch = "false"; }

function queryprefs() {
	if (keyboard == "true") {
		document.write("<br /><span id='keyboard'>keyboard:");
		for (var i=224; i<255; i++) {
			if (i != 247) {
				document.write(" <a href='javascript:void(0);' title='click here to add this character to your query' onclick='ty("+i+")'>&#"+i+";</a>");
				}
			}
		document.write("</span>");
		if (spellcheck == "true") {
			document.write("<span style='width:20px'></span>");
			}
		}
	if (autosearch == "true") {
		document.write("<input type='button' class='button' value='autosearch' onclick='autosearch2()' title='click here to start or continue autosearching' />");
		}
	if (spellcheck == "true") {
		document.write("<span id=\"spell\"> <a title=\"click here to check the spelling of your query\" href=\"javascript:location.href='http://www.spellcheck.net/cgi-bin/spell.exe?action=CHECKPG&string='+document.f.t.value\">&#8594; check spelling</a></span>");
		}
	}

function ty(c) {
	var z = document.f.t.value + String.fromCharCode(c);
	document.f.t.value = "";
	textfocus();
	document.f.t.value = z;
	}

function rssval() {
	if (location.href.toLowerCase().indexOf("_changes.shtml")>-1) {
		document.write("<a href='http://feeds.archive.org/validator/check?url=" + location.href + "' hreflang='en' rel='validate' title='validate this page&#8217;s RSS feed using the Mark Pilgram and Sam Ruby&#8217;s validator'>RSS</a>");
		}
	}

var searchwindow;
/* "2" because the autosearch is predefined */
function autosearch2() {
	if (typeof searchwindow == 'undefined' || searchwindow.closed) {
		searchwindow = open("", "searchwindow", "scrollbars,top=200,height=500");
		document.f.target = "searchwindow";
		submitform();
		searchwindow.focus();
		}
	else {
		for (var i=0; i<document.f.tool.length; i++) {
			if (document.f.tool[i].checked) {
				var newoption;
				if (i<document.f.tool.length-1) { newoption = i + 1; }
				else {	newoption = 0; }
				document.f.tool[newoption].click();
				submitform();
				searchwindow.focus();
				break;
				}
			}
		}
	}
