<!--                                                                  -->
<!--  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="productType" select="/Root/Form/TypeList/Type[ProductTypeID = /Root/Form/Product/ProductTypeID]/Type" />

    <xsl:template name="productShowLayout">
        <div class="section">
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Product successfully updated!</xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="albumView" />
            <br />
            <xsl:call-template name="productShow" />
            <br />
            <xsl:if test="Access/rps/price/edit = 1 or /Root/Client/ClientID = 338">
                <xsl:call-template name="priceShow" />
                <br />
            </xsl:if>
            <xsl:call-template name="trackListShow" />
            <br /><br />
        </div>
        <xsl:call-template name="buttons" />
    </xsl:template>

    <xsl:template name="productShow">
        <fieldset>
            <legend>Product</legend>
            <div class="insideFieldset">
                <xsl:call-template name="column1Show" />
                <xsl:call-template name="column2Show" />
            </div>
        </fieldset>
    </xsl:template>

    <xsl:template name="column1Show">
        <div class="column1">
            <table>
                <tr>
                    <td class="leftCol"><label for="Form_Product_ProductTypeID">Type:</label></td>
                    <xsl:choose>
                        <xsl:when test="/Root/Client/ClientID = 338">
                            <td>
                                <xsl:variable name="EMIReleaseTypeCode" select="/Root/Form/Product/EMIReleaseTypeCode" />
                                <xsl:choose>
                                    <xsl:when test="$EMIReleaseTypeCode = 26">Digital Media (Audio Album)</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 27">Digital Media (Multi-track Audio Single)</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 28">Digital Media (Multi-track Video Album)</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 29">Digital Media (One-track Recording)</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 34">Ringtune Clip</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 40">Digital Media (Single-track Video)</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 42">Digital Graphics Product</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 43">Digital Box Set</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 44">Ring Video</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 45">Digital Media (Longform Video Album)</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 46">Digital Media (Multi-track Video Single)</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 48">Mobile Application</xsl:when>
                                    <xsl:when test="$EMIReleaseTypeCode = 51">Digital Alert Tone</xsl:when>
                                    <xsl:otherwise><xsl:value-of select="$EMIReleaseTypeCode" /></xsl:otherwise>
                                </xsl:choose>
                            </td>
                        </xsl:when>
                        <xsl:otherwise>
                            <td><xsl:value-of select="Form/TypeList/Type[ProductTypeID = /Root/Form/Product/ProductTypeID]/Description" /></td>
                        </xsl:otherwise>
                    </xsl:choose>
                </tr>
                <tr>
                    <td class="leftCol"><label for="Form_Product_ProductID">Product ID:</label></td>
                    <td>
                        <xsl:value-of select="Form/Product/ProductCode" />
                    </td>
                </tr>
                <tr>
                    <td class="leftCol"><label for="Form_Product_UPC">
                        <xsl:choose>
                            <xsl:when test="/Root/Client/ClientID = 338">Digital ICPN:</xsl:when>
                            <xsl:otherwise>UPC:</xsl:otherwise>
                        </xsl:choose>
                    </label></td>
                    <td>
                        <xsl:value-of select="Form/Product/UPC" />
                    </td>
                </tr>
            </table>
        </div>
    </xsl:template>

    <xsl:template name="column2Show">
        <div class="column2">
            <table>
                <tr>
                    <td class="leftCol"><label for="Form_Product_ReleaseDate">Release Date:</label></td>
                    <td><xsl:value-of select="Form/Product/ReleaseDate" /></td>
                </tr>

                <tr>
                    <td class="leftCol"><label for="Form_Product_ProductStatusID">Status:</label></td>
                    <td>
                        <xsl:for-each select="Form/StatusList/Status[ProductStatusID = /Root/Form/Product/ProductStatusID]">
                            <xsl:value-of select="Description" />
                        </xsl:for-each>
                    </td>
                </tr>

                <xsl:if test="ClientTypes/ClientType[ClientTypeID = 6]/IsClientTypeFlag = 1">
                    <tr>
                        <td class="leftCol">Deleted:</td>
                        <td>
                            <xsl:choose>
                                <xsl:when test="Form/Product/Deleted = 0">
                                    No
                                </xsl:when>
                                <xsl:otherwise>
                                    Yes&#160;&#160;<strong>Deletion Date:</strong>&#160;<xsl:value-of select="Form/Product/DeletedDate" />
                                </xsl:otherwise>
                            </xsl:choose>
                        </td>
                    </tr>
                </xsl:if>

            </table>
        </div>
    </xsl:template>

    <xsl:template name="priceShow">
        <fieldset>
            <legend>Prices</legend>
            <xsl:variable name="priceTest">
                <xsl:for-each select="Form/PriceLevelList/PriceLevel[Type = $productType]">
                    <xsl:variable name="priceLevelID" select="PriceLevelID" />
                    <xsl:for-each select="/Root/Form/Product/PriceList/Price[PriceLevelID = $priceLevelID]">
                        <xsl:value-of select="PriceID" />
                    </xsl:for-each>
                </xsl:for-each>
            </xsl:variable>
            <xsl:choose>
                <xsl:when test="normalize-space($priceTest)">
                    <div class="column1">
                        <table>
                            <xsl:choose>
                                <xsl:when test="Form/TypeList/Type[ProductTypeID = /Root/Form/Product/ProductTypeID]/Type = 1">
                                    <xsl:for-each select="Form/PriceLevelList/PriceLevel[Type = 1]">
                                        <xsl:call-template name="priceLevelRowShow" />
                                    </xsl:for-each>
                                    <tr>
                                        <td class="leftCol"><label for="Form_Product_DefaultPriceLevelID">Default:</label></td>
                                        <td>
                                            <xsl:for-each select="Form/PriceLevelList/PriceLevel[Type = 1]">
                                                <xsl:if test="PriceLevelID = /Root/Form/Product/DefaultPriceLevelID">
                                                    <xsl:value-of select="Name" />
                                                </xsl:if>
                                            </xsl:for-each>
                                        </td>
                                    </tr>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:for-each select="Form/PriceLevelList/PriceLevel[Type != 1]">
                                        <xsl:choose>
                                            <xsl:when test="/Root/Client/ClientID = 338">
                                                <xsl:call-template name="EMIpriceLevelRowShow" />
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:call-template name="priceLevelRowShow" />
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:for-each>
                                </xsl:otherwise>
                            </xsl:choose>
                        </table>
                    </div>
                </xsl:when>
                <xsl:otherwise>
                    <div class="insideFieldset">
                        No price information has been entered.
                    </div>
                </xsl:otherwise>
            </xsl:choose>
        </fieldset>
    </xsl:template>

    <!-- Going to try and re-write this template to deal with multiple prices per price level. -->
    <xsl:template name="EMIpriceLevelRowShow">
        <xsl:variable name="priceLevelID" select="PriceLevelID" />
        <xsl:variable name="priceLevelName" select="Name" />
        <xsl:if test="normalize-space(/Root/Form/Product/PriceList/Price[PriceLevelID = $priceLevelID]/ProductPriceID)">
            <td class="leftCol"><label for="Form_Product_PriceList_Price_{@i}_PriceID"><xsl:value-of select="$priceLevelName" />:</label></td>
            <td></td>
            <xsl:for-each select="/Root/Form/Product/PriceList/Price[PriceLevelID = $priceLevelID]">
                <xsl:variable name="priceID" select="PriceID" />
                <tr>
                    <td class="leftCol"><xsl:value-of select="/Root/Form/PriceList/Price[PriceID = $priceID]/Name" /></td>
                    <td>
                        (<xsl:value-of select="/Root/Form/PriceList/Price[PriceID = $priceID]/CurrencyCode" />)
                        <xsl:value-of select="/Root/Form/PriceList/Price[PriceID = $priceID]/Wholesale" />
                    </td>
                </tr>
            </xsl:for-each>

        </xsl:if>
    </xsl:template>

    <xsl:template name="priceLevelRowShow">
        <xsl:variable name="priceLevelID" select="PriceLevelID" />
        <xsl:if test="normalize-space(/Root/Form/Product/PriceList/Price[PriceLevelID = $priceLevelID]/ProductPriceID)">
            <tr>
                <td class="leftCol"><label for="Form_Product_PriceList_Price_{@i}_PriceID"><xsl:value-of select="Name" />:</label></td>
                <td>
                    <xsl:for-each select="/Root/Form/PriceList/Price">
                        <xsl:if test="PriceID = /Root/Form/Product/PriceList/Price[PriceLevelID = $priceLevelID]/PriceID">
                            <xsl:call-template name="formatDollars">
                                <xsl:with-param name="dollarAmount" select="Retail" />
                            </xsl:call-template>
                        </xsl:if>
                    </xsl:for-each>
                </td>
            </tr>
        </xsl:if>
    </xsl:template>

    <xsl:template name="trackListShow">
        <xsl:variable name="includedTracks" select="count(/Root/Form/Product/TrackList/Track[Included = 1])" />
        <fieldset id="productTrackTableShow">
            <legend>Tracks</legend>
            <xsl:choose>
                <xsl:when test="$includedTracks &gt; 0">
                    <table class="textChart">
                        <tbody>
                            <tr>
                                <th id="trackIncl">Status</th>
                                <xsl:if test="$showAlbumPurchaseOnly = 1">
                                    <th id="trackAlbumOnly" class="status">Album Purchase Only</th>
                                </xsl:if>
                                <th id="trackNum">Track</th>
                                <th id="trackName">Name</th>
                                <th id="trackLength">Length</th>
                                <th>Media Type</th>
                                <xsl:if test="/Root/Client/ClientID = 338">
                                    <th>Price Category</th>
                                </xsl:if>
                                <th id="discNum">Disc #</th>
                                <th id="discTrack">Disc Track</th>
                            </tr>
                            <xsl:for-each select="/Root/Form/Product/TrackList/Track[Included = 1]">
                                <xsl:call-template name="trackListShowRow" />
                            </xsl:for-each>
                        </tbody>
                    </table>
                </xsl:when>
                <xsl:otherwise>
                    <div class="insideFieldset">
                        No tracks have been included for this product.
                    </div>
                </xsl:otherwise>
            </xsl:choose>
        </fieldset>
    </xsl:template>

    <xsl:template name="trackListShowRow">
        <xsl:variable name="trackID" select="TrackID" />
        <tr class="row{position() mod 2}">
            <td class="trackStatus">
                <xsl:if test="Included = 1 and IsBonusTrack != 1">Included</xsl:if>
                <xsl:if test="IsBonusTrack = 1">Bonus</xsl:if>
            </td>
            <xsl:if test="$showAlbumPurchaseOnly = 1">
                <td class="status">
                    <xsl:choose>
                        <xsl:when test="AlbumOnly &gt; 0">Yes</xsl:when>
                        <xsl:otherwise>No</xsl:otherwise>
                    </xsl:choose>
                </td>
            </xsl:if>
            <td class="trackNumber"><xsl:if test="TrackOrder &lt; 10">0</xsl:if><xsl:value-of select="TrackOrder" /></td>
            <td class="trackTitle"><xsl:value-of select="Title" /></td>
            <td class="length"><xsl:value-of select="Duration" /></td>
            <td>
                <xsl:choose>
                    <xsl:when test="MediaType = 2">Video</xsl:when>
                    <xsl:otherwise>Audio</xsl:otherwise>
                </xsl:choose>
            </td>
            <xsl:if test="/Root/Client/ClientID = 338">
                <td><xsl:value-of select="PriceCategory" /></td>
            </xsl:if>
            <td><xsl:value-of select="DiscNumber" /></td>
            <td><xsl:value-of select="DiscTrack" /></td>
        </tr>
        <xsl:if test="IsBonusTrack = 1">
            <tr class="row{position() mod 2}" id="bonus{@i}">
                <td class="servicesShow" colspan="7">
                    <xsl:if test="/Root/Form/Product/ProductDigital/ProductID &gt; 0">
                        <xsl:attribute name="colspan">8</xsl:attribute>
                    </xsl:if>
                    <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>
                </td>
            </tr>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>
