# -*-s2-*-

layerinfo type = "layout";
layerinfo name = "Tabular Indent";
layerinfo redist_uniq = "tabularindent/layout";
layerinfo previews = "tabularindent/tabularindent.jpg";
layerinfo des = "Two information and navigation boxes at the top and bottom of the page surround entries indented slightly from the left.";

propgroup presentation {
  property string content_width {
      des = "Content area width";
      note = "Don't forget to include units; e.g. px, %";
  }
  property string content_alignment {
      des = "Alignment of the content area";
      values = "left|Left|center|Center|right|Right";
  }
  property string content_top_margin {
      des = "Margin size on the top of the content area";
      note = "You can use this to shift your journal contents down in order to display a background image at the top of your journal.  Don't forget to include units; e.g. px, %";
  }
  property string entryborder_size {
      des = "Size of borders around entries";
      note = "Don't forget to include the units, e.g. px";
  }
  property string entryborder_style {
      des = "Style of borders around entries";
      values = "solid|Solid|dashed|Dashed|dotted|Dotted|double|Double|hidden|Invisible";
  }
  property bool transparent {
      des = "Make journal content transparent instead of using given background colors";
  }
  property bool show_entry_userpic {
      des = "Display your userpic with your entries";
  }
  property use page_recent_items;
  property use page_friends_items;
  property use use_shared_pic;
  property use view_entry_disabled;
  property use linklist_support;
  property use external_stylesheet;
  property string counter_code {
      des = "If you have an external web counter, you can enter the HTML for it here";
      note = "Your counter will appear at the bottom of the header at the top of your journal.";
      maxlength = 2000;
      string_mode = "html-oneline";
  }
  property use custom_control_strip_colors;
}
set content_width = "100%";
set content_alignment = "left";
set content_top_margin = "0";
set entryborder_size = "";
set entryborder_style = "hidden";
set transparent = false;
set show_entry_userpic = true;
set page_recent_items = 20;
set page_friends_items = 20;
set view_entry_disabled = false;
set counter_code = "";

propgroup colors {
  property Color body_bgcolor {
      des = "Body background color";
      s1color = "page_back";
  }
  property Color main_bgcolor {
      des = "Background of main text areas";
      s1color = "page_back";
  }
  property Color main_fgcolor {
      des = "Main text color";
      s1color = "page_text";
  }
  property Color border_color {
      des = "Color of borders";
      # No s1color equivalent
  }
  property Color border_color_entries {
      des = "Color of borders around entries";
  }
  property Color headerbar_bgcolor {
      des = "Background color of header bar(s)";
      s1color = "stronger_back";
  }
  property Color headerbar_fgcolor {
      des = "Header bar text color";
      s1color = "stronger_text";
  }
  property Color captionbar_mainbox_bgcolor {
      des = "Main background color of caption bar";
      s1color = "page_back";
  }
  property Color captionbar_mainbox_fgcolor {
      des = "Text color of caption bar";
      s1color = "page_text";
  }
  property Color captionbar_userpicbox_color {
      des = "User picture background color of caption bar";
      s1color = "strong_back";
  }
  property Color accent_bgcolor {
      des = "Background color of accented areas";
      s1color = "weak_back";
  }
  property Color accent_fgcolor {
      des = "Accented area text color";
      s1color = "weak_text";
  }
  property Color link_color {
      des = "Link color";
      s1color = "page_link";
  }
  property Color vlink_color {
      des = "Visited link color";
      s1color = "page_vlink";
  }
  property Color alink_color {
      des = "Active link color";
      s1color = "page_alink";
  }
  property Color comment_bar_one_bgcolor {
      des = "Alternating background color for comment bars (one)";
  }
  property Color comment_bar_two_fgcolor {
      des = "Text color on alternating comment bars (one)";
  }
  property Color comment_bar_two_bgcolor {
      des = "Alternating background color for comment bars (two)";
  }
  property Color comment_bar_one_fgcolor {
      des = "Text color on alternating comment bars (two)";
  }
  property Color comment_bar_screened_bgcolor {
      des = "Background bar color for screened comments";
  }
  property Color comment_bar_screened_fgcolor {
      des = "Text color on background bar for screened comments";
  }
  property use control_strip_bgcolor;
  property use control_strip_fgcolor;
  property use control_strip_bordercolor;
  property use control_strip_linkcolor;
}
set body_bgcolor = "#ffffff";
set main_bgcolor = "#ffffff";
set main_fgcolor = "#000000";
set border_color = "#000000";
set border_color_entries = "#000000";
set headerbar_bgcolor = "#6666cc";
set headerbar_fgcolor = "#ffffff";
set captionbar_mainbox_bgcolor = "#ffffff";
set captionbar_mainbox_fgcolor = "#000000";
set captionbar_userpicbox_color = "#c0c0ff";
set accent_bgcolor = "#eeeeff";
set accent_fgcolor = "#000000";
set link_color = "#000050";
set vlink_color = "#500050";
set alink_color = "#ff00c0";
set comment_bar_one_bgcolor = "#c0c0ff";
set comment_bar_one_fgcolor = "#000000";
set comment_bar_two_bgcolor = "#eeeeff";
set comment_bar_two_fgcolor = "#000000";
set comment_bar_screened_bgcolor = "#dddddd";
set comment_bar_screened_fgcolor = "#000000";

propgroup images {
  property string page_background_image {
      des = "Background image URL";
  }

  property string page_background_repeat {
      des = "Background image repeat";
      values = "repeat|Repeat|no-repeat|Don't repeat|repeat-x|Repeat across only|repeat-y|Repeat down only";
  }

  property string page_background_position {
      des = "Background image position";
      note = "Does not apply if Background Image Repeat is set to 'Repeat'.";
      values = "top|Top|top left|Top-left|top right|Top-right|center|Center|center left|Center-left|center right|Center-right|bottom|Bottom|bottom left|Bottom-left|bottom right|Bottom-right|left|Left|right|Right";
  }

  property string page_background_scrolling {
      des = "Background image scrolling";
      note = "Not supported in all browsers, but allows for the background image to be in a fixed position when scrolling.";
      values = "scroll|Scroll|fixed|Fixed";
  }
  property string img_btwn_comments {
      des = "URL to an image to be used between your comment links";
      note = "If you specify an image to use, it will replace any text between the comment links.";
  }
}
set page_background_image = "";
set page_background_repeat = "repeat";
set page_background_position = "center";
set page_background_scrolling = "scroll";
set img_btwn_comments = "";

propgroup text {
  property use text_post_comment;
  property use text_read_comments;
  property use text_post_comment_friends;
  property use text_read_comments_friends;
  property string text_left_comments {
        des = "Text to be used in front of your comment links";
  }
  property string text_btwn_comments {
        des = "Text to be used between your comment links";
        note = "If you specified an image to be used between your comments links in the \"Images\" section, then this option will not have any effect.";
  }
  property string text_right_comments {
        des = "Text to be used at the end of your comment links";
  }
  property string date_format {
        des = "Date format for entries";
  }
  property string time_format {
        des = "Time format for entries";
  }
  property string datetime_comments_format {
        des = "Date and time format for comments";
  }
  property string date_monthpage_format {
        des = "Month format for the month page";
  }
}
set text_left_comments = "comments: ";
set text_btwn_comments = " or ";
set text_right_comments = "";
set date_format = "%%month%% %%dayord%%, %%yyyy%%";
set time_format = "%%hh%%:%%min%% %%a%%m";
set datetime_comments_format = "%%yyyy%%-%%mm%%-%%dd%% %%hh%%:%%min%% %%a%%m";
set date_monthpage_format = "%%month%% %%yyyy%%";

propgroup customcss {
  property use include_default_stylesheet;
  property use linked_stylesheet;
  property use custom_css;
}

set tags_aware = true;

function prop_init () {
    if ($*control_strip_bgcolor.as_string == "") {
        $*control_strip_bgcolor = $*main_bgcolor;
    }
    if ($*control_strip_fgcolor.as_string == "") {
        $*control_strip_fgcolor = $*main_fgcolor;
    }
    if ($*control_strip_bordercolor.as_string == "") {
        $*control_strip_bordercolor = $*border_color;
    }
    if ($*control_strip_linkcolor.as_string == "") {
        $*control_strip_linkcolor = $*link_color;
    }

    $*theme_bgcolor = $*main_bgcolor;
    $*theme_fgcolor = $*main_fgcolor;
    $*theme_bordercolor = $*border_color;
    $*theme_linkcolor = $*link_color;
}

function Page::lay_captionbar_navigation () { }

function Page::print_linklist() {
    if (size $.linklist <= 0) {
        return;
    } elseif (not $*linklist_support) {
        return;
    }

    var string linklist = "";
    var string link = "";
    var bool section_open = false;
    var bool first = true;

    foreach var UserLink l ($.linklist) {
        if ($l.title) {
            if ($l.is_heading or $first) {
                if ($section_open) {
                    $linklist = $linklist + "</td></tr>";
                }
                if ($l.is_heading) {
                    $link = "<tr><td>$l.title:</td><td>";
                } else {
                    $link = "<tr><td>View:</td><td><a href='$l.url'>$l.title</a>. ";
                }
                $section_open = true;
                $first = false;
            } else {
                $link = "<a href='$l.url'>$l.title</a>. ";
            }
        } else {
            $link = """<tr><td>&nbsp;</td></tr>""";
        }
        $linklist = $linklist + $link;
    }
    if ($linklist != "") {
        "$linklist" + "</td></tr>";
    }
}

function captionbar (Page p, bool top) {
    var string title = $p->title();

    var string userpic;
    var Image up_img = $p.journal.default_pic;
    if (defined $up_img) {
        $userpic = """<img src="$up_img.url" height="$up_img.height" width="$up_img.width" alt="[icon]" />""";
    }

    var string website_name = $p.journal.website_name ? $p.journal.website_name : $*text_website_default_name;
    var string website;
    if ($p.journal.website_url != "") {
        $website = """<tr><td>View:</td><td><a href="$p.journal.website_url">Website ($website_name)</a>.</td></tr>""";
    }

    var string links;
    foreach var string v ($p.views_order) {
        $links = "$links<tr><td>View:</td><td>" + ($p.view == $v ?
                           lang_viewname($v) :
                           "<a href='$p.view_url{$v}'>"+lang_viewname($v)+"</a>") + ".</td></tr>\n";
    }

    var string captionbar_userpicbox_style = "background-color: $*captionbar_userpicbox_color";
    """
<table height='100' class='captionbar' cellpadding='5' cellspacing='1'><tr>
  <td class="captionbar-userpicbox" align='center' valign='center' width='100' style='$captionbar_userpicbox_style'>$userpic</td>
    """;
    print safe "<td><b>$title</b><br />";
    """
    <table border='0'>
      $links
      $website""";
      $p->print_linklist();
      """
      <tr>
        <td colspan='2'>""";

    $p->lay_captionbar_navigation();
    if ($top and $*counter_code != "") {
        """<br />$*counter_code""";
    }
    "
        </td>
      </tr>
    </table>
  </td>
</tr></table>";
}

function captionbar (Page p) {
    captionbar($p, false);
}

function print_stylesheet ()
{
    if(clean_url($*page_background_image) != "") {
      """body {
    background-image: url("$*page_background_image");
    background-position: $*page_background_position;
    background-repeat: $*page_background_repeat;
    background-attachment: $*page_background_scrolling;
}""";
    }
    """/* Tabular Indent Stylesheet */
body {
    background-color:  $*body_bgcolor;
}
.captionbar {
    width:             100%;
    border:            1px solid $*border_color;
}
.captionbar, .captionbar td {
    background-color:  $*captionbar_mainbox_bgcolor;
    color:             $*captionbar_mainbox_fgcolor;
}
.captionbar-userpicbox {
    border-right:      1px solid $*border_color;
    background-color:  $*captionbar_userpicbox_color;
    color:             $*captionbar_mainbox_fgcolor;
}
body,td,p {
    font-family:       verdana, arial, helvetica, sans-serif;
    font-size:         8pt;
}
a {
    color:             $*link_color;
    font-family:       verdana, arial, helvetica, sans-serif;
    font-size:         8pt;
    text-decoration:   none;
}
a:visited {
    color:             $*vlink_color;
    font-family:       verdana, arial, helvetica, sans-serif;
    font-size:         8pt;
    text-decoration:   none;
}
a:active {
    color:             $*alink_color;
    font-family:       verdana, arial, helvetica, sans-serif;
    font-size:         8pt;
    text-decoration:   none;
}
a:hover {
    color:             $*alink_color;
    font-family:       verdana, arial, helvetica, sans-serif;
    font-size:         8pt;
    text-decoration:   underline;
}
h3.page-header {
    font-size:         8pt;
    font-family:       verdana, arial, helvetica, sans-serif;
    font-weight:       normal;
    background-color:  $*headerbar_bgcolor;
    color:             $*headerbar_fgcolor;
    padding: 6px;
    border:            1px solid $*border_color;
}
""";
if ($*transparent) {
"""
table table, tr, td, h3.page-header, .captionbar {
    background: transparent !important;
    border: 0 !important;
}
""";
}

print_custom_control_strip_css();
}

function Page::print ()
{
    var string margin = "";
    if ($*content_top_margin != "0") {
        $margin = """<table style="width: $*content_width; margin-top: $*content_top_margin;" align="$*content_alignment">""";
    }

    var string title = $this->title();
    println "<html>\n<head>\n";

    $this->print_head();
    $this->print_stylesheets();
    print safe """<title>$title</title>
 </head>
 <body>
    """;

    $this->print_control_strip();
    if ($margin == "") {
        print safe """<table style="width: $*content_width;" align="$*content_alignment">""";
    } else {
        print safe $margin;
    }
    "<tr><td>";
    "<p>"; captionbar($this, true); "</p>";

    if (viewer_sees_vbox()) {
        """<table width="100%" height="100%">""";
        """<tr><td valign="top">""";
    }
    if (viewer_sees_hbox_top()) {
        """<div style="text-align: center;">""";
        $this->print_hbox_top();
        "</div>";
    }

    "<p>"; $this->print_body(); "</p>";

    if (viewer_sees_vbox()) {
        "</td>";
        "<td valign=\"top\" align=\"center\" width=\"20%\">";
        $this->print_vbox();
        "</td></tr></table>\n";
    }
    if (viewer_sees_hbox_bottom()) {
        """<div style="text-align: center;">""";
        $this->print_hbox_bottom();
        "</div>";
    }

    "<p>"; captionbar($this); "</p>";
    "</td></tr></table>";

    """
  </body>
</html>
    """;
}

function print_box_open (string{} colors, string metapic, string{} meta, string domid) {
    var string bgcolor = $colors{"bgcolor"};
    var string fgcolor = $colors{"fgcolor"};
    if ($domid != "") { $domid = "id='"+ehtml($domid)+"'"; }

    var string style = "background-color: "+ehtml($bgcolor)+"; color: "+ehtml($fgcolor)+";";
    var string border = " border: $*entryborder_size $*entryborder_style $*border_color_entries;";
    print safe "<div align='right'><table $domid width='95%' cellpadding='5' cellspacing='1' style='$style$border'>";
    print safe "<tr><td><table border='0' width='100%' style='$style'><tr>";

    if ($metapic) {
        print safe "<td width='100' valign='top' align='center'>$metapic</td>";
    }

    print safe "<td valign='top'><table border='0' style='$style'>";

    foreach var string k ($meta) {
        var string key = $k;
        var string val = $meta{$k};
        print safe "<tr><td align='right'>$key</td><td>$val</td></tr>";
    }

    "</table></td></tr></table></td></tr>";
    print safe "<tr><td style='background-color: $*main_bgcolor; color: $*main_fgcolor'>";
}

function print_box_close (string footer) {
    "</td></tr>";

    if ($footer) {
        print safe "<tr><td style='white-space: nowrap'>$footer</td></tr>";
    }

    "</table></div><br />";
}
function print_box (string{} colors, string metapic, string{} meta, string content, string footer, string domid) {
    print_box_open($colors, $metapic, $meta, $domid);
    print safe $content;
    print_box_close($footer);
}

function print_header (string header)
{
    print safe "<h3 class='page-header'>$header</h3>";
}

function print_genericbox_open () {
    print safe "<div align='right'><table border='0' width='95%' cellpadding='5' cellspacing='1' bgcolor='$*accent_bgcolor'>";
    print safe "<tr><td style='background-color: $*main_bgcolor; color: $*main_fgcolor'>";
}

function print_genericbox_close ()
{
    "</td></tr></table></div><br />";
}

function print_entry (Page p, Entry e, Color bgcolor, Color fgcolor, bool hide_text)
{
    var string{} colors; var string{} meta; var string footer = "";
    $colors{"bgcolor"} = "$*accent_bgcolor";
    $colors{"fgcolor"} = "$*accent_fgcolor";
    if ($p.view == "recent") {
        if ($e.new_day) {
            print_header($e.time->date_format($*date_format));
        }
    } else {
        print_header($e.time->date_format($*date_format));
    }
    # Userpic
    var string metapic = "";
    if ($p.view == "friends" or
        $*show_entry_userpic == true or
        $e.journal.username != $e.poster.username)
    {
        var string userpic = defined $e.userpic ? "<img src='$e.userpic.url' style='border: 0' />" : "";
        var string url = $e.journal->base_url() + "/";
        $metapic = "<div style='background-color: $bgcolor; color: $fgcolor;'>";
        $metapic = "$metapic <a href='$url'>$userpic</a>";
        if ($e.journal.username != $e.poster.username) {
            var string purl = $e.poster->base_url() + "/";
            $metapic = "$metapic<br />[<a href='$purl' style='color: $fgcolor;'>$e.poster.username</a>]";
        }
        if ($p.view == "friends") { $metapic = "$metapic<br /><a href='$url' style='color: $fgcolor;'>$e.journal.username</a>"; }
        $metapic = "$metapic</div>";
    }
    # Security Icon
    if ($e.security) {
        $meta{"Security:"} = "$e.security_icon $e.security";
    }
    # Subject
    if ($e.subject) {
        $meta{"Subject:"} = $e.subject;
    }
    # Time posted
    var string time = $e.time->time_format($*time_format);
    $meta{"Time:"} = $time;
    # Current
    if (size $e.metadata) {
        foreach var string k ($e.metadata) {
            var string key = $k; var string val = $e.metadata{$k};
            if ($k == "mood") {
                $key = $*text_meta_mood;
            } elseif ($k == "music") {
                $key = $*text_meta_music;
            } elseif ($k == "location") {
                $key = $*text_meta_location;
            }
            if ($k == "mood" and defined $e.mood_icon) {
                var Image i = $e.mood_icon;
                $val = "<img src='$i.url' width='$i.width' height='$i.height' align='absmiddle' alt='[mood icon]' /> $val";
            }
            $meta{"$key:"} = $val;
        }
    }
    # Tags
    if ($e.tags) {
        var int tcount = 0;
        var string tag;
        foreach var Tag t ($e.tags) {
            $tag = $tag + """<a rel="tag" href="$t.url">$t.name</a>""";
            $tcount++;
            if ($tcount != size $e.tags) { $tag = $tag + ", "; }
        }
        $meta{"Tags:"} = $tag;
    }

    if ($e.comments.show_readlink or $e.comments.show_postlink) {
        $footer = $footer + "$*text_left_comments";
        if ($e.comments.show_readlink) {
            $footer = $footer +
                      "<a href=\"$e.comments.read_url\">" +
                      get_plural_phrase($e.comments.count, $p.view == "friends" ? "text_read_comments_friends" : "text_read_comments") +
                      "</a>";
        }
        if ($e.comments.show_postlink and $e.comments.show_readlink) {
            if (clean_url($*img_btwn_comments) != "") {
                $footer = $footer + """ <img src="$*img_btwn_comments" alt="" /> """;
            } else {
                $footer = $footer + "$*text_btwn_comments";
            }
        }
        if ($e.comments.show_postlink) {
            if ($e.comments.maxcomments) {
                $footer = $footer + "$*text_max_comments";
            } else {
                $footer = $footer +
                          "<a href=\"$e.comments.post_url\">" +
                          ($p.view == "friends" ? $*text_post_comment_friends : $*text_post_comment) +
                          "</a>";
            }
        }
        $footer = $footer + "$*text_right_comments";
    }

    # Misc Links
    var Link link;
    if ($p.view == "entry")
    {
        $link = $e->get_link("nav_prev"); $footer = "$footer $link";
    }
    foreach var string link_key ($e.link_keyseq) {
        $link = $e->get_link($link_key);
        if(defined $link) {
            $footer = "$footer $link";
        }
    }
    if ($p.view == "entry")
    {
        $link = $e->get_link("nav_next"); $footer = "$footer $link";
    }

    # Print
    print_box_open($colors, $metapic, $meta, "");
    if (not $hide_text) { $e->print_text(); }
    print_box_close($footer);
}

function Page::print_entry (Entry e)
{
    print_entry($this, $e, null Color, null Color, false);
}

function FriendsPage::print_entry (Entry e) {
    var Friend f = $.friends{$e.journal.username};
    print_entry($this, $e, $f.bgcolor, $f.fgcolor, false);
}

function RecentPage::lay_captionbar_navigation()
{
    var string nav = "";
    if ($.nav.backward_url != "") {
        $nav = """<a href="$.nav.backward_url">back $.nav.backward_count entries</a>""";
    }
    if ($.nav.forward_url != "" and $.nav.backward_url != "") {
        $nav = "$nav or ";
    }
    if ($.nav.forward_url != "") {
        $nav = """$nav<a href="$.nav.forward_url">forward $.nav.forward_count entries</a>""";
    }
    print "You're looking at the latest ";
    print size $.entries;
    print ($.nav.skip > 0) ? " entries, after skipping $.nav.skip newer ones." :" entries.";
    if ($nav != "") { print "<br />Missed some entries?  Then simply jump $nav"; }
}

function RecentPage::print_body {
    foreach var Entry e ($.entries) {
        $this->print_entry($e);
        if ($e->viewer_sees_ebox()) {
            """<div align="center" style="margin-bottom: 10px;">""";
            $e->print_ebox();
            "</div>";
        }
    }
}

function FriendsPage::print_body {
    foreach var Entry e ($.entries) {
        $this->print_entry($e);
        if ($e->viewer_sees_ebox()) {
            """<div align="center" style="margin-bottom: 10px;">""";
            $e->print_ebox();
            "</div>";
        }
    }
}

function YearPage::print_body {
    print_header(string($.year));
    print_genericbox_open();
    foreach var YearMonth m ($.months) {
        $this->print_month($m);
    }
    print_genericbox_close();
}

function YearPage::lay_captionbar_navigation()
{
    $this->print_year_links();
}

function YearPage::print_year_links ()
{
    foreach var YearYear y ($.years) {
        if ($y.displayed) {
            "$y.year&nbsp;";
        } else {
            "<a href=\"$y.url\">$y.year</a>&nbsp;";
        }
    }
}

function YearPage::print_month(YearMonth m)
{
    if (not $m.has_entries) { return; }
    "<center><table border='1' cellpadding='4' width='80%'>";
    # Month header
    "<tr align='center'><td colspan='7' bgcolor='$*headerbar_bgcolor'>";
    "<font color='$*headerbar_fgcolor'><b>"; print $m->month_format(); "</b></font></td></tr>";
    # Weekdays
    "<tr align='center' bgcolor='$*accent_bgcolor'>";
    foreach var int d (weekdays()) {
        "<td><font color='$*accent_fgcolor'>"+$*lang_dayname_short[$d]+"</font></td>\n";
    }
    "</tr>";
    foreach var YearWeek w ($m.weeks) {
        $w->print();
    }
    "<tr align='center'><td colspan='7'><a href='$m.url'>View Subjects</a>";
    "</td></tr></table></center>";
}

function YearWeek::print () {
    "<tr>";
    if ($.pre_empty) { "<td colspan='$.pre_empty' bgcolor='$*accent_bgcolor'>&nbsp;</td>"; }
    foreach var YearDay d ($.days) {
        "<td valign='top'><b>$d.day</b>";
        "<div align='center'>";
        if ($d.num_entries) {
            """<a href="$d.url">$d.num_entries</a>""";
        } else {
            "&nbsp;";
        }
        "</div></td>";
    }
    if ($.post_empty) { "<td colspan='$.post_empty' bgcolor='$*accent_bgcolor'>&nbsp;</td>"; }
    "</tr>";
}

function DayPage::lay_captionbar_navigation()
{
    print "Missed some entries? Then simply jump to the <a href='$.prev_url'>previous day</a> or the <a href='$.next_url'>next day</a>.";
}

function DayPage::print_body ()
{
    if (not $.has_entries) {
        "<table border='0' width='100%' cellpadding='5' cellspacing='1' bgcolor='$*border_color'>";
        "<tr><td bgcolor='$*headerbar_bgcolor'><font color='$*headerbar_fgcolor'>";
        print $.date->date_format($*date_format);
        "</font></td></tr></table><br />";
        print "No journal entries for this day.";
    } else {
        foreach var Entry e ($.entries) {
            $this->print_entry($e);
            if ($e->viewer_sees_ebox()) {
                """<div align="center" style="margin-bottom: 10px;">""";
                $e->print_ebox();
                "</div>";
            }
        }
    }
}

function MonthPage::print_body {
    print_header($.date->date_format($*date_monthpage_format));
    print_genericbox_open();
    "<form method='post' action='$.redir.url'><center>";
    $.redir->print_hiddens();
    if ($.prev_url != "") { "[<a href='$.prev_url'>&lt;&lt;&lt;</a>]\n"; }
    if (size $.months > 1) {
        "<select name='redir_key'>\n";
        foreach var MonthEntryInfo mei ($.months) {
            var string sel;
            if ($mei.date.year == $.date.year and $mei.date.month == $.date.month) {
                $sel = " selected='selected'";
            }
            "<option value='$mei.redir_key'$sel>" + $mei.date->date_format($*lang_fmt_month_long) + "</option>";
        }
        "</select>\n<input type='submit' value='View' />";
    }
    if ($.next_url != "") { "\n[<a href='$.next_url'>&gt;&gt;&gt;</a>]\n"; }
    "</center></form>\n<dl>";
    foreach var MonthDay d ($.days) {
        if ($d.has_entries) {
            "<dt><a href=\"$d.url\"><b>";
            print lang_ordinal($d.day);
            "</b></a></dt>\n<dd>";
            $d->print_subjectlist();
            "</dd>\n";
        }
    }
    "</dl>\n";
    print_genericbox_close();
}

function EntryPage::print_body () {
        set_handler("unscreen_comment_#", [
                                           [ "style_bgcolor", "cmtbar#", "$*comment_bar_one_bgcolor", ],
                                           [ "style_color", "cmtbar#", "$*comment_bar_one_fgcolor", ],
                                           ]);
        set_handler("screen_comment_#", [
                                         [ "style_bgcolor", "cmtbar#", "$*comment_bar_screened_bgcolor", ],
                                         [ "style_color", "cmtbar#", "$*comment_bar_screened_fgcolor", ],
                                         ]);

    print_entry($this, $.entry, null Color, null Color, $.viewing_thread);
    if ($.entry.comments.enabled and $.comment_pages.total_subitems > 0)
    {
        $this->print_multiform_start();

        print_header("Comments:");
        if ($.comment_pages.total_subitems > 0) {
            $.comment_pages->print();
            $this->print_comments($.comments);
        }
        if ($this.multiform_on) {
            print_header("Mass Action:");

            print_genericbox_open();
            $this->print_multiform_actionline();
            print_genericbox_close();

            $this->print_multiform_end();
        }
    }
}

function EntryPage::print_comment_partial (Comment c) {
    var string poster = defined $c.poster ? $c.poster->as_string() : "<i>(Anonymous)</i>";
    var string subj = $c.subject != "" ? $c.subject : $*text_nosubject;
    print_genericbox_open();
    print "<a href='$c.permalink_url'>$subj</a> - $poster";
    print_genericbox_close();
}

function EntryPage::print_comment (Comment c) {
    var string{} colors; var string{} meta; var string footer = "";

    if ($c.screened) {
        $colors{"bgcolor"} = "$*comment_bar_screened_bgcolor";
        $colors{"fgcolor"} = "$*comment_bar_screened_fgcolor";
    } elseif ($c.depth % 2) {
        $colors{"bgcolor"} = "$*comment_bar_one_bgcolor";
        $colors{"fgcolor"} = "$*comment_bar_one_fgcolor";
    } else {
        $colors{"bgcolor"} = "$*comment_bar_two_bgcolor";
        $colors{"fgcolor"} = "$*comment_bar_two_fgcolor";
    }

    # Userpic
    var string poster = defined $c.poster ? $c.poster->as_string() : "<i>(Anonymous)</i>";
    var string metapic = "";
    if (defined $c.userpic and $*comment_userpic_style != "off")
    {
        var string userpic = defined $c.userpic ? "<img src='$c.userpic.url' style='border: 0' />" : "";
        $metapic = "$userpic<br />$poster";
    } else {
        $metapic = $poster;
    }

    # Subject
    var string sub_icon;
    if (defined $c.subject_icon) {
        $sub_icon = $c.subject_icon->as_string();
    }
    if ($c.subject or $sub_icon) {
        $meta{"Subject:"} = "$c.subject $sub_icon";
    }

    # Time posted
    $meta{"Time:"} = $c->time_display($*datetime_comments_format, "none");

    # Link
    $meta{"Link:"} = "(<a href='$c.permalink_url'>Link</a>)";

    # IP Address:
    if ($c.metadata{"poster_ip"}) {
        $meta{"IP Address:"} = $c.metadata{"poster_ip"};
    }

    if ($c.frozen) {
        $footer = "(Replies frozen) ";
    } else {
        $footer = "(<a href='$c.reply_url'>Reply to this</a>) ";
    }
    if ($c.parent_url != "") { $footer = "$footer (<a href='$c.parent_url'>Parent</a>) "; }
    if ($c.thread_url != "") { $footer = "$footer (<a href='$c.thread_url'>Thread</a>) "; }

    var Link link = new Link;
    foreach var string k ($c.link_keyseq) {
        $link = $c->get_link($k);
        if (defined $link) {
            $footer = "$footer $link";
        }
    }
    println "<a name='$c.anchor'></a>";
    print_box_open($colors, $metapic, $meta, "cmtbar$c.talkid");
    $c->print_text();
    print_box_close($footer);
}

function ReplyPage::print_body () {
    if (not $.entry.comments.enabled)
    {
        print_header($*text_reply_nocomments_header);
        print "<p>$*text_reply_nocomments</p>";
        return;
    }

    var string{} meta; var string metapic;

    print_header($.replyto.time->date_format($*date_format));

    # Userpic
    if (defined $.replyto.userpic and $*comment_userpic_style != "off")
    {
        $metapic = "<img src='$.replyto.userpic.url' />";
    }

    # Subject
    if ($.replyto.subject) {
        $meta{"Subject:"} = $.replyto.subject;
    }

    # Time posted
    $meta{"Time:"} = $.replyto.time->time_format($*time_format);

    print_box_open({ "bgcolor" => "$*accent_bgcolor", "fgcolor" => "$*accent_fgcolor" },
              $metapic, $meta, "");
    $.replyto->print_text();
    print_box_close("");

    print_header("Reply:");

    print_genericbox_open();
    $.form->print();
    print_genericbox_close();

}

function TagsPage::print_body() {
    print_header($*text_tags_page_header);

    print_genericbox_open();
    print "<ul class='ljtaglist'>";

    foreach var TagDetail td ($.tags) {
        var string uses = get_plural_phrase($td.use_count, "text_tag_uses");
        print """<li><a href="$td.url">$td.name</a> - $uses</li>""";
    }

    print "</ul>";
    print_genericbox_close();
}

function print_theme_preview()
{
    "<table width='100%' bgcolor='$*body_bgcolor' cellpadding=10><tr><td>";
    "<table border='0' width='100%' cellpadding='5' cellspacing='1' bgcolor='$*border_color'>";
    "<tr><td bgcolor='$*headerbar_bgcolor'><font color='$*headerbar_fgcolor'>October 29th, 2003";
    "</font></td></tr></table><br />";
    "<div align='right'><table border='0' width='95%' cellpadding='5' cellspacing='1' bgcolor='$*accent_bgcolor'>";
    "<tr><td align='left' bgcolor='$*accent_bgcolor'>";
    "<table border='0' width='100%'><tr>";
    "<td valign='top'><table border='0'>";
    "<tr><td align='right'><font color='$*accent_fgcolor'>Subject:</font>";
    "</td><td><font color='$*accent_fgcolor'>Words Words Words</font></td></tr>";
    "<tr><td align='right'><font color='$*accent_fgcolor'>Time:</font></td>";
    "<td><font color='$*accent_fgcolor'>1:37 pm</font></td></tr>";
    "</table></td></tr></table></td></tr>";
    "<tr><td align='left' bgcolor='$*main_bgcolor'><font color='$*main_fgcolor'>Preview text, preview text, etc, etc..... words, words and more words.</font></td></tr>";
    """<tr><td align='left' bgcolor='$*accent_bgcolor'><font color='$*accent_fgcolor'><nobr>comments: <a href="#">20 comments</a> or <a href="#">Leave a comment</a></nobr></font></td></tr>""";
    "</table></div><br />";
    "</td></tr></table>";
}