<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" indent="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"/>
	<xsl:param name="message"/>
	<xsl:param name="pageTitle">Tables</xsl:param>
	<xsl:param name="timepath" select="/configuration/egress/tables/dvb/tot"/>
	<xsl:include href="namedtemplates.xsl"/>
	<xsl:template match="/">
		<html>
			<head>
				<title>
					<xsl:value-of select="$web_title"/>
				</title>
				<xsl:if test="configuration/user_data/auto_logout_time != 0">
					<xsl:element name="meta">
						<xsl:attribute name="http-equiv">refresh</xsl:attribute>
						<xsl:attribute name="content"><xsl:value-of select="(configuration/user_data/auto_logout_time * 60)+ 5"/>;URL=tables.py</xsl:attribute>
					</xsl:element>
				</xsl:if>
				<xsl:call-template name="common_imports"/>
				<script type="text/javascript" src="/javascript/tables.js"/>
			</head>
			<body onload="StartFloat(); init();">
				<xsl:call-template name="initPage">
					<xsl:with-param name="pageName">tables.py</xsl:with-param>
					<xsl:with-param name="message" select="$message"/>
				</xsl:call-template>
				<div id="displayresults">
					<form action="tables.py" method="post" name="applyform">
						<input type="hidden" name="action" value="apply"/>
						<table class="inner">
							<tr>
								<td>
									<h1 class="display">Tables</h1>
								</td>
								<td>
									<select name="active_table" id="active_table" onchange="ActiveTableChange()">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">table_type</xsl:with-param>
											<xsl:with-param name="defaultValue" select="/configuration/egress/tables/@active"/>
										</xsl:call-template>
									</select>
								</td>
							</tr>
						</table>
						<xsl:apply-templates/>
					</form>
				</div>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="configuration/egress/tables">
		<table class="outer">
			<tbody id="MPEG">
				<tr class="header">
					<td>
						MPEG
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner">
							<tr>
								<td>
									PAT Rate:
								</td>
								<td style="font-weight: normal">
									<input name="mpeg_pat_rate" type="text" value="{mpeg/pat/rate}" size="5"/> tenths
								</td>
							</tr>
							<tr>
								<td>
									PMT Rate:
								</td>
								<td style="font-weight: normal">
									<input name="mpeg_pmt_rate" type="text" value="{mpeg/pmt/rate}" size="5"/> tenths
								</td>
							</tr>
							<tr>
								<td>
									CAT Rate:
								</td>
								<td style="font-weight: normal">
									<input name="mpeg_cat_rate" type="text" value="{mpeg/cat/rate}" size="5"/> tenths
								</td>
							</tr>
							<tr>
								<td>
									PAT Transport Stream ID:
								</td>
								<td>
									<input name="mpeg_pat_transport_stream_id" type="text" value="{mpeg/pat/transport_stream_id}" size="5"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</tbody>
			<tbody id="DVB">
				<tr class="header">
					<td>
						DVB
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="TableShareContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">Table Sharing</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Enable:
								</td>
								<td>
									<select class="dropdowntablecell" name="inter_table_enable">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">yesno</xsl:with-param>
											<xsl:with-param name="defaultValue" select="enableInterTables"/>
										</xsl:call-template>
									</select>
								</td>
							</tr>
							<tr>
								<td>
									Master:
								</td>
								<td>
									<select class="dropdowntablecell" name="inter_table_master">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">yesno</xsl:with-param>
											<xsl:with-param name="defaultValue" select="enableInterMaster"/>
										</xsl:call-template>
									</select>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="NitContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">NIT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Enable:
								</td>
								<td>
									<select class="dropdowntablecell" name="dvb_nit_enable">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">yesno</xsl:with-param>
											<xsl:with-param name="defaultValue" select="dvb/nit/enable"/>
										</xsl:call-template>
									</select>
								</td>
							</tr>
							<tr>
								<td>
									Rate:
								</td>
								<td style="font-weight: normal">
									<input name="dvb_nit_rate" type="text" value="{dvb/nit/rate}" size="5"/> tenths
								</td>
							</tr>
							<tr>
								<td>
									Network Name:
								</td>
								<td>
									<input name="dvb_nit_network_name" type="text" value="{dvb/nit/network_name}"/>
								</td>
							</tr>
							<tr>
								<td>
									Network ID:
								</td>
								<td>
									<input name="dvb_nit_network_id" type="text" value="{dvb/nit/network_id}"/>
								</td>
							</tr>
							<tr>
								<td>
									Original Network ID:
								</td>
								<td>
									<input name="dvb_nit_orig_network_id" type="text" value="{dvb/nit/original_network_id}"/>
								</td>
							</tr>
							<tr>
								<td>
									Delivery Descriptor:
								</td>
								<td>
									<select class="dropdowntablecell" name="delivery_descriptor" id="delivery_descriptor" onchange="NitDeliveryDescChange()">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">delivery_descriptor</xsl:with-param>
											<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/delivery_descriptor"/>
										</xsl:call-template>
									</select>
								</td>
							</tr>
							<tbody id="NitCableAndSatellite">
								<tr>
									<td>
										Frequency:
									</td>
									<td>
										<input name="dvb/nit/transport_stream[@index='1']/frequency" type="text" value="{dvb/nit/transport_stream/frequency}"/>
									</td>
								</tr>
								<tr>
									<td>
										Symbol Rate:
									</td>
									<td>
										<input name="dvb/nit/transport_stream[@index='1']/symbol_rate" type="text" value="{dvb/nit/transport_stream/symbol_rate}"/>
									</td>
								</tr>
								<tr>
									<td>
										Modulation Type:
									</td>
									<td>
										<input name="dvb/nit/transport_stream[@index='1']/modulation_type" type="text" value="{dvb/nit/transport_stream/modulation_type}" readonly="readonly"/>
									</td>
								</tr>
							</tbody>
							<tbody id="NitSatellite">
								<tr>
									<td>
										Polarization:
									</td>
									<td>
										<select class="dropdowntablecell" name="polarization">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">polarization</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/polarization"/>
											</xsl:call-template>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										East/West:
									</td>
									<td>
										<select class="dropdowntablecell" name="east_west">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">east_west</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/east_west"/>
											</xsl:call-template>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										Orbital Position:
									</td>
									<td>
										<input name="dvb/nit/transport_stream[@index='1']/orbital_position" type="text" value="{dvb/nit/transport_stream/orbital_position}"/>
									</td>
								</tr>
							</tbody>
							<tbody id="NitTerrestrial">
								<tr>
									<td>
										Center Frequency:
									</td>
									<td>
										<input name="dvb/nit/transport_stream[@index='1']/center_frequency" type="text" value="{dvb/nit/transport_stream/center_frequency}"/>
									</td>
								</tr>
								<tr>
									<td>
										Bandwidth:
									</td>
									<td>
										<select class="dropdowntablecell" name="bandwidth">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">bandwidth</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/bandwidth"/>
											</xsl:call-template>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										Constellation:
									</td>
									<td>
										<select class="dropdowntablecell" name="constellation">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">constellation</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/constellation"/>
											</xsl:call-template>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										Hierarchial Information:
									</td>
									<td>
										<select class="dropdowntablecell" name="hierarchy_information">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">hierarchy_information</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/hierarchy_information"/>
											</xsl:call-template>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										Code Rate HP Stream:
									</td>
									<td>
										<select class="dropdowntablecell" name="code_rate_HP_stream">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">qpsk</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/code_rate_HP_stream"/>
												<xsl:with-param name="ignoredValue">6/7</xsl:with-param>
											</xsl:call-template>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										Code Rate LP Stream:
									</td>
									<td>
										<select class="dropdowntablecell" name="code_rate_LP_stream">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">qpsk</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/code_rate_LP_stream"/>
												<xsl:with-param name="ignoredValue">6/7</xsl:with-param>
											</xsl:call-template>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										Guard Interval:
									</td>
									<td>
										<select class="dropdowntablecell" name="guard_interval">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">guard_interval</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/guard_interval"/>
											</xsl:call-template>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										Transmission Mode:
									</td>
									<td>
										<select class="dropdowntablecell" name="transmission_mode">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">transmission_mode</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/transmission_mode"/>
											</xsl:call-template>
										</select>
									</td>
								</tr>
								<tr>
									<td>
										Other Frequency Flag:
									</td>
									<td>
										<select class="dropdowntablecell" name="other_frequency_flag">
											<xsl:call-template name="printOptions">
												<xsl:with-param name="optionName">yesno</xsl:with-param>
												<xsl:with-param name="defaultValue" select="dvb/nit/transport_stream/other_frequency_flag"/>
											</xsl:call-template>
										</select>
									</td>
								</tr>
							</tbody>
							<!-- Test removed until application code updated for Chris' request (mlt)-->
							<xsl:if test="not(contains($udd_info, 'cnf'))"><!-- and enableInterTables = enableInterMaster"-->
								<tr>
									<td colspan="2">
										First Loop User Definable Descriptors:
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<table class="inner">
											<tr>
												<th>
													Index
												</th>
												<th>
													Tag
												</th>
												<th>
													Data
												</th>
												<th style="text-align: center">
													Action
												</th>
											</tr>
											<xsl:call-template name="udd">
												<xsl:with-param name="pText" select="$udd_info"/>
											</xsl:call-template>
										</table>
									</td>
								</tr>
							</xsl:if>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="SdtContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">SDT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Enable:
								</td>
								<td>
									<select class="dropdowntablecell" name="dvb_sdt_enable">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">yesno</xsl:with-param>
											<xsl:with-param name="defaultValue" select="dvb/sdt/enable"/>
										</xsl:call-template>
									</select>
								</td>
							</tr>
							<tr>
								<td>
									Rate:
								</td>
								<td style="font-weight: normal">
									<input name="dvb_sdt_rate" type="text" value="{dvb/sdt/rate}" size="5"/> tenths
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="TdtContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">TDT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Enable:
								</td>
								<td>
									<select class="dropdowntablecell" name="dvb_tdt_enable">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">yesno</xsl:with-param>
											<xsl:with-param name="defaultValue" select="dvb/tdt/enable"/>
										</xsl:call-template>
									</select>
								</td>
							</tr>
							<tr>
								<td>
									Rate:
								</td>
								<td style="font-weight: normal">
									<input name="dvb_tdt_rate" type="text" value="{dvb/tdt/rate}" size="5"/> tenths
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="TotContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">TOT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td colspan="2">
									Local Time Offset Descriptor
								</td>
							</tr>
							<tr>
								<td>
									Country Code:
								</td>
								<td>
									<input type="text" name="countrycode" value="{$timepath/iso3166_country_code}" size="2"/>
								</td>
							</tr>
							<tr>
								<td>
									Country Time Zone:
								</td>
								<td>
									<input type="text" name="countrytimezone" value="{$timepath/country_time_zone}" size="2"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="EitContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">EIT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Enable:
								</td>
								<td>
									<select class="dropdowntablecell" name="dvb_eit_enable">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">yesno</xsl:with-param>
											<xsl:with-param name="defaultValue" select="dvb/eit/enable"/>
										</xsl:call-template>
									</select>
								</td>
							</tr>
							<tr>
								<td>
									Rate:
								</td>
								<td style="font-weight: normal">
									<input name="dvb_eit_rate" type="text" value="{dvb/eit/rate}" size="5"/> tenths
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</tbody>
			<tbody id="ATSC">
				<tr class="header">
					<td>
						ATSC
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="PsipContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">PSIP</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Mode:
								</td>
								<td>
									<select class="dropdowntablecell" name="psip_mode">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">delivery_descriptor</xsl:with-param>
											<xsl:with-param name="defaultValue" select="atsc/psip/vct_table_mode"/>
											<xsl:with-param name="ignoredValue">Satellite</xsl:with-param>
										</xsl:call-template>
									</select>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="VctContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">VCT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Rate:
								</td>
								<td style="font-weight: normal">
									<input name="psip_vct_rate" type="text" value="{atsc/psip/vct/rate}" size="5"/> tenths
								</td>
							</tr>
							<tr>
								<td>
									Major Channel #:
								</td>
								<td>
									<input name="psip_vct_major_channel" type="text" value="{atsc/psip/vct/major_channel}"/>
								</td>
							</tr>
							<tr>
								<td>
									Primary Language Code:
								</td>
								<td>
									<input name="psip_vct_primary_language" type="text" value="{atsc/psip/vct/primary_language}"/>
								</td>
							</tr>
							<tr>
								<td>
									Secondary Language Code:
								</td>
								<td>
									<input name="psip_vct_secondary_language" type="text" value="{atsc/psip/vct/secondary_language}"/>
								</td>
							</tr>
							<tr>
								<td>
									Modulation Mode:
								</td>
								<td>
									<select class="dropdowntablecell" name="psip_vct_modulation_mode">
										<xsl:call-template name="printOptions">
											<xsl:with-param name="optionName">atsc_vct</xsl:with-param>
											<xsl:with-param name="defaultValue" select="atsc/psip/vct/modulation_mode"/>
										</xsl:call-template>
									</select>
								</td>
							</tr>
							<tr>
								<td>
									Carrier Frequency:
								</td>
								<td>
									<input name="psip_vct_carrier_frequency" type="text" value="{atsc/psip/vct/carrier_frequency}"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="MgtContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">MGT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Rate:
								</td>
								<td style="font-weight: normal">
									<input name="psip_mgt_rate" type="text" value="{atsc/psip/mgt/rate}" size="5"/> tenths
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="SttContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">STT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Rate:
								</td>
								<td style="font-weight: normal">
									<input name="psip_stt_rate" type="text" value="{atsc/psip/stt/rate}" size="5"/> tenths
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="RrtContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">RRT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Rate:
								</td>
								<td style="font-weight: normal">
									<input name="psip_rrt_rate" type="text" value="{atsc/psip/rrt/rate}" size="5"/> tenths
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table class="inner" id="AtscEitContent">
							<xsl:call-template name="innerHeader">
								<xsl:with-param name="label">EIT</xsl:with-param>
							</xsl:call-template>
							<tr>
								<td>
									Rate:
								</td>
								<td style="font-weight: normal">
									<input name="psip_eit_rate" type="text" value="{atsc/psip/eit/rate}" size="5"/> tenths
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</tbody>
		</table>
	</xsl:template>
	<xsl:template match="text()">
	</xsl:template>
	<xsl:template name="udd">
		<xsl:param name="pText" select="."/>
		<xsl:param name="index" select="0"/>
		<xsl:choose>
			<xsl:when test="string-length($pText)">
				<xsl:variable name="id" select="substring-before($pText, ',')"/>
				<xsl:variable name="data" select="substring-before(substring-after($pText, ','), ',')"/>
				<xsl:variable name="remainder" select="substring-after(substring-after($pText, ','), ',')"/>
				<tr style="font-weight: normal">
					<td>
						<xsl:value-of select="$index"/>
					</td>
					<td>
						<input type="text" name="udd_id{$index}" value="{$id}" maxlength="2" size="1"/>
					</td>
					<td>
						<input type="text" name="udd_data{$index}" value="{$data}" maxlength="256"/>
					</td>
					<td style="text-align: center">
						<input type="button" name="udd_update" value="Update" onclick="update_udd({$index})"/>
						<input type="button" name="udd_remove" value="Remove" onclick="remove_udd({$index})"/>
					</td>
				</tr>
				<xsl:call-template name="udd">
					<xsl:with-param name="pText" select="$remainder"/>
					<xsl:with-param name="index" select="$index + 1"/>
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:if test="$index &lt; 20">
					<tr style="font-weight: normal">
						<td style="width: 10%">
							<xsl:value-of select="$index"/>
							<input type="hidden" name="udd_index" value="{$index}"/>
						</td>
						<td style="width: 10%">
							<input type="text" name="udd_id" maxlength="2" size="1"/>
						</td>
						<td>
							<input type="text" name="udd_data" maxlength="256"/>
						</td>
						<td style="text-align: center">
							<input type="button" name="udd_update" value="Add" onclick="add_udd()"/>
						</td>
					</tr>
				</xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="innerHeader">
		<xsl:param name="label"/>
		<tr class="header">
			<td>
				<xsl:value-of select="$label"/>
			</td>
			<td style="text-align: right">
				[<a href="javascript: void(0)">hide</a>]
			</td>
		</tr>
	</xsl:template>
</xsl:stylesheet>
