   </table>
  </td>
 </tr>

 <tr>
  <td class="smallheader" colspan="2" align="left"><b><?php echo _("Message flags") ?></b></td>
 </tr>

 <tr>
  <td class="item" colspan="2">
   <table cellspacing="0" cellpadding="0" width="100%">
    <tr>
     <td class="item1" align="left" nowrap="nowrap">
      <input type="radio" id="flag_seen_0" name="search_flag[<?php echo IMP_SEARCH_FLAG_SEEN ?>]" value="0" <?php if (!empty($search['flag']) && $search['flag'][IMP_SEARCH_FLAG_SEEN] == 0) echo 'checked="checked" '; ?>/>
      <i><?php echo Horde::label('flag_seen_0', _("Old messages")) ?></i>
     </td>
     <td class="item1" align="left" nowrap="nowrap">
      <input type="radio" id="flag_seen_1" name="search_flag[<?php echo IMP_SEARCH_FLAG_SEEN ?>]" value="1" <?php if (!empty($search['flag']) && $search['flag'][IMP_SEARCH_FLAG_SEEN] == 1) echo 'checked="checked" '; ?>/>
      <i><?php echo Horde::label('flag_seen_1', _("New messages")) ?></i>
     </td>
     <td class="item1" align="left" nowrap="nowrap">
      <input type="radio" id="flag_seen_2" name="search_flag[<?php echo IMP_SEARCH_FLAG_SEEN ?>]" value="2" <?php if (empty($search['flag']) || $search['flag'][IMP_SEARCH_FLAG_SEEN] == 2) echo 'checked="checked" '; ?> />
      <i><?php echo _("Both") ?></i>
     </td>
     <td class="item1" width="100%">&nbsp;</td>
    </tr>

    <tr>
     <td class="item0" align="left" nowrap="nowrap">
      <input type="radio" id="flag_answered_0" name="search_flag[<?php echo IMP_SEARCH_FLAG_ANSWERED ?>]" value="0" <?php if (!empty($search['flag']) && $search['flag'][IMP_SEARCH_FLAG_ANSWERED] == 0) echo 'checked="checked" '; ?>/>
      <i><?php echo Horde::label('flag_answered_0', _("Answered messages")) ?></i>
     </td>
     <td class="item0" align="left" nowrap="nowrap">
      <input type="radio" id="flag_answered_1" name="search_flag[<?php echo IMP_SEARCH_FLAG_ANSWERED ?>]" value="1" <?php if (!empty($search['flag']) && $search['flag'][IMP_SEARCH_FLAG_ANSWERED] == 1) echo 'checked="checked" '; ?>/>
      <i><?php echo Horde::label('flag_answered_1', _("Unanswered messages")) ?></i>
     </td>
     <td class="item0" align="left" nowrap="nowrap">
      <input type="radio" id="flag_answered_2" name="search_flag[<?php echo IMP_SEARCH_FLAG_ANSWERED ?>]" value="2" <?php if (empty($search['flag']) || $search['flag'][IMP_SEARCH_FLAG_ANSWERED] == 2) echo 'checked="checked" '; ?>/>
      <i><?php echo _("Both") ?></i>
     </td>
     <td class="item0" width="100%">&nbsp;</td>
    </tr>

    <tr>
     <td class="item1" align="left" nowrap="nowrap">
      <input type="radio" id="flag_flagged_0" name="search_flag[<?php echo IMP_SEARCH_FLAG_FLAGGED ?>]" value="0" <?php if (!empty($search['flag']) && $search['flag'][IMP_SEARCH_FLAG_FLAGGED] == 0) echo 'checked="checked" '; ?>/>
      <i><?php echo Horde::label('flag_flagged_0', _("Important messages")) ?></i>
     </td>
     <td class="item1" align="left" nowrap="nowrap">
      <input type="radio" id="flag_flagged_1" name="search_flag[<?php echo IMP_SEARCH_FLAG_FLAGGED ?>]" value="1" <?php if (!empty($search['flag']) && $search['flag'][IMP_SEARCH_FLAG_FLAGGED] == 1) echo 'checked="checked" '; ?>/>
            <i><?php echo Horde::label('flag_flagged_1', _("Not important messages")) ?></i>
      </td>
     <td class="item1" align="left" nowrap="nowrap">
      <input type="radio" id="flag_flagged_2" name="search_flag[<?php echo IMP_SEARCH_FLAG_FLAGGED ?>]" value="2" <?php if (empty($search['flag']) || $search['flag'][IMP_SEARCH_FLAG_FLAGGED] == 2) echo 'checked="checked" '; ?>/>
      <i><?php echo _("Both") ?></i>
     </td>
     <td class="item1" width="100%">&nbsp;</td>
    </tr>

    <tr>
     <td class="item0" align="left" nowrap="nowrap">
      <input type="radio" id="flag_deleted_0" name="search_flag[<?php echo IMP_SEARCH_FLAG_DELETED ?>]" value="0" <?php if (!empty($search['flag']) && $search['flag'][IMP_SEARCH_FLAG_DELETED] == 0)echo 'checked="checked" '; ?>/>
      <i><?php echo Horde::label('flag_deleted_0', _("Deleted messages")) ?></i>
     </td>
     <td class="item0" align="left" nowrap="nowrap">
      <input type="radio" id="flag_deleted_1" name="search_flag[<?php echo IMP_SEARCH_FLAG_DELETED ?>]" value="1" <?php if (!empty($search['flag']) && $search['flag'][IMP_SEARCH_FLAG_DELETED] == 1) echo 'checked="checked" '; ?>/>
      <i><?php echo Horde::label('flag_deleted_1', _("Not deleted messages")) ?></i>
     </td>
     <td class="item0" align="left" nowrap="nowrap">
      <input type="radio" id="flag_deleted_2" name="search_flag[<?php echo IMP_SEARCH_FLAG_DELETED ?>]" value="2" <?php if (empty($search['flag']) || $search['flag'][IMP_SEARCH_FLAG_DELETED] == 2) echo 'checked="checked" '; ?>/>
      <i><?php echo _("Both") ?></i>
     </td>
     <td class="item0" width="100%">&nbsp;</td>
    </tr>
   </table>
  </td>
 </tr>

<?php if (!empty($search['mbox'])): ?>
 <input id="preselected_folders" type="hidden" name="search_folders[]" value="<?php echo $search['mbox'] ?>" />
<?php else: ?>
 <tr>
  <td class="smallheader" colspan="2" align="left"><b><?php echo _("Message folders") ?></b></td>
 </tr>

 <tr>
  <td class="item" colspan="2">
   <a href="#" onclick="toggleAll(true); return false;" onmouseover="status='<?php echo _("Select all") ?>'; return true;"><?php echo _("Select all") ?></a> |
   <a href="#" onclick="toggleAll(false); return false;" onmouseover="status='<?php echo _("Select none") ?>'; return true;"><?php echo _("Select none") ?></a>
<?php if ($subscribe): ?>
<?php $inverse_subscribe = ($shown == IMP_SEARCH_SHOW_UNSUBSCRIBED) ? IMP_SEARCH_SHOW_SUBSCRIBED_ONLY : IMP_SEARCH_SHOW_UNSUBSCRIBED; ?>
 | <a href="#" onclick="document.search.show_subscribed_only.value='<?php echo $inverse_subscribe ?>';document.search.submit(); return false;" onmouseover="status='<?php echo ($inverse_subscribe) ? _("Show Only Subscribed Folders") : _("Show All Folders")?>';return true;"><?php echo ($inverse_subscribe) ? _("Show Only Subscribed Folders") : _("Show All Folders") ?></a>
<?php endif; ?>
  </td>
 </tr>

 <tr>
  <td class="control" valign="top" align="center" colspan="2">
   <table cellspacing="0" cellpadding="2" width="100%">
    <tr>
     <td class="item" valign="top" align="left">
      <?php echo $folderlist ?>
     </td>
    </tr>
   </table>
  </td>
 </tr>
<?php endif; ?>

 <tr>
  <td class="smallheader" colspan="2" align="left"><b><?php echo _("Virtual Folders") ?></b></td>
 </tr>

 <tr>
  <td class="item" colspan="2">
   <table cellspacing="0" cellpadding="0" width="100%">
<?php if ($create_vfolder): ?>
    <input type="hidden" name="create_vfolder" value="1" />
    <input type="hidden" name="save_vfolder" value="1" />
<?php elseif ($edit_vfolder): ?>
    <input type="hidden" name="edit_vfolder" value="1" />
    <input type="hidden" name="edit_vfolder_id" value="<?php echo $edit_vfolder_id ?>" />
    <input type="hidden" name="save_vfolder" value="1" />
<?php else: ?>
    <tr>
     <td class="item0" align="left" nowrap="nowrap">
      <i><?php echo _("Save search as a virtual folder?") ?></i>&nbsp;<input type="checkbox" id="save_vfolder" name="save_vfolder" <?php if (!empty($search['save_vfolder'])) echo 'checked="checked" '; ?>/>
     </td>
    </tr>
<?php endif; ?>
    <tr>
     <td class="item1" align="left" nowrap="nowrap">
      <i><?php echo _("Virtual folder label") ?>:</i>&nbsp;<input type="text" id="vfolder_label" name="vfolder_label" <?php if (!empty($search['vfolder_label'])) echo 'value="' . $search['vfolder_label'] . '" '; ?>/>
     </td>
    </tr>
   </table>
  </td>
 </tr>

 <tr>
  <td valign="top" colspan="2">
   <input type="submit" class="button" value="<?php echo $submit_label ?>" onclick="return formCheck();" />
   <input type="button" class="button" value="<?php echo _("Reset") ?>" onclick="document.search.actionID.value = 'reset_search';document.search.submit();return true;" />
  </td>
 </tr>
</table>
</div>
</form>
