// oplinCustom.js
//
// Oplin Custom JavaScript Functions
//
// 02/03/2004		HHlaing
// modified brule molo 11/1/2004

// Open full text in a New Window 1=yes | 0=No
newFullTextWindow = 1;

var iButtonImg = 'http://search3.webfeat.org/Images/i.jpg';
var helpImage = 'http://search3.webfeat.org/Images/i_small.jpg';

var strHelpText = "<font class=\"wfrdblink\">Help</font></a>&nbsp;|&nbsp;";
var strDescText = "<font class=\"wfrdblink\">Resource Description</font></a>&nbsp;|&nbsp;<a href=\"#top\"><font class=\"wfrdblink\">Top</font></a>";

//Variables for scoreboard
	var WFsbHeader = '<table width="100%" border="0" cellpadding="0" cellspacing="0" align="left">';
	WFsbHeader += '<tr bgcolor="#7091A4"><td width="10%" align="left"> <font face="Arial, Helvetica, Verdana, Sans-Serif"  size="-1" color="white"><b>Items</b> </font></td>';
	WFsbHeader += '<td width="90%" align="left"><font face="Arial, Helvetica, Verdana, Sans-Serif" size="-1" color="white"><b>Database</b></font></td>';
	//WFsbHeader += '<td width="50%" align="left" nowrap><font face="Arial, Helvetica, Verdana, Sans-Serif"  size="-1" color="white"><b>Description</b></font></td>';
	WFsbHeader += '</tr>';
	var WFsbRowTemplate = '<tr bgColor="white">';
	WFsbRowTemplate += '<td align="left"><font face="Arial, Helvetica, Verdana, Sans-Serif"  size="-1"><strong><<count>></strong></font></td>';
	WFsbRowTemplate += '<td align="left"><font face="Arial, Helvetica, Verdana, Sans-Serif"  size="-1"><a href="#<<wf name>>"><<db name>></a></font></td>';
	//WFsbRowTemplate += '<td align="left"><font face="Arial, Helvetica, Verdana, Sans-Serif"  size="-1"><<description>></font></td>';
	WFsbRowTemplate += '</tr>';
	var WFsbRowFooter = '</table>';

function populateCategoryDBs(categoryName)
{
	var dbString = '';
	for (i=0; i < category.length; i++)
	{

		if (category[i][0][0] == categoryName)
		{
			for (j=0; j<category[i][1].length; j++)
			{
				dbString += category[i][1][j] + ',';
			}//end of j
			dbString = dbString.substr(0,dbString.length -1);
			//alert(dbString);

		}//end of if category

	}//end of if i

	return dbString;

}//end of populateCategoryDBs


function showHomePageForm()
{

	//document.write('<form name="wfform" action="/OplinAuth.asp" method="get" onSubmit="setRRefineSearch(document.wfform);return ProcessQuickForm();">');
	document.write('<form name="wfform" action="http://search2.webfeat.org/OplinAuth.asp" method="post" onSubmit="setRRefineSearch(document.wfform);return ProcessQuickForm();">');
	//document.write('<form name="wfform" action="http://www.oplin.org/controller.php?l=ra&Id=67-22642" method="post" onSubmit="setRRefineSearch(document.wfform);return ProcessQuickForm();">');
	document.write('<input type="hidden" name="Command" value="Search">');
	document.write('<input type="hidden" name="BypassSessData" value="Yes">');
	document.write('<input type="hidden" name="Client_ID" value="oplin">');
	document.write('<input type="hidden" name="noserial" value="1">');
	document.write('<input type="hidden" name="wf_field1" value="wf_keyword">');
	document.write('<input type="hidden" name="nexturl">');

	document.write('<table width="180" border="0" cellpadding="2" cellspacing="0">');
	document.write('<tr><td colspan="2"><div align="left">');
	//showCategoryBoxWithDefaultName('Databases', '', 'Search All Databases');
	showCategoryBox('Databases', 'Search All Databases');
	document.write('</div></td></tr>');

	document.write('<td><div align="left"><tr><td><div align="left">');
	document.write('<input type="text" name="wf_term1" size="25" value="Enter your search topic here." onFocus="this.value=\'\';"></font>');
	document.write('</div></td>');
	document.write('<td><input type=image src="http://new.oplin.org/GO_2%5B1%5D.gif" width="52" height="22" alt="Search"></td></tr>');

	document.write('<tr><td valign="top"><div align="center"><font color="#003399" size="1" face="Verdana, Arial, Helvetica, sans-serif">');
	document.write('<a href="http://search3.webfeat.org/oplinsearch.html"><strong>Advanced Search</strong></a></font></div></td>');
	document.write('<td valign="top"><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">');
	document.write('<a href="javascript:popmanual(\'http://new.oplin.org/whatisonesearch.htm\');"><strong>Help?</strong></a></font></div></td>');
	//document.write('<td>&nbsp;</td>');
	document.write('</tr></table></form>');

	document.write('<scr' + 'ipt language="JavaScript"' + '>loadRRefineSearch(document.wfform);</scr' + 'ipt>');
}


function showResultPageForm()
{

	document.write('<form name="wfform" action="/cgi-bin/webfeat.dll" method="get" onSubmit="setRRefineSearch(document.wfform)">');
	// document.write('<form name="wfform" action="/scripts/webfeat.dll" method="get" onSubmit="setRRefineSearch(document.wfform)">');
	document.write('<input type="hidden" name="Command" value="Search">');
	document.write('<input type="hidden" name="BypassSessData" value="Yes">');
	document.write('<input type="hidden" name="Client_ID" value="oplin">');
	document.write('<Input type="hidden" name="wut_code" value="">');
	document.write('<input type="hidden" name="noserial" value="1">');
	document.write('<input type="hidden" name="wf_field1" value="wf_keyword">');

	document.write('<table width="375" border="0" cellpadding="0" cellspacing="0">');
	document.write('<tr><td colspan="3"><div align="left"><strong>Search Again</strong></div></td></tr>');
	document.write('<tr><td><div align="left">');
	showCategoryBox('Databases', 'Search All Databases');
	document.write('</div></td>');

	document.write('<td><div align="left">');
	document.write('<input type="text" name="wf_term1" size="30"></font>');
	document.write('</div></td>');
	document.write('<td><div align="left"><input type=image src="http://new.oplin.org/GO_2%5B1%5D.gif" width="52" height="22" alt="Search"></div></td></tr>');

	document.write('<tr><td><div align="center"><font color="#003399" size="1" face="Verdana, Arial, Helvetica, sans-serif">');
	document.write('<a href="/oplinsearch.html"><strong>Advanced Search</strong></a></font></div></td>');
	document.write('<td><div align="center"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">');
	document.write('</font></div></td>');
	document.write('<td>&nbsp;</td>');
	document.write('</tr></table></form>');

	document.write('<scr' + 'ipt language="JavaScript"' + '>loadRRefineSearch(document.wfform);</scr' + 'ipt>');

	var swutcode = getCookie('wut_code');

	if ((swutcode != null) && (swutcode))
	{
		document.wfform.wut_code.value = swutcode;
	}

}


function loadSRefineSearch(oForm)
{
	// let's load all the terms, fields, and operators from wfsearch cookie
	if (typeof(oForm.wf_term1) != 'undefined')
	{
		var wfterm = getSearchCookie('t1:');

		if (wfterm != null)
		{
			oForm.wf_term1.value = wfterm;
		}
	}

	return true;
}


function setSRefineSearch(oForm)
{
	document.cookie = "wfsearch=f1:wf_keyword&t1:" + oForm.wf_term1.value + "; path=/;";
}


function loadRRefineSearch(oForm)
{

	nBegin = document.location.search.indexOf('&wf_cat=');
	if (nBegin > 0)
	{
		var rCat = "";
		var rTerm = "";

		nBegin += 8;
		nEnd = document.location.search.indexOf('&', nBegin);
		if (nEnd == -1) { nEnd = document.location.search.length;}
		rCat = document.location.search.substr(nBegin, nEnd-nBegin);

		nBegin = document.location.search.indexOf('&wf_term1=');
		nBegin += 10;
		nEnd = document.location.search.indexOf('&', nBegin);
		if (nEnd == -1) { nEnd = document.location.search.length;}
		rTerm = document.location.search.substr(nBegin, nEnd-nBegin);
		rTerm = unescape(rTerm);
		rTerm = rTerm.replace(/\+/g," ");

		// alert('rCat ' + rCat);
		// alert('rTerm ' + rTerm);

		document.cookie = "wfrscat=" + rCat + "; path=/;";
		document.cookie = "wfsearch=f1:wf_keyword&t1:" + rTerm + "; path=/;";
	}

	// alert(getSearchCookie('f1:'));
	// alert(getWFCookie('wfrscat'));

	// let's load all the terms, fields, and operators from wfsearch cookie
	if(typeof(oForm.wf_term1) != 'undefined')
	{
		var wfterm = getSearchCookie('t1:');

		if (wfterm != null)
		{
			oForm.wf_term1.value = wfterm;
		}
	}


	// select category
	if(typeof(oForm.Databases) != 'undefined')
	{
		var selectCat = getWFCookie('wfrscat');

		if (selectCat != null)
		{
			oForm.Databases[parseInt(selectCat)].selected = true;
		}
	}

	return true;
}

function setRRefineSearch(oForm)
{

	var dbidx = "";
	var limits = "";

	document.cookie = "wfrscat=; path=/;";
	document.cookie = "wfsearch=; path=/;";
	document.cookie = "wfrsurl=; path=/;";


	// select category
	if(typeof(oForm.Databases) != 'undefined')
	{
		for (var loop=0; loop < oForm.Databases.length; loop++)
		{
			if (oForm.Databases[loop].selected == true)
			{
				dbidx = loop;
			}
		}
	}


	// alert("wfrscat: " + dbidx);
	// alert("wfsearch: " + oForm.wf_term1.value);
	document.cookie = "wfrscat=" + dbidx + "; path=/;";
	document.cookie = "wfsearch=f1:wf_keyword&t1:" + oForm.wf_term1.value + "; path=/;";
}

// Return value of cookie (or null if it doesn't exist)
function getWFCookie(cookiename)
{
	var result = null;
	var myCookie = " " + document.cookie + ";";
	var searchName = " " + cookiename + "=";
	var startOfCookie = myCookie.indexOf(searchName);
	var endOfCooke;

	if (startOfCookie != -1)
	{
		startOfCookie += searchName.length;
		endOfCookie = myCookie.indexOf(";", startOfCookie);
		if(endOfCookie == -1) { endOfCookie = myCookielength(); }
		result = unescape(myCookie.substring(startOfCookie, endOfCookie));

	}
	return result;
}


function setSearch(nSearch)
{
	searchType = nSearch;
}


function popmanual( strURL )
{
	window.open(strURL, "Help", "height=351,width=342,resizable=yes,scrollbars=yes,location=no,status=no,toolbar=no,personalbar=no,menubar=no");
}

// Show help window
function showHelp( strURL )
{
	strURL = strURL.replace(/\/Help.html/gi, 'oplinPopuphelp.html');
	strURL = strURL.replace(/Help.php/gi, 'oplinPopuphelp.html');
	window.open(strURL, "Help", "height=400,width=500,resizable=yes,scrollbars=yes,location=no,status=no,toolbar=no,personalbar=no,menubar=no");
}

	// Select / Deselect all function
function changeSelect()
{

	checkOn = true;

	if (document.wfform.Databases.length == null)
	{
		// Only one checkbox present
		document.wfform.Databases.checked = checkOn;
	}
	else
	{
		for (i=0; i< document.wfform.Databases.length; i++)
			document.wfform.Databases[i].checked = checkOn;
	}

}

function checkDBs()
{
	var count = document.wfform.Databases.length;
	var noneSelected = true;


	if (document.wfform.Databases.length == null)
	{
		// Only one checkbox present
		if (document.wfform.Databases.checked == true)
			noneSelected = false;
	}
	else {
		for (i=0; i< document.wfform.Databases.length; i++)
		{
			 if (document.wfform.Databases[i].checked == true)
			{
				noneSelected = false;
				break;
			}
			else
				noneSelected = true;
		}//end of for
	}//end of else

	if (noneSelected == true)
	{
		alert('Please select at least one database!');
		return false;
	}
	else return true;

}

function validateTerms()
{

	boolDBs = checkDBs();
	if (boolDBs == false) return false;

	//Check for non-empty term
	if (document.wfform.wf_term1.value.length <= 0)
	{
		alert( "Please enter a search term before proceeding" )
		return false;
	}

	if (document.wfform.wf_term2.value.length > 0)
	{
		if (document.wfform.wf_op2.value.length <= 0)
		{
			alert( "Please select a boolean operator before proceeding" );
			return false;
		}
	}
}


function ProcessQuickForm()
{

	//Check for non-empty term
	if (document.wfform.wf_term1.value.length <= 0)
	{
		alert( "Please enter a search term before proceeding" )
		return false;
	}

	var strDatabases = document.wfform.Databases.value;
	//alert(strDatabases);

	var strTerm1 = document.wfform.wf_term1.value;
	var dbidx = document.wfform.Databases.selectedIndex;

	// nexturl = "/scripts/webfeat.dll?Command=Search&BypassSessData=yes&noserial=1&Databases=" + strDatabases;
	nexturl = "/cgi-bin/webfeat.dll?Command=Search&BypassSessData=yes&noserial=1&Databases=" + strDatabases;
	nexturl += '&wf_cat=' + dbidx;
	nexturl += '&Client_ID=oplin&wf_all_years=yes&wf_field1=wf_keyword&wf_term1=' + escape(strTerm1);
	nexturl += '&rurl=' + escape(document.location.href);

	//alert(nexturl);
	document.wfform.nexturl.value = nexturl;
	document.wfform.Databases.value = "";
	return true;
}


function processForm()
{
	if (searchType == 2)
	{
		document.forms[0].wf_term1.value = document.forms[0].term2.value;
		strField = document.forms[0].field2.options[document.forms[0].field2.selectedIndex].value;
		document.forms[0].wf_field1.value = strField;

		strDatabases = '';

		for (i=0; i<document.forms[0].Database2.length; i++)
		{
			if (document.forms[0].Database2[i].checked)
			{
				strDatabases += "," + document.forms[0].Database2[i].value;
				document.forms[0].Database2[i].checked = false;
			}
		}

		strDatabases = strDatabases.substring(1);
		document.forms[0].Databases.value = strDatabases;

		document.cookie= "sb=Advanced Search Results; path=/;";
	}
	else
	{
		document.forms[0].wf_term1.value = document.forms[0].term1.value;

		strField = document.forms[0].field1.options[document.forms[0].field1.selectedIndex].value;
		document.forms[0].wf_field1.value = strField;

		strDatabases = document.forms[0].Database1.options[document.forms[0].Database1.selectedIndex].value;
		document.forms[0].Databases.value = strDatabases;

		document.cookie= "sb=" + document.forms[0].Database1.options[document.forms[0].Database1.selectedIndex].text + "; path=/;";
	}

	document.cookie = "sterm=" + document.forms[0].wf_term1.value + "; path=/;";

	return true;
}

function setSubjectCookie()
{
	var selCatText = document.wfform.Databases.options[document.wfform.Databases.selectedIndex].text;
	document.cookie = "sb=" + selCatText + "; path=/;";
	document.cookie = "sTerm=" + document.wfform.wf_term1.value + "; path=/;";
	document.wfform.sb.value = selCatText;
}

//JS functions for new design SFPL
function showSubjectListSFPL(subjectOmit, descriptionText, subjectOnly, categoryClick, nCols)
{
	// 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')
		subjectOnly = '';

	if (typeof(descriptionText) == 'undefined')
		descriptionText = '';

	if (typeof(nCols) == 'undefined')
		nCols = 1;

	var subSelIdx = 0;

	//Find number of categories to show
	var numCategories = category.length;
	var categoryStr ='';
	var midCategory ='';



	for (i=0; i<category.length; i++)
	{
		if (subjectOmit.indexOf(category[i][0][0]) >= 0)
			numCategories--;
		categoryStr += i + ':' + category[i][0][0] + ' ';
	}

	if (numCategories%nCols != 0)
	{
		numCategories--;
		midCategory = category[numCategories][0][0];
		// alert(midCategory);
	}

	var offset = 0;
	if (typeof(nCols) != 'undefined')
		offset = Math.ceil(numCategories / nCols);
	if (nCols == 1)
		offset = 0;

	var useIdx = 0;
	var rowNum = 0;
	var colNum = 0;

	// Loop through the category array to build the page
	for (i=0; i<category.length; i++)
	{
		var subSelBegin = subSelIdx;
		var subSelEnd = subSelIdx;
		if (subjectOmit.indexOf(category[i][0][0]) >= 0)
		{
			continue;
		}

		if (rowNum == offset)
			useIdx = ((rowNum + 1) * nCols) - nCols;
		else
			useIdx = (colNum * offset) + rowNum;
		catName = category[useIdx][0][0];

		wfSubNames = '';

		if (offset)
		{
			if (colNum == 0)
				document.write('<tr>');
			// useIdx = (colNum * offset) + rowNum;
		}
		else
		{
			useIdx = i;
			document.write('<tr>');
		}
			//alet(useIdx + ' ' + catName+' '+rowNum+' '+colNum);

		// Build the complete subject wf_name list first
		for (j=0; j<category[useIdx][1].length; j++)
		{
			wfSubNames += ',' + category[useIdx][1][j];
			subSelEnd++;
		}

		wfSubNames = wfSubNames.substr(1);

		if (midCategory == catName)
			sTemplate = ALT_SUBJECT_T;
		else
			sTemplate = g_SubjectTemplate;
		sCheckbox = '';

		if (subjectOnly)
		{
			if (categoryClick)
			{
				sCheckbox = '<input type="checkbox" title="Check box to include in search" name="CheckAll" value="';
				sCheckbox += catName + '"';
				sCheckbox += ' onClick="javascript:catFunction('+ i +', this.checked);">';
			}
			else
			{
				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)">';
		}

		// Set the Index for the next group
		subSelIdx = subSelEnd;

		sTemplate = sTemplate.replace(/<<checkbox>>/g, sCheckbox);
		sTemplate = sTemplate.replace(/<<category name>>/g, catName);

		//bad sfpl hack for removing all resources categories
		//if (catName != 'All Resources')
			document.write(sTemplate);

		if (offset)
		{
			if (midCategory == catName)
				document.write('</tr>');
			else if (colNum == (nCols - 1))
			{
				colNum = 0;
				rowNum++;
				document.write('</tr>');
			}
			else
				colNum++;
		}
		else
			document.write('</tr>');

	}
}


function showDBsForCatNameSFPL(categoryName, descriptionText, helpText, nCols, omitDatabase, format,top)
{

	// Use the default template if g_CheckboxTemplate is not present
	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(helpText) == 'undefined')
		helpText = '';

	if(typeof(nCols) == 'undefined')
		nCols = 1;

	if(typeof(omitDatabase) == 'undefined')
		omitDatabase = '';

	if(typeof(format) == 'undefined')
		format = '';

	if(typeof(top) == 'undefined')
		top = '';


	for (i=0; i< category.length; i++)
	{
		if (category[i][0][0] == categoryName)
		{
			var offset = 0;

			if (typeof(nCols) != 'undefined')
				offset = Math.ceil(category[i][1].length / nCols);
			if (nCols == 1)
				offset = 0;

			var useIdx = 0;
			var rowNum = 0;
			var colNum = 0;
			var count = 0;
			var shouldColor = 0;
			var anchors = omitDatabase;
			var text="";
			var textanchor="";

			for (j=0; j<category[i][1].length; j++)
			{
				if (offset)
				{
					if(colNum == 0)
						document.write('<tr>');
					useIdx = (colNum * offset) + rowNum;
				}
				else
				{
					useIdx = j;
					document.write('<tr>');
				}

				wfname = category[i][1][useIdx];

				for (k=0; k<databases.length; k++)
				{
					if (databases[k][0] == wfname)
					{
						dbArray = databases[k];
					}
				}

				if ( (dbArray[0] == 'wf_iefbr14') )
					// ||(omitDatabase.indexOf(dbArray[0]) >= 0))
				{
					continue;
				}


				if( (count!=0) && ((count%2)==0) )
				{
					shouldColor = (shouldColor+1)%2; // toggle flg between 1 and 0
				}


				if(shouldColor==1)
				{
					sTemplate= '<tr class="datarowson">';
				}

				else
				{
					sTemplate= '<tr class="datarowsoff">';
				}

				sTemplate += g_CheckboxTemplate;

				sCheckbox = '';
				sDBname = '';
				sDescLink = '';
				sHelpLink = '';
				sDescription='';

				wfName = dbArray[0];
				dbName = dbArray[1];
				sDBDesc = dbArray[5];
				sDescription = dbArray[7];
				
				
				
				
				
				//Adding an IF statement so we can discern DBs with links and DBs without links.
				
				if (dbArray[6] == "") {
				sNativeLink = dbArray[6];
				}
				
				else
				
				{
				sNativeLink = '<a class=dblink href="' + dbArray[6] + '" title="Click to access this resource directly">';
				}
				//End of new IF statement
				
				
				
				

				sCheckbox = '<input type="checkbox" title="Check box to include in search" name="' + g_CheckboxName + '" value="';
				sCheckbox += wfName + '">';
				sDBname = dbName;

				if (sDBname.indexOf('<!-- link only -->') >= 0)
				{
					sCheckbox = '<input type="checkbox" name="" disabled="disabled">';
				}

				if (oplinaccess == 1)
				{
					// for those database that are not accessible remotely
					if ( (dbArray[9].indexOf(strWUTCode) < 0) && (dbArray[2] == 0) )
					{
						sCheckbox = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
						sNativeLink = '';
					}
				}

				sDescLink = '<a href="javascript:showHelp(\'/oplinPopuphelp.html?wffield=' + wfName + '\');">' + descriptionText + '</a>';
				sHelpLink = '<a href="javascript:showHelp(\'/oplinPopuphelp.html?wffield=' + wfName + '&type=help\');">' + helpText + '</a>';

				//sDBname = sDBname.replace(/<span class=h2red>full text<\/span>/g, '');

				sTemplate = sTemplate.replace(/<<checkbox>>/g, sCheckbox);
				sTemplate = sTemplate.replace(/<<database name>>/g, sDBname);
				sTemplate = sTemplate.replace(/<<description link>>/g, sDescLink);
				sTemplate = sTemplate.replace(/<<help link>>/g, sHelpLink);
				sTemplate = sTemplate.replace(/<<description>>/g, sDescription);
				sTemplate = sTemplate.replace(/<<database description>>/g, sDBDesc);
				sTemplate = sTemplate.replace(/<<native link>>/g, sNativeLink);


				for (l = 0 ; l < anchors.length ; l++)
				{
					if (sDBname.charAt(0) == anchors[l])
					{
						if ( anchors[l] != "*" )
						{
							text = anchors[l].toLowerCase();
							anchors[l]= "*" ;
							textanchor = "<a name='#"+text+"'></a>";
						}
						break;
					}
				}
				document.write(textanchor);

				//var ti="";
		  		for (p = 0;p < format.length ; p++)
				{
					if (sDBname.charAt(0).toUpperCase() == format[p] && format[p]!="*")
					{
						format[p]="*";
						document.write(top);
						break;
				   }
				}
				document.write(sTemplate);

				count++;


				if (offset)
				{
					if (colNum == (nCols - 1))
					{
						colNum = 0;
						rowNum++;

						document.write('</tr>');
					}
					else
						colNum++;
				}
				else
					document.write('</tr>');
			}
			break;
		}
	}
}


function showDBsForCatNameBasic(categoryName, descriptionText, nCols, omitDatabase)
{
	// Use the default template if g_CheckboxTemplate is not present
	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 = '';

	for (i=0; i< category.length; i++)
	{
		if (category[i][0][0] == categoryName)
		{

			var offset = 0;

			if (typeof(nCols) != 'undefined')
				offset = Math.ceil(category[i][1].length / nCols);
			if (nCols == 1)
				offset = 0;

			var useIdx = 0;
			var rowNum = 0;
			var colNum = 0;

			for (j=0; j<category[i][1].length; j++)
			{
				if (offset)
				{
					if(colNum == 0)
						document.write('<tr>');
					useIdx = (colNum * offset) + rowNum;
				}
				else
				{
					useIdx = j;
					document.write('<tr>');
				}

				wfname = category[i][1][useIdx];

				for (k=0; k<databases.length; k++)
					if (databases[k][0] == wfname)
						dbArray = databases[k];

				if ((dbArray[2] != 2 && dbArray[2] != g_wfaccess) || (dbArray[0] == 'wf_iefbr14' )
					|| ( omitDatabase == dbArray[0] ) )
				{
					continue;
				}

				sTemplate = g_CheckboxTemplate;
				sCheckbox = '';
				sDBname = '';
				sDescLink = '';

				wfName = dbArray[0];
				dbName = dbArray[1];
				sDBDesc = dbArray[5];
				
				
				
								//Adding an IF statement so we can discern DBs with links and DBs without links.
				
				if (dbArray[6] == "") {
				sNativeLink = dbArray[6];
				}
				
				else
				
				{
				sNativeLink = '<a class=dblink href="' + dbArray[6] + '" title="Click to access this resource directly">';
				}
				//End of new IF statement
				
	
	

				sDescLink = '<a href="javascript:showHelp(\'/help.html?wffield=';
				sDescLink += wfName;
				sDescLink += '\');">' + descriptionText + '</a>';

				sCheckbox = '<input type="checkbox" title="Check box to include in search" name="' + g_CheckboxName + '" value="';
				sCheckbox += wfName + '">';
				sDBname = dbName;

				//tkamdar 05/19 removing fulltext
				sDBname = sDBname.replace(/<span class=h2red>full text<\/span>/g, '');


				//tkamdar 04/02 to align link only xlators with other xlators
				if (sDBname.indexOf('<!-- link only -->') >= 0)
					sCheckbox = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';

				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);

				document.write(sTemplate);

				if (offset)
				{
					if (colNum == (nCols - 1))
					{
						colNum = 0;
						rowNum++;
						document.write('</tr>');
					}
					else
						colNum++;
				}
				else
					document.write('</tr>');
			}
			break;
		}
	}
}

function showDateRangeOPLIN(startYear)
{
	var today = new Date();
	currentYear = today.getYear();
	if (currentYear < 1900)
		currentYear += 1900;

	//wf_from_year
	document.write('<TD valign="middle" align="center" colspan="2">From: ');
	document.write('<select name="wf_from_year" size="1">');
	document.write('<option value="' + startYear + '" selected>' + startYear + '</option>');
	for (i=startYear +  1; i <= currentYear ; i++)
	{
		document.write('<option value="' + i + '">' + i + '</option>');
	}
	document.write('</select>');

	//wf_to_year
	document.write('&nbsp;&nbsp;&nbsp;&nbsp;To: ');
	document.write('<select name="wf_to_year" size="1">');
	document.write('<option value="' + currentYear + '" selected>' + currentYear + '</option>');
	for (i=currentYear - 1; i >= startYear ; i--)
	{
		document.write('<option value="' + i + '">' + i + '</option>');
	}
	document.write('</select></TD>');
}
