<!--                                                                  -->
<!--  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="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" encoding="utf-8" />

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

    <xsl:variable name="ccompTest"><xsl:if test="//IsControlledComp = 1">1</xsl:if></xsl:variable>
    <xsl:variable name="contractName">AlbumContractID</xsl:variable>
    <xsl:variable name="contractID"><xsl:value-of select="/Root/Params/AlbumContractID" /></xsl:variable>
 
 
    <xsl:template name="pickLayout">
        <xsl:call-template name="catalogViewLayout" />
    </xsl:template>


    <xsl:template name="catalogViewLayout">   
        <xsl:call-template name="trackList" /><br />
        <xsl:call-template name="productView" />
    </xsl:template>


    <xsl:template name="trackList">
        <fieldset id="trackListTable">
            <legend>Tracks</legend>
            <table class="textChart" id="trackTable">
                <tbody>
                    <xsl:if test="Form/Album/TrackList/Track">
                        <xsl:call-template name="addTrackButton">
                            <xsl:with-param name="position" select="'top'" />
                        </xsl:call-template>
                        <tr>
                            <th id="trackCol">Track</th>
                            <th id="nameCol">Name</th>              
                            <th></th>             
                            <th id="lengthCol">Length</th>
                            <th id="artistCol">Artist</th>
                            <th>Parental Advisory</th>
                            <th>Media Type</th>
                            <xsl:if test="Access/rps/track/edit">
                                <th id="trackEdit">Actions</th>
                            </xsl:if>
                        </tr>
                        <xsl:for-each select="Form/Album/TrackList/Track">
                            <xsl:call-template name="trackListRow" />
                        </xsl:for-each>
                    </xsl:if>
                    <xsl:call-template name="addTrackButton">
                        <xsl:with-param name="position" select="'bottom'" />
                    </xsl:call-template>
                </tbody>
            </table>
        </fieldset>
    </xsl:template>
    
  
    <xsl:template name="addTrackButton">
        <xsl:param name="position" />
        <xsl:if test="Access/rps/track/edit">
            <tr>
                <td colspan="8" class="right">
                    <xsl:if test="$position = 'bottom'">
                        <input type="button" value="Edit Tracks" onClick="javascript:location.href='catalog?AlbumID={Form/Album/AlbumID}&amp;c=da_edit'" class="{$position}Button" />	
                    </xsl:if>                   
                    <input type="button" value="Add Track" onClick="javascript:location.href='track?AlbumID={Form/Album/AlbumID}&amp;c=edit'" class="{$position}Button" />
                </td>
            </tr>
        </xsl:if>  
    </xsl:template>


    <xsl:template name="trackListRow">
        <xsl:variable name="trackRowID">trackSummary_<xsl:value-of select="TrackID" /></xsl:variable>
        <tr class="row{position() mod 2}" id="{$trackRowID}">    
            	
            <td>
                <a href="javascript:void(0);" onClick="showTrackDetails(this,'{TrackID}');" title="Expand" onMouseOver="javascript:window.status=''; return true;" id="toggle_{TrackID}"><img src="/production/images/icons/expand.gif" class="showDetails" /></a>
                <span id="{$trackRowID}_TrackOrderDisplay">
                    <xsl:if test="TrackOrder &lt; 10">0</xsl:if><xsl:value-of select="TrackOrder" />
                </span>	   
                <script type="text/javascript">
                    addSweetTitle('toggle_<xsl:value-of select="TrackID" />');
                </script>   	
            </td>  
            
            <td>
                <a href="track?c=show&amp;TrackID={TrackID}"><xsl:value-of select="Title" /></a>&#160;
                <xsl:if test="/Root/Access/app/reports/k">
                    <xsl:variable name="trackID" select="TrackID" />
                    <xsl:for-each select="/Root/Form/TrackProductList/TrackProduct[AssetID = $trackID]">
                        <xsl:variable name="parentProductID" select="ParentProductID" />
                        <xsl:variable name="upc">
                            <xsl:choose>
                                <xsl:when test="normalize-space($parentProductID)">
                                    <xsl:value-of select="/Root/Form/ProductList/Product[ProductID = $parentProductID]/UPC" />
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="UPC" />
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>      	        
                        <a href="/app/reports?c=k&amp;product={ProductID}" title="Sales Analytics for &quot;{$upc}&quot;" class="iconLink" id="analytics_{$trackID}"><img src="/production/images/icons/office/Pie-Chart2-(14x14).png" /></a>
                        <script type="text/javascript">
                            addSweetTitle('analytics_<xsl:value-of select="$trackID" />');
                        </script> 
                    </xsl:for-each>
                </xsl:if>         
            </td>
        
            <td class="previewIcon">        
                <xsl:if test="normalize-space(AudioPreviewURL) and /Root/Access/rps/catalog/download_mp3">
                    <a href="{AudioPreviewURL}" title="Download MP3" id="preview_{TrackID}"><img src="/production/images/icons/office/Volume-(16x16).png" height="16" width="16" /></a>
                    <script type="text/javascript">
                        addSweetTitle('preview_<xsl:value-of select="TrackID" />');
                    </script>   	
                </xsl:if>     	
            </td>
        
            <td><xsl:value-of select="Master/Duration" /></td>
            
            <td>
                <xsl:value-of select="ArtistName" />
                <xsl:if test="count(AdditionalArtistList/AdditionalArtist) != 0">
                    &#160;<a class="iconLink" id="artists_{TrackID}">
                        <xsl:attribute name="title">
                            <xsl:for-each select="AdditionalArtistList/AdditionalArtist">
                                <xsl:sort select="AdditionalArtistID" data-type="number" />
                                <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>   
                <script type="text/javascript">
                    addSweetTitle('artists_<xsl:value-of select="TrackID" />');
                </script>                
            </td>
        
            <td>
                <xsl:call-template name="albumParentalAdvisory">
                    <xsl:with-param name="advisory" select="ParentalAdvisory" />
                </xsl:call-template>
            </td>
            
            <td>
                <xsl:choose>
                    <xsl:when test="MediaType = 2">Video</xsl:when>
                    <xsl:otherwise>Audio</xsl:otherwise>
                </xsl:choose>
            </td>
        
            <xsl:if test="/Root/Access/rps/track/edit">
                <td class="icon">
                    <a href="/rps/track?c=edit&amp;TrackID={TrackID}">Edit</a>
                </td>
            </xsl:if>
        </tr>
        
        <tr class="trackInfo row{position() mod 2}" id="trackArtists_{TrackID}" style="display:none">
        <td colspan="4" />
        <td colspan="3">
        <xsl:if test="/Root/Access/rps/track/edit">
        <xsl:attribute name="colspan">4</xsl:attribute>
        </xsl:if>     
        <xsl:for-each select="AdditionalArtistList/AdditionalArtist">
        <xsl:sort select="AdditionalArtistID" />
        <xsl:value-of select="Name" /> (<xsl:value-of select="Role/Role" />)<br />
        </xsl:for-each>
        </td>
        </tr>
        
        <tr class="trackInfo row{position() mod 2}" id="trackDetails_{TrackID}" style="display:none">
        <td colspan="7" class="subTable">
        <xsl:if test="/Root/Access/rps/track/edit">
        <xsl:attribute name="colspan">9</xsl:attribute>
        </xsl:if>      
        <table class="textTable">
        <tr>
        <th colspan="2">Track</th>
        </tr>
        <tr>
        <td class="leftCol">Client Track ID:</td>
        <td><xsl:value-of select="ClientTrackID" /></td>
        </tr>          
        <tr>
        <td class="leftCol">
        <xsl:choose>
        <xsl:when test="/Root/Client/ClientID = 338">DTI:</xsl:when>
        <xsl:otherwise>Custom 1:</xsl:otherwise>
        </xsl:choose>
        </td>
        <td><xsl:value-of select="Custom1" /></td>
        </tr>
        <tr>
        <td class="leftCol">Custom 2:</td>
        <td><xsl:value-of select="Custom2" /></td>
        </tr>
        <tr>
        <td class="leftCol">Custom 3:</td>
        <td><xsl:value-of select="Custom3" /></td>
        </tr>                    
        </table>
        <table class="textTable">
        <tr>
        <th colspan="2">Master</th>
        </tr>
        <tr>
        <td class="leftCol">Title:</td>
        <td><xsl:value-of select="Master/Title" /></td>
        </tr>
        <tr>
        <td class="leftCol">Artist:</td>
        <td><xsl:value-of select="Master/ArtistName" /></td>
        </tr>
        <tr>
        <td class="leftCol">ISRC:</td>
        <td><xsl:value-of select="Master/ISRC" /></td>
        </tr>
        <tr>
        <td class="leftCol">Recording Date:</td>
        <td><xsl:value-of select="Master/DateRecorded" /></td>
        </tr>
        </table>
        <table class="textTable">
        <tr>
        <th colspan="2">Song</th>
        </tr>
        <tr>
        <td class="leftCol">Title:</td>
        <td><xsl:value-of select="Master/Song/Title" /></td>
        </tr>
        <tr>
        <td class="leftCol">Composer:</td>
        <td><xsl:value-of select="Master/Song/ComposerName" /></td>
        </tr>
        <tr>
        <td class="leftCol">ISWC:</td>
        <td><xsl:value-of select="Master/Song/ISWC" /></td>
        </tr>
        </table>
        </td>
        </tr>
    </xsl:template>


    <xsl:template name="productView">
        <fieldset id="productViewTable">
            <legend>Products</legend>
            <table class="textChart">
                <tbody>
                    
                    <xsl:if test="Form/ProductList/Product">
                        <tr>
                            <th id="productType">Type</th>
                            <th id="productTitle">Product Title</th>
                            <th id="productID">Product ID</th>
                            <th id="productUPC">UPC</th>
                            <th id="productDate">Release Date</th>
                            <th id="productStatus" class="status">Status</th>
                            <th class="editCol">Actions</th>
                        </tr>
                        <xsl:for-each select="Form/ProductList/Product[ProductTypeID = 3]">
                            <xsl:call-template name="productRow" />
                        </xsl:for-each>
                        <xsl:for-each select="Form/ProductList/Product[ProductTypeID != 3]">
                            <xsl:call-template name="productRow">
                                <xsl:with-param name="daCount" select="count(/Root/Form/ProductList/Product[ProductTypeID = 3])" />
                            </xsl:call-template>
                        </xsl:for-each>              
                    </xsl:if>
                        
                    <xsl:if test="ClientTypes/ClientType[ClientTypeID = 2]/IsClientTypeFlag = 1 or ClientTypes/ClientType[ClientTypeID = 5]/IsClientTypeFlag = 1 or ClientTypes/ClientType[ClientTypeID = 6]/IsClientTypeFlag = 1">
                        <tr>
                            <td colspan="7" class="right">
                                <input type="button" id="addProductButton" value="Add Product" onClick="location.href='product?c=edit&amp;AlbumID={Form/Album/AlbumID}'" class="bottomButton">          
                                    <xsl:if test="not(Form/Album/TrackList/Track/TrackID)">
                                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                                    </xsl:if>
                                </input>
                            </td>
                        </tr>
                    </xsl:if>
                    
                </tbody>
            </table>
        </fieldset>
    </xsl:template>


    <xsl:template name="productRow">
        <xsl:param name="daCount" select="'0'" />
        <tr class="row{($daCount + position()) mod 2}">   
            <td>
                <xsl:variable name="productTypeID" select="ProductTypeID" />
                <a href="/rps/product?c=show&amp;ProductID={ProductID}">
                    <xsl:value-of select="/Root/Form/TypeList/Type[ProductTypeID = $productTypeID]/Description" />
                </a>
                <xsl:if test="/Root/Access/app/reports/a and $productTypeID = 3">            	
                    &#160;<a href="/app/reports?c=a&amp;product={ProductID}" title="Sales Analytics for &quot;{UPC}&quot;" class="iconLink" id="analytics_{ProductID}"><img src="/production/images/icons/office/Pie-Chart2-(14x14).png" /></a>
                    <script type="text/javascript">
                        addSweetTitle('analytics_<xsl:value-of select="ProductID" />');
                    </script>             
                </xsl:if>               
            </td>
            <td><xsl:value-of select="Title" /></td>
            <td><xsl:value-of select="ProductCode" /></td>
            <td><xsl:value-of select="UPC" /></td>
            <td><xsl:value-of select="ReleaseDate" /></td>   
            <td class="status">
                <xsl:variable name="productStatusID" select="ProductStatusID" />
                <xsl:value-of select="/Root/Form/StatusList/Status[ProductStatusID = $productStatusID]/Description" />
            </td>
            <td class="icon">
                <a href="/rps/product?c=edit&amp;ProductID={ProductID}">Edit</a>
            </td>
        </tr>
    </xsl:template>
  

</xsl:stylesheet>
