// JavaScript Document
// scripts to sort and display the contents of an Ebook XML file (generated by makeXML.js)

// First call find_DBs which loads the correct file, removes preceiding articles from the title and saves the titles;
// find_DBs saves to ttl_arr;
//   find_DBs also determines if title is new by calling DBcheck_date
// find_DBs then sorts ttl_arr and displays the results

//*************************************************************************
// ttl_arr:
//		ttl_arr[x] - title 							[set in find_DBs()]
//			ttl_arr[x][1] - provider info			[set in find_DBs()]
//			ttl_arr[x][2] - date range string		[set in find_DBs()]
//			ttl_arr[x][3] - article 				[set in find_DBs()]
//			ttl_arr[x][4] - bool (Free?)			[set in find_DBs()]
//			ttl_arr[x][5] - bool (New?)				[set in find_DBs()]
//			ttl_arr[x][6] - notes info string		[set in find_DBs()]
//			ttl_arr[x][7] - limit (BCD or BUMC?)	[set in find_DBs()]
//			ttl_arr[x][8] - description string		[set in find_DBs()]  3/26/09
//			ttl_arr[x][9] - content string			[set in find_DBs()]  3/31/09
//			ttl_arr[x][10][i] - array of languages 	[set in getLangInfoDB()]	6/12/09
//			ttl_arr[x][11] - number of lans			[set in getLangInfoDB()]	6/12/09
//*************************************************************************

//Global vars
//-----------
var result_text = '';
var startsWithLettRegExp = /^\D/;
var newCount = 0;						//??????????????change this???????????
var searchStr;


//*****************************************************************************************************
// DBcheck_date()
// ------------
// returns: bool
//
// is passed a month value and checks whether it precedes the current month by 3; if so, true is
// returned, and a new icon is added next to the title.
//*****************************************************************************************************
function DBcheck_date (dateNode) {
			
		var today = new Date();
		adYr  = adDate[0].getElementsByTagName("year");
		adMon = adDate[0].getElementsByTagName("month");

	switch (today.getMonth()+1) {
		case 1:
			if (((today.getFullYear() - adYr[0].firstChild.nodeValue == 1) &&
				((adMon[0].firstChild.nodeValue == 12) || 
				 (adMon[0].firstChild.nodeValue == 11) || 
				 (adMon[0].firstChild.nodeValue == 10)))
				||
				((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 (adMon[0].firstChild.nodeValue == 1)))
				return true;
			break;
		case 2:
			if (((today.getFullYear() - adYr[0].firstChild.nodeValue == 1) &&
				((adMon[0].firstChild.nodeValue == 12) || 
				 (adMon[0].firstChild.nodeValue == 11)))
				||
				((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 2) || 
				  (adMon[0].firstChild.nodeValue == 1))))
				return true;
			break;
		case 3:
			if (((today.getFullYear() - adYr[0].firstChild.nodeValue == 1) &&
				(adMon[0].firstChild.nodeValue == 12))
				||
				((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 3) || 
				  (adMon[0].firstChild.nodeValue == 2) || 
				  (adMon[0].firstChild.nodeValue == 1))))
				return true;
			break;
		case 4:
			if ((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 4) ||
				  (adMon[0].firstChild.nodeValue == 3) ||
				  (adMon[0].firstChild.nodeValue == 2) ||
				  (adMon[0].firstChild.nodeValue == 1)))
				return true;
			break;
		case 5:
			if ((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 5) ||
				  (adMon[0].firstChild.nodeValue == 4) ||
				  (adMon[0].firstChild.nodeValue == 3) ||
				  (adMon[0].firstChild.nodeValue == 2)))
				return true;
			break;
		case 6:
			if ((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 6) ||
				  (adMon[0].firstChild.nodeValue == 5) ||
				  (adMon[0].firstChild.nodeValue == 4) ||
				  (adMon[0].firstChild.nodeValue == 3)))
				return true;
			break;
		case 7:
			if ((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 7) ||
				  (adMon[0].firstChild.nodeValue == 6) ||
				  (adMon[0].firstChild.nodeValue == 5) ||
				  (adMon[0].firstChild.nodeValue == 4)))
				return true;
			break;
		case 8:
			if ((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 8) ||
				  (adMon[0].firstChild.nodeValue == 7) ||
				  (adMon[0].firstChild.nodeValue == 6) ||
				  (adMon[0].firstChild.nodeValue == 5)))
				return true;
			break;
		case 9:
			if ((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 9) ||
				  (adMon[0].firstChild.nodeValue == 8) ||
				  (adMon[0].firstChild.nodeValue == 7) ||
				  (adMon[0].firstChild.nodeValue == 6)))
				return true;
			break;
		case 10:
			if ((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 10) ||
				  (adMon[0].firstChild.nodeValue == 9) ||
				  (adMon[0].firstChild.nodeValue == 8) ||
				  (adMon[0].firstChild.nodeValue == 7)))
				return true;
			break;
		case 11:
			if ((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 11) ||
				  (adMon[0].firstChild.nodeValue == 10) ||
				  (adMon[0].firstChild.nodeValue == 9) ||
				  (adMon[0].firstChild.nodeValue == 8)))
				return true;
			break;
		case 12:
			if ((today.getFullYear() == adYr[0].firstChild.nodeValue) && 
				 ((adMon[0].firstChild.nodeValue == 12) ||
				  (adMon[0].firstChild.nodeValue == 11) ||
				  (adMon[0].firstChild.nodeValue == 10) ||
				  (adMon[0].firstChild.nodeValue == 9)))
				return true;
			break;
	}
	return false;
}	//**DBcheck_date**//


//*****************************************************************************************************
// getDBSubjHead()
// ------------
// parms: valu1--the subject short-hand name requested by user
//		  *returns: subject long name for display in table
//
// converts the subject heading from the short name used to call the functions to the longer name used
// in the select list that users see.
//*****************************************************************************************************
function getDBSubjHead(valu1) {
	switch (valu1) {
		case 'Dentistry': 	return ("Dentistry &amp; Medicine");
		case 'Evidence': 	return ("Evidence-Based Medicine");
		case 'Economics': 	return ("Economics &amp; Business");
		case 'Life': 		return ("Environmental &amp; Life Sciences");
		case 'General':		return ("General Reference");
		case 'Science': 	return ("Science &amp; Engineering");
		case 'Social': 		return ("Social Sciences &amp; Humanities");
		case 'Consumer' : 	return ("Consumer Health");
		case 'Patient' :	return ("Patient Education Materials");
		case 'http://webcomm.bcd.tamhsc.edu/library/DBsXML/Consumer' : return ("Databases");

		//for those subject headings that are the same
		default: return (valu1);
	}
}


//*****************************************************************************************************
// getLangInfoDB()
// ---------------
// parms: x--array of <item> nodes from WebResources
//        i--current iteration of for loop from 0-x.length
//        ttl_arr--array of titles and associated info pulled from WebResources
//
// for each publisher get URL, name, edition, pubdate and whether it's free and new;
// write values to ttl_arr[x][1,2,4,5]
//*****************************************************************************************************
function getLangInfoDB (x, i, arr_cnt, ttl_arr) {
//alert(ttl_arr[i]);
	//Publisher Names and URLs
	lang = x[i].getElementsByTagName("language");
	
	ttl_arr[arr_cnt][10] = new Array;
	//titles can have 0-3 non-English links
	for(j=0; j<lang.length; j++) {
		lVal = lang[j].getElementsByTagName("val");
		lURL = lang[j].getElementsByTagName("langURL");

		//how many languages for this resource? and VAL (name of lang)
		ttl_arr[arr_cnt][10][j] = new Array (lVal[0].firstChild.nodeValue);
		ttl_arr[arr_cnt][11] = lang.length;
		
		//URL (to alternate web page)
		if (lURL[0])
			ttl_arr[arr_cnt][10][j][1] = lURL[0].firstChild.nodeValue;
		else
			ttl_arr[arr_cnt][10][j][1] = "#";
	}
}



//*****************************************************************************************************
// displayDBs()
// ------------
// parms: field1--whether we're dealing with a letter, subject, etc.
//        valu1--the beginnig letter or subject requested by user
//        ttl_arr[]--array of information on each <item> in the specific XML file
//        pass--how many times have we called this (or another displayXX() funct.) already?
//      * result_text--global string
//
// writes one long string to result_text which is then written to the page using innerHTML 
// property of displayResults;
// results structure is a table with a green header that includes search value and # of results;
//
// first write header,
// then if title has only one publisher write the row for the title
//		more info icon, free icon?, url, title, new icon?, more info box 
//			(with title, authors, publisher name, edition & pubdate)
//			if title had a preceding article before sorting put it back when writing title
//	else if title has multiple publishers write the row with publisher URLs after title
//			include other information and articles too
//*****************************************************************************************************
// move FREE to here
// need getAuth() or equivalent?
// need getPrvdInfo() separate or move here?
//*****************************************************************************************************
//*************************************************************************
// ttl_arr:
//		ttl_arr[x] - title 							[set in find_DBs()]
//			ttl_arr[x][1] - provider info			[set in find_DBs()]
//			ttl_arr[x][2] - date range string		[set in find_DBs()]
//			ttl_arr[x][3] - article 				[set in find_DBs()]
//			ttl_arr[x][4] - bool (Free?)			[set in find_DBs()]
//			ttl_arr[x][5] - bool (New?)				[set in find_DBs()]
//			ttl_arr[x][6] - notes info string		[set in find_DBs()]
//			ttl_arr[x][7] - limit (BCD or BUMC?)	[set in find_DBs()]
//			ttl_arr[x][8] - description string		[set in find_DBs()]  3/26/09
//			ttl_arr[x][9] - content string			[set in find_DBs()]  3/31/09
//			ttl_arr[x][10][i] - array of languages 	[set in getLangInfoDB()]	6/12/09
//			ttl_arr[x][11] - number of lans			[set in getLangInfoDB()]	6/12/09
//*************************************************************************
function displayDBs (field1, valu1, ttl_arr, pass) {
		
	//init result_text
	if (pass==1)
		result_text = '';

	//Elibrary disclaimer
	if (valu1 == 'Elibraries') {
		result_text = '<p class="Optional">Baylor Health Sciences Library maintains a list of the most relevant health related Ebooks available to our patrons. However, more Ebooks are available through subscriptions and free access to various Ebook libraries. If you are unable to find what you are looking for in our Ebook lists above, try the following Elibraries for more online books.</p>'	
	}
	
	//begin of result table
	if (pass==1) {
		result_text += '<table cellpadding="0" cellspacing="0" width="100%">';
			result_text += '<tr class="TableHeader">';
			if (field1 == "beginLett") {
				result_text += '<td class="EbooksLink" width="335">View: <u>' + valu1 + '</u></td>';
			}
			else if (field1 == "subject") {
				result_text += '<td class="EbooksLink" width="335">View: <u>' + getDBSubjHead(valu1) + '</u></td>';
			}
			else if (field1 == "BCD") {
				result_text += '<td class="EbooksLink" width="335">' + field1 + ': <u>' + valu1 + '</u></td>';
			}
			else if (field1 == "new") {  //New ebooks
				result_text += '<td class="EbooksLink" width="335">' + valu1 + '</td>';
			}
			else if (field1 == "nonJava") {
				result_text += '<td class="EbooksLink" width="335">View: <u>' + valu1 + '</td>';
			}
			result_text += '<td class="EbooksLink" width="200" align="right">Number of DBs: <u>' + (ttl_arr.length) + '</u></td>';
			result_text += '</tr>';
	}
	else {
		result_text += '<table cellpadding="0" cellspacing="0" width="100%">';
		//add some formatting
			result_text += '<tr><td width="30px">&nbsp;</td><td width="335">&nbsp;</u></td><td width="200" align="right">&nbsp;</td></tr>';
		//add a subheader to show what the resource type is, only if not the nonJava page
			result_text += '<tr><td>&nbsp;</td></tr><tr><td align="center" style="border-bottom:solid 2px #006600"><a href="javascript:void(0);" onClick="showHideList(' + "'DBList'" + ');"><img src="http://bcd.tamhsc.edu/library/img/web/misc/green-hide.gif" id="DBListImg" alt="Hide List" title="Hide List"/></a></td><td colspan="2" style="border-bottom:solid 2px #006600"><font color="#006600" face="Arial, Helvetica, sans-serif" size="-1"><strong>Databases</strong></font></td></tr>';
		//put a border along the left side and start the table
			result_text += '<tr><td style="border-left:solid 2px #006600">&nbsp;</td><td colspan="2" id="DBList"><table cellpadding="0" cellspacing="0" width="100%">';
//			result_text += '<tr><td valign="top" style="border-top:solid 2px #99CC99"><img src="http://bcd.tamhsc.edu/library/img/web/misc/3rd_DB_Title_grn.gif" class="VrtMenuTitle" style="vertical-align:top" /></td> <td colspan="2" valign="top" width="100%" style="border-top:solid 2px #99CC99"><table cellpadding="0" cellspacing="0" width="100%">';
	}

	for (i=0; i<ttl_arr.length; i++) {
			//set vars to ttl_arr[] values
			Title 	= ttl_arr[i][0];
			Provdr	= ttl_arr[i][1];
				Name    = ttl_arr[i][1][0];
				URL	    = ttl_arr[i][1][1];
				About	= ttl_arr[i][1][2];
			DateRng = ttl_arr[i][2];
			Article = ttl_arr[i][3];
			Free 	= ttl_arr[i][4];
			New 	= ttl_arr[i][5];
			Notes	= ttl_arr[i][6];
			Limit	= ttl_arr[i][7];
			Descr	= ttl_arr[i][8];
			Cntnt	= ttl_arr[i][9];
			numLang	= ttl_arr[i][11];
			
		//for new DBs we need to keep count of the total # of new databases, since
		//this function gets called 3 times for newest, newer and new books
		x = i + newCount;
				
		//put section header rows based on first letter of title
		if (valu1 == "All") {
			if (i==0) {
				result_text += '<tr><td>&nbsp;</td></tr>';
				result_text += '<tr class="TableHeader"><td colspan="2"><a class="EbooksLink">A</a></td></tr>';
			}
			else if ((startsWithLettRegExp.test(Title.toString())) && (Title.toString().charAt(0) != ttl_arr[i-1][0].toString().charAt(0))) {  //the first letter of the title has changed
				result_text += '<tr><td>&nbsp;</td></tr>';
				result_text += '<tr class="TableHeader"><td><a class="EbooksLink" name="' + Title.toString().charAt(0) + '">' + Title.toString().charAt(0) + '</a></td>';
				if (pass == 1)
					result_text += '<td align="right"><a href="#top">top<img src="http://bcd.tamhsc.edu/library/img/web/misc/return_arrow_bw.gif" height="20px" width="20px" border="0" alt="Return to top of page." align="texttop" title="Return to top of page."></a></td></tr>';
				else
					//don't put the link back to top of page if this is part of a Subject page
					result_text += '<td>&nbsp;</td></tr>';
			}
		}

		statusMsg = "Resource Info";
		statusBlnk = "";
		
		//base the info note numbering on a system with the pass # as a prefix
		passNum = pass + "-" + i;

		resultId = "infoNote" + passNum;
		tableRowId = "resultRow" + passNum;
		infoBoxId = "infoBox" + passNum;
		infoBoxClass = "DB_info_box";
		infoBoxId_str = "'infoBox" + passNum + "'";
		infoBoxClass_str = "'DB_info_box'";

		if (pass==1)
			result_text += '<tr><td class="TableRow" colspan="2" id="' + tableRowId + '">';
		else
			result_text += '<tr><td class="TableRow" colspan="2" id="' + tableRowId + '" style="padding-left:1px">';

			//INFO-more icon and event action
			result_text += '<a href="javascript:void(0);" onClick="showHide_DBs(' + infoBoxId_str + ',' + infoBoxClass_str +')" style="cursor:help"><img align="texttop" src="http://bcd.tamhsc.edu/library/img/web/misc/info-more.gif" id="' + resultId + '" title="Show info"  onMouseOver="window.status=statusMsg; return true" onMouseOut="window.status=statusBlnk;"/></a> ';
			//FREE?
			if (Free)
				result_text += '<img align="texttop" src="http://bcd.tamhsc.edu/library/img/web/buttons_bars/FreeStar.gif" alt="Free"> ';
			//URL
			result_text += '<a class="Results" href="' + URL.toString() + '">';
			
			//put any preceding articles back at front of title
			if (Article == 1)
				result_text += 'A ';
			else if (Article == 2)
				result_text += 'An ';
			else if (Article == 3)
				result_text += 'The ';
			//TITLE
			result_text += Title.toString() + '</a>';
			
			//if MULTIPLE LANGUAGEs, then create links to them too
			if (numLang > 0) {
//alert("lang > 0");
				//start a new line and indent in a bit
				result_text += '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				if (numLang == 1) {
					if (ttl_arr[i][10][0][1]) {
						Txt = ttl_arr[i][10][0][0];
						lURL = ttl_arr[i][10][0][1];
						
						if (lURL == '#')
							result_text += ' (' + Txt.toString() + ')';
						else
							result_text += ' (<a class="Results" href="' + lURL.toString() + '">' + Txt.toString() + '</a>)';
					}
				}

				else {
					result_text += '(';
					for (j=0; j<numLang; j++) {
						Txt = ttl_arr[i][10][j][0];
						lURL = ttl_arr[i][10][j][1];
					
						result_text += '<a class="Results" href="' + lURL.toString() + '">' + Txt.toString() + '</a>';
						//separate entries with a "|"
						if (j<(numLang-1))
							result_text += ' | ';
					}
					result_text += ')';
				}
			}
			
			//NEW?
			if (New)
				result_text += ' <img src="http://bcd.tamhsc.edu/library/img/web/misc/new.gif" align="absmiddle" alt="new" title="new"/>';
			
			//LIMITed avail? If item in only avail. at BCD, etc.
			if (Limit)
				if (Limit == 'BCD only')
					result_text += ' <font color="red"><i>BCD only</i></font>';
				else if (Limit == 'BUMC only')
					result_text += ' <font color="red"><i>BUMC only</i></font>';
			
			//new divs for additional info slidedown box
			result_text += '<div id="' + infoBoxId + '" class="' + infoBoxClass +'" style="display:none">';
				result_text += '<center>';
					result_text += '<table width="90%" cellpadding="0" cellspacing="0" style="font-size:1.2em">';
						//Date Range info
						if (DateRng) {
						result_text += '<tr>';
							result_text += '<td style="border-bottom:solid 1px #000000" valign="top"><b>Date Range: </b></td>';
							result_text += '<td style="border-bottom:solid 1px #000000">[' + DateRng.toString() + ']</td>';
						result_text += '</tr>';
						}
						//PUBLISHER's NAME & ABOUT URL
						result_text += '<tr>';
							result_text += '<td width="20%" style="border-bottom:solid 1px #000000" valign="top"><b>Provider: </b></td>';
							result_text += '<td width="80%" style="border-bottom:solid 1px #000000">' + Name.toString() + ' (<a href="' + About.toString() + '" alt="Provider info" title="Provider info"><b>About</b></a>)</td>';
						result_text += '</tr>';
						//DESCR
						if(Descr) {
						result_text += '<tr>';
							result_text += '<td style="border-bottom:solid 1px #000000" valign="top"><b>Description: </b></td>';
							result_text += '<td style="border-bottom:solid 1px #000000">' + Descr.toString() + '</td>';
						result_text += '</tr>';
						}
						//NOTES
						if (Notes) {
						result_text += '<tr>';
							result_text += '<td style="border-bottom:solid 1px #000000" valign="top"><font color="#FF3300"><b>Note: </b></font></td>';
							result_text += '<td style="border-bottom:solid 1px #000000">' + Notes.toString() + '</td>';
						result_text += '</tr>';
						}
					result_text += '</table>';
				result_text += '</center>';
			result_text += '</div>';
	
		result_text += '</td></tr>';
	}
	result_text += '<tr><td>&nbsp;</td></tr>';
	result_text += "</table>";
	
	if (pass>1)
		result_text += " </td></tr></table>";
	
	//before leaving add the length of ttl_arr to newCount; if this is being called from find_newDBs()
	//this this function will be called again, and newCount will serve as an offset to keep a count of
	//each new book
	newCount += ttl_arr.length;
}	//**displayDBs**//


//*****************************************************************************************************
// displayAllDBs()						***NOT USED***
// ------------
// parms: valu1--the beginnig letter or subject requested by user
//        ttl_arr[]--array of information on each <item> in the specific XML file
//      * result_text--global string
//
// same as displayEBs() but only called when user requests View All option--it does not include
// the more info box (it takes way to long to build the display for all that info); instead
// the info icon displays the publisher name as a title/alt tag of the info icon image.
//*****************************************************************************************************
function displayAllDBs (valu1, ttl_arr) {

	//init result_text
	result_text = '';
	
	result_text += '<table cellpadding="0" cellspacing="0" width="100%">';
		result_text += '<tr class="TableHeader">';
			result_text += '<td class="EbooksLink" width="200">View: ' + valu1 + '</td>';
			result_text += '<td class="EbooksLink" width="365" align="right">Number of Titles: ' + (ttl_arr.length) + '</td>';
		result_text += '</tr>';
		result_text += '<tr><td>&nbsp;</td></tr>';

	for (i=0; i<ttl_arr.length; i++) {
			//set vars to ttl_arr[] values
			Title = ttl_arr[i][0];
			numPubs = ttl_arr[i][2];
			Article = ttl_arr[i][3];
			Free = ttl_arr[i][4];
			New = ttl_arr[i][5];
		
		//put section header rows based on first letter of title
		if (i==0) {
			result_text += '<tr class="TableHeader"><td colspan="2"><a class="EbooksLink">0to9</a></td></tr>';
		}
		else if ((startsWithLettRegExp.test(Title.toString())) && (Title.toString().charAt(0) != ttl_arr[i-1][0].toString().charAt(0))) {  //the first letter of the title has changed
			result_text += '<tr><td>&nbsp;</td></tr>';
			result_text += '<tr class="TableHeader"><td><a class="EbooksLink" name="' + Title.toString().charAt(0) + '">' + Title.toString().charAt(0) + '</a></td>';
			result_text += '<td align="right"><a href="#top">top<img src="http://bcd.tamhsc.edu/library/img/web/misc/return_arrow_bw.gif" height="20px" width="20px" border="0" alt="Return to top of page." align="texttop" title="Return to top of page."></a></td></tr>';
		}
		
		//create the info icon and title link 
		for (j=0; j<(numPubs); j++) {
				//Publisher sub-fields in ttl_var[]
				URL     = ttl_arr[i][1][j][0];
				Name    = ttl_arr[i][1][j][1];
			
			result_text += '<tr><td class="TableRow" colspan="2">';
				result_text += '<img align="texttop" src="http://bcd.tamhsc.edu/library/img/web/buttons_bars/info.gif" alt="Provided through ' + Name.toString() + '" title="Provided through ' + Name.toString() + '"> ';
				
				//include a Free icon if free from this publisher
				if (Free)
					result_text += '<img align="texttop" src="http://bcd.tamhsc.edu/library/img/web/buttons_bars/FreeStar.gif" alt="Free"> '
				
				result_text += '<a class="Results" href="' + URL.toString() + '">';
				
				//put any preceding articles back at front of title
				if (Article == 1)
					result_text += 'A ';
				else if (Article == 2)
					result_text += 'An ';
				else if (Article == 3)
					result_text += 'The ';
				result_text += Title.toString() + '</a>';
				
				//for titles with multiple pubs, include pub name in ()
				if (numPubs>1)
					result_text += ' (' + Name.toString() + ')';
				
				//if this is new then include the new! icon
				if (New)
					result_text += ' <img src="http://bcd.tamhsc.edu/library/img/web/misc/new.gif" align="absmiddle" alt="new" title="new"/>';
				
				//LIMITed avail? If item in only avail. at BCD, etc.
				if (Limit)
					if (Limit == 'BCD only')
						result_text += ' <font color="red"><i>BCD only</i></font>';
					else if (Limit == 'BUMC only')
						result_text += ' <font color="red"><i>BUMC only</i></font>';
			

			result_text += '</td></tr>';
		}
	}
	result_text += "</table>";
}	//**displayAllDBs**//


//*****************************************************************************************************
// find_DBs()
// -------------
// parms: field1--indicates what type of value valu1 is (beginLett, subject)
//        valu1--the letter or subject used to locate the appropriate XML file
//
// for each entry in the specified XML file, remove any preceding articles from the titles,
// write the title and article indicator to ttl_arr[], then gather the publisher and author info;
// sort the array alphabetically by title; 
// call displayDBs() to create the result_text string and set to displayResults.innerHTML
//*****************************************************************************************************
function find_DBs (field1, valu1) {
//alert("find_DBs");

		var precedArt = /^A\s|^An\s|^The\s/i;
		var ttl_arr = new Array();
		var fPath = "http://webcomm.bcd.tamhsc.edu/library/DBsXML/";

	if (field1 != 'nonJava') {
		//change pointer and text to show something is happening
		document.body.style.cursor="wait";
		document.getElementById('displayResults').innerHTML = "<p>Working...</p>";
		//reset the subject category choice
		document.getElementById('EB_Subject').selectedIndex = 0;
	}
	
	//reset the slidedownIndex used in showHide_Ebooks() of dropDown.js
	//everytime that a new page is requested, in case they left a info box
	//open when they went to another page
	//slidedownIndex = -1;
	//don't need this anymore; using showhide_DBs() instead
	
	if (valu1 == 'All') {
		if (field1 == 'nonJava') {
			fName = "http://bcd.tamhsc.edu/library/databases/abc.xml";
			DBs = loadXMLDoc(fName);
		}
		else {
			//change some appearance parameters based on search choice
			document.getElementById('hiddenJumpTo').style.visibility='visible'; 
			document.getElementById('alphaloopAll').style.borderBottom='none'
			
			//determine the name of the file to load
			fName = "abc.xml";
			DBs = loadXMLDoc(fName);
		}
	}
	else {
		//change some appearance parameters based on search choice
		document.getElementById('hiddenJumpTo').style.visibility='hidden';
		document.getElementById('alphaloopAll').style.borderBottom='1px solid';
		document.getElementById('alphaloopAll').className='alphaloopAll'
		
		//determine the name of the file to load
		fName = valu1 + ".xml";
		DBs = loadXMLDoc(fName);
	}
	
	//move the XML file into variable x
	x=DBs.getElementsByTagName("item");
//alert (x.length);
		
	for (i=0; i<x.length; i++) {
		ttl 	= x[i].getElementsByTagName("title");					//ttl_arr[x]
		provd 	= x[i].getElementsByTagName("provider");				//ttl_arr[x][1]
			prvName = provd[0].getElementsByTagName("name");
			url 	= provd[0].getElementsByTagName("URL");
			about 	= provd[0].getElementsByTagName("aboutURL");
		dateRng = x[i].getElementsByTagName("dateRange");				//ttl_arr[x][2]
		free 	= x[i].getElementsByTagName("source");					//ttl_arr[x][4]
		adDate 	= x[i].getElementsByTagName("date_added");				//ttl_arr[x][5]
		notes 	= x[i].getElementsByTagName("notes");					//ttl_arr[x][6]
		limit	= x[i].getElementsByTagName("limit");					//ttl_arr[x][7]
		descr	= x[i].getElementsByTagName("descr");					//ttl_arr[x][8]
		cntnt	= x[i].getElementsByTagName("content");					//ttl_arr[x][9]
		lang	= x[i].getElementsByTagName("language");				//ttl_arr[x][10]

		//Check the title for preceding A, An, or The
		if (ttl[0].firstChild.nodeValue.substr(0,2) == "A ") {
			title = ttl[0].firstChild.nodeValue.slice(2);
			art = 1;
		}
		else if (ttl[0].firstChild.nodeValue.substr(0,3) == "An ") {
			title = ttl[0].firstChild.nodeValue.slice(3);
			art = 2;
		}
		else if (ttl[0].firstChild.nodeValue.substr(0,4) == "The ") {
			title = ttl[0].firstChild.nodeValue.slice(4);
			art = 3;
		}
		else {
			title = ttl[0].firstChild.nodeValue;
			art = 0;
		}
		ttl_arr[i] = new Array (title, new Array ());
		ttl_arr[i][3] = art;

		//URL & NAME -- array
		ttl_arr[i][1] = new Array (prvName[0].firstChild.nodeValue, url[0].firstChild.nodeValue, about[0].firstChild.nodeValue);
	
		//get date range of DB, if any
		if (dateRng[0]) {
			ttl_arr[i][2] = dateRng[0].firstChild.nodeValue;
		}

		//FREE?
		if (free[0]) {
			if (free[0].firstChild.nodeValue == "Free")
				ttl_arr[i][4] = true;
		}
			
		//NEW?
		if (adDate[0]) 
			ttl_arr[i][5] = DBcheck_date(adDate);

		//get any notes
		if (notes[0]) {
			ttl_arr[i][6] = notes[0].firstChild.nodeValue;
		}
		
		//LIMITed avail?
		if (limit[0]) {
			ttl_arr[i][7] = limit[0].firstChild.nodeValue;
		}
		
		//DESCRiption avail?
		if (descr[0]) {
			ttl_arr[i][8] = descr[0].firstChild.nodeValue;
		}

		//CoNTeNT avail?
		if (cntnt[0]) {
			ttl_arr[i][9] = cntnt[0].firstChild.nodeValue;
		}

		//non-English LANGUAGE?
		if (lang[0]) {
			getLangInfoDB(x, i, i, ttl_arr);
		}
		else //no non-English languages
			ttl_arr[i][11] = 0;
	}
	
	
	//sort the array of results
	ttl_arr.sort();

	//set newCount to 0 in case it was previously called by find_newDBs()
	newCount = 0;
	
	//if this is for the nonJava page then send the result back to insert in the HTML page
	if (field1 == "nonJava") {
		displayDBs (field1, valu1, ttl_arr, 1);
//alert (result_text);
		return result_text;
	}
	//otherwise display the results
	else 
		displayDBs (field1, valu1, ttl_arr, 1);
	
	//change pointer back to default
	document.body.style.cursor="default";
	
//alert(result_text);

	//display result table
	document.getElementById('displayResults').innerHTML = result_text;
}	//**Find_DBs**//

