// JavaScript Document
// scripts to sort and display the contents of a Web Resource XML file (generated by makeXML.js)

// First call find_WEBs which loads the correct file, removes preceding articles from the title and saves the titles;
// find_WEBs then calls getPrvdInfo and getAuthInfo to gather associated publisher and author/editor info and save to ttl_arr;
//   getPrvdInfo also determines if title is new by calling check_date
// find_WEBs then sorts ttl_arr and displays the results

//*************************************************************************
// ttl_arr:
//		ttl_arr[x] - title 							[set in find_WEBs()]
//			ttl_arr[x][1][y] - provider info		[set in find_WEBs()]
//			ttl_arr[x][2] - date range string		[set in find_WEBs()]
//			ttl_arr[x][3] - article 				[set in find_WEBs()]
//			ttl_arr[x][4] - bool (Availability)		[set in find_WEBs()]
//			ttl_arr[x][5] - bool (New?)				[set in find_WEBs()]
//			ttl_arr[x][6] - notes info string		[set in find_WEBs()]
//			ttl_arr[x][7][i] - array of languages 	[set in getLangInfoWeb()]
//			ttl_arr[x][8] - number of lans			[set in getLangInfoWeb()]
//			ttl_arr[x][9] - description string		[set in find_WEBs()]  4/22/09
//*************************************************************************

//Global vars
//-----------
var result_text = '';
var startsWithLettRegExp = /^\D/;
var newCount = 0;						//??????????????change this???????????
var searchStr;


//*****************************************************************************************************
// WEBcheck_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 WEBcheck_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;
}	//**WEBcheck_date**//


//*****************************************************************************************************
// getLangInfoWeb()
// ----------------
// 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 getLangInfoWeb (x, i, ttl_arr) {
	//Publisher Names and URLs
	lang = x[i].getElementsByTagName("language");
	
	ttl_arr[i][7] = new Array;
	//titles can have 0-3 non-English links
	for(j=0; j<lang.length; j++) {
		lVal = lang[j].getElementsByTagName("val");
		lTtl = lang[j].getElementsByTagName("lTitle");
		lURL = lang[j].getElementsByTagName("langURL");

		//how many languages for this resource? and VAL (name of lang)
		ttl_arr[i][7][j] = new Array (lVal[0].firstChild.nodeValue);
		ttl_arr[i][8] = lang.length;
		
		//if a TITLE is available use it instead of VAL
		if (lTtl[0])
			ttl_arr[i][7][j][0] = lTtl[0].firstChild.nodeValue;
		
		//URL (to alternate web page)
		if (lURL[0])
			ttl_arr[i][7][j][1] = lURL[0].firstChild.nodeValue;
		else
			ttl_arr[i][7][j][1] = "#";
	}
	
}


//*****************************************************************************************************
// getWEBSubjHead()
// ------------
// 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 getWEBSubjHead(valu1) {
	switch (valu1) {
		case 'Association': 	return ("Associations &amp; Organizations");
		case 'Trials': 			return ("Clinical Trials");
		case 'Pharm': 			return ("Drugs &amp; Medications");
		case 'Ejournals': 		return ("Electronic Journals");
		case 'Financ': 			return ("Financial Assistance");
		case 'Locator': 		return ("Find a Dentist, Physician, or Specialist");
		case 'General': 		return ("General Health Guides");
		case 'Government': 		return ("Government Sources");
		case 'Tests': 			return ("Medical Tests");
		case 'NonEnglish': 		return ("Non-English Language Resources");
		case 'Search': 			return ("Finding &amp; Evaluating Web Info");

		case 'Evidence': 		return ("Evidence-Based Medicine");
		case 'Patient':			return ("Patient Education Materials");
		
		//for those subject headings that are the same
		default: return (valu1);
	}
}


//*****************************************************************************************************
// displayWEBs()
// ------------
// 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
//      * 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_WEBs()]
//			ttl_arr[x][1][y] - provider info		[set in find_WEBs()]
//			ttl_arr[x][2] - date range string		[set in find_WEBs()]
//			ttl_arr[x][3] - article 				[set in find_WEBs()]
//			ttl_arr[x][4] - bool (Availability)		[set in find_WEBs()]
//			ttl_arr[x][5] - bool (New?)				[set in find_WEBs()]
//			ttl_arr[x][6] - notes info string		[set in find_WEBs()]
//			ttl_arr[x][7][i] - array of languages 	[set in getLangInfoWeb()]
//			ttl_arr[x][8] - number of lans			[set in getLangInfoWeb()]
//			ttl_arr[x][9] - description string		[set in find_WEBs()]  4/22/09
//*************************************************************************
function displayWEBs (field1, valu1, ttl_arr, pass) {
//alert ("displayWEBs");
	
	//init result_text
	result_text = '';

	//begin of result table
	result_text += '<table cellpadding="0" cellspacing="0" width="100%">';
		result_text += '<tr colspan="2" class="TableHeader"><td width="30px">&nbsp;</td>';
		if ((field1 == "beginLett") || (field1 == "nonJava")) {
			result_text += '<td class="EbooksLink" width="335">View: <u>' + valu1 + '</u></td>';
		}
		else if (field1 == "new") {  //New WebResources
			result_text += '<td class="EbooksLink" width="335">' + valu1 + '</td>';
		}
		else {
			result_text += '<td class="EbooksLink" width="335">View: <u>' + getWEBSubjHead(valu1) + '</u></td>';
		}
		result_text += '<td class="EbooksLink" width="200" align="right">Number of Web Sites: <u>' + (ttl_arr.length) + '</u></td>';
		result_text += '</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(' + "'WebList'" + ');"><img src="http://bcd.tamhsc.edu/library/img/web/misc/green-hide.gif" id="WebListImg" 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>Web Sites</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="WebList"><table cellpadding="0" cellspacing="0" width="100%">';
//			result_text += '<tr><td valign="top"><img src="http://bcd.tamhsc.edu/library/img/web/misc/3rd_WEB_Title_grn.gif" class="VrtMenuTitle" style="vertical-align:top" /></td> <td colspan="2"><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];
			Avail 	= ttl_arr[i][4];
			New 	= ttl_arr[i][5];
			Notes	= ttl_arr[i][6];
			numLang	= ttl_arr[i][8];
			Descr	= ttl_arr[i][9];
			
		//for new Web resources we need to keep count of the total # of new books, 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>';
				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>';
			}
		}

		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'";

		result_text += '<tr><td class="TableRow" colspan="2" id="' + tableRowId + '">';
			//INFO-more icon and event action
			result_text += '<a href="javascript:void(0);" onClick="showHide_DBs(' + infoBoxId_str + ',' + infoBoxClass_str +');return false;" style="cursor:help"><img align="texttop" src="http://bcd.tamhsc.edu/library/img/web/misc/info-more.gif" id="' + resultId + '" title="More info"  onMouseOver="window.status=statusMsg; return true" onMouseOut="window.status=statusBlnk;"/></a> ';
			//FREE?
			if (Avail == 'Free')
				result_text += '<img align="texttop" src="http://bcd.tamhsc.edu/library/img/web/buttons_bars/FreeStar.gif" alt="Free"> ';
			else if (Avail == 'Mix')
				result_text += '<img align="texttop" src="http://bcd.tamhsc.edu/library/img/web/misc/Half_FreeStar.gif" alt="For Free &amp; For Fee content available"> ';
			
			//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) {
				//start a new line and indent in a bit
				result_text += '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
				if (numLang == 1) {
					Txt = ttl_arr[i][7][0][0];
					lURL = ttl_arr[i][7][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][7][j][0];
						lURL = ttl_arr[i][7][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"/>';
			
			//AVAIL? If item in only avail. at BCD, etc.
//			if (Avail != 'Free')
//					result_text += ' <font color="red"><i> ' + Avail + ' </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>';
	}
	
	if (valu1 == "Ejournals")
		result_text += '<tr><td class="TableRow"><a href="http://linkresolver.tamu.edu:9003/bhsl/azlist/default?perform=locate">Search</a> or <a href="http://linkresolver.tamu.edu:9003/bhsl/azlist/default?perform=searchCategories">Browse</a> our Ejournals page for more titles.</td></tr>';
	else if (valu1 == "EB")
		result_text += '<tr><td class="TableRow">See BHSL&rsquo;s <a href="http://webcomm.bcd.tamhsc.edu/library/EbooksXML/Ebooks_XML.html">Ebooks page</a> for more titles.</td></tr>';
//	else
//		result_text += '<tr><td>&nbsp;</td></tr>';
		
	result_text += '</table></td></tr>';
	result_text += "</table>";
	
	//before leaving add the length of ttl_arr to newCount; if this is being called from find_newEbooks()
	//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;
}	//**displayWEBs**//


//*****************************************************************************************************
// displayAllWEBs()						***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 displayAllWEBs (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>";
}	//**displayAllWEBs**//


//*****************************************************************************************************
// find_WEBs()
// -------------
// parms: field1--indicates what type of value valu1 is (beginLett, subject)
//        valu1--the letter or subject used to locate the appropriate XML file
//        field2--indicates what type of value valu1 is (beginLett, subject)
//        valu2--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 displayWEBs() to create the result_text string and set to displayResults.innerHTML
//*****************************************************************************************************
function find_WEBs (field1, valu1, field2, valu2) {
//alert("find_WEBs");

		var precedArt = /^A\s|^An\s|^The\s/i;
		var ttl_arr = new Array();
		var pass = 1;

	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

	//determine the directory of the file to load
//	if (field2 == 'resc_type')
//		if (valu2 == 'Consumer Health')
//			dName = "ConsHXML";

	//now get the rest of the file name
	if (valu1 == 'All') {
		if (field1 == 'nonJava') {
			fName = "http://bcd.tamhsc.edu/library/consumer_health/abc.xml";
			WebRsc = 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";
			WebRsc = loadXMLDoc(fName);
		}
	}
	else if (valu2 != 'SubjGd') {
		//This is not a subject guide page (i.e. no "View All" button), so
		//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";
		WebRsc = loadXMLDoc(fName);
	}
	else {
		//determine the name of the file to load
		fName = valu1 + ".xml";
		WebRsc = loadXMLDoc(fName);
	}
	
	//move the XML file into variable x
	x=WebRsc.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]
		avail 	= x[i].getElementsByTagName("avail");					//ttl_arr[x][4]
		adDate 	= x[i].getElementsByTagName("date_added");				//ttl_arr[x][5]
		notes 	= x[i].getElementsByTagName("notes");					//ttl_arr[x][6]
		lang	= x[i].getElementsByTagName("language");				//ttl_arr[x][7]
		descr	= x[i].getElementsByTagName("descr");					//ttl_arr[x][9]

		//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, AboutURL & NAME -- array
		//first make sure there is an aboutURL; if not fill it in with blank link value
		if ((about.length != 0) && (about[0].firstChild != null))
			ttl_arr[i][1] = new Array (prvName[0].firstChild.nodeValue, url[0].firstChild.nodeValue, about[0].firstChild.nodeValue);
		else
			ttl_arr[i][1] = new Array (prvName[0].firstChild.nodeValue, url[0].firstChild.nodeValue, '#');
	
		//get date range of resource, if any
		if (dateRng[0]) {
			ttl_arr[i][2] = dateRng[0].firstChild.nodeValue;
		}

		//AVAILABILITY
		if (avail[0]) {
			ttl_arr[i][4] = avail[0].firstChild.nodeValue;
		}
			
		//NEW?
		if (adDate[0]) 
			ttl_arr[i][5] = WEBcheck_date(adDate);

		//get any notes
		if (notes[0]) {
			ttl_arr[i][6] = notes[0].firstChild.nodeValue;
		}
		
		//non-English LANGUAGE?
		if (lang[0]) {
			getLangInfoWeb(x, i, ttl_arr);
		}
		else //no non-English languages
			ttl_arr[i][8] = 0;
			
		//DESCRiption avail?
		if (descr[0]) {
			ttl_arr[i][8] = descr[0].firstChild.nodeValue;
		}


	}
	
	
	//sort the array of results
	ttl_arr.sort();

	//set newCount to 0 in case it was previously called by find_newEbooks()
	newCount = 0;
	
	//if this is for the nonJava page then send the result back to insert in the HTML page
	if (field1 == "nonJava") {
		displayWEBs (field1, valu1, ttl_arr, pass);
//alert (result_text);
		return result_text;
	}
	//otherwise display the results
	else 
	displayWEBs (field1, valu1, ttl_arr, pass); pass++;
	
	//check for databases & ebooks, and display them also
	prepare_DBs(field1, valu1, field2, valu2, pass); pass++;
	prepare_EBs(field1, valu1, field2, valu2, pass); pass++;
	if (valu2 == 'SubjGd')
		prepare_EJs(field1, valu1, pass);
//alert (result_text);
	
	//change pointer back to default
	document.body.style.cursor="default";

	//display result table
	document.getElementById('displayResults').innerHTML = result_text;
	
	return (result_text);
}	//**Find_WEBs**//


//*****************************************************************************************************
// prepare_DBs()
// -------------
// parms: field1--indicates what type of value valu1 is (beginLett, subject)
//        valu1--the letter or subject used to locate the appropriate XML file
//        field2--indicates what type of value valu1 is (beginLett, subject)
//        valu2--the letter or subject used to locate the appropriate XML file
//        pass--how many times have we called this (or another displayXX() funct.) already?
//
// 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
//
// the source file for this fuction is Consumer.xml in DBsXML/. Since it is a small file, we will
// step through its entries here, looking only for items that match the criteria of field1/valu1.
//
// this is a copy of find_DBs() from DBshowXML.js, but without the initial setup stuff.
//*****************************************************************************************************
function prepare_DBs (field1, valu1, field2, valu2, pass) {

		var precedArt = /^A\s|^An\s|^The\s/i;
		var ttl_arr = new Array();
		var arr_cnt = 0;

	//determine the name of the file to load
	if ((field2 == 'resc_type') && (valu2 == 'Consumer Health')) {
		fName = "../DBsXML/Consumer.xml";
	}
	else fName = "../DBsXML/" + valu1 + ".xml";
	
	//load the XML file and initialize
//alert(fName);
	DBs = loadXMLDoc(fName);
	x=DBs.getElementsByTagName("item");
//alert(x.length);
		
	for (i=0; i<x.length; i++) {
		var grabit = false;

		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]

		//if a field1 is "subject" check valu1 to see if it matches any of the item's subject fields
		if (field1 == "subject") {
			subj = x[i].getElementsByTagName("subject");
			if ((subj.length != 0) && (subj[0].firstChild != null))
				for (j=0; j<subj.length; j++) {
					if (subj[j].firstChild.nodeValue.match(valu1) != null)
						grabit = true;
				}
		}
		else if (field1 == "source") {
			srce = x[i].getElementsByTagName("source");
			if ((srce.length != 0) && (srce[0].firstChild != null))
				for (j=0; j<srce.length; j++) {
					if (srce[j].firstChild.nodeValue.match(valu1) != null)
						grabit = true;
				}
		}
		else if (field1 == "language") {
			lang = x[i].getElementsByTagName("language");
			if ((lang.length != 0) && (lang[0].firstChild != null))
				grabit = true;
		}
		
		//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;
		}
		//if field1 is "beginLett" check valu1 to see if it matches the first letter of the title
		if (field1 == "beginLett") {
			if ((valu1 == title.charAt(0)) || (valu1 == 'All'))
				grabit = true;
		}
		
		
		if (grabit) {
			ttl_arr[arr_cnt] = new Array (title, new Array ());
			ttl_arr[arr_cnt][3] = art;
	
			//URL & NAME -- array
			ttl_arr[arr_cnt][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[arr_cnt][2] = dateRng[0].firstChild.nodeValue;
			}
	
			//FREE?
			if (free[0]) {
				if (free[0].firstChild.nodeValue == "Free")
					ttl_arr[arr_cnt][4] = true;
			}
				
			//NEW?
			if (adDate[0]) 
				ttl_arr[arr_cnt][5] = DBcheck_date(adDate);
	
			//get any notes
			if (notes[0]) {
				ttl_arr[arr_cnt][6] = notes[0].firstChild.nodeValue;
			}
			
			//LIMITed avail?
			if (limit[0]) {
				ttl_arr[arr_cnt][7] = limit[0].firstChild.nodeValue;
			}
		
			//DESCRiption avail?
			if (descr[0]) {
				ttl_arr[arr_cnt][8] = descr[0].firstChild.nodeValue;
			}
	
			//CoNTeNT avail?
			if (cntnt[0]) {
				ttl_arr[arr_cnt][8] = cntnt[0].firstChild.nodeValue;
			}
				
			//non-English LANGUAGE?
			if (lang[0]) {
				getLangInfoDB(x, i, arr_cnt, ttl_arr);
			}
			else //no non-English languages
				ttl_arr[arr_cnt][11] = 0;
//alert(i + ", " + arr_cnt + ", " + ttl_arr[arr_cnt][11] + ", " + ttl_arr[arr_cnt][10]);

			//increase the array count by 1
			arr_cnt++;
		}
	}
	
	
	if (ttl_arr.length > 0) {
		//sort the array of results
		ttl_arr.sort();
		//display the results
		displayDBs (field1, valu1, ttl_arr, 2);
	}
	
	//display result table
	document.getElementById('displayResults').innerHTML = result_text;
}	//**Prepare_DBs**//


//*****************************************************************************************************
// prepare_EBs()
// -------------
// parms: field1--indicates what type of value valu1 is (beginLett, subject)
//        valu1--the letter or subject used to locate the appropriate XML file
//        field2--indicates what type of value valu1 is (beginLett, subject)
//        valu2--the letter or subject used to locate the appropriate XML file
//        pass--how many times have we called this (or another displayXX() funct.) already?
//
// 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 displayEBs() to create the result_text string and set to displayResults.innerHTML
//
// the source file for this fuction is Consumer.xml in DBsXML/. Since it is a small file, we will
// step through its entries here, looking only for items that match the criteria of field1/valu1.
//
// this is a copy of find_Ebooks() from EBshowXML.js, but without the initial setup stuff.
//*****************************************************************************************************
function prepare_EBs (field1, valu1, field2, valu2, pass) {

		var precedArt = /^A\s|^An\s|^The\s/i;
		var ttl_arr = new Array();
		var arr_cnt = 0;

	//determine the name of the file to load
	if ((field2 == 'resc_type') && (valu2 == 'Consumer Health')) {
		fName = "../EbooksXML/Consumer.xml";
	}
	else fName = "../EbooksXML/" + valu1 + ".xml";

//load the XML file and initialize
	Ebooks = loadXMLDoc(fName);
	x=Ebooks.getElementsByTagName("item");

		
	for (i=0; i<x.length; i++) {
		var grabit = false;
		ttl = x[i].getElementsByTagName("title");
		series = x[i].getElementsByTagName("series");
		notes = x[i].getElementsByTagName("notes");
		pubs = x[i].getElementsByTagName("publisher");
		adDate = x[i].getElementsByTagName("date_added");
		auths = x[i].getElementsByTagName("editauth");

		//if a field1 is "subject" check valu1 to see if it matches any of the item's subject fields
		if (field1 == "subject") {
			subj = x[i].getElementsByTagName("subject");
			if ((subj.length != 0) && (subj[0].firstChild != null))
				for (j=0; j<subj.length; j++) {
					if (subj[j].firstChild.nodeValue.match(valu1) != null) {
						grabit = true;
					}
				}
		}
		else if (field1 == "language") {
			lang = x[i].getElementsByTagName("language");
			if ((lang.length != 0) && (lang[0].firstChild != null)) {
				grabit = true;
			}
		}
		
		//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;
		}
		//if field1 is "beginLett" check valu1 to see if it matches the first letter of the title
		if (field1 == "beginLett") {
			if ((valu1 == title.charAt(0)) || (valu1 == 'All')) {
				grabit = true;
			}
		}
		
		
		if (grabit) {
			ttl_arr[arr_cnt] = new Array (title, new Array ());
			ttl_arr[arr_cnt][3] = art;
	
			//get series info, if any
			if (series[0]) {
				ttl_arr[arr_cnt][7] = series[0].firstChild.nodeValue;
			}
	
			//get any notes
			if (notes[0]) {
				ttl_arr[arr_cnt][8] = notes[0].firstChild.nodeValue;
			}
	
			//get other info: Publisher names, URLs, Edition, Pubdate, Authors, free and new info
			//getPubInfo(x, i, ttl_arr);
			for (j=0; j<pubs.length; j++) {
				url = pubs[j].getElementsByTagName("URL");
				pubName = pubs[j].getElementsByTagName("name");
				free = pubs[j].getElementsByTagName("Free");
				pubEd = pubs[j].getElementsByTagName("edition");
				pubDate = pubs[j].getElementsByTagName("pubdate");
		
				//URL & NAME -- array
				ttl_arr[arr_cnt][1][j] = new Array (url[0].firstChild.nodeValue, pubName[0].firstChild.nodeValue);
				ttl_arr[arr_cnt][2] = pubs.length;
				
				//EDITION
				if (pubEd[0])
					ttl_arr[arr_cnt][1][j][2] = pubEd[0].firstChild.nodeValue;
				
				//PUBDATE
				if (pubDate[0])
					ttl_arr[arr_cnt][1][j][3] = pubDate[0].firstChild.nodeValue;
				
				//FREE?
				if (free.length >= 1) 
					ttl_arr[arr_cnt][4] = true;
			}
			
			//NEW?
			if (adDate.length >= 1) 
				ttl_arr[arr_cnt][5] = check_date(adDate);


			//getAuthInfo(x, i, ttl_arr);
			ttl_arr[arr_cnt][6] = new Array;
			for (j=0; j<auths.length; j++) {
				//get LAST NAME only
				ttl_arr[arr_cnt][6][j] = auths[j].firstChild.nodeValue.split(",",1);
			}

			//increase the array count by 1
			arr_cnt++;
		}
	}
	
	
	if (ttl_arr.length > 0) {
		//sort the array of results
		ttl_arr.sort();
		//display the results
		displayEBs (field1, valu1, ttl_arr, 2);
	}
	
	//display result table
	document.getElementById('displayResults').innerHTML = result_text;
}	//**Prepare_EBs**//



//*****************************************************************************************************
// prepare_EJs()
// -------------
// parms: field1--indicates what type of value valu1 is (beginLett, subject)
//        valu1--the letter or subject used to locate the appropriate XML file
//
// generate a link to an SFX results page with the passed subject (valu1) and provide a quick search
// box for searching SFX by title.
//
//*****************************************************************************************************
function prepare_EJs(field1, valu1, pass) {
		var ctgry = 0;
		var subctgry = 0;
		var pattern = null;
		
	switch (valu1) {
		case 'Dentistry':	 	{ctgry = 1; subctgry = 150; break};
		case 'Evidence':		{pattern = 'evidence based'; break};
		case 'Nursing':		 	{ctgry = 1; subctgry = 136; break};
		case 'Patient':			{pattern = 'consumer health'; break};

		//for those subject headings that don't match an entry in SFX, do nothing, but do include the search box
		default: 				{ctgry = 0; subctgry = 0};
	}
	
	//create a new table for the 
	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(' + "'EJList'" + ');"><img src="http://bcd.tamhsc.edu/library/img/web/misc/green-hide.gif" id="EJListImg" 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>EJournals</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="EJList"><table cellpadding="0" cellspacing="0" width="100%">';
		
	//if there is a matching SFX category
	if (ctgry != 0) {
		result_text += '<tr><td class="TableRow">'
		//INFO icon
		result_text += '<img align="texttop" src="http://bcd.tamhsc.edu/library/img/web/buttons_bars/info.gif" alt="List of Ejournals by Subject" title="List of Ejournals by Subject"/> ';

		//add the link to EJs by subject
		result_text += '<a class="Results" href="http://linkresolver.tamu.edu:9003/bhsl/azlist/default?current_view=table&perform=searchCategories&type=browseSubCategory&letter_group=&service=&category=' + ctgry + '&subcategory=' + subctgry + '" target="_blank" alt="opens in another window" title="opens in another window">See a list of our Ejournals about ' + getWEBSubjHead(valu1) + '</a><font color="red"><sup>*</sup></font></td></tr>';
	}
	//there's no category set what about a title search?
	else if (pattern != null) {
		result_text += '<tr><td class="TableRow">'
		//INFO icon
		result_text += '<img align="texttop" src="http://bcd.tamhsc.edu/library/img/web/buttons_bars/info.gif" alt="List of Ejournals by Subject" title="List of Ejournals by Subject"/> ';

		result_text += '<a class="Results" href="http://linkresolver.tamu.edu:9003/bhsl/azlist/default?current_view=table&perform=locate&current_view=table&letter_group=&service=&pattern=' + pattern + '&textSearchType=contains&category=&subcategory=" target="_blank" alt="opens in another window" title="opens in another window">See a list of our Ejournals about ' + getWEBSubjHead(valu1) + '</a><font color="red"><sup>*</sup></font></td></tr>';
	}

	//Disclaimer
	result_text += '<tr><td style="border-bottom:solid 1px #000000; font-size:10.0pt; padding-left:6px"><font color="red"><sup>*</sup></font> Please do not consider this a complete list of our EJournal holdings for this subject. Some titles that we <b>DO</b> have may not show up in this list. If there is a specific journal title you are looking for, please use the Title Quick Search box below.</td></tr>';

	result_text += '<tr><td>&nbsp;</td></tr>';
	
	//include an SFX Quick Search box
	result_text += '<tr><td colspan="5"><style type="text/css">.sfxTable{border-right: solid 1px #CCCCCC;border-bottom: solid 1px #CCCCCC;border-left: solid 1px #CCCCCC;border-top: solid 1px #CCCCCC;text-align: left;font-size: 12pt;background-color: #F9F9F1;width: 240px}</style><form name="az_user_form" method="get" action="http://linkresolver.tamu.edu:9003/bhsl/azlist/default" target="_blank"><input type="hidden" name="perform" id="locate_perform" value="locate"><input type="hidden" name="current_view" id="locate_current_view" value="table"><table class=sfxTable  id=resultTable><tr><td colspan=2><label for="pattern_" style="font-weight: bold">Journals Quick Search by Title</label></td></tr><tr><td style="width: 100%"><input type="text" name="pattern" id="pattern_" value="" style="width: 100%;" /></td><td><input type="submit" value="Go"></td></tr><tr><td colspan=2><input type="radio" name="textSearchType" id="startsWith" value="startsWith" ><label for="startsWith">Starts with</label><input type="radio" name="textSearchType" checked="checked" id="contains" value="contains" ><label for="contains">Contains</label><input type="radio" name="textSearchType" id="exactMatch" value="exactMatch" ><label for="exactMatch">Exact</label></td></tr></table></form></td></tr>';
	
	//close out the table tags
	result_text += '</table>';
	
	
}
