<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/strict.dtd">
<html>
<!--#include file="sidebar_html.xps"-->
<!--#include file="spacer.xps"-->
<%
use Apache::Request;

my $apr = Apache::Request->instance($r);
my $sect = $apr->param('section');

$r->no_cache(1);

my $this_page = $r->uri;

my ($prev, $next);
my $sects = findvalue('count(/article/sect1)');
$sects = "$sects";
if ($sects > 1) {
	if ($sect >= $sects) {
		$prev = $sects - 1;
	}
	elsif ($sect <= 1) {
		$next = 2;
	}
	else {
		$prev = $sect - 1;
		$next = $sect + 1;
	}
}

%>
<!--#include file="docbook_tags.xps"-->
<%
$t->{'xref'}{testcode} = sub {
		my ($node, $t) = @_;
		my $id = findvalue('@linkend', $node);
		my ($dest) = findnodes("id('$id')/title");
		my $sect = findvalue("count(ancestor::sect1/preceding-sibling::sect1) + 1", $dest);
		$t->{pre} = "<b><a href=\"$this_page?section=$sect#";
		$t->{pre} .= $id . '">';
		$t->{pre} .= findvalue("id('$id')/title/text()");
		$t->{post} = '</a></b>';
		return -1;
	};
%>
<head>
<title><%= findvalue('/article/artheader/title/text()') %></title>
<link rel="stylesheet" href="/stylesheets/axkit.css" type="text/css" />
</head>

<!--#include file="body_tag_html.xps"-->

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<!-- navbar -->
<td align="left" valign="top" width="172">

<!--#include file="navbar_html.xps"-->

</td>

<!-- whitespace -->
<td align="left" valign="top" width="10"><%= spacer(10,1) %></td>

<!-- content -->
<td align="left" valign="top" style="font-size: small;">

<%
if (!$sect) {
	# display title/TOC page
	print apply_templates('/article/artheader/*');
	my $page = 0;
	foreach my $sect (findnodes('/article/sect1')) {
		$page++;
		print "<a href=\"$this_page?section=$page\">";
		print findvalue('title/text()', $sect);
		print "</a><br>\n";
	}
	%><hr><%
}
else {

%>
<table width="100%">
<tr>
<td align="left">
<%
	if ($prev) {
%>
<a href="<%=$this_page%>?section=<%=$prev%>">Prev</a>
<% } else {
%>
Prev
<% } %>
</td><td align="center"><a href="<%=$this_page%>">Top</a></td><td align="right">
<%
	if ($next) {
%>
<a href="<%=$this_page%>?section=<%=$next%>">Next</a>
<% } else { %>
Next
<% } %>
</td></tr></table>
<hr>

<%
	# display particular page
	foreach my $section (findnodes("/article/sect1[$sect]")) {
		# should only be 1
		print apply_templates($section);
	}

if (@footnotes) {
    print "<table cellspacing=\"0\" cellpadding=\"3\">";
    print "<caption>Footnotes</caption>";
    my $i = 1;
    foreach my $footnote (@footnotes) {
        print "<tr><td valign=\"top\"><p>$i</p></td><td valign=\"top\"><div class=\"footnote\">$footnote</div></td></tr>";
        $i++;
    }
    print "</table><hr>";
}

}

if ($sect) {
%>
<table width="100%">
<tr>
<td align="left">
<%
	if ($prev) {
%>
<a href="<%=$this_page%>?section=<%=$prev%>">Prev</a>
<% } else {
%>
Prev
<% } %>
</td><td align="center"><a href="<%=$this_page%>">Top</a></td><td align="right">
<%
	if ($next) {
%>
<a href="<%=$this_page%>?section=<%=$next%>">Next</a>
<% } else { %>
Next
<% } %>
</td></tr></table>
<hr>
<% } 
%>
<table width="100%"><tr><td align="right">
<a href="<%=$this_page%>?style=print">Printer Friendly</a>
</td></tr>
<tr><td align="right">
<a href="<%=$this_page%>?passthru=1">Raw XML</a>
</td></tr></table>

</td>

<!-- whitespace -->
<td align="left" valign="top" width="10"><%= spacer(10,1) %></td>

</tr>
</table>

</body>
</html>
