<!--                                                                  -->
<!--  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:output method="html" indent="no" doctype-system="" encoding="utf-8" />

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


    <xsl:variable name="physicalProduct">
        <xsl:choose>
            <xsl:when test="Root/Sale/ProductType = 'A'">0</xsl:when>
            <xsl:when test="Root/Sale/ProductType = 'T'">0</xsl:when>
            <xsl:otherwise>1</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="showTypeCol">
        <xsl:choose>
            <xsl:when test="Root/Sale/ProductType = 'T'">1</xsl:when>
            <xsl:when test="$physicalProduct = 1">1</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="saleProductType">
        <xsl:if test="Root/Sale/ProductType = 'A'">Album</xsl:if>
        <xsl:if test="Root/Sale/ProductType = 'T'">Track</xsl:if>
        <xsl:if test="Root/Sale/ProductType = '1'">LP</xsl:if>
        <xsl:if test="Root/Sale/ProductType = '2'">CD</xsl:if>
        <xsl:if test="Root/Sale/ProductType = '3'">VHS</xsl:if>
        <xsl:if test="Root/Sale/ProductType = '4'">CASS</xsl:if>
        <xsl:if test="Root/Sale/ProductType = '5'">VCD</xsl:if>
        <xsl:if test="Root/Sale/ProductType = '7'">7"</xsl:if>
        <xsl:if test="Root/Sale/ProductType = '8'">MiniDisc</xsl:if>
        <xsl:if test="Root/Sale/ProductType = '9'">DVD</xsl:if>
        <xsl:if test="Root/Sale/ProductType = 'C'">CD5</xsl:if>
        <xsl:if test="Root/Sale/ProductType = 'D'">DVDCD</xsl:if>
        <xsl:if test="Root/Sale/ProductType = 'K'">CAS5</xsl:if>
        <xsl:if test="Root/Sale/ProductType = 'B'">DBLCD</xsl:if>
        <xsl:if test="Root/Sale/ProductType = 'P'">LP5</xsl:if>
        <xsl:if test="Root/Sale/ProductType = 'U'">BluRay</xsl:if>
    </xsl:variable>

    <xsl:variable name="showAlbumCustom1">
        <xsl:for-each select="/Root/Products/Product">
            <xsl:choose>
                <xsl:when test="normalize-space(AlbumCustom1)">1</xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:variable>

    <xsl:variable name="showAlbumCustom2">
        <xsl:for-each select="/Root/Products/Product">
            <xsl:choose>
                <xsl:when test="normalize-space(AlbumCustom2)">1</xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:variable>

    <xsl:variable name="showAlbumCustom3">
        <xsl:for-each select="/Root/Products/Product">
            <xsl:choose>
                <xsl:when test="normalize-space(AlbumCustom3)">1</xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:variable>

    <xsl:variable name="showTrackCustom1">
        <xsl:for-each select="/Root/Products/Product">
            <xsl:choose>
                <xsl:when test="normalize-space(TrackCustom1)">1</xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:variable>

    <xsl:variable name="showTrackCustom2">
        <xsl:for-each select="/Root/Products/Product">
            <xsl:choose>
                <xsl:when test="normalize-space(TrackCustom2)">1</xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:variable>

    <xsl:variable name="showTrackCustom3">
        <xsl:for-each select="/Root/Products/Product">
            <xsl:choose>
                <xsl:when test="normalize-space(TrackCustom3)">1</xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:variable>

    <xsl:template name="pickLayout">
        <xsl:call-template name="matcherLayout" />
    </xsl:template>

    <xsl:template name="matcherErrorMessages">
        <xsl:call-template name="errorMessageBox">
            <xsl:with-param name="errorMessage">
                <xsl:if test="Messages/Message/Code = 'unmatch_failed'">Unable to undo this match.</xsl:if>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="matcherLayout">

        <div class="Matcher-manage" id="manageImport">
            <xsl:call-template name="helpLink" />

            <div class="Matcher-manage-file-name">
                <span class="FileName"><xsl:value-of select="File/OrigFileName" /></span>
            </div>
            <table class="Table Matcher-manage-table">
                <tr class="Table-row Table-row-header">
                    <th class="Table-col Matcher-manage-table-col">Service</th>
                    <th class="Table-col Matcher-manage-table-col">Records</th>
                    <th class="Table-col Matcher-manage-table-col">Exceptions (Left/Initial)</th>
                </tr>
                <tr class="Table-row Table-row-data">
                    <td class="Table-col Matcher-manage-table-col"><xsl:value-of select="File/ServiceName" /></td>
                    <td class="Table-col Matcher-manage-table-col"><xsl:value-of select="File/Records" /></td>
                    <td class="Table-col Matcher-manage-table-col"><xsl:value-of select="File/RemainingExceptions" />/<xsl:value-of select="File/TotalExceptions" /></td>
                </tr>
            </table>
        </div>

        <div class="Matcher-exceptions">

            <xsl:call-template name="navLinks" />

            <xsl:call-template name="matcherChart" />

            <div class="Matcher-matches">

                <xsl:if test="Sale/ProductID = '' or Sale/ProductID = 0">
                    <div class="Matcher-search">
                        <h2 class="Matcher-search-header">
                            <xsl:choose>
                                <xsl:when test="normalize-space(Sale/ProductID) and Sale/ProductID != 0">
                                    Current Match
                                </xsl:when>
                                <xsl:otherwise>
                                    Suggested Matches
                                </xsl:otherwise>
                            </xsl:choose>
                        </h2>
                        <form action="/app/matcher" name="matcherSearch" class="Form">
                            <input type="hidden" name="sale" value="{Sale/SaleID}" />
                            <input type="hidden" name="trackerPage" value="{Params/trackerPage}" />
                            <script src="/production/javascript/validateSearch.js?v=1" type="text/javascript"></script>

                            <xsl:variable name="matcherSearchItems">
                                <map>
                                    <mapEntry><name>Smart</name><value>smart</value></mapEntry>
                                    <mapEntry><name>All</name><value>all</value></mapEntry>
                                    <mapEntry><name>Artists</name><value>artist</value></mapEntry>
                                    <mapEntry><name>Albums</name><value>album</value></mapEntry>
                                    <mapEntry><name>Tracks</name><value>track</value></mapEntry>
                                    <mapEntry><name>UPC</name><value>upc</value></mapEntry>
                                    <mapEntry><name>ISRC</name><value>isrc</value></mapEntry>
                                </map>
                            </xsl:variable>
                            <span id="searchText"></span>
                            <div class="Form-group Form-group-horizontal Form-group-horizontal-up">
                                <div class="Form-item">
                                    <div class="ControlsGroup ControlsGroup-type-input">
                                        <label class="ControlsGroup-item">
                                            <xsl:call-template name="uiDropdown">
                                                <xsl:with-param name="items" select="$matcherSearchItems"/>
                                                <xsl:with-param name="name" select="'search_type'"/>
                                                <xsl:with-param name="active" select="Params/search_type"/>
                                                <xsl:with-param name="className" select="'Matcher-search-dropdown'"/>
                                            </xsl:call-template>
                                        </label>

                                        <Label class="InputWrapper InputWrapper-with-icon InputWrapper-with-icon-right ControlsGroup-item Matcher-search-input">
                                            <input class="Input" type="text" placeholder="Search..." name="search" maxlength="100" value="{Params/search}" onFocus="this.select();"/>
                                            <label class="InputWrapper-icon Icon-trigger InputWrapper-icon-search">
                                                <input type="submit" name="Go"/>
                                                <xsl:call-template name="icon">
                                                    <xsl:with-param name="type" select="'search'" />
                                                    <xsl:with-param name="role" select="'action'" />
                                                </xsl:call-template>
                                            </label>
                                        </Label>
                                    </div>
                                    <div class="Form-error-text-wrapper">
                                        <span id="ERRORsearch" class="Form-error"></span>
                                    </div>
                                </div>
                                <div class="Form-item">
                                    <xsl:call-template name="uiButton">
                                        <xsl:with-param name="name" select="'Go'" />
                                        <xsl:with-param name="elemType" select="'submit'" />
                                        <xsl:with-param name="content" select="'Search'" />
                                    </xsl:call-template>
                                </div>

                                <div class="Form-item">
                                    <xsl:call-template name="uiButton">
                                        <xsl:with-param name="name" select="'clear'" />
                                        <xsl:with-param name="content" select="'Clear'" />
                                        <xsl:with-param name="onClick">
                                            document.forms['matcherSearch'].elements['search'].value = '';
                                        </xsl:with-param>
                                    </xsl:call-template>
                                </div>

                            </div>
                            <xsl:if test="normalize-space(Params/search)">
                                <div class="Matcher-return-button-container">
                                    <xsl:call-template name="uiButton">
                                        <xsl:with-param name="name" select="'clear'" />
                                        <xsl:with-param name="content" select="'Return To Suggestions'" />
                                        <xsl:with-param name="url">
                                            <xsl:text>/app/matcher?sale=</xsl:text>
                                            <xsl:value-of select="Sale/SaleID" />
                                            <xsl:text>&amp;trackerPage=</xsl:text>
                                            <xsl:value-of select="Params/trackerPage" />
                                        </xsl:with-param>
                                    </xsl:call-template>
                                </div>
                            </xsl:if>
                        </form>
                    </div>
                </xsl:if>
                <div class="Matcher-matcher">
                    <form action="/app/matcher" name="match">
                        <input type="hidden" name="sale" value="{Sale/SaleID}" />
                        <input type="hidden" name="trackerPage" value="{Params/trackerPage}" />

                        <span id="ERRORproduct" class="Form-error"></span>
                        <xsl:if test="not(Params/search)">
                            <xsl:call-template name="messages" />
                        </xsl:if>
                        <xsl:if test="normalize-space(Sale/ProductID) and Sale/ProductID != 0 and not(/Root/Messages/Message[Type='error'])">

                            <xsl:call-template name="uiWarning">
                                <xsl:with-param name="type" select="'success'" />
                                <xsl:with-param name="description">
                                    This sale has been matched.
                                </xsl:with-param>
                            </xsl:call-template>

                        </xsl:if>
                        <xsl:if test="File/RemainingExceptions = 0">
                            <xsl:call-template name="uiWarning">
                                <xsl:with-param name="type" select="'success'" />
                                <xsl:with-param name="description">
                                    All exceptions resolved for <span class="FileName"><xsl:value-of select="File/OrigFileNamePretty"/></span>.
                                </xsl:with-param>
                            </xsl:call-template>
                        </xsl:if>

                        <xsl:if test="Sale">
                            <xsl:call-template name="suggestedChart" />
                        </xsl:if>

                        <fieldset class="Form-fieldset Form-fieldset-buttons">
                            <xsl:if test="File/FileStatus = 4">
                                <xsl:if test="normalize-space(Sale/ProductID) and Sale/ProductID != 0 and Sale/ImportStatus != 1">
                                    <input type="hidden" name="c" value="unmatch" />

                                    <xsl:call-template name="uiButton">
                                        <xsl:with-param name="content" select="'Undo Match'" />
                                        <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="disabled">
                                            <xsl:if test="Sale/ImportStatus != 2 and Sale/ImportStatus != 3">
                                                <xsl:text>true</xsl:text>
                                            </xsl:if>
                                        </xsl:with-param>
                                    </xsl:call-template>

                                </xsl:if>
                                <xsl:if test="normalize-space(Products/Product/ProductID)">
                                    <xsl:if test="Sale/ProductID = '' or Sale/ProductID = 0">

                                    <xsl:call-template name="uiButton">
                                        <xsl:with-param name="content" select="'Match to Catalog'" />
                                        <xsl:with-param name="className" select="'Form-button'" />
                                        <xsl:with-param name="elemType" select="'submit'" />
                                        <xsl:with-param name="name" select="'submitMatch'" />
                                        <xsl:with-param name="disabled" select="'true'" />
                                    </xsl:call-template>

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

                            <xsl:call-template name="uiButton">
                                <xsl:with-param name="content" select="'Back to Summary'" />
                                <xsl:with-param name="className" select="'Form-button'" />

                                <xsl:with-param name="url">
                                    <xsl:text>/app/tracker?page=</xsl:text>
                                    <xsl:value-of select="Params/trackerPage" />
                                    <xsl:text>#file</xsl:text>
                                    <xsl:value-of select="File/FileID" />
                                </xsl:with-param>
                            </xsl:call-template>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </xsl:template>

    <xsl:template name="matcherChart">
        <div class="Matcher-chart">
            <xsl:if test="not(Sale)">
                <xsl:call-template name="uiWarning">
                    <xsl:with-param name="type" select="'error'" />
                    <xsl:with-param name="description">
                        Line #<xsl:value-of select="Params/line" /> does not exist in this file.
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:if>

            <xsl:if test="Sale">
                <table class="Table">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col" width="50">Type</th>
                            <th class="Table-col">Artist</th>
                            <th class="Table-col">Album</th>
                            <xsl:if test="Sale/ProductType = 'T'">
                                <th class="Table-col">Track</th>
                                <th class="Table-col">ISRC</th>
                            </xsl:if>
                            <th class="Table-col">UPC</th>
                            <xsl:if test="Sale/ProductType = 'T'">
                                <th class="Table-col">Track#</th>
                            </xsl:if>

                            <xsl:if test="/Root/User/ClientNameClean = 'wmg'">
                                <th class="Table-col">Format</th>
                            </xsl:if>
                            <xsl:if test="/Root/User/ClientNameClean = 'bsd'">
                                <th class="Table-col">Label</th>
                            </xsl:if>

                            <th class="Table-col">Client&#160;ID</th>
                            <th class="Table-col">Vendor&#160;ID</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="Table-row Table-row-data">
                            <td class="Table-col">
                                <xsl:if test="Sale/MediaType = '2'">Video </xsl:if><xsl:value-of select="$saleProductType" />
                            </td>
                            <td class="Table-col"><xsl:value-of select="Sale/ArtistName" /></td>
                            <td class="Table-col"><xsl:value-of select="Sale/AlbumName" /></td>

                            <xsl:if test="Sale/ProductType = 'T'">
                                <td class="Table-col"><xsl:value-of select="Sale/TrackName" /></td>
                                <td class="Table-col"><xsl:value-of select="Sale/ISRC" /></td>
                            </xsl:if>
                            <td class="Table-col"><xsl:value-of select="Sale/UPC" /></td>

                            <xsl:if test="Sale/ProductType = 'T'">
                                <td class="Table-col"><xsl:value-of select="Sale/TrackNum" /></td>
                            </xsl:if>

                            <xsl:if test="/Root/User/ClientNameClean = 'wmg'">
                                <td class="Table-col"><xsl:value-of select="Sale/FormatTypePretty" /></td>
                            </xsl:if>
                            <xsl:if test="/Root/User/ClientNameClean = 'bsd'">
                                <td class="Table-col"><xsl:value-of select="Sale/LabelName" /></td>
                            </xsl:if>

                            <td class="Table-col"><xsl:value-of select="Sale/ClientProductID" /></td>
                            <td class="Table-col"><xsl:value-of select="Sale/ServiceProductID" /></td>
                        </tr>
                    </tbody>
                </table>
            </xsl:if>
        </div>
    </xsl:template>


    <xsl:template name="suggestedChart">

        <xsl:if test="Params/search">
            <div class="TextNode">
            <p>
                <strong><xsl:value-of select="count(Products/Product)" /></strong>
                result<xsl:if test="count(Products/Product) != 1">s</xsl:if> found for <strong>'<xsl:value-of select="Params/search" />'</strong>
            </p>
            </div>
        </xsl:if>

        <div class="Matcher-matches-chart js-sticky-table">
                <xsl:variable name="sortOrder">
                    <xsl:choose>
                        <xsl:when test="normalize-space(Params/sort_order)">descending</xsl:when>
                        <xsl:otherwise>ascending</xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>
                <xsl:variable name="sortParam">
                    <xsl:choose>
                        <xsl:when test="Params/sort = 'artist'">translate(ArtistName,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'album'">translate(ProductTitle,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'track'">translate(TrackName,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'isrc'">translate(ISRC,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'upc'">UPC</xsl:when>
                        <xsl:when test="Params/sort = 'track_clientid'">translate(ClientTrackID,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'album_clientid'">translate(ClientAlbumID,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'trackpos'">TrackNumber</xsl:when>
                        <xsl:when test="Params/sort = 'catalog'">translate(CatalogID,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'media' and /Root/User/ClientNameClean = 'srgi'">translate(TrackCustom1,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'media' and /Root/User/ClientNameClean = 'wmg'">translate(AlbumCustom2,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'release'">translate(ReleaseDate,'-', '')</xsl:when>
                        <xsl:when test="Params/sort = 'album_custom_1'">translate(AlbumCustom1,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'album_custom_2'">translate(AlbumCustom2,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'album_custom_3'">translate(AlbumCustom3,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'track_custom_1'">translate(TrackCustom1,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'track_custom_2'">translate(TrackCustom2,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                        <xsl:when test="Params/sort = 'track_custom_3'">translate(TrackCustom3,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')</xsl:when>
                    </xsl:choose>
                </xsl:variable>
                <xsl:variable name="dataType">
                    <xsl:choose>
                        <xsl:when test="Params/sort = 'upc' or Params/sort = 'trackpos'">number</xsl:when>
                        <xsl:otherwise>text</xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>

                <xsl:if test="Products">
                    <div class="Table-sticky-header">
                        <div class="Table-wrapper Table-wrapper-sticky-header">
                            <table class="Table Table-with-highlight Matcher-matches-table">
                                <thead>
                                    <xsl:call-template name="productHeaderRow"/>
                                </thead>
                            </table>
                        </div>
                    </div>
                    <div class="Table-wrapper Matcher-matches-chart-wrapper Table-wrapper-sticky-body">
                        <table class="Table Table-with-highlight Matcher-matches-table">
                            <tbody>
                                <xsl:for-each select="Products/Product">
                                    <xsl:sort select="dyn:evaluate($sortParam)" data-type="{$dataType}" order="{$sortOrder}" />
                                    <xsl:call-template name="productDataRow"/>
                                </xsl:for-each>
                            </tbody>
                        </table>
                    </div>
                </xsl:if>
        </div>
    </xsl:template>


    <xsl:template name="matcherFilesSort">
        <xsl:param name="name" />
        <xsl:param name="caption" />
        <xsl:variable name="sortLink">/app/matcher?sale=<xsl:value-of select="Params/sale"/>&amp;<xsl:if test="Params/search_type">search_type=<xsl:value-of select="Params/search_type"/>&amp;</xsl:if><xsl:if test="Params/search">search=<xsl:value-of select="Params/search"/></xsl:if>&amp;trackerPage=<xsl:value-of select="/Root/Params/trackerPage" />&amp;</xsl:variable>


        <xsl:variable name="sortLinkWithType">
            <xsl:value-of select="$sortLink" />
            <xsl:text>sort=</xsl:text>
            <xsl:value-of select="$name" />
            <xsl:if test="Params/sort = $name and not(Params/sort_order)">
                <xsl:text>&amp;sort_order=1</xsl:text>
            </xsl:if>
        </xsl:variable>

        <xsl:call-template name="uiTableSorting">
            <xsl:with-param name="caption" select="$caption" />
            <xsl:with-param name="sortBy" select="Params/sort"/>
            <xsl:with-param name="name" select="$name"/>
            <xsl:with-param name="sortReverse" select="Params/sort_order" />
            <xsl:with-param name="onClick">
                location.href = '<xsl:value-of select="$sortLinkWithType" />'
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="productHeaderRow">

        <tr class="Table-row Table-row-header">
            <xsl:if test="not(normalize-space(Sale/ProductID)) or Sale/ProductID = 0">
                <th class="Table-col Matcher-matches-table-choose">Choose</th>
            </xsl:if>

            <xsl:if test="$showTypeCol = 1">
                <th class="Table-col Matcher-matches-table-type">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'type'"/>
                        <xsl:with-param name="caption" select="'Type'" />
                    </xsl:call-template>
                </th>
            </xsl:if>

            <th class="Table-col Matcher-matches-table-artist">
                <xsl:call-template name="matcherFilesSort">
                    <xsl:with-param name="name" select="'artist'"/>
                    <xsl:with-param name="caption" select="'Artist'" />
                </xsl:call-template>
            </th>

            <th class="Table-col Matcher-matches-table-album">
                <xsl:call-template name="matcherFilesSort">
                    <xsl:with-param name="name" select="'album'"/>
                    <xsl:with-param name="caption" select="'Album'" />
                </xsl:call-template>
            </th>

            <xsl:if test="Sale/ProductType = 'T'">
                <th class="Table-col Matcher-matches-table-track">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'track'"/>
                        <xsl:with-param name="caption" select="'Track'" />
                    </xsl:call-template>
                </th>
                <th class="Table-col Matcher-matches-table-isrc">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'isrc'"/>
                        <xsl:with-param name="caption" select="'ISRC'" />
                    </xsl:call-template>
                </th>
            </xsl:if>

            <th class="Table-col Matcher-matches-table-upc">
                <xsl:call-template name="matcherFilesSort">
                    <xsl:with-param name="name" select="'upc'"/>
                    <xsl:with-param name="caption" select="'UPC'" />
                </xsl:call-template>
            </th>

            <xsl:if test="Sale/ProductType = 'T'">
                <th class="Table-col Matcher-matches-table-trackpos">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'trackpos'"/>
                        <xsl:with-param name="caption" select="'Track#'" />
                    </xsl:call-template>
                </th>
            </xsl:if>


            <th class="Table-col Matcher-matches-table-catalog">
                <xsl:call-template name="matcherFilesSort">
                    <xsl:with-param name="name" select="'catalog'"/>
                    <xsl:with-param name="caption" select="'Catalog'" />
                </xsl:call-template>
            </th>


            <xsl:if test="/Root/User/ClientNameClean = 'srgi'">
                <th class="Table-col Matcher-matches-table-dig">Dig</th>
                <th class="Table-col Matcher-matches-table-release">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'release'"/>
                        <xsl:with-param name="caption" select="'Release Date'" />
                    </xsl:call-template>
                </th>
            </xsl:if>

            <xsl:if test="/Root/User/ClientNameClean = 'wmg'">
                <th class="Table-col Matcher-matches-table-media">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'media'"/>
                        <xsl:with-param name="caption" select="'Media'" />
                    </xsl:call-template>
                </th>
                <th class="Table-col Matcher-matches-table-release">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'release'"/>
                        <xsl:with-param name="caption" select="'Release Date'" />
                    </xsl:call-template>
                </th>
            </xsl:if>

            <xsl:if test="/Root/User/ClientNameClean = 'cmg'">
                <th class="Table-col Matcher-matches-table-release">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'release'"/>
                        <xsl:with-param name="caption" select="'Release Date'" />
                    </xsl:call-template>
                </th>
            </xsl:if>

            <xsl:if test="/Root/User/ClientNameClean = 'srgiuk'">
                <th class="Table-col Matcher-matches-table-release">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'release'"/>
                        <xsl:with-param name="caption" select="'Release Date'" />
                    </xsl:call-template>
                </th>
            </xsl:if>

            <xsl:if test="/Root/User/ClientNameClean = 'sfw'">
                <th class="Table-col Matcher-matches-table-release">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'release'"/>
                        <xsl:with-param name="caption" select="'Release Date'" />
                    </xsl:call-template>
                </th>
            </xsl:if>

            <xsl:if test="/Root/User/ClientNameClean = 'bsd'">
                <th class="Table-col Matcher-matches-table-release">
                    <xsl:call-template name="matcherFilesSort">
                        <xsl:with-param name="name" select="'release'"/>
                        <xsl:with-param name="caption" select="'Label'" />
                    </xsl:call-template>
                </th>
            </xsl:if>

            <xsl:choose>
                <xsl:when test="Sale/ProductType = 'T'">
                    <th class="Table-col Matcher-matches-table-clientid">
                        <xsl:call-template name="matcherFilesSort">
                            <xsl:with-param name="name" select="'track_clientid'"/>
                            <xsl:with-param name="caption" select="'Client ID'" />
                        </xsl:call-template>
                    </th>
                    <xsl:if test="$showTrackCustom1 != 0">
                        <th class="Table-col Matcher-matches-table-custom-1">
                            <xsl:call-template name="matcherFilesSort">
                                <xsl:with-param name="name" select="'track_custom_1'"/>
                                <xsl:with-param name="caption" select="'Custom&#160;1'" />
                            </xsl:call-template>
                        </th>
                    </xsl:if>
                    <xsl:if test="$showTrackCustom2 != 0">
                        <th class="Table-col Matcher-matches-table-custom-2">
                            <xsl:call-template name="matcherFilesSort">
                                <xsl:with-param name="name" select="'track_custom_2'"/>
                                <xsl:with-param name="caption" select="'Custom&#160;2'" />
                            </xsl:call-template>
                        </th>
                    </xsl:if>
                    <xsl:if test="$showTrackCustom3 != 0">
                        <th class="Table-col Matcher-matches-table-custom-3">
                            <xsl:call-template name="matcherFilesSort">
                                <xsl:with-param name="name" select="'track_custom_3'"/>
                                <xsl:with-param name="caption" select="'Custom&#160;3'" />
                            </xsl:call-template>
                        </th>
                    </xsl:if>
                </xsl:when>
                <xsl:otherwise>
                    <th class="Table-col Matcher-matches-table-clientid">
                        <xsl:call-template name="matcherFilesSort">
                            <xsl:with-param name="name" select="'album_clientid'"/>
                            <xsl:with-param name="caption" select="'Client ID'" />
                        </xsl:call-template>
                    </th>
                    <xsl:if test="$showAlbumCustom1 != 0">
                        <th class="Table-col Matcher-matches-table-custom-1">
                            <xsl:call-template name="matcherFilesSort">
                                <xsl:with-param name="name" select="'album_custom_1'"/>
                                <xsl:with-param name="caption" select="'Custom&#160;1'" />
                            </xsl:call-template>
                        </th>
                    </xsl:if>
                    <xsl:if test="$showAlbumCustom2 != 0">
                        <th class="Table-col Matcher-matches-table-custom-2">
                            <xsl:call-template name="matcherFilesSort">
                                <xsl:with-param name="name" select="'album_custom_2'"/>
                                <xsl:with-param name="caption" select="'Custom&#160;2'" />
                            </xsl:call-template>
                        </th>
                    </xsl:if>
                    <xsl:if test="$showAlbumCustom3 != 0">
                        <th class="Table-col Matcher-matches-table-custom-3">
                            <xsl:call-template name="matcherFilesSort">
                                <xsl:with-param name="name" select="'album_custom_3'"/>
                                <xsl:with-param name="caption" select="'Custom&#160;3'" />
                            </xsl:call-template>
                        </th>
                    </xsl:if>
                </xsl:otherwise>
            </xsl:choose>
        </tr>
    </xsl:template>

    <xsl:template name="productDataRow">
        <xsl:variable name="alreadyMatched">
            <xsl:choose>
                <xsl:when test="normalize-space(/Root/Sale/ProductID) and /Root/Sale/ProductID != 0">1</xsl:when>
                <xsl:otherwise>0</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <tr class="Table-row Table-row-data">
            <xsl:if test="not(normalize-space(/Root/Sale/ProductID)) or /Root/Sale/ProductID = 0">
                <td class="Table-col Matcher-matches-table-choose">
                    <xsl:call-template name="uiRadio">
                        <xsl:with-param name="name" select="'product'"/>
                        <xsl:with-param name="onClick">
                            enableField('match','submitMatch');
                        </xsl:with-param>
                        <xsl:with-param name="value" select="ProductID"/>
                    </xsl:call-template>
                </td>
            </xsl:if>

            <xsl:if test="$showTypeCol = 1">
                <td class="Table-col Matcher-matches-table-type">
                    <xsl:if test="$physicalProduct = 1">
                        <xsl:variable name="productType">
                            <xsl:if test="ProductTypeID = 1">LP</xsl:if>
                            <xsl:if test="ProductTypeID = 2">CD</xsl:if>
                            <xsl:if test="ProductTypeID = 5">VHS</xsl:if>
                            <xsl:if test="ProductTypeID = 6">CASS</xsl:if>
                            <xsl:if test="ProductTypeID = 7">7"</xsl:if>
                            <xsl:if test="ProductTypeID = 9">DVD</xsl:if>
                            <xsl:if test="ProductTypeID = 11">CD5</xsl:if>
                            <xsl:if test="ProductTypeID = 12">CAS5</xsl:if>
                            <xsl:if test="ProductTypeID = 13">DVDCD</xsl:if>
                            <xsl:if test="ProductTypeID = 14">DBLCD</xsl:if>
                            <xsl:if test="ProductTypeID = 15">RING</xsl:if>
                            <xsl:if test="ProductTypeID = 16">LP5</xsl:if>
                            <xsl:if test="ProductTypeID = 17">BluRay</xsl:if>
                        </xsl:variable>
                        <span>
                            <xsl:if test="$productType = $saleProductType and $alreadyMatched = 0">
                                <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="$productType" />
                        </span>
                    </xsl:if>
                    <xsl:if test="$physicalProduct != 1">
                        <xsl:if test="MediaType = 1">Audio</xsl:if>
                        <xsl:if test="MediaType = 2">Video</xsl:if>
                    </xsl:if>
                </td>
            </xsl:if>

            <td class="Table-col Matcher-matches-table-atrist">
                <span>
                    <xsl:if test="translate(ArtistName,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') = translate(/Root/Sale/ArtistName,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') and $alreadyMatched = 0">
                        <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                    </xsl:if>
                    <xsl:value-of select="ArtistName" />
                </span>
            </td>
            <td class="Table-col Matcher-matches-table-album">
                <span>
                    <xsl:if test="translate(ProductTitle,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') = translate(/Root/Sale/AlbumName,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') and $alreadyMatched = 0">
                        <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                    </xsl:if>
                    <xsl:value-of select="ProductTitle" />
                </span>
            </td>

            <xsl:if test="/Root/Sale/ProductType = 'T'">
                <td class="Table-col Matcher-matches-table-track">
                    <span>
                        <xsl:if test="translate(TrackName,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') = translate(/Root/Sale/TrackName,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') and $alreadyMatched = 0">
                            <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="TrackName" />
                    </span>
                </td>
                <td class="Table-col Matcher-matches-table-isrc">
                    <span>
                        <xsl:if test="ISRC = /Root/Sale/ISRC and $alreadyMatched = 0">
                            <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="ISRC" />
                    </span>
                </td>
            </xsl:if>

            <td class="Table-col Matcher-matches-table-upc">
                <span>
                    <xsl:if test="UPC = /Root/Sale/UPC and $alreadyMatched = 0">
                        <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                    </xsl:if>
                    <xsl:value-of select="UPC" />
                </span>
            </td>

            <xsl:if test="/Root/Sale/ProductType = 'T'">
                <td class="Table-col Matcher-matches-table-trackpos">
                    <span>
                        <xsl:if test="TrackNumber = /Root/Sale/TrackNum and $alreadyMatched = 0">
                            <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="TrackNumber" />
                    </span>
                </td>
            </xsl:if>

            <td class="Table-col Matcher-matches-table-catalog"><xsl:value-of select="CatalogID" /></td>

            <xsl:if test="/Root/User/ClientNameClean = 'srgi'">
                <td class="Table-col Matcher-matches-table-custom-1"><xsl:value-of select="AlbumCustom2" /></td>
                <td class="Table-col"><xsl:value-of select="ReleaseDatePretty" /></td>
            </xsl:if>
            <xsl:if test="/Root/User/ClientNameClean = 'wmg'">
                <td class="Table-col Matcher-matches-table-custom-2"><xsl:value-of select="AlbumCustom2" /></td>
                <td class="Table-col"><xsl:value-of select="ReleaseDatePretty" /></td>
            </xsl:if>
            <xsl:if test="/Root/User/ClientNameClean = 'cmg'">
                <td class="Table-col Matcher-matches-table-release"><xsl:value-of select="ReleaseDatePretty" /></td>
            </xsl:if>
            <xsl:if test="/Root/User/ClientNameClean = 'srgiuk'">
                <td class="Table-col Matcher-matches-table-release"><xsl:value-of select="ReleaseDatePretty" /></td>
            </xsl:if>
            <xsl:if test="/Root/User/ClientNameClean = 'sfw'">
                <td class="Table-col Matcher-matches-table-release"><xsl:value-of select="ReleaseDatePretty" /></td>
            </xsl:if>
            <xsl:if test="/Root/User/ClientNameClean = 'bsd'">
                <td class="Table-col Matcher-matches-table-release">
                    <span>
                        <xsl:if test="translate(LabelName,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') = translate(/Root/Sale/LabelName,'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') and $alreadyMatched = 0">
                            <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                        </xsl:if>
                        <xsl:value-of select="LabelName" />
                    </span>
                </td>
            </xsl:if>

            <td class="Table-col Matcher-matches-table-clientid">
                <xsl:choose>
                    <xsl:when test="normalize-space(ClientTrackID)">
                        <span>
                            <xsl:if test="ClientTrackID = /Root/Sale/ClientProductID and $alreadyMatched = 0">
                                <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="ClientTrackID" />
                        </span>
                    </xsl:when>
                    <xsl:otherwise>
                        <span>
                            <xsl:if test="ClientAlbumID = /Root/Sale/ClientProductID and $alreadyMatched = 0">
                                <xsl:attribute name="class">Matcher-exact-match</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="ClientAlbumID" />
                        </span>
                    </xsl:otherwise>
                </xsl:choose>
            </td>

            <xsl:choose>
                <xsl:when test="/Root/Sale/ProductType = 'T'">
                    <xsl:if test="$showTrackCustom1 != 0">
                        <td class="Table-col Matcher-matches-table-custom-1"><xsl:value-of select="TrackCustom1" /></td>
                    </xsl:if>
                    <xsl:if test="$showTrackCustom2 != 0">
                        <td class="Table-col Matcher-matches-table-custom-2"><xsl:value-of select="TrackCustom2" /></td>
                    </xsl:if>
                    <xsl:if test="$showTrackCustom3 != 0">
                        <td class="Table-col Matcher-matches-table-custom-3"><xsl:value-of select="TrackCustom3" /></td>
                    </xsl:if>
                </xsl:when>
                <xsl:otherwise test="/Root/Sale/ProductType = 'A'">
                    <xsl:if test="$showAlbumCustom1 != 0">
                        <td class="Table-col Matcher-matches-table-custom-1"><xsl:value-of select="AlbumCustom1" /></td>
                    </xsl:if>
                    <xsl:if test="$showAlbumCustom2 != 0">
                        <td class="Table-col Matcher-matches-table-custom-2"><xsl:value-of select="AlbumCustom2" /></td>
                    </xsl:if>
                    <xsl:if test="$showAlbumCustom3 != 0">
                        <td class="Table-col Matcher-matches-table-custom-3"><xsl:value-of select="AlbumCustom3" /></td>
                    </xsl:if>
                </xsl:otherwise>
            </xsl:choose>

        </tr>
    </xsl:template>

    <xsl:template name="navLinks">
        <div class="Matcher-navigation">
            <div class="Matcher-navigation-item Matcher-navigation-prev">
                <xsl:attribute name="class">
                    <xsl:text>Matcher-navigation-item Matcher-navigation-next</xsl:text>
                    <xsl:if test="not(normalize-space(PreviousError)) and not(normalize-space(PreviousUnfixed))">
                        <xsl:text> Matcher-navigation-item-hidden</xsl:text>
                    </xsl:if>
                </xsl:attribute>

                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="'Previous Exception'" />
                    <xsl:with-param name="className" select="'Matcher-navigation-button'" />
                    <xsl:with-param name="disabled">
                        <xsl:if test="normalize-space(PreviousUnfixed) = ''">true</xsl:if>
                    </xsl:with-param>

                    <xsl:with-param name="iconLeftType" select="'arrow-left'" />
                    <xsl:with-param name="url">
                        <xsl:text>?sale=</xsl:text>
                        <xsl:value-of select="PreviousUnfixed" />
                        <xsl:text>&amp;trackerPage=</xsl:text>
                        <xsl:value-of select="Params/trackerPage" />
                        <xsl:text>&amp;c=sale</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>

                <xsl:call-template name="uiButton">
                    <xsl:with-param name="className" select="'Matcher-navigation-button Matcher-navigation-button-arrow'" />
                    <xsl:with-param name="disabled">
                        <xsl:if test="normalize-space(PreviousError) = ''">true</xsl:if>
                    </xsl:with-param>

                    <xsl:with-param name="iconLeftType" select="'arrow-left'" />
                    <xsl:with-param name="url">
                        <xsl:text>?sale=</xsl:text>
                        <xsl:value-of select="PreviousError" />
                        <xsl:text>&amp;trackerPage=</xsl:text>
                        <xsl:value-of select="Params/trackerPage" />
                        <xsl:text>&amp;c=sale</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="Matcher-navigation-item Matcher-navigation-line">
                <form action="/app/matcher" name="lineSearch">
                    <input type="hidden" name="trackerPage" value="{Params/trackerPage}" />
                    <input type="hidden" name="file" value="{File/FileID}" />
                    <div class="Form-group Form-group-horizontal">
                        <div class="Form-item Form-item-horizontal">
                            <label class="Form-label">
                                <span class="Form-label-caption">Go To Line #</span>
                                <div class="Form-input-wrapper">
                                    <input class="Input Form-input Matcher-manage-input" type="text" name="line" size="7" maxlength="10" onFocus="this.select();">
                                        <xsl:attribute name="value">
                                            <xsl:if test="Sale/LineNum"><xsl:value-of select="Sale/LineNum" /></xsl:if>
                                            <xsl:if test="not(Sale/LineNum) and Params/line"><xsl:value-of select="Params/line" /></xsl:if>
                                        </xsl:attribute>
                                    </input>
                                </div>
                            </label>
                        </div>
                        <div class="Form-item">
                            <xsl:call-template name="uiButton">
                                <xsl:with-param name="content" select="'Go'" />
                                <xsl:with-param name="elemType" select="'submit'" />
                            </xsl:call-template>
                        </div>
                    </div>
                </form>
            </div>
            <div class="Matcher-navigation-item Matcher-navigation-next">
                <xsl:attribute name="class">
                    <xsl:text>Matcher-navigation-item Matcher-navigation-next</xsl:text>
                    <xsl:if test="not(normalize-space(NextError)) and not(normalize-space(NextUnfixed))">
                        <xsl:text> Matcher-navigation-item-hidden</xsl:text>
                    </xsl:if>
                </xsl:attribute>

                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="''" />
                    <xsl:with-param name="className" select="'Matcher-navigation-button Matcher-navigation-button-arrow'" />
                    <xsl:with-param name="disabled">
                        <xsl:if test="normalize-space(NextError) = ''">true</xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="iconRightType" select="'arrow-right'" />
                    <xsl:with-param name="url">
                        <xsl:text>?sale=</xsl:text>
                        <xsl:value-of select="NextError" />
                        <xsl:text>&amp;trackerPage=</xsl:text>
                        <xsl:value-of select="Params/trackerPage" />
                        <xsl:text>&amp;c=sale</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>

                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="'Next Exception'" />
                    <xsl:with-param name="className" select="'Matcher-navigation-button'" />
                    <xsl:with-param name="disabled">
                        <xsl:if test="normalize-space(NextUnfixed) = ''">true</xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="iconRightType" select="'arrow-right'" />
                    <xsl:with-param name="url">
                        <xsl:text>?sale=</xsl:text>
                        <xsl:value-of select="NextUnfixed" />
                        <xsl:text>&amp;trackerPage=</xsl:text>
                        <xsl:value-of select="Params/trackerPage" />
                        <xsl:text>&amp;c=sale</xsl:text>
                    </xsl:with-param>
                </xsl:call-template>
            </div>
        </div>
    </xsl:template>

</xsl:stylesheet>


