//-------------------------------------------------------------------
// Function:      clearfield
// Developer:     Telly
// Date Created:  09/02/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:  09/02/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:  09/02/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,strParsedSearchArg;
	var strSite, strClient, strProxyStylesheet, strOutput, strFilter, strGetFields;
	
	//strRootChannelUrl = form.RootChannelUrl.value;
						
	strArg = form.search.value;
	strSite = form.site.value;
	strClient = form.client.value;
	strProxyStylesheet = form.proxystylesheet.value;
	strOutput = form.output.value;
//	strRestrict = form.filter.value;
	strGetFields = form.getfields.value;
	
	window.location = loc+'?q='+strArg+'&site='+strSite+'&client='+strClient+'&proxystylesheet='+strProxyStylesheet+'&output='+strOutput+'&filter='+strFilter+'&getfields='+strGetFields;
	
}

//-------------------------------------------------------------------
// Function:      trim
// Developer:     Telly
// Source:		  http://www.devx.com/tips/Tip/16157?trk=DXRSS_WEBDEV by Kesav Kumar Kolla
// Date Created:  02/17/2004
// Description:   This code uses regular expressions to strip the spaces 
//				  around given input string.
// Parameter1:    input  = the user's search string
//-------------------------------------------------------------------
function trim(input)
{
  var lre = /^\s*/;
  var rre = /\s*$/;
  input = input.replace(lre, "");
  input = input.replace(rre, "");
  return input;
}

//-------------------------------------------------------------------
// Function:      RemoveNoiseWords
// Developer:     Telly
// Source:		  microsoft.public.sqlserver.fulltext by Hilary Cotter
// Date Created:  02/13/2004
// Description:   Removes noise words from search strint
// Parameter1:    phrase  = the user's search string
//-------------------------------------------------------------------
function RemoveNoiseWords(phrase)
{
	//dimensionalizing variables
	noisearray=new Array();
	array_phrase=new Array();
	array_pruned=new Array();
	//alert(phrase);

	var noisearray=new Array
	("","0","1","2","3","4","5","6","7","8","9","$","&","a","about","after","all","also","an","and","another","any","are","as","at","b","be","because","been","before","being","between","both","but","by","c","came","can","come","could","d","did","do","does","e","each","else","f","for","from","g","get","got","h","had","has","have","he","her","here","him","himself","his","how","i","if","in","into","is","it","its","j","just","k","l","like","m","make","many","me","might","more","most","much","must","my","n","never","now","o","of","on","only","or","other","our","out","over","p","q","r","re","s","said","same","see","should","since","so","some","still","such","t","take","Test","than","that","the","their","them","then","there","these","they","this","those","through","to","too","u","under","up","use","v","very","w","want","was","way","we","well","were","what","when","where","which","while","who","will","with","would","x","y","you","your","z");
	var array_pruned_length = 0;
	var counter=0;
	var counter1 = 0;
	var counter2 = 0;
	var phrase1;
	var length = 0;
	var noise_array_counter=0;
	var search_phrase = "";
	var phrase1;
	phrase1 = phrase;

	//spliting the search phrase into an array
	array_pruned = phrase.split(" ");
	array_pruned_length =  array_pruned.length;

	//Check to see if the phrase has a double quote.  
	//If it does, the user is making a phrase search.	
	if(phrase.indexOf('"') == -1)
	{
		//if(phrase.search(/(or|near)/i) == -1)
		if(phrase.search(/\b(or|near)\b/gi) == -1)
		{
			for (counter = 0; counter < array_pruned_length; counter++)
			{
				counter2 = 0;
				counter1 = 0;

				for (counter1 = 0; counter1 < noisearray.length; counter1++)
				{

					if(array_pruned[counter].toUpperCase() == noisearray[counter1].toUpperCase())
					{
						search_phrase = " " + array_pruned[counter] + " ";
						search_phrase_first_position = array_pruned[counter] + " ";
						counter2 = phrase.indexOf(search_phrase,0);
						counter3 = phrase.indexOf(search_phrase_first_position,0);
						
						if(counter3 < counter2)
							counter2 = counter3;
						while (counter2 >= 0)
							{
								temp_string = array_pruned[counter];
								length = temp_string.length;
								phrase = phrase.substr(0,counter2) + phrase.substr(counter2 + length + 1);
								counter2 = phrase.indexOf(search_phrase,0);
							}
					}
				}
			}
			
			phrase = phrase.replace(/\s/g," AND ");
			//phrase = phrase.replace(/\,|\;|\:|\./g,"");
			//alert('This is the phrase: ' + phrase);
		}
	}	
	return phrase;
}

//-------------------------------------------------------------------
// Function:      catchKeyPress
// Developer:     Telly
// Date Created:  09/02/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 == 'search'){
			ret=document.getElementById("btnG");
		}
		if(ret) { 
			ret.click(); 
		}
	}               
}

//-------------------------------------------------------------------
// Function:      testForEnterAndEsc
// Developer:     Telly
// Date Created:  09/02/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";
//		}
//	}
