///////////////////////////////////////////////////////////////////////////////
//	Symantec Corporation
//	Enterprise Product Selection Dropdown menu
// 
//	Description:
//		This script determines and shows selections depending on what is entered
//	by the visitor
//
//	Author: 		Kevin De Angelis (KJD) <Kevin_DeAngelis [at] Symantec.com>
// 	Born on Date: 	2006.08.01
//
//	Revisions:
//		2006.08.01 KJD: Initial script created
//		2006.09.06 KJD: Added dynamic width
//		2006.10.10 KJD: Updated to also include URL for the link
//		2006.10.27 KJD: Check for Text in field
//		2006.12.19 KJD: Enter key pressed when moused over will populate
//		2007.09.24 KJD: Changed to replace superscript 3
//						Start checking upon 2 characters entered
//		2007.09.26-8 TLW: Debugged including superscript 3
//					Added support for re-search on every character after 2
//					Added support for matching 'anti' and 'virus' to
//						SOA/Web Service related products
///////////////////////////////////////////////////////////////////////////////

var TextCleared 	= 0;
//var EntryText 		= " Enter product name";

var CurrentItem 	= 0;
var ShowingItems	= 0;
var PageItems 		= new Array();

// 2007.09.24 KJD: Not Used, set it in the results box instead
var offsetAmount 	= "390px";
var offsetLeftAmount= 122;



var inputFormName	= "document.myForm";

var widthMultiplier = 6.1;				// adjust for width ( char.length * this = width )

// 2006.08.31 KJD: Things we want to omit in the search
// var OmitEnteredValues		= new Array( "symantec", "norton" );

// 2006.10.24 KJD: Do not omit anything in the search
var OmitEnteredValues		= new Array( );

var showSeparator	= 0;

var maxWidth 		= 0;

// 2006.10.24 KJD: itemURL is clearing, make it global
var viewItemURL 	= "";
//2007.11.21 AKD: make global
var allProductsURL;
if(PageElements['country']!='us'){
	allProductsURL = "/"+PageElements['language'] + "/" + PageElements['country']+"/business/products/allproducts.jsp";
}else{allProductsURL="/business/products/allproducts.jsp";}

///////////////////////////////////////////////////////////////////////////////
// FindProduct 	- Find Entered products from an array
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	string
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
document.body.onclick=ProductHide;


function FindProduct( myString, thisKey )
{
	if( ( thisKey != 38 ) && ( thisKey != 40 ) && ( thisKey != 13 ) )
	{
		var startlength	= 1;
		var TermsFound	= new Array();
	
		var thisTerm 	= "";

		// 2006.08.02 KJD: Check for "symantec" in string
		myString = myString.toUpperCase();
		// myString = myString.replace( "SYMANTEC ", "" );
		
		
		// 2006.08.31 KJD: Remove the omitted values
		for( i = 0; i < OmitEnteredValues.length; i++ )
		{
			thisTerm = OmitEnteredValues[i].toUpperCase() + " ";
			myString = myString.replace( thisTerm, "" );
		}


		if( myString.length > startlength )
		{
			TermsFound = GetProductMatch( myString );

			// 2006.08.01 KJD: Terms found, so show them
			if( TermsFound )
			{
				// 2006.09.06 KJD: Reset the max width
				maxWidth = 0;
			
				// 2007.10.01 TLW: Separating special terms matches from standard matches
				if( ( TermsFound['BeginsWith'] ) || ( TermsFound['Contains'] ) ||
					( TermsFound['SpecialTermsBeginsWith'] ) ||
						( TermsFound['SpecialTermsContains'] ) )
				// 2007.09.28 TLW: TermsFound['BeginsWith'].length and TermsFound['Contains'].length
				//                 take an exception of length is zero as "no properties".
				//if( ( TermsFound['BeginsWith'].length ) || ( TermsFound['Contains'].length ) )
				{
					// 2007.10.01 TLW: causes artifacts if empty string
					//                 *** TODO: HACK BELOW PREVENTS ARTIFACTS
					var tempTestForEmptyString = ProductFormat( TermsFound );
					
					if( tempTestForEmptyString == "" ) {
						ProductHide();
					}
					else
					{
						ProductShow( tempTestForEmptyString );
					}
					
					//ProductShow( ProductFormat( TermsFound ) );
				}
				else
				{
					//ProductHide();
					
					// 2007.09.28 TLW: cannot show products if ther are not any
					// ProductShow( ProductFormat( TermsFound ) );
					ProductHide();
				}

				document.getElementById( 'myResults' ).style.width = maxWidth + 5;
			
				
				// 2007.10.01 TLW: Remove this dead code.
				// 2006.09.06 KJD: Adjust separator width
				/********************
				if( showSeparator )
				{
					// ProductSeparator.style.width = myResults.style.width;
					// alert( 'width=' + document.getElementById( 'myResults' ).style );
					// document.getElementById( 'ProductSeparator' ).style.width = "100%";
					//document.getElementById( 'ProductSeparator_inner' ).style.width = maxWidth;
					//document.getElementById( 'ProductSeparator_outer' ).style.width = maxWidth;
				}
				*********************/
			}
		}
		else
		{
					
			// 2007.09.28 TLW: cannot show products if ther are not any
			ProductHide();
			// ProductHide();
		}
	}
	
	// 2006.10.10 KJD: Clear the stored URL
	document.myForm.productURL.value = "";
}
var matchSpecialTerms      = new Array();
///////////////////////////////////////////////////////////////////////////////
// GetProductMatch 	- Check for a match of the product in array
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	string
// Return: 		array
///////////////////////////////////////////////////////////////////////////////
function GetProductMatch( myString )
{
	var BeginsWith	= new Array();
	var Contains	= new Array();
	var AllMatches	= new Array();

	var thisString	= myString.toUpperCase();
	var matchString	= "";
		
	var thisProductName = "";
	
	// 2007.09.28 TLW: this is the starter. We want to re-match every character typed now.
	var minMatchLength = myString.length; // match terms by length of input
	// var minMatchLength = 2; / / match terms at length 2
	//2007.11.27 AKD: Adding this to remove the hardcoded text 
	// This fuction is in product_select.tag
	initializeSpecialTerms(myString);
	
	// 2007.09.26 TLW: This block of code to check for match related to Special Terms (which themselves will NOT match)
//	var matchSpecialTerms      = new Array();
	var SpecialTermsBeginsWith = new Array();
	var SpecialTermsContains   = new Array();
	var j = matchSpecialTerms .length-1; // index used on matchSpecialTerms[]
	//var j = 0; // index used on matchSpecialTerms[]
	var k; // index used to index into matchSpecialTerms[]['specialmatches']
	var l; // index used to index into matchSpecialTerms[]['specialmatches']
	var matchLength = 0;

	//The code form here is put in tag

	var matchingIndex; // matching index to check against begin of word
	
	for(i = 0 ; i <= j ; i++) {
		matchString = matchSpecialTerms[i]['termabbrev'];
		if( ( matchingIndex = matchString.indexOf( thisString ) ) > -1 )
		{
			if( matchingIndex == 0 ) // string begins with
			{
				for(k = 0, l = (matchSpecialTerms[j]['specialmatches']).length ; k < l ; k++) {
					SpecialTermsBeginsWith[ SpecialTermsBeginsWith.length ] =
						matchSpecialTerms[j]['specialmatches'][k];
				}
			}
			else // match but string does not begin with
			{
				for(k = 0, l = (matchSpecialTerms[j]['specialmatches']).length ; k < l ; k++) {
					SpecialTermsContains[ SpecialTermsBeginsWith.length ] =
						matchSpecialTerms[j]['specialmatches'][k];
				}
			} // end else
			
		} // end if
	} // end for(i = 0 ; i < j ; i++)

	
	
	// 2007.09.27 TLW: Let's check the list	
	for( i = 0; i < ProductArray.length ; i++ )
	// 2006.08.01 KJD: Let's check the list
	// for( i = 0; i < 5; i++ )
	{
		thisProductName = ProductArray[i]['name'];
		
		// 2006.08.01 KJD: Check if it contains the string
		// matchString = ProductArray[i]['name'].toUpperCase();

		// 2007.09.28 TLW: Corrected and re-enabled check for superscript 3 in product name;
		//                 changed order of conversion to upper case.
		// 2007.09.24 KJD: Check for superscript 3 in product name
		// matchString = thisProductName;
		matchString = thisProductName.toUpperCase();
		matchString = matchString.replace( "IÂ³", "I3" );
		//matchString = thisProductName.replace( /i\³/ig, "i3" );
		//matchString = matchString.toUpperCase();
		
		
		if( matchString.indexOf( thisString ) > -1 )
		{
			//alert( 'yes(' + thisString + '):' + matchString.indexOf( thisString ) + ProductArray[i]['name'] );
			Contains[ Contains.length ] = ProductArray[i]['name'] + ";" + ProductArray[i]['id'] + ";" + ProductArray[i]['url'];
		}
	}
	
	// 2007.10.01 TLW: Contains.length can cause problems
	// 2006.08.01 KJD: Check if it begins with the string
	if( Contains )
	//if( Contains.length )
	{
		// 2006.08.01 KJD: Check if it begins with the string
		for( i=0; i < Contains.length; i++ )
		{
			matchString = Contains[i].substr( 0, myString.length ).toUpperCase();
			
			if( matchString == thisString )
			{
				if( BeginsWith ) {
					BeginsWith[ BeginsWith.length ] = Contains[i];
				} else {
					BeginsWith[ 0 ] = Contains[i];
				}
				Contains[i] = "";
			}
		}
	}
	
	// 2006.08.01 KJD: Remove Blank Array Values
	
	var tempContains = new Array();

	// 2007.10.01 TLW: Contains.length can cause problems
	if( Contains )
	//if( Contains.length )
	{
		for( i=0, j=0; i < Contains.length; i++ )
		{
			if( tempContains ) {
				if( Contains[i] ) {
					tempContains[ j++ ] = Contains[i];
				}
			}
		}
	}
	
	Contains = tempContains;


	// 2007.10.01 TLW: Preping three-dimensional array to pass up.
	// 2007.10.01 TLW: Changed to not access array length until verified valid array

	// on special terms, we are not sorting
	if( SpecialTermsBeginsWith ) {
	// if( SpecialTermsBeginsWith.length > 0 ) {
		AllMatches['SpecialTermsBeginsWith'] =  SpecialTermsBeginsWith;
	}
	if( SpecialTermsContains ) {
	// if( SpecialTermsContains.length > 0 ) {
		AllMatches['SpecialTermsContains'] =  SpecialTermsContains;		
	}
	
	// sort before displaying
	if( BeginsWith ) {
	// if( BeginsWith.length ) {
		AllMatches['BeginsWith'] = BeginsWith.sort();
	}
	if( Contains ) {
	// if( Contains.length ) {
		AllMatches['Contains'] = Contains.sort();
	}

	return AllMatches;
}

///////////////////////////////////////////////////////////////////////////////
// ProductFormat	- Format the Results
// Author: 		Kevin De Angelis
// Re-written by	Tish Wood
// Date: 		2006.08.01
// Receive: 	array
// Return: 		string
///////////////////////////////////////////////////////////////////////////////
function ProductFormat( myArray )
{
	var ToShow 		= "";
	var itemCount 	= 0;
	var beginsWithMatches             = false;
	var specialTermsBeginsWithMatches = false;
	
	
	PageItems	= new Array();
	
	
	if( myArray['BeginsWith'] )
	{
	
		for( i=0; i < myArray['BeginsWith'].length; i++ )
		{
			beginsWithMatches = true; // put inside for loop to keep from getting empty section

			var thisValue = new Array();
			thisValue = myArray['BeginsWith'][i].split( ";" );
			
			ToShow += ItemFormat( thisValue[0], thisValue[1], itemCount, thisValue[2] );
			PageItems[itemCount] = thisValue[0];
			itemCount++;
		}
	}

	if( myArray['SpecialTermsBeginsWith'] != '' )
	{
	
		if( ( myArray['Contains'].length > 0) && ( beginsWithMatches == true ) ) {
			ToShow += "<hr CLASS='ProductSelectHR'/>";
			specialTermsBeginsWithMatches = true; // put inside for loop to keep from getting empty section
		}

		for( i=0; i < myArray['SpecialTermsBeginsWith'].length; i++ )
		{
			var thisValue = new Array();
			thisValue = myArray['SpecialTermsBeginsWith'][i].split( ";" );
			
			ToShow += ItemFormat( thisValue[0], thisValue[1], itemCount, thisValue[2] );
			PageItems[itemCount] = thisValue[0];
			itemCount++;
		}
	}

	if( myArray['Contains'] )
	{
	
		if( ( myArray['Contains'].length > 0) &&
			( (beginsWithMatches == true) || (specialTermsBeginsWithMatches == true) ) ) {
			ToShow += "<hr CLASS='ProductSelectHR'/>";
		}
			
		for( i=0; i < myArray['Contains'].length; i++ )
		{			
			var thisValue = new Array();
			thisValue = myArray['Contains'][i].split( ";" );
			
			ToShow += ItemFormat( thisValue[0], thisValue[1], itemCount, thisValue[2] );
			PageItems[itemCount] = thisValue[0];
			itemCount++;
		}
	}
	
	
	// 2006.09.06 KJD: Show extra messages
	if( myArray['Contains'].length )
	{
		ToShow += "<hr CLASS='ProductSelectHR'/>";
		ToShow += ItemFormat( DontSeeText, "all_prods", itemCount, allProductsURL );
	}
	else
	{
		ToShow += ItemFormat( BrandText, "all_prods", itemCount, allProductsURL );
	}
	
	

	itemCount++;
	
	ShowingItems = itemCount;
	
	return ToShow;
}

///////////////////////////////////////////////////////////////////////////////
// ProductFormat	- Format the Results
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	array
// Return: 		string
///////////////////////////////////////////////////////////////////////////////
function ProductFormat_OBSOLETE( myArray )
{
	var ToShow 		= "";
	var itemCount 	= 0;
	
	PageItems	= new Array();
	
	// 2007.09.28 TLW: myArray['BeginsWith'].length causes exception if no elements
	if( myArray['BeginsWith'] )
	// 2006.08.01 KJD: Items begin with
	// if( myArray['BeginsWith'].length )
	{
		ToShow += "";
	
		for( i=0; i < myArray['BeginsWith'].length; i++ )
		{
			var thisValue = new Array();
			thisValue = myArray['BeginsWith'][i].split( ";" );
			
			ToShow += ItemFormat( thisValue[0], thisValue[1], itemCount, thisValue[2] );
			PageItems[itemCount] = thisValue[0];
			itemCount++;
		}
		

	}

	// 2007.09.28 TLW: myArray['BeginsWith'].length OR myArray['Contains'].length will cause exception if no elements
	if( ( myArray['BeginsWith'] ) && ( myArray['Contains'] ) )
	// 2006.08.01 KJD: A divider
	//if( ( myArray['BeginsWith'].length ) && ( myArray['Contains'].length ) )
	{
		ToShow += ItemFormat( DontSeeText, "all_prods", itemCount, allProductsURL);
		ToShow += "<hr CLASS='ProductSelectHR'/>";
		// 2006.08.31 KJD: Create a div instead of HR
		// ToShow += "<SPAN CLASS='ProductSeparatorOuter' ID='ProductSeparator_outer'>1<SPAN ID='ProductSeparator_inner' CLASS='ProductSeparatorInner'>2</SPAN></SPAN>";

		showSeparator = 1;
	}
	else
	{
		showSeparator = 0;
	}

	// 2007.09.28 TLW: myArray['Contains'].length will cause exception if no elements
	if( myArray['Contains'] )
	// 2006.08.01 KJD: Items that contain the term
	// if( myArray['Contains'].length )
	{
		/*
		if( myArray['BeginsWith'].length )
		{
			ToShow += "<b>Also Found in:</b><br/>";
		}
		*/
	
		for( i=0; i < myArray['Contains'].length; i++ )
		{
			var thisValue = new Array();
			thisValue = myArray['Contains'][i].split( ";" );
			
			ToShow += ItemFormat( thisValue[0], thisValue[1], itemCount, thisValue[2] );
			PageItems[itemCount] = thisValue[0];
			itemCount++;
		}
	}
	
	
	// 2007.09.28 TLW: myArray['Contains'].length will cause exception if no elements
	if( myArray['Contains'] )
	// 2006.09.06 KJD: Show extra messages
	// if( myArray['Contains'].length )
	{
		ToShow += ItemFormat( DontSeeText, "all_prods", itemCount, allProductsURL );
	}
	else
	{
		ToShow += ItemFormat( BrandText, "all_prods", itemCount, allProductsURL );
	}
	
	

	itemCount++;
	
	ShowingItems = itemCount;
	
	return ToShow;
}

///////////////////////////////////////////////////////////////////////////////
// ItemFormat 	- 
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	string
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function ItemFormat( itemname, prodid, itemid, itemurl )
{
	var itemstring 		= "";
	var mouseActionOver 	= "EnterItem( " + itemid + ", '" + itemurl + "' );";
	var mouseActionDown 	= "EnterItem( " + itemid + ", '" + itemurl + "' );";

	// 2006.09.06 KJD: Adjust the width to the length of the product name
	var thisWidth = itemname.length * widthMultiplier;
	
	if( thisWidth >= maxWidth ){ maxWidth = thisWidth + 5; }
		
	// 2006.09.06 KJD: Product not listed
	if( itemname ==  DontSeeText )
	{
		//itemstring = "<a href='/enterprise/support/all_prods' style='text-decoration:none;'>Don't see my product</a><br/>";
		mouseActionOver = "";
		mouseActionDown = "location.href=allProductsURL;";
	}
	
	// 2006.09.06 KJD: Enter product name
	if( itemstring == BrandText )
	{
		//itemstring = "<a href='/enterprise/support/index.jsp' style='text-decoration:none;'>Enter a product name, excluding Brand</a><br/>";
	}
	
	itemstring += "<div "
						+ "onMouseOver=\"" + mouseActionOver + "DeselectAll();this.className='ProductSelect';\" "
						+ "onMouseOut=\"this.className='ProductDeselect'\" "
						+ "onClick=\"" + mouseActionDown + "ProductHide();\" "
						+ "class='ProductDeselect' "
						+ "id='prodSelect_" + itemid 
						+ "' STYLE='width:" + maxWidth + "px;'>" 
						+ itemname 
						+ "</div>";

	return itemstring;
}

///////////////////////////////////////////////////////////////////////////////
// ProductShow 	- Show the Results
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	string
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function ProductShow( myString )
{
	
	document.getElementById( 'myResults' ).innerHTML 		= myString;
	document.getElementById( 'myResults' ).style.visibility 	= "visible";
	//document.getElementById( 'MainSection_Top' ).style.overflow="visible";
	//document.getElementById( 'MainSection_Top' ).style.zIndex="999";
	
	document.getElementById( 'myResults' ).style.position	= "absolute";
	
	/*
	myResults.style.left 		= eval( inputFormName ).offsetLeft + offsetLeftAmount;
	myResults.style.top 		= eval( inputFormName ).offsetTop + offsetAmount;
	*/

	// 2006.12.20 KJD: Only hard code left amount
	// 2006.11.06 KJD: Hard code amounts
	// document.getElementById( 'myResults' ).style.left 	= offsetLeftAmount;
	
	// 2007.09.21 KJD: Added to place location
	// document.getElementById( 'myResults' ).style.top = offsetAmount;
	
	//myResults.style.top 	= offsetAmount;
	
	// 2006.08.31 KJD: Do not select item by default
	CurrentItem = -1;
	// Highlight( CurrentItem );
}

///////////////////////////////////////////////////////////////////////////////
// ProductHide 	- Hide the Results
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	void
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function ProductHide(  )
{
	if( document.getElementById( 'myResults' ) )
	{
		document.getElementById( 'myResults' ).style.visibility = "hidden";
			//document.getElementById( 'MainSection_Top' ).style.overflow="hidden";
	//document.getElementById( 'MainSection_Top' ).style.zIndex="999";
	}
}

///////////////////////////////////////////////////////////////////////////////
// SelectItem 	- Select a listing
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	object, object
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function SelectItem( charCode )
{
	

	// 2006.08.01 KJD: Only if the menu is open
	if( document.getElementById( 'myResults' ).style.visibility == "visible" )
	{
		// alert( charCode );
		if( charCode == 38 ) // Up Arrow
		{
			
			if( CurrentItem > 0 )
			{
				CurrentItem--;
				Highlight( CurrentItem );
			}
			
		}
		else if( charCode == 40 ) // Down Arrow
		{
			
			if( CurrentItem < ( ShowingItems - 1 ) )
			{
				CurrentItem++;
				Highlight( CurrentItem );
			}
		}
		else if( charCode == 13 ) // Enter key
		{
			// 2006.10.24 KJD: if we have matching items.
			if( PageItems.length > 0 )
			{
				// 2006.10.24 KJD: Match with selection or what is entered
				if ( CurrentItem  > -1 )
				{
					var matchString = PageItems[CurrentItem].toUpperCase();
				}
				else
				{
					var matchString = document.myForm.myField.value.toUpperCase();
				}
				
				
				
				var itemURL = "";
				// 2006.10.24 KJD: Find the product in the Product Array
				for( var i = 0; i < ProductArray.length; i++ )
				{
					// 2006.10.24 KJD: Check if it contains the string
					if( matchString.indexOf( ProductArray[i]['name'].toUpperCase() ) >  -1 )
					{
						itemURL = ProductArray[i]['url'];
					}
				}

				EnterItem( CurrentItem, itemURL );
				
				ProductHide();
			}
			else
			{
				FormSubmit(  );
			}
		}
	}
	else
	{
		if( charCode == 13 )
		{
			FormSubmit(  );
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
// Highlight 	- highlight a listing
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	object, object
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function Highlight( itemid )
{
	DeselectAll( );
	eval("prodSelect_" + itemid).className = "ProductSelect";
}

///////////////////////////////////////////////////////////////////////////////
// DeselectAll	- Deselect all listings
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	object, object
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function DeselectAll( )
{
	for( i=0; i < ShowingItems; i++ )
	{
		eval("prodSelect_" + i).className = "ProductDeselect";
	}
}

///////////////////////////////////////////////////////////////////////////////
// EnterItem	- Enter the item into the form
// Author: 		Kevin De Angelis
// Date: 		2006.08.01
// Receive: 	integer
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function EnterItem( itemid, itemurl )
{
	// 2006.08.31 KJD: Check for something we're not showing
	if( PageItems[itemid] )
	{
		document.myForm.myField.value = PageItems[itemid];
		
		// 2007.09.23 KJD: Added for bug fix, text not displaying if ID not declared.
		document.getElementById( 'select_myField' ).value = PageItems[itemid];
	}
	
	// ProductHide(  );
	
	if( itemurl != "" )
	{
		if( PageItems[itemid] )
		{
			// 2006.10.10 KJD: Keep the url
			document.myForm.productURL.value 	= itemurl;
			viewItemURL 						= itemurl;
		}
		else
		{
			// location.href						= itemurl;
		}

		// 2006.10.24 KJD: Do not submit
		// FormSubmit();
		
	}
	else
	{
		// 2006.10.10 KJD: submit only if there's no url
		FormSubmit(  );
	}
}

///////////////////////////////////////////////////////////////////////////////
// FormSubmit	- Submit the Form
// Author: 		Kevin De Angelis
// Date: 		2006.08.02
// Receive: 	void
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function FormSubmit(  )
{
	// 2006.10.24 KJD: Somehow the var is not getting set, so let's check for it
	if(  ( viewItemURL ) && !( document.myForm.productURL.value ) )
	{
		document.myForm.productURL.value = viewItemURL;
	}

	// 2006.10.10 KJD: Check for url
	if( document.myForm.productURL.value != "" )
	{
		// location.href = document.myForm.productURL.value;
	}
	else
	{

		/*
		if( document.myForm.myField.value != "" )
		{
			
			//myForm.qt.value = myForm.myField.value;
			//myForm.submit();
			
			
			// location.href= document.myForm.action;
		}
		
		if( ( document.myForm.myField.value == "" ) || ( document.myForm.myField.value == " Enter product name" ) )
		{
			FinderSubmit();
		}
		*/
	}
	
	FinderSubmit();
}


///////////////////////////////////////////////////////////////////////////////
// LoadHere	- What to load into the text field
// Author: 		Kevin De Angelis
// Date: 		2006.10.27
// Receive: 	void
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function LoadHere( item )
{
	if( item )
	{

		if( !( item.value ) && !( TextCleared ) )
		{
			item.value = EntryText;
		}
	}
}

///////////////////////////////////////////////////////////////////////////////
// CheckEntry	- Check if the field has been cleared or not
// Author: 		Kevin De Angelis
// Date: 		2006.10.27
// Receive: 	void
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function CheckEntry( item )
{
	if( item.value != EntryText )
	{
		TextCleared = 1;
	}
	else
	{
		item.value = "";
	}
}

///////////////////////////////////////////////////////////////////////////////
// HelpWindow	- Show or hide help window
// Author: 		Kevin De Angelis
// Date: 		2006.10.30
// Receive: 	string
// Return: 		void
///////////////////////////////////////////////////////////////////////////////
function HelpWindow( thisStyle )
{
	document.getElementById("PopupWindow").style.visibility = thisStyle;
}


///////////////////////////////////////////////////////////////////////////////
// FinderSubmit	- Form return setting
// Author: 		Kevin De Angelis
// Date: 		2006.12.19
// Receive: 	void
// Return: 		boolean t/f
///////////////////////////////////////////////////////////////////////////////
function FinderSubmit(  )
{
	var WindowStatus = document.getElementById("myResults").style.visibility;

	//var allProductsURL = "/business/products/allproducts.jsp";
	var goToPage = "";
	
	// 2006.12.19 KJD: Check if menu open/closed
	if( WindowStatus == "hidden" )
	{
		if( ( viewItemURL )&& ( viewItemURL != "" ) )
		{
			// Menu is close and we have a URL, redirect
			// alert("1: " + viewItemURL);
			
			goToPage	= viewItemURL;
		}
		else
		{
			// alert('nothing entered');
			goToPage	= allProductsURL;
		}
	}
	else
	{
		// 2006.12.19 KJD: If the entered info doesn't match anything go to all products page
		if( !( viewItemURL ) && !( document.myForm.productURL.value ) )
		{
			// 2006.12.19 KJD: Bogus info entered, go view all products
			// location.href	= ;
			// alert("2: " + "../products/allproducts.jsp");
			goToPage	= allProductsURL;
		}
		else
		{
			// alert('3: v:' + viewItemURL + " d:" + document.myForm.productURL.value);
			goToPage	= viewItemURL;
		}
	}
		
	location.href= goToPage;
	
	ProductHide();
	return false;

}


// 2006.10.27 KJD: Load the text into the field
// 2007.02.02 KJD: Check if searchdiv exists first
if( document.getElementById('searchDiv') )
{
	LoadHere( document.myForm.myField );
}

