# -*-s2-*-

layerinfo type = "layout";
layerinfo name = "Clean and Simple";
layerinfo redist_uniq = "cleansimple/layout";
layerinfo author_name = "Martin Atkins";
layerinfo previews = "cleansimple/cleansimple.jpg";
layerinfo des = "A simple layout with a left sidebar, a heading bar and configurable margins.";

propgroup presentation {
  property string opt_navbar_pos {
      des = "Side Navbar Position";
      values = "left|Left|right|Right";
  }
  property int opt_content_width {
      des = "Percentage Width of the Content Area";
      note = "Maximum is 100, minimum is 20";
  }
  property string opt_content_alignment {
      des = "Alignment of the Content Area";
      values = "left|Left|center|Center|right|Right";
  }
  property string opt_daylines_style {
      des = "Style of Lines Around Day Headings";
      values = "solid|Solid|dashed|Dashed|dotted|Dotted|double|Double|hidden|Invisible";
  }
  property string opt_entryborder_size {
      des = "Size of Lines Around Entries";
      note = "Don't forget to include the units, e.g. px";
  }
  property string opt_entryborder_style {
      des = "Style of Lines Around Entries";
      values = "solid|Solid|dashed|Dashed|dotted|Dotted|double|Double|hidden|Invisible";
  }
  property use page_recent_items;
  property use page_friends_items;
  property string opt_margin_size {
      des = "Size of page border";
      values = "0|None|5px|Tiny|25px|Small|50px|Medium|75px|Large|100px|Extra Large";
      note = "This only has an effect on the left and right borders if your content width is 100";
  }
  property string opt_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.  If set to anything except \"0\", this will override the top border size specified by the previous option.  Don't forget to include units; e.g. px, %";
  }
  property use view_entry_disabled;
  property use use_shared_pic;
  property bool show_entrynav_icons {
      des = "Toggle to show the next, memory, edit, etc icons on the entry view page";
  }
  property use linklist_support;
  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 all of the sidebar content.";
      maxlength = 2000;
      string_mode = "html-oneline";
  }
  property use external_stylesheet;
  property use custom_control_strip_colors;
}
set opt_navbar_pos = "left";
set opt_content_width = 100;
set opt_content_alignment = "center";
set opt_daylines_style = "dashed";
set opt_entryborder_size = "";
set opt_entryborder_style = "hidden";
set opt_margin_size = "50px";
set opt_top_margin = "0";
set view_entry_disabled = false;
set show_entrynav_icons = true;
set counter_code = "";

propgroup colors {
  property Color body_bgcolor {
      des = "Page border color";
      note = "If you set the border size to 'None', this won't show up.";
      s1color = "stronger_back";
  }
  property Color entry_bgcolor {
      des = "Background of entries";
      s1color = "page_back";
  }
  property Color entry_fgcolor {
      des = "Text color of entries";
      s1color = "page_text";
  }
  property Color meta_color {
      des = "Color of entry headings and meta-information";
      s1color = "page_text_em";
  }
  property Color border_color {
      des = "Color of lines around entries";
      note = "If you don't set a line size and style in the \"Presentation\" section, this won't have any effect.";
  }
  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 topbar_bgcolor {
      des = "Background color of titlebar and userpic";
      s1color = "strong_back";
  }
  property Color topbar_fgcolor {
      des = "Titlebar text color";
      s1color = "strong_text";
  }
  property Color navbar_bgcolor {
      des = "Background color of sidebar";
      s1color = "weak_back";
  }
  property Color navbar_fgcolor {
      des = "Sidebar text color";
      s1color = "weak_text";
  }
  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 = "#6666cc";
set entry_bgcolor = "#ffffff";
set entry_fgcolor = "#000000";
set meta_color = "#c00000";
set border_color = "#000000";
set link_color = "#000050";
set vlink_color = "#500050";
set alink_color = "#00ffff";
set topbar_bgcolor = "#c0c0ff";
set topbar_fgcolor = "#000000";
set navbar_bgcolor = "#eeeeff";
set navbar_fgcolor = "#000000";
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 fonts {
  property use font_base;
  property use font_fallback;
  property string font_topbar_base {
      des = "Preferred font for top bar";
      note = "As with the main font, leave blank if you don't care.";
  }
  property string font_topbar_fallback {
      des = "Alternative font style for top bar";
      values = "sans-serif|Sans-serif|serif|Serif|cursive|Cursive|monospace|Monospaced|none|Use browser's default";
  }
  property string font_sidebar_base {
      des = "Preferred font for side navigation bar";
      note = "As with the main font, leave blank if you don't care.";
  }
  property string font_sidebar_fallback {
      des = "Alternative font style for side navigation bar";
      values = "sans-serif|Sans-serif|serif|Serif|cursive|Cursive|monospace|Monospaced|none|Use browser's default";
  }
}
set font_topbar_fallback = "none";
set font_sidebar_fallback = "none";

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 opt_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 opt_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 opt_text_left_comments {
    des = "Text to be used in front of your comment links";
  }
  property string opt_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 opt_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_format {
    des = "Date and time format for comments";
  }
}
set opt_text_left_comments = "";
set opt_text_btwn_comments = " | ";
set opt_text_right_comments = "";
set date_format = "%%month%% %%dayord%%, %%yyyy%%";
set time_format = "%%hh%%:%%min%% %%a%%m";
set datetime_format = "%%month%% %%dayord%%, %%yyyy%% %%hh%%:%%min%% %%a%%m";

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

set tags_aware = true;

function prop_init() {
    if ($*opt_content_width > 100) {
        $*opt_content_width = 100;
    } elseif ($*opt_content_width < 20) {
        $*opt_content_width = 20;
    }

    if ($*control_strip_bgcolor.as_string == "") {
        $*control_strip_bgcolor = $*entry_bgcolor;
    }
    if ($*control_strip_fgcolor.as_string == "") {
        $*control_strip_fgcolor = $*entry_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 = $*entry_bgcolor;
    $*theme_fgcolor = $*entry_fgcolor;
    $*theme_bordercolor = $*border_color;
    $*theme_linkcolor = $*link_color;
}

function css_fontspec(string base, string fallback)
 "Prints a CSS font-family specification based on the base and fallback given"
{
    if ($base != "" or $fallback != "none") {
        "font-family: ";
        if ($base != "") {
            print safe "\"$base\"";
            if ($fallback != "none") {
                ", ";
            }
        }
        if ($fallback != "none") {
            print safe $fallback;
        }
        ";";
    }
}

function print_stylesheet ()
{
  var int margin_width = 99 - $*opt_content_width;

  print "body {";
  if(clean_url($*page_background_image) != "") {
"""
    background-image: url("$*page_background_image");
    background-position: $*page_background_position;
    background-repeat: $*page_background_repeat;
    background-attachment: $*page_background_scrolling;
""";
  }
"""
background-color: $*body_bgcolor;
color: $*entry_fgcolor;
""";
if (not viewer_sees_control_strip()) {
    """
    padding-top: $*opt_margin_size;
    padding-bottom: $*opt_margin_size;
    """;
    if ($*opt_content_width == 100) {
    """padding-left: $*opt_margin_size;
    padding-right: $*opt_margin_size;""";
    }
    """
    margin: 0;
    """;
}
css_fontspec($*font_base,$*font_fallback);
"""
}
a:link {
color: $*link_color;
background: transparent;
}
a:visited {
color: $*vlink_color;
background: transparent;
}
a:active {
color: $*alink_color;
background: transparent;
}
img {
vertical-align: absmiddle;
}
table {
""";

if ($*opt_content_width == 100) {
"""
width: auto;
""";
} else {
"""width: $*opt_content_width"""; "%;
";
    if ($*opt_content_alignment == "left") {
    """margin-right: ${margin_width}%;""";
    } elseif ($*opt_content_alignment == "right") {
    """margin-left: ${margin_width}%;""";
    } else { # center
    """margin-left: auto; margin-right: auto;""";
    }
}

"""
}
""";
if (viewer_sees_control_strip()) {
"""#main {
""";
if ($*opt_content_width == 100) {
"""margin: $*opt_margin_size;""";
} else {
"""margin-top: $*opt_margin_size;
margin-bottom: $*opt_margin_size;""";
}
"""
}""";
}
"""
pre {
text-align: left;
}
#topbar {
background: $*topbar_bgcolor none;
color: $*topbar_fgcolor;
""";
css_fontspec($*font_topbar_base,$*font_topbar_fallback);
"""
}
#topbar h1 {
margin-top: 5px;
margin-bottom: 0;
text-align: center;
font-size: 1.5em;
}
#topbar h2 {
margin-top: 0;
margin-bottom: 5px;
text-align: center;
font-size: 1.25em;
}
#navbar {
background: $*navbar_bgcolor none;
color: $*navbar_fgcolor;
""";
if (viewer_sees_vbox()) { "width: 20%;"; } else { "width: 25%;"; }
css_fontspec($*font_sidebar_base,$*font_sidebar_fallback);
"""
}
#navbar ul {
list-style: none;
margin: 10px;
}
#navbar ul li {
margin: 0;
}
#navbar ul li.active {
font-weight: bold;
}
#navbar a:link, #navbar a:active, #navbar a:visited {
background: $*navbar_bgcolor none;
color: $*navbar_fgcolor;
text-decoration: none;
}
#navbar a:hover {
text-decoration: underline;
}
#userlinklist ul {
margin-top: 0;
margin-bottom: 0;
}
#mainstuff {
""";
if (viewer_sees_vbox()) { "width: 70%;"; } else { "width: 75%;"; }
"""
background: $*entry_bgcolor none;
color: $*entry_fgcolor;
}
#userpic {
text-align: center;
margin: 10px;
}
#userpic img {
border: 2px solid $*topbar_bgcolor;
background: $*topbar_bgcolor none;
color: $*topbar_fgcolor;
}
#entries {
margin: 10px;
}
#range {
margin-bottom: 0.5em;
}
.day {
border-top: 1px $*opt_daylines_style $*entry_fgcolor;
clear: both;
}
.day h3 {
border-bottom: 1px $*opt_daylines_style $*entry_fgcolor;
padding: 2px;
margin: 0;
font-size: 1.1em;
text-align: center;
}

address {
text-align: center;
font-style: normal;
font-size: 0.95em;
}

/* entries */
.entrytext {
padding: 2px;
text-align: justify;
}
.entry {
clear: both;
border: $*opt_entryborder_size $*opt_entryborder_style $*border_color;
}
.entrytext p, .entrytext ul, .entrytext ol, .entrytext table {
margin-top: 0.5em;
margin-bottom: 0.5em;
}
.entryheading {
font-weight: bold;
}
.timestamp, .subject, .altposter {
font-weight: bold;
color: $*meta_color;
background: $*entry_bgcolor;
}
.altposter a {
color: $*meta_color;
background: $*entry_bgcolor;
text-decoration: underline;
}
.altposter img {
border: 2px $*navbar_fgcolor solid;
background: $*navbar_bgcolor none;
color: $*navbar_fgcolor;
}
.talklinks {
font-size: 0.75em;
text-align: right;
margin-bottom: 2px;
clear: right;
}
.frienduserpic {
border: 2px solid $*topbar_bgcolor;
background: $*topbar_bgcolor none;
color: $*topbar_fgcolor;
}
""";

print_custom_control_strip_css();
}

function Page::lay_viewspec_nav() {
    # Intentionally blank
}
function RecentPage::lay_viewspec_nav() {
    # FIXME: There is currently no decent way to i18nize this
    if ($.nav.forward_url != "" or $.nav.backward_url != "") {
        "<ul id=\"skiplinks\">";
        if ($.nav.forward_url != "") {
            println """<li><a href="$.nav.forward_url">Next</a></li>""";
        }
        if ($.nav.backward_url != "") {
            println """<li><a href="$.nav.backward_url">Previous</a></li>""";
        }
        "</ul>";
    }

}

function Page::lay_view_name(string view) : string
"This function is deprecated, since this functionality is now provided by [global[lang_viewname(string)]]." {
    return lang_viewname($view);
}

function Page::lay_viewspec_heading() : string
 "Returns some text to display under the main heading. Overridden in subclasses." {
  return "";
}
function RecentPage::lay_viewspec_heading() : string {
    return $*text_view_recent;
}
function FriendsPage::lay_viewspec_heading() : string {
    if ($.journal.journal_type == "C") {
        return $*text_view_friends_comm;
    } else {
        return $*text_view_friends;
    }
}
function DayPage::lay_viewspec_heading() : string {
    return $*text_view_archive;
}
function YearPage::lay_viewspec_heading() : string {
    return $*text_view_archive;
}
function MonthPage::lay_viewspec_heading() : string {
    return $*text_view_archive;
}

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

    var bool section_open = false;

    println "<ul id='userlinklist'>";
    foreach var UserLink l ($.linklist) {
        if ($l.title) {
            if ($l.is_heading) {
                if ($section_open) {
                    println "</ul></li>";
                }
                println """<li><span style="font-style: italic;">$l.title</span>\n<ul>""";
                $section_open = true;
            } else {
                println """<li><a href="$l.url">$l.title</a></li>""";
            }
        }
    }
    if ($section_open) {
        println "</ul></li>";
    }
    println "</ul>";
}


function Page::lay_print_navbar() {
    var string userpic;
    var Image up_img = $.journal.default_pic;
    if (defined $up_img) {
        $userpic = """<div id="userpic"><img border="0" src="$up_img.url" height="$up_img.height" width="$up_img.width" alt="" /></div>""";
    }
    var string website_name = $.journal.website_name ? $.journal.website_name : $*text_website_default_name;
    var string website;
    if ($.journal.website_url != "") {
        $website = """<li><a href="$.journal.website_url">$website_name</a></li>""";
    }

"""<td id="navbar" valign="top">

<ul id="viewlinks">
""";

foreach var string v ($.views_order) {
    if ($v == $.view) {
        println """<li class="active">"""+
        $this->lay_view_name($v)+
        """</li>""";
    } else {
        println """<li><a href="$.view_url{$v}">"""+
        $this->lay_view_name($v)+
        """</a></li>""";
    }
}

"""
$website
</ul>
""";
    $this->lay_viewspec_nav();
"$userpic";

$this->print_linklist();

if ($*counter_code != "") {
    """<ul><li>$*counter_code</li></ul>""";
}

"</td>";
}

function Page::print ()
{
    var string title = $this->title();
    var string top_margin = "";
    if ($*opt_top_margin != "0") {
        $top_margin = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-top: $*opt_top_margin;\"";
        if (viewer_sees_control_strip()) { $top_margin = $top_margin + " id=\"main\""; }
        $top_margin = $top_margin + ">";
    }

"""<html>\n<head>\n""";
    $this->print_head();
    $this->print_stylesheets();

print safe """<title>$title</title>
</head>
<body>""";
$this->print_control_strip();
if (viewer_sees_hbox_top()) {
    """<div style="text-align: center; margin-bottom: -15px;">""";
    $this->print_hbox_top();
    "</div>";
}
if ($top_margin == "") {
    "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"";
    if (viewer_sees_control_strip()) { " id=\"main\""; }
    ">";
} else {
    print safe $top_margin;
}
"""<tr><td colspan="""; if (viewer_sees_vbox()) { "\"3\" "; } else { "\"2\" "; } """id="topbar" valign="top">""";

"<h1>$.journal.name</h1>";
"<h2>" + $this->lay_viewspec_heading() + "</h2>";

"""
</td></tr>

<tr>
""";

if ($*opt_navbar_pos == "left") {
    $this->lay_print_navbar();
} else {
    if (viewer_sees_vbox()) {
        """<td valign="top" style="background: #eeeeff; width: 10%; padding: 10px;">""";
        $this->print_vbox();
        "</td>";
    }
}

"""<td id="mainstuff" valign="top">
<div id="entries">
""";

    $this->print_body();

"""
</div>

<address>"""; server_sig(); """</address>

</td>
""";

if ($*opt_navbar_pos == "right") {
    $this->lay_print_navbar();
} else {
    if (viewer_sees_vbox()) {
        """<td valign="top" style="background: #eeeeff; width: 10%; padding: 10px;">""";
        $this->print_vbox();
        "</td>";
    }
}

"""</tr>

</table>

""";
if (viewer_sees_hbox_bottom()) {
    """<div style="text-align: center; margin-top: -15px;">""";
    $this->print_hbox_bottom();
    "</div>";
}
"""
</body>
</html>
""";
}

function print_entry (Page p, Entry e, Color bgcolor, Color fgcolor, bool hide_text)
{
    var string time = $e.time->time_format($*time_format);
    if ($e.new_day) {
        """<div class="day"><h3>"""+$e.time->date_format($*date_format)+"</h3>";
    }
    """<div class="entry" id="entry$e.itemid"><div class="entrytext">""";

    if ($p.view == "entry" and $*show_entrynav_icons)
    {
        print "<div style='text-align: center'>";
        $e->print_linkbar();
        print "</div>";
    }

    """<span class="entryheading">""";

    if ($p.view == "friends") {
        if ($e.poster.username != $e.journal.username) {
            "<span class=\"altposter\"><a href=\"";
            print get_url($e.poster,"userinfo");
            "\">"+$e.poster.username;
            "</a></span>, posting in ";
        }

        "<a style=\"color: $fgcolor; background: $bgcolor; padding-left: 0.5em; padding-right: 0.5em;\"";
        " href=\""+get_url($e.journal,"userinfo")+"\">$e.journal.username</a> @ ";
    } else {
        if ($e.poster.username != $e.journal.username) {
            "<span class=\"altposter\">";
            if (defined $e.userpic) {
                """<img src="$e.userpic.url" width="$e.userpic.width"
                    height="$e.userpic.height" alt="" align="right" />""";
            }
            "<a href=\""+
            get_url($e.poster,"userinfo")+
            "\">$e.poster.username</a></span> @ ";
        }
    }
    "<span class=\"timestamp\">"+$e.time->time_format($*time_format)+"</span>: ";

    if ($e.security) {
        $e.security_icon->print();
    }
    if ($e.subject) {
        " <span class=\"subject\">$e.subject</span>";
    }
    println "</span>"+($e.subject != "" ? "<br />" : "");

    if ($p.view == "friends" and defined $e.userpic) {
        """<img src="$e.userpic.url" width="$e.userpic.width"
            style="color: $fgcolor; background: $bgcolor; border: 2px solid $bgcolor;"
            height="$e.userpic.height" alt="" align="right" class="frienduserpic" />""";
    }

    if (not $hide_text) {
        $e->print_text();
        print "<br /><br />";
        if (size $e.metadata) {
            """<div class="currents">""";
            foreach var string k ($e.metadata) {
                var string text = $k;
                var string val = $e.metadata{$k};
                if ($k == "mood") {
                    $text = $*text_meta_mood;
                } elseif ($k == "music") {
                    $text = $*text_meta_music;
                } elseif ($k == "location") {
                    $text = $*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'> $val";
                }
                """<div class="current$k"><strong>$text:</strong> $val</div>""";
            }
            "</div>\n";
        }
        if ($e.tags) {
            var int tcount = 0;
            "<strong>Tags:</strong> ";
            foreach var Tag t ($e.tags) {
                """<a rel="tag" href="$t.url">$t.name</a>""";
                $tcount++;
                if ($tcount != size $e.tags) { ", "; }
            }
            "<br />";
        }
    }

    $e.comments->print(); "\n";

    "</div></div>";

    if ($e.end_day) {
        "</div>";
    }
}

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 CommentInfo::print() {
    if ($.show_readlink or $.show_postlink) {
        print safe """<div class="talklinks" clear="all">$*opt_text_left_comments""";
        if ($.show_readlink) {
            $this->print_readlink();
        }
        if ($.show_postlink and $.show_readlink) {
            if (clean_url($*opt_img_btwn_comments) != "") {
                """ <img src="$*opt_img_btwn_comments" alt="" /> """;
            } else {
                print safe "$*opt_text_btwn_comments";
            }
        }
        if ($.show_postlink) {
            $this->print_postlink();
        }
        print safe "$*opt_text_right_comments</div>";
    }
}

# This should really be provided in core
function RecentPage::lay_range_text() : string {
    if ($.nav.skip == 0) {
        return "You are viewing the most recent "+(size $.entries)+" entries";
    } else {
        return "You are viewing "+(size $.entries)+" entries, $.nav.skip into the past";
    }
}

function RecentPage::print_body ()
{
    """<p id="range">"""+$this->lay_range_text()+"""</p>""";
    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_year_links ()
{
    """<ul id="skiplinks">""";
    foreach var YearYear y ($.years) {
        if ($y.displayed) {
            println "<li class=\"active\">$y.year</span>";
        } else {
            println "<li><a href=\"$y.url\">$y.year</a></li>";
        }
    }
    "</ul>";

}

function YearPage::print_month (YearMonth m)
{
    if (not $m.has_entries) { return; }
    """<center><table border="0" cellpadding="4" cellspacing="0" style="margin-top: 10px; margin-bottom: 10px;">""";
    """<tr align="center"><td colspan="7" bgcolor="$*topbar_bgcolor"><font color="$*topbar_fgcolor">""";

    "<b>"; print $m->month_format(); """</b> (<a href="$m.url">...</a>)</font></td></tr>""";

    """<tr align="center" bgcolor="$*navbar_bgcolor">""";

    foreach var int d (weekdays()) {
        """<td><font color="$*navbar_fgcolor">"""; print $*lang_dayname_short[$d]; "</td>\n";
    }

    "</tr>";

    foreach var YearWeek w ($m.weeks) {
        $w->print();
    }

    "</table></center>";
}

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

function YearPage::print_body() {
    "<h3>$.year</h3>";
    foreach var YearMonth m ($.months) {
        $this->print_month($m);
    }
}

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

function DayPage::lay_viewspec_nav() {
"""
<ul id="skiplinks">
<li><a href="$.prev_url">$*text_day_prev</a></li>
<li><a href="$.next_url">$*text_day_next</a></li>
</ul>
""";
}

function DayPage::print_body() {

    if (not $.has_entries) {
        println $*text_noentries_day;
    }

    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>";
        }
    }
    println "</div>";
}

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();
        """<div class="day"><h3>Comments</h3></div>""";
        if ($.comment_pages.total_subitems > 0) {
            $.comment_pages->print();
            $this->print_comments($.comments);
        }
        if ($this.multiform_on) {
            """<div class="day"><h3>Mass Action</h3></div>""";
             $this->print_multiform_actionline();
             $this->print_multiform_end();
        }
    }
}

# Clean style. Hate to clutter it up with this:
function EntryPage::print_comment (Comment c) {
    var Color background; var Color color;
    if ($c.screened) {
        $background = $*comment_bar_screened_bgcolor;
        $color = $*comment_bar_screened_fgcolor;
    } elseif ($c.depth % 2) {
        $background = $*comment_bar_one_bgcolor;
        $color = $*comment_bar_one_fgcolor;
    } else {
        $background = $*comment_bar_two_bgcolor;
        $color = $*comment_bar_two_fgcolor;
    }
    var string poster = defined $c.poster ? $c.poster->as_string() : "<i>(Anonymous)</i>";
    var string sub_icon;
    if (defined $c.subject_icon) {
        $sub_icon = $c.subject_icon->as_string();
    }
    "<a name='$c.anchor'></a><div id='cmtbar$c.talkid' style='background-color: $background; color: $color; margin-top: 10px; width: 100%'>";
    "<table cellpadding='2' cellspacing='0' summary='0' style='width: 100%'><tr valign='top'>";
    if (defined $c.userpic and $*comment_userpic_style != "off") {
        var int w = $c.userpic.width;
        var int h = $c.userpic.height;
        # WARNING: this will later be done by the system (it'll be a
        # constructional property), so don't copy this hack into your
        # layout layers or you'll be messed up later.
        if ($*comment_userpic_style == "small") {
            $w = $w / 2;
            $h = $h / 2;
        }
        print "<td style='width: 102px'><img src='$c.userpic.url' width='$w' height='$h' alt='[User Picture]' /></td>";
    }

    "<td style='width: 100%'><table style='width: 100%'><tr>";

    ### From, date, etc
    "<td align='left' style='width: 50%'>";
      print "<table>";
      print "<tr><th align='right'>From:</th><td>$poster</td></tr>\n";
      print "<tr><th align='right'>Date:</th><td style='white-space: nowrap'>";
        print $c->time_display($*datetime_format, "none") + "</td></tr>";
      if ($c.metadata{"poster_ip"}) { print "<tr><th align='right'>IP Address:</th><td>(" + $c.metadata{"poster_ip"} + ")</td></tr>"; }
    "</table></td>";

    ### Gadgets
    "<td align='right' style='width: 50%'>";
    if ($this.multiform_on) {
        " <label for='ljcomsel_$c.talkid'>$*text_multiform_check</label>";
        $c->print_multiform_check();
    }
    $c->print_linkbar();
    "</td></tr>";

    ### Subject / icon
    print "<tr valign='top'><td style='width: 50%'>";
    print (defined $c.subject_icon or $c.subject != "") ? "<h3>$c.subject_icon $c.subject</h3>" : "";
    print "</td>";

    ### Permalink
    print "<td style='width: 50%' align='right'><strong>(<a href='$c.permalink_url'>Link</a>)</strong></td></tr>";

    print "</table></td></tr></table></div>";
    print "<div style='margin-left: 5px'>"; $c->print_text(); "</div>";
    print "<div style='margin-top: 3px; font-size: smaller'>";
    if ($c.frozen) {
        print "(Replies frozen) ";
    } else {
        print "(<a href='$c.reply_url'>Reply to this</a>) ";
    }
    if ($c.parent_url != "") { "(<a href='$c.parent_url'>Parent</a>) "; }
    if ($c.thread_url != "") { "(<a href='$c.thread_url'>Thread</a>) "; }
    "</div>";
}

function ReplyPage::print_body () {
    var string time = $.replyto.time->time_format($*time_format);
    """
<div class="entry">
<div class="entrytext">
<span class="entryheading">
    """;

    if (not $.entry.comments.enabled)
    {
        print "<span class='subject'>$*text_reply_nocomments_header</span></span><br />
               $*text_reply_nocomments</div></div>";
        return;
    }
    "<span style='padding-left: 0.5em; padding-right: 0.5em;'>";
    print defined $.replyto.poster ? $.replyto.poster->as_string() : "<i>(Anonymous)</i>";
    "</span> @ ";
    "<span class='timestamp'>$time</span>: ";

    if ($.replyto.subject) {
        " <span class=\"subject\">$.replyto.subject</span>";
    }
    println "</span>"+($.replyto.subject ? "<br />" : "");

    if (defined $.replyto.userpic) {
        """<img src="$.replyto.userpic.url" width="$.replyto.userpic.width"
            style="border: 2px solid $*entry_fgcolor;"
            height="$.replyto.userpic.height" alt="" align="right" class="frienduserpic" />""";
    }

    $.replyto->print_text();

    """<div class="talklinks" clear="all"><a href='$.entry.comments.read_url'>Read Comments</a></div>""";

    "</div>";

    """<div class="day"><h3>Reply</h3></div>""";
    $.form->print();

}

function print_theme_preview ()
{
    print """
<div style="background: $*body_bgcolor none; color: $*entry_fgcolor;
            padding-left: 50px; padding-right: 50px; padding-top: 10px;
            padding-bottom: 10px; margin: 0;">

<table border="0" cellpadding="0" cellspacing="0">
  <tr><td colspan="2" style="background: $*topbar_bgcolor none; color: $*topbar_fgcolor" valign="top">
      <h1 style="margin-top: 5px; margin-bottom: 5px; text-align: center; font-size: 1.5em;">John Doe</h1>
      <h2 style="margin-top: 0;   margin-bottom: 5px; text-align: center; font-size: 1.25em;">Recent Entries</h2>
  </td></tr>
  <tr><td style="background: $*navbar_bgcolor none; color: $*navbar_fgcolor; width: 25%;" valign="top">
<ul style="list-style: none; margin: 10px">
  <li style="margin: 0; font-weight: bold;">Recent Entries</li>
  <li><a style="background: $*navbar_bgcolor none; color: $*navbar_fgcolor;" href="#">Archive</a></li>
  <li><a style="background: $*navbar_bgcolor none; color: $*navbar_fgcolor;" href="#">Friends</a></li>
  <li><a style="background: $*navbar_bgcolor none; color: $*navbar_fgcolor;" href="#">User Info</a></li>
</ul>
  </td><td style="width: 75%; background: $*entry_bgcolor none; color: $*entry_fgcolor" valign="top">
<div style="margin: 10px;">
  <div style="border-top: 1px dashed $*entry_fgcolor; clear: both;">
    <h3 style="border-bottom: 1px dashed $*entry_fgcolor; padding: 2px; margin: 0; font-size: 1.1em; text-align: center;">December 17th, 2002</h3>
    <div style="clear: both;" id="entry2839"><div style="padding: 2px; text-align: justify">
      <span style="font-weight: bold;">
        <span style="font-weight: bold; color: $*meta_color; background: $*entry_bgcolor none;">06:42 pm</span>:
        <span style="font-weight: bold; color: $*meta_color; background: $*entry_bgcolor none;">Neque porro quisquam&hellip;</span>
      </span>
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit
Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit
<div style="font-size: 0.75em; text-align: right; margin-bottom: 2px; clear: right;" >
<a href="#" style="color: $*link_color;">2 Comments Posted</a> | <a href="#" style="color: $*vlink_color">Leave a comment</a></div>
  </div></div></div></div>
</td></tr></table>
</div>
    """;
}