[% currentPage = 'search.html' %]
[% currentPageTitle = 'Search' %]
[% q = modwheel.getParam('q')  %]
[% offset = modwheel.getParam('offset') %]
[% limit = modwheel.getParam('limit')   %]
[% baseoffset = limit %]
[% DEFAULT limit  = 10 %]
[% DEFAULT offset = 0 %]

[% INCLUDE header.html %]
<h1>Search</h1>
<div id="search">
<p>
    <form id="frmSearch" action="search.html">
    <input type="text" autocomplete="off" style="Width: 500px" id="txtSearch" name="q" alt="Search Criteria" value="[% q %]" autocomplete="off" />
    <input type="submit" id="cmdSearch" name="cmdSearch" value="Search" alt="Run Search" />
    <br />
    <div class="autocompleteContainer">
        <div id="autocomplete" class="autocomplete"></div>
    </div>
    </form>
</p>
</div>
[% IF q %]
    [% results = modwheel.search(q, limit, offset, 1, 0) %]
    [% c = modwheel.lastRowCount() %]
    <h2>A search for '[% q %]' yielded [% c %] result(s).</h2>
    <p id="nextResult">
        [% pages = c / limit %]
        [% pages = modwheel.ceil(pages) %]
        <b>[</b>
        [% FOREACH p = [ 1..pages ] %]
            <a href="[% currentPage %]?q=[% q %]&limit=[% limit %]&offset=[% limit * (p - 1) %]">[% p %]</a>
            [% UNLESS p >= pages %] | [% END %]
        [% END %]
        <b>]</b>
    </p>
    <p id="results">    
    [% FOREACH result = results %]
        <div id="resultName">
            [% IF result.type == 'directory' %]
             <a href="editDir.html?id=[%result.id %]">[% result.name %]</a>
            [% ELSIF result.type == 'article' %]
             <a href="edit.html?id=[% result.id %]">[% result.name %]</a>
            [% END %]
        </div>

        <div id="resultPath">-&gt;
            <a href="index.html?parent=[% result.parent %]">[% modwheel.objectPath(result.parent) %]</a>
        </div>

        [% IF result.description %]
            [% description = modwheel.striptags(result.description) %]
            <div id="resultDescription">[% modwheel.abbreviate(description, 250) %]</div>
        [% ELSIF result.data %]
            [% data = modwheel.striptags(result.data) %]
            <div id="resultDescription">[% modwheel.abbreviate(data, 250) %]</div>
        [% END %]

        [% objtags = modwheel.getTagsForObject(result.id) %]
        [% IF objtags %]
            <div id="resultTags"><b>Tags:</b>
            [% FOREACH thistag = objtags %]
                [% thistag.name %],
            [% END %]
            <br />
        [% END %]
        <br />
    [% END %]
    </p>
    <p id="nextResult">
        [% pages = c / limit %]
        [% pages = modwheel.ceil(pages) %]
        <b>[</b>
        [% FOREACH p = [ 1..pages ] %]
            <a href="[% currentPage %]?q=[% q %]&limit=[% limit %]&offset=[% limit * (p - 1) %]">[% p %]</a>
            [% UNLESS p >= pages %] | [% END %]
        [% END %]
        <b>]</b>
    </p>
[% END %]

[% INCLUDE footer.html %]
