<?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">Mappings</xsl:param>
	<xsl:param name="defaultBase"/>
	<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=system.py</xsl:attribute>
					</xsl:element>
				</xsl:if>
				<xsl:call-template name="common_imports"/>
				<script type="text/javascript" src="/javascript/mappings.js"/>
			</head>
			<body onload="StartFloat(); disableManualEntries();">
				<xsl:call-template name="initPage">
					<xsl:with-param name="pageName">advmappings.py</xsl:with-param>
					<xsl:with-param name="message" select="$message"/>
				</xsl:call-template>
				<div id="displayresultsmappings">
					<form action="advmappings.py" method="post" name="applyform">
						<input type="hidden" name="action" value="apply"/>
						<xsl:call-template name="outputs"/>
						<xsl:apply-templates/>
					</form>
				</div>
			</body>
		</html>
	</xsl:template>
	<xsl:template name="outputs">
		<table class="clear">
			<tr>
				<td>
					<h1 class="display">Mappings</h1>
				</td>
				<td style="text-align: right; color: #000000; font-weight: bold">
					Total Programs: <xsl:value-of select="count(/configuration/status/port/routed_programs/program) + count(/configuration/status/ghost/program)"/>
				</td>
			</tr>
			<tr>
				<td>
					<div class="generalcell" style="width: 200px">
						Filter Input Port:
						<select name="inputPort" style="width: 5em" onchange="show_input(this.value)">
						<option value="all">All</option>
						<xsl:for-each select="/configuration/port">
							<option value="{position()}"><xsl:value-of select="position()"/></option>
						</xsl:for-each>
						</select>
					</div>
				</td>
				<td>
					<table class="detailOptions" style="width: 535px">
						<tr>
							<td style="font-weight: bold; color: #000000">
								Group Display:
							</td>
							<td id="nav_group">
								<div id="nav_all" onclick="show_all('all')">
									All
								</div>
								<div id="nav_gen" onclick="show_all('gen')">
									General
								</div>
								<div id="nav_pids" onclick="show_all('pids')">
									PIDs
								</div>
								<xsl:for-each select="/configuration/ca">
									<div id="nav_ca{position()}" onclick="show_all('ca{position()}')">
										CA<xsl:value-of select="position()"/>
									</div>
								</xsl:for-each>
							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
		<table class="serviceTable" width="750px">
			<thead>
				<tr class="service">
					<th class="standard">Input</th>
					<th class="standard" width="90px">Svc. ID<br/> In</th>
					<th class="standard" width="90px">Svc. ID <br/> Out</th>
					<xsl:choose>
						<xsl:when test="/configuration/egress/tables/@active = 'ATSC'">
							<th class="standard" width="90px">Major-Minor</th>
							<th class="standard" width="90px">Short Name</th>
							<th class="standard" width="90px">Extended Name</th>
						</xsl:when>
						<xsl:otherwise>
							<th class="standard" width="90px">LCN</th>
							<th class="standard">Name</th>
							<th class="standard">Provider</th>
						</xsl:otherwise>
					</xsl:choose>
				</tr>
			</thead>
			<tbody id="rowContainer">
				<xsl:for-each select="/configuration/port">
					<xsl:variable name="curIndex" select="@index"/>
					<xsl:variable name="manual">
						<xsl:if test="mode = 'Manual' and tabletype = 'NONE'">
							<xsl:text>manual</xsl:text>
						</xsl:if>
					</xsl:variable>
					<!-- <xsl:choose>
						<xsl:when test="mode = 'Manual' and tabletype = 'NONE'">-->
							<xsl:for-each select="/configuration/status/port[@index=$curIndex]/routed_programs/program">
								<xsl:sort select="@program_number_in" data-type="number" order="ascending"/>
								<xsl:variable name="curProgNum" select="@program_number_in"/>
								<tr id="s{$curIndex}p{$curProgNum}_basic" class="{$manual}">
									<xsl:attribute name="class">
										<xsl:choose>
											<xsl:when test="@status = 'active'">
												<xsl:text>activeService </xsl:text>
											</xsl:when>
											<xsl:otherwise>
												<xsl:text>inactiveService </xsl:text>
											</xsl:otherwise>
										</xsl:choose>
										<xsl:value-of select="$manual"/>
									</xsl:attribute>
									<td><xsl:value-of select="$curIndex"/></td>
									<td><xsl:value-of select="$curProgNum"/></td>
									<xsl:variable name="assigned" select="@assigned"/>
									<td>
										<input name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/program_number_out?create=1^removeIfEmpty=1^updateIfNotEqual={$assigned}" type="text" value="{$assigned}" size="3"/>
									</td>
									<td>
										<xsl:choose>
											<xsl:when test="/configuration/egress/tables/@active = 'ATSC'">
												<input name="major_minor[{$curIndex},{$curProgNum}]" style="width: 90px">
													<xsl:attribute name="value">
														<xsl:call-template name="getServiceLCN">
															<xsl:with-param name="aIndex" select="$curIndex"/>
															<xsl:with-param name="aProgramNumberIn" select="$curProgNum"/>
														</xsl:call-template>
													</xsl:attribute>
												</input>
											</xsl:when>
											<xsl:otherwise>
												<input name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/logical_channel_num?create=1" style="width: 90px">
													<xsl:attribute name="value">
														<xsl:call-template name="getServiceLCN">
															<xsl:with-param name="aIndex" select="$curIndex"/>
															<xsl:with-param name="aProgramNumberIn" select="$curProgNum"/>
														</xsl:call-template>
													</xsl:attribute>
												</input>
											</xsl:otherwise>
										</xsl:choose>
									</td>
									<td>
										<xsl:variable name="name">
											<xsl:choose>
												<xsl:when test="name_out">
													<xsl:value-of select="name_out"/>
												</xsl:when>
												<xsl:otherwise>
													<xsl:value-of select="@name"/>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:variable>
										<input style="width:300px;" name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/name_out?create=1^updateIfNotEqual='{name_out | name}'^txt_enc_enable={name_out/@text_encoding_enable}" type="text" value="{$name}"/>
									</td>
									<td>
										<xsl:variable name="txt_enc_enable">
											<xsl:choose>
												<xsl:when test="provider/@text_encoding_enable">
													<xsl:value-of select="provider/@text_encoding_enable"/>
												</xsl:when>
												<xsl:otherwise>
													<xsl:text>Yes</xsl:text>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:variable>
										<xsl:variable name="provider">
											<xsl:choose>
												<xsl:when test="provider">
													<xsl:value-of select="provider"/>
												</xsl:when>
												<xsl:otherwise>
													<xsl:text>Manual</xsl:text>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:variable>
										<input name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/provider_out?create=1^txt_enc_enable={$txt_enc_enable}" type="text" value="{$provider}"/>
									</td>
								</tr>
								<tr class="components {$manual}" id="s{$curIndex}p{$curProgNum}_options">
									<td colspan="7">
										<div class="detailOptions">
											<div id="nav_p{$curIndex}s{$curProgNum}">
												<xsl:if test="/configuration/port[@index=$curIndex]/program_remap/program">
													<div id="nav_p{$curIndex}s{$curProgNum}_gen" onclick="show_general('p{$curIndex}s{$curProgNum}')">
														General
													</div>
												</xsl:if>
												<div id="nav_p{$curIndex}s{$curProgNum}_pids" onclick="show_pids('p{$curIndex}s{$curProgNum}')">
													PIDs
												</div>
												<xsl:if test="/configuration/port[@index=$curIndex]/program_remap/program">
													<xsl:choose>
														<xsl:when test="count(/configuration/port[@index=$curIndex]/program_remap/program[@program_number_in=$curProgNum]/scramble) = 0">
															<div id="nav_p{$curIndex}s{$curProgNum}_ca" onclick="show_ca('p{$curIndex}s{$curProgNum}ca')">
																CA
															</div>
														</xsl:when>
														<xsl:otherwise>
															<xsl:for-each select="/configuration/port[@index=$curIndex]/program_remap/program[@program_number_in=$curProgNum]/scramble">
																<div id="nav_p{$curIndex}s{$curProgNum}_ca{position()}" onclick="show_ca('p{$curIndex}s{$curProgNum}ca{position()}')">
																	<xsl:text>CA</xsl:text><xsl:value-of select="position()"/>
																</div>
															</xsl:for-each>
														</xsl:otherwise>
													</xsl:choose>
												</xsl:if>
											</div>
										</div>
										<div class="serviceDetailTop">
											<table id="p{$curIndex}s{$curProgNum}_pids" class="pidTable" style="display: none">
												<thead>
													<tr>
														<xsl:comment><th class="standard2">Select</th></xsl:comment>
														<th class="standard2">Stream Type</th>
														<th class="standard2">Mode</th>
														<th class="standard2">PID In</th>
														<th class="standard2">PID Out</th>
														<th class="standard2">Other</th>
														<th class="standard2">Comp. CA</th>
													</tr>
												</thead>
												<tbody>
													<xsl:for-each select="pid">
														<tr>
															<td>
																<xsl:value-of select="./@stream_type"/>
															</td>
															<td>
																<select name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/pid_remap[pid_in='{./@pid_in}']/pid_out?base={$defaultBase}*" onchange="pidModeChanged('s{$curIndex}p{$curProgNum}p{./@assigned}')">
																	<xsl:call-template name="printOptions">
																		<xsl:with-param name="optionName">pid_mode</xsl:with-param>
																		<xsl:with-param name="defaultValue">
																			<xsl:if test="./@assigned = '0000' or ./@assigned = '1FFF'">
																				<xsl:value-of select="./@assigned"/>
																			</xsl:if>
																		</xsl:with-param>
																	</xsl:call-template>
																</select>
															</td>
															<td>
																<xsl:choose>
																	<xsl:when test="$defaultBase = '16'">
																		<xsl:value-of select="./@pid_in"/>
																	</xsl:when>
																	<xsl:otherwise>
																		<xsl:call-template name="hex2dec">
																			<xsl:with-param name="num" select="./@pid_in"/>
																		</xsl:call-template>
																	</xsl:otherwise>
																</xsl:choose>
															</td>
															<td>
																<input id="s{$curIndex}p{$curProgNum}p{./@assigned}" name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/pid_remap[pid_in='{./@pid_in}']/pid_out?base={$defaultBase}*" type="text" size="3">
																	<xsl:attribute name="value">
																		<xsl:choose>
																			<xsl:when test="$defaultBase = '16'">
																				<xsl:value-of select="./@assigned"></xsl:value-of>
																			</xsl:when>
																			<xsl:otherwise>
																				<xsl:call-template name="hex2dec">
																					<xsl:with-param name="num" select="./@assigned"/>
																				</xsl:call-template>
																			</xsl:otherwise>
																		</xsl:choose>
																	</xsl:attribute>
																</input>
															</td>
															<td>
																<xsl:if test="./@stream_type='PMT'">
																	Dyn. Track
																	<select name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/pmt_dynamic_tracking_state?create=1">
																		<xsl:call-template name="printOptions">
																			<xsl:with-param name="optionName">enabledisable</xsl:with-param>
																			<xsl:with-param name="defaultValue" select="/configuration/port[@index=$curIndex]/program_remap/program[@program_number_in=$curProgNum]/pmt_dynamic_tracking_state"/>
																		</xsl:call-template>
																	</select>
																</xsl:if>
																<xsl:call-template name="getServiceLanguageCode">
																	<xsl:with-param name="aIndex" select="$curIndex"/>
																	<xsl:with-param name="aProgramNumberIn" select="$curProgNum"/>
																	<xsl:with-param name="aPidIn" select="./@pid_in"/>
																</xsl:call-template>
															</td>
															<td>
																<xsl:if test="./@stream_type!='PMT'">
																	<select name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/pid_remap[pid_in='{./@pid_in}']/component_level_scrambling?create=1">
																		<xsl:variable name="pid_in" select="./@assigned"/>
																		<xsl:call-template name="printOptions">
																			<xsl:with-param name="optionName">yesno</xsl:with-param>
																			<xsl:with-param name="defaultValue" select="/configuration/port[@index=$curIndex]/program_remap/program[@program_number_in=$curProgNum]/pid_remap[pid_in=$pid_in]/component_level_scrambling"/>
																		</xsl:call-template>
																	</select>
																</xsl:if>
															</td>
														</tr>
													</xsl:for-each>
												</tbody>
											</table>
										</div>
										<xsl:if test="/configuration/port[@index=$curIndex]/program_remap/program">
											<div class="serviceDetailBottom">
												<table id="p{$curIndex}s{$curProgNum}_general" class="mappingstable" style="display: none">
													<xsl:call-template name="generalSettings">
														<xsl:with-param name="index" select="$curIndex"/>
														<xsl:with-param name="program_number_in" select="$curProgNum"/>
													</xsl:call-template>
												</table>
												<xsl:call-template name="ServiceCaRows">
													<xsl:with-param name="aIndex" select="$curIndex"/>
													<xsl:with-param name="aProgramNumberIn" select="$curProgNum"/>
												</xsl:call-template>
											</div>
										</xsl:if>
									</td>
								</tr>
							</xsl:for-each>
						<!--</xsl:when>
						<xsl:otherwise>
							<xsl:for-each select="program_remap/program">
								<xsl:sort select="program_number_out" data-type="number" order="ascending"/>
								<xsl:variable name="curProgNum" select="@program_number_in"/>
								<tr id="s{$curIndex}p{$curProgNum}_basic">
									<xsl:choose>
										<xsl:when test="/configuration/status/port[@index=$curIndex]/routed_programs/program[@program_number_in=$curProgNum]/@status = 'active'">
											<xsl:attribute name="class">activeService</xsl:attribute>
										</xsl:when>
										<xsl:otherwise>
											<xsl:attribute name="class">inactiveService</xsl:attribute>
										</xsl:otherwise>
									</xsl:choose>
									<td><xsl:value-of select="$curIndex"/></td>
									<td><xsl:value-of select="$curProgNum"/></td>
									<xsl:variable name="assigned" select="/configuration/status/port[@index=$curIndex]/routed_programs/program[@program_number_in=$curProgNum]/@assigned | $curProgNum"/>
									<td>
										<input class="sid" name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/program_number_out?create=1^removeIfEmpty=1^updateIfNotEqual={$assigned}" type="text" value="{$assigned}"/>
									</td>
									<td>
										<xsl:choose>
											<xsl:when test="/configuration/egress/tables/@active = 'ATSC'">
												<input name="major_minor[{$curIndex},{$curProgNum}]" style="width: 90px">
													<xsl:attribute name="value">
														<xsl:call-template name="getServiceLCN">
															<xsl:with-param name="aIndex" select="$curIndex"/>
															<xsl:with-param name="aProgramNumberIn" select="$curProgNum"/>
														</xsl:call-template>
													</xsl:attribute>
												</input>
											</xsl:when>
											<xsl:otherwise>
												<input name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/logical_channel_num?create=1" style="width: 90px">
													<xsl:attribute name="value">
														<xsl:call-template name="getServiceLCN">
															<xsl:with-param name="aIndex" select="$curIndex"/>
															<xsl:with-param name="aProgramNumberIn" select="$curProgNum"/>
														</xsl:call-template>
													</xsl:attribute>
												</input>
											</xsl:otherwise>
										</xsl:choose>
									</td>
									<td>
										<input style="width:300px;" name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/name_out?create=1^updateIfNotEqual='{name_out}'^txt_enc_enable={name_out/@text_encoding_enable}" type="text" value="{name_out}"/>
									</td>
									<td>
										<input name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/provider_out?create=1^txt_enc_enable={provider/@text_encoding_enable}" type="text" value="{provider_out}"/>
									</td>
								</tr>
								<tr class="components" id="s{$curIndex}p{$curProgNum}_options">
									<td colspan="7">
										<div class="detailOptions">
											<div id="nav_p{$curIndex}s{$curProgNum}">
												<div id="nav_p{$curIndex}s{$curProgNum}_gen" onclick="show_general('p{$curIndex}s{$curProgNum}')">
													General
												</div>
												<div id="nav_p{$curIndex}s{$curProgNum}_pids" onclick="show_pids('p{$curIndex}s{$curProgNum}')">
													PIDs
												</div>
												<xsl:if test="count(/configuration/port[@index=$curIndex]/program_remap/program[@program_number_in=$curProgNum]/scramble) = 0">
													<div id="nav_p{$curIndex}s{$curProgNum}_ca" onclick="show_ca('p{$curIndex}s{$curProgNum}ca')">
														CA
													</div>
												</xsl:if>
												<xsl:for-each select="/configuration/port[@index=$curIndex]/program_remap/program[@program_number_in=$curProgNum]/scramble">
													<div id="nav_p{$curIndex}s{$curProgNum}_ca{position()}" onclick="show_ca('p{$curIndex}s{$curProgNum}ca{position()}')">
														<xsl:text>CA</xsl:text><xsl:value-of select="position()"/>
													</div>
												</xsl:for-each>
											</div>
										</div>
										<div class="serviceDetailTop">
											<table id="p{$curIndex}s{$curProgNum}_pids" class="pidTable" style="display: none">
												<thead>
													<tr>
														<xsl:comment><th class="standard2">Select</th></xsl:comment>
														<th class="standard2">Stream Type</th>
														<th class="standard2">Mode</th>
														<th class="standard2">PID In</th>
														<th class="standard2">PID Out</th>
														<th class="standard2">Other</th>
														<th class="standard2"> Comp. CA</th>
													</tr>
												</thead>
												<tbody>
													<xsl:for-each select="pid_remap">
														<tr>
															<td>
																<xsl:value-of select="stream_type"/>
															</td>
															<td>
																<select name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/pid_remap[pid_in='{pid_in}']/pid_out?base={$defaultBase}*" onchange="pidModeChanged('s{$curIndex}p{$curProgNum}p{pid_out}')">
																	<xsl:call-template name="printOptions">
																		<xsl:with-param name="optionName">pid_mode</xsl:with-param>
																		<xsl:with-param name="defaultValue">
																			<xsl:if test="pid_out = '0000' or pid_out = '1FFF'">
																				<xsl:value-of select="pid_out"/>
																			</xsl:if>
																		</xsl:with-param>
																	</xsl:call-template>
																</select>
															</td>
															<td>
																<xsl:choose>
																	<xsl:when test="$defaultBase = '16'">
																		<xsl:value-of select="pid_in"/>
																	</xsl:when>
																	<xsl:otherwise>
																		<xsl:call-template name="hex2dec">
																			<xsl:with-param name="num" select="pid_in"/>
																		</xsl:call-template>
																	</xsl:otherwise>
																</xsl:choose>
															</td>
															<td>
																<xsl:variable name="pid_in"><xsl:value-of select="pid_in"/></xsl:variable>
																<input class="pid" id="s{$curIndex}p{$curProgNum}p{pid_out}" name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/pid_remap[pid_in='{pid_in}']/pid_out?base={$defaultBase}*" type="text">
																	<xsl:attribute name="value">
																		<xsl:choose>
																			<xsl:when test="$defaultBase = '16'">
																				<xsl:value-of select="/configuration/status/port[@index=$curIndex]/routed_programs/program[@program_number_in=$curProgNum]/pid[@pid_in=$pid_in]/@assigned"/>
																			</xsl:when>
																			<xsl:otherwise>
																				<xsl:call-template name="hex2dec">
																					<xsl:with-param name="num" select="/configuration/status/port[@index=$curIndex]/routed_programs/program[@program_number_in=$curProgNum]/pid[@pid_in=$pid_in]/@assigned"/>
																				</xsl:call-template>
																			</xsl:otherwise>
																		</xsl:choose>
																	</xsl:attribute>
																	<xsl:if test="pid_out = '1FFF'">
																		<xsl:attribute name="readonly">readonly</xsl:attribute>
																	</xsl:if>
																</input>
															</td>
															<td>
																<xsl:if test="stream_type='PMT'">
																	Dyn. Track
																	<select name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/pmt_dynamic_tracking_state?create=1">
																		<xsl:call-template name="printOptions">
																			<xsl:with-param name="optionName">enabledisable</xsl:with-param>
																			<xsl:with-param name="defaultValue" select="/configuration/port[@index=$curIndex]/program_remap/program[@program_number_in=$curProgNum]/pmt_dynamic_tracking_state"/>
																		</xsl:call-template>
																	</select>
																</xsl:if>
																<xsl:call-template name="getServiceLanguageCode">
																	<xsl:with-param name="aIndex" select="$curIndex"/>
																	<xsl:with-param name="aProgramNumberIn" select="$curProgNum"/>
																	<xsl:with-param name="aPidIn" select="pid_in"/>
																</xsl:call-template>
															</td>
															<td>
																<xsl:if test="stream_type!='PMT'">
																	<select name="xpath:/configuration/port[@index='{$curIndex}']/program_remap/program[@program_number_in='{$curProgNum}']/pid_remap[pid_in='{pid_in}']/component_level_scrambling?create=1">
																		<xsl:variable name="pid_in" select="pid_in"/>
																		<xsl:call-template name="printOptions">
																			<xsl:with-param name="optionName">yesno</xsl:with-param>
																			<xsl:with-param name="defaultValue" select="/configuration/port[@index=$curIndex]/program_remap/program[@program_number_in=$curProgNum]/pid_remap[pid_in=$pid_in]/component_level_scrambling"/>
																		</xsl:call-template>
																	</select>
																</xsl:if>
															</td>
														</tr>
													</xsl:for-each>
												</tbody>
											</table>
										</div>
										<div class="serviceDetailBottom">
											<table id="p{$curIndex}s{$curProgNum}_general" class="mappingstable" style="display: none">
												<xsl:call-template name="generalSettings">
													<xsl:with-param name="index" select="$curIndex"/>
													<xsl:with-param name="program_number_in" select="$curProgNum"/>
												</xsl:call-template>
											</table>
											<xsl:call-template name="ServiceCaRows">
												<xsl:with-param name="aIndex" select="$curIndex"/>
												<xsl:with-param name="aProgramNumberIn" select="$curProgNum"/>
											</xsl:call-template>
										</div>
									</td>
								</tr>
							</xsl:for-each>
						</xsl:otherwise>
					</xsl:choose>-->
				</xsl:for-each>
				<xsl:for-each select="/configuration/status/ghost/program">
					<xsl:variable name="ghostIndex" select="../@index"/>
					<xsl:variable name="sourcePort" select="./pid[2]/source_port"/>
					<tr id="g{$sourcePort}p{$ghostIndex}_basic">
						<xsl:choose>
							<xsl:when test="@status = 'active'">
								<xsl:attribute name="class">activeService</xsl:attribute>
							</xsl:when>
							<xsl:otherwise>
								<xsl:attribute name="class">inactiveService</xsl:attribute>
							</xsl:otherwise>
						</xsl:choose>
						<td colspan="2">
							Virtual
						</td>
						<td>
							<input class="sid" name="xpath:/configuration/ghost[@index='{$ghostIndex}']/program/program_number_out" type="text" value="{@assigned}"/>
						</td>
						<td>
							<input name="xpath:/configuration/ghost[@index='{$ghostIndex}']/program/logical_channel_num?create=1" type="text" style="width: 90px">
								<xsl:attribute name="value">
									<xsl:value-of select="/configuration/ghost[@index=$ghostIndex]/program/logical_channel_num"/>
								</xsl:attribute>
							</input>
						</td>
						<td>
							<input name="xpath:/configuration/ghost[@index='{$ghostIndex}']/program/name_out?create=1^updateIfNotEqual='{name_out}'^txt_enc_enable={name_out/@text_encoding_enable}" type="text" value="{name_out}" style="width: 300px"/>
						</td>
						<td>
							<input name="xpath:/configuration/ghost[@index='{$ghostIndex}']/program/provider_out?create=1^txt_enc_enable={provider/@text_encoding_enable}" type="text" value="{provider}"/>
						</td>
					</tr>
					<tr class="components" id="g{$sourcePort}p{$ghostIndex}_options">
						<td colspan="6">
							<div class="detailOptions">
								<div id="nav_g{$ghostIndex}">
									<div id="nav_g{$ghostIndex}_gen" onclick="show_general('g{$ghostIndex}')">
										General
									</div>
									<div id="nav_g{$ghostIndex}_pids" onclick="show_pids('g{$ghostIndex}')">
										PIDs
									</div>
								</div>
							</div>
							<div class="serviceDetailTop">
								<table id="g{$ghostIndex}_pids" class="pidTable" style="display: none">
									<thead>
										<tr>
											<th class="standard2">Stream Type</th>
											<th class="standard2">Mode</th>
											<th class="standard2">PID</th>
											<th class="standard2">Language</th>
										</tr>
									</thead>
									<tbody>
										<xsl:for-each select="pid">
											<tr>
												<td>
													<xsl:value-of select="@stream_type"/>
												</td>
												<xsl:choose>
													<xsl:when test="@shared='Yes'">
														<td>Shared</td>
														<td>
															<xsl:value-of select="@assigned"/>
														</td>
														<td>
															<xsl:value-of select="@language_code"/>
														</td>
													</xsl:when>
													<xsl:otherwise>
														<td>
															<select name="xpath:/configuration/ghost[@index='{$ghostIndex}']/program/pid_remap[source_port='{source_port}'][source_program_number='{source_program_number}'][pid_in='{@pid_in}']/pid_out*">
																<xsl:call-template name="printOptions">
																	<xsl:with-param name="optionName">pid_mode</xsl:with-param>
																	<xsl:with-param name="defaultValue">
																		<xsl:if test="@requested = '0000' or @requested = '1FFF'">
																			<xsl:value-of select="@requested"/>
																		</xsl:if>
																	</xsl:with-param>
																</xsl:call-template>
															</select>
														</td>
														<td>
															<input class="pid" name="xpath:/configuration/ghost[@index='{$ghostIndex}']/program/pid_remap[source_port='{source_port}'][source_program_number='{source_program_number}'][pid_in='{@pid_in}']/pid_out*" type="text" value="{@assigned}"/>
														</td>
														<td>
															<xsl:call-template name="getGhostLanguageCode">
																<xsl:with-param name="aIndex" select="$ghostIndex"/>
																<xsl:with-param name="aSourcePort" select="source_port"/>
																<xsl:with-param name="aSourceProgramNumber" select="source_program_number"/>
																<xsl:with-param name="aPidIn" select="@pid_in"/>
															</xsl:call-template>
														</td>
													</xsl:otherwise>
												</xsl:choose>
											</tr>
										</xsl:for-each>
									</tbody>
								</table>
							</div>
							<div class="serviceDetailBottom">
								<table id="g{$ghostIndex}_general" style="display: none" class="mappingstable">
									<tr>
										<td>
											<label for="g{$ghostIndex}_desc">Description:</label>
										</td>
										<td>
											<input class="desc" id="g{$ghostIndex}_desc" name="xpath:/configuration/ghost[@index='{$ghostIndex}']/program/description_out?create=1" type="text">
												<xsl:attribute name="value"><xsl:call-template name="getGhostDescription"><xsl:with-param name="aIndex" select="$ghostIndex"/></xsl:call-template></xsl:attribute>
											</input>
										</td>
									</tr>
									<tr>
										<td>
											Service Type:
										</td>
										<td>
											<select name="xpath:/configuration/ghost[@index='{$ghostIndex}']/program/service_type_out" id="xpath:/configuration/ghost[@index='{$ghostIndex}']/program/service_type_out">
												<xsl:call-template name="printOptions">
													<xsl:with-param name="optionName">service_type_out</xsl:with-param>
													<xsl:with-param name="defaultValue" select="/configuration/ghost[@index=$ghostIndex]/program/service_type_out"/>
												</xsl:call-template>
											</select>
										</td>
									</tr>
									<xsl:call-template name="GhostCaRows">
										<xsl:with-param name="aIndex" select="$ghostIndex"/>
									</xsl:call-template>
								</table>
							</div>
						</td>
					</tr>
				</xsl:for-each>
			</tbody>
		</table>
	</xsl:template>
	<xsl:template name="inputs">
	INPUTS
	</xsl:template>
	<xsl:template match="text()"/>
	<xsl:template name="getServiceLCN">
		<xsl:param name="aIndex"/>
		<xsl:param name="aProgramNumberIn"/>
		<xsl:choose>
			<xsl:when test="/configuration/egress/tables/@active = 'ATSC'">
				<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/program_tables/atsc/vct/major_channel"/>
				<xsl:text>-</xsl:text>
				<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/program_tables/atsc/vct/minor_channel"/>
			</xsl:when>
			<xsl:when test="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/logical_channel_num">
				<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/logical_channel_num"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:text>NA</xsl:text>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="getServiceDescription">
		<xsl:param name="aIndex"/>
		<xsl:param name="aProgramNumberIn"/>
		<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/description_out"/>
	</xsl:template>
	<xsl:template name="getServiceMhpProgram">
		<xsl:param name="aIndex"/>
		<xsl:param name="aProgramNumberIn"/>
		<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/mhp_program_number"/>
	</xsl:template>
	<xsl:template name="getAtscVctCarrierFreq">
		<xsl:param name="aIndex"/>
		<xsl:param name="aProgramNumberIn"/>
		<xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/program_tables/atsc/vct/carrier_frequency"/>
	</xsl:template>
	<xsl:template name="getGhostDescription">
		<xsl:param name="aIndex"/>
		<xsl:value-of select="/configuration/ghost[@index=$aIndex]/program/description_out"/>
	</xsl:template>
	<xsl:template name="getServiceCaCriteria">
		<xsl:param name="aIndex" select="../../@index"/>
		<xsl:param name="aProgramNumberIn" select="@program_number_in"/>
		<xsl:value-of select="/configuration/port[@index=$aIndex]/ca/program[@program_number_in=$aProgramNumberIn]/scramble/@access_criteria"/>
	</xsl:template>
	<xsl:template name="getServiceVoipDest">
		<xsl:param name="aIndex" select="../../@index"/>
		<xsl:param name="aProgramNumberIn" select="@program_number_in"/>
		<input class="octet" id="p{$aIndex}s{$aProgramNumberIn}_voipaddr" name="xpath:/configuration/port[@index='{$aIndex}']/voip/program[@program_number_in='{$aProgramNumberIn}']/stream_dest_inet_addr?create=1*" type="text">
			<xsl:attribute name="value"><xsl:value-of select="substring-before(/configuration/port[@index=$aIndex]/voip/program[@program_number_in=$aProgramNumberIn]/stream_dest_inet_addr, '.')"/></xsl:attribute>
		</input>
		<input class="octet" id="p{$aIndex}s{$aProgramNumberIn}_voipaddr" name="xpath:/configuration/port[@index='{$aIndex}']/voip/program[@program_number_in='{$aProgramNumberIn}']/stream_dest_inet_addr?create=1*" type="text">
			<xsl:attribute name="value"><xsl:value-of select="substring-before(substring-after(/configuration/port[@index=$aIndex]/voip/program[@program_number_in=$aProgramNumberIn]/stream_dest_inet_addr, '.'), '.')"/></xsl:attribute>
		</input>
		<input class="octet" id="p{$aIndex}s{$aProgramNumberIn}_voipaddr" name="xpath:/configuration/port[@index='{$aIndex}']/voip/program[@program_number_in='{$aProgramNumberIn}']/stream_dest_inet_addr?create=1*" type="text">
			<xsl:attribute name="value"><xsl:value-of select="substring-before(substring-after(substring-after(/configuration/port[@index=$aIndex]/voip/program[@program_number_in=$aProgramNumberIn]/stream_dest_inet_addr, '.'), '.'), '.')"/></xsl:attribute>
		</input>
		<input class="octet" id="p{$aIndex}s{$aProgramNumberIn}_voipaddr" name="xpath:/configuration/port[@index='{$aIndex}']/voip/program[@program_number_in='{$aProgramNumberIn}']/stream_dest_inet_addr?create=1*" type="text">
			<xsl:attribute name="value"><xsl:value-of select="substring-after(substring-after(substring-after(/configuration/port[@index=$aIndex]/voip/program[@program_number_in=$aProgramNumberIn]/stream_dest_inet_addr, '.'), '.'), '.')"/></xsl:attribute>
		</input>
	</xsl:template>
	<xsl:template name="getServiceVoipPortAttributes">
		<xsl:param name="aIndex" select="../../@index"/>
		<xsl:param name="aProgramNumberIn" select="@program_number_in"/>
		<xsl:attribute name="name"><xsl:text/>xpath:/configuration/port[@index=<xsl:value-of select="$aIndex"/>]/voip/program[@program_number_in=<xsl:value-of select="$aProgramNumberIn"/>]/stream_dest_port?updateIfNotEqual=<xsl:value-of select="/configuration/port[@index=$aIndex]/voip/program[@program_number_in=$aProgramNumberIn]/stream_dest_port"/>^create=1<xsl:text/></xsl:attribute>
		<xsl:attribute name="value"><xsl:value-of select="/configuration/port[@index=$aIndex]/voip/program[@program_number_in=$aProgramNumberIn]/stream_dest_port"/></xsl:attribute>
	</xsl:template>
	<xsl:template name="getServiceLanguageCode">
		<xsl:param name="aIndex"/>
		<xsl:param name="aProgramNumberIn"/>
		<xsl:param name="aPidIn"/>
		<xsl:if test="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/pid_remap[pid_in=$aPidIn]/language_code">
			Lang: <input name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/pid_remap[pid_in='{$aPidIn}']/language_code">
				<xsl:attribute name="value"><xsl:value-of select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/pid_remap[pid_in=$aPidIn]/language_code"/></xsl:attribute>
			</input>
		</xsl:if>
	</xsl:template>
	<xsl:template name="getGhostLanguageCode">
		<xsl:param name="aIndex"/>
		<xsl:param name="aSourcePort"/>
		<xsl:param name="aSourceProgramNumber"/>
		<xsl:param name="aPidIn"/>
		<xsl:if test="/configuration/ghost[@index=$aIndex]/program/pid_remap[source_port=$aSourcePort][source_program_number=$aSourceProgramNumber][pid_in=$aPidIn]/language_code">
			<input name="xpath:/configuration/ghost[@index='{$aIndex}']/program/pid_remap[source_port='{$aSourcePort}'][source_program_number='{$aSourceProgramNumber}'][pid_in='{$aPidIn}']/language_code">
				<xsl:attribute name="value"><xsl:value-of select="/configuration/ghost[@index=$aIndex]/program/pid_remap[source_port=$aSourcePort][source_program_number=$aSourceProgramNumber][pid_in=$aPidIn]/language_code"/></xsl:attribute>
			</input>
		</xsl:if>
	</xsl:template>
	<xsl:template name="getOptions_ServiceCaTypes">
		<xsl:param name="ScrambleIndex"/>
		<option value="0">
			<xsl:if test="$ScrambleIndex = '0'">
				<xsl:attribute name="selected">selected</xsl:attribute>
			</xsl:if>
			No
		</option>
		<xsl:variable name="biss">
			<xsl:choose>
				<xsl:when test="/configuration/ca[@index='1']/enable = 'BISS1'">
					<xsl:value-of select="1"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="0"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:for-each select="/configuration/ca">
			<xsl:if test="@index = '1' or $biss = 0">
				<option value="{@index}">
					<xsl:if test="@index = $ScrambleIndex">
						<xsl:attribute name="selected">selected</xsl:attribute>
					</xsl:if>
					<xsl:value-of select="@index"/>: <xsl:value-of select="enable"/>
				</option>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="ServiceCaRows">
		<xsl:param name="aIndex"/>
		<xsl:param name="aProgramNumberIn"/>
		<xsl:if test="count(/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/scramble) = 0">
		<table id="p{$aIndex}s{$aProgramNumberIn}_ca" class="mappingstable" style="display: none">
			<tr>
				<td colspan="2">
					<font color="black">
						<b> - CA - </b>
					</font>
				</td>
			</tr>
			<tr>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_cascramble">Scramble:</label>
				</td>
				<td>
					<select class="shortselect" id="p{$aIndex}s{$aProgramNumberIn}_cascramble" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble/@index">
						<xsl:call-template name="getOptions_ServiceCaTypes">
							<xsl:with-param name="ScrambleIndex" select="''"/>
						</xsl:call-template>
					</select>
				</td>
			</tr>
			<tr>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_cacriterialength">Criteria Length:</label>
				</td>
				<td>
					<input id="p{$aIndex}s{$aProgramNumberIn}_cacriterialength" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble/@access_criteria_length" type="text" value="{@access_criteria_length}"/>
				</td>
			</tr>
			<tr>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_cacriteria">Criteria:</label>
				</td>
				<td>
					<input size="75" id="p{$aIndex}s{$aProgramNumberIn}_cacriteria" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble/@access_criteria" type="text" value="{@access_criteria}"/>
				</td>
			</tr>
			<tr>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_capvdatalength">Private Data Length:</label>
				</td>
				<td>
					<input id="p{$aIndex}s{$aProgramNumberIn}_capvdatalength" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble/@private_data_length" type="text" value="{@private_data_length}"/>
				</td>
			</tr>
			<tr>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_capvdata">Private Data:</label>
				</td>
				<td>
					<input size="75" id="p{$aIndex}s{$aProgramNumberIn}_capvdata" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble/@private_data" type="text" value="{@private_data}"/>
				</td>
			</tr>
			<tr>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_caecmpid">ECM PID:</label>
				</td>
				<td>
					<input id="p{$aIndex}s{$aProgramNumberIn}_caecmpid" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble/@ecm_pid_requested" type="text" value="{@ecm_pid_requested}"/>
				</td>
			</tr>
		</table>
		</xsl:if>
		<xsl:for-each select="/configuration/port[@index=$aIndex]/program_remap/program[@program_number_in=$aProgramNumberIn]/scramble">
		<xsl:variable name="biss">
			<xsl:choose>
				<xsl:when test="/configuration/ca[@index='1']/enable = 'BISS1' and position() > 1">
					<xsl:value-of select="'Disabled'"/>
				</xsl:when>
				<xsl:otherwise>		
					<xsl:value-of select="''"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<table id="p{$aIndex}s{$aProgramNumberIn}_ca{position()}" class="mappingstable" style="display: none">
			<tr>
				<td colspan="2">
					<font color="black"> 
						<b> - CA<xsl:value-of select="position()"/> - <xsl:value-of select="$biss"/></b>
					</font>
				</td>
			</tr>
			<tr>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_cascramble">Scramble:</label>
				</td>
				<td>
					<select class="shortselect" id="p{$aIndex}s{$aProgramNumberIn}_cascramble" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble[{position()}]/@index?create=1">
						<xsl:if test="$biss = 'Disabled'">
							<xsl:attribute name="disabled" select="$biss"/>
						</xsl:if>
						<xsl:call-template name="getOptions_ServiceCaTypes">
							<xsl:with-param name="ScrambleIndex" select="@index"/>
						</xsl:call-template>
					</select>
				</td>
			</tr>
			<tr>
				<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1' and position() = 1">
					<xsl:attribute name="style">display: none</xsl:attribute>
				</xsl:if>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_cacriterialength">Criteria Length:</label>
				</td>
				<td>
					<input id="p{$aIndex}s{$aProgramNumberIn}_cacriterialength" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble[{position()}]/@access_criteria_length" type="text" value="{@access_criteria_length}">
						<xsl:if test="$biss = 'Disabled'">
							<xsl:attribute name="disabled" select="$biss"/>
						</xsl:if>
					</input>
				</td>
			</tr>
			<tr>
				<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1' and position() = 1">
					<xsl:attribute name="style">display: none</xsl:attribute>
				</xsl:if>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_cacriteria">Criteria:</label>
				</td>
				<td>
					<input size="75" id="p{$aIndex}s{$aProgramNumberIn}_cacriteria" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble[{position()}]/@access_criteria?create=1" type="text" value="{@access_criteria}">
						<xsl:if test="$biss = 'Disabled'">
							<xsl:attribute name="disabled" select="$biss"/>
						</xsl:if>
					</input>
				</td>
			</tr>
			<tr>
				<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1' and position() = 1">
					<xsl:attribute name="style">display: none</xsl:attribute>
				</xsl:if>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_capvdatalength">Private Data Length:</label>
				</td>
				<td>
					<input id="p{$aIndex}s{$aProgramNumberIn}_capvdatalength" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble[{position()}]/@private_data_length" type="text" value="{@private_data_length}">
						<xsl:if test="$biss = 'Disabled'">
							<xsl:attribute name="disabled" select="$biss"/>
						</xsl:if>
					</input>
				</td>
			</tr>
			<tr>
				<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1' and position() = 1">
					<xsl:attribute name="style">display: none</xsl:attribute>
				</xsl:if>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_capvdata">Private Data:</label>
				</td>
				<td>
					<input size="75" id="p{$aIndex}s{$aProgramNumberIn}_capvdata" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble[{position()}]/@private_data?create=1" type="text" value="{@private_data}">
						<xsl:if test="$biss = 'Disabled'">
							<xsl:attribute name="disabled" select="$biss"/>
						</xsl:if>
					</input>
				</td>
			</tr>
			<tr>
				<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1' and position() = 1">
					<xsl:attribute name="style">display: none</xsl:attribute>
				</xsl:if>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_caecmpid">ECM PID:</label>
				</td>
				<td>
					<input id="p{$aIndex}s{$aProgramNumberIn}_caecmpid" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble[{position()}]/@ecm_pid_requested" type="text" value="{@ecm_pid_requested}">
						<xsl:if test="$biss = 'Disabled'">
							<xsl:attribute name="disabled" select="$biss"/>
						</xsl:if>
					</input>
					<br/>
				</td>
			</tr>
			<tr style="display: none">
				<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1' and position() = 1">
					<xsl:attribute name="style">display: </xsl:attribute>
				</xsl:if>
				<td>
					<label for="p{$aIndex}s{$aProgramNumberIn}_bissKey">Biss Key:</label>
				</td>
				<td>
					<xsl:variable name="biss_index" select="string(@biss_key_select)"/>
					<select id="p{$aIndex}s{$aProgramNumberIn}_bissKey" name="xpath:/configuration/port[@index='{$aIndex}']/program_remap/program[@program_number_in='{$aProgramNumberIn}']/scramble[{position()}]/@biss_key_select?create=1" type="text">
						<xsl:for-each select="/configuration/ca_biss_keys/key">
							<option value="{position()}">
								<xsl:if test="$biss_index = string(position())">
									<xsl:attribute name="selected">selected</xsl:attribute>
								</xsl:if>
								<xsl:value-of select="position()"/>:	<xsl:value-of select="."/>
							</option>
						</xsl:for-each>
					</select>
				</td>
			</tr>
		</table>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="GhostCaRows">
		<xsl:param name="aIndex"/>
		<xsl:for-each select="/configuration/ghost[@index=$aIndex]/program/scramble">
			<tr>
				<td colspan="2" style="font-weight: bold">
					- CA -
					<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1'">
						Disabled (Virtual/Ghost services do not support BISS encryption.)
					</xsl:if>
				</td>
			</tr>
			<tr>
				<td>
					<label for="g{$aIndex}_cascramble">Scramble:</label>
				</td>
				<td>
					<select class="shortselect" id="g{$aIndex}_cascramble" name="xpath:/configuration/ghost[@index='{$aIndex}']/program/scramble[{position()}]/@index?create=1*">
						<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1'">
							<xsl:attribute name="disabled">disabled</xsl:attribute>
						</xsl:if>
						<xsl:call-template name="getOptions_ServiceCaTypes">
							<xsl:with-param name="ScrambleIndex" select="@index"/>
						</xsl:call-template>
					</select>
				</td>
			</tr>
			<tr>
				<td>
					<label for="g{$aIndex}_cacriterialength">Criteria Length:</label>
				</td>
				<td>
					<input id="g{$aIndex}_cacriterialength" name="xpath:/configuration/ghost[@index='{$aIndex}']/program/scramble[{position()}]/@access_criteria_length*" type="text" value="{@access_criteria_length}">
						<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1'">
							<xsl:attribute name="disabled">disabled</xsl:attribute>
						</xsl:if>
					</input>
				</td>
			</tr>
			<tr>
				<td>
					<label for="g{$aIndex}_cacriteria">Criteria:</label>
				</td>
				<td>
					<input size="50" id="g{$aIndex}_cacriteria" name="xpath:/configuration/ghost[@index='{$aIndex}']/program/scramble[{position()}]/@access_criteria?create=1*" type="text" value="{@access_criteria}">
						<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1'">
							<xsl:attribute name="disabled">disabled</xsl:attribute>
						</xsl:if>
					</input>
				</td>
			</tr>
			<tr>
				<td>
					<label for="g{$aIndex}_cacriterialength">Private Data Length:</label>
				</td>
				<td>
					<input id="g{$aIndex}_cacriterialength" name="xpath:/configuration/ghost[@index='{$aIndex}']/program/scramble[{position()}]/@private_data_length?create=1*" type="text" value="{@private_data_length}">
						<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1'">
							<xsl:attribute name="disabled">disabled</xsl:attribute>
						</xsl:if>
					</input>
				</td>
			</tr>
			<tr>
				<td>
					<label for="g{$aIndex}_cacriterialength">Private Data:</label>
				</td>
				<td>
					<input size="50" id="g{$aIndex}_cacriterialength" name="xpath:/configuration/ghost[@index='{$aIndex}']/program/scramble[{position()}]/@private_data?create=1*" type="text" value="{@private_data}">
						<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1'">
							<xsl:attribute name="disabled">disabled</xsl:attribute>
						</xsl:if>
					</input>
				</td>
			</tr>
			<tr>
				<td>
					<label for="g{$aIndex}_cacriterialength">ECM PID:</label>
				</td>
				<td>
					<input id="g{$aIndex}_cacriterialength" name="xpath:/configuration/ghost[@index='{$aIndex}']/program/scramble[{position()}]/@ecm_pid_requested?create=1*" type="text" value="{@ecm_pid_requested}">
						<xsl:if test="/configuration/ca[@index='1']/enable = 'BISS1'">
							<xsl:attribute name="disabled">disabled</xsl:attribute>
						</xsl:if>
					</input>
				</td>
			</tr>
		</xsl:for-each>
	</xsl:template>
	<xsl:template name="generalSettings">
		<xsl:param name="index"/>
		<xsl:param name="program_number_in"/>
		<tr>
			<td>
				<label for="p{$index}s{$program_number_in}_desc">Description:</label>
			</td>
			<td>
				<input class="desc" id="p{$index}s{$program_number_in}_desc" name="xpath:/configuration/port[@index='{$index}']/program_remap/program[@program_number_in='{$program_number_in}']/description_out?create=1" type="text">
					<xsl:attribute name="value"><xsl:call-template name="getServiceDescription"><xsl:with-param name="aIndex" select="$index"/><xsl:with-param name="aProgramNumberIn" select="$program_number_in"/></xsl:call-template></xsl:attribute>
				</input>
			</td>
		</tr>
		<tr>
			<td>
				<label for="p{$index}s{$program_number_in}_desc">Service Type:</label>
			</td>
			<td>
				<select name="xpath:/configuration/port[@index='{$index}']/program_remap/program[@program_number_in='{$program_number_in}']/service_type_out">
					<xsl:call-template name="printOptions">
						<xsl:with-param name="optionName">service_type_out</xsl:with-param>
						<xsl:with-param name="defaultValue" select="/configuration/port[@index=$index]/program_remap/program[@program_number_in=$program_number_in]/service_type_out"/>
					</xsl:call-template>
				</select>
			</td>
		</tr>
		<xsl:if test="/configuration/egress/tables/@active = 'ATSC'">
			<tr>
				<td>
					<label for="p{$index}s{$program_number_in}_desc">Modulation Mode:</label>
				</td>
				<td>
					<select name="xpath:/configuration/port[@index='{$index}']/program_remap/program[@program_number_in='{$program_number_in}']/program_tables/atsc/vct/modulation_mode">
						<xsl:call-template name="printOptions">
							<xsl:with-param name="optionName">atsc_vct</xsl:with-param>
							<xsl:with-param name="defaultValue" select="/configuration/port[@index=$index]/program_remap/program[@program_number_in=$program_number_in]/program_tables/atsc/vct/modulation_mode"/>
						</xsl:call-template>
					</select>
				</td>
			</tr>
			<tr>
				<td>
					<label for="p{$index}s{$program_number_in}_desc">Carrier Frequency:</label>
				</td>
				<td>
					<input class="desc" id="p{$index}s{$program_number_in}_desc" name="xpath:/configuration/port[@index='{$index}']/program_remap/program[@program_number_in='{$program_number_in}']/program_tables/atsc/vct/carrier_frequency?create=1" type="text">
						<xsl:attribute name="value"><xsl:call-template name="getAtscVctCarrierFreq"><xsl:with-param name="aIndex" select="$index"/><xsl:with-param name="aProgramNumberIn" select="$program_number_in"/></xsl:call-template></xsl:attribute>
					</input>
				</td>
			</tr>
		</xsl:if>
		<tr>
			<td>
				<label for="p{$index}s{$program_number_in}_mhp">MHP Program Number:</label>
			</td>
			<td>
				<input class="desc" id="p{$index}s{$program_number_in}_mhp" name="xpath:/configuration/port[@index='{$index}']/program_remap/program[@program_number_in='{$program_number_in}']/mhp_program_number?create=1" type="text">
					<xsl:attribute name="value"><xsl:call-template name="getServiceMhpProgram"><xsl:with-param name="aIndex" select="$index"/><xsl:with-param name="aProgramNumberIn" select="$program_number_in"/></xsl:call-template></xsl:attribute>
				</input>
			</td>
		</tr>
	</xsl:template>
</xsl:stylesheet>
