<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:param name="web_title"><xsl:value-of select="$hostname"/> - <xsl:value-of select="$pageTitle"/> - Web Configuration </xsl:param>
	<xsl:param name="version"/>
	<xsl:variable name="lcase">abcdefghijklmnopqrstuvwxyz</xsl:variable>
	<xsl:variable name="ucase">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
	<xsl:template name="SystemStatus">
		<table id="statusTable" style="width: 100%">
			<tr>
				<th colspan="2" style="text-align: center; font-size: 13px">
					Status
				</th>
			</tr>
			<tr>
				<td>
					ASI Data:
				</td>
				<td style="text-align: right">
					<xsl:value-of select="/configuration/status/egress/data_rate"/>
					<xsl:text>&#160;</xsl:text>
					<xsl:value-of select="/configuration/status/egress/data_rate/@units"/>
				</td>
			</tr>
			<tr>
				<td>
					ASI Fill:
				</td>
				<td style="text-align: right">
					<xsl:value-of select="/configuration/status/egress/fill_rate"/>
					<xsl:text>&#160;</xsl:text>
					<xsl:value-of select="/configuration/status/egress/fill_rate/@units"/>
				</td>
			</tr>
			<xsl:if test="/configuration/status/egress/voip_rate">
				<tr>
					<td>
						IPTV:
					</td>
					<td style="text-align: right">
						<xsl:value-of select="/configuration/status/egress/voip_rate"/>
						<xsl:text>&#160;</xsl:text>
						<xsl:value-of select="/configuration/status/egress/voip_rate/@units"/>
					</td>
				</tr>
			</xsl:if>
			<xsl:if test="$version = 3">
				<tr>
					<td>
						Redundancy:
					</td>
					<td style="text-align: right">
						<xsl:value-of select="/configuration/status/redundancy/mux/mode"/>
					</td>
				</tr>
			</xsl:if>
		</table>
	</xsl:template>
	<xsl:template name="nav">
		<div id="tabs">
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">system.py</xsl:with-param>
				<xsl:with-param name="link">Status</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">/ui/myles.html#page=pg_sys</xsl:with-param>
				<xsl:with-param name="link">System</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">inputs.py</xsl:with-param>
				<xsl:with-param name="link">Inputs</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">advmappings.py</xsl:with-param>
				<xsl:with-param name="link">Mappings</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">outputs.py</xsl:with-param>
				<xsl:with-param name="link">Outputs</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">tables.py</xsl:with-param>
				<xsl:with-param name="link">Tables</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">advca.py</xsl:with-param>
				<xsl:with-param name="link">CA</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">ip_destinations.py</xsl:with-param>
				<xsl:with-param name="link">IP Destinations</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">advmpe.py</xsl:with-param>
				<xsl:with-param name="link">MPE</xsl:with-param>
			</xsl:call-template>
			<xsl:if test="$version = 3">
				<xsl:call-template name="navtab">
					<xsl:with-param name="page">advredundancy.py</xsl:with-param>
					<xsl:with-param name="link">Redundancy</xsl:with-param>
				</xsl:call-template>
			</xsl:if>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">logs.py</xsl:with-param>
				<xsl:with-param name="link">Logs</xsl:with-param>
			</xsl:call-template>
			<xsl:if test="$version = 3">
				<xsl:call-template name="navtab">
					<xsl:with-param name="page">/api/release_notes_dta.html</xsl:with-param>
					<xsl:with-param name="link">Help</xsl:with-param>
				</xsl:call-template>
			</xsl:if>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">/ui/myles.html</xsl:with-param>
				<xsl:with-param name="link">Update/Features</xsl:with-param>
			</xsl:call-template>
			<xsl:call-template name="navtab">
				<xsl:with-param name="page">/ui/myles.html#page=pg_dtv</xsl:with-param>
				<xsl:with-param name="link">DTVGuide Configuration</xsl:with-param>
			</xsl:call-template>
		</div>
	</xsl:template>
	<xsl:template name="navtab">
		<xsl:param name="page"/>
		<xsl:param name="link"/>
		<div class="tab">
			<img src="../images/trabuf.gif" style="width: 10px; height: 10px"/>
			<a href="{$page}"><xsl:value-of select="$link"/></a>
		</div>
	</xsl:template>
	<xsl:template name="getGhostPidStreamType">
		<xsl:param name="sourcePort"/>
		<xsl:param name="sourceProgram"/>
		<xsl:param name="sourcePid"/>
		<xsl:for-each select="/configuration/status/port[@index=$sourcePort]/available_programs/program[@program_number=$sourceProgram]/pid">
			<xsl:if test=". = $sourcePid">
				<xsl:value-of select="@stream_type"/>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="getServiceTypeOut">
		<xsl:param name="aIndex"/>
		<xsl:param name="aProgramNumberIn"/>
		<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/service_type_out"/>
	</xsl:template>
	<xsl:template name="refresh_alert">
		Please wait while your configuration is saved. <img id="loadingBar" src="../images/ajax-loading-bar.gif"/>
	</xsl:template>
	<xsl:template name="initPage">
		<xsl:param name="pageName"/>
		<xsl:param name="reloadPage" select="$pageName"/>
		<xsl:param name="message"/>
		<xsl:param name="applyClick" select="'document.applyform.submit()'"/>
		<xsl:param name="params" select="''"/>
		<div id="container">
			<span id="AdFloater">
				<div id="logo">
					<img src="../images/dtalogo.gif"/>
					<br/>
					<xsl:value-of select="/configuration/system/sw_version"/>
				</div>
				<xsl:call-template name="nav"/>
				<form name="logoutForm" action="{$pageName}" method="post">
					<input type="hidden" name="action" value="logout"/>
					<div id="logout">
						<center>
							<input type="image" name="submit" src="../images/logoutsm.gif" onclick="this.form.submit()"/>
						</center>
					</div>
				</form>
				<div id="servermessageadmin">
					<xsl:call-template name="SystemStatus"/>
				</div>
				<div id="apply">
					<input type="image" name="submit" src="../images/applychanges.gif" align="middle">
						<xsl:attribute name="onclick">
							<xsl:value-of select="$applyClick"/>
						</xsl:attribute>
					</input>
				</div>
				<div id="reloadadmin">
					<xsl:variable name="reloadPath">
						<xsl:value-of select="$reloadPage"/>
						<xsl:if test="$params != ''">
							<xsl:if test="not(starts-with($params, '?'))">?</xsl:if>
							<xsl:value-of select="$params"/>
						</xsl:if>
					</xsl:variable>
					<a id="reloadAdminLink" href="{$reloadPath}">Reload</a>
				</div>
			</span>
			<xsl:call-template name="serverAlert">
				<xsl:with-param name="message" select="$message"/>
			</xsl:call-template>
		</div>
	</xsl:template>
	<xsl:template name="initROPage">
		<xsl:param name="pageName"/>
		<xsl:param name="reloadPage" select="$pageName"/>
		<xsl:param name="message"/>
		<div id="container">
			<span id="AdFloater">
				<div id="logo">
					<img src="../images/dtalogo.gif"/>
					<br/>
					<xsl:value-of select="/configuration/system/sw_version"/>
				</div>
				<xsl:call-template name="nav"/>
				<form name="loginForm" action="{$pageName}" method="post">
					<input type="hidden" name="action" value="login"/>
					<div id="login">
						<center>
							Password:<br/>
							<input type="password" name="admin_pw" size="15"/>
							<br/>
							<input type="image" name="submit" src="../images/loginsm.gif" onclick=" this.form.submit() " align="top"/>
						</center>
					</div>
				</form>
				<div id="servermessagereadonly">
					<xsl:call-template name="SystemStatus"/>
				</div>
				<div id="reloadreadonly">
					<a id="reloadAdminLink" href="{$reloadPage}">Reload</a>
				</div>
			</span>
			<xsl:call-template name="serverAlert">
				<xsl:with-param name="message" select="$message"/>
			</xsl:call-template>
		</div>
	</xsl:template>
	<xsl:template name="serverAlert">
		<xsl:param name="message"/>
		<div id="serveralert">
			<xsl:if test="$message != ''">
				<xsl:attribute name="style">display: block</xsl:attribute>
				<xsl:choose>
					<xsl:when test="$message = 'refresh_alert'">
						<xsl:call-template name="refresh_alert"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$message"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:if>
		</div>
	</xsl:template>
	<xsl:template name="common_imports">
		<style type="text/css" media="all">@import url(/form.css);</style>
		<style type="text/css" media="all">@import url(/design.css);</style>
		<script type="text/javascript" src="/javascript/floater.js"/>
		<script type="text/javascript" src="/javascript/jquery-1.7.1.min.js"/>
	</xsl:template>
	<xsl:template name="printOptions">
		<xsl:param name="optionName"/>
		<xsl:param name="defaultValue" select="document('options.xml')//lists/list[@name=$optionName]/@default"/>
		<xsl:param name="ignoredValue" select="'no_ignore_option'"/>
		<xsl:for-each select="document('options.xml')//lists/list[@name=$optionName]/option">
			<xsl:if test="@value != $ignoredValue">
				<option value="{@value}">
					<xsl:variable name="value">
						<xsl:call-template name="lowercase">
							<xsl:with-param name="text" select="@value"/>
						</xsl:call-template>
					</xsl:variable>
					<xsl:variable name="testValue">
						<xsl:call-template name="lowercase">
							<xsl:with-param name="text" select="$defaultValue"/>
						</xsl:call-template>
					</xsl:variable>
					<xsl:if test="$value = $testValue">
						<xsl:attribute name="selected">selected</xsl:attribute>
					</xsl:if>
					<xsl:value-of select="."/>
				</option>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="uppercase">
		<xsl:param name="text"/>
		<xsl:value-of select="translate($text, $lcase, $ucase)"/>
	</xsl:template>
	<xsl:template name="lowercase">
		<xsl:param name="text"/>
		<xsl:value-of select="translate($text, $ucase, $lcase)"/>
	</xsl:template>
	<xsl:template name="hex2dec">
		<xsl:param name="num" select="0"/>
		<xsl:param name="hex" select="translate($num,'abcdef','ABCDEF')"/>
		<xsl:param name="acc" select="0" />
		<xsl:choose>
			<xsl:when test="string-length($hex)">
				<xsl:call-template name="hex2dec">
					<xsl:with-param name="hex" select="substring($hex,2,string-length($hex))" />
					<xsl:with-param name="acc" select="$acc * 16 + string-length(substring-before('0123456789ABCDEF',substring($hex,1,1)))" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$acc" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
</xsl:stylesheet>
