/* redirect away from index.* files and not using "www" */
var u = location.href.toLowerCase();
if (u.substring(u.length-"index.html".length,u.length)=="index.html") {
	location.href = u.substring(0, u.indexOf("index.html"));
	}
else if (u.substring(u.length-"index.shtml".length,u.length)=="index.shtml") {
	location.href = u.substring(0, u.indexOf("index.shtml"));
	}
if (u.indexOf("faganfinder.com")>1 && u.indexOf("www.faganfinder.com")==-1) {
	location.href = "http://www." + u.substring(u.indexOf("faganfinder.com"),u.length);
	}

function setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
	}

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));
	}

function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0) date.setTime(date.getTime() - skew);
}

/* 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 doOnload() {
	if (textbox=="true") {
		/* check the checked checkbox */
		for (var i=0; i<document.f.elements.length; i++) {
			if (document.f.elements[i].type=="radio") {
				if (document.f.elements[i].checked) {
					document.f.elements[i].click();
					break;
					}
				}
			}
		/* change search target */
		document.f.target = search_target;
		textfocus();
		}
	/* 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();
		}
	}

/* radio button option selector */
function c(x) {
	var y = x.split(",");
	if (y[0].toLowerCase().indexOf("http")>-1) {
		document.f.action = y[0];
		}
	else {
		document.f.action = "http://" + y[0];
		}
	document.f.method = y[1];
	document.f.t.name = y[2];
	var j=0;
	for (var i=3; i<y.length; i=i+2) {
		if (j<document.f.h.length) {
			document.f.h[j].name = y[i];
			document.f.h[j].value = y[i+1];
			j++;
			}
		}
	textfocus();
	}
function d(x) {
	var n = x;
	if (n.indexOf("?")==-1) { n += "?"; }
	for (var i=n.indexOf("?"); i<x.length; i++) {
		if (x.charAt(i)=="&" || x.charAt(i)=="=") {
			n = n.substring(0, i) + "," + n.substring(i+1,n.length);
			}
		}
	if (n.indexOf(",")>-1) {
		var tmp = n.split(",");
		var tmp2 = tmp[tmp.length-1]
		n = n.substring(0,n.indexOf("?")) + ",get," + tmp2 + "," + n.substring(n.indexOf("?")+1,n.length-tmp2.length-1);
		}
	else {
		n = n.substring(0,n.indexOf("?")) + ",get," + n.substring(n.indexOf("?")+1,n.length);
		}
	c(n);
	}
function textfocus() {
	document.f.t.focus();
	}
function clearform() {
	document.f.t.value="";
	textfocus();
	}
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() {
	document.f.t.value = trim(document.f.t.value);
	if (!document.f.t.value && navigator.appName.toLowerCase().indexOf("netscape")==-1) {
		alert("Please enter some text");
		textfocus();
		}
	else {
		document.f.submit();
		}
	}
	
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>");
		}
	}

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.z.length; i++) {
			if (document.f.z[i].checked) {
				var newoption;
				if (i<document.f.z.length-1) { newoption = i + 1; }
				else {	newoption = 0; }
				document.f.z[newoption].click();
				submitform();
				searchwindow.focus();
				break;
				}
			}
		}
	}

/* keyboard ("typewriter") */
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>");
		}
	}
	
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 foo(x) {
/*
	var tmp = x.split("?");
	document.f.action = "http://" + tmp[0];
	tmp = tmp[1].split("&");
	document.f.t.name = tmp[tmp.length-1];
	for (var i=0; i<document.f.h.length; i++) {
		document.f.h[i].name= "";
		document.f.h[i].value= "";
		}
	for (var i=0; i<(tmp.length-1); i++) {
		var foo = tmp[i].split("=");
alert("1make " + foo[0] + " be " + foo[1]);
		document.f.h[i].name = foo[0];
		document.f.h[i].value = foo[1];
alert("2make " + document.f.h[i].name + " be " + document.f.h[i].value);
		}
*/
document.f.action  = "http://mapmachine.nationalgeographic.com/mapmachine/searchandbrowse.html";
document.f.t.name = "place";
document.f.h[0].name = "task";
document.f.h[1].value = "getSearchPlace";
	textfocus();
	}