//-------------------------------------------------------------------
// Function:      clearfield
// Developer:     Telly
// Date Created:  08/27/2003
// Description:   Clears the current textbox of the default value.
// Parameter:     field  = current form element
//-------------------------------------------------------------------
function clearfield(field){
	if (field.value == field.defaultValue)
			field.value = "";
}

//-------------------------------------------------------------------
// Function:      checkField
// Developer:     Telly
// Date Created:  08/27/2003
// Description:   Adds the default text to the textbox if empty.
// Parameter:     field  = current form element
//-------------------------------------------------------------------
function checkField(field){
	if(field.value == ""){
			field.value = field.defaultValue;
	}
}

//-------------------------------------------------------------------
// Function:      RedirectPopUp
// Developer:     Telly
// Date Created:  08/27/2003
// Description:   Redirects the users based on the search type chosen
//                in the search user control.
// Parameter1:  loc  = URL
// Parameter2:  form = the form.
//-------------------------------------------------------------------
function RedirectPopUp (loc,form) {
	var strType,strArg,strRootChannelUrl;
	var strSite, strClient, strProxyStylesheet, strOutput, strRestrict, strGetFields;
	
	strRootChannelUrl = form.RootChannelUrl.value;

	if(form.dlSearchType.options[form.dlSearchType.selectedIndex].value == ""
	|| form.SearchArg.value == "" || form.SearchArg.value == "Enter Keyword")
	{
		alert("Please completely fill out your search criteria.");
	}
	else if(form.dlSearchType.options[form.dlSearchType.selectedIndex].value == "WebsiteOnly")
	{					
		strArg = form.SearchArg.value;
		strSite = form.site.value;
		strClient = form.client.value;
		strProxyStylesheet = form.proxystylesheet.value;
		strOutput = form.output.value;
		strFilter = form.filter.value;
		strGetFields = form.getfields.value;
		window.location = 'http://search2.google.cit.nih.gov/search?q='+strArg+'&site='+strSite+'&client='+strClient+'&proxystylesheet='+strProxyStylesheet+'&output='+strOutput+'&filter='+strFilter+'&getfields='+strGetFields;
	}
	else if(form.dlSearchType.options[form.dlSearchType.selectedIndex].value == "OnlineJournals")
	{					
		strArg = form.SearchArg.value;
		window.location = strRootChannelUrl + 'ResearchTools/default.htm?srchType=OnlineJournals&issearch=yes&searchtext='+strArg;
	}
	else
	{
		strType = form.dlSearchType.options[form.dlSearchType.selectedIndex].value;
		strArg = form.SearchArg.value;

		/*top.new_win =*/ window.open(loc+'?arg='+strArg+'&type='+strType, 'Search_Redirect','toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=500');
		//top.new_win.creator = self;			
	}		
}

//-------------------------------------------------------------------
// Function:      catchKeyPress
// Developer:     Telly
// Date Created:  08/27/2003
// Description:   Check to see if the user pressed the enter 
//                button on the search user control and calls the
//                click method of the button.
// Parameter1:  code   = the key pressed on the keyboard
// Parameter2:  sender = the element on the page the action will be 
//                       taken against.
//-------------------------------------------------------------------
function catchKeyPress(code, sender) {
	var ret=null;
	
	testForEnterAndEsc();
	
	if(code == '13') {
		if(sender.name == 'SearchArg'){
			ret=document.getElementById("btnGo");
		}
		
		if(ret) { 
			ret.click(); 
		}
	}               
}

//-------------------------------------------------------------------
// Function:      testForEnterAndEsc
// Developer:     Telly
// Date Created:  08/27/2003
// Description:   used with the catchKeyPress function to prevent 
//                bubbling of the event.
//-------------------------------------------------------------------
function testForEnterAndEsc() {    
	if (event.keyCode == 13){// || event.keyCode == 27) {        
		event.cancelBubble = true;
		event.returnValue = false;
	}
}

//-------------------------------------------------------------------
// Function:      ChangeSearchArgText
// Developer:     Telly
// Date Created:  09/22/2003
// Description:   Changes the text of the SearchArg textbox based on the 
//                user's dropdown selection.
// Parameter1:  dropdown	= the dropdown selection value
// Parameter2:  form		= the SearchArg textbox 
//-------------------------------------------------------------------
function ChangeSearchArgText(dropdown,form){
	if(dropdown.options[dropdown.selectedIndex].value == "WebsiteOnly"){
		form.value = "Search Keyword";		
	}
	else{
		form.value = "Search Title";
	}
} 