

function changeSearchInfo(searchType, isDefault, div) {
	var searchInfoDiv = document.getElementById("SearchInfo");
	searchInfoDiv.innerHTML = document.getElementById("searchinfo-" + searchType).innerHTML;
	if (isDefault) {
		if (div != null) {
			div.style.backgroundColor = "";
		}
	} else if (div != null) {
		div.style.backgroundColor = "#F7F7F7";
	}
}

function resetSearchInfo(div) {
	var searchInfoDiv = document.getElementById("SearchInfo");
	searchInfoDiv.innerHTML = "";

	if (div != null) {
		div.style.backgroundColor = "";
	}
}

/* detect Enter key on the dropdown and submit the form */
function searchModeKeyDown(evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
	if ((charCode == 13) || (charCode == 3)) {
		doSearchBoxSubmit();
		return false;
	}
	return true;
}

/*
 *   toggle: function(element) {
    element = $(element);
    Element[Element.visible(element) ? 'hide' : 'show'](element);
    return element;
  },
 */

/** 
 * Show or hide the more options div based on the state of "on"
 */
function showHideOptions(on) {
	
	var moreOptions = document.getElementById("moreOptions");
	var advancedSearch = document.getElementById("advancedSearch");
	var hideQsBox = document.getElementById("hideQsBox");
	
	moreOptions.style.display = (moreOptions.style.display == "none") ? "" : "none";
	advancedSearch.style.display = (advancedSearch.style.display == "none") ? "" : "none";
	hideQsBox.style.display = (hideQsBox.style.display == "none") ? "" : "none";
	
	if (on) { 
		var curQuery = document.FindIn.query.value;	// save & restore the current query before the "reset" below
		document.getElementById("FindIn").reset();
		document.FindIn.query.value = curQuery;
		
	}

	var searchBoxInnerDiv = document.getElementById("searchBoxInnerDiv");
	searchBoxInnerDiv.style.borderTop = (on ? "solid black 1px" : "none");
	searchBoxInnerDiv.style.borderLeft = (on ? "solid black 1px" : "none");
	searchBoxInnerDiv.style.borderRight = (on ? "solid black 1px" : "none"); 
}

function changeSearchLocation(searchType, searchQuery, fromSearchBox) {

	var gotoURL;
	
	// Depending on search type, we will be going to different URLs for the results
	switch (searchType) {
		case "total":
		case "companysites":
		case "appnotes":
		case "patents":
		case "standards":
		case "materials":
		case "partnumbers":
		case "thissite":	//added for 'this site' searches - RH 3/20/2006
			gotoURL = engWebURL + encodeURIComponent(searchQuery) + "&show=" + searchType;
			break;
		case "products":
			gotoURL = productFinderURL + encodeURIComponent(searchQuery);				
			break;
		case "services":				
			gotoURL = productFinderURL + encodeURIComponent(searchQuery) + "&mode=services";				
			break;
		case "prodannounce":
			gotoURL = productAnnouncementsURL + encodeURIComponent(searchQuery);
			break;
		case "engnews":
		
			if (searchQuery == "") {
				gotoURL = engnewsHomeUrl;
			} else {
				gotoURL = engnewsSearchUrl + encodeURIComponent(searchQuery);	
			}			
			break;
		default:
			gotoURL = engWebURL + encodeURIComponent (searchQuery)+ "&show=total";
			break;
	}
	
	//alert(gotoURL);
	location.href = gotoURL;
}

// A version of doSearchBoxSubmit that ascertains which petal to show based on the form.
function doSearchBoxSubmit() {			
	var searchterm = document.FindIn.query.value;
	var gotoURL = searchDomain + "/Search?query=";		
	var show;
	var radioButtons = document.FindIn.show;	

	for(i=0; i < radioButtons.length; i++) {
		if(radioButtons[i].checked) {
			show = radioButtons[i].value;
		}		
	}
	
	/*
	Since Engineering news has a homepage, its okay to submit it without
	a query. KC 09/11/06
	*/
	if (searchterm == "" && show != "engnews") {
		alert("Please enter a search term");
	} else {
		var fromSearchBox = true;	
		changeSearchLocation(show, searchterm, fromSearchBox);
	}		
}


