<!--
////////////////////////////////////////////////////////////
// COOKIE HANDLER
////////////////////////////////////////////////////////////
function setUpdatePrefs(key,value) {
	// add/update new key and value to prefs array
    prefs[key] = value;
	
	var rgx_multival, psversion, pssearch, ksversion, kssearch;
    var cookieprefs = '';

	// match preferences with multiple values.
	rgx_multival = new RegExp("^(pslookup|keysearch)_(search|version)(\\d+)");

    // build string of prefs to store in cookie
    for (key in prefs) {
		if (key.match(rgx_multival)) { // multiple value key
			var item = key.substring(0, key.length-1); 
			var newval = item+'@'+prefs[key];
			
			switch (item) {
				case 'pslookup_search':
					if (pssearch) {pssearch += '>'+prefs[key];} 
					else { pssearch = newval; } break;
				case 'pslookup_version':
					if (psversion) {psversion += '>'+prefs[key];}
					else { psversion = newval; } break;
				case 'keysearch_search':
	         		 if (cookieprefs) { cookieprefs += '&'; }
				     cookieprefs += item+'@'+prefs[key]; break;
				case 'keysearch_version':
					if (ksversion) {ksversion += '>'+prefs[key];}
					else { ksversion = newval; } break;
			}
		} else {
	         if (cookieprefs) { cookieprefs += '&'; }
		     cookieprefs += key+'@'+prefs[key];
		}
    }
	cookieprefs += '&'+pssearch+'&'+psversion+'&'+kssearch+'&'+ksversion;

    // set cookie
    var futureDate = new Date(); // initialise Date object
    futureDate.setYear(futureDate.getFullYear() + 50); // advance by fifty year
    document.cookie = "BG_PREFS=" + cookieprefs + ";expires=" + futureDate + 
					  ";path=/";
}


////////////////////////////////////////////////////////////
// SHOW & HIDE OPTION INFO
// To populate info div with info about an option button
////////////////////////////////////////////////////////////
function ShowOptionInfo(text1,text2) {
	var newtext = "<strong>"+text1+"</strong> &raquo; "+text2;
        document.getElementById('result-options-info').innerHTML = newtext;
}
function HideOptionInfo() {
	document.getElementById('result-options-info').innerHTML = '&nbsp;';
}


////////////////////////////////////////////////////////////
// SHOW & HIDE OPTION INFO FOR SECOND OPTIONS DIV
// To populate info div with info about an option button
////////////////////////////////////////////////////////////
function ShowOptionInfo2(text1,text2) {
	var newtext = "<strong>"+text1+"</strong> &raquo; "+text2;
        document.getElementById('result-options-info2').innerHTML = newtext;
}
function HideOptionInfo2() {
	document.getElementById('result-options-info2').innerHTML = '&nbsp;';
}


////////////////////////////////////////////////////////////
// SHOW/HIDE
// To show/hide page sections
////////////////////////////////////////////////////////////
function ExpandSection(id)
{
        document.getElementById(id+'-open').style.display = "block";
        document.getElementById(id+'-closed').style.display = "none";
        setUpdatePrefs(id,"open");
}
function CollapseSection(id)
{
        document.getElementById(id+'-open').style.display = "none";
        document.getElementById(id+'-closed').style.display = "block";
        setUpdatePrefs(id,"closed");
}

////////////////////////////////////////////////////////////
// SET WHOLE WORDS ONLY (KEYWORD SEARCH)
// Enable or disable the "whole words only" checkbox based
// on if the searchtype is word or phrase based.
////////////////////////////////////////////////////////////
function SetKeysearchWholewordsonly(searchtype) {
	if (searchtype=='phrase') { 
		document.getElementById('wholewordsonly').disabled=true;
		document.getElementById('wholewordsonlytext').style.color='#bbb';
	} else { 
		document.getElementById('wholewordsonly').disabled=false;
		document.getElementById('wholewordsonlytext').style.color='#336';
	}
}

////////////////////////////////////////////////////////////
// SET LIMIT SEARCH OPTIONS (KEYWORD SEARCH)
// Enable or disable the text/dropdowns of limiting items
// that are not checked.
////////////////////////////////////////////////////////////
function SetKeysearchLimitoptions(limitoptions) {
	if (limitoptions=='none') { 
		document.getElementById('limit-bookset-dropdown').disabled=true;
		document.getElementById('limit-span-begin').disabled=true;
		document.getElementById('limit-span-end').disabled=true;
		document.getElementById('limit-none-label').style.color='#336';
		document.getElementById('limit-bookset-label').style.color='#bbb';
		document.getElementById('limit-span-label').style.color='#bbb';
	} else if (limitoptions=='bookset') { 
		document.getElementById('limit-bookset-dropdown').disabled=false;
		document.getElementById('limit-span-begin').disabled=true;
		document.getElementById('limit-span-end').disabled=true;		
		document.getElementById('limit-none-label').style.color='#bbb';
		document.getElementById('limit-bookset-label').style.color='#336';
		document.getElementById('limit-span-label').style.color='#bbb';
	} else {
		document.getElementById('limit-bookset-dropdown').disabled=true;
		document.getElementById('limit-span-begin').disabled=false;
		document.getElementById('limit-span-end').disabled=false;		
		document.getElementById('limit-none-label').style.color='#bbb';
		document.getElementById('limit-bookset-label').style.color='#bbb';
		document.getElementById('limit-span-label').style.color='#336';
	}
}

////////////////////////////////////////////////////////////
// BUILD JAVASCRIPT PART OF LINK FOR POPUP WINDOW
// Requires a destination and terms to build the link.
// Popup page should parse the destination and terms.
////////////////////////////////////////////////////////////
function InfoPopup(url) {
	window.open (url,'Info','resizable=no, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, width=300, height=300');
	return false;
}

////////////////////////////////////////////////////////////
// (DIS)ABLE LANGUAGE OPTIONS ON /PREFERENCES PAGE
// (Dis)ables the languages and their input boxes when 
// "use all languages" is selected (for clarity)
// Accepts "active" or "disabled"
////////////////////////////////////////////////////////////

function setLanguageOptsDisabledState(disabledState) { 
	// SET SETTINGS
	if (disabledState=='disabled') {
		var inputState='disabled';
		var color='#ccc';
	} else {
		var inputState='';
		var color='#336';
	}
	// DO THE INPUTS
	var allInputs = new Array();
	var allInputs = document.getElementsByTagName('input');  
	for (i=0; i<allInputs.length; i++) { 
		if (allInputs[i].className=='languageOpt') { 
			allInputs[i].disabled=inputState;
		} 
	} 
	// DO THE TEXT
	var allTds = new Array();
	var allTds = document.getElementsByTagName('td');
	for (i=0; i<allTds.length; i++) { 
	if (allTds[i].className=='languageOpts') { 
			allTds[i].style.color=color;
		} 
	}
}

function enableOption(ids) {
	for (i=0; i<ids.length; i++) { 
		 alert(ids[i]);
		 document.getElementsByID(ids[i]).checked='checked';  
	}	 
}

function redirect(url)
{
	window.location = url;
}
var updatePrefs='';
// -->

