var jsdebug = "NO";

// NLNZ: Copy of bits from validate.js and getcheck.js to handle site-wide query box called queryboxtop

function validate_form_browse_nlnz()
{

	if ( document.queryboxtop.pm_SA.value == "")
	{
		alert ( "Please enter a term to search on." );
		return false;
	}
	else if (document.queryboxtop.pm_SC.value == "FT" || document.queryboxtop.pm_SC.value == "AFT")
	{
		xloc = document.fttop.action;
		xloc += "OUTPUTXSL=" + document.fttop.OUTPUTXSL.value;

		if(document.queryboxtop.pm_SC.value == "FT")
		{
			xloc += "&pm_FT=" + encodeURIComponent(document.queryboxtop.pm_SA.value);
		}
		else if (document.queryboxtop.pm_SC.value == "AFT")
		{
			xloc += "&pm_AFT=" + encodeURIComponent(document.queryboxtop.pm_SA.value);
		}

		xloc += "&Submit=Go";
		xloc += "&pm_MH=" + document.queryboxtop.pm_MH.value;
		if ( document.queryboxtop.pm_CL.length)
		{
			for(i = 0; i <  document.queryboxtop.pm_USI.length; i++)
			{
				if( document.queryboxtop.pm_USI[i].selected)
				{
					xloc += "&pm_USI=" +  document.queryboxtop.pm_USI[i].value;
				}
			}
		}
		xloc += "&api_2=SIMULFIND" ;
		
		// Dedupe Flag ?
		if(document.queryboxtop.DDF.checked)
		{
			xloc += "&ds_svGeneric_DDF=Y";
		}
		else
		{
			xloc += "&ds_svGeneric_DDF=N";
		}
		
		// Include Local Catalog ?
		if(document.queryboxtop.pm_OPC.checked)
		{
			xloc += "&pm_OPC=Y";
		}
		else
		{
			xloc += "&pm_OPC=N";
		}
		if ( document.queryboxtop.pm_CL.length)
		{
			for(i = 0; i < document.queryboxtop.pm_CL.length; i++)
			{
				if(document.queryboxtop.pm_CL[i].checked)
				{
					xloc += "&pm_CL=" + document.queryboxtop.pm_CL[i].value;
				}
			}
		}

		else
		{
        	xloc += "&pm_CL=" + document.queryboxtop.pm_CL.value;
		}
		
		xloc += "&api_1=COLLECTION_REPOLOGIN";
		xloc += "&DIRECTIVE=createSrHist&ds_svGeneric_MH=" + document.queryboxtop.pm_MH.value;

		if (jsdebug == "YES")
		{
			alert(xloc);
		}
		location.href = xloc;

		return false;
    }

	 else
	 {
	 	document.queryboxtop.ds_svGeneric_MH.value = document.queryboxtop.pm_MH.value;
		
		// Dedupe Flag ?
		if(document.queryboxtop.DDF.checked)
		{
			document.queryboxtop.ds_svGeneric_DDF.value = "Y";
		}
		else
		{
			document.queryboxtop.ds_svGeneric_DDF.value = "N";
		}
		
			document.queryboxtop.submit();
	 }
    return true;

}

function HandleFt_nlnz()
{

	// OR free text searching
	if (document.queryboxtop.pm_SC.value == 'FT' )
	{
		if (typeof(document.fttop.pm_FT) != "undefined")
		{
			document.fttop.pm_FT.value = unescape(document.queryboxtop.pm_SA.value);
			document.fttop.pm_OPC.value = document.queryboxtop.pm_OPC.value;
			document.fttop.pm_MH.value = document.queryboxtop.pm_MH.value;
		}
	}
	// AND free text searching
	if (document.queryboxtop.pm_SC.value == 'AFT' )
	{ 
		if (typeof(document.fttop.pm_AFT) != "undefined")
		{
		document.fttop.pm_AFT.value = unescape(document.queryboxtop.pm_SA.value);
		document.fttop.pm_OPC.value = document.queryboxtop.pm_OPC.value;
		document.fttop.pm_MH.value = document.queryboxtop.pm_MH.value;
		}
	}
}


function GetChecked_nlnz()
{
	HandleFt_nlnz();
	return validate_form_browse_nlnz();	//Use this to call the querybox form to validate 
						//if anything is in the search box
}

function GetChecked_nlnz_topic()
//same as real GetChecked but don't check pm_CL is there (topic search box uses
//a single pm_CL whereas real GetChecked expects it to be a series of checkboxes)
{
	HandleFt();
	return validate_form_browse_nlnz();	//Use this to call the querybox form to validate 
						//if anything is in the search box
}
