// Check or uncheck the dbs in a subject

function chkSubject(Databases, state)
{
  var found = 0;
  if (state == true)
  {
    for (i = 0; i < document.wfform.Databases.length; i++)
    {
      if (Databases.indexOf(document.wfform.Databases[i].value) >= 0)
      {
        if (document.wfform.Databases[i].disabled == false)
        {
          document.wfform.Databases[i].checked = true;
        }
      }
    }
  }
  else
  {
    var chkArray = Databases.split(",");
    // For each database, see if any other category checks it.  If not, uncheck it
    for (i = 0; i < chkArray.length; i++)
    {
      found = 0;
      for (j = 0; j < document.wfform.CheckAll.length; j++)
      {
        if (document.wfform.CheckAll[j].checked == true)
        {
          if (document.wfform.CheckAll[j].value.indexOf(chkArray[i]) >= 0)
          {
            found = 1;
          }
        }
      }
      if (found == 0)
      {
        for (j = 0; j < document.wfform.Databases.length; j++)
        {
          if (chkArray[i].indexOf(document.wfform.Databases[j].value) >= 0)
          {
            document.wfform.Databases[j].checked = false;
          }
        }
      }
    }
  }
}



function showAllDbs(wrkArray)
{
  //descCount will be used to name DIV tags for Description links
  var descCount = 0;
  var index = 0;

  for (var i = 0; i < wrkArray.clientTranslators.length; i++)
  {
    var wfName = wrkArray.clientTranslators[i].wfName;
    var assignedName = wrkArray.clientTranslators[i].assignedName;
    var nativeLink = wrkArray.clientTranslators[i].nativeLink;
    var helpText = wrkArray.clientTranslators[i].helpText;
    var auxiliaryData = wrkArray.clientTranslators[i].auxiliaryData;
	var shortDescription = wrkArray.clientTranslators[i].shortDescription;
	var linkOnly = wrkArray.clientTranslators[i].linkOnly;

    //Adding Back To Top links
    if (index % 20 == 0 && index != 0)
    {
      document.write("<tr class='datarowson'><td colspan='3' align='right'><a class='subtitle2' href='#top'>Back to Top</a></td></tr>");
      index++;
    }

    if (index % 2 == 0)
    {
      document.write("<tr class='datarowson'>");
    }
    else
    {
      document.write("<tr class='datarowsoff'>");
    }
    document.write("<td width='4%'>");
    document.write('<input name="Databases" type="checkbox" value="' + wfName + '" ');
    if (wfName.indexOf('LINK') > -1)
    {
      document.write('disabled');
    }
    document.write('></TD><TD>');
    if (nativeLink != '')
    {
      document.write('<A NAME="' + assignedName.charAt(0) + '">&nbsp</A><a href="' + nativeLink + '" target="_blank" class="link_bold">');
    }
    document.write('' + assignedName);
    document.write('</a>&nbsp;&nbsp;&nbsp;');
    if (helpText != '')
    {
      document.write('<div class="description" id="' + descCount + '_switch" style="visibility: visible; display: inline; cursor: pointer;">&nbsp;&nbsp;&nbsp;&nbsp;');
      document.write('<a class="bio_link" onClick="JavaScript:showHide(\'' + descCount + '\', 1); return false;"><B>Description</B></a></div></div>');
      document.write('<div class="description" id="' + descCount + '_desc" style="visibility: hidden; display: none; cursor: pointer;">');
      document.write('<div class="description">' + helpText + '&nbsp;&nbsp;&nbsp;&nbsp;');
      document.write('<a class="bio_link" onClick="JavaScript:showHide(\'' + descCount + '\', 0); return false;"><B>Hide Description</B></a></div></div>');
      descCount++;
    }
    else
    {
      document.write('');
    }
    document.write("</TD>");
	
	
	
	//Need to provide Vendor in different fields depending on linkOnly status
	if (linkOnly == 1)
	{
	document.write('<TD width="15%">' + shortDescription + '</TD>');
	}
	
	else
	{
      document.write('<TD width="15%">' + auxiliaryData + '</TD>');
	}
	
    document.write("</TR>");
    index++;
  }
}

// Display the DBs on a subject page
function showDbs(dbArray, coreArray)
{
  //descCount will be used to name DIV tags for Description links
  var descCount = 0;
  var index = 0;

  // Display the core dbs first, checked
  
  for (var i = 0; i < coreArray.clientTranslators.length; i++)
  {
    var wfName = coreArray.clientTranslators[i].wfName;
    var assignedName = coreArray.clientTranslators[i].assignedName;
    var nativeLink = coreArray.clientTranslators[i].nativeLink;
    var helpText = coreArray.clientTranslators[i].helpText;
    var auxiliaryData = coreArray.clientTranslators[i].auxiliaryData;
	var shortDescription = coreArray.clientTranslators[i].shortDescription;
	var linkOnly = coreArray.clientTranslators[i].linkOnly;
	
    if (index % 2 == 0)
    {
      document.write("<tr class='datarowson'>");
    }
    else
    {
      document.write("<tr class='datarowsoff'>");
    }
    document.write("<td width='4%'>");
    document.write('<input name="Databases" type="checkbox" value="' + wfName + '" ');
    if (wfName.indexOf('LINK') > -1)
    {
      document.write('disabled');
    }
    else
    {
      document.write('checked');
    }
    document.write('></TD><TD>');
    if (nativeLink != '')
    {
      document.write('<A NAME="' + assignedName.charAt(0) + '">&nbsp</A><a href="' + nativeLink + '" target="_blank" class="link_bold">');
    }
    document.write('' + assignedName);
    document.write('</a>&nbsp;&nbsp;&nbsp;');
    if (helpText != '')
    {
      document.write('<div class="description" id="' + descCount + '_switch" style="visibility: visible; display: inline; cursor: pointer;">&nbsp;&nbsp;&nbsp;&nbsp;');
      document.write('<a class="bio_link" onClick="JavaScript:showHide(\'' + descCount + '\', 1); return false;"><B>Description</B></a></div></div>');
      document.write('<div class="description" id="' + descCount + '_desc" style="visibility: hidden; display: none; cursor: pointer;">');
      document.write('<div class="description">' + helpText + '&nbsp;&nbsp;&nbsp;&nbsp;');
      document.write('<a class="bio_link" onClick="JavaScript:showHide(\'' + descCount + '\', 0); return false;"><B>Hide Description</B></a></div></div>');
      descCount++;
    }
    else
    {
      document.write('');
    }
    document.write("</TD>");

	//Need to provide Vendor in different fields depending on linkOnly status
	if (linkOnly == 1)
	{
	document.write('<TD width="15%">' + shortDescription + '</TD>');
	}
	
	else
	{
      document.write('<TD width="15%">' + auxiliaryData + '</TD>');
	}
	
    document.write("</TR>");
    index++;
  }
  
  for (var i = 0; i < dbArray.clientTranslators.length; i++)
  {
    var wfName = dbArray.clientTranslators[i].wfName;
    var assignedName = dbArray.clientTranslators[i].assignedName;
    var nativeLink = dbArray.clientTranslators[i].nativeLink;
    var helpText = dbArray.clientTranslators[i].helpText;
    var auxiliaryData = dbArray.clientTranslators[i].auxiliaryData;
	var shortDescription = dbArray.clientTranslators[i].shortDescription;
	var linkOnly = dbArray.clientTranslators[i].linkOnly;
	
    if (index % 2 == 0)
    {
      document.write("<tr class='datarowson'>");
    }
    else
    {
      document.write("<tr class='datarowsoff'>");
    }
    document.write("<td width='4%'>");
    document.write('<input name="Databases" type="checkbox" value="' + wfName + '" ');
    if (wfName.indexOf('LINK') > -1)
    {
      document.write('disabled');
    }
    else if (wfName == 'wf_litera_crit_onln' || wfName == 'wf_galelitrc')
    {
      document.write('checked');
    }
    document.write('></TD><TD>');
    if (nativeLink != '')
    {
      document.write('<A NAME="' + assignedName.charAt(0) + '">&nbsp</A><a href="' + nativeLink + '" target="_blank" class="link_bold">');
    }
    document.write('' + assignedName);
    document.write('</a>&nbsp;&nbsp;&nbsp;');
    if (helpText != '')
    {
      document.write('<div class="description" id="' + descCount + '_switch" style="visibility: visible; display: inline; cursor: pointer;">&nbsp;&nbsp;&nbsp;&nbsp;');
      document.write('<a class="bio_link" onClick="JavaScript:showHide(\'' + descCount + '\', 1); return false;"><B>Description</B></a></div></div>');
      document.write('<div class="description" id="' + descCount + '_desc" style="visibility: hidden; display: none; cursor: pointer;">');
      document.write('<div class="description">' + helpText + '&nbsp;&nbsp;&nbsp;&nbsp;');
      document.write('<a class="bio_link" onClick="JavaScript:showHide(\'' + descCount + '\', 0); return false;"><B>Hide Description</B></a></div></div>');
      descCount++;
    }
    else
    {
      document.write('');
    }
    document.write("</TD>");


	//Need to provide Vendor in different fields depending on linkOnly status
	if (linkOnly == 1)
	{
	document.write('<TD width="15%">' + shortDescription + '</TD>');
	}
	
	else
	{
      document.write('<TD width="15%">' + auxiliaryData + '</TD>');
	}
	
    document.write("</TR>");
    index++;
  }
  
}

// Show the categories on the subject page

function showCats(varName)
{
  var varFunction = eval(varName);

  var catCount = 0;
  var cols = 2;
  var rows = Math.ceil(varFunction.clientCategories.length / cols);
  var catNum = 0;
  var dbStr = '';
  var catName = '';
  for (var i = 0; i < cols; i++)
  {
    for (var j = 0; j < rows; j++)
    {
      if (i == 0 && j == 0)
      {
        document.write("<td width='50%'>");
      }
      else if (i == 1 && j == 0)
      {
        document.write("</td><td width='50%'>");
      }
      if (catCount < varFunction.clientCategories.length)
      {
        for (k = 0; k < category.length; k++)
        {
          if (varFunction.clientCategories[catCount].name == category[k][0][0])
          {
            dbStr = '';
            for (x = 0; x < category[k][1].length; x++)
            {
              dbStr += "," + category[k][1][x];
            }
            if (dbStr != '')
            {
              dbStr = dbStr.substr(1);
            }
            catName = varFunction.clientCategories[catCount].name;
            catName = catName.replace(/Find-/, '');
            catName = catName.replace(/K5-/, '');
			catName = catName.replace(/612-/, '');
			
			var newCatName = catName.replace(/&/g, "%26");
			//newCatName = catName.replace(/&#241;/g, "n");

			
			if (catName == "Quick Searches")
			{
            document.write('<input type="checkbox" CHECKED onClick="chkSubject(this.value, this.checked);" name="CheckAll" value="' + dbStr + '"/>');
			}
			else
			{
			document.write('<input type="checkbox" onClick="chkSubject(this.value, this.checked);" name="CheckAll" value="' + dbStr + '"/>');
			}
			
			
            document.write('<b><font color="#A74A1B" size=2><a href="lvccldkidsSearch.asp?cid=' + Client_ID + '&cat=' + varFunction.clientCategories[catCount].id + '&catName=' + newCatName + '" class="link_bold">' + catName + '</a><BR>');
          }		  
        }
      }
      catCount++;
    }
  }
  document.write("<BR>");
}






// Show/hide div elements (advanced catalog options, descriptions)
function showHide(divID, visFlag)
{
  if (visFlag == 0)
  {
    document.getElementById(divID + '_switch').style.visibility = 'visible';
    document.getElementById(divID + '_switch').style.display = 'inline';
    document.getElementById(divID + '_desc').style.visiblity = 'hidden';
    document.getElementById(divID + '_desc').style.display = 'none';
  }
  else
  {
    document.getElementById(divID + '_switch').style.visibility = 'hidden';
    document.getElementById(divID + '_switch').style.display = 'none';
    document.getElementById(divID + '_desc').style.visibility = 'visible';
    document.getElementById(divID + '_desc').style.display = 'inline';
  }
}

function showHideAll(visFlag)
{
  if (visFlag == 1)
  {
    document.getElementById('all_off').style.visibility = 'hidden';
    document.getElementById('all_off').style.display = 'none';
    document.getElementById('all_on').style.visibility = 'visible';
    document.getElementById('all_on').style.display = 'inline';
    
    for (i = 0; i < document.wfform.Databases.length; i++)
    {
      if (document.getElementById(i + '_desc'))
      {
        document.getElementById(i + '_desc').style.visibility = 'visible';
        document.getElementById(i + '_desc').style.display = 'inline';
        document.getElementById(i + '_switch').style.visiblity = 'hidden';
        document.getElementById(i + '_switch').style.display = 'none';
      }
    }
  }
  else
  {
    document.getElementById('all_on').style.visibility = 'hidden';
    document.getElementById('all_on').style.display = 'none';
    document.getElementById('all_off').style.visibility = 'visible';
    document.getElementById('all_off').style.display = 'inline';

    for (i = 0; i < document.wfform.Databases.length; i++)
    {
      if (document.getElementById(i + '_desc'))
      {
        document.getElementById(i + '_desc').style.visibility = 'hidden';
        document.getElementById(i + '_desc').style.display = 'none';
        document.getElementById(i + '_switch').style.visibility = 'visible';
        document.getElementById(i + '_switch').style.display = 'inline';
      }
    }
  }
}


function runSpelling(spellStruc) {
var corrected = 0;
if ( spellStruc.spellcheck[0].words != aSearchStruct[1] ) {
corrected = 1;
}
if ( spellStruc.spellcheck[1].words != aSearchStruct[4] ) {
corrected = 1;
}
if ( spellStruc.spellcheck[2].words != aSearchStruct[7] ) {
corrected = 1;
}
if (corrected) {
document.write("<br/>\n");
document.write('<font size="+1">Did you mean: ');
document.write('<a href="javascript:spellCheckSearch(\'' + spellStruc.spellcheck[0].words 
+'\',\'' + spellStruc.spellcheck[1].words 
+'\',\'' + spellStruc.spellcheck[2].words 
+'\')">');
if (spellStruc.spellcheck[0].words != "") {
document.write(spellStruc.spellcheck[0].words);
}
if (spellStruc.spellcheck[1].words != "") {
document.write(" " + aSearchStruct[2] + " " + spellStruc.spellcheck[1].words);
}
if (spellStruc.spellcheck[2].words != "") {
document.write(" " + aSearchStruct[5] + " " + spellStruc.spellcheck[2].words );
}
document.write("</a></font>");
document.write("<br/>");
}
}


var recordTitleFTLink = 0;
var isCatalog = 0;

// Clear advanced catalog options when search is hidden

function clearAdvOptions()
{
  document.wfform.wf_numtype.selectedIndex = 0;
  document.wfform.wf_number.value = '';
  document.wfform.wf_collection.selectedIndex = 0;
  document.wfform.wf_publisher.value = '';

  for (i = 0; i < document.wfform.wf_location.options.length; i++)
  {
    document.wfform.wf_location.options[i].selected = false;
  }
  for (i = 0; i < document.wfform.wf_material.options.length; i++)
  {
    document.wfform.wf_material.options[i].selected = false;
  }
  for (i = 0; i < document.wfform.wf_language.options.length; i++)
  {
    document.wfform.wf_language.options[i].selected = false;
  }
}

// Display the custom Infoguide searches

function showInfoguideSearch(guideID)
{
  var wfNames = '';

  for (i = 0; i < category.length; i++)
  {
    if (category[i][0][4] == guideID)
    {
      for (j = 0; j < category[i][1].length; j++)
      {
        wfNames += ',' + category[i][1][j];
      }
    }
  }
  wfNames = wfNames.substr(1);

  document.write('<table border="0" cellpadding="0" cellspacing="4">');
  document.write('  <tr>');
  document.write('    <td align="left" colspan="2">');
  document.write('      <center><span class="search_title">SEARCH INFOGUIDE DATABASES</span></center>');
  document.write('    </td>');
  document.write('  </tr>');
  document.write('  <form name="wfinfo">');
  document.write('  <input type=hidden value="' + wfNames + '" name=Databases>');
  document.write('  <tr>');
  document.write('    <td align=left>');
  document.write('      <input type="text" name="wf_term1" size=14 value="">');
  document.write('    </td>');
  document.write('    <td align=left valign="middle">');
  document.write('      <a href="#" onClick="wfProcessInfo(); return false;" class="tiny_btn">GO</a>');
  document.write('    </td>');
  document.write('  </tr>');
  document.write('  </form>');
  document.write('</table>');
}

// Display the standard left-side QS box

function showQuickSearch()
{
  document.write('<table border="0" cellspacing="0">');
  document.write('  <form name="wfqs1">');
  document.write('  <tr>');
  document.write('    <td colspan="3" class="search_form">');
  document.write('      Keyword Search&nbsp;<input type="text" name="wf_term1" size=16 class="search" value="">');
  document.write('    </td>');
  document.write('  </tr>');
  document.write('  <tr>');
  document.write('    <td class="search_form">in</td>');
  document.write('    <td>');
  document.write('      <select class="searchin" size=1 name="qsdbs">');
  document.write('      <option value="wf_lvccld_basic" selected>Catalog</option>');
  document.write('      <option value="wf_lvccld_basic,wf_novelist,wf_galelitrc,wf_galewdirn,wf_ift:itof">Catalog Plus</option>');
  document.write('      <option value="wf_lvcclavhold">A/V Catalog</option>');
  document.write('      <option value="wf_lvccldevents">Event Calendar</option>');
  document.write('    </td>');
  document.write('    <td>');
  document.write('      <a href="#" onClick="wfProcessQS1(); return false;" class="search_btn">Go</a>');
  document.write('    </td>');
  document.write('  </tr>');
  document.write('  </form>');
  document.write('</table>');
  document.write('<img src="http://www.lvccld.org/images/spacer.gif" border="0" class="menu_bullet"><a class="nav2" href="http://' + document.location.host + '/clients/lvccldkids/lvccldkidssearch.asp">Library Catalog &amp; <br>');
  document.write('<img src="http://www.lvccld.org/images/spacer.gif" width="13px" border="0">Research Databases</a><br>');
}

// Display the inline footer search

function showBottomSearch()
{
  document.write('<form name="wfqs2">');
  document.write('<td align="center" class="search_block_text">Search&nbsp;for</td>');
  document.write('<td class="search_block"><input class="search" type="text" name="wf_term1" size=53 value="" onFocus="this.select();"></td>');
  document.write('<td class="search_block_text">by</td>');
  document.write('<td class="search_block">');
  document.write('  <select class="searchin" size=1 name="wf_field1">');
  document.write('    <option value="wf_title" selected>Title</option>');
  document.write('    <option value="wf_author">Author</option>');
  document.write('    <option value="wf_subject">Subject</option>');
  document.write('    <option value="wf_keyword">Keyword</option>');
  document.write('  </select>');
  document.write('</td>');
  document.write('<td class="search_block_text">in</td>');
  document.write('<td class="search_block">');
  document.write('  <select class="searchin" size=1 name="qsdbs">');
  document.write('    <option value="wf_lvccld_basic" selected>Catalog</option>');
  document.write('    <option value="wf_lvccld_basic,wf_novelist,wf_galelitrc,wf_galewdirn,wf_ift:itof">Catalog Plus</option>');
  document.write('    <option value="wf_lvcclavhold">A/V Catalog</option>');
  document.write('    <option value="wf_lvccldevents">Event Calendar</option>');
  document.write('  </select>');
  document.write('</td>');
  document.write('<td width="25px" class="search_block_text">');
  document.write('  <a href="#" onClick="wfProcessQS2(); return false;" class="tiny_btn" style="width:25px">GO</a>');
  document.write('</td>');
  document.write('</form>');
}


// Overloading checkDBs() in order to add the nexturl variable

function checkDBs()
{
  var sCookieText = '';
  var sDatabaseCookie = '';
  var noneSelected = true;
  var missing = 1;
  var temp = '';
  var nexturl = '';

  if (document.wfform.wf_term1.value.length > 0)
  {
    missing = 0;
  }
  if (document.wfform.wf_term2)
  {
    if (document.wfform.wf_term2.value.length > 0)
    {
      missing = 0;
    }
  }
  if (document.wfform.wf_term3)
  {
    if (document.wfform.wf_term3.value.length > 0)
    {
      missing = 0;
    }
  }

  if (missing == 1)
  {
  	alert('Please enter a search term!');
  	return false;
  }

  if (document.wfform.wf_field1.value != 'wf_keyword')
  {
    sCookieText += document.wfform.wf_field1.options[document.wfform.wf_field1.selectedIndex].value + "):(";
    sCookieText += document.wfform.wf_term1.value + "):(";
  }
  else
  {
    sCookieText += "wf_keyword):(";
    sCookieText += document.wfform.wf_term1.value + "):(";
  }
  if (document.wfform.wf_term2)
  {
    sCookieText += document.wfform.wf_op2.options[document.wfform.wf_op2.selectedIndex].value + "):(";
    sCookieText += document.wfform.wf_field2.options[document.wfform.wf_field2.selectedIndex].value + "):(";
    sCookieText += document.wfform.wf_term2.value+ "):(";
  }
  else
  {
    sCookieText += '):():():(';
  }
  if (document.wfform.wf_term3)
  {
    sCookieText += document.wfform.wf_op3.options[document.wfform.wf_op3.selectedIndex].value + "):(";
    sCookieText += document.wfform.wf_field3.options[document.wfform.wf_field3.selectedIndex].value + "):(";
    sCookieText += document.wfform.wf_term3.value+ "):(";
  }
  else
  {
    sCookieText += '):():():(';
  }
  if (document.wfform.wf_all_years)
  {
    if (document.wfform.wf_all_years.value != null)
    {
      sCookieText += document.wfform.wf_all_years.value + '):(0):(0):(';
    }
    else
    {
      if (document.wfform.wf_all_years[0].checked == true)
      {
        sCookieText += 'yes):(0):(0):(';
      }
      else
      {
        sCookieText += document.wfform.wf_all_years[1].value + '):(';
        sCookieText += document.wfform.wf_from_year.selectedIndex + '):(';
        sCookieText += document.wfform.wf_to_year.selectedIndex + '):(';
      }
    }
  }
  if (document.wfform.wf_ftonly)
  {
    sCookieText += document.wfform.wf_ftonly.checked + '):(';
  }
  else
  {
    sCookieText += 'false):(';
  }
  if (document.wfform.wf_peeronly)
  {
    sCookieText += document.wfform.wf_peeronly.checked + '):(';
  }

  sCookieText = sCookieText.substr(0, sCookieText.length - 3);
  document.cookie = 'wf_search_structure=' + sCookieText + '; Path=/';

  if (document.wfform.Databases.value != null)
  {
    sDatabaseCookie += document.wfform.Databases.value;
    document.cookie = 'wf_selected_databases=' + sDatabaseCookie + '; Path=/';
    return true;
  }
  else
  {
    if (document.wfform.Databases.length == null)
    {
      // Only one checkbox present
      if (document.wfform.Databases.checked == true)
      noneSelected = false;
    }
    else
    {
      noneSelected = true;
      for (i=0; i< document.wfform.Databases.length; i++)
      {
        if (document.wfform.Databases[i].checked == true)
        {
          noneSelected = false;
          sDatabaseCookie += document.wfform.Databases[i].value + ',';
          //break;
        }
      }//end of for
    }//end of else
    if (noneSelected == true)
    {
      alert('Please select at least one database!');
      return false;
    }
    else
    {
	  //Creating nexturl data
    nexturl = 'http://' + document.location.host + '/wfsearch/search?Command=Search&Client_ID=10997&noserial=1&format=JS&rtmpl=js&wf_codeset=utf-8&useSessions=1';

  nexturl += '&wf_field1=' + document.wfform.wf_field1.options[document.wfform.wf_field1.selectedIndex].value;
  nexturl += '&wf_term1=' + document.wfform.wf_term1.value;
  if (document.wfform.wf_term2)
  {
    if (document.wfform.wf_term2.value != '')
    {
      nexturl += '&wf_op2=' + document.wfform.wf_op2.options[document.wfform.wf_op2.selectedIndex].value;
      nexturl += '&wf_field2=' + document.wfform.wf_field2.options[document.wfform.wf_field2.selectedIndex].value;
	  nexturl += '&wf_term2=' + document.wfform.wf_term2.value;
	}
  }

    if (document.wfform.wf_all_years[0].checked == true)
    {
      nexturl += '&wf_all_years=yes';
    }
    else
    {
      nexturl += '&wf_all_years=' + document.wfform.wf_all_years[1].value;
      nexturl += '&wf_from_year=' + document.wfform.wf_from_year.options[document.wfform.wf_from_year.selectedIndex].value;
      nexturl += '&wf_to_year=' + document.wfform.wf_to_year.options[document.wfform.wf_to_year.selectedIndex].value;
    }

  if (document.wfform.wf_ftonly)
  {
    if (document.wfform.wf_ftonly.checked == true)
    {
      nexturl += '&wf_ftonly=yes';
    }
  }

  nexturl += '&Databases=' + sDatabaseCookie;
   nexturl = nexturl.replace(/&/g, '%26');
   //End of nexturl creation
   
   //document.write(nexturl);
      sDatabaseCookie = sDatabaseCookie.substr(0, sDatabaseCookie.length - 1);
      document.cookie = 'wf_selected_databases=' + sDatabaseCookie + '; Path=/';
	  document.cookie = 'nexturl=' + nexturl + '; Path=/';
      return true;
    }
  }
}



// Process the normal left-side QS
function wfProcessQS1()
{
  var dbStr = '';
  var nexturl;

  var missing = 1;

  if (document.wfqs1.wf_term1.value.length > 0)
  {
    missing = 0;
  }

  if (missing == 1)
  {
    alert('Please enter a search term!');
    return false;
  }

  dbStr = document.wfqs1.qsdbs.options[document.wfqs1.qsdbs.selectedIndex].value;

  nexturl = 'http://' + document.location.host + '/wfsearch/search?Command=Search&Client_ID=lvccldkids&BypassSessData=yes&noserial=1&format=JS&rtmpl=js';
  nexturl += '&wf_all_years=yes&wf_field1=wf_keyword&wf_term1=' + document.wfqs1.wf_term1.value;
  nexturl += '&Databases=' + dbStr;

  if (document.wfqs1.qsdbs.selectedIndex != 1)
  {
    document.location = nexturl;
  }
  else
  {
    nexturl = nexturl.replace(/&/g, '%26');
    document.location = "http://" + document.location.source  + "/clients/lvccldkids/lvccldkids_Auth.asp?nexturl=" + nexturl;
  }
  return false;
}

// Process the inline footer search
function wfProcessQS2()
{
  var dbStr = '';
  var nexturl;

  var missing = 1;

  if (document.wfqs2.wf_term1.value.length > 0)
  {
    missing = 0;
  }

  if (missing == 1)
  {
    alert('Please enter a search term!');
    return false;
  }

  dbStr = document.wfqs2.qsdbs.options[document.wfqs2.qsdbs.selectedIndex].value;

  nexturl = 'http://dev.webfeat.org/wfsearch/search?Command=Search&Client_ID=lvccldkids&BypassSessData=yes&noserial=1&format=JS&rtmpl=js';
  nexturl += '&wf_all_years=yes&wf_field1=' + document.wfqs2.wf_field1.options[document.wfqs2.wf_field1.selectedIndex].value + '&wf_term1=' + document.wfqs2.wf_term1.value;
  nexturl += '&Databases=' + dbStr;

  if (document.wfqs2.qsdbs.selectedIndex != 1)
  {
    document.location = nexturl;
  }
  else
  {
    nexturl = nexturl.replace(/&/g, '%26');
    document.location = "http://dev.webfeat.org/clients/lvccldkids/lvccldkids_Auth.asp?nexturl=" + nexturl;
  }
  return false;
}

// Process the Infoguide search
function wfProcessInfo()
{
  var dbStr = '';
  var nexturl;

  var missing = 1;

  if (document.wfinfo.wf_term1.value.length > 0)
  {
    missing = 0;
  }

  if (missing == 1)
  {
    alert('Please enter a search term!');
    return false;
  }

  if (typeof(document.wfinfo.qsdbs) != 'undefined') 
  {
    dbStr = document.wfinfo.qsdbs.options[document.wfinfo.qsdbs.selectedIndex].value;
  }
  else 
  {
    dbStr = document.wfinfo.Databases.value;
  }

  nexturl = 'http://' + document.location.host + '/wfsearch/search?Command=Search&Client_ID=lvccldkids&BypassSessData=yes&noserial=1&format=JS&rtmpl=js';
  nexturl += '&wf_all_years=yes&wf_field1=wf_keyword&wf_term1=' + document.wfinfo.wf_term1.value;
  nexturl += '&Databases=' + dbStr;
  nexturl = nexturl.replace(/&/g, '%26');
  window.open("http://" + document.location.host + "/clients/lvccldkids/lvccldkids_Auth.asp?nexturl=" + nexturl);
  //document.location = "http://search3.webfeat.org/clients/lvccldkids/lvccldkids_Auth.asp?nexturl=" + nexturl;
  return false;
}




// Process the basic/advanced searches
function wfProcess()
{
  var dbStr = '';
  var nexturl;

  // Check for missing search terms - call number search doesn't need a wf_term

  var missing = 1;

  if (document.wfform.wf_term1.value.length > 0)
  {
    missing = 0;
  }
  if (document.wfform.wf_term2)
  {
    if (document.wfform.wf_term2.value.length > 0)
    {
      missing = 0;
    }
  }
  if (document.wfform.wf_term3)
  {
    if (document.wfform.wf_term3.value.length > 0)
    {
      missing = 0;
    }
  }

  if (missing == 1)
  	{
  	  alert('Please enter a search term!');
  	  return false;
  	}
  

  // Append category values & database values to dbStr

  if (document.wfform.CheckAll)
  {
    for(i=0;i<document.wfform.CheckAll.length;i++)
    {
      if (document.wfform.CheckAll[i].checked == true)
      {
        wfNames = document.wfform.CheckAll[i].value.split(",");
        for (j = 0; j < wfNames.length; j++)
        {
          if (dbStr.indexOf(wfNames) < 0)
          {
            dbStr += ',' + document.wfform.CheckAll[i].value;
          }
        }
      }
    }
  }

  if (document.wfform.dbs)
  {
    if (document.wfform.dbs.value == 'wf_lvccldkidscat')
    {
      dbStr += ',wf_lvccldkidscat';
    }
    else if (document.wfform.dbs.value == 'wf_lvccld_basic')
    {
      dbStr += ',wf_lvccld_basic';
    }
    else
    {
      for(i=0;i<document.wfform.dbs.length;i++)
      {
        if (document.wfform.dbs[i].checked == true)
        {
          if (dbStr.indexOf(document.wfform.dbs[i].value) < 0)
          {
            dbStr += ',' + document.wfform.dbs[i].value;
          }
        }
      }
    }
  }

  if (dbStr == '')
  {
    alert('Please select a database!');
    return false;
  }

  var advStr = '';


  // If any advanced options are chosen, remove all other databases

  
  //8-22-07 : Commenting this out because there are no longer basic/advanced options, and I believe we only need a value for dbStr if the box was checked on the Search page
  //if (advFound == 1)
  //{
   // dbStr = 'wf_lvccldkidscat';
  //}

  nexturl = 'http://' + document.location.host + '/wfsearch/search?Command=Search&Client_ID=10997&noserial=1&format=JS&rtmpl=js&wf_codeset=utf-8&useSessions=1';

  nexturl += '&wf_field1=' + document.wfform.wf_field1.options[document.wfform.wf_field1.selectedIndex].value;
  nexturl += '&wf_term1=' + document.wfform.wf_term1.value;
  if (document.wfform.wf_term2)
  {
    if (document.wfform.wf_term2.value != '')
    {
      nexturl += '&wf_op2=' + document.wfform.wf_op2.options[document.wfform.wf_op2.selectedIndex].value;
      nexturl += '&wf_field2=' + document.wfform.wf_field2.options[document.wfform.wf_field2.selectedIndex].value;
	  nexturl += '&wf_term2=' + document.wfform.wf_term2.value;
	}
  }


    if (document.wfform.wf_all_years[0].checked == true)
    {
      nexturl += '&wf_all_years=yes';
    }
    else
    {
      nexturl += '&wf_all_years=' + document.wfform.wf_all_years[1].value;
      nexturl += '&wf_from_year=' + document.wfform.wf_from_year.options[document.wfform.wf_from_year.selectedIndex].value;
      nexturl += '&wf_to_year=' + document.wfform.wf_to_year.options[document.wfform.wf_to_year.selectedIndex].value;
    }
  

  if (document.wfform.wf_ftonly)
  {
    if (document.wfform.wf_ftonly.checked == true)
    {
      nexturl += '&wf_ftonly=yes';
    }
  }

  // Strip leading comma

  if (dbStr.indexOf("w") > 0)
  {
    dbStr = dbStr.substr(1);
  }

  // If the search is only LVCCLD databases, do not authenticate.

  nexturl += '&Databases=' + dbStr;
  
  var wfFree = '';
document.write(nexturl);

  tempStr = dbStr.replace(/wf_lvebooks|wf_lvccldkidscat|wf_lvccldevents|wf_lvcclavhold|wf_lvccld_basic/g, '');
  
  //alert("tempStr is: " + dbStr);
  if (tempStr.indexOf('w') < 0)
  {
  wfFree = 'yes';
  nexturl += '&wfFree=' + wfFree;
  
  
  alert(wfFree);
  document.location = nexturl;
    //document.location = nexturl;
    return false;
  }
  else
  {
  wfFree = 'no';
  
  
  //alert(wfFree);
  nexturl = nexturl.replace(/&/g, "%26");
  //alert(nexturl);
  document.location = 'postAuth.asp?nexturl=' + nexturl;
 
    //document.wfform.nexturl.value = nexturl;
    return true;
  }

  return false;
}

// Overloaded to change the default catalog display, and to handle the events database

function makeStdRecord(n, showName)
{
  var temp;
  var m;

  if (typeof(showName) == 'undefined') {
    showName = false;
  }

  var grpidx = rec[n][rec_grp_idx];
  var wfname = grp[grpidx][grp_wfname_idx];
  var markup = '';

  // Title
  // check if the title need to link to full-text or not
  if (recordTitleFTLink && (rec[n][rec_fullurl_idx] != '') ) {
    markup += '<span class="wfrtitle"><a href="#" class="wfrtitle" onClick="';
    markup += "JavaScript:viewWF2URL(" + rec[n][rec_grp_idx] + ",'" + rec[n][rec_fullurl_idx] + "'," + n + "); return false;";
    markup += '">' + rec[n][rec_title_idx] + '</a></span><br>';
  } else {
    markup += '<span class="wfrtitle">' + rec[n][rec_title_idx] + '</span><br>';
  }

  if (wfname == 'wf_lvccldevents')
  {
    // Author/Event Type
    markup += markupElementLV(n, rec_auth_idx, 'Event Type');

    // Source/Location
    markup += markupElementLV(n, rec_src_idx, 'Location');

    // Publisher/Date
    markup += markupElementLV(n, rec_pubdate_idx, 'Date');
  }
  else
  {
    // Author
    markup += markupElement(n, rec_auth_idx);

    // Source
    markup += markupElement(n, rec_src_idx);


    if (wfname == 'wf_lvccldkidscat' || wfname == 'wf_lvccld_basic' || wfname == 'wf_lvcclavhold')
    {
      // Journal
      markup += markupElementLV(n, rec_journal_idx, 'Publisher');

      // Append Pubdate directly
      markup += rec[n][rec_pubdate_idx] + '<br>';
    }
    else
    {
      // Journal
      markup += markupElement(n, rec_journal_idx);

      // Publication Date
      markup += markupElement(n, rec_pubdate_idx);
    }

    // Volume
    markup += markupElement(n, rec_vol_idx);

    // Issue
    markup += markupElement(n, rec_issue_idx);

    // Pages
    markup += markupElement(n, rec_pages_idx);

    // Citation
    markup += markupElement(n, rec_citation_idx);

    // ISBN
    markup += markupElement(n, rec_isbn_idx);

    // ISSN
    markup += markupElement(n, rec_issn_idx);

    // Call Number
    markup += markupElement(n, rec_callnum_idx);

    // Subject
    markup += markupElement(n, rec_subj_idx);

    // Description
    if (wfname != 'wf_lvccldkidscat' && wfname != 'wf_lvccld_basic')
      markup += markupElement(n, rec_desc_idx);

    // Publisher
    markup+=markupElement(n, rec_publish_idx);

    // Place of Publication
    markup+=markupElement(n, rec_pubplace_idx);

    // Editor
    markup+=markupElement(n, rec_edt_idx);
  }

  // Resource/Database Name
  if (showName) {
    markup += markupElement(n, lang_resourcename_idx);
  }

  // Full-record links
  var grpidx = rec[n][rec_grp_idx];

  var temp = rec[n][rec_fullurl_idx];

  var bHaveLinks = false;

  if (temp != '')
  {
    if (!bHaveLinks)
    {
      bHaveLinks = true;
      markup += '<div class="wfrftlink">';
    }
    var clickAction = "JavaScript:viewWF2URL(" + grpidx + ",'" + temp + "'," + n + ")";
    markup += makeLinkButton(langStrings[lang_view_idx][lang], clickAction, 'linkbuttonover', 'linkbuttonout');
  }

  // Alternate full-record links always appear as URL/text pairs at the end of the record array
  var i;
  for (i = rec_otherurls_idx; i < rec[n].length - 1; i += 2)
  {
    if (rec[n][i] == '' || rec[n][i + 1] == '') {
      break;
    }

    if (!bHaveLinks)
    {
      bHaveLinks = true;
      markup += '<div class="wfrftlink">';
    }
    temp = rec[n][i];
    // If this is a Save/Request Items link, process it to use the catalog script
    if (rec[n][i+1] == 'Save/Request Items') {
      temp = processCartLink(temp, grp[grpidx][grp_nexturl_idx], grp[grpidx][grp_wf2srv_idx]);
      rec[n][i+1] = 'Add/Remove From Book Bag';
      //temp = '';
    }
    if (temp != '') {
      var clickAction = 'JavaScript:viewWF2URL(' + grpidx + ",'" + temp + '\')';
      markup += makeLinkButton(rec[n][i + 1], clickAction, 'linkbuttonover', 'linkbuttonout');
    }
  }

  // Add an OpenURL link if one's available
  if (rec[n][rec_openurl_idx] != '')
  {
    if (!bHaveLinks)
    {
      bHaveLinks = true;
      markup += '<div class="wfrftlink">';
    }

    var ouText = rec[n][rec_openurltext_idx];
    if (ouText == '') {
      ouText = langStrings[lang_openurl_idx][lang];
    }

    var clickAction;
    if (rec[n][rec_pubdatestd_idx] != 0) {
      clickAction = 'JavaScript:viewURL(' + "'" + rec[n][rec_openurl_idx].replace(/\&date=[^\&]+\&/,'&date='+formatDate(rec[n][rec_pubdatestd_idx])+'&') + '\')';
    } else {
      clickAction = 'JavaScript:viewURL(' + "'" + rec[n][rec_openurl_idx] + '\')';
    }

    if (ouText.indexOf('/images/') >= 0) {
      markup += makeLinkImage(ouText, clickAction);
    } else {
      markup += makeLinkButton(ouText, clickAction, 'oulinkbuttonover', 'oulinkbuttonout');
    }
  }

  if (bHaveLinks) {
    markup += '</div>';
  }

  return markup;
}

function markupElementLV(n,elemidx, label)
{
  var m = '';
  var temp = rec[n][elemidx];

  if (temp != '') {
    m = '<span class="wfrelem">' + label + ': </span>';
    m += temp;
    if (label != 'Publisher')
    {
      m += '<br />';
    }
  }

  return m;
}

//----------------------------------------------------------------------
// makes given group
//----------------------------------------------------------------------
function makeDisplayGroup(n, prevGrpIdx, nextGrpIdx)
{
  //alert ("makeDisplayGroup");

  if (grp[n][grp_wfname_idx] == 'wf_lvccldkidscat' || grp[n][grp_wfname_idx] == 'wf_lvccld_basic')
  {
    recordTitleFTLink = 1;
    isCatalog = 1;
  }
  else
  {
    recordTitleFTLink = 0;
    isCatalog = 0;
  }

  // create alignment table
  var temp = '<table border=0 cellpadding=0 cellspacing=0 width="100%"><tr><td>&nbsp;</td><td width="700">';

  // Display header
  temp += makeHeader(n);

  // Make a box around the summary records
  temp += '<div class="resultrecs">';

  // Display category if it is there
  temp += makeCategory(n);

  // Display summary stats
  if (grp[n][grp_totaltally_idx] <= 0) {
    if (grp[n][grp_usermsg_idx] == '') {
      temp += '<div class=wfrsum>No search results from this source</div>';
    } else {
      temp += '<div class=wfrsum>' + grp[n][grp_usermsg_idx] + '</div>';
    }
  } else {
    if (grp[n][grp_usermsg_idx] != '') {
      temp += '<div class=wfrsum>' + grp[n][grp_usermsg_idx] + '</div>';
    }

    temp += '<div class=wfrsum>' + makeSummaryRecord(n) + '</div>';

    // Add a checkbox to select/deselect all records in this group
    temp += makeSelectAllCheckbox(n, '');
    temp += makeDisplayRecords(n);
    temp += makeSetLinks(n, prevGrpIdx, nextGrpIdx);
  }

  // Close records div
  temp += '</div>';

  // Close the alignment table
  temp += '</td><td>&nbsp;</td></tr></table>';

  //alert ("makeDisplayGroup: " + temp);
  return temp;
}

//----------------------------------------------------------------------
// makes display records in grouped mode for the given group
//----------------------------------------------------------------------
function makeDisplayRecords(n)
{
  //alert ("makeDisplayRecords");

  // Display records
  var i = 0;
  var recNum = grp[n][grp_firstnum_idx];

  temp = '';
  temp = '<table border=0 cellpadding=0 cellspacing=0 description="Table with Webfeat Search Results">';
  for (; i < rec.length; i++)
  {
    if (rec[i][rec_grp_idx] == n)
    {
      var grpidx = rec[i][rec_grp_idx];
      var wfname = grp[grpidx][grp_wfname_idx];

      // Add the add to cart button
      if (typeof(altMakeStdRecord) == 'function')
      {
        //alert("Using altMakeRec from makeDisplayRecords");
        var localMarkup = altMakeStdRecord(n, i, recNum++);

        if (localMarkup != null) {
          temp += localMarkup;
        }
      }
      else
      {
        if (wfname == 'wf_lvccldkidscat' || wfname == 'wf_lvccld_basic')
        {
          // Break up the Description parameter into type icon and rating
          var arrDescription = rec[i][rec_desc_idx].split('&nbsp;&nbsp;');
          var strDescription = arrDescription.shift();
          var strRating = arrDescription.join('');
          temp += "<tr><td class=wfrrecn width=30>" + recNum++ + ". " + makeRecordCheckbox(i, '');
          temp += '<br/>' + strDescription + '</td>';
          temp += '<td>' + makeDisplayImage(i) + '<br/>' + strRating + '</td>';
          if (isCatalog == 1)
          {
            temp += "<td class=wfrrec width='5%'>&nbsp;</td>";
            temp += "<td class=wffrec>" + makeStdRecord(i) + "</td>";
          }
          else
          {
            temp += "<td class=wfrrec width=500>" + makeRecordCheckbox(i, '') + makeStdRecord(i) + "</td>";
          }
          temp += '</tr><tr><td colspan="4">&nbsp;</td></tr>';
        }
        else
        {
          temp += "<tr><td class=wfrrecn width=30>" + recNum++ + ".</td>";
          temp += '<td>' + makeDisplayImage(i) + '</td>';
          temp += "<td class=wfrrec width=500>" + makeRecordCheckbox(i, '') + makeStdRecord(i) + "</td>";
          temp += "</tr>";
        }
      }
    }
  }
  temp += "</table>";

  //alert ("makeDisplayRecords: " + temp);
  return temp;
}

//----------------------------------------------------------------------
// Make image for specified record index
//----------------------------------------------------------------------
function makeDisplayImage(i)
{
  var temp = '';

  if (rec[i][rec_imgurl_idx] == '') {
    temp += '&nbsp;';
    return temp;
  }

  // preload the image to determine its size
  var image1 = new Image();
  image1.src = rec[i][rec_imgurl_idx];


// alert("Height: "+image1.height);

  if (image1.height == 0) {
    temp += '<img valign="center" onload="Resize(this)" border="0" HSPACE="4" VSPACE="2" src="' + rec[i][rec_imgurl_idx] + '" alt="' + rec[i][rec_imgtxt_idx] + '">';
  } else {
    temp += '<img valign="center" border="0" HSPACE="4" VSPACE="2"';


    if((image1.height>80) || (image1.width>150)) {

      if (image1.width > image1.height) {

    	ratio=150/image1.width;
    	image1.height=Math.round((1/ratio)*image1.height);
    	if(ratio < 1) {
    	   image1.width=150;
         }
    	}//if
    	else {

        	ratio=80/image1.height;
        	image1.height=Math.round(ratio*image1.height);
    		image1.width=Math.round(ratio*image1.width);

         }//else
      }//if
    else if((image1.height>80) && (image1.width>150)) {

    	    image1.height=80;
    	    image1.width=150;
	}//else if

    temp += ' height="' + image1.height + '"';
    temp += ' width="' + image1.width + '"';
    temp += ' src="' + image1.src + '" alt="' + rec[i][rec_imgtxt_idx] + '">';
  }

  return temp;
}

function setSubjectCookie(url, subjectName)
{
  document.cookie = "wfSubject=" + subjectName + ";Path=/;";
  document.cookie = "wfBack=" + escape(url.href) + ";Path=/;";
}

function processCartLink(linkUrlCart, linkUrlNextSet, strWf2Host)
{
  // Get the session ID so we can add the item to the correct users cart
  //  /wfsearch/search?Command=Search&Databases=wf_lvccldkidscat&wf_action=nextset&wf_url=http%3A%2F%2Filsweb.lvccld.org%2Fsearch%2FXN%3A(brake)%26searchscope%3D12%26b%3D%26m%3D%26l%3D%26p%3D%26Da%3D%26Db%3D%26SORT%3DA%2FXN%3A(brake)%26searchscope%3D12%26b%3D%26m%3D%26l%3D%26p%3D%26Da%3D%26Db%3D%26SORT%3DA%2F13%252C16%252C16%252CB%2Fbrowse
  //      &format=JS&rtmpl=js&wf_cookies=SESSION_ID%3D1140375233.14833&wf_searchterms=brake
  // ***************** UPDATE ???? Sara is discussing with Rob at LVCCLD ************************
  // Possible Update?  Look for the session ID from a cookie rather then the link so we can use the same ID accross searches.
  var nBegin = linkUrlNextSet.indexOf('SESSION_ID%3D') + 13;
  var nEnd = linkUrlNextSet.indexOf('&', nBegin);
  var strSessionID = linkUrlNextSet.substr(nBegin, nEnd-nBegin);
  // point the link at shoppingcart.pl instead of the servlet
  // /wfsearch/search?Command=Redirect&url=http%3A%2F%2Filsweb.lvccld.org%2Fsearch%2FXN%3A(brake)%26searchscope%3D12%26b%3D%26m%3D%26l%3D%26p%3D%26Da%3D%26Db%3D%26SORT%3DA%2FXN%3A(brake)%26searchscope%3D12%26b%3D%26m%3D%26l%3D%26p%3D%26Da%3D%26Db%3D%26SORT%3DA%2F1%252C16%252C16%252CB%2Fbrowse%3Fsave%3Db1003663
  //      &Databases=wf_lvccldkidscat&wf_action=fulltext
  nBegin = linkUrlCart.indexOf('&url=') + 5;
  nEnd = linkUrlCart.indexOf('&', nBegin);
  strCartUrl = linkUrlCart.substr(nBegin, nEnd-nBegin);

  return '/clients/lvccldkids/shoppingcart.pl?url=' + strCartUrl + '&sessionid=' + strSessionID + '&wf2host=' + strWf2Host;
  //return 'http://64.73.208.132:8080?url=' + escape(strCartUrl) + '&wf_cookies=SESSION_ID%3D' + strSessionID;
}
