<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<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:variable name="formatType">
        <xsl:for-each select="/Root/Form/TypeList/Type">
            <xsl:if test="ProductTypeID = /Root/Form/Product/ProductTypeID"><xsl:value-of select="Type" /></xsl:if>
        </xsl:for-each>
    </xsl:variable>


    <xsl:variable name="isPhysical">
        <xsl:choose>
            <xsl:when test="/Root/Form/TypeList/Type[ProductTypeID = /Root/Form/Product/ProductTypeID]/Type = 1">1</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>


    <xsl:template name="productEditLayout">
        <script src="/production/javascript/validateProduct.js?v=8" type="text/javascript"></script>
        <form action="/rps/product" name="productEdit" id="productEdit" method="post">
            <input type="hidden" name="formSubmit" value="1" />
            <input type="hidden" name="c" value="edit" />
            <xsl:call-template name="productEdit" />
            <xsl:call-template name="buttons" />
        </form>
    </xsl:template>


    <xsl:template name="productEdit">
        <xsl:if test="normalize-space(Form/Album/AlbumID)">
            <input type="hidden" name="AlbumID" value="{Form/Album/AlbumID}" />
        </xsl:if>
        <xsl:if test="normalize-space(Form/Product/ProductID)">
            <input type="hidden" name="ProductID" value="{Form/Product/ProductID}" />
        </xsl:if>
        <xsl:if test="Params/show_errors">
            <input type="hidden" name="show_errors" value="1" />
        </xsl:if>
        <div class="ProductEdit">
            <xsl:call-template name="openRunStatusMessage" />
            <xsl:call-template name="errorMessageGeneral" />

            <section class="ProductEdit-section Required-notice-wrapper">
                <xsl:call-template name="albumView" />
                <div class="Required-notice" />
            </section>

            <section class="ProductEdit-section">
                <xsl:call-template name="productInfo" />
            </section>

            <section class="ProductEdit-section">
                <xsl:call-template name="priceInfo" />
            </section>

            <section class="ProductEdit-section">
                <xsl:call-template name="servicesHash" />
            </section>

            <section class="ProductEdit-section">
                <xsl:call-template name="trackList" />
            </section>

        </div>
    </xsl:template>


    <xsl:template name="productInfo">
        <fieldset class="Form-fieldset">
            <h2>Product</h2>
            <div class="Form-header">
                <p>Enter product information here.</p>
            </div>

            <div class="InformationCols ProductEdit-product">
                <xsl:call-template name="column1Edit" />
                <xsl:call-template name="column2Edit" />
            </div>
        </fieldset>
    </xsl:template>

    <xsl:template name="column1Edit">
        <div class="InformationCols-item ProductEdit-product-col">

            <script type="text/javascript">
                //setting up product type id/type id hash
                var typeCollection = new Object();
                <xsl:for-each select="Form/TypeList/Type">
                    typeCollection[<xsl:value-of select="ProductTypeID" />] = <xsl:value-of select="Type" />;
                </xsl:for-each>
                //setting up an array of all possible types
                var typeList = new Array();
                <xsl:for-each select="Form/TypeList/Type">
                    typeList[<xsl:value-of select="@i" />] = <xsl:value-of select="Type" />;
                </xsl:for-each>
                //setting up an array of all price levels
                var levelList = new Array();
                <xsl:for-each select="Form/PriceLevelList/PriceLevel">
                    levelList[<xsl:value-of select="@i" />] = <xsl:value-of select="PriceLevelID" />;
                </xsl:for-each>
                //setting up level id/name hash
                var levelNames = new Object();
                <xsl:for-each select="Form/PriceLevelList/PriceLevel">
                    levelNames[<xsl:value-of select="PriceLevelID" />] = '<xsl:value-of select="Name" />';
                </xsl:for-each>
            </script>


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

                <label class="Form-label">
                    <span class="Form-label-caption">Type</span>
                    <div class="Form-input-wrapper">
                        <xsl:variable name="productEditTypeItems">
                            <map>
                                <mapEntry><name>Choose...</name><value></value></mapEntry>
                                <xsl:for-each select="Form/TypeList/Type[ProductTypeID != 15]">
                                    <mapEntry>
                                        <name><xsl:value-of select="Description" /></name>
                                        <value><xsl:value-of select="ProductTypeID" /></value>
                                    </mapEntry>
                                </xsl:for-each>
                            </map>
                        </xsl:variable>
                        <xsl:call-template name="uiDropdown">
                            <xsl:with-param name="items" select="$productEditTypeItems"/>
                            <xsl:with-param name="id" select="'Form_Product_ProductTypeID'"/>
                            <xsl:with-param name="name" select="'Form_Product_ProductTypeID'"/>
                            <xsl:with-param name="active" select="/Root/Form/Product/ProductTypeID"/>
                            <xsl:with-param name="disabled">
                                <xsl:if test="(normalize-space(Form/Product/ProductID) and normalize-space(Form/Product/ProductTypeID) and Form/Product/ProductTypeID != 0) or $openRuns = 1">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="onChange">
                                <xsl:text>updatePriceFields(typeCollection[this.value]); updateAlbumOnly(this.value); restrictBonusTracks(this.value, </xsl:text>
                                <xsl:value-of select="count(Form/Product/TrackList/Track)" />
                                <xsl:text>)</xsl:text>
                            </xsl:with-param>
                        </xsl:call-template>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/Product/ProductTypeID</xsl:with-param>
                    <xsl:with-param name="displayName">Type</xsl:with-param>
                </xsl:call-template>
            </div>

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

                <label class="Form-label">
                    <span class="Form-label-caption">Product Title</span>
                    <div class="Form-input-wrapper">
                        <input type="text" class="Input Form-input" name="Form_Product_Title" id="Form_Product_Title" value="{Form/Product/Title}" >
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
                        </input>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/Product/Title</xsl:with-param>
                    <xsl:with-param name="displayName">Product Title</xsl:with-param>
                </xsl:call-template>
            </div>

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

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


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

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

    <xsl:template name="column2Edit">
        <div class="InformationCols-item ProductEdit-product-col">
            <div class="Form-item">
                <xsl:if test="Form/Product/ReleaseDate[@e]">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item Form-item-error</xsl:text>
                    </xsl:attribute>
                </xsl:if>

                <label class="Form-label">
                    <span class="Form-label-caption">Release Date</span>
                    <div class="Form-input-wrapper">
                        <xsl:call-template name="uiDatepicker">
                            <xsl:with-param name="id" select="'Form_Product_ReleaseDate'" />
                            <xsl:with-param name="name" select="'Form_Product_ReleaseDate'" />
                            <xsl:with-param name="value">
                                <xsl:choose>
                                    <xsl:when test="normalize-space(Form/Product/ReleaseDate)">
                                        <xsl:value-of select="Form/Product/ReleaseDate" />
                                    </xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="Form/TodaysDate" />
                                    </xsl:otherwise>
                                </xsl:choose>
                            </xsl:with-param>

                            <xsl:with-param name="disabled">
                                <xsl:if test="$openRuns = 1">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/Product/ReleaseDate</xsl:with-param>
                    <xsl:with-param name="displayName">Release Date</xsl:with-param>
                </xsl:call-template>
            </div>

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

                <label class="Form-label">
                    <span class="Form-label-caption">Status</span>
                    <div class="Form-input-wrapper">
                        <xsl:variable name="productEditStatusItems">
                            <map>
                                <xsl:for-each select="Form/StatusList/Status">
                                    <mapEntry>
                                        <name><xsl:value-of select="Description" /></name>
                                        <value><xsl:value-of select="ProductStatusID" /></value>
                                    </mapEntry>
                                </xsl:for-each>
                            </map>
                        </xsl:variable>
                        <xsl:call-template name="uiDropdown">
                            <xsl:with-param name="items" select="$productEditStatusItems"/>
                            <xsl:with-param name="id" select="'Form_Product_ProductStatusID'"/>
                            <xsl:with-param name="name" select="'Form_Product_ProductStatusID'"/>
                            <xsl:with-param name="active" select="/Root/Form/Product/ProductStatusID"/>
                            <xsl:with-param name="disabled">
                                <xsl:if test="$openRuns = 1">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                        </xsl:call-template>
                    </div>
                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/Product/ProductStatusID</xsl:with-param>
                    <xsl:with-param name="displayName">Status</xsl:with-param>
                </xsl:call-template>
            </div>

            <xsl:if test="ClientTypes/ClientType[ClientTypeID = 6]/IsClientTypeFlag = 1">

                <div class="Form-item">
                    <xsl:if test="Form/Product/Deleted[@e] or Form/Product/DeletedDate[@e]">
                        <xsl:attribute name="class">
                            <xsl:text>Form-item Form-item-error</xsl:text>
                        </xsl:attribute>
                    </xsl:if>
                    <label class="Form-label">
                        <span class="Form-label-caption">Deleted</span>
                        <div class="Form-input-wrapper">
                            <xsl:variable name="productEditDeletedItems">
                                <map>
                                    <mapEntry>
                                        <name>No</name>
                                        <value></value>
                                    </mapEntry>
                                    <mapEntry>
                                        <name>Yes</name>
                                        <value>1</value>
                                    </mapEntry>
                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$productEditDeletedItems"/>
                                <xsl:with-param name="id" select="'Form_Product_Deleted'"/>
                                <xsl:with-param name="name" select="'Form_Product_Deleted'"/>
                                <xsl:with-param name="active" select="Form/Product/Deleted"/>
                                <xsl:with-param name="disabled">
                                    <xsl:if test="$openRuns = 1">
                                        <xsl:text>true</xsl:text>
                                    </xsl:if>
                                </xsl:with-param>
                                <xsl:with-param name="onChange">
                                    <xsl:text>checkDeleted(this.value)</xsl:text>
                                </xsl:with-param>
                            </xsl:call-template>
                        </div>
                    </label>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Form/Product/Deleted</xsl:with-param>
                        <xsl:with-param name="displayName">Deleted</xsl:with-param>
                    </xsl:call-template>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Form/Product/DeletedDate</xsl:with-param>
                        <xsl:with-param name="displayName">Deletion Date</xsl:with-param>
                    </xsl:call-template>
                </div>

                <xsl:variable name="disableDeletionDate">
                    <xsl:if test="Form/Product/Deleted != 1 or not(normalize-space(Form/Product/Deleted))">1</xsl:if>
                </xsl:variable>

                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">Deletion Date</span>
                        <div class="Form-input-wrapper">

                            <xsl:call-template name="uiDatepicker">
                                <xsl:with-param name="id" select="'Form_Product_DeletedDate'" />
                                <xsl:with-param name="name" select="'Form_Product_DeletedDate'" />
                                <xsl:with-param name="value" select="Form/Product/DeletedDate" />

                                <xsl:with-param name="disabled">
                                    <xsl:if test="$disableDeletionDate = 1 or $openRuns = 1">
                                        <xsl:text>true</xsl:text>
                                    </xsl:if>
                                </xsl:with-param>
                                <xsl:with-param name="readonly">
                                    <xsl:if test="$disableDeletionDate = 1 or $openRuns = 1">
                                        <xsl:text>true</xsl:text>
                                    </xsl:if>
                                </xsl:with-param>
                                <xsl:with-param name="iconId" select="'calendarIcon'" />
                            </xsl:call-template>

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

    <xsl:template name="priceInfo">
        <fieldset class="Form-fieldset">
            <h2>Prices</h2>
            <div class="Form-header">
                <p class="ProductEdit-prices-form-header">
                    <xsl:choose>
                        <xsl:when test="$formatType != ''">
                            <xsl:text>Enter price information here.</xsl:text>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text>Choose product type first.</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                </p>
            </div>
            <div class="InformationCols">
                <div class="ProductEdit-prices InformationCols-item">
                    <xsl:attribute name="class">
                        <xsl:text>ProductEdit-prices InformationCols-item</xsl:text>
                        <xsl:if test="$formatType != ''">
                            <xsl:text> ProductEdit-prices-type</xsl:text><xsl:value-of select="$formatType" />
                        </xsl:if>
                    </xsl:attribute>
                    <div class="ProductEdit-prices-wrapper">
                        <xsl:call-template name="column1PriceEdit" />
                        <xsl:call-template name="column2PriceEdit" />
                    </div>
                </div>
            </div>
        </fieldset>
    </xsl:template>

    <xsl:template name="column1PriceEdit">
        <div class="ProductEdit-prices-col ProductEdit-prices-col-type1">
            <xsl:for-each select="Form/PriceLevelList/PriceLevel[Type = 1]">
                <xsl:call-template name="priceLevelRow" />
            </xsl:for-each>

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

                <label class="Form-label">
                    <span class="Form-label-caption">Default</span>
                    <div class="Form-input-wrapper">
                        <xsl:variable name="productEditPricesItems">
                            <map>
                                <mapEntry><name>Choose...</name><value></value></mapEntry>
                                <xsl:for-each select="Form/PriceLevelList/PriceLevel[Type = 1]">
                                    <mapEntry>
                                        <name><xsl:value-of select="Name" /></name>
                                        <value><xsl:value-of select="PriceLevelID" /></value>
                                    </mapEntry>
                                </xsl:for-each>
                            </map>
                        </xsl:variable>
                        <xsl:call-template name="uiDropdown">
                            <xsl:with-param name="items" select="$productEditPricesItems"/>
                            <xsl:with-param name="selectClassName" select="'type1'"/>
                            <xsl:with-param name="id" select="'Form_Product_ProductStatusID'"/>
                            <xsl:with-param name="name" select="'Form_Product_DefaultPriceLevelID'"/>
                            <xsl:with-param name="active" select="/Root/Form/Product/DefaultPriceLevelID"/>
                            <xsl:with-param name="disabled">
                                <xsl:if test="$formatType != 1 or $formatType = '' or $openRuns = 1">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="onChange">
                                <xsl:text>defaultPriceLevel(this.value)</xsl:text>
                            </xsl:with-param>
                        </xsl:call-template>
                    </div>

                    <xsl:for-each select="Form/PriceLevelList/PriceLevel[Type = 1]">
                        <xsl:if test="PriceLevelID = /Root/Form/Product/DefaultPriceLevelID">
                            <script type="text/javascript">
                                requirePriceField(<xsl:value-of select="PriceLevelID" />,'Form_Product_PriceList_Price_<xsl:value-of select="PriceLevelID - 1" />_PriceID');
                            </script>
                        </xsl:if>
                    </xsl:for-each>

                </label>
                <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/Product/DefaultPriceLevelID</xsl:with-param>
                    <xsl:with-param name="displayName">Default</xsl:with-param>
                </xsl:call-template>
            </div>
        </div>
    </xsl:template>

    <xsl:template name="column2PriceEdit">
        <div class="ProductEdit-prices-col ProductEdit-prices-col-type2">
            <xsl:for-each select="Form/PriceLevelList/PriceLevel[Type = 2]">
                <xsl:call-template name="priceLevelRow" />
            </xsl:for-each>
        </div>
    </xsl:template>

    <xsl:template name="priceLevelRow">
        <xsl:variable name="priceLevelID" select="PriceLevelID" />

        <div class="Form-item">
            <xsl:if test="Form/Product/PriceList/Price/@i/PriceID[@e]">
                <xsl:attribute name="class">
                    <xsl:text>Form-item Form-item-error</xsl:text>
                </xsl:attribute>
            </xsl:if>

            <label class="Form-label">
                <span class="Form-label-caption"><xsl:value-of select="Name" /></span>
                <div class="Form-input-wrapper">
                    <xsl:variable name="productEditPricesListItems">
                        <map>
                            <mapEntry><name>Choose...</name><value></value></mapEntry>
                            <xsl:for-each select="/Root/Form/PriceList/Price">
                                <mapEntry>
                                    <name>
                                        <xsl:value-of select="Name" />
                                        (<xsl:call-template name="formatDollars">
                                        <xsl:with-param name="dollarAmount" select="Retail" />
                                        </xsl:call-template>)
                                    </name>
                                    <value><xsl:value-of select="PriceID" /></value>
                                    <selected>
                                        <xsl:if test="PriceID = /Root/Form/Product/PriceList/Price[PriceLevelID = $priceLevelID]/PriceID">
                                            <xsl:text>true</xsl:text>
                                        </xsl:if>
                                    </selected>
                                </mapEntry>
                            </xsl:for-each>
                        </map>
                    </xsl:variable>
                    <xsl:call-template name="uiDropdown">
                        <xsl:with-param name="items" select="$productEditPricesListItems"/>
                        <xsl:with-param name="name">
                            <xsl:text>Form_Product_PriceList_Price_</xsl:text>
                            <xsl:value-of select="@i" />
                            <xsl:text>_PriceID</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="id">
                            <xsl:text>Form_Product_PriceList_Price_</xsl:text>
                            <xsl:value-of select="@i" />
                            <xsl:text>_PriceID</xsl:text>
                        </xsl:with-param>

                        <xsl:with-param name="selectClassName">
                            <xsl:text>type</xsl:text><xsl:value-of select="Type" />
                        </xsl:with-param>

                        <xsl:with-param name="disabled">
                            <xsl:if test="$formatType != Type or $formatType = '' or $openRuns = 1">
                                <xsl:text>true</xsl:text>
                            </xsl:if>
                        </xsl:with-param>
                        <xsl:with-param name="onChange">
                            <xsl:text>defaultPriceLevel(this.value)</xsl:text>
                        </xsl:with-param>
                    </xsl:call-template>
                </div>

            </label>
            <xsl:call-template name="inlineError">
                <xsl:with-param name="path">Form/Product/PriceList/Price/<xsl:value-of select="@i" />/PriceID</xsl:with-param>
                <xsl:with-param name="displayName"><xsl:value-of select="Name" /></xsl:with-param>
            </xsl:call-template>
        </div>

</xsl:template>


<xsl:template name="servicesHash">
    <input type="hidden" name="serviceCount" id="serviceCount" value="{Form/ServiceList/Service/@size}" />
    <script type="text/javascript">
        //setting up service id/service name hash
        var serviceCollection = new Object();
        <xsl:for-each select="Form/ServiceList/Service">
            serviceCollection[<xsl:value-of select="ServiceID" />] = '<xsl:call-template name="escapeJavascript"><xsl:with-param name="string" select="ServiceName" /></xsl:call-template>';
        </xsl:for-each>

        updatePriceFields('<xsl:value-of select="$formatType"/>');
    </script>
</xsl:template>


<xsl:template name="trackList">
    <fieldset class="Form-fieldset" id="productTrackTable">
        <h2>Tracks</h2>
        <xsl:call-template name="trackErrorMessages" />
        <table class="Table">
            <thead>
                <tr class="Table-row Table-row-header">
                    <th class="Table-col" id="trackIncl">Status</th>
                    <xsl:if test="$showAlbumPurchaseOnly = 1">
                        <th class="Table-col" id="trackAlbumOnly">
                            Album Purchase Only
                            <xsl:call-template name="helpIcon">
                                <xsl:with-param name="tip">
                                    &lt;span style="font-weight: normal"&gt;
                                    Some retailers do not accept album purchase only.
                                    <xsl:value-of select="$tipBreak" />
                                    <xsl:value-of select="$tipBreak" />
                                    &lt;b&gt;If you don't want your album delivered to those retailers, you
                                    <xsl:value-of select="$tipBreak" />
                                    must deselect the &quot;approved for delivery&quot; checkbox in the
                                    <xsl:value-of select="$tipBreak" />
                                    album distribution settings page.&lt;/b&gt;
                                    <xsl:value-of select="$tipBreak" />
                                    <xsl:value-of select="$tipBreak" />
                                    Retailers that accept album purchase only tracks are 24/7 Entertainment,
                                    <xsl:value-of select="$tipBreak" />
                                    Amazon, DJ Download, Juno, Liquid, MediaNet, MySpace Music, Napster,
                                    <xsl:value-of select="$tipBreak" />
                                    Nokia, Rhapsody, Shockhound/HotTopic, and Trackitdown.
                                    &lt;/span&gt;
                                </xsl:with-param>
                            </xsl:call-template>
                        </th>
                    </xsl:if>
                    <th class="Table-col" id="trackNum">Track</th>
                    <th class="Table-col" id="trackName">Name</th>
                    <th class="Table-col" id="trackLength">Length</th>
                    <th class="Table-col">Media&#160;Type</th>
                    <th class="Table-col" id="discNum">*Disc&#160;#</th>
                    <th class="Table-col" id="discTrack">*Disc&#160;Track</th>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="/Root/Form/Product/TrackList/Track">
                    <xsl:call-template name="trackListRow" />
                </xsl:for-each>
            </tbody>
        </table>
    </fieldset>
</xsl:template>

<xsl:template name="trackListRow">
    <xsl:variable name="trackPrefix">Form_Product_TrackList_Track_<xsl:value-of select="@i" />_</xsl:variable>
    <xsl:variable name="trackID" select="TrackID" />

    <tr class="Table-row Table-row-data Table-row-inputs">
        <xsl:call-template name="uiEvenOddTrClass">
            <xsl:with-param name="className" select="'Table-row-inputs'"/>
            <xsl:with-param name="position" select="position()"/>
        </xsl:call-template>

        <input type="hidden" name="{$trackPrefix}TrackID" value="{$trackID}" />
        <td class="Table-col">
            <xsl:variable name="productEditTrackStatusItems">
                <map>
                    <mapEntry>
                        <name>Included</name>
                        <value>Included</value>
                        <selected>
                            <xsl:if test="not(/Root/Params/ProductID) or Included = 1">
                                <xsl:text>true</xsl:text>
                            </xsl:if>
                        </selected>
                    </mapEntry>
                    <mapEntry>
                        <name>Not Included</name>
                        <value>Not</value>
                        <selected>
                            <xsl:if test="/Root/Params/ProductID and (Included = 0 or Included = '')">
                                <xsl:text>true</xsl:text>
                            </xsl:if>
                        </selected>
                    </mapEntry>
                </map>
            </xsl:variable>
            <xsl:call-template name="uiDropdown">
                <xsl:with-param name="items" select="$productEditTrackStatusItems"/>
                <xsl:with-param name="className" select="'ProductEdit-track-status-dropdown'"/>
                <xsl:with-param name="selectClassName">
                    type<xsl:value-of select="Type"/>
                </xsl:with-param>
                <xsl:with-param name="id">
                    <xsl:text>Included_Options_</xsl:text>
                    <xsl:value-of select="@i" />
                </xsl:with-param>
                <xsl:with-param name="name">
                    <xsl:text>Included_Options_</xsl:text>
                    <xsl:value-of select="@i" />
                </xsl:with-param>

                <xsl:with-param name="disabled">
                    <xsl:if test="$openRuns = 1">
                        <xsl:text>true</xsl:text>
                    </xsl:if>
                </xsl:with-param>
                <xsl:with-param name="onChange">
                    <xsl:text>modifyProductTrack(this.value, </xsl:text>
                    <xsl:value-of select="@i" />
                    <xsl:text>)</xsl:text>
                </xsl:with-param>
            </xsl:call-template>

            <input type="hidden" name="{$trackPrefix}Included" id="{$trackPrefix}Included">
                <xsl:attribute name="value">
                    <xsl:choose>
                        <xsl:when test="not(/Root/Params/ProductID) or Included = 1">1</xsl:when>
                        <xsl:otherwise>0</xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
            </input>
            <input type="hidden" name="{$trackPrefix}IsBonusTrack" id="{$trackPrefix}IsBonusTrack">
                <xsl:attribute name="value">
                    <xsl:choose>
                        <xsl:when test="IsBonusTrack = 1">1</xsl:when>
                        <xsl:otherwise>0</xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
            </input>
        </td>

        <xsl:if test="$showAlbumPurchaseOnly = 1">
            <td class="Table-col">
                <xsl:variable name="productEditTrackStatusItems">
                    <map>
                        <mapEntry>
                            <name>No</name>
                            <value>0</value>
                            <selected>
                                <xsl:if test="not(AlbumOnly)">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </selected>
                        </mapEntry>
                        <mapEntry>
                            <name>Yes</name>
                            <value>1</value>
                            <selected>
                                <xsl:if test="AlbumOnly &gt; 0">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </selected>
                        </mapEntry>
                    </map>
                </xsl:variable>
                <xsl:call-template name="uiDropdown">
                    <xsl:with-param name="items" select="$productEditTrackStatusItems"/>
                    <xsl:with-param name="selectClassName" select="'albumOnlyField'" />
                    <xsl:with-param name="className" select="'ProductEdit-track-status-dropdown'"/>
                    <xsl:with-param name="id">
                        <xsl:value-of select="$trackPrefix" />
                        <xsl:text>AlbumOnly</xsl:text>
                    </xsl:with-param>
                    <xsl:with-param name="name">
                        <xsl:value-of select="$trackPrefix" />
                        <xsl:text>AlbumOnly</xsl:text>
                    </xsl:with-param>


                    <xsl:with-param name="disabled">
                        <xsl:if test="$openRuns = 1">
                            <xsl:text>true</xsl:text>
                        </xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="onChange">
                        <xsl:text>modifyProductTrack(this.value, </xsl:text>
                        <xsl:value-of select="@i" />
                        <xsl:text>)</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </td>
        </xsl:if>

        <td class="Table-col"><xsl:if test="TrackOrder &lt; 10">0</xsl:if><xsl:value-of select="TrackOrder" /></td>
        <td class="Table-col"><xsl:value-of select="Title" /></td>
        <td class="Table-col"><xsl:value-of select="Duration" /></td>
        <td class="Table-col">
            <xsl:choose>
                <xsl:when test="MediaType = 2">Video</xsl:when>
                <xsl:otherwise>Audio</xsl:otherwise>
            </xsl:choose>
        </td>
        <td class="Table-col">
            <div class="Form-item ProductEdit-disc-number-input">
                <xsl:if test="DiscNumber/@e">
                    <xsl:attribute name="class">Form-item Form-item-error</xsl:attribute>
                </xsl:if>
                <div class="Form-input-wrapper">
                    <input type="text" class="Input Form-input" name="{$trackPrefix}DiscNumber" id="{$trackPrefix}DiscNumber">
                        <xsl:attribute name="value">
                            <xsl:choose>
                                <xsl:when test="normalize-space(DiscNumber)">
                                    <xsl:value-of select="DiscNumber" />
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="NextDiscNumber" />
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:if test="/Root/Params/ProductID and Included != 1 and IsBonusTrack != 1 or $openRuns = 1">
                            <xsl:attribute name="disabled">disabled</xsl:attribute>
                        </xsl:if>
                    </input>
                </div>
            </div>
        </td>
        <td class="Table-col">
            <div class="Form-item ProductEdit-disc-track-input">
                <xsl:if test="DiscTrack/@e">
                    <xsl:attribute name="class">Form-item Form-item-error</xsl:attribute>
                </xsl:if>
                <div class="Form-input-wrapper">
                    <input type="text" class="Input Form-input" name="{$trackPrefix}DiscTrack" id="{$trackPrefix}DiscTrack">
                        <xsl:attribute name="value">
                            <xsl:choose>
                                <xsl:when test="normalize-space(DiscTrack)">
                                    <xsl:value-of select="DiscTrack" />
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="NextDiscTrack" />
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:if test="/Root/Params/ProductID and Included != 1 and IsBonusTrack != 1 or $openRuns = 1">
                            <xsl:attribute name="disabled">disabled</xsl:attribute>
                        </xsl:if>
                    </input>
                </div>
            </div>
        </td>
    </tr>
    <tr id="bonus{@i}" class="Table-row Table-row-data">
        <xsl:if test="IsBonusTrack = 0 or IsBonusTrack = ''">
            <xsl:attribute name="style">display: none</xsl:attribute>
        </xsl:if>

        <xsl:call-template name="uiEvenOddTrClass">
            <xsl:with-param name="position" select="position()"/>
        </xsl:call-template>
        <td class="Table-col" colspan="7">
            <xsl:if test="$showAlbumPurchaseOnly = 1">
                <xsl:attribute name="colspan">8</xsl:attribute>
            </xsl:if>

            <xsl:variable name="productEditDonusButtonAttr">
                <map>
                    <mapEntry>
                        <name>data-track</name>
                        <value><xsl:value-of select="@i"/></value>
                    </mapEntry>
                </map>
            </xsl:variable>

            <!-- JS for button path '\src\js\rps\product.js' -->
            <xsl:call-template name="uiButton">
                <xsl:with-param name="content" select="'Edit Services'" />
                <xsl:with-param name="id" select="'launchBonus'" />
                <xsl:with-param name="name" select="'launchBonus'" />
                <xsl:with-param name="className" select="'js-product-edit-bonus-button'" />
                <xsl:with-param name="dataAttrs" select="$productEditDonusButtonAttr" />
                <xsl:with-param name="disabled">
                    <xsl:if test="$openRuns = 1">
                        <xsl:text>true</xsl:text>
                    </xsl:if>
                </xsl:with-param>
            </xsl:call-template>
            <div class="ProductEdit-service-list">
                <strong>Services:</strong><xsl:text> </xsl:text>
                <span id="serviceList{@i}">
                    <xsl:variable name="serviceTest">
                        <xsl:for-each select="BonusTrackList/BonusTrack">
                            <xsl:if test="normalize-space(ServiceID)"><xsl:value-of select="ServiceID" /></xsl:if>
                        </xsl:for-each>
                    </xsl:variable>
                    <xsl:choose>
                        <xsl:when test="normalize-space($serviceTest)">
                            <xsl:for-each select="BonusTrackList/BonusTrack">
                                <xsl:sort select="ServiceName" />
                                <xsl:variable name="serviceID" select="ServiceID" />
                                <xsl:if test="position() != 1">, </xsl:if>
                                <xsl:value-of select="/Root/Form/ServiceList/Service[ServiceID = $serviceID]/ServiceName" />
                            </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>None</xsl:otherwise>
                    </xsl:choose>
                </span>
            </div>
            <div id="bonusFields{@i}">
                <xsl:for-each select="BonusTrackList/BonusTrack">
                    <input type="hidden" name="{$trackPrefix}BonusTrackList_BonusTrack_{ServiceID}_ServiceID" id="{$trackPrefix}BonusTrackList_BonusTrack_{ServiceID}_ServiceID" value="{ServiceID}" />
                    <input type="hidden" name="{$trackPrefix}BonusTrackList_BonusTrack_{ServiceID}_DateStart" id="{$trackPrefix}BonusTrackList_BonusTrack_{ServiceID}_DateStart" value="{DateStart}" />
                    <input type="hidden" name="{$trackPrefix}BonusTrackList_BonusTrack_{ServiceID}_DateEnd" id="{$trackPrefix}BonusTrackList_BonusTrack_{ServiceID}_DateEnd" value="{DateEnd}" />
                </xsl:for-each>
            </div>
        </td>
    </tr>
</xsl:template>

<xsl:template name="trackErrorMessages">
    <xsl:if test="Form/Product/TrackList/Track/*[@e or @emsg]">
        <div class="error" id="trackErrorTop">
            <xsl:if test="Form/Product/TrackList/Track/DiscNumber[@e = 'field_blank']">Disc Number cannot be blank.<br /></xsl:if>
            <xsl:if test="Form/Product/TrackList/Track/DiscTrack[@e = 'field_blank']">Disc Track cannot be blank.<br /></xsl:if>
            <xsl:if test="Form/Product/TrackList/Track/DiscNumber[@e = 'field_invalid']">Disc Number is invalid.<br /></xsl:if>
            <xsl:if test="Form/Product/TrackList/Track/DiscTrack[@e = 'field_invalid']">Disc Track is invalid.<br /></xsl:if>
            <xsl:if test="Form/Product/TrackList/Track/DiscNumber[@emsg]">Disc Number must be between 1 and 99.<br /></xsl:if>
            <xsl:if test="Form/Product/TrackList/Track/DiscTrack[@emsg]">Disc Track must be between 1 and 99.<br /></xsl:if>
        </div>
        <br />
    </xsl:if>
</xsl:template>

</xsl:stylesheet>
