<& /_elements/header, title => _('Calendar'_ &>
<body class="calpopup">

<a href="#" onclick="window.close(); return false;"><% _('Close window')%></a>

<div class="calendar">
  <table>
    <caption>
      <a class="prev" href="calendar.html?DisplayedMonth=<%$prev_month%>&DisplayedYear=<%$prev_year%>&field=<%$field%>">Prev</a>
      <span class="month"><% $months[$DisplayedMonth-1] %> <% _($DisplayedYear) %></span>
      <a class="next" href="calendar.html?DisplayedMonth=<%$next_month%>&DisplayedYear=<%$next_year%>&field=<%$field%>">Next</a>
    </caption>
    <tr>
% foreach my $wday (@weekdays) {
      <th><%_($wday)%></th>
% }
    </tr>
% foreach my $week (@cal) {
    <tr>
%     foreach my $day (@{$week}) {
      <td>
%         if ($day) {
%             my $datestr = sprintf('%04d-%02d-%02d', $DisplayedYear, $DisplayedMonth, $day);
        <a href="#" onclick="Jifty.Utils.updateParentField('<% $field %>','<% $datestr %>'); return false;"><% $day %></a>
%         } else {
        &nbsp;
%         }
      </td>
%     } #foreach $day
    </tr>
% } # foreach $week
  </table>
  <span class="calendar today">
%             my $datestr = sprintf('%04d-%02d-%02d', $today[5]+1900,$today[4]+1, $today[3]);
        <a href="#" onclick="Jifty.Utils.updateParentField('<% $field %>','<% $datestr %>'); return false;">Today</a>
  
  </span>
  <span class="calendar tomorrow">
% my @tomorrow = localtime(time()+86400);
% $datestr = sprintf('%04d-%02d-%02d', $tomorrow[5]+1900,$tomorrow[4]+1, $tomorrow[3]);
        <a href="#" onclick="Jifty.Utils.updateParentField('<% $field %>','<% $datestr %>'); return false;">Tomorrow</a>
  </span>
</div>
</div>
</body>
</html>
% $m->abort();
<%init>
my @today = localtime(time());

my @weekdays;
push @weekdays, $_
  for qw(Sun Mon Tue Wed Thu Fri Sat);

my @months;
push @months, $_
  for qw(January February March April May June July August
         September October November December);

unless ($DisplayedYear) {
    $DisplayedMonth = $today[4] + 1;
    $DisplayedYear  = ($today[5] + 1900);
}

my ($prev_year, $next_year, $prev_month, $next_month);
$prev_month = $next_month = $DisplayedMonth;
$prev_year  = $next_year  = $DisplayedYear;

$next_month++;
$prev_month--;

if ($DisplayedMonth == 12) {
    $next_year++;
    $next_month = 1;
}
elsif ($DisplayedMonth == 1) {
    $prev_month = 12;
    $prev_year--;
}

use Calendar::Simple;
my @cal = Calendar::Simple::calendar($DisplayedMonth, $DisplayedYear);
</%init>

<%args>
$field => 'none'
$DisplayedMonth => undef
$DisplayedYear => undef
</%args>
