{$context->oPage->requireJSResource('thirdpartyjs/MochiKit/MochiKitPacked.js')}
{$context->oPage->requireJSResource('resources/js/toggleselect.js')}

<div class="collapsible">
<h4 onclick="toggleElementClass('expanded', this.parentNode)">{i18n}Search Criteria{/i18n}</h4>
<div class="collapsiblebody">
<fieldset>
	<legend>{i18n}Search Criteria{/i18n}</legend>
	{$txtQuery}
	<br>
{if empty($iSavedID)}
	{capture assign=options}
    	<a href="{addQS}action=queryBuilder{/addQS}">{i18n}Search Critieria Editor{/i18n}</a>
    {/capture}
	{i18n arg_options=$options}Use the #options# to extend your search criteria.{/i18n}
{/if}
{if !empty($iSavedID)}
	{capture assign=options}
    	<a href="{addQS}action=queryBuilder&fSavedSearchId={$iSavedID}{/addQS}">Query Editor</a>
    {/capture}
	{i18n arg_options=$options}To edit the search criteria, use the #options#.{/i18n}
{/if}
	<font color=brown><div id="savedSearch" style="display: none">{i18n}The search criteria has been saved.{/i18n}</div></font>
</fieldset>
<br>
{if !empty($iSavedID)}
<fieldset>
	<legend>{i18n}Saved Search{/i18n}</legend>
	{i18n}This is the saved search criteria:{/i18n} {$txtSavedName}. <br/>
	{capture assign=options}
    	<a href="{addQS}action=manage{/addQS}">{i18n}Manage Saved Search Criteria{/i18n}</a>
    {/capture}
	{i18n arg_options=$options}To delete this saved search criteria or to edit other saved search criteria, #options#.{/i18n}
</fieldset>
{/if}
{literal}
<script language="javascript">
var savesearch_gotStatus = function callBack(o)
{
	if (o.responseText != '{}')
	{
		var resp = eval('(' + o.responseText + ')');

		if (resp.status == 0)
		{
			parseSuccess = true;
			$('saveSearch').style.display='none';
			$('savedSearch').style.display='block';
			//alert('{/literal}{i18n}The search expression has been saved.{/i18n}{literal}');
		}
		else
		{
			 alert('{/literal}{i18n}There is a problem saving the expression expression.{/i18n}{literal}\n\n' + resp.message );
		}
	}
}
var savesearch_gotNoStatus = function callBack(o)
{
	alert('{/literal}{i18n}There is a problem communicating with the server.{/i18n}{literal}' +  o.responseText);
}

var saveSearchCallback =
{
	success:savesearch_gotStatus,
	failure:savesearch_gotNoStatus
}
function saveSearch()
{
	var txtName = $('txtSaveName');
	if (txtName.value == '')
	{
		alert('{/literal}{i18n}Please enter a name for the search expression.{/i18n}{literal}');
		txtName.focus();
		return;
	}
	url='{/literal}{$rootUrl}{literal}/search2/ajax/saveExpr.php?txtName='+ txtName.value +'&txtQuery={/literal}{$txtQuery|escape:'quotes'}{literal}';
	YAHOO.util.Connect.asyncRequest('GET',url, saveSearchCallback);
}

function onSelectAll()
{
	var cbSelectAll = $('cbSelectAll');

	for(var i={/literal}{$firstRec}{literal};i<{/literal}{$lastRec}{literal};i++)
	{
		var cb = $('cb' + i);

		cb.checked = cbSelectAll.checked;
	}
}

function onShowAll(showall)
{
	url = "{/literal}{addQS}{literal}action=searchResults&pageOffset={/literal}{$pageOffset}{literal}&showAll=" + showall + "{/literal}{/addQS}{literal}";

	document.location = url;
}

</script>
{/literal}
</div>
</div>
{if empty($iSavedID)}
<div id="saveSearch">
<fieldset>
	<legend>{i18n}You can save this search:{/i18n}</legend>
	<input id=txtSaveName>
	<input type=button value="{i18n}Save{/i18n}" onclick="saveSearch()">
</fieldset>
</div>
{/if}


<fieldset>

<legend>{i18n}Search Results{/i18n}</legend>

{if $numResults == 0}

	{i18n}There are no search results matching your search criteria.{/i18n}

	<p>
	{capture assign=options}
		<a href="{addQS}action=queryBuilder{/addQS}">{i18n}Search Criteria Editor{/i18n}</a>
	{/capture}

	{i18n arg_options=$options}Use the #options# to extend this query.{/i18n}

{else}

	<form method=post action="/action.php">
	<table border=0 cellpadding="1" cellspacing="1" width="800px" align=center>
	{assign var=cbid value=0}

	{foreach item=document from=$results}
		<tr><td>
		<input type="checkbox" name="selection_d[]" id="cb{$cbid}" value="{$document->DocumentID}"><nobr><a href="view.php?fDocumentId={$document->DocumentID}"><B>{$document->Title}</b></a>
		{if $document->Title != $document->Filename}
			&nbsp;&nbsp;
			<font style=" color: green "> - Filename: {$document->Filename}</font>
		{/if}
		{if !$document->IsAvailable}
			&nbsp;&nbsp;
			<font style=" color: red "><B> * {i18n}NOT AVAILABLE{/i18n} * </B></font>
		{/if}
		</td><td align=right>
			<font style="color: green ">{i18n}Document ID:{/i18n} {$document->DocumentID}</font>
			&nbsp;&nbsp;
			<font style=" color: orange ">{i18n}Version:{/i18n} {$document->Version}</font></td>
		</tr>
		<tr><td colspan=2>{$document->Text}</td></tr>
		<tr><td><font style=" color: green "><a href="{$rootUrl}/browse.php?fFolderId={$document->FolderId}">{$document->FullPath}</a>/{$document->Title} - {$document->Filesize}</font></td>
			<td align=right><nobr>
				<font style="color: orange ">
				{i18n}Created By:{/i18n} {$document->CreatedBy}
				{i18n}on{/i18n} {$document->DateCreated}
				</font>
			</td>


		<tr><td>
			{if $workflow != ''}
				<font style="color: orange ">{i18n}Workflow:{/i18n} $document->Workflow}</font>
			{/if}
			</td>
			<td align=right><nobr>
				<font style="color: brown ">
				{if $document->CheckedOutUser != ''}
					<b>{i18n}Checked out by:{/i18n} {$document->CheckedOutUser}
					{i18n}on{/i18n} {$document->DateCheckedOut}</b>
				{else}
					{i18n}Modified by:{/i18n} {$document->ModifiedBy}
					{i18n}on{/i18n} {$document->DateModified}
				{/if}
				</font>
			</td>

		<tr><td colspan=2><br></br></td></tr></tr>

		{assign var=cbid value=$cbid+1}
	{/foreach}

	<tr><td>
		<input type="checkbox" id="cbSelectAll" onclick="onSelectAll()">{i18n}Select All{/i18n}
		{if $showAll}
			<input type="checkbox"  onclick="onShowAll('false')" checked>{i18n}Show All{/i18n}
		{/if}
		{if !$showAll}
			<input type="checkbox"  onclick="onShowAll('true')">{i18n}Show All{/i18n}
		{/if}
		<br>
  		<input type="hidden" name="fFolderId" value="1" />
  		<input type="hidden" name="sListCode" value="" />
  		<input type="hidden" name="action" value="bulkaction" />
  		<input type="hidden" name="fReturnAction" value="search2" />
  		<input type="hidden" name="fReturnData" value="1" />

  		<nobr>
  		{foreach from=$bulkactions item=bulkaction}
      		<input type="submit" name="submit[{$bulkaction->getName()}]" value="{$bulkaction->getDisplayName()}" />
		{/foreach}
  		</nobr>
</table>
</form>

{/if}


</fieldset>

{if $endMovement - $startMovement > 0}
<br>
<br>
<table align="center">
<tr>
	{foreach item=move from=$pageMovement}
		{if $move == $startMovement}
			<td></td>
		{/if}
			<td><a href="search2.php?action=searchResults&pageOffset={$move}">{$move}</a></td>
		{if $move == $endMovement}
			<td></td>
		{/if}
	{/foreach}
</tr>
</table>
{/if}