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 showHide(divID, visFlag)
{
  if (visFlag == 1)
  {
    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 showDbs(dbArray)
{
  var wrkArray = new Object();
  wrkArray = eval(dbArray);
  
  var outstr = '';
  var wfName = '';
  var assignedName = '';
  var helpText = '';
  var colorCount = 0;
  var selected = 0;
  var linkOnly = 0;

  for (i = 0; i < wrkArray.clientTranslators.length; i++)
  {
    outstr = '';

    wfName = wrkArray.clientTranslators[i].wfName;
    assignedName = wrkArray.clientTranslators[i].assignedName;
    helpText = wrkArray.clientTranslators[i].helpText;
    selected = wrkArray.clientTranslators[i].selected;
    linkOnly = wrkArray.clientTranslators[i].linkOnly;
	nativeLink = wrkArray.clientTranslators[i].nativeLink;

    if (colorCount % 2 == 0)
    {
      outstr = "<tr class='datarowson'>";
    }
    else
    {
      outstr = "<tr class='datarowsoff'>"
    }
    colorCount++;
    outstr += "<td align='left' width='5%'>";
    outstr += "<input type='checkbox' name='Databases' value='" + wfName + "'";
    if (linkOnly == 1)
    {
      outstr += "disabled";
    }
    if (selected == 1)
    {
      outstr += "checked";
    }
    outstr += "></td><td align='left' class='databases' width='44%'>";

	if (nativeLink =="")
	{
	outstr += "<font color='#000000'><B>" + assignedName + "</B></TD>";
	}
	else
	{
    outstr += "<A HREF='" + nativeLink + "'><font color='#000000'><B>" + assignedName + "</B></A></TD>";
	}
    outstr += "<td align='left' valign='middle' class='detailslink'>";
    outstr += "<font color='#000000'>" + helpText + '</td>';
    document.write(outstr);
  }
}

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 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>");
				
				 "<td width=\"6%\" align=\"right\"><a href=\"JavaScript:showHideLayer('WFDB" + i + "');JavaScript:swap('WFSign" + i + "')\">" +
        "<IMG class=\"arrowbutton\"" +
        "src=\"/images/plus_on.gif\" name=\"WFSign" + i + "\"></a></td>");
		}
		else
		{
			sTemplate = sTemplate.replace(/<<category image>>/g, "");
			//sTemplate = sTemplate.replace(/<<category image>>/g, "<td width=\"10%\">&nbsp;</td>");
		}
			
    }
    else
    {
      sTemplate = sTemplate.replace(/<<category image>>/g,"");
    }
    sTemplate = sTemplate.replace(/<<checkbox>>/g, sCheckbox);
	
    sTemplate = sTemplate.replace(/<<category name>>/g, "<font class=\"categorytitle\">" + catName + "</font>");


    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]);
	  
	  document.write("<div class=\"categorytitle\" id=\"WFDB" + i + "\">" + sSubTemplate + "</div>");			
    }

    if (rowNum == (offset - 1))
    {
      rowNum = 0;
    }
    else
    {
      rowNum++;
    }
  }
  document.write('</td>');
}
