function setCookie (name, value, expires) {
	if (!expires) expires = new Date();
	document.cookie = name + "=" + escape (value) + "; expires=" + expires.toGMTString() + "; path=/";
}
// These only apply when the search box is present
function setBrowse() {
	document.theSearch.action.value = "start";
}
function setSearch() {
	document.theSearch.action.value = "none";
	// NEW 8/19/10
	// Sets the within_words cookie based on dropdown selection
	var within_words = document.theSearch.within_words[document.theSearch.within_words.selectedIndex].value;
	setCookie('within_words', within_words, expdate);
}
function setFocus() {
	document.theSearch.term0.focus();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function getCookie (name) {
    var dcookie = document.cookie; 
    var cname = name + "=";
    var clen = dcookie.length;
    var cbegin = 0;
        while (cbegin < clen) {
        var vbegin = cbegin + cname.length;
            if (dcookie.substring(cbegin, vbegin) == cname) { 
            var vend = dcookie.indexOf (";", vbegin);
                if (vend == -1) vend = clen;
            return unescape(dcookie.substring(vbegin, vend));
            }
        cbegin = dcookie.indexOf(" ", cbegin) + 1;
            if (cbegin == 0) break;
        }
    return null;
   }

var expdate = new Date ();
expdate.setTime (expdate.getTime() + (1000 * 60 * 30));
if ( getCookie('results_per_page') == null )
{
	setCookie('results_per_page', 10, expdate);
}
if ( getCookie('within_words') == null )
{
	setCookie('within_words', 50, expdate);
} else {
	
}
if ( getCookie('relevance') == null )
{
        setCookie('relevance', 'yes', expdate);
}
function setAction(theValue, theHighlights)
{
    document.action.action.value = theValue;
	document.action.highlights.value = theHighlights;
    document.action.submit();
}

function hitSet( theBigString )
{
	document.passalong.bigstring.value = theBigString;
	document.passalong.submit();
}

var pagetitle = '';

if ( getCookie('key') == null ) {
	pagetitle = '<title>MarpX Precision Search</title>';
	setCookie('key', '', expdate);
} else if ( getCookie('key') == '' ) {
	pagetitle = '<title>MarpX Precision Search</title>';
} else {
	pagetitle = '<title>Current selection: ' + getCookie('key') + '</title>';
}


function convertSpaces(str) {
	var out = "", flag = 0;
	for (i = 0; i < str.length; i++) {
	if (str.charAt(i) != " ") {
		out += str.charAt(i);
		flag = 0;
}
else {
	if(flag == 0) {
		out += "+";
		flag = 1;
      }
   }
}
return out;
}
function deleteAllCookies() {
    var cookies = document.cookie.split(";");

    for (var i = 0; i < cookies.length; i++) {
        var cookie = cookies[i];
        var eqPos = cookie.indexOf("=");
        var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
        document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
    }
}
// Un-comment the line below to clear all cookies - CGM
// deleteAllCookies();
