<!--
    // This function is called by default.aspx's Body onload event to set focus to the textbox
    function setFocus()
    {
        // Focus on the main input box
        if (document.getElementById("searchText") != null)
            document.getElementById("searchText").focus();
        else if (document.getElementById("quickSearch") != null)
            document.getElementById("quickSearch").focus();
    }

	// ----- Quick search -----
	// Functions related to the quick search edit box and button
	// these functions make sure that proper search criteria is passed
	// to the server when client enter a search string.
	//
	// Also provide support for triggering the search using enter button
	// while in edit mode.
	function onQuickKeyDown(e)
	{
		var keyEvent = e ? e : event;
		
		if (keyEvent != null)
		{
		    if((keyEvent.which && keyEvent.which == 13) || 
			    (keyEvent.keyCode && keyEvent.keyCode == 13))
            {
			    goQuickSearch();
			
			    return false;
			}
		} 
		
		return true;
	}

	// This function is responsible for generation of proper search
	// criteria string, so the server can provide best results.
	function goQuickSearch()
	{
		var searchStr = GetValidatedSearchStr(document.getElementById("quickSearch").value);
		
		if ( searchStr != null && searchStr != "" )
		{
			window.location = "./Default.aspx?" + searchStr;
		}
		else
		{
		    window.alert("Please enter what you would like to search for using words and numbers, separated by spaces.");
		}
	}
	
	// ----- Advanced search -----
	// Functions related to advanced search.
	// The onAdvKeyDown will be called for each key entered by the client
	// allowing triggering of the search by simply pressing the enter key
	function onAdvKeyDown(e)
	{
		var keyEvent = e ? e : event;
		
		if (keyEvent != null)
		{
		    if((keyEvent.which && keyEvent.which == 13) || 
			    (keyEvent.keyCode && keyEvent.keyCode == 13))
            {
			    onSearch();
			
			    return false;
			}
		} 
		
		return true;
	}
	
	// The onSearch function is responsible to generate proper search
	// query string which will be processed by the "GroupMain.asp" page
	// The search query string will inclue:
	//	- Search - string containing all search words.  Spaces in the string
	//				will be relaced with "+" characters.
	//	- Product - ID representing which product user wants to concentrate on.
	//				All products will be searched if the ID is missing or zero.
	//	- Using - indicating which search type user wants
	//				o Exact Phrase	(E)
	//				o All Words		(A) - default
	//				o Any Word		(W)
	//	- Platform - indicating the platform to search
	//
	function onSearch()
	{
		if ( document.getElementById("searchText").value.length == 0 )
		{
			window.alert( "Please enter what you would like to search for." );
			return;
		}
	
		var resultStr;
		resultStr = "";
		
		resultStr += GetValidatedSearchStr(document.getElementById("searchText").value);
		resultStr += GetProductID();
		resultStr += GetUsingStr();
		resultStr += GetTechnologyID();
		
		if(resultStr != "")
		{
		    window.location = "./Default.aspx?" + resultStr;
		}
		else
		{
		    window.alert("Please enter what you would like to search for using words and numbers, separated by spaces.");
		}
	}
	
	// Removes all non-digits and non-letters except for %, and replaces spaces
	// with + sign. Returns empty if not valid
	function GetValidatedSearchStr(searchStr)
	{		
	    if ( searchStr != null && searchStr != "" )
	    {        
	        // remove common words
	        searchStr = searchStr.replace( /\bthe\b|\band\b|\bwhen\b|\bwhere\b|\bhow\b|\bby\b|\ba\b|\ban\b|\bi\b|\bto\b|\bmy\b|\binto\b|\bwith\b|\bthat\b|\bfor\b|\bits\b|\bwhich\b|\bthis\b/g, "" );
	        
	        // replace all non-alphanumeric and non-wildcard characters with a plus sign
	        searchStr = searchStr.replace( /[^\w%]+/g, "+" );
    		
	        // remove any plus signs from beginning and end
	        searchStr = searchStr.replace( /^\+|\+$/g, "" );
	        	        
	        if ( searchStr != "" )
	        {
	         	searchStr = "Search=" + searchStr;
	        }
	    }
	    
	    else
	    {
	        searchStr = "";
	    }
		
		return searchStr;
	}

	// Return information on the selected product
	function GetProductID()
	{
		var prodID = document.getElementById("PageContent1_AdvancedSearch1_prodList").value;
		
		if ( prodID != -1 )
		{
			// return product ID of selected product
			return "&searchProduct=" + prodID;
		}
		
		return "";
	}
	
	// the "using" selection identifies which search method to use
	//	o Exact Phrase
	//	o All Words
	//	o Any Word
	function GetUsingStr()
	{
		var returnStr = "";
		var selectedIndex = document.getElementById("usingSelect").selectedIndex;
		
		switch( selectedIndex )
		{
			case 0:
				returnStr = "&Using=E";
				break;
			case 2:
				returnStr = "&Using=W";
				break;
		}
		return returnStr;
	}
	
	// Return information on the selected technology
	function GetTechnologyID()
	{		
		var platID = document.getElementById("PageContent1_AdvancedSearch1_technologyList").value;
		
		if ( platID != -1 )
		{
			// return product ID of selected product
			return "&searchPlatform=" + platID;
		}
		
		return "";
	}

-->
