[% up = 0; disabled = 0; down = 0; %]
[% BLOCK site %]
    <div class='backend' style="[% style %]">
      [% SET name  = 'unknown'                                         %]
      [% SET name = backend_detail.$pd.name IF backend_detail.$pd.name %]

      [% SET class = 'button_peerDOWN'                                    %]
      [% SET class = 'button_peerUP'  IF backend_detail.$pd.running       %]
      [% SET class = 'button_peerDIS' IF backend_detail.$pd.disabled == 2 %][%# hidden by user #%]
      [% SET class = 'button_peerHID' IF backend_detail.$pd.disabled == 3 %][%# hidden by backend param #%]
      [% SET class = 'button_peerHID' IF param_backend && pd != param_backend %]
      [% SET class = 'button_peerDIS' IF backend_detail.$pd.disabled == 6 %]
      [% SET class = 'button_peerUP'  IF backend_detail.$pd.disabled == 7 %]
      <input type="button"[%IF use_id == 1 %] id='button_[% pd %]'[% END %] class="[% class %]" value="[% name %]" title="[% IF backend_detail.$pd.last_error %][% escape_js(backend_detail.$pd.last_error) %][% ELSE %][% name %][% END %]" onMouseOver="button_over(this)" onMouseOut="button_out(this)"[% IF backend_detail.$pd.disabled == 5 %] disabled[% ELSE %] onClick="[% onclick %]"[% END %]>
      [% IF class == 'button_peerUP'   %][% up       = up       + 1 %][% END %]
      [% IF class == 'button_peerHID'  %][% disabled = disabled + 1 %][% END %]
      [% IF class == 'button_peerDIS'  %][% disabled = disabled + 1 %][% END %]
      [% IF class == 'button_peerDOWN' %][% down     = down     + 1 %][% END %]
    </div>
[% END %]

<table border=0 cellpadding=0 cellspacing=0>
  <tr>
    <td>
    [% IF hide_backends_chooser == 0 && ( c.db.sections.keys.size > 1 || backends.size >= 10 ) %]
      [% popup = BLOCK %]
      <div id="site_panel" style="display: none;">
      <div class="shadow"><div class="shadowcontent">
      <table class="site_panel" cellspacing=0 cellpadding=0 width="100%">
        <tr>
            <th colspan=2>Choose your sites</th>
        </tr>
        <tr>
            [% FOREACH section IN c.db.sections.keys.sort %]
            <th class="site_panel [% UNLESS loop.first %]notfirst[% END %]">
                [% section %]
            </th>
            [% END %]
        </tr>
        <tr>
            [% FOREACH section IN c.db.sections.keys.sort %]
            <td valign="top" class="site_panel[% UNLESS loop.first %] notfirst[% END %]">
            <table cellpadding=0 cellspacing=0 border=0><tr>
            <td valign="top">
            [% count = 0 %]
            [% FOREACH bname IN c.db.sections.$section.keys.sort %]
                [% FOREACH p IN c.db.sections.$section.$bname %]
                [% pd = p.key %]
                [% PROCESS site style="clear: both;" onclick="toggleBackend('" _ pd _ "')" use_id=1 %]
                [% count = count + 1 %]
                [% IF count > 15 %][% count = 0 %]</td><td valign="top">[% END %]
                [% END %]
            [% END %]
            </td>
            </tr></table>
            </td>
            [% END %]
        </tr>
      </table>
      </div></div>
      </div>
      [% END %]
      [% IF backend_chooser == 'switch' && param_backend %]
        [% PROCESS site style="" pd=param_backend onclick="toggleSitePanel()" use_id=0 %]
      [% ELSE %]
        <div class='backend'><input type="button" class="[% IF up > 0 %]button_peerUP[% ELSE %]button_peerDIS[% END %]" value="[% up %] up"         onMouseOver="button_over(this)" onMouseOut="button_out(this)" onClick="toggleSitePanel()"></div>[%
      %]<div class='backend'><input type="button" class="button_peerDIS" value="[% disabled %] disabled"                                            onMouseOver="button_over(this)" onMouseOut="button_out(this)" onClick="toggleSitePanel()"></div>[%
      %]<div class='backend'><input type="button" class="[% IF down > 0 %]button_peerDOWN[% ELSE %]button_peerDIS[% END %]" value="[% down %] down" onMouseOver="button_over(this)" onMouseOut="button_out(this)" onClick="toggleSitePanel()"></div>
      [% END %]
      [% popup %]

    [% ELSIF hide_backends_chooser == 0 && backends.size > 1 %]
      [% FOREACH pd IN backends %]
        [% PROCESS site style="" onclick="toggleBackend('" _ pd _ "')" use_id=1 %]
      [% END %]
    [% END %]
    </td>
  </tr>
</table>
