<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="html" indent="no" doctype-system="" encoding="utf-8" />

    <xsl:include href="/app/tools/rps/templates/global.xsl" />

    <xsl:variable name="fieldPrefix">Form_McpsLicense_McpsLicenseRetentionList_McpsLicenseRetention_</xsl:variable>

    <xsl:variable name="priceTiersConfigured">
        <xsl:value-of select="count(/Root/Form/Product/PriceList/Price[PriceID &gt; 0])" />
    </xsl:variable>

    <xsl:variable name="committed">
        <xsl:choose>
            <xsl:when test="/Root/Form/McpsLicense/Committed = 1">1</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>


    <xsl:template name="pickLayout">
        <div class="MainBaseSection">
            <script type="text/javascript" src="/production/javascript/validate/mcpsLicense.js?v=1" />
            <form name="mcpsLicenseEdit" id="mcpsLicenseEdit" method="post" action="uk_mech">
                <input type="hidden" name="formSubmit" value="1" />
                <input type="hidden" name="c" value="edit_mcps_license" />
                <input type="hidden" name="McpsLicenseID" value="{Form/McpsLicense/McpsLicenseID}" />
                <input type="hidden" name="ProductID" value="{Form/Product/ProductID}" />
                <input type="hidden" name="Form_McpsLicense_ProductID" value="{Form/Product/ProductID}" />
                <div class="LicenseEdit">
                    <xsl:call-template name="helpLink">
                        <xsl:with-param name="helpCommand" select="'show_mcps_license'" />
                    </xsl:call-template>
                    <xsl:call-template name="albumView" />

                    <xsl:call-template name="openRunStatusMessage" />
                    <xsl:call-template name="errorMessageGeneral" />
                    <xsl:call-template name="mcpsLicenseErrors" />
                    <section class="LicenseEdit-section">
                        <xsl:call-template name="mcpsLicenseEdit" />
                    </section>
                    <xsl:call-template name="buttons" />

                </div>
            </form>
        </div>
    </xsl:template>

    <xsl:template name="submitButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="type" select="'primary'" />
            <xsl:with-param name="className" select="'Form-button'" />
            <xsl:with-param name="elemType" select="'submit'" />
            <xsl:with-param name="name" select="'Submit'" />
            <xsl:with-param name="id" select="'submitButton'" />
            <xsl:with-param name="content" select="'Update'" />
            <xsl:with-param name="disabled">
                <xsl:if test="$openRuns = 1">
                    <xsl:text>true</xsl:text>
                </xsl:if>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="cancelButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Return to Album'" />
            <xsl:with-param name="className" select="'Form-button'" />
            <xsl:with-param name="url">
                <xsl:text>catalog?c=show&amp;AlbumID=</xsl:text>
                <xsl:value-of select="Form/Album/AlbumID" />
                <xsl:text>&amp;tab=ukLicenseTab</xsl:text>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="mcpsLicenseEdit">
        <h2>MCPS Data</h2>
        <div class="Form-header">
            <p>Enter MCPS product information here.</p>
        </div>
        <section class="LicenseEdit-form-wrapper">
            <xsl:call-template name="column1Edit" />
            <xsl:call-template name="column2Edit" />
        </section>
    </xsl:template>


    <xsl:template name="column1Edit">

        <xsl:variable name="productTypeID" select="Form/Product/ProductTypeID" />
        <xsl:variable name="productType" select="Form/TypeList/Type[ProductTypeID = $productTypeID]/Description" />

        <div class="LicenseEdit-column">
            <fieldset class="Form-fieldset Form-fieldset-standart">
                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">Product Type</span>
                        <span class="Form-input-wrapper">
                            <span class="Input Form-input Input-readonly">
                                <xsl:value-of select="$productType" />
                            </span>
                        </span>
                    </label>
                </div>

                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">Product ID</span>
                        <span class="Form-input-wrapper">
                            <span class="Input Form-input Input-readonly">
                                <xsl:value-of select="Form/Product/ProductCode" />
                            </span>
                        </span>
                    </label>
                </div>

                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item</xsl:text>
                        <xsl:if test="Form/McpsLicense/McpsID[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>
                    </xsl:attribute>

                    <label class="Form-label">
                        <span class="Form-label-caption">MCPS ID</span>
                        <span class="Form-input-wrapper">
                            <input type="text" class="Input Form-input mcpsLicenseIDField" name="Form_McpsLicense_McpsID" id="Form_McpsLicense_McpsID" value="{Form/McpsLicense/McpsID}">
                                <xsl:if test="$openRuns = 1">
                                    <xsl:attribute name="disabled" select="'disabled'" />
                                </xsl:if>
                            </input>
                        </span>
                    </label>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Form/McpsLicense/McpsID</xsl:with-param>
                        <xsl:with-param name="displayName">MCPS ID</xsl:with-param>
                    </xsl:call-template>
                </div>

                <xsl:if test="$productType = 'DVD'">

                    <div class="Form-item">
                        <xsl:attribute name="class">
                            <xsl:text>Form-item</xsl:text>
                            <xsl:if test="Form/McpsLicense/DvdCategory[@e]">
                                <xsl:text> Form-item-error</xsl:text>
                            </xsl:if>
                        </xsl:attribute>

                        <label class="Form-label">
                            <span class="Form-label-caption">DVD Category</span>
                            <span class="Form-input-wrapper">
                                <xsl:variable name="mcpsLicenseDvdCategoryItems">
                                    <map>
                                        <mapEntry><name>A</name><value>A</value></mapEntry>
                                        <mapEntry><name>B</name><value>C</value></mapEntry>
                                        <mapEntry><name>C</name><value>C</value></mapEntry>
                                        <mapEntry><name>AVP</name><value>AVP</value></mapEntry>
                                    </map>
                                </xsl:variable>
                                <xsl:call-template name="uiDropdown">
                                    <xsl:with-param name="items" select="$mcpsLicenseDvdCategoryItems"/>
                                    <xsl:with-param name="id" select="'Form_McpsLicense_DvdCategory'"/>
                                    <xsl:with-param name="name" select="'Form_McpsLicense_DvdCategory'"/>
                                    <xsl:with-param name="active" select="Form/McpsLicense/DvdCategory"/>
                                    <xsl:with-param name="disabled">
                                        <xsl:if test="$openRuns = 1">
                                            <xsl:text>true</xsl:text>
                                        </xsl:if>
                                    </xsl:with-param>
                                </xsl:call-template>

                            </span>
                        </label>
                        <xsl:call-template name="inlineError">
                            <xsl:with-param name="path">Form/McpsLicense/DvdCategory</xsl:with-param>
                            <xsl:with-param name="displayName">DVD Category</xsl:with-param>
                        </xsl:call-template>
                    </div>
                </xsl:if>

                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">Product Status</span>
                        <span class="Form-input-wrapper">
                            <span class="Input Form-input Input-readonly">
                                <xsl:variable name="productStatusID" select="Form/Product/ProductStatusID" />
                                <xsl:value-of select="Form/StatusList/Status[ProductStatusID = $productStatusID]/Description" />
                            </span>
                        </span>
                    </label>
                </div>

                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">Release Date</span>
                        <span class="Form-input-wrapper">
                            <span class="Input Form-input Input-readonly">
                                <xsl:value-of select="Form/Product/ReleaseDate" />
                            </span>
                        </span>
                    </label>
                </div>

                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">Current Default Price</span>
                        <span class="Form-input-wrapper">
                            <span class="Input Form-input Input-readonly">
                                <xsl:variable name="priceLevelID" select="Form/Product/DefaultPriceLevelID" />
                                <xsl:value-of select="Form/PriceLevelList/PriceLevel[PriceLevelID = $priceLevelID]/Name" />
                            </span>
                        </span>
                    </label>
                </div>

                <!-- The payor drop-down and supplier code below it need to start out (and stay)
                in sync, so we'll figure out the selected payor ahead of time and reference
                it for both rows.  We'll also create hash in javascript to store the payor id/
                supplier code pairs so that we can update it when the drop-down changes -->

                <xsl:variable name="selectedPayorID">
                    <xsl:choose>
                        <xsl:when test="normalize-space(Form/McpsLicense/PayorID)">
                            <xsl:value-of select="Form/McpsLicense/PayorID" />
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="Form/PayorList/Payor[IsDefault = 1]/PayorID" />
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>

                <div class="Form-item">

                    <xsl:attribute name="class">
                        <xsl:text>Form-item</xsl:text>
                        <xsl:if test="Form/McpsLicense/PayorID[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>
                    </xsl:attribute>

                    <script type="text/javascript">
                        var supplierCodes = new Object();
                        <xsl:for-each select="Form/PayorList/Payor">
                            supplierCodes[<xsl:value-of select="PayorID" />] = '<xsl:value-of select="SupplierCode" />';
                        </xsl:for-each>
                    </script>

                    <label class="Form-label">
                        <span class="Form-label-caption">Payor</span>
                        <span class="Form-input-wrapper">
                            <xsl:variable name="mcpsLicensePayorIDItems">
                                <map>
                                    <xsl:for-each select="Form/PayorList/Payor">
                                        <mapEntry>
                                            <name><xsl:value-of select="Name" /></name>
                                            <value><xsl:value-of select="PayorID" /></value>
                                        </mapEntry>
                                    </xsl:for-each>
                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$mcpsLicensePayorIDItems"/>
                                <xsl:with-param name="id" select="'Form_McpsLicense_PayorID'"/>
                                <xsl:with-param name="name" select="'Form_McpsLicense_PayorID'"/>
                                <xsl:with-param name="active" select="$selectedPayorID"/>
                                <xsl:with-param name="disabled">
                                    <xsl:if test="$openRuns = 1">
                                        <xsl:text>true</xsl:text>
                                    </xsl:if>
                                </xsl:with-param>
                            </xsl:call-template>

                        </span>
                    </label>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Form/McpsLicense/PayorID</xsl:with-param>
                        <xsl:with-param name="displayName">Payor</xsl:with-param>
                    </xsl:call-template>
                </div>

                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">Supplier Code</span>
                        <span class="Form-input-wrapper">
                            <span class="Input Form-input Input-readonly">
                                <xsl:value-of select="Form/PayorList/Payor[PayorID = $selectedPayorID]/SupplierCode" />
                            </span>
                        </span>
                    </label>
                </div>
            </fieldset>
        </div>
    </xsl:template>

    <xsl:template name="column2Edit">

        <xsl:variable name="initialPeriods">
            <xsl:choose>
                <xsl:when test="normalize-space(Form/McpsLicense/InitialPeriodsCompleted)">
                    <xsl:value-of select="Form/McpsLicense/InitialPeriodsCompleted" />
                </xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <div class="LicenseEdit-column">
            <fieldset class="Form-fieldset Form-fieldset-standart">
                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item</xsl:text>
                        <xsl:if test="Form/McpsLicense/RetentionCategory/PayorID[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>
                    </xsl:attribute>

                    <label class="Form-label">
                        <span class="Form-label-caption">TV Advertised</span>
                        <span class="Form-input-wrapper">
                            <xsl:variable name="mcpsLicenseRetentionCategoryItems">
                                <map>
                                    <mapEntry>
                                        <name>No</name>
                                        <value>S</value>
                                    </mapEntry>
                                    <mapEntry>
                                        <name>Yes</name>
                                        <value>T</value>
                                    </mapEntry>
                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$mcpsLicenseRetentionCategoryItems"/>
                                <xsl:with-param name="id" select="'Form_McpsLicense_RetentionCategory'"/>
                                <xsl:with-param name="name" select="'Form_McpsLicense_RetentionCategory'"/>
                                <xsl:with-param name="active" select="Form/McpsLicense/RetentionCategory"/>
                                <xsl:with-param name="disabled">
                                    <xsl:if test="$openRuns = 1">
                                        <xsl:text>true</xsl:text>
                                    </xsl:if>
                                </xsl:with-param>
                            </xsl:call-template>

                        </span>
                    </label>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Form/McpsLicense/RetentionCategory</xsl:with-param>
                        <xsl:with-param name="displayName">TV Advertised</xsl:with-param>
                    </xsl:call-template>
                </div>

                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item</xsl:text>
                        <xsl:if test="Form/McpsLicense/InitialPeriodsCompleted/PayorID[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>
                    </xsl:attribute>

                    <label class="Form-label">
                        <span class="Form-label-caption">Initial Periods Completed</span>
                        <span class="Form-input-wrapper">
                            <xsl:variable name="mcpsLicenseInitialPeriodsCompletedItems">
                                <map>
                                    <mapEntry>
                                        <name>0</name>
                                        <value>0</value>
                                    </mapEntry>
                                    <mapEntry>
                                        <name>1</name>
                                        <value>1</value>
                                    </mapEntry>
                                    <mapEntry>
                                        <name>2</name>
                                        <value>2</value>
                                    </mapEntry>
                                    <mapEntry>
                                        <name>3</name>
                                        <value>3</value>
                                    </mapEntry>
                                    <mapEntry>
                                        <name>4</name>
                                        <value>4</value>
                                    </mapEntry>
                                    <mapEntry>
                                        <name>5+</name>
                                        <value>5</value>
                                        <selected>
                                            <xsl:if test="Form/McpsLicense/InitialPeriodsCompleted &gt; 4">
                                                <xsl:text>true</xsl:text>
                                            </xsl:if>
                                        </selected>
                                    </mapEntry>
                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$mcpsLicenseInitialPeriodsCompletedItems"/>
                                <xsl:with-param name="id" select="'Form_McpsLicense_InitialPeriodsCompleted'"/>
                                <xsl:with-param name="name" select="'Form_McpsLicense_InitialPeriodsCompleted'"/>
                                <xsl:with-param name="active" select="Form/McpsLicense/InitialPeriodsCompleted"/>
                                <xsl:with-param name="disabled">
                                    <xsl:if test="$committed = 1 or $openRuns = 1">
                                        <xsl:text>true</xsl:text>
                                    </xsl:if>
                                </xsl:with-param>
                                <xsl:with-param name="onChange">
                                    <xsl:choose>
                                        <xsl:when test="$priceTiersConfigured &gt; 0">
                                            <xsl:text>historicalRetentions(this.value)</xsl:text>
                                        </xsl:when>
                                        <xsl:otherwise>
                                            <xsl:text>historicalRetentions(0)</xsl:text>
                                        </xsl:otherwise>
                                    </xsl:choose>
                                </xsl:with-param>
                            </xsl:call-template>
                        </span>
                    </label>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Form/McpsLicense/InitialPeriodsCompleted</xsl:with-param>
                        <xsl:with-param name="displayName">Initial Periods Completed</xsl:with-param>
                    </xsl:call-template>
                </div>
            </fieldset>

            <xsl:if test="$committed = 0 or ($committed = 1 and $initialPeriods &gt; 0)">
                <fieldset class="Form-fieldset">
                    <div class="Form-item">

                        <div class="Form-label">

                            <span class="Form-label-caption">Historical Retentions</span>

                            <div class="Form-input-wrapper">
                                <xsl:variable name="showPeriod2">
                                    <xsl:choose>
                                        <xsl:when test="$committed = 0 or ($committed = 1 and $initialPeriods &gt; 1)">1</xsl:when>
                                        <xsl:otherwise>0</xsl:otherwise>
                                    </xsl:choose>
                                </xsl:variable>

                                <xsl:variable name="showPeriod3">
                                    <xsl:choose>
                                        <xsl:when test="$committed = 0 or ($committed = 1 and $initialPeriods &gt; 2)">1</xsl:when>
                                        <xsl:otherwise>0</xsl:otherwise>
                                    </xsl:choose>
                                </xsl:variable>

                                <xsl:variable name="showPeriod4">
                                    <xsl:choose>
                                        <xsl:when test="$committed = 0 or ($committed = 1 and $initialPeriods &gt; 3)">1</xsl:when>
                                        <xsl:otherwise>0</xsl:otherwise>
                                    </xsl:choose>
                                </xsl:variable>

                                <table class="Table" id="historicalRetentions">
                                    <thead>
                                        <tr class="Table-row Table-row-header">
                                            <th class="Table-col Table-col-heading">Period</th>
                                            <th class="Table-col">1</th>
                                            <xsl:if test="$showPeriod2 = 1">
                                                <th class="Table-col">2</th>
                                            </xsl:if>
                                            <xsl:if test="$showPeriod3 = 1">
                                                <th class="Table-col">3</th>
                                            </xsl:if>
                                            <xsl:if test="$showPeriod4 = 1">
                                                <th class="Table-col">4</th>
                                            </xsl:if>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr class="Table-row Table-row-data">
                                            <td class="Table-col Table-col-heading">#&#160;Held</td>
                                            <td class="Table-col">
                                                <xsl:if test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 1]/UnitsHeld[@e]">
                                                    <xsl:attribute name="class">errorInput</xsl:attribute>
                                                </xsl:if>
                                                <input type="text" class="Form-input Input" name="{$fieldPrefix}0_UnitsHeld" id="{$fieldPrefix}0_UnitsHeld" value="{Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 1]/UnitsHeld}">
                                                    <xsl:if test="$committed = 1 or $openRuns = 1 or $priceTiersConfigured = 0">
                                                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                                                    </xsl:if>
                                                </input>
                                                <input type="hidden" name="{$fieldPrefix}0_McpsLicenseID" value="{Form/McpsLicense/McpsLicenseID}" />
                                                <input type="hidden" name="{$fieldPrefix}0_PeriodID" value="1" />
                                                <input type="hidden" name="{$fieldPrefix}0_Delete" id="{$fieldPrefix}0_Delete" />
                                            </td>
                                            <xsl:if test="$showPeriod2 = 1">
                                                <td class="Table-col">
                                                    <xsl:if test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 2]/UnitsHeld[@e]">
                                                        <xsl:attribute name="class">errorInput</xsl:attribute>
                                                    </xsl:if>
                                                    <input type="text" class="Form-input Input" name="{$fieldPrefix}1_UnitsHeld" id="{$fieldPrefix}1_UnitsHeld" value="{Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 2]/UnitsHeld}">
                                                        <xsl:if test="$committed = 1 or $openRuns = 1 or $priceTiersConfigured = 0">
                                                            <xsl:attribute name="disabled">disabled</xsl:attribute>
                                                        </xsl:if>
                                                    </input>
                                                    <input type="hidden" name="{$fieldPrefix}1_McpsLicenseID" value="{Form/McpsLicense/McpsLicenseID}" />
                                                    <input type="hidden" name="{$fieldPrefix}1_PeriodID" value="2" />
                                                    <input type="hidden" name="{$fieldPrefix}1_Delete" id="{$fieldPrefix}1_Delete" />
                                                </td>
                                            </xsl:if>
                                            <xsl:if test="$showPeriod3 = 1">
                                                <td class="Table-col">
                                                    <xsl:if test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 3]/UnitsHeld[@e]">
                                                        <xsl:attribute name="class">errorInput</xsl:attribute>
                                                    </xsl:if>
                                                    <input type="text" class="Form-input Input" name="{$fieldPrefix}2_UnitsHeld" id="{$fieldPrefix}2_UnitsHeld" value="{Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 3]/UnitsHeld}">
                                                        <xsl:if test="$committed = 1 or $openRuns = 1 or $priceTiersConfigured = 0">
                                                            <xsl:attribute name="disabled">disabled</xsl:attribute>
                                                        </xsl:if>
                                                    </input>
                                                    <input type="hidden" name="{$fieldPrefix}2_McpsLicenseID" value="{Form/McpsLicense/McpsLicenseID}" />
                                                    <input type="hidden" name="{$fieldPrefix}2_PeriodID" value="3" />               <input type="hidden" name="{$fieldPrefix}2_Delete" id="{$fieldPrefix}2_Delete" />
                                                </td>
                                            </xsl:if>
                                            <xsl:if test="$showPeriod4 = 1">
                                                <td class="Table-col">
                                                    <xsl:if test="Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 4]/UnitsHeld[@e]">
                                                        <xsl:attribute name="class">errorInput</xsl:attribute>
                                                    </xsl:if>
                                                    <input type="text" class="Form-input Input" name="{$fieldPrefix}3_UnitsHeld" id="{$fieldPrefix}3_UnitsHeld" value="{Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = 4]/UnitsHeld}">
                                                        <xsl:if test="$committed = 1 or $openRuns = 1 or $priceTiersConfigured = 0">
                                                            <xsl:attribute name="disabled">disabled</xsl:attribute>
                                                        </xsl:if>
                                                    </input>
                                                    <input type="hidden" name="{$fieldPrefix}3_McpsLicenseID" value="{Form/McpsLicense/McpsLicenseID}" />
                                                    <input type="hidden" name="{$fieldPrefix}3_PeriodID" value="4" />
                                                    <input type="hidden" name="{$fieldPrefix}3_Delete" id="{$fieldPrefix}3_Delete" />
                                                </td>
                                            </xsl:if>
                                        </tr>
                                        <tr class="Table-row Table-row-data">
                                            <td class="Table-col Table-col-heading">Price&#160;Tier</td>
                                            <td class="Table-col">
                                                <xsl:call-template name="priceTierSelect">
                                                    <xsl:with-param name="period" select="'1'" />
                                                </xsl:call-template>
                                            </td>
                                            <xsl:if test="$showPeriod2 = 1">
                                                <td class="Table-col">
                                                    <xsl:call-template name="priceTierSelect">
                                                        <xsl:with-param name="period" select="'2'" />
                                                    </xsl:call-template>
                                                </td>
                                            </xsl:if>
                                            <xsl:if test="$showPeriod3 = 1">
                                                <td class="Table-col">
                                                    <xsl:call-template name="priceTierSelect">
                                                        <xsl:with-param name="period" select="'3'" />
                                                    </xsl:call-template>
                                                </td>
                                            </xsl:if>
                                            <xsl:if test="$showPeriod4 = 1">
                                                <td class="Table-col">
                                                    <xsl:call-template name="priceTierSelect">
                                                        <xsl:with-param name="period" select="'4'" />
                                                    </xsl:call-template>
                                                </td>
                                            </xsl:if>
                                        </tr>

                                        <xsl:if test="$committed = 0 and $openRuns = 0 and $priceTiersConfigured &gt; 0">
                                            <script type="text/javascript">
                                                <xsl:variable name="periodsCompleted">
                                                    <xsl:choose>
                                                        <xsl:when test="normalize-space(Form/McpsLicense/PeriodsCompleted)">
                                                            <xsl:value-of select="Form/McpsLicense/PeriodsCompleted" />
                                                        </xsl:when>
                                                        <xsl:otherwise>0</xsl:otherwise>
                                                    </xsl:choose>
                                                </xsl:variable>
                                                historicalRetentions(<xsl:value-of select="$periodsCompleted" />);
                                            </script>
                                        </xsl:if>
                                    </tbody>
                                </table>
                            </div>
                        </div>

                        <xsl:if test="$priceTiersConfigured = 0 and $committed = 0 and $openRuns = 0">
                            <div class="HelpText HelpText-bybutton" style="display:block">
                                Price tiers must be configured for the associated product in order to enter historical retentions.
                            </div>
                        </xsl:if>

                    </div>
                </fieldset>
            </xsl:if>
        </div>
    </xsl:template>


    <xsl:template name="priceTierSelect">
        <xsl:param name="period" />

            <xsl:variable name="priceTierSelectItems">
                <map>
                    <xsl:for-each select="Form/PriceLevelList/PriceLevel[Type = 1]">
                        <xsl:variable name="priceLevelID" select="PriceLevelID" />
                        <xsl:variable name="priceID" select="/Root/Form/Product/PriceList/Price[PriceLevelID = $priceLevelID]/PriceID" />
                        <xsl:if test="normalize-space($priceID)">

                            <xsl:variable name="priceTierPrice">
                                <xsl:choose>
                                    <xsl:when test="$committed = 0">
                                        <xsl:value-of select="/Root/Form/PriceList/Price[PriceID = $priceID]/Wholesale" />
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="/Root/Form/McpsLicense/McpsLicenseRetentionList/McpsLicenseRetention[PeriodID = $period]/Price" />
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable>

                            <mapEntry>
                                <name><xsl:value-of select="Name" /> / <xsl:value-of select="$priceTierPrice" /></name>
                                <value><xsl:value-of select="PriceLevelID" /></value>
                            </mapEntry>

                        </xsl:if>
                    </xsl:for-each>
                </map>
            </xsl:variable>
            <xsl:call-template name="uiDropdown">
                <xsl:with-param name="items" select="$priceTierSelectItems"/>
                <xsl:with-param name="name">
                    <xsl:value-of select="$fieldPrefix" />
                    <xsl:value-of select="$period - 1" />
                    <xsl:text>_PriceLevelID</xsl:text>
                </xsl:with-param>
                <xsl:with-param name="id">
                    <xsl:value-of select="$fieldPrefix" />
                    <xsl:value-of select="$period - 1" />
                    <xsl:text>_PriceLevelID</xsl:text>
                </xsl:with-param>
                <xsl:with-param name="active" select="Form/McpsLicense/RetentionCategory"/>
                <xsl:with-param name="disabled">
                    <xsl:if test="$committed = 1 or $openRuns = 1 or $priceTiersConfigured = 0">
                        <xsl:text>true</xsl:text>
                    </xsl:if>
                </xsl:with-param>
            </xsl:call-template>
    </xsl:template>

    <xsl:template name="mcpsLicenseErrors">
        <div class="Form-error">
            <xsl:if test="//UnitsHeld[@e]">
                <xsl:call-template name="uiWarning">
                    <xsl:with-param name="type" select="'error'" />
                    <xsl:with-param name="title" select="''"/>
                    <xsl:with-param name="description" select="'# Held is invalid.'"/>
                    <xsl:with-param name="hidden" select="'false'" />
                </xsl:call-template>
            </xsl:if>
        </div>
    </xsl:template>

</xsl:stylesheet>
