<!--//


//-------------------------------------------------------------------
// NAME
// fixLinkAndGo
//
// DESCRIPTION
// Toggles between basic & advanced forms, resets a few booleans, 
// submits form
//
// INPUT
// blnAdvanced: Boolean; True if currently in advanced form, false otherwise
// blnSections: Boolean; True if showing other category types besides default; false otherwise
// blnNew: 		Boolean; Flags that we are entering advanced form, not recursing
// blnReset: 	Boolean; True if we want form to reset, false otherwise
//
// OUTPUT
// None; submits form
//
//-------------------------------------------------------------------

function fixLinkAndGo(blnAdvanced, blnSections, blnNew, blnReset)
{
	
	var bFullBooleanExists = false;

	for (i=0; i < document.frmSearch.elements.length; i++) {
		if (document.frmSearch.elements[i].name == 'fullBoolean'){
			bFullBooleanExists = true;
			break;
		}
	}

	if (blnAdvanced == 'True' ) {
	//back to basic
		document.frmSearch.advanced.value = 'False';
		document.frmSearch.isNew.value = blnNew;

	}else{
	//go to advanced
		document.frmSearch.advanced.value = 'True';
		document.frmSearch.isNew.value = blnNew;
	}
	
	if (blnReset == 'True' ){
	//reset the form
		document.frmSearch.resetForm.value = 'True';

		if (document.frmSearch.selCategory){
			if (document.frmSearch.selCategory.type == "hidden"){
				document.frmSearch.selCategory.value = 0;
			}else{
				document.frmSearch.selCategory.selectedIndex = 0;
			}
		}

		if (document.frmSearch.selMultiSite){
			if (document.frmSearch.selMultiSite.type != "hidden"){
				document.frmSearch.selMultiSite.selectedIndex = 0;
			}
		}
		
		if (bFullBooleanExists) { document.frmSearch.fullBoolean.checked = false; }
		document.frmSearch.qu.value = '';

	}else if (blnReset == 'False' ){
		document.frmSearch.resetForm.value = 'False';
	}
		
	document.frmSearch.otherSections.value = blnSections;
	document.frmSearch.searchaction.value = '';
	document.frmSearch.submit();
		
}




//-------------------------------------------------------------------
// NAME
// FixFormAndSubmit
//
// DESCRIPTION
// Checks to see if boolean is in search phrase; if so, alerts user.
// Sets values on hidden form fields, returns T/F.
//
// INPUT
// None
//
// OUTPUT
// Boolean; true if no boolean or if user continues; false if user cancels
//
//-------------------------------------------------------------------
function FixFormAndSubmit()
{

	var sTmp = '';
	var iCount = 0;
	var iPos = 0;
	var sMsg = '';
		
	var bContinue = true;
	var sPhrase = window.document.frmSearch.qu.value;
	var re = new RegExp("\\sand\\s|\\snot\\s|\\sor\\s", "gi");
	var re1 = /^"|^'/; 
//"
	var re2 = /"$|'$/;
//"
		
	var bPhrase = (re1.test(sPhrase) && re2.test(sPhrase))	

	var bFullBooleanExists = false;
	var bFullBoolean = false;
	if (document.frmSearch.fullBoolean) {bFullBooleanExists = true;}

	if (bFullBooleanExists) {
		if ( document.frmSearch.fullBoolean.checked == true ) 
		{
			 bFullBoolean = true;
		}
	}

	sTmp = sPhrase;
	iPos = sTmp.indexOf("\"")
	while ( iPos >= 0 ) {
		iCount ++;
		iPos = sTmp.indexOf("\"", iPos+1)
	}

	if (iCount % 2 != 0) {
		sMsg += '\nCaution! Unmatched quotes may affect your search. Do you wish to continue?\n'
	}

	if ( re.test(sPhrase) && ! bPhrase && ! bFullBoolean) {
		sMsg += '\nThe words AND, OR and NOT will be removed from your phrase.\nIf you wish to do a boolean search, please use the dropdowns or the full boolean search checkbox in the Advanced Search.\n\nIf advanced search criteria are selected, they will be used.\nOtherwise, the search will match against all other words in the phrase.\n';
	}

	if ( bFullBoolean ){
		re = /[,;\-!\*%\.<>]/
	}else{
		re = /[,;\-!\*%\.<>()]/
	}


	if ( re.test(sPhrase) && ! bPhrase ) {
		sMsg += '\nThe following characters will be removed from your phrase:\n < ( !  ,  ;  .  *  -  % ) >  and excess quotation marks\n\nIf you wish to do a boolean search, please use the Advanced Search feature.\n'
	}

	if (sMsg != '') {
		if ( ! confirm(sMsg)){ bContinue = false; }
	}

	if (bContinue){
		window.document.frmSearch.btnSearch.value='Search';
		window.document.frmSearch.resetForm.value='False';
		window.document.frmSearch.isNew.value='False';
		window.document.frmSearch.searchaction.value = 'find';
	}

	return bContinue;

}


//-------------------------------------------------------------------
// NAME
// FixPagingAndSubmit
//
// DESCRIPTION
// Results page-- Sets values on hidden form fields which may influence 
// which page and record we show of search results; submits results form
//
// INPUT
// iType:	Integer; Type of search -- internal, external
// iPage:	Integer; Current results page number
// iRecNum:	Ingeter; Current results record number
//
// OUTPUT
// None; submits form
//
//-------------------------------------------------------------------
function FixPagingAndSubmit(iType, iPage, iRecNum, sDomain)
{

	document.frmSearch.pg.value = iPage;
	document.frmSearch.RN.value = iRecNum;
	document.frmSearch.searchtype.value = iType;
	document.frmSearch.pageDomain.value = sDomain;
	window.document.frmSearch.resetForm.value='False';
	window.document.frmSearch.isNew.value='False';
	document.frmSearch.submit();

}


//-------------------------------------------------------------------
// NAME
// launchWindow
//
// DESCRIPTION
// Launches a new window
//
// INPUT
// newURL:	String; URL of new window
// newName:	String; Name of new window
// newFeatures: String; Options of new window
//
// OUTPUT
// None; opens window
//
//-------------------------------------------------------------------

function launchWindow(newURL, newName, newFeatures) {
  var launchFeatures = newFeatures + ",resizable=yes,scrollbars=yes,status=yes,menubar=yes,toolbar=yes,location=yes,directories=yes";
  var remote = open(newURL, newName, launchFeatures);
  if (remote.opener == null) // if something went wrong
    remote.opener = window;
  return remote;
}





//-------------------------------------------------------------------
// NAME
// defaultDates
//
// DESCRIPTION
// Only if advanced search is being used
//
// INPUT
// dFirst:	String; Sets hidden form field value to date of first post
// dLast:	String; Sets hidden form field value to date of last post
//
// OUTPUT
// None
//
//-------------------------------------------------------------------

function defaultDates(dFirst, dLast)
{
	document.frmSearch.dtStart.value=dFirst;
	document.frmSearch.dtEnd.value=dLast;
}



//------------------------------------------------------
// NAME
// checkEnter
//
// DESCRIPTION
// If Enter key pressed, submits form
//
// INPUT
// event:	Event; The keypress
//
// OUTPUT
// None; Submits form. The function defined in onSubmit then takes over.
//
//-------------------------------------------------------------------
NS4 = (document.layers) ? true : false;

function checkEnter(event)
{ 	

	var code = 0;

	if (window.event){
	//don't take action for IE
	
		code =  event.keyCode; //0; //
	
	}else if (event){
	//take action for Netscape
	
		code = event.which;
	
	}else{
	//some other browser that doesn't follow the above
	
		alert('Please click the "Search" or "Go" button.');
	}

	if (code==13){
		if ( FixFormAndSubmit() ) { document.frmSearch.submit(); }
	}else{
		return true;
	}

}




//------------------------------------------------------
// NAME
// fncRecurseFormGMSearch
//
// DESCRIPTION
// Determines if selected search site's GM status matches
// current search site's GM status.
// If so, OK; else recurse the form without doing the search.
// Purpose is to change the display of advanced functions.
//
// INPUT
// objSelect: Object; select box
// objForm: Object; search form
// iCurrentMulti: Integer; name of current siteid
//
// OUTPUT
// None; If need be, submits form to recurse without performing search.
//
//-------------------------------------------------------------------
function fncRecurseFormGMSearch(objSelect, objForm, iCurrentMulti)
{

	var iSelectedMulti = objSelect.options[objSelect.selectedIndex].value;

//alert(iSelectedGM + ' ' + iCurrentGM + ' ' +	(iSelectedGM == iCurrentGM));

	if (! (iSelectedMulti == iCurrentMulti) ){
		objForm.searchaction.value = '';
		objForm.submit();
	}
	
	return;

}



//------------------------------------------------------
// NAME
// fncRecurseFormFullBoolean
//
// DESCRIPTION
// Recurses form without searching when full boolean checkbox is 
// checked or unchecked
//
// INPUT
// objForm: Object; search form
//
// OUTPUT
// None; If need be, submits form to recurse without performing search.
//
//-------------------------------------------------------------------
function fncRecurseFormFullBoolean(objForm, bShowingAdvancedOptions)
{
//alert(bShowingAdvancedOptions);

	if (bShowingAdvancedOptions == 'True'){
		objForm.searchaction.value = '';
		objForm.submit();
	}

	return;
}



//------------------------------------------------------
// NAME
// fncRecurseFormSelect
//
// DESCRIPTION
// Recurses form without searching when list selection is changed
//
// INPUT
// objForm: Object; search form
//
// OUTPUT
// None; If need be, submits form to recurse without performing search.
//
//-------------------------------------------------------------------
function fncRecurseFormSelect(objForm)
{

	objForm.searchaction.value = '';
	objForm.submit();
}




//-------------------------------------------------------------------
// NAME
// stopNonStandardSearch
//
// DESCRIPTION
// Sets up link to taxonomy search and submits
//
// INPUT
// sRedirect: String; page to redirect to
// sQSSpecial; String; specific special parm(s) to add to querystring
// 	includes leading &
//
// OUTPUT
// None; submits form
//
//-------------------------------------------------------------------
function stopNonStandardSearch(objForm)
{

	objForm.Taxonomy.value = 'False';
	objForm.specialSearch.value = 'False';
	return;
}


//-------------------------------------------------------------------
// NAME
// fixSpecialLinkAndGo
//
// DESCRIPTION
// Sets up link to taxonomy search and submits
//
// INPUT
// sAction: String; form action (find)
// iKWID: Integer; Selected Keyword ID
// bReSet: Boolean; how to set flag Reset
// bNewt: Boolean; how to set flag isNew
// bSpecial: Boolean; how to set flag for special search
// bTaxonomy: Boolean; how to set flag for taxonomy
//
// OUTPUT
// None; submits form
//
//-------------------------------------------------------------------
function fixSpecialLinkAndGo(sAction, iKWID, bReSet, bNew, bSpecial, bTaxonomy)
{

	document.frmSearch.advanced.value = 'False';
	document.frmSearch.isNew.value = bNew;
	document.frmSearch.resetForm.value = bReSet;
	document.frmSearch.searchaction.value = sAction;
	document.frmSearch.specialSearch.value = bSpecial;
	document.frmSearch.Taxonomy.value = bTaxonomy;

	for (i=0; i < document.frmSearch.elements.length; i++){
		if (document.frmSearch.elements[i].name == "KWIDS"){
			document.frmSearch.KWIDS.value = iKWID;
			break;
		}
	}
	document.frmSearch.submit();

}



//-->

