// ---------------------------------------------------------------------------------------
//
// search.js
//
// Website Search Tool written by Greg Beacher
//
// ---------------------------------------------------------------------------------------

// Array Size Constants
var NUM_SECTIONS		= 20 ;
var NUM_KEYWORDS		= 30 ;
var NUM_PAGES			= 100 ;
			
// Array Element Constants
var ELEM_SECTION		= 0 ;
var ESN				= 0 ;
var ESC				= 1 ;
var PT				= 0 ;
var PD				= 1 ;
var URL				= 2 ;
var KWD				= 3 ; 
			
// Main Site Map Array
var siteMap			= new Array ( NUM_SECTIONS ) ;
			
var sectionCount		= 0 ;
var pageCount			= 0 ;
			
// Build nested array structure
for ( sectionCount = 0; sectionCount < NUM_SECTIONS; sectionCount++ )
{
		
	siteMap [ sectionCount ] = new Array ( 2 ) ;
	siteMap [ sectionCount ][ ESC ] = new Array ( NUM_PAGES ) ;
				
	for ( pageCount = 0; pageCount < NUM_PAGES; pageCount++ )
	{
				
		siteMap [ sectionCount ][ ESC ][ pageCount ] = new Array ( 4 ) ;
		siteMap [ sectionCount ][ ESC ][ pageCount ][ KWD ] = new Array ( NUM_KEYWORDS ) ;
					
	}	
				
}

// ---------------------------------------------------------------------------------------
// submitSearchRequest
// ---------------------------------------------------------------------------------------
function submitSearchRequest ( objSearchBox )
{

  // Declare Local Variables
  var keyword			= objSearchBox.value ;
	
  // if the keyword is empty then just return otherwise navigate to the search screen
  if ( keyword.length == 0 )
  {
	return
  }
  else
  {
	parent.main.document.location.href = "../misc/search.htm?keyword=" + keyword ;
  }

} // End submitSearchRequest

// -----------------------------------------------------------------------------------------------------------------------
// listPagesBySection
// -----------------------------------------------------------------------------------------------------------------------			
function listPagesBySection ( )
{
			
	var sectionCount	= 0 ;
	var pageCount		= 0 ;
	var navigationBar	= '' ;
	var tabCode		= '' ;
	var paramList 		= '';
				
	// Iterate through the sections listing the contents as we go
	for ( sectionCount = 0; sectionCount < NUM_SECTIONS; sectionCount++ )
	{
				
		if ( siteMap [ sectionCount ][ ESN ] != null )
		{
			
			document.write ("<table width='560' cellpadding='0' cellspacing='0' border='0'>");
			document.write ("<tr height='15'>");
			document.write ("<td class='boldtext'>");
			document.write ( siteMap [ sectionCount ][ ESN ] ) ;
			document.write ("</td>");
			document.write ("</tr>");
			document.write ("</table>");
						
			// Display the pages within this section
			document.write ("<table width='560' cellpadding='0' cellspacing='0' border='0'>");

			for ( pageCount = 0; pageCount < NUM_PAGES; pageCount++ )
			{
						
				if ( siteMap [ sectionCount ][ ESC ][ pageCount ][ PT ] != null )
				{

					navigationBar = obtainNavigationPath ( sectionCount ) ;
					tabCode = obtainTabCode ( sectionCount ) ;
					paramList = "javascript:navigateThroughParent('" + navigationBar + "','" + siteMap [ sectionCount ][ ESC ][ pageCount ][ URL ] + "','" + tabCode + "')" ;
					
					document.write ("<tr height='25'>");
					document.write ( "<td width='250'>");		
					document.write ( "<A HREF=" + paramList + ">" ) ;
					document.write ( siteMap [ sectionCount ][ ESC ] [ pageCount ][ PT ] ) ;
					document.write ( "</A>" ) ;
					document.write ( "</td>");
					document.write ( "<td width='310'>");		
					document.write ( siteMap [ sectionCount ][ ESC ][ pageCount ][ PD ] ) ;
					document.write ( "</td>");
					document.write ("</tr>");					
					
				}	// end if
						
			} // end for
			
			document.write ("</table>");
			document.write ("<br>");
						
		} // end if
					
	} // end for
				
} // end listPagesBySection

// -----------------------------------------------------------------------------------------------------------------------
// performSearch
// -----------------------------------------------------------------------------------------------------------------------			
function performSearch ( keyword )
{

	var sectionCount	= 0 ;
	var pageCount		= 0 ;
	var keywordCount	= 0 ;
	var searchSuccess	= false ;
	var navigationBar	= '' ;
	var tabCode		= '' ;
	var paramList 		= '';
				
	// Escape out if the supplied keyword parameter is empty
	if ( keyword.length > 0 )
	{

		// Convert the incoming keyword to lowercase
		keyword = keyword.toLowerCase() ;
		
		// Iterate through the sections
		for ( sectionCount = 0; sectionCount < NUM_SECTIONS; sectionCount++ )
		{
					
			if ( siteMap [ sectionCount ][ ESN ] != null )
			{

				// iterate through the pages within this section
				for ( pageCount = 0; pageCount < NUM_PAGES; pageCount++)
				{
								
					// iterate through the keywords within this page
					for ( keywordCount = 0; keywordCount < NUM_KEYWORDS; keywordCount++ )
					{
								
						if ( siteMap [ sectionCount ][ ESC ][ pageCount ][ KWD ][ keywordCount ]  != null )
						{
							
							if ( siteMap [ sectionCount ][ ESC ][ pageCount ][ KWD ][ keywordCount ].toLowerCase() == keyword )
							{

							navigationBar = obtainNavigationPath ( sectionCount ) ;
							tabCode = obtainTabCode ( sectionCount ) ;
							paramList = "javascript:navigateThroughParent('" + navigationBar + "','" + siteMap [ sectionCount ][ ESC ][ pageCount ][ URL ] + "','" + tabCode + "')" ;

				  			// Display Section Name
				  			document.write ("<table width='560' cellpadding='0' cellspacing='0' border='0'>");
							document.write ("<tr>");
							document.write ("<td class='boldtext'>");
							document.write ( siteMap [ sectionCount ][ ESN ] ) ;
							document.write ("</td>");
							document.write ("</tr>");
							document.write ("</table>");
						
							// Display the pages within this section
							document.write ("<table width='560' cellpadding='0' cellspacing='0' border='0'>");						
							document.write ("<tr>");
							document.write ( "<td width='250'>");		
							document.write ( "<A HREF=" + paramList + ">" ) ;
							document.write ( siteMap [ sectionCount ][ ESC ] [ pageCount ][ PT ] ) ;
							document.write ( "</A>" ) ;
							document.write ( "</td>");
							document.write ( "<td width='310'>");		
							document.write ( siteMap [ sectionCount ][ ESC ][ pageCount ][ PD ] ) ;
							document.write ( "</td>");
							document.write ("</tr>");					
							document.write ("</table>");
							document.write ("<br>");

							searchSuccess = true ;
									
						} // end if
								
					} // end if
								
				} // end for
								
			} // end for
				
		} // end if
						
	} // end for
					
} // end if
				
// Display a message if nothing was found
	if ( searchSuccess == false )
	{
				
		document.write ( "Nothing Found For Keyword: " + keyword ) ;
				
	}
							
} // end performSearch

// -----------------------------------------------------------------------------------------------------------------------
// obtainNavigationPath
// -----------------------------------------------------------------------------------------------------------------------			
function obtainNavigationPath ( sectionID )
{

	var navPath = '' ;

	switch ( sectionID ) 
	{
		case 0: // Solution By Area
		{
			navPath = "../navbars/sba_sidenav.htm" ;
			break ;
		}
		case 1: // Solution By Industry
		{
			navPath = "../navbars/sbi_sidenav.htm" ;
			break ;
		}
		case 2: // Services
		{
			navPath = "../navbars/ser_sidenav.htm" ;
			break ;
		}
		case 3: // Customers
		{
			navPath = "../navbars/cus_sidenav.htm" ;
			break ;
		}
		case 4: // Company
		{
			navPath = "../navbars/com_sidenav.htm" ;
			break ;
		}
		case 5: // Contact
		{
			navPath = "../navbars/con_sidenav.htm" ;
			break ;
		}
		case 6: // Misc
		{
			navPath = "../navbars/defaultsidenav.htm" ;
			break ;
		}	} // end switch

	return navPath ;
}

// -----------------------------------------------------------------------------------------------------------------------
// obtainTabCode
// -----------------------------------------------------------------------------------------------------------------------			
function obtainTabCode ( sectionID )
{

	var tabCode = '' ;

	switch ( sectionID ) 
	{
		case 0: // Solution By Area
		{
			tabCode = "sba" ;
			break ;
		}
		case 1: // Solution By Industry
		{
			tabCode = "sbi" ;
			break ;
		}
		case 2: // Services
		{
			tabCode = "ser" ;
			break ;
		}
		case 3: // Customers
		{
			tabCode = "cus" ;
			break ;
		}
		case 4: // Company
		{
			tabCode = "com" ;
			break ;
		}
		case 5: // Contact
		{
			tabCode = "con" ;
			break ;
		}
		case 6: // Misc
		{
			tabCode = "def" ;
			break ;
		}	} // end switch

	return tabCode ;
}