<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">


    <xsl:variable name="showDigitalUPC">
        <xsl:choose>
            <xsl:when test="$cmd = 'search_import' or $cmd = 'search_no_dr' or $cmd = 'search_no_image' or $cmd = 'search_no_audio' or $cmd = 'search_no_metadata'">1</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>


    <xsl:template name="catalogSearchLayout">
        <div class="CatalogSearch">
            <xsl:choose>
                <xsl:when test="Progress &gt; 0">
                    <xsl:call-template name="searchProgressBar" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:choose>
                        <xsl:when test="not($cmd = 'search' or $cmd = 'search_track' or $cmd = 'search_product') and not( count(Album) )" >
                            <section class="Table-empty-results Table-empty-results-no-header">
                                <p>No results matched your search.</p>
                            </section>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:call-template name="searchResults" />
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:otherwise>
            </xsl:choose>
        </div>
    </xsl:template>


    <xsl:template name="searchProgressBar">
        One or more albums have been updated in the catalog.  This report must be re-generated.
        <div id="searchProgressBar"></div>
        <script type="text/javascript">
            var style = {
                'loadedcolor': '#326694',
                'width': '350',
                'height': '15',
                'bordercolor': 'black',
                'labelwidth': 50
            }

            var options = {
                initurl: "/rps/catalog?c=dist_cache",
                statusurl: "/rps/catalog?c=dist_cache_status",
                failurl: '/rps/catalog?c=<xsl:value-of select="Params/c" />&amp;Page=<xsl:value-of select="Params/Page" />',
                successurl: '/rps/catalog?c=<xsl:value-of select="Params/c" />&amp;Page=<xsl:value-of select="Params/Page" />'
            };

            var bar = new RSAjaxProgressBar( "searchProgressBar", style, options );
        </script>
        <script type="text/javascript">bar.start( "<B>Generating Report</B>" );</script>
    </xsl:template>


    <xsl:template name="searchResults">


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

        <xsl:if test="$cmd = 'search' or $cmd = 'search_track' or $cmd = 'search_product'">
            <div class="Table-controls Table-controls-top">
                <div class="Table-controls-item">
                    <xsl:call-template name="searchLinks" />
                </div>
            </div>
        </xsl:if>

        <xsl:if test="Pagination/Total &gt; 0 or count(Track) != 0 or count(Album) != 0 or count(Product) != 0">
            <xsl:choose>
                <xsl:when test="$cmd = 'search_track'" >
                    <xsl:call-template name="trackResults" />
                </xsl:when>
                <xsl:when test="$cmd = 'search_product'" >
                    <xsl:call-template name="productResults" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:call-template name="albumResults" />
                </xsl:otherwise>
            </xsl:choose>
        </xsl:if>

        <div class="Table-controls Table-controls-bottom">
            <div class="Table-controls-item">
                <xsl:call-template name="pageSizeForm" />
            </div>
            <div class="Table-controls-item Table-controls-item-pagination">
                <xsl:call-template name="searchNavRecords" />
            </div>
        </div>
    </xsl:template>


    <xsl:template name="albumResults">
        <table class="Table Table-with-highlight">
            <thead>
                <tr class="Table-row Table-row-header">
                    <xsl:if test="$showDigitalUPC = 1">
                        <th class="Table-col">Digital UPC</th>
                    </xsl:if>
                    <th class="Table-col">Title</th>
                    <th class="Table-col">Catalog #</th>
                    <th class="Table-col">Artist</th>
                    <xsl:if test="LabelList/Label">
                        <th class="Table-col">Label</th>
                    </xsl:if>
                    <xsl:if test="$cmd = 'search_import'">
                        <th class="Table-col">Date Imported</th>
                    </xsl:if>
                    <xsl:if test="Params/c = 'search_in_queue'">
                        <th class="Table-col">Date Queued</th>
                    </xsl:if>
                    <xsl:if test="Params/c = 'search_delivered'">
                        <th class="Table-col">Date Delivered</th>
                    </xsl:if>
                    <th class="Table-col">Status</th>
                    <xsl:if test="Access/rps/catalog/edit or Access/rps/catalog/da_edit">
                        <th class="Table-col Table-col-icon">Edit</th>
                    </xsl:if>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="Album">
                    <tr class="Table-row Table-row-data">
                        <xsl:if test="$showDigitalUPC = 1">
                            <td class="Table-col">
                                <a href="catalog?AlbumID={AlbumID}&amp;c={$daTest}show">
                                    <xsl:value-of select="DigitalUPC" />
                                </a>
                            </td>
                        </xsl:if>
                        <td class="Table-col">
                            <a href="catalog?AlbumID={AlbumID}&amp;c={$daTest}show">
                                <xsl:value-of select="Title" /><xsl:if test="TitleVersion != ''"> (<xsl:value-of select="TitleVersion" />)</xsl:if>
                            </a>
                        </td>
                        <td class="Table-col"><xsl:value-of select="CatalogNumber" /></td>
                        <td class="Table-col">
                            <xsl:value-of select="ArtistName" />
                            <xsl:if test="count(AdditionalArtistList/AdditionalArtist) != 0">
                                &#160;<a class="js-tooltip">
                                    <xsl:attribute name="title">
                                        <xsl:for-each select="AdditionalArtistList/AdditionalArtist">
                                            <xsl:sort select="AdditionalArtistID" />
                                            <xsl:call-template name="escapeJavascript">
                                                <xsl:with-param name="string" select="Name" />
                                            </xsl:call-template> (<xsl:value-of select="Role/Role" />)<xsl:value-of select="$tipBreak" />
                                        </xsl:for-each>
                                    </xsl:attribute>
                                    <xsl:call-template name="icon">
                                        <xsl:with-param name="type" select="'more'" />
                                    </xsl:call-template>
                                </a>
                            </xsl:if>
                        </td>
                        <xsl:if test="/Root/LabelList/Label">
                            <xsl:variable name="albumLabelID"><xsl:value-of select="LabelID" /></xsl:variable>
                            <td class="Table-col"><xsl:value-of select="/Root/LabelList/Label[LabelID = $albumLabelID]/LabelName" /></td>
                        </xsl:if>
                        <xsl:if test="$cmd = 'search_import'">
                            <td class="Table-col"><xsl:value-of select="CreatedDate" /></td>
                        </xsl:if>
                        <xsl:if test="/Root/Params/c = 'search_in_queue'">
                            <td class="Table-col"><xsl:value-of select="DateQueued" /></td>
                        </xsl:if>
                        <xsl:if test="/Root/Params/c = 'search_delivered'">
                            <td class="Table-col"><xsl:value-of select="DateDelivered" /></td>
                        </xsl:if>
                        <td class="Table-col">
                            <xsl:call-template name="albumStatus">
                                <xsl:with-param name="status" select="Status" />
                            </xsl:call-template>
                        </td>
                        <xsl:if test="/Root/Access/rps/catalog/edit or /Root/Access/rps/catalog/da_edit">
                            <td class="Table-col Table-col-icon">
                                <a href="catalog?c={$daTest}edit&amp;AlbumID={AlbumID}" class="js-tooltip" title="Edit">
                                    <xsl:call-template name="icon">
                                        <xsl:with-param name="type" select="'edit'" />
                                        <xsl:with-param name="role" select="'action'" />
                                    </xsl:call-template>
                                </a>
                            </td>
                        </xsl:if>
                    </tr>
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>

    <xsl:template name="trackResults">
        <table class="Table Table-with-highlight">
            <thead>
                <tr class="Table-row Table-row-header">
                    <th class="Table-col">Title</th>
                    <th class="Table-col">Track #</th>
                    <th class="Table-col">ISRC</th>
                    <th class="Table-col">Track Artist</th>
                    <th class="Table-col">Album Title</th>
                    <th class="Table-col Table-col-icon">Edit</th>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="Track">
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col"><a href="/rps/track?c=show&amp;TrackID={TrackID}"><xsl:value-of select="Title" /></a></td>
                        <td class="Table-col"><xsl:value-of select="TrackOrder" /></td>
                        <td class="Table-col"><xsl:value-of select="Master/ISRC" /></td>
                        <td class="Table-col">
                            <xsl:value-of select="ArtistName" />
                            <xsl:if test="count(AdditionalArtistList/AdditionalArtist) != 0">
                                &#160;<a class="js-tooltip">
                                <xsl:attribute name="title">
                                    <xsl:for-each select="AdditionalArtistList/AdditionalArtist">
                                        <xsl:sort select="AdditionalArtistID" />
                                        <xsl:call-template name="escapeJavascript">
                                            <xsl:with-param name="string" select="Name" />
                                        </xsl:call-template> (<xsl:value-of select="Role/Role" />)<xsl:value-of select="$tipBreak" />
                                    </xsl:for-each>
                                </xsl:attribute>
                                <xsl:call-template name="icon">
                                    <xsl:with-param name="type" select="'more'" />
                                </xsl:call-template>
                            </a>
                        </xsl:if>
                        </td>
                        <td class="Table-col"><xsl:value-of select="AlbumName" /></td>
                        <td class="Table-col Table-col-icon">
                            <a href="/rps/track?c=edit&amp;TrackID={TrackID}" class="js-tooltip" title="Edit">
                                <xsl:call-template name="icon">
                                    <xsl:with-param name="type" select="'edit'" />
                                    <xsl:with-param name="role" select="'action'" />
                                </xsl:call-template>
                            </a>
                        </td>
                    </tr>
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>


    <xsl:template name="productResults">
        <table class="Table Table-with-highlight">
            <thead>
                <tr class="Table-row Table-row-header">
                    <th class="Table-col">Title</th>
                    <th class="Table-col">Type</th>
                    <th class="Table-col">Product ID</th>
                    <th class="Table-col">UPC</th>
                    <th class="Table-col">Artist</th>
                    <th class="Table-col Table-col-icon">Edit</th>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="Product">
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col">
                            <a href="/rps/product?c=show&amp;ProductID={ProductID}">
                                <xsl:value-of select="Title" />
                            </a>
                        </td>
                        <td class="Table-col">
                            <xsl:variable name="productTypeID" select="ProductTypeID" />
                            <xsl:value-of select="/Root/TypeList/Type[ProductTypeID = $productTypeID]/Description" />
                        </td>
                        <td class="Table-col"><xsl:value-of select="ProductCode" /></td>
                        <td class="Table-col"><xsl:value-of select="UPC" /></td>
                        <td class="Table-col"><xsl:value-of select="ArtistName" /></td>
                        <td class="Table-col Table-col-icon">
                            <a href="/rps/product?c=edit&amp;ProductID={ProductID}" class="js-tooltip" title="Edit">
                                <xsl:call-template name="icon">
                                    <xsl:with-param name="type" select="'edit'" />
                                    <xsl:with-param name="role" select="'action'" />
                                </xsl:call-template>
                            </a>
                        </td>
                    </tr>
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>


    <xsl:template name="pageSizeForm" >
        <form method="get" action="/rps/catalog">
            <input type="hidden" name="c" value="{/Root/Params/c}" />
            <input type="hidden" name="Query" value="{/Root/Params/Query}" />
            <xsl:if test="/Root/Pagination/CurrentRecord">
                <input type="hidden" name="Record" value="{/Root/Pagination/CurrentRecord}" />
            </xsl:if>
            <div class="Form-group Form-group-horizontal">
                <div class="Form-item Form-item-horizontal">
                    <label class="Form-label">
                        <span class="Form-label-caption">Results per page</span>
                        <div class="Form-input-wrapper">
                            <xsl:variable name="catalogSearchPerPageItems">
                                <map>
                                    <xsl:if test="Pagination/PageSize != 25 and Pagination/PageSize != 50 and Pagination/PageSize != 100">
                                        <mapEntry>
                                            <name><xsl:value-of select="Pagination/PageSize" /></name>
                                            <value><xsl:value-of select="Pagination/PageSize" /></value>
                                        </mapEntry>
                                    </xsl:if>
                                    <mapEntry><name>25</name><value>25</value></mapEntry>
                                    <mapEntry><name>50</name><value>50</value></mapEntry>
                                    <mapEntry><name>100</name><value>100</value></mapEntry>

                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$catalogSearchPerPageItems"/>

                                <xsl:with-param name="name" select="'PageSize'"/>
                                <xsl:with-param name="active" select="Pagination/PageSize"/>
                                <xsl:with-param name="className" select="'Form-item-per-page-select'"/>
                            </xsl:call-template>
                        </div>
                    </label>
                </div>
                <div class="Form-item">
                    <xsl:call-template name="uiButton">
                        <xsl:with-param name="elemType" select="'submit'" />
                        <xsl:with-param name="content" select="'Update'" />
                    </xsl:call-template>
                </div>
            </div>
        </form>
    </xsl:template>


    <xsl:template name="searchLinks" >
        <div class="ControlsGroup">
            <div class="ControlsGroup-item">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="'Album'" />
                    <xsl:with-param name="active">
                        <xsl:if test="$cmd = 'search'">
                            <xsl:text>true</xsl:text>
                        </xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="url">
                        <xsl:if test="$cmd != 'search'">
                            <xsl:text>/rps/catalog?c=search&amp;Query=</xsl:text>
                            <xsl:value-of select="EncodedQuery" />
                        </xsl:if>
                    </xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="ControlsGroup-item">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="'Track'" />
                    <xsl:with-param name="active">
                        <xsl:if test="$cmd = 'search_track'">
                            <xsl:text>true</xsl:text>
                        </xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="url">
                        <xsl:if test="$cmd != 'search_track'">
                            <xsl:text>/rps/catalog?c=search_track&amp;Query=</xsl:text>
                            <xsl:value-of select="EncodedQuery" />
                        </xsl:if>
                    </xsl:with-param>
                </xsl:call-template>
            </div>
            <div class="ControlsGroup-item">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="'Product'" />
                    <xsl:with-param name="active">
                        <xsl:if test="$cmd = 'search_product'">
                            <xsl:text>true</xsl:text>
                        </xsl:if>
                    </xsl:with-param>
                    <xsl:with-param name="url">
                        <xsl:if test="$cmd != 'search_product'">
                            <xsl:text>/rps/catalog?c=search_product&amp;Query=</xsl:text>
                            <xsl:value-of select="EncodedQuery" />
                        </xsl:if>
                    </xsl:with-param>
                </xsl:call-template>
            </div>
        </div>
    </xsl:template>


    <xsl:template name="searchResultsTitle" >
        <xsl:choose>
            <xsl:when test="$cmd = 'search' or $cmd = 'search_track' or $cmd = 'search_product'" >
                <h2>
                    Search Results <xsl:if test="string-length(Params/Query)">for "<xsl:value-of select="Params/Query" />"</xsl:if>
                    <xsl:if test="AlbumCount or TrackCount or ProductCount">
                        <p class="Heading-addition">
                            <strong><xsl:value-of select="AlbumCount" /></strong> album<xsl:if test="AlbumCount != 1">s</xsl:if>,
                            <strong><xsl:value-of select="TrackCount" /></strong> track<xsl:if test="TrackCount != 1">s</xsl:if>,
                            and <strong><xsl:value-of select="ProductCount" /></strong> product<xsl:if test="ProductCount != 1">s</xsl:if>
                        </p>
                    </xsl:if>
                </h2>
            </xsl:when>
            <xsl:when test="$cmd = 'search_import'">
                <h3>Search Results</h3>
            </xsl:when>
            <xsl:when test="$cmd = 'search_duplicate'">
                <h3>Search Results</h3>
            </xsl:when>
            <xsl:when test="$cmd != 'search_no_image' or $cmd != 'search_no_audio' or $cmd != 'search_no_metadata' or $cmd != 'search_no_dr' ">
                <h3>Search Results</h3>
            </xsl:when>
            <xsl:otherwise>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


</xsl:stylesheet>
