function prepare_search_form(selector, default_string, search_term) {

  // what should the default label text be?
  var default_term = 'search...'
  if (default_string && default_string != '') {
    default_term = default_string;
  }

  // lets make sure we are starting fresh
  $(selector).unbind();

  // set the label text to either the default, or the search string
  if (search_term != '') {
    $(selector).val(search_term);
  } else {
    $(selector).val(default_term);
  }

  // add the click on, click off behavior
  $(selector).focus(
    function() {
     if ($(selector).val() == default_term) {
       $(selector).val('');
     }
    });
  $(selector).blur(
    function() {
     if ($(selector).val() == '') {
       $(selector).val(default_term);
     }
    });
}

function popup_helpres()
{window.location.href = "http://www.origins.net/help/helpres.aspx";}

function popup_libsog()
{window.location.href = "http://www.origins.net/help/lib-sog.aspx";}

function popup_aboutcensus1841()
{window.location.href = "http://www.origins.net/help/aboutbo-census1841.aspx";}

function popup_aboutcensus1841accuracy()
{window.location.href = "http://www.origins.net/help/aboutbo-census1841-accuracy.aspx";}

function popup_faqbopc()
{window.location.href = "http://www.origins.net/help/faqbo-pc.aspx";}

function popup_gallerygotopageemploy()
{window.location.href = "http://www.origins.net/Help/helpsearchtips.aspx";}

function popup_gallerygotopage()
{window.location.href = "http://www.origins.net/Help/helpsearchtips.aspx";}

function popup_wildcards()
{window.location.href = "http://www.origins.net/Help/helpsearchtips.aspx";}

function popup_helpnamex()
{window.location.href = "http://www.origins.net/help/helpnamex.aspx";}

function popup_oldnewdates()
{window.location.href = "http://www.origins.net/Help/helpsearchtips.aspx";}

function popup_narrowing()
{window.location.href = "http://www.origins.net/Help/helpsearchtips.aspx";}

function popup_afterdate()
{window.location.href = "http://www.origins.net/Help/helpsearchtips.aspx";}

function popup_sorting()
{window.location.href = "http://www.origins.net/Help/helpsearchtips.aspx";}

function popup_abouteo()
{window.location.href = "http://www.origins.net/help/aboutbo.aspx";}

function popup_aboutio()
{window.location.href = "http://www.origins.net/help/aboutio.aspx";}

function popup_aboutota()
{window.location.href = "http://www.origins.net/help/aboutota.aspx";}

function popup_aboutso()
{window.location.href = "http://www.origins.net/help/aboutso.aspx";}

function popup_aboutcoll()
{window.location.href = "http://www.origins.net/help/about.aspx";}

function popup_sog()
{window.location.href = "http://www.origins.net/Help/aboutbo-sog.aspx";}

function popup_aboutsog()
{window.location.href = "http://www.origins.net/Help/aboutbo-sog.aspx";}

function popup_abouton()
{window.location.href = "http://www.origins.net/help/abouton.aspx";}

function popup_privacy()
{window.location.href = "http://www.origins.net/help/termsofservice.aspx";}

function popup_termsofservice()
{window.location.href = "http://www.origins.net/help/termsofservice.aspx";}

function popup_cart()
{window.location.href = "http://www.origins.net/help/helpres.aspx";}

function popup_contact()
{window.location.href = "http://www.origins.net/help/contact.aspx";}

function popup_faq()
{window.location.href = "http://www.origins.net/help/faq.aspx";}

function popup_archives()
{window.location.href = "http://www.origins.net/help/resarchives.aspx";}

function popup_helpsearching()
{window.location.href = "http://www.origins.net/help/help.aspx";}

function popup_articles()
{window.location.href = "http://www.origins.net/help/resarticles.aspx";}

function popup_newsletter()
{window.location.href = "http://www.origins.net/help/newsletter.aspx";}

function popup_search(site)
{
var url = "/freesearch.aspx?site=" + site;

windowOpener(url,'freesearch','toolbar=yes,status=no,scrollbars=yes,location=yes,menubar=no,resizable=1,directories=no,width=700,height=430,left=40,top=30')}

function StatusShow( msgStr )
{
	status=msgStr;
}

function SaveSearch( strPageName )
{
var strURL = "http://" + location.hostname + "/popup-SavedSearches.aspx?PageName=" + strPageName;

window.open(strURL,'SaveSearch','toolbar=yes,status=no,scrollbars=yes,location=yes,menubar=no,resizable=1,directories=no,width=500,height=200,left=40,top=30');
}

function GoToLocalSavedSearch( WebsiteID )
{
	var strSavedSearchPage = "";

	if (WebsiteID == 1)
	{
		strSavedSearchPage = "/BritishOrigins/Users/SavedSearches/BOSavedSearches.aspx";
	}
	if (WebsiteID == 2)
	{
		strSavedSearchPage = "/IrishOrigins/Users/SavedSearches/IOSavedSearches.aspx";
	}
	if (WebsiteID == 3)
	{
		strSavedSearchPage = "/NationalWills/Users/SavedSearches/SavedSearches.aspx";
	}

	document.location = strSavedSearchPage;
}

function popup_EditVariants(type,name,precision)
{

var strURL = "";


//strURL = "http://" + location.hostname + "/NameX/NameXSelect.aspx?Name=" + name + "&NameXLevel=" + precision  + "&Type=" + type;

strURL = "/NameX/NameXDisplay.aspx?Name=" + name + "&NameXLevel=" + precision  + "&Type=" + type;

//alert(strURL);
popupWin = window.open(strURL,'NameXEdit','toolbar=yes,status=no,scrollbars=yes,location=yes,menubar=no,resizable=1,directories=no,width=400,height=430,left=40,top=30');

//window.open(strURL);
}

function OpenAddAlertsPopUp(strURLPart)
{
var strURL = "http://" + location.hostname + "/Alerts/" + strURLPart;

windowOpener(strURL,"AddAlert",'toolbar=yes,status=no,scrollbars=yes,location=yes,menubar=no,resizable=1,directories=no,width=500,height=250,left=40,top=30')
}

//DO NOT DELETE
//INCLUDE IN ALL JSSource Pages
function windowOpener(url, name, args)
{
	if (typeof(popupWin) != "object")
	{
		//alert("got here 1");
		popupWin = window.open(url,name,args);
		popupWin.focus();
	}
	else 
	{
		//alert("got here 2");
		//alert("newname: " + name);
		if (!popupWin.closed)
		{ 
		//alert("got here 3");	
			if (!popupWin.name == name)
			{
				popupWin.location.href = url;
				popupWin.focus();
			}
			else
			{
				popupWin2 = window.open(url, name,args);
				popupWin2.focus();
			}	
		} 
		else
		{
//		alert("got here 4");
			popupWin = window.open(url, name,args);
			popupWin.focus();
		}	
	}	
}
