// In this function  formCategoryList was changed from 'QS' to 'All Resources'
// document.wfform.Databases.value = formCategoryList('All Resources');
// this is where the databases are defined

function checkQuick()
{
  var sCookieText = '';
  var sDatabaseCookie = '';
  var missing = 1;

  if (document.wfform.wf_term1.value.length > 0)
  {
    missing = 0;
  }

  if (missing == 1)
  {
  	alert('Please enter a search term!');
  	return false;
  }

  sCookieText += "Keyword):(" + document.wfform.wf_term1.value;
  document.cookie = 'wf_search_structure=' + sCookieText + '; Path=/';

  document.wfform.Databases.value = formCategoryList('All Resources');
  sDatabaseCookie = document.wfform.Databases.value;
  document.cookie = 'wf_selected_databases=' + sDatabaseCookie + '; Path=/';

  szUrl = '/cgi-bin/WebFeat.Dll?Command=Search&Databases=';

  szUrl += document.wfform.Databases.value;
  szUrl += '&Client_ID=allegan&BypassSessData=Yes&wf_field1=wf_keyword';
  szUrl += '&wf_term1=' + escape(document.wfform.wf_term1.value) + '&sb=' + document.wfform.sb.value;
  szUrl += '&wf_all_years=yes&noserial=1';
  szUrl += '&format=JS&rtmpl=js';

  document.wfform.nexturl.value = szUrl;
  return true;
}

// action=/cgi-bin/WebFeat.Dll needs to be changed when moved to production

function showQuickSearchForm()
{

  document.write('<FORM name="wfform" action="http://search3.webfeat.org/alleganAuth.asp" method="GET" onSubmit="return checkQuick();">');
  document.write('<input type="hidden" name="Command" value="Search">');
  document.write('<input type="hidden" name="Client_ID" value="allegan">');
  document.write('<input type="hidden" name="Databases" value="">');
  document.write('<input type="hidden" name="wf_field1" value="wf_keyword">');
  document.write('<input type="hidden" name="nexturl" value="">');
  document.write('<input type="hidden" name="sb" value="">');
  document.write('<input type="hidden" name="format" value="JS">');
  document.write('<input type="hidden" name="rtmpl" value="js">');

  document.write('<table><tr><td align="left" valign="top" rowspan="2" width="25%">&nbsp;</td>');
  document.write('<td align="center" valign="middle">')
  document.write('<input name="wf_term1" size="44" type="text" id="searchTerm"></td>');
  document.write('<td align="left" valign="middle" width="25%"><p>');
  document.write('<a href="http://search3.webfeat.org/wf3_allegan.html"><span style="font-size:8pt;">Advanced Search</span></a></p></td></tr>');
  document.write('<tr><td align="center" valign="middle"><a href="javascript:void(submitCatSearch(8126719))">');
  document.write('<img src="http://www.youseemore.com/Allegany/images/FindIt.gif" width="141" height="30" border=0 name="search" alt="Find It: Catalog Search.">');
  document.write('</a><input type="image" src="http://www.youseemore.com/Allegany/images/ResearchIt.gif" width="141" height="30" border=0 name="submit" alt="Research It: Catalog & Database Search."></td>');
  document.write('<td align="left" valign="top">&nbsp;</td></tr></table></font></form>');
}

function submitCatSearch(searchType)
{
  var targetLocation="http://64.193.88.130/tlcScripts/interpac.dll?Search&Config=ysm&LimitsId=0&StartIndex=0&ItemsPerPage=10&SearchType=1&Branch=0&SearchField=";
  var toFind=document.wfform.wf_term1.value;
  targetLocation+=searchType;
  targetLocation+="&SearchData=";
  targetLocation+=toFind;
  targetLocation=encodeit(targetLocation);
  window.location=targetLocation;
}

function encodeit(searchstring)
{
  var toreturn;
  toreturn = "";
  temp = searchstring.split(" ");
  for(x = 0;x < temp.length; x++)
  {
    toreturn = toreturn + temp[x];
    if(x != temp.length - 1)
    {
      toreturn = toreturn + "+";
    }
  }
  return toreturn;
}

