<!--                                                                  -->
<!--  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="section">
            <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) )" >
                            <p>No results matched your search.</p><br />
                        </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">

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

        <div class="searchSize"><xsl:call-template name="pageSizeForm" /></div>

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

        <xsl:call-template name="searchNavRecords" />
        <xsl:call-template name="searchText" />

        <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>
        
        <xsl:call-template name="searchNavRecords" />
        
        <xsl:if test="normalize-space(Pagination/Previous) or normalize-space(Pagination/Next)">
            <br class="superBreak" />
            <br />
        </xsl:if>

    </xsl:template>
  

    <xsl:template name="albumResults">
        <table class="textChart hiOn">
            
            <tr>
                <xsl:if test="$showDigitalUPC = 1">
                    <th>Digital UPC</th>
                </xsl:if>
                <th>Title</th>
                <th>Catalog #</th>
                <th>Artist</th>
                <xsl:if test="LabelList/Label">
                    <th>Label</th>
                </xsl:if>
                <xsl:if test="$cmd = 'search_import'">
                    <th>Date Imported</th>
                </xsl:if>
                <xsl:if test="Params/c = 'search_in_queue'">
                    <th>Date Queued</th>
                </xsl:if>
                <xsl:if test="Params/c = 'search_delivered'">
                    <th>Date Delivered</th>
                </xsl:if>
                <th class="status">Status</th>
                <xsl:if test="Access/rps/catalog/edit or Access/rps/catalog/da_edit">
                    <th class="editCol">Edit</th>
                </xsl:if>
            </tr>
        
            <xsl:for-each select="Album">
                <tr class="row{position() mod 2}">
                    <xsl:if test="$showDigitalUPC = 1">
                        <td>
                            <a href="catalog?AlbumID={AlbumID}&amp;c={$daTest}show">
                                <xsl:value-of select="DigitalUPC" />
                            </a>
                        </td>
                    </xsl:if>
                    <td>
                        <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><xsl:value-of select="CatalogNumber" /></td>
                    <td>
                        <xsl:value-of select="ArtistName" />
                        <xsl:if test="count(AdditionalArtistList/AdditionalArtist) != 0">
                            &#160;<a class="iconLink">
                                <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>
                                <img src="/production/images/icons/speech_bubble.gif" style="vertical-align: top" />
                            </a>
                        </xsl:if>
                    </td>
                    <xsl:if test="/Root/LabelList/Label">
                        <xsl:variable name="albumLabelID"><xsl:value-of select="LabelID" /></xsl:variable>
                        <td><xsl:value-of select="/Root/LabelList/Label[LabelID = $albumLabelID]/LabelName" /></td>
                    </xsl:if>
                    <xsl:if test="$cmd = 'search_import'">
                        <td><xsl:value-of select="CreatedDate" /></td>
                    </xsl:if>
                    <xsl:if test="/Root/Params/c = 'search_in_queue'">
                        <td><xsl:value-of select="DateQueued" /></td>
                    </xsl:if>
                    <xsl:if test="/Root/Params/c = 'search_delivered'">
                        <td><xsl:value-of select="DateDelivered" /></td>
                    </xsl:if>
                    <td class="status">
                        <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="icon">
                            <a href="catalog?c={$daTest}edit&amp;AlbumID={AlbumID}" title="Edit">
                                <img src="/production/images/icons/office/Edit-(16x16).gif" />
                            </a>
                        </td>
                    </xsl:if>
                </tr>
            </xsl:for-each>
            
        </table>
    </xsl:template>


    <xsl:template name="trackResults">
        <table class="textChart hiOn">
            
            <tr>
                <th>Title</th>
                <th>Track #</th>
                <th>ISRC</th>
                <th>Track Artist</th>
                <th>Album Title</th>
                <th class="editCol">Edit</th>
            </tr>

            <xsl:for-each select="Track">
                <tr class="row{position() mod 2}">
                    <td><a href="/rps/track?c=show&amp;TrackID={TrackID}"><xsl:value-of select="Title" /></a></td>
                    <td><xsl:value-of select="TrackOrder" /></td>
                    <td><xsl:value-of select="Master/ISRC" /></td>
                    <td>
                        <xsl:value-of select="ArtistName" />
                        <xsl:if test="count(AdditionalArtistList/AdditionalArtist) != 0">
                            &#160;<a class="iconLink">
                                <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>
                                <img src="/production/images/icons/speech_bubble.gif" style="vertical-align: top" />
                            </a>
                        </xsl:if>
                    </td>
                    <td><xsl:value-of select="AlbumName" /></td>
                    <td class="icon">
                        <a href="/rps/track?c=edit&amp;TrackID={TrackID}" title="Edit">
                            <img src="/production/images/icons/office/Edit-(16x16).gif" />
                        </a>
                    </td>
                </tr>
            </xsl:for-each>
            
        </table>
    </xsl:template>


    <xsl:template name="productResults">
        <table class="textChart hiOn">
            
            <tr>
                <th>Title</th>
                <th>Type</th>
                <th>Product ID</th>
                <th>UPC</th>
                <th>Artist</th>
                <th class="editCol">Edit</th>
            </tr>

            <xsl:for-each select="Product">
                <tr class="row{position() mod 2}">
                    <td>
                        <a href="/rps/product?c=show&amp;ProductID={ProductID}">
                            <xsl:value-of select="Title" />
                        </a>
                    </td>
                    <td>
                        <xsl:variable name="productTypeID" select="ProductTypeID" />   
                        <xsl:value-of select="/Root/TypeList/Type[ProductTypeID = $productTypeID]/Description" />
                    </td>                                 
                    <td><xsl:value-of select="ProductCode" /></td>
                    <td><xsl:value-of select="UPC" /></td>
                    <td><xsl:value-of select="ArtistName" /></td> 
                    <td class="icon">
                        <a href="/rps/product?c=edit&amp;ProductID={ProductID}" title="Edit">
                            <img src="/production/images/icons/office/Edit-(16x16).gif" />
                        </a>
                    </td>
                </tr>
            </xsl:for-each>
            
        </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>

            <select name="PageSize">
                <xsl:if test="Pagination/PageSize != 25 and Pagination/PageSize != 50 and Pagination/PageSize != 100">
                    <option ><xsl:attribute name="value" select="Pagination/PageSize" />
                        <xsl:value-of select="Pagination/PageSize" />
                    </option>
                </xsl:if>
                <option value="25" >
                    <xsl:if test="Pagination/PageSize = 25">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                    </xsl:if>
                    25
                </option>
                <option value="50" >
                    <xsl:if test="Pagination/PageSize = 50">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                    </xsl:if>
                    50
                </option>
                <option value="100" >
                    <xsl:if test="Pagination/PageSize = 100">
                        <xsl:attribute name="selected">selected</xsl:attribute>
                    </xsl:if>
                    100
                </option>
            </select>
            results per page
            <input type="submit" value="Update" />
        </form>
    </xsl:template>


    <xsl:template name="searchLinks" >

        <xsl:choose>
            <xsl:when test="$cmd = 'search'"><b>Album</b></xsl:when>
            <xsl:otherwise><a href="/rps/catalog?c=search&amp;Query={EncodedQuery}">Album</a></xsl:otherwise>
        </xsl:choose>
        |
        <xsl:choose>
            <xsl:when test="$cmd = 'search_track'"><b>Track</b></xsl:when>
            <xsl:otherwise><a href="/rps/catalog?c=search_track&amp;Query={EncodedQuery}">Track</a></xsl:otherwise>
        </xsl:choose>
        |
        <xsl:choose>
            <xsl:when test="$cmd = 'search_product'"><b>Product</b></xsl:when>
            <xsl:otherwise><a href="/rps/catalog?c=search_product&amp;Query={EncodedQuery}">Product</a></xsl:otherwise>
        </xsl:choose>
        
    </xsl:template>


    <xsl:template name="searchResultsTitle" >
        <xsl:choose>
            <xsl:when test="$cmd = 'search' or $cmd = 'search_track' or $cmd = 'search_product'" >
                <h3 class="comboSearchHeader">
                    Search Results <xsl:if test="string-length(Params/Query)">for "<xsl:value-of select="Params/Query" />"</xsl:if>
                </h3>
                <xsl:if test="AlbumCount or TrackCount or ProductCount">
                    <xsl:value-of select="AlbumCount" /> album<xsl:if test="AlbumCount != 1">s</xsl:if>, <xsl:value-of select="TrackCount" /> track<xsl:if test="TrackCount != 1">s</xsl:if>, and <xsl:value-of select="ProductCount" /> product<xsl:if test="ProductCount != 1">s</xsl:if>
                </xsl:if>
            </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>
