//---------------------------------------------------------------------------
// WebFeat LAPL Custom JavaScript code
//
// This file contains custom functions and variables needed to generate the
// LAPL Quick Search 
//---------------------------------------------------------------------------
//
// Updated:
// 12/13/2002	Brian Schelp
// 09/14/2004	HHlaing
// 09/14/2004 	Matthew Mattson, LAPL
//---------------------------------------------------------------------------

var idx = 0;
var category = new Array;
var databases = new Array;
//Setting up Category Arrays

// SELECT distinct category, selected, show_selections, show_descriptions, description FROM client_category WHERE client_id IN ('lapublic') ORDER BY display_order;


category[idx++] = [
	["Library Catalog", "", "", "", ""], 
	[	"wf_laplcat"
	]
];


category[idx++] = [
	["Selected Databases", "", "", "", ""], 
	[	"wf_galebiorc",
		"wf_galehwrc",
		"wf_ift:itof",
		"wf_galelitrc",
		"wf_ofr_all"
	]

];

category[idx++] = [
	["Photo Collection", "", "", "", ""], 
	[	"wf_laplphoto"
	
	]
];
category[idx++] = [
	["LAPL Web site", "", "", "", ""], 
	[	"wf_laplweb"
	]
];

category[idx++] = [
	["Select All", "", "", "", ""], 
	[	"wf_laplcat",
		"wf_galebiorc",
		"wf_galehwrc",
		"wf_ift:itof",
		"wf_galelitrc",
		"wf_ofr_all",
		"wf_laplphoto",
		"wf_laplweb"
	]
];



// SELECT distinct wf_name, assigned_name, availability, selected, help_text, native_link, short_description, require_auth, icon_description, urllink FROM translator_authentication WHERE client_id IN ('lapublic') ORDER BY assigned_name;

databases = [
		["wf_galebiorc", "Biography Resource Center (Gale)", "2", "0", "", "<!-- Level: 1 -->  <font SIZE=\"-1\" color=\"#339900\">1*</font><br>  &nbsp;&nbsp;&nbsp;&nbsp;Comprehensive database of biographical information on more than 275,000 individuals from many sources. Includes the complete <b>Marquis Who's Who</b>.",
			 "http://webcheck.lapl.org/wcr-bin/gale3 target=_blank",
			 "",
			 "1",
			 "",
			 ""],
		["wf_galehwrc", "Health & Wellness Resource Center", "2", "0", "", "<!-- Level: 1 -->  <font SIZE=\"-1\" color=\"#339900\">1*</font><br>  &nbsp;&nbsp;&nbsp;&nbsp;Full text medical encyclopedias, nearly 400 health and medical journals, more than 800 pamphlets and nearly 2,100 health articles from general interest publications.",
			 "http://webcheck.lapl.org/wcr-bin/gale7 target=_blank",
			 "",
			 "1",
			 "",
			 ""],
		["wf_ift:itof", "Infotrac OneFile (Gale)", "2", "0", "", "<!-- Level: 1 -->  <font SIZE=\"-1\" color=\"#339900\">1*</font><br>      News and periodical articles on a wide range of topics: business, computers, current events, economics, education, environmental issues, health, hobbies, humanities, law, literature and art, politics, science, social science, sports, technology with many full-text articles.",
			 "http://webcheck.lapl.org/wcr-bin/onefile target=_blank",
			 "",
			 "1",
			 "",
			 ""],
		["wf_laplphoto", "LAPL Photo Database", "2", "0", "", "",
			 "http://catalog.lapl.org/a_photo.html  target=_blank",
			 "",
			 "0",
			 "",
			 ""],
		["wf_galelitrc", "Literature Resource Center", "2", "0", "", "<!-- Level: 1 -->  <font SIZE=\"-1\" color=\"#339900\">1*</font><br>  &nbsp;&nbsp;&nbsp;&nbsp;Now includes <b>Twayne's Author Series</b>,  <b>Scribner's Writers Series</b> and <b>MLA (Modern Language Association)</b>. Covers more than 90,000 novelists, poets, essayists, journalists and other writers, with in-depth coverage of 2,000 of the most-studied authors.",
			 "http://webcheck.lapl.org/wcr-bin/gale6 target=_blank",
			 "",
			 "1",
			 "",
			 ""],
		["wf_ofr_all", "Oxford Reference Online - Premium Collection", "2", "0", "", "<!-- Level: 1 -->  <font SIZE=\"-1\" color=\"#339900\">1*</font><br>  &nbsp;&nbsp;&nbsp;&nbsp;Quick reference and scholarly articles from a broad range of subjects in over 100 titles that include key titles from the Oxford Companion series and the complete Oxford Dictionary of Quotations.",
			 "http://webcheck.lapl.org/wcr-bin/oro target=_blank",
			 "",
			 "1",
			 "",
			 ""],
		["wf_laplcat", "LAPL Catalog", "2", "0", "", "",
			 "http://catalog.lapl.org/ target=_top target=_blank",
			 "",
			 "0",
			 "",
			 ""],
		["wf_laplweb", "LAPL Web site", "2", "0", "", "",
			 "",
			 "",
			 "1",
			 "",
			 ""],
		
];



function setSearch(nSearch)
{
	searchType = nSearch;
}

// Show help window
function showHelp( strURL )
{
	strURL = strURL.replace(/Help.html/gi, 'lapublicPopuphelp.html');
	strURL = strURL.replace(/Help.php/gi, 'lapublicPopuphelp.html');
	window.open(strURL, "Help", "height=400,width=500,resizable=yes,scrollbars=yes,location=no,status=no,toolbar=no,personalbar=no,menubar=no");
}

	// Select / Deselect all function
function changeSelect()
{

		checkOn = true;

	if (document.wfform.Databases.length == null)
	{
		// Only one checkbox present
		document.wfform.Databases.checked = checkOn;
	}
	else
	{
		for (i=0; i< document.wfform.Databases.length; i++)
			document.wfform.Databases[i].checked = checkOn;
	}

}


function validateTerms()
{

	var allTerms;

	boolDBs = checkDBs();
	if (boolDBs == false) return false;

	//Check for non-empty term
	if (document.wfform.wf_term1.value.length <= 0)
	{
	alert( "Please enter a search term before proceeding" )
	return false;
	}
	else
	allTerms = escape(document.wfform.wf_term1.value);
		
	
	if (document.wfform.wf_term2.value.length > 0)
	{
	if (document.wfform.wf_op2.value.length <= 0)
		{
		alert( "Please select a boolean operator before proceeding" );
		return false;
		}
	allTerms += "%20" + document.wfform.wf_op2.value.toUpperCase() + "%20" + escape(document.wfform.wf_term2.value);
	}

	document.cookie = "allterm=" + allTerms + "; path=/;";
}


//--------------------------------------------------------------------------------
// This function will create a select box with all listed categories
//
//
// Uses Parameters
//		selectName - This parameter will specify the name to be given to the HTML
//						select object
//---------------------------------------------------------------------------------
function showSelCategoryBox(categoryNames)
{
	selectName = 'Databases';

	categoryNames = ',' + categoryNames + ',';

	document.write('<select name="' + selectName + '">');

	for (i=0; i< category.length; i++)
	{
		if (categoryNames.indexOf(',' + category[i][0][0] + ',') < 0)
			continue;

		sOptionValue = '';
		sOptionText = '';

		sOptionText = category[i][0][0];

		for (j = 0; j < category[i][1].length; j++)
		{
			sOptionValue += ',' + category[i][1][j];
		}

		sOptionValue = sOptionValue.substr(1);
						
		document.write('<option id="' + sOptionText + '" value="' + sOptionValue + '">');
		document.write(sOptionText + '</option>\n');
	}
	document.write('</select>');     
}

function showHomePageForm()
{
	if (typeof(TestHost) == 'undefined')
		document.write('<form name="wfform" action="http://search3.webfeat.org/cgi-bin/WebFeat.dll" method="GET"  onSubmit="return ProcessQuickForm();">');
	else
		document.write('<form name="wfform" action="http://' + TestHost + '/cgi-bin/WebFeat.dll" method="GET"  onSubmit="return ProcessQuickForm();">');


	document.write('    <td align="left" class="searchText">');

	document.write('<input type=hidden name="Command" value="Search">');
	document.write('<input type=hidden name="BypassSessData" value="Yes">');
	document.write('<input type="hidden" name="Client_ID" value="lapublic">');
	document.write('<input type="hidden" name="noserial" value="1">');
	document.write('<input type=hidden name="wf_all_years" value="yes">');

	document.write('<input type="hidden" name="cid" value="lapublic">');
	document.write('<input type="hidden" name="nexturl">');
	document.write('<input type="hidden" name="wf_field1" value="wf_keyword">');
	document.write('<input type="text" name="wf_term1" size="24">');
	document.write('&nbsp;in&nbsp;');
	showSelCategoryBox('Library Catalog,Selected Databases,Photo Collection,LAPL Web site,Select All');
	document.write('&nbsp;<input type="image" name="search" src="/images/search_submit.gif" alt="Go" align="absmiddle" width="20" height="26" border="0">');
	document.write('    </td>');

	document.write('</form>');
}


function ProcessQuickForm()
{
	//Check for non-empty term
	if (document.wfform.wf_term1.value.length <= 0)
	{
		alert( "Please enter a search term before proceeding" )
		return false;
	}

	var selIndex = document.wfform.Databases.selectedIndex;

	//for all other categories but selected databases
	if (document.wfform.Databases.options[selIndex].id != 'Selected Databases')
	{
		return true;
	}

	if (typeof(TestHost) == 'undefined')
		document.wfform.action = "http://search3.webfeat.org/webfeatauth.asp";
	else
		document.wfform.action = "http://" + TestHost + "/webfeatauth.asp";

	nexturl = '/cgi-bin/WebFeat.Dll?Command=Search';
	nexturl += '&BypassSessData=Yes&wf_field1=wf_keyword';
	nexturl += '&wf_term1=' + escape(document.wfform.wf_term1.value);
	nexturl += '&wf_all_years=yes&noserial=1';
	nexturl += '&Databases=' + document.wfform.Databases.value;

	document.wfform.nexturl.value = nexturl;
	document.wfform.Databases.value = '';

	return true;
}
