<% #top %>
<tr>
<td align="right" valign="baseline" class="small"><% param.position %></td>
<td align="right" valign="baseline"><% story.requests %></td>
<td valign="baseline"><% story.created "yyyy-MM-dd" %></td>
<td valign="baseline"><% story.title | story.link %></td>
<td valign="baseline"><% story.creator %></td>
</tr>

<% #listItem %>
<div class="listSeparator"> </div>
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<% if <% story.status %> is closed then 
   '<td rowspan="2" width="10" align="center" valign="top" nowrap="nowrap" 
   class="listFlag">c<br />l<br />o<br />s<br />e<br />d</td>
   <td rowspan="2" width="5" nowrap="nowrap"></td>' 
else <% if <% story.mode %> is hidden then 
   '<td rowspan="2" width="10" align="center" valign="top" nowrap="nowrap" 
   class="listFlag">h<br />i<br />d<br />d<br />e<br />n</td>
   <td rowspan="2" width="5" nowrap="nowrap"></td>' %>
%>
<td class="small">
   <strong><% gettext Macro suffix=: %></strong> <% story.macro %><br />
   <div class="ample"><strong><% gettext Status suffix=: %></strong>
   <% story.status %><% story.tags link prefix=" in " %>,
   <% story.comments link %></div>
</td>
<td rowspan="2" width="10" nowrap="nowrap"> </td>
<td valign="bottom" rowspan="2" align="right" class="small">
   <% story.link edit prefix="... " suffix="<br />" %>
   <% story.link . <% gettext Show %> prefix="... " suffix="<br />" %>
   <% story.link rotate prefix="... " suffix="<br />" %>
   <% story.link delete prefix="... " %>
</td>
</tr>
<tr valign="top">
<td>
   <div class="storyTitle"><% story.title %></div>
   <div class="storyDate"><% gettext "{0} on {1}" <% story.creator link %>
   <% story.created short %> %></div>
   <% story.text | clip %>
</td>
</tr>
</table>

<% #backlink %>
referrers.push(new Antville.Referrer("<% param.referrer %>", 
      "<% param.text %>", <% param.requests %>));

<% #backlinks %>
<a name="backlinks" id="backlinks"></a><br />
<table border="0" cellspacing="0" cellpadding="1">
<script type="text/javascript"><!--
var referrers = [];
<% param.referrers %>
var query = new Antville.Query();
var spamFilter = new Antville.Filter([<% site.spamfilter %>]);
var searchFilter = new Antville.Filter(query.filter);
var searchEngineFilters = [
   new Antville.Filter("http:\/\/.*google.*\?", "q"),
   new Antville.Filter("http:\/\/.*search\.msn.*\?", "q"),
   new Antville.Filter("http:\/\/.*altavista.*\?", "q"),
   new Antville.Filter("http:\/\/.*search\.yahoo.*\?", "p"),
];
var cnt = 0;
var prefix = "<em>Search request:</em> ";
for (var i in referrers) {
   var ref = referrers[i];
   var text = ref.text;
   if (spamFilter.test(ref.url)) {
      continue;
   }
   if (query.filter && !searchFilter.test(ref.url)) {
      continue;
   }
   for (var e in searchEngineFilters) {
      var filter = searchEngineFilters[e];
      if (filter.test(ref.url)) {
         text = ref.compose(filter.key, prefix);
         break;
      }
   }
   if (++cnt == 1) {
      document.writeln('<tr>');
      document.writeln('<td align="right" class="small">&nbsp;</td>');
      document.writeln('<td rowspan="999" class="small">&nbsp;&nbsp;</td>');
      document.writeln('<td class="small"><strong>Backlinks</strong></td>');
      document.writeln('</tr>');
   }
   document.writeln('<tr>');
   document.writeln('<td align="right" valign="top" class="small">', 
         ref.count, '</td>');
   document.writeln('<td class="small"><a href="', ref.url, '">', 
         text, '</a></td>');
   document.writeln('</tr>');
}
//--></script>
<noscript>
<tr>
<td colspan="3">
<% site.skin $Site#noscript %>
</td>
</tr>
</noscript>
</table>

<% #restore %>
<script type="text/javascript">
<!--
$(function() {
   if (!"<% session.backup %>") {
      $("#restore").hide();
   } else {
      $("#restore").click(function() {
         $("#title").val(decodeURIComponent("<% session.backup.title %>"));
         $("#text").val(decodeURIComponent("<% session.backup.text %>"));
         $(this).hide();
         return;
      });
   }
   
   var currentTitle, currentText;
   $(".backup > :input").blur(function() {
      var title = $.trim($("#title").val());
      var text = $.trim($("#text").val());
      if ((title || text) && (currentTitle || currentText) && 
            (currentTitle !== title || currentText !== text)) {
         $.ajax({
            async: true,
            type: "POST",
            url: '<% root.href backup.js %>',
            data: {title: encodeURIComponent(title),
                  text: encodeURIComponent(text)},
            dataType: "json"
         });
      }
      currentTitle = title;
      currentText = text
      return;;
   });
   return;
});
//-->
</script>
