// JavaScript Document
//array for displaying number of ../nuggets found during search... 
var numConversion = new Array();

//array for storing links to ../nuggets, nugget title, keyintropcss...
var item = new Array();

//populating the array...
for (var i=0; i<150; i++){
	numConversion[i] = i;
}

// "Page Name","path","Page Title","Many,Key,Words","Descriptive Comments"
//c++; item[c]=new Array("javascript:openNugget('../nuggets/windows/Chapter8//_nugget.html',670,530);","","","","");

c=0; item[c]=new Array("#","","Selecting worksheets","Selecting worksheets","");
c++; item[c]=new Array("#","","Selecting columns","Selecting columns","");
c++; item[c]=new Array("#","","Selecting Ranges of Cells","Selecting Ranges of Cells","");
c++; item[c]=new Array("#","","Selecting Rows","Selecting Rows","");

c++; item[c]=new Array("#","","Entering Text","Entering Text","");
c++; item[c]=new Array("#","","Entering Numbers","Entering Numbers","");
c++; item[c]=new Array("#","","Entering Functions","Entering Functions","");
c++; item[c]=new Array("#","","Entering Formulas","Entering Formulas","");

c++; item[c]=new Array("#","","Printing portrait and landscape worksheets","Printing portrait and landscape worksheets","");
c++; item[c]=new Array("#","","Margins","Margins","");
c++; item[c]=new Array("#","","Printing worksheets","Printing worksheets","");
c++; item[c]=new Array("#","","Printing ranges","Printing ranges","");

c++; item[c]=new Array("#","","Replacing cell contents","Replacing cell contents","");
c++; item[c]=new Array("#","","Editing cell contents","Editing cell contents","");
c++; item[c]=new Array("#","","Undoing the last command","Undoing the last command","");
c++; item[c]=new Array("#","","Inserting rows","Inserting rows","");
c++; item[c]=new Array("#","","Inserting columns","Inserting columns","");
c++; item[c]=new Array("#","","Deleting rows","Deleting rows","");
c++; item[c]=new Array("#","","Deleting columns","Deleting columns","");
c++; item[c]=new Array("#","","Deleting cells","Deleting cells","");
c++; item[c]=new Array("#","","Deleting worksheets","Deleting worksheets","");
c++; item[c]=new Array("#","","Changing column width","Changing column width","");
c++; item[c]=new Array("#","","Automatic column width","Automatic column width","");
c++; item[c]=new Array("#","","Changing row height","Changing row height","");
c++; item[c]=new Array("#","","Automatic row height","Automatic row height","");
c++; item[c]=new Array("#","","Freezing column and row titles","Freezing column and row titles","");
c++; item[c]=new Array("#","","Unfreezing column and row titles","Unfreezing column and row titles","");

c++; item[c]=new Array("#","","Aligning ranges horizontally","Aligning ranges horizontally","");
c++; item[c]=new Array("#","","Aligning ranges vertically","Aligning ranges vertically","");
c++; item[c]=new Array("#","","Changing cell entry orientation","Changing cell entry orientation","");
c++; item[c]=new Array("#","","Centering across columns","Centering across columns","");
c++; item[c]=new Array("#","","Changing font sizes","Changing font sizes","");
c++; item[c]=new Array("#","","Changing boldface and italics","Changing boldface and italics","");
c++; item[c]=new Array("#","","Changing cell borders","Changing cell borders","");

/*******************************************************************************
	Function Name:	search();
	Arguments:			frm - form object containing the search keywords entered by the user.
	Description:			This function is used to search for nuggets using the search value entered by
								the user in the Search field. It matches the search string with the nugget title
								and its corresponding keywords and displays the link for the nugget if a match 
								is found. This function is called when the Search button is clicked.
********************************************************************************/

page =  ' 	<html> 																															'
page +=	'  		<head> 																														'
page += '			<link rel="stylesheet" type="text/css" href="css/ie-stylesheet.css"> 						'
page +=	' 			<script language="JavaScript1.2" src="scripts/nugget.js"></script> 							'
page +=	' 			<script language="JavaScript1.2" src="scripts/functions.js"></script> 							'
page +=	' 			<title>Search Results: Excel XP eLearning Nuggets</title> 										'	
page +=	' 		</head>																														'
page +=	' 		<body onUnload="setFocus();"> 																														'
page +=	'			<img class="srchLogo" src="images/search_logo.gif">													'
page +=	' 			<div id="srchMain"> 																								';

function search(frm) {
	
	//search string to display in the search window...
  	srchTxt = frm.srchVal.value;

	//search string to be used for matching with nugget title and keywords...	
  	txt = frm.srchVal.value.toLowerCase();

	//splitting search sentences using space as a delimiter and storing it as an array...
  	txt = txt.split(" ");
  	fnd = new Array(); 
	total=0;

	//searching for a match...
	for (i = 0; i < item.length; i++) {
     	fnd[i] = 0; 
   		for (k = 0; k < txt.length; k++)
   	  		if (item[i][3].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "")
       			fnd[i] += (1);
     }

	//creating a window in which the search results will be displayed...
  	win = window.open("","","scrollbars, width=625, height=300");
	
	//writing/rendering the heading section of the search window...	
  	win.document.write(page);

	//finding and formatting links for display in the search window...
     for (i = 0; i < fnd.length; i++) {
     	n = 0; 
		w = -1;
        
		for (j = 0;j < fnd.length; j++)
         	if (fnd[j] > n) { n = fnd[j]; w = j; };
            	if (w > -1) 
			   		total += show(w, win);
               	fnd[w] = 0;
     }

	//rendering the rest of the page...	
	win.document.write('<br></div>');
		
	//displaying the heading in the search window... 
	win.document.write('<span class="srchWndHeading1">Search text: '+srchTxt+'</span><br>');
	win.document.write('<span class="srchWndHeading2">Total number of eLearning Nuggets found: '+numConversion[total]+'</span>');
	win.document.write('</body></html>');
	win.document.close();
}

/*****************************************************************************************************
	Function Name:	show();
	Arguments:			which 	- the element in the item array containing all the links.
								wind 	- the window in which to display the links.
	Description:			This function is used to format and display all the matching links in the
								search window.
******************************************************************************************************/

function show(which,wind) {

	link = item[which][1] + item[which][0];
   	if (link.indexOf("#") > -1)
		line = '<span class="disabled">'+item[which][2]+'</span><br>';
   	else
		line = '<a class="enabled" onFocus="loseFocus(this);" href="'+link+'">'+item[which][2]+'</a><br>';

   wind.document.write(line);
   return 1;
}	//Function show()
