// Text for other page elements - Overloading to change the 'VIEW' text
var langStrings = new Array();
lang_view_idx = 0;
lang_nextset_idx = 1;
lang_openurl_idx = 2;
lang_select_idx = 3;
lang_stats_idx = 4;
lang_hits_idx = 7;
lang_database_idx = 8;
lang_description_idx = 9;
lang_displaymode_idx = 10;
lang_previousset_idx = 11;

langStrings[lang_view_idx] = ["View Record", "Acreditar"];
langStrings[lang_nextset_idx] = ["Next&nbsp;Set...", "Pr&oacute;ximo&nbsp;Grupo..."];
langStrings[lang_openurl_idx] = ["OpenURL", "OpenURL"];
langStrings[lang_select_idx] = ["Select or un-select all", "Todos seleccionar"];
langStrings[lang_stats_idx] = ["Results <<first>> to <<last>> of <<total>>", "Resultado <<first>> a <<last>> ante <<total>>"];
langStrings[lang_hits_idx] = ["Hits", "Numerar"];
langStrings[lang_database_idx] = ["Database", "Venera"];
langStrings[lang_description_idx] = ["Description", "Descripci&oacute;n"];
langStrings[lang_displaymode_idx] = ["Results display mode", "Exhibici&oacute;n moda"];
langStrings[lang_previousset_idx] = ["Previous&nbsp;Set...", "Anterior&nbsp;Grupo..."];


function showHide(divID, visFlag)
{

//var divID = divID.replace(/&/g, "%26");
//var divID = divID.replace(/ /g, "%20");
//alert(divID);
  if (visFlag == 1)
  {
//alert(divID);
    document.getElementById(divID).style.visibility = 'visible';
    document.getElementById(divID).style.display = 'inline';
    document.getElementById(divID + '_desc').style.visiblity = 'hidden';
    document.getElementById(divID + '_desc').style.display = 'none';
  }
  else
  {

    document.getElementById(divID).style.visibility = 'hidden';
    document.getElementById(divID).style.display = 'none';
    document.getElementById(divID + '_desc').style.visibility = 'visible';
    document.getElementById(divID + '_desc').style.display = 'inline';
  }
}


function subshowHide(divID2, visFlag2)
{

//var divID = divID.replace(/&/g, "%26");
//var divID = divID.replace(/ /g, "%20");
//alert(divID);
  if (visFlag2 == 1)
  {
//alert(divID);
    document.getElementById(divID2).style.visibility = 'visible';
    document.getElementById(divID2).style.display = 'inline';
    document.getElementById(divID2 + '_desc').style.visiblity = 'hidden';
    document.getElementById(divID2 + '_desc').style.display = 'none';
  }
  else
  {

    document.getElementById(divID2).style.visibility = 'hidden';
    document.getElementById(divID2).style.display = 'none';
    document.getElementById(divID2 + '_desc').style.visibility = 'visible';
    document.getElementById(divID2 + '_desc').style.display = 'inline';
  }
}



function showDBsForCatNameClient(categoryName, descriptionText, nCols, omitDatabase, format, top)
{
  // Make sure everything is defined or the default

  var goodDbs = new Array();

  if(typeof(g_CheckboxTemplate) == 'undefined')
  {
    g_CheckboxTemplate = CHECKBOX_TEMPLATE_D;
  }

  if(typeof(g_CheckboxName) == 'undefined')
  {
    g_CheckboxName = 'Databases';
  }

  if (typeof(categoryName) == 'undefined')
  {
    categoryName = category[0][0][0];
  }

  if(typeof(descriptionText) == 'undefined')
  {
    descriptionText = '';
  }

  if(typeof(nCols) == 'undefined')
  {
    nCols = 1;
  }

  if(typeof(omitDatabase) == 'undefined')
  {
    omitDatabase = '';
  }

  if(typeof(format) == 'undefined')
  {
    format = '';
  }

  if(typeof(top) == 'undefined')
  {
    top = '';
  }

  if(typeof(anchors) == 'undefined')
  {
    var anchors = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
  }


  
  for (i=0; i< category.length; i++)
  {
    if (category[i][0][0] == categoryName)
    {
      var offset = 0;
      var dbCount = category[i][1].length;
      var goodCount = 0;

      for(j=0; j<category[i][1].length; j++)
      {
        wfname = category[i][1][j];
        for (k = 0; k < databaseList.length; k++)
        {
          if (databaseList[k][0] == wfname)
          {
            dbArray = databaseList[k];
            goodDbs[goodCount] = wfname;
            goodCount++;
          }
        }
      }

      if (typeof(nCols) != 'undefined')
      {
        if (nCols == 1)
        {
          offset = 0;
        }
        else
        {
          offset = Math.ceil((dbCount) / nCols);
        }
      }

      var useIdx = 0;
      var rowNum = 0;
      var colNum = 0;
      var count = 0;
      var shouldColor = 0;
      var text='';
      var textanchor='';
      var letterChange = 0;

      for (j = 0; j < goodDbs.length; j++)
      {
        if (offset != 0)
        {
          useIdx = (colNum * offset) + rowNum;
        }
        else
        {
          useIdx = j;
        }

        wfname = goodDbs[useIdx];

        for (k=0; k<databaseList.length; k++)
        {
          if (databaseList[k][0] == wfname)
          {
            dbArray = databaseList[k];
          }
        }

        if (count == 0)
        {
          if (offset % 2 == 0)
          {
            sTemplate = '<tr class="datarowson">' + g_CheckboxTemplate;
            currentColor = 'on';
          }
          else
          {
            sTemplate = '<tr class="datarowsoff">' + g_CheckboxTemplate;
            currentColor = 'off';
          }
        }
        else
        {
          sTemplate = g_CheckboxTemplate;
        }

        sCheckbox = '';
        sDBname = '';
        sDescLink = '';
        sNativeLink = '';

        wfName = dbArray[0];
        dbName = dbArray[1];
        sDBDesc = dbArray[5];
        sDBname = dbName;
        sIconDesc = dbArray[9];


        for (l = 0 ; l < anchors.length ; l++)
        {
          if (sDBname.charAt(0) == anchors[l])
          {
            if ( anchors[l] != "*" )
            {
              text = anchors[l];
              anchors[l]= "*" ;
              letterChange = 1;
            }
          break;
          }
        }

        if (dbArray[6] != '')
        {
          sNativeLink = '<a ';
          if (letterChange == 1)
          {
            sNativeLink += 'name="' + text + '" ';
            letterChange = 0;
          }
          sNativeLink += 'class=dblink href="' + dbArray[6] + '">';
        }
		
		
		
		
		
		

		sDescLink = '<a href="javascript:showHelp(\'help.html?Client_ID=' + Client_ID + '&wf_name=' + wfName;
		//sDescLink += '\');">' + descriptionText + '</a>';
		sDescLink += '\');">';
        if (descriptionText == '<<database name>>')
        {
			sDescLink += sDBname;
        }
        else
        {
			sDescLink += descriptionText;
        }
        sDescLink += '</a>';
		

		

        if (sDBname.indexOf('link only') >= 0)
        {
          sCheckbox = '<input type="checkbox" disabled>';
        }
        else
        {
			sCheckbox = '<input type="checkbox" onClick="javascript: dbFunction(this.value, this.checked);" name="' + g_CheckboxName + '" value="';
			if (dbArray[3] == 1) {
				sCheckbox += wfName + '" checked>';
			} else {
				sCheckbox += wfName + '">';
			}
		}

		var wfNameDesc = wfName + "_desc";
		sTemplate = sTemplate.replace(/<<dbNameDesc>>/g, wfNameDesc);
		sTemplate = sTemplate.replace(/<<dbName>>/g, wfName);
        sTemplate = sTemplate.replace(/<<checkbox>>/g, sCheckbox);
        sTemplate = sTemplate.replace(/<<database name>>/g, sDBname);
        sTemplate = sTemplate.replace(/<<description link>>/g, sDescLink);
        sTemplate = sTemplate.replace(/<<database description>>/g, sDBDesc);
        sTemplate = sTemplate.replace(/<<native link>>/g, sNativeLink);
        
        if (dbArray[11] != 2) {
        	sTemplate = sTemplate.replace(/<<auth desc>>/g, "<br><bean:message key='searchForm.authIncomplete'/>");
        } else {
	        sTemplate = sTemplate.replace(/<<auth desc>>/g, "");
	    }                        

        for (p = 0;p < format.length ; p++)
        {
          if (sDBname.charAt(0) == format[p] && format[p]!="*")
          {
            format[p]="*";
            document.write(top);
            break;
          }
        }

        document.write(sTemplate);

        count++;

        if (offset != 0)
        {
          if (colNum == (nCols - 1))
          {
            colNum = 0;
            rowNum++;
            document.write('</tr>');

            if(currentColor == 'off')
            {
              document.write('<tr class="datarowson">');
              currentColor = 'on';
            }
            else
            {
              document.write('<tr class="datarowsoff">');
              currentColor = 'off';
            }
          }
          else
          {
            colNum++;
          }
        }
        else
        {
          document.write('</tr>');
          if(currentColor == 'off')
          {
            document.write('<tr class="datarowson">');
            currentColor = 'on';
          }
          else
          {
            document.write('<tr class="datarowsoff">');
            currentColor = 'off';
          }
        }
      }
      break;
    }
  }
}



//Handles popup with DB list in advSearch.asp
function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
  var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
  var int_windowTop = (screen.height - a_int_windowHeight) / 2;
  var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
  var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
    if (parseInt(navigator.appVersion) >= 4) {
      obj_window.window.focus();
    }
}

function showSubjectListClient(subjectOmit, descriptionText, subjectOnly, categoryClick, nCols)
{
  var subSelIdx = 0;
  //Find number of categories to show
  var numCategories = category.length;
  var categoryStr ='';
  var offset = 0;
  var useIdx = 0;
  var rowNum = 0;
  var colNum = 0;
  var currIdx = 0;

  // Use the default template if g_SubjectTemplate is not set
  if(typeof(g_SubjectTemplate) == 'undefined') {
    g_SubjectTemplate = MAIN_SUBJECT_T;
  }

  // Use the default template if g_SubjectDatabaseTemplate is not set
  if(typeof(g_SubjectDatabaseTemplate) == 'undefined') {
    g_SubjectDatabaseTemplate = SUBJECT_DATABASE_T;
  }

  // Use the default template if g_SubjectDatabaseTemplate is not set
  if(typeof(subjectOnly) == 'undefined') {
    subjectOnly = true;
  }

  if (typeof(subjectOmit) == 'undefined') {
    subjectOmit = '';
  }

  if (typeof(descriptionText) == 'undefined') {
    descriptionText = '';
  }

  if (typeof(nCols) == 'undefined') {
    nCols = 1;
  }

  if (subjectOmit.indexOf('^') > 0) {
    var omitArray = subjectOmit.split('^');
  }

  for (i=0; i<category.length; i++)
  {
    // Added to allow parsing of ^-delimited omit lists
    if (omitArray != null)
    {
      for (x = 0; x < omitArray.length; x++)
      {
        if (category[i][0][0] == omitArray[x])
        {
          numCategories--;
        }
      }
    }
    else
    {
      if (subjectOmit.indexOf(category[i][0][0]) >= 0)
      {
        numCategories--;
      }
    }
    categoryStr += i + ':' + category[i][0][0] + ' ';
  }

  if (typeof(nCols) != 'undefined')
  {
    offset = Math.ceil(numCategories / nCols);
  }
  if (nCols == 1)
  {
    offset = 0;
  }

  document.write('<td class="arrowcell" colspan="2" rowspan="2" width="50%">');

  // Loop through the category array to build the page

  var catCount = 0;
  var skipCat = 0;

  for (i=0; i<category.length; i++)
  {
    var subSelBegin = subSelIdx;
    var subSelEnd = subSelIdx;

    if (typeof(category[i][1]) == 'undefined') {
    	continue;
    }
        
    if (omitArray != null)
    {
      for (x = 0; x < omitArray.length; x++)
      {
        if (category[i][0][0] == omitArray[x])
        {
          skipCat = 1;
        }
      }
    }
    else
    {
      if (subjectOmit.indexOf(category[i][0][0]) >= 0)
      {
        skipCat = 1;
      }
    }
	
    if (skipCat == 1)
    {
      skipCat = 0;
      continue;
    }
    catCount++;

    catName = category[i][0][0];
    catId = category[i][0][5];
	//if (catId != 0)
	//{
		//descLink = '<a style="{text-decoration: underline; color: white }" href="javascript:showCategory(\'showCategory.do?catId=' + catId + '\')">'+catName + '</a>';
		//catName = descLink;
	//}

    wfSubNames = '';


	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
   // else
   // {
      // document.write('<br><div class=wfcatbot></div>');
      //document.write('<br>');
   // }
    
    // Build the complete subject wf_name list first
    for (j=0; j<category[i][1].length; j++)
    {
      wfSubNames += ',' + category[i][1][j];
      subSelEnd++;
    }

    wfSubNames = wfSubNames.substr(1);    

    sTemplate = g_SubjectTemplate;
    sCheckbox = '';
	
    if (subjectOnly)
    {
      if (categoryClick)
      {
        // Get the subcategory and checkbox
        var subcat_array = "";
        var subcat  = "cat" + i;
				
        eval("if (typeof(" + subcat + ") != 'undefined')" + "	subcat_array = " + subcat);        
		//This latest fix is to help make the categories and DB checkboxes work together
		
			//If you need to check a category by default, enable this IF block
		//if (catName == "All Express Databases")
		//{
		//sCheckbox = '<input type="checkbox" CHECKED title="Check box to include in search" name="CheckAll" value="';
        //sCheckbox += wfSubNames + '"';
		//sCheckbox += ' onClick="javascript:chkSubject(this.value,this.checked);">';
		
		//checkCatIndices[checkCatCount] = i;
		//checkCatCount++;
		//}
		//else
		//{
		sCheckbox = '<input type="checkbox" title="Check box to include in search" name="CheckAll" value="';
        sCheckbox += wfSubNames + '"';
        //sCheckbox += ' onClick="javascript:chkSubject(this.value,this.checked);" onClick="javascript:catFunction('+ currIdx +',this.checked,\'' + subcat + '\',1);">';
		//Trying to fix this call so subcats will function again
		//sCheckbox += ' onClick="javascript:chkSubject(this.value,this.checked,'+ currIdx +',\'' + subcat + '\',1);">'

		 sCheckbox += ' onClick="javascript:catFunction('+ currIdx +',this.checked,\'' + subcat + '\',1);">';
		//}
		}

      else
      {
	  var subcat_array = "";
        sCheckbox = '<input type="checkbox" title="Check box to include in search" name="Databases" value="';
        sCheckbox += wfSubNames + '">';
      }
 }
    else
    {
      sCheckbox = '<input type="checkbox" title="Check box to include in search" name="CategoryBoxes" value=""';
      sCheckbox += ' onClick="subSel(' + subSelBegin + ',' + subSelEnd;
      sCheckbox += ', this.checked)">';
    }
    currIdx++;
	
	


    // Set the Index for the next group
    subSelIdx = subSelEnd;

    eval("WFSign" + i + "='+'");
    var noSubcats = 0;
    eval("if (typeof(" + subcat + ") == 'undefined')" + "  noSubcats = 1");
    if (noSubcats == 0)
    {
		if(subcat_array.length > 0)
		{
			sTemplate = sTemplate.replace(/<<category image>>/g,
				"<a href=\"JavaScript:showHideLayer('WFDB" + i + "');JavaScript:swap('WFSign" + i + "')\">" +
				"<IMG class=\"arrowbutton\"" +
				"src=\"images/plus_on.gif\" name=\"WFSign" + i + "\"></a>");
		}
		else
		{
			sTemplate = sTemplate.replace(/<<category image>>/g, "");
		}
			
    }
    else
    {
      sTemplate = sTemplate.replace(/<<category image>>/g,"");
    }
    sTemplate = sTemplate.replace(/<<checkbox>>/g, sCheckbox);
	
	
	

	 //if (catCount > 1)
	// document.write("catName is: " + catName);
     if (catName == "Anthropology")
      {
        document.write('</td>');
        document.write('<td class="arrowcell" colspan="2" rowspan="2" width="50%">');
      }
    
	
	
	
	
	
		var catGrouping = '';
				if (catName == "QuickSearch")
	{
	catGrouping = "<BR>&nbsp;&nbsp;<B>ARTICLE EXPRESS</B><BR>";
	sTemplate = sTemplate.replace(/<<catGrouping>>/g, catGrouping);
	}
	else
		if (catName == "Art & Architecture")
	{
	catGrouping = "<BR>&nbsp;&nbsp;<B>ARTS AND HUMANITIES</B><BR>";
	sTemplate = sTemplate.replace(/<<catGrouping>>/g, catGrouping);
	}
	
	//else
	//if (catName == "Classics & Archaeology")
	//{
	//catGrouping = "<BR>&nbsp;&nbsp;<B>HUMANITIES</B><BR>";
	//sTemplate = sTemplate.replace(/<<catGrouping>>/g, catGrouping);
	//}
	
	else
		if (catName == "Astronomy")
	{
	catGrouping = "<BR>&nbsp;&nbsp;<B>SCIENCES, ENGINEERING, AND MEDICINE</B><BR>";
	sTemplate = sTemplate.replace(/<<catGrouping>>/g, catGrouping);
	}
	else
		if (catName == "Anthropology")
	{
	catGrouping = "<BR>&nbsp;&nbsp;<B>SOCIAL SCIENCES</B><BR>";
	sTemplate = sTemplate.replace(/<<catGrouping>>/g, catGrouping);
	}
	else
		if (catName == "African & African American Studies")
	{
	catGrouping = "<BR>&nbsp;&nbsp;<B>INTERDISCIPLINARY AREAS</B><BR>";
	sTemplate = sTemplate.replace(/<<catGrouping>>/g, catGrouping);
	}
		else
		if (catName == "Audio Visual Media")
	{
	catGrouping = "<BR>&nbsp;&nbsp;<B>MATERIAL TYPE</B><BR>";
	sTemplate = sTemplate.replace(/<<catGrouping>>/g, catGrouping);
	}
	else
		{
	catGrouping = "";
	sTemplate = sTemplate.replace(/<<catGrouping>>/g, catGrouping);
	}
	

	var newCatName = '';
	 newCatName = catName.replace(/&/g, "%26");
	//newCatName = catName.replace(/ /g, "%20");
	
    //sTemplate = sTemplate.replace(/<<category name>>/g, "<font class=\"categorytitle\">" + catName + "</font>");
	//sTemplate = sTemplate.replace(/<<category name>>/g, "<font class=\"categorytitle\">" + catName + " <A HREF=\"javascript:displayWindow('showDBs.asp?catName=" + newCatName + "',400,500)\"> ?</A></font>");
    //sTemplate = sTemplate.replace(/<<category name>>/g, "<font class=\"categorytitle\"><A TARGET='_blank' HREF=\"showDBs.asp?catName=" + newCatName + "&subcatName=none\">" + catName + "</A></font>");
	
	sTemplate = sTemplate.replace(/<<category name>>/g, "<TABLE BORDER='0' CELLPADDING='1' CELLSPACING='0' WIDTH='100%'><TR><td width='60%'><font class=\"categorytitle\">" + catName + "</TD><TD ALIGN='LEFT'><a href=\"showDBs.asp?catName=" + newCatName + "\" onclick=\"newWindow(this.href, 'popup', 400, 500, 1, 1, 0, 0, 1, 1, 0); return false;\" target=\"_blank\"><IMG SRC='images/query.gif' BORDER='0' title=\"what's in here?\"></A></FONT></TD></TR></TABLE>");
	
	
	//Adding this check so we can manipulate the columns better.  If a heading does not appear in the proper place, position one of the three insert categories properly in the WAC, and you can change how things look.
	if ((catName == "insert1") || (catName == "insert2") || (catName == "insert3") || (catName == "insert4") || (catName == "insert5"))
	{
	document.write("<BR>");
	}
	else
	{
    document.write(sTemplate);
	}
	

    for (p=0; p<subcat_array.length; p++)
    {
      sSubTemplate = MAIN_SUBSUBJECT_T;
      sSubTemplate = sSubTemplate;
      sSubCheckbox = '<input type="checkbox" title="Check box to include in search" name="CheckSubAll" value="';
      sSubCheckbox += p + ':::' + subcat + ':::' + i + '"';
      sSubCheckbox += ' onClick="javascript:catFunction('+ p +', this.checked, \''+ subcat +'\', 0);">';

      sSubTemplate = sSubTemplate.replace(/<<subcheckbox>>/g, sSubCheckbox);
      //sSubTemplate = sSubTemplate.replace(/<<subcategory name>>/g, subcat_array[p][0][0]);
	  var newSubCat = subcat_array[p][0][0].replace(/&/g, "%26");
	  sSubTemplate = sSubTemplate.replace(/<<subcategory name>>/g, "<TABLE BORDER='0' CELLPADDING='1' CELLSPACING='0' WIDTH='100%'><TR><td width='100%'><font class=\"categorytitle\">" + subcat_array[p][0][0] + "</TD> <TD ALIGN='LEFT'><a href=\"showDBSubcats.asp?catName=" + newCatName + "&subcategory=" + newSubCat + "\" onclick=\"newWindow(this.href, 'popup', 400, 500, 1, 1, 0, 0, 1, 1, 0); return false;\" target=\"_blank\"> <IMG SRC='images/query.gif' BORDER='0' title=\"what's in here?\"> </A></FONT></TD></TR></TABLE>");
	  
	  document.write("<div class=\"subcategorytitle\" id=\"WFDB" + i + "\">" + sSubTemplate + "</div>");
			
    }

    if (rowNum == (offset - 1))
    {
      rowNum = 0;
    }
    else
    {
      rowNum++;
    }
  }
  document.write('</td>');
}


	


	
	
	//Need this function for Basic Page so we can specify 5 categories to show
	function showSubjectListClientBasic(subjectOmit, descriptionText, subjectOnly, categoryClick, nCols)
{
  var subSelIdx = 0;
  //Find number of categories to show
  var numCategories = category.length;
  var categoryStr ='';
  var offset = 0;
  var useIdx = 0;
  var rowNum = 0;
  var colNum = 0;
  var currIdx = 0;

  // Use the default template if g_SubjectTemplate is not set
  if(typeof(g_SubjectTemplate) == 'undefined') {
    g_SubjectTemplate = MAIN_SUBJECT_T;
  }

  // Use the default template if g_SubjectDatabaseTemplate is not set
  if(typeof(g_SubjectDatabaseTemplate) == 'undefined') {
    g_SubjectDatabaseTemplate = SUBJECT_DATABASE_T;
  }

  // Use the default template if g_SubjectDatabaseTemplate is not set
  if(typeof(subjectOnly) == 'undefined') {
    subjectOnly = true;
  }

  if (typeof(subjectOmit) == 'undefined') {
    subjectOmit = '';
  }

  if (typeof(descriptionText) == 'undefined') {
    descriptionText = '';
  }

  if (typeof(nCols) == 'undefined') {
    nCols = 1;
  }

  if (subjectOmit.indexOf('^') > 0) {
    var omitArray = subjectOmit.split('^');
  }

  for (i=0; i<category.length; i++)
  {
  
  
  
  		if (category[i][0][0] == "History")
	{
	skipCat = 0;
	continue;
	//document.write("<BR>" + category[i][0][0] + "<BR>");
	}
	


	
		

	
	
	
    // Added to allow parsing of ^-delimited omit lists
    if (omitArray != null)
    {
      for (x = 0; x < omitArray.length; x++)
      {
        if (category[i][0][0] == omitArray[x])
        {
          numCategories--;
        }
      }
    }
    else
    {
      if (subjectOmit.indexOf(category[i][0][0]) >= 0)
      {
        numCategories--;
      }
    }
    categoryStr += i + ':' + category[i][0][0] + ' ';
  }

  if (typeof(nCols) != 'undefined')
  {
    offset = Math.ceil(numCategories / nCols);
  }
  if (nCols == 1)
  {
    offset = 0;
  }

  document.write('<td width="30%" class="arrowcell">');

  // Loop through the category array to build the page

  var catCount = 0;
  var skipCat = 0;

  for (i=0; i<category.length; i++)
  {
    var subSelBegin = subSelIdx;
    var subSelEnd = subSelIdx;
    
    if (typeof(category[i][1]) == 'undefined') {
    	continue;
    }
        
    if (omitArray != null)
    {
      for (x = 0; x < omitArray.length; x++)
      {
        if (category[i][0][0] == omitArray[x])
        {
          skipCat = 1;
        }
      }
    }
    else
    {
      if (subjectOmit.indexOf(category[i][0][0]) >= 0)
      { 
        skipCat = 1;
      }
    }

    	    
    if (skipCat == 1)
    {
      skipCat = 0;  
      continue;
    }
    catCount++;;
    catName = category[i][0][0];
    catId = category[i][0][5];
    		
    wfSubNames = '';

    if (rowNum == 0)
    {
      if (catCount > 1)
      {
        document.write('</td>');
        document.write('<td width="30%" class="arrowcell">');
      }
    }
        

    // Build the complete subject wf_name list first
    for (j=0; j<category[i][1].length; j++)
    {
      wfSubNames += ',' + category[i][1][j];
      subSelEnd++;
    }

    wfSubNames = wfSubNames.substr(1);

    sTemplate = g_SubjectTemplate;
    sCheckbox = '';

    if (subjectOnly)
    {
      if (categoryClick)
      {
        // Get the subcategory and checkbox
        var subcat_array = "";
        var subcat  = "cat" + i;
				
        eval("if (typeof(" + subcat + ") != 'undefined')" + "	subcat_array = " + subcat);

        sCheckbox = '<input type="checkbox" title="Check box to include in search" name="CheckAll" value="';
        sCheckbox += wfSubNames + '"';
        sCheckbox += ' onClick="javascript:catFunction('+ currIdx +',this.checked,\'' + subcat + '\',1);">';
      }
      else
      {
        var subcat_array = "";
        sCheckbox = '<input type="checkbox" title="Check box to include in search" name="Databases" value="';
        sCheckbox += wfSubNames + '">';
      }
    }
    else
    {
      sCheckbox = '<input type="checkbox" title="Check box to include in search" name="CategoryBoxes" value=""';
      sCheckbox += ' onClick="subSel(' + subSelBegin + ',' + subSelEnd;
      sCheckbox += ', this.checked)">';
    }
    currIdx++;

    // Set the Index for the next group
    subSelIdx = subSelEnd;

    eval("WFSign" + i + "='+'");
    var noSubcats = 0;
    eval("if (typeof(" + subcat + ") == 'undefined')" + "  noSubcats = 1");
    if (noSubcats == 0)
    {
		if(subcat_array.length > 0)
		{
			sTemplate = sTemplate.replace(/<<category image>>/g,
				"<a href=\"JavaScript:showHideLayer('WFDB" + i + "');JavaScript:swap('WFSign" + i + "')\">" +
				"<IMG class=\"arrowbutton\"" +
				"src=\"/images/plus_on.gif\" name=\"WFSign" + i + "\"></a>");
		}
		else
		{
			sTemplate = sTemplate.replace(/<<category image>>/g, "");
		}
			
    }
    else
    {
      sTemplate = sTemplate.replace(/<<category image>>/g,"");
    }
    sTemplate = sTemplate.replace(/<<checkbox>>/g, sCheckbox);
    sTemplate = sTemplate.replace(/<<category name>>/g, "<font class=\"categorytitle\">" + catName + "</font>");
	//sTemplate = sTemplate.replace(/<<category name>>/g, "<font class='mywflink'>" + catName + "<A HREF='#' CLASS=\"mywflink\" onclick=\"listDBs('" + catName + "','test')\">? What's in here</A>");


    document.write(sTemplate);

	
    for (p=0; p<subcat_array.length; p++)
    {
      sSubTemplate = MAIN_SUBSUBJECT_T;
      sSubTemplate = sSubTemplate;
      sSubCheckbox = '<input type="checkbox" title="Check box to include in search" name="CheckSubAll" value="';
      sSubCheckbox += p + ':::' + subcat + ':::' + i + '"';
      sSubCheckbox += ' onClick="javascript:catFunction('+ p +', this.checked, \''+ subcat +'\', 0);">';
	  
	  var newSubcat = subcat_array[p][0][0].replace(/&/g, "%26");

      sSubTemplate = sSubTemplate.replace(/<<subcheckbox>>/g, sSubCheckbox);
      sSubTemplate = sSubTemplate.replace(/<<subcategory name>>/g, subcat_array[p][0][0]);
	  //sSubTemplate = sSubTemplate.replace(/<<subcategory name>>/g, "" + subcat_array[p][0][0] + "<A HREF='#' CLASS=\"mywflink\" onclick=\"listDBs('" + catName + "','" + subcat_array[p][0][0] + "','test')\">? What's in here</A>");
	  
	  document.write("<div class=\"subcategorytitle\" id=\"WFDB" + i + "\">" + sSubTemplate + "</div>");			
    }

    if (rowNum == (offset - 1))
    {
      rowNum = 0;
    }
    else
    {
      rowNum++;
    }
  }
  document.write('</td>');
}



function showLetterLinks()
{
  var found = 0;
    //var letterArray = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
  var letterArray = new Array('A','B','C','D','E','F','G','H-K','L','M','N','O-Q','R','S','T-Z');
  var letterArrayDisplay = new Array('A','B','C','D','E','F','G','H-K','L','M','N','O-Q','R','S','T-Z');
	
  for (i = 0; i < letterArray.length; i++)
  {
  
      letterArray[i] = letterArray[i].substr(0, 1);

    for (j = 0; j < databaseList.length; j++)
    {
      if (databaseList[j][1] != '' && databaseList[j][1].substring(0, 1).toUpperCase() == letterArray[i]) 
      {
        found = 1;
      }     
    }
    if (found == 1)
    {
      document.write('<a href="#' + letterArray[i] + '" class="nameLink">' + letterArrayDisplay[i] + '</a>');
    }
    else
    {
      document.write(letterArray[i]);
    }
    if (letterArray[i] != 'Z')
    {
	  document.write(' | ');
    }
    found = 0;
  }
}  



//The rest of these functions are somewhat specific to the Results page
function makeScoreboardHeader()
{
  var temp = '<td class="SBhead" valign="top" align="right" width="10%"><a class="SBhead" href="#WF" onClick="wfToggleSortSBTotalDM()">' + langStrings[lang_hits_idx][lang] + '</a></td>';
 temp += '<td class="SBhead" valign="top" align="left" WIDTH="50"><a class="SBhead" href="#WF" onClick="wfToggleSortSBName()">' + langStrings[lang_database_idx][lang] + '</a></td>';
  temp += '<tr><td colspan="2" VALIGN="TOP"><HR WIDTH="100%" SIZE="1" COLOR="#dddddd"></td>';
  return temp;
}



//----------------------------------------------------------------------
// Toggle the scoreboard sort order for total hits - Overloading so clicking HITS the first time will sort by most DBs
//----------------------------------------------------------------------

var wfbSBTotalAscending = 0;

function wfToggleSortSBTotalDM()
{
  if (wfbSBTotalAscending) {
    wfScore.sort(wfCompareTotal);
    wfbSBTotalAscending = 1;
  } else {
    wfScore.sort(wfCompareTotalR);
    wfbSBTotalAscending = 0;
  }

  if (wfbSBLinked) {
    wfWriteScoreboard(true);
  } else {
    wfWriteScoreboard(false);
  }
}



function addGroupNEW(n)
{
  lang = 2 // For italian
  if (!document.getElementById("WFsb2")) {
    return;
  }

  var wfName = grp[n][grp_wfname_idx];
  //alert ("addGroup: wf_name: " + wfName);

  // get database's display name
  var displayName = getDisplayName(wfName, grp[n][grp_dbname_idx]);
  //alert ("addGroup:  display name: " + displayName);

  // add a scoreboard entry if this is a new database being displayed
  if ( findWfNameInScoreboard(wfName) == -1 ) {
  
      // We need to strip this name out of the list of bad databases
    for (i = 0; i < stripArray.length; i++) {
      if (stripArray[i] == wfName) {
        stripArray[i] = 'null';
      }
    }
	
    // Add a new score object
    wfScore[++wfScoreIdx] = new WFScore(n, wfName, displayName, grp[n][grp_totaltally_idx]);

    // Update the scoreboard
    wfWriteScoreboard(true);
  }

  if (!document.getElementById("WFX_RESULTS_ELEMENT")) {
    return;
  }

  var resultsElement = document.getElementById("WFX_RESULTS_ELEMENT");

  // add this group to the group list by wfName array
  // if the database previously exists in the list, it's position is returned
  var grpWfNameIndex = addGrpWfName(n);

  // create group id
  var groupid = "wfgroup" + grpWfNameIndex;

  // create group data
  // note that all groups of this wfName are made here
  var temp = makeDisplayGroupSet(grpWfNameIndex);
  
  //alert("addGroup: groupExists: " + document.getElementById(groupid));
  // if this is a new group, make an anchor and create the group div
  if (document.getElementById(groupid) == null || 
  	typeof(document.getElementById(groupid)) == 'undefined') {
    // Create an anchor
    resultsElement.innerHTML += '<a name="' + wfName + '"></a>';
  	resultsElement.innerHTML += '<div id="' + groupid + '" class="resappear">' + temp + '</div>';

    // make the current subgroup visible
    showDivById('wfsubgroup' + n, true);

  // if the group div already exists, replace the group display in it
  } else {
    document.getElementById(groupid).innerHTML = temp;

    // make the latest subgroup visible
    var lastGrpIdxPos = grpWfName[grpWfNameIndex][1].length - 1;
    var lastGrpIdx = grpWfName[grpWfNameIndex][1][lastGrpIdxPos];
    document.getElementById('wfsubgroup' + lastGrpIdx).style.display = "block";
  }

  // Make this visible if we're currently in "Grouped" display mode
  if (currDisplayMode == "grouped") {
    showDivById(groupid, true);
  }

}



//----------------------------------------------------------------------
// Required function: Register and display a new result set group
//----------------------------------------------------------------------
function addGroup(n)
{
  //alert ("addGroup: " + n);

  if (!document.getElementById("WFsb2")) {
    return;
  }

  var wfName = grp[n][grp_wfname_idx];
  //alert ("addGroup: wf_name: " + wfName);

  // get database's display name
  var displayName = getDisplayName(wfName, grp[n][grp_dbname_idx]);
  //alert ("addGroup:  display name: " + displayName);

  // add a scoreboard entry if this is a new database being displayed
  if ( findWfNameInScoreboard(wfName) == -1 ) 
  {
   //if (typeof(stripArray) != 'undefined') 
   // {   
      // We need to strip this name out of the list of bad databases
	  for (i = 0; i < stripArray.length; i++) 
	  {
	    if (stripArray[i] == wfName) 
		{
	    	stripArray[i] = 'null';
	  	}
	  }
	//}  
  
    // Add a new score object
    wfScore[++wfScoreIdx] = new WFScore(n, wfName, displayName, grp[n][grp_totaltally_idx]);

    // Update the scoreboard
    wfWriteScoreboard(true);
  }
  
  if (!document.getElementById("WFX_RESULTS_ELEMENT")) {
    return;
  }

  var resultsElement = document.getElementById("WFX_RESULTS_ELEMENT");
  // add this group to the group list by wfName array
  // if the database previously exists in the list, it's position is returned
  var grpWfNameIndex = addGrpWfName(n);

  // create group id
  var groupid = "wfgroup" + grpWfNameIndex;

  //alert ("addGroup: grpWfNameIndex: " + grpWfNameIndex + ", groupid: " + groupid);

  // create group data
  // note that all groups of this wfName are made here
  var temp = makeDisplayGroupSet(grpWfNameIndex);

  //alert("addGroup: groupExists: " + document.getElementById(groupid));
  // if this is a new group, make an anchor and create the group div
  if (document.getElementById(groupid) == null || 
  	typeof(document.getElementById(groupid)) == 'undefined') {
    // Create an anchor
    resultsElement.innerHTML += '<a name="' + wfName + '"></a>';
	resultsElement.innerHTML += '<div id="' + groupid + '" class="resappear">' + temp + '</div>';

    // make the current subgroup visible
    showDivById('wfsubgroup' + n, true);

  // if the group div already exists, replace the group display in it
  } else {

    document.getElementById(groupid).innerHTML = temp;

    // make the latest subgroup visible
    var lastGrpIdxPos = grpWfName[grpWfNameIndex][1].length - 1;
    var lastGrpIdx = grpWfName[grpWfNameIndex][1][lastGrpIdxPos];
    document.getElementById('wfsubgroup' + lastGrpIdx).style.display = "block";
  }

  // Make this visible if we're currently in "Grouped" display mode
  if (currDisplayMode == "grouped") {
    showDivById(groupid, true);
  }
}


// Writing diags to the scoreboard

function wfUpdateSBDiags()
{
  var prevSB = document.getElementById("WFsb2").innerHTML;
  var diagFound = 0;
 
  var newSB = '';
  var innerStr = '';
  
  for (i = 0; i < stripArray.length; i++)
  {
    if (stripArray[i] != 'null')
    {
      innerStr += '<tr>' + makeSBDiagRow(stripArray[i]) + '</tr>';
      diagFound = 1;
    }
  }
  if (diagFound == 1)
  {
    newSB = '<table border="0" width="100%" cellpadding=0 cellspacing=0>' + innerStr;
    newSB += '<tr><td colspan="2" VALIGN="TOP"><HR WIDTH="100%" SIZE="1" COLOR="#dddddd"></td>';
	
	
	if (wf_nextset == "no")
	{
    newSB += '<tr><td colspan="2" class="SBCol" align="center">*Resource temporarily unavailable</td></tr>';
	}
	
	else
	
	{
	newSB += '<tr><td colspan="2" class="SBCol" align="center">*Click Back key to go back to original search</td></tr>';
	}
	
	
    prevSB += newSB + '</table>';
    document.getElementById("WFsb2").innerHTML = prevSB;
  }  
}

// Writing individual diag rows

function makeSBDiagRow(wfName)
{
  for (x = 0; x < databaseList.length; x++)
  {
    if (databaseList[x][0] == wfName)
    {
      dbName = databaseList[x][1];
    }
  }
  var temp = '<td class="wfsbdata0" colspan="2" class="SBCol" valign="top" align="left">*' + dbName + '</td>';
  return temp;
}

      
//----------------------------------------------------------------------
// returns the scoreboard data header
//----------------------------------------------------------------------
function makeScoreboardRow(bLinked, i)
{
  var rowClass = "wfsbdata" + i % 2;

  var temp = '<tr>';
  temp += '<td class="' + rowClass + '" valign="top" align="right"><font class="sbText"><<count>>&nbsp;&nbsp;</td>';
  if (bLinked) {
    temp += '<td class="' + rowClass + '" valign="top" align="left"><a class="SBCol" href="#<<wf name>>"><font class="sbText"><<db name>></a></td>';
  } else {
    temp += '<td class="' + rowClass + '" valign="top" align="left"><span class="SBCol"><font class="sbText"><<db name>></span></td>';
  }

  temp += '</tr>';
  
  temp = temp.replace(/<<wf name>>/g, wfScore[i].WFname);
  temp = temp.replace(/<<db name>>/g, wfScore[i].DisplayName);
  temp = temp.replace(/<<count>>/g, wfScore[i].Total);
  
  return temp;
}





function wfWriteScoreboard(bLinked)
{
  if (!bUseScoreboard) {
    return;
  }

  // Update the mode setting
  if (bLinked) {
    wfbSBLinked = true;
  } else {
    wfbSBLinked = false;
  }

  var i;
  var temp = '';
  temp += '<table border="0" width="285" cellpadding=0 cellspacing=0>';
  temp += '<tr>' + makeScoreboardHeader() + '</tr>';

  for (i = 0; i < wfScore.length; ++i) {
    temp += makeScoreboardRow(bLinked, i);
  }

  temp += '</table>';

  if (document.getElementById("WFsb2")) {
    document.getElementById("WFsb2").innerHTML = temp;
  }
}



function setCatName()
{
  //Adding these three lines so we can create a cookie out of the category name and use that as the default selection on the Results page
  selectedCatName = document.wfform.Databases.options[document.wfform.Databases.selectedIndex].text;
selectedCatName = selectedCatName.replace(/\&/g, '%26');
  document.cookie = 'selectedCatName=' + selectedCatName + '; Path=/';
  
  //alert(selectedCatName);
  }
  
  
//Adding this so we can delete the databases cookie when the category drop-down on the Results page is used
function deleteCookie(cookieName)
{
  var theDate = new Date();
  var yesterdayDate = new Date(theDate.getTime() - 86400);
  document.cookie= cookieName + "=;Path=/;Expires=" + yesterdayDate.toGMTString();
  
  //alert("wfterm1 is now: " + cookieName);
}


//Providing category drop-down list on Results page
function showResultsCategoryBox(selectName, categoryOmit)
{
var selectedCatName26 = getCookie('selectedCatName');
 //selectedCatName26 = selectedCatName26.replace(/\+/g, '');
var sSelectedDatabases = getCookie('wf_selected_databases');

//alert("categoryOmit: " + categoryOmit);
//document.write('<select name="' + selectName + '" onchange="' + setCatName() + '">');
	document.write('<select name="' + selectName + '">');
//document.write('<option selected>Choose a Category</option>');

//alert(sSelectedDatabases);


if (selectedCatName26 == null)
{
var catDisplayMSG = "User Selected Resources";
document.write('<option selected value="' + sSelectedDatabases + '">' + catDisplayMSG + '</option>');
}
else
{
document.write('<option selected value="' + sSelectedDatabases + '">' + selectedCatName26 + '</option>');
}


	for (i=0; i< category.length; i++)
	{
	
	
		if (categoryOmit.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 value="' + sOptionValue + '">');
		//document.write(sOptionText + '</option>\n');
		document.write(sOptionText + '</option>\n');
	}
	document.write('</select>');
}




//Works with showCategoryBox
function processSearch(theForm) {
var selectedCatName = '';
selectedCatName = theForm.Databases.options[theForm.Databases.selectedIndex].text;
selectedCatName = selectedCatName.replace(/\&/g, '%26');
  var wf_term1 = '';
  wf_term1 = theForm.q.value;
  if (wf_term1 == '')
  {
    alert('Please enter a search term!')
    return false;
  }
  wf_term1 = wf_term1.replace(/\"/g, '');
  wf_term1 = wf_term1.replace(/\'/g, '');
  
  var dbs = theForm.Databases.value;
  var nexturl = '';

  nexturl = '?Command=Search&Client_ID=dartmou&BypassSessData=yes&noserial=1&format=JS&rtmpl=js&wf_field1=wf_keyword&wf_term1=' + wf_term1;
  nexturl += '&Databases=' + theForm.Databases.value;
  nexturl = nexturl.replace(/\&/g, '%26');

  //Adding these three lines so we can create a cookie out of the category name and use that as the default selection on the Results page
  document.cookie = 'selectedCatName=' + selectedCatName + '; Path=/';
  
  document.write('<div style="visibility: hidden">');
    document.write('<form name="wfform" action="http://wfxsearch.webfeat.org/wfsearch/search" method="GET">');
    document.write('<input type="hidden" name="Command" value="Search">');
    document.write('<input type="hidden" name="Client_ID" value="10340">');
    document.write('<input type="hidden" name="rtmpl" value="wfx_ui2.jsp">');
    document.write('<input type="hidden" name="format" value="JS">');       
    document.write('<input type="hidden" name="utf-8" value="wf_codeset">');    
    document.write('<input type="hidden" name="noserial" value="1">');
	
	   document.write('Enter term: <input type="text" name="wf_term1" size="20" value="' + wf_term1 + '"">');
    document.write('<input type="hidden" name="wf_field1" value="wf_keyword">');
	document.write('<input type="hidden" name="wf_all_years" value="yes">'); 
	document.write('<input type="hidden" name="Databases" value="' + dbs + '">');
	
	document.write('<input type="hidden" name="selectedCatName" value="' + selectedCatName + '">'); 
	
	document.write('<input type="submit" value="sendit">');
	document.write('</form>');
	
	document.write('</div>');
	
	document.wfform.submit();
  
  return false;
}




//New customized QuickSearch form that will allow client to change appearance - This one does not sort the category drop-down items in the same order as they are put in the function call.
function showCategoryBoxOLD(selectName, categoryOmit, categorySelect)
{
document.write('<form onsubmit="return processSearch(this);">');
document.write('<table class="search360ot" >');
document.write('<tr><td valign="middle" align="left">');
document.write('<input type="text" name="q" id="q" size="20" maxlength="255" value="" /> ');

//document.write("categorySelect: " + categorySelect);


document.write('<select name="' + selectName + '">');

	for (i=0; i< category.length; i++)
	{
	if (categoryOmit.indexOf(category[i][0][0]) >= 0)
			continue;
			
	if (categorySelect.indexOf(category[i][0][0]) >= 0)
		
{
		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);

		//Adding check for any categories which may come up because they share the same word as the Express ones
		//if (sOptionText == "Engineering")
		//{
		//}
		//else
		//{
		document.write('<option value="' + sOptionValue + '"');
		//if (categorySelect == category[i][0][0])
		//{
		//	document.write(' selected="selected"');
		//}
		document.write('>');
		document.write(sOptionText + '</option>\n');
		//}

	}
	}
document.write('</select>');
document.write(' <input type="submit" value="Search">');
document.write('</td>');
document.write('</tr></table></form>');

}








//This version does order the categories according to the order of the function call
function showCategoryBox(selectName, categoryOmit, categorySelect)
{
document.write('<form onsubmit="return processSearch(this);">');
document.write('<table class="search360ot" >');
document.write('<tr><td valign="middle" align="left">');
document.write('<input type="text" name="q" id="q" size="20" maxlength="255" value="" /> ');

//document.write("categorySelect: " + categorySelect + "<BR><BR><BR>");

document.write('<select name="' + selectName + '">');

categorySelect = categorySelect.split(",");
for (i = 0; i < categorySelect.length; i++)
{
document.write("CATNAMES: " + categorySelect[i] + "<BR>");

  for (j = 0; j < category.length; j++)
  {
	if (categoryOmit.indexOf(category[j][0][0]) >= 0)
			continue;
			
	//if (categorySelect.indexOf(category[j][0][0]) >= 0)
//{


    if (category[j][0][0] == categorySelect[i])
	{
		sOptionValue = '';
		sOptionText = '';
		sOptionText = category[j][0][0];

		for (b = 0; b < category[j][1].length; b++)
		{
			sOptionValue += ',' + category[j][1][b];
		}

		sOptionValue = sOptionValue.substr(1);

		document.write('<option value="' + sOptionValue + '"');
		document.write('>');
		document.write(sOptionText + '</option>\n');
	}
	
	
//}
  }
}

document.write('</select>');
document.write(' <input type="submit" value="Search">');
document.write('</td>');
document.write('</tr></table></form>');

}







// The list which will hold an associative array containing the wfname pointing
// to a count of how many ways that db is checked. 
var dbCheckList = new Array();

// Seed our associative array with zeros for each database, so we don't have NaN's
// floating around in an awkward way
function buildDBCheckList () {
  for ( var i=0; i< databaseList.length; i++) {
    dbCheckList[databaseList[i][0]] = 0;
  }
}

// we actually need to _run_ buildDBCheckList() - later we should probably move this
// to being connected to onLoad
buildDBCheckList();

// Given a db, increment or decrement its value in the dbCheckList array
// based on state and make sure that we haven't fallen off of the edge of
// zero.
function dbFunction (value, state) {
//Adding the next three lines to support multiple-DB checkboxes
if (value.indexOf(',') != -1) {
    return;
  }
  
  if (state == true) {
      dbCheckList[value] = dbCheckList[value] + 1;
  } else {
    dbCheckList[value] = 0;
  }
}











//--------------------------------------------------------------------------------
// catFunction - Selects all the dbs in a category
//---------------------------------------------------------------------------------
function catFunctionWHY(index,state,subname)
{
  var wfnames = new Array;
  var dbGroup = new Array;
  var subdbGroup;
  var catCount = 0;

  //if (typeof(subname) != 'undefined')
  //	eval(subdbGroup + " = subname");

  for (m=0; m<document.wfform.Databases.length; m++)
  {
    document.wfform.Databases[m].checked = false;
  }

  // document.wfform.CheckAll.length
  if (document.wfform.CheckAll.length != null)
  {
    catCount = document.wfform.CheckAll.length;
  }
  else
  {
    catCount = 1;
  }

  for (i=0; i<catCount; i++)
  {
  	if (catCount != 1)
  	{
      state = document.wfform.CheckAll[i].checked;
    }
    else
    {
      state = document.wfform.CheckAll.checked;
    }
    if (state == true)
    {
      if (catCount != 1)
      {
        wfnames = document.wfform.CheckAll[i].value.split(",");
      }
      else
      {
        wfnames = document.wfform.CheckAll.value.split(",");
      }
      for (l=0; l<document.wfform.Databases.length; l++)
      {
        dbGroup[l]=document.wfform.Databases[l].value;
      }
      for (k=0; k<document.wfform.Databases.length; k++)
      {
        for (l=0; l<wfnames.length; l++)
        {
          if (dbGroup[k] == wfnames[l])
          {
            document.wfform.Databases[k].checked = true;
          }
        }// end of first for
      }//end of for
    }
  }

  // Subcat code
  if (typeof(document.wfform.CheckSubAll) != 'undefined')
  {
    if (document.wfform.CheckSubAll.length != null)
    {
      catCount = document.wfform.CheckSubAll.length;
    }
    else
    {
      catCount = 1;
    }

    var wfnames = new Array;
    var dbGroup = new Array;

    // document.wfform.CheckSubAll.length
    for (i=0; i < catCount; i++)
    {
      if (catCount != 1)
      {
        state = document.wfform.CheckSubAll[i].checked;
      }
      else
      {
        state = document.wfform.CheckSubAll.checked;
      }
      if (state == true)
      {
        if (catCount != 1)
        {
          subdbArray = document.wfform.CheckSubAll[i].value.split(":::");
        }
        else
        {
          subdbArray = document.wfform.CheckSubAll.value.split(":::");
        }
        eval("subdbGroup = " + subdbArray[1] + "[" + subdbArray[0] + "]");

        for (j=0; j<subdbGroup[1].length; j++)
        {
          wfnames[j] =  subdbGroup[1][j];
        }

        for (l=0; l<document.wfform.Databases.length; l++)
        {
          dbGroup[l]=document.wfform.Databases[l].value;
        }

        for (k=0; k<document.wfform.Databases.length; k++)
        {
          for (l=0; l<wfnames.length; l++)
          {
            if (dbGroup[k] == wfnames[l])
            {
              document.wfform.Databases[k].checked = true;
            }
          }// end of first for
        }//end of for
      }
    }
  }
}









// given a list of dbs, increment the counters for those dbs in the
// checked array or decriment based on the state
function chkSubject(dbs, state, currIdx, subcat, one)
{
  var subjDBs = dbs.split(',');

  for (var i = 0; i < subjDBs.length; i++) {
    if (state == true) {
        dbCheckList[subjDBs[i]] = dbCheckList[subjDBs[i]] + 1;
    } else {
      if (dbCheckList[subjDBs[i]] > 0) {
        dbCheckList[subjDBs[i]]--;
      }
    }
  }
  checkDBsEnabled();
  //catFunction(currIdx, subcat, one);
}

// Run through the list of DBs on the page, and check to see if it has
// been checked at all in the array, and update the checkbox appropriately
function checkDBsEnabled() {
  for (var i = 0; i< document.wfform.Databases.length; i++) {
  //Adding the next three lines to support multi-DB checkboxes
  if(document.wfform.Databases[i].value.indexOf(',') != -1) {
      continue;
    }
	
    if (dbCheckList[document.wfform.Databases[i].value] > 0) {
      document.wfform.Databases[i].checked = true;
    } else {
      document.wfform.Databases[i].checked = false;
    }
  }
}

// This is a debugging function that dumps the contents of the 'checked' array
// needs firebug enabled!
function dumpChkList() {
  var tabs = "\t-\t";
  for (var i in dbCheckList) {
    if (i.length < 15) { tabs = "\t\t-\t"; } else { tabs = "\t-\t"; }
    console.log(i + tabs + dbCheckList[i]);
  }
}


//Using this to display a single category checkbox on the search page
function showGenCat(catname)
{
for (i = 0; i < category.length; i++)
{
  if (category[i][0][0] == catname)
  {
    document.write('<input type="checkbox" name="Databases" value="' + formCategoryList(catname) + '" onClick="' + dbFunction(this.value, this.checked) + '">');
    //document.write('onClick="javascript:catFunction(' + i + ', this.state)">');
  }
}
}





function parseQueryString2(QueryString)
{
  QueryString = QueryString.replace('?', '');

  var aParamList = QueryString.split('&');
  var aSearchStruct = ['','','','','','','','','','','',0,0];
  var sDatabaseCookie = '';

  for (i=0; i<aParamList.length; i++)
  {
    var elemPair = aParamList[i].split('=');

    if (elemPair.length < 2)
    {
      alert ('Bad pair: ' + i);
    }

    if (elemPair[0] == 'wf_field1')
    {
      aSearchStruct[0] = elemPair[1];
    }
    else if (elemPair[0] == 'wf_term1')
    {
      aSearchStruct[1] = decodeQueryURL(elemPair[1]);
    }
    else if (elemPair[0] == 'wf_op2')
    {
      aSearchStruct[2] = elemPair[1];
    }
    else if (elemPair[0] == 'wf_field2')
    {
      aSearchStruct[3] = elemPair[1];
    }
    else if (elemPair[0] == 'wf_term2')
    {
      aSearchStruct[4] = decodeQueryURL(elemPair[1]);
    }
    else if (elemPair[0] == 'wf_op3')
    {
      aSearchStruct[5] = elemPair[1];
    }
    else if (elemPair[0] == 'wf_field3')
    {
      aSearchStruct[6] = elemPair[1];
    }
    else if (elemPair[0] == 'wf_term3')
    {
      aSearchStruct[7] = decodeQueryURL(elemPair[1]);
    }
    else if (elemPair[0] == 'wf_all_years')
    {
      aSearchStruct[8] = elemPair[1];
    }
    else if (elemPair[0] == 'wf_from_year')
    {
      aSearchStruct[9] = elemPair[1];
    }
    else if (elemPair[0] == 'wf_to_year')
    {
      aSearchStruct[10] = elemPair[1];
    }
    else if (elemPair[0] == 'wf_ftonly')
    {
      aSearchStruct[11] = 'true';
    }
    else if (elemPair[0] == 'wf_peeronly')
    {
      aSearchStruct[12] = 'true';
    }
    else if (elemPair[0] == 'Databases')
    {
      document.cookie = 'wf_selected_databases=' + elemPair[1] + '; Path=/';
    }
  }

  if (aSearchStruct[8] == 'range')
  {
    var count = 0;
    var today = new Date();
    var currentYear = today.getYear();
	var startYear = '';
    if (currentYear < 1900)
    {
      currentYear += 1900;
    }
    for (x = startYear; x <= currentYear; x++)
    {
      if (aSearchStruct[9] == x)
      {
        aSearchStruct[9] = count;
      }
      count++;
    }
    count = 0;
    for (x = currentYear; x >= startYear; x--)
    {
      if (aSearchStruct[10] == x)
      {
        aSearchStruct[10] = count;
      }
      count++;
    }
  }

  for (i = 0; i < aSearchStruct.length; i++)
  {
    if (typeof(aSearchStruct[i]) == 'string')
    {
      aSearchStruct[i] = aSearchStruct[i].replace(/%20/g, ' ');
    }
  }

  return(aSearchStruct);
}






//Overloading to allow previous selections show up
function showDateRangeDM(startYear)
{
  var today = new Date();
  currentYear = today.getYear();

  if (currentYear < 1900)
  {
    currentYear += 1900;
  }
  
  //wf_from_year
  document.write('From:');
  
  //Checking for the variable again so we can make the drop-down enabled or disabled as necessary
  if (wf_from_year == '')
  {
  document.write('<select class="datebox" name="wf_from_year" size="1" disabled>');
  }
  else
  {
    document.write('<select class="datebox" name="wf_from_year" size="1">');
	}
	
  document.write('<option value="' + startYear + '" selected>' + startYear + '</option>');
  //for (i=startYear +  1; i <= currentYear ; i++)
  
  
  for (i=startYear + 1; i <= currentYear ; i++)
  {
    document.write('<option value="' + i + '">' + i + '</option>');
  }
  
  if (wf_to_year != '')
  {
  var currentYear2 = wf_to_year;
  }
  else
  {
  var currentYear2 = currentYear;
  }

   //wf_to_year
  document.write('</select>&nbsp;To:');
  
    //Checking for the variable again so we can make the drop-down enabled or disabled as necessary
  if (wf_to_year == '')
  {
   document.write('<select class="datebox" name="wf_to_year" size="1" disabled>');
  }
  else
  {
     document.write('<select class="datebox" name="wf_to_year" size="1">');
	}

  document.write('<option value="' + currentYear2 + '" selected>' + currentYear2 + '</option>');
  
  //adding this check because for some reason, when we use currentYear2 as the selected option, the current year is set to one below what it really is, so we need to manually insert it.
    if (wf_to_year != '')
  {
  document.write('<option value="' + currentYear + '">' + currentYear + '</option>');
  }
  
  for (i=currentYear - 1; i >= startYear ; i--)
  {
    document.write('<option value="' + i + '">' + i + '</option>');
  }

  document.write('</select>');
}




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/>");
  }
}


// Function to trap the enter key, overloading because default function uses BasicTerm fix
function checkSubmitDM(event, oForm)
{
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if (keyCode == 13)
  {
    if (checkDBs())
    {
      oForm.submit();
      return false;
    }
  }
  return true;
}


//This new version will handle links
	function changeDisplayMode2(sortBy)
{
  var currDisplayMode = sortBy;

  if (currDisplayMode == "") {
    return false;
  } else if (currDisplayMode == "merged") {
    displayMerged();
  } else if (currDisplayMode == "grouped") {
    displayGrouped();
  } else if (currDisplayMode == "sorted") {
    displaySortTitle();
  } else if (currDisplayMode == "sortauth") {
    displaySortAuth();
  } else if (currDisplayMode == "deduped") {
    displayDeduped();
  } else if (currDisplayMode == "selected") {
    displaySelected();
  } else if (currDisplayMode == "ranked") {
    displayRanked();
  } else if (currDisplayMode == "sortdate") {
    displaySortDate();
  } else if (currDisplayMode == "clustered") {
    createCluster();
  }
}