<!--                                                                  -->
<!--  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:variable name="reportLink">?c=<xsl:value-of select="$cmd" /><xsl:if test="/Root/Params/run_id">&amp;run_id=<xsl:value-of select="/Root/Params/run_id" /></xsl:if></xsl:variable>
  
    <xsl:variable name="regionParam">
  	    <xsl:if test="normalize-space(/Root/Params/region_id)">&amp;region_id=<xsl:value-of select="/Root/Params/region_id" /></xsl:if>
    </xsl:variable>
  
    <xsl:variable name="labelParam">
  	    <xsl:if test="normalize-space(/Root/Params/label_id)">&amp;label_id=<xsl:value-of select="/Root/Params/label_id" /></xsl:if>
    </xsl:variable>  
    
    <xsl:variable name="payorParam">
  	    <xsl:if test="normalize-space(/Root/Params/payor_id)">&amp;payor_id=<xsl:value-of select="/Root/Params/payor_id" /></xsl:if>
    </xsl:variable>    

    <xsl:variable name="licenseArea">
        <xsl:choose>
            <xsl:when test="$cmd = 'ca_inactive_licenses'">ca_license</xsl:when>
            <xsl:otherwise>license</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:variable name="publisherArea">
        <xsl:choose>
            <xsl:when test="$cmd = 'ca_inactive_licenses' or $cmd = 'ca_publisher_mailing'">ca_publisher</xsl:when>
            <xsl:otherwise>publisher</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:include href="/app/tools/rps/templates/global.xsl" />
    <xsl:include href="tracks_no_timings.xsl" />
    <xsl:include href="license_overage.xsl" />
	<xsl:include href="tracks_no_licenses.xsl" />
	<xsl:include href="inactive_licenses.xsl" />
	<xsl:include href="albums_no_contracts.xsl" />
	<xsl:include href="products_no_prices.xsl" />
	<xsl:include href="missed_sales.xsl" />	
	<xsl:include href="payee_mailing.xsl" />
	<xsl:include href="publisher_mailing.xsl" />
	<xsl:include href="license_accrual.xsl" />
	<xsl:include href="artist_reserve_pipeline.xsl" />	
	<xsl:include href="uk_mech_unit_summary.xsl" />
	<xsl:include href="uk_mech_negative_units.xsl" />
	<xsl:include href="uk_mech_current_retentions.xsl" />
	<xsl:include href="uk_mech_retention_summary.xsl" />
	<xsl:include href="uk_mech_missed_sales.xsl" />
	<xsl:include href="mechanical_reserve_pipeline.xsl" />	
	<xsl:include href="labels_no_contracts.xsl" />
	<xsl:include href="labels_multiple_contracts.xsl" />
	
  <xsl:template name="pickLayout">
    <xsl:choose>
      <xsl:when test="$cmd = 'tracks_no_timings' or $cmd = 'ca_tracks_no_timings'">
        <xsl:call-template name="tracksNoTimingsLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'license_overage' or $cmd = 'ca_license_overage'">
        <xsl:call-template name="licenseOverageLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'tracks_no_licenses' or $cmd = 'ca_tracks_no_licenses'">
        <xsl:call-template name="tracksNoLicensesLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'inactive_licenses' or $cmd = 'ca_inactive_licenses'">
        <xsl:call-template name="inactiveLicensesLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'albums_no_contracts'">
        <xsl:call-template name="albumsNoContractsLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'products_no_prices'">
        <xsl:call-template name="productsNoPricesLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'missed_sales'">
        <xsl:call-template name="missedSalesLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'payee_mailing'">
        <xsl:call-template name="payeeMailingLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'publisher_mailing' or $cmd = 'ca_publisher_mailing'">
        <xsl:call-template name="publisherMailingLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'license_accrual' or $cmd = 'ca_license_accrual'">
        <xsl:call-template name="licenseAccrualLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'artist_reserve_pipeline'">
        <xsl:call-template name="artistPipelineLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'uk_mech_unit_summary'">
        <xsl:call-template name="ukMechUnitSummaryLayout" />
      </xsl:when>      
      <xsl:when test="$cmd = 'uk_mech_negative_units'">
        <xsl:call-template name="ukMechNegativeUnitsLayout" />
      </xsl:when>     
      <xsl:when test="$cmd = 'uk_mech_current_retentions'">
        <xsl:call-template name="ukMechCurrentRetentionsLayout" />
      </xsl:when>   
      <xsl:when test="$cmd = 'uk_mech_retention_summary' or $cmd = 'uk_mech_retention_run_summary'">
        <xsl:call-template name="ukMechRetentionSummaryLayout" />
      </xsl:when>      
      <xsl:when test="$cmd = 'uk_mech_missed_sales'">
        <xsl:call-template name="ukMechMissedSalesLayout" />
      </xsl:when>                           
      <xsl:when test="$cmd = 'mechanical_reserve_pipeline' or $cmd = 'ca_mechanical_reserve_pipeline'">
        <xsl:call-template name="mechanicalPipelineLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'labels_no_contracts'">
        <xsl:call-template name="labelsNoContractsLayout" />
      </xsl:when>      
      <xsl:when test="$cmd = 'labels_multiple_contracts'">
        <xsl:call-template name="labelsMultipleContractsLayout" />
      </xsl:when>          
    </xsl:choose>
  </xsl:template>
  
	<xsl:template name="reportHeading">
	
		<xsl:variable name="page">
			<xsl:choose>
				<xsl:when test="normalize-space(Report/Page)">
					<xsl:value-of select="Report/Page" />
				</xsl:when>
				<xsl:otherwise>1</xsl:otherwise>
			</xsl:choose>	
		</xsl:variable>
		
		<xsl:variable name="numPages">
			<xsl:choose>
				<xsl:when test="normalize-space(Report/NumPages)">
					<xsl:value-of select="Report/NumPages" />
				</xsl:when>
				<xsl:otherwise>1</xsl:otherwise>
			</xsl:choose>		
		</xsl:variable>
	
		<div class="reportHeading">
			<span class="pageInfo">
				Page <xsl:value-of select="$page" /> of <xsl:value-of select="$numPages" />
			</span>
			<a href="{$reportLink}&amp;download=1" title="Download Text File"><img src="/production/images/icons/office/Document-(16x16).gif" height="16" width="16" /></a> <a href="{$reportLink}&amp;download=1">Download Text File</a>
		</div>
	</xsl:template>

	<xsl:template name="reportNavNext">
    <xsl:if test="Report/Page &lt; Report/NumPages">
    	&#160;
      <a href="{$reportLink}&amp;page={Report/Page + 1}{$regionParam}{$labelParam}{$payorParam}">Next &#8250;</a>
      &#160;
      <a href="{$reportLink}&amp;page={Report/NumPages}{$regionParam}{$labelParam}{$payorParam}">Last &#187;</a>
    </xsl:if>	
	</xsl:template>
	
	<xsl:template name="reportNavPrev">
    <xsl:if test="Report/Page &gt; 1 and Report/NumPages != 1">
      <a href="{$reportLink}&amp;page=1{$regionParam}{$labelParam}{$payorParam}">&#171; First</a>
      &#160;
      <a href="{$reportLink}&amp;page={Report/Page - 1}{$regionParam}{$labelParam}{$payorParam}">&#8249; Previous</a>
      &#160;
    </xsl:if>
	</xsl:template>
	
	<xsl:template name="reportNav">
		<xsl:if test="Report/NumPages != 1">
			<div class="navDigits">
			
				<xsl:call-template name="reportNavPrev" />
				
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'10'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'9'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'8'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'7'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'6'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'5'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'4'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'3'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'2'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkBack">
					<xsl:with-param name="goBack" select="'1'" />
				</xsl:call-template>
				
				<span class="navDigitsOn"><xsl:value-of select="Report/Page" /></span>
	
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'1'" />
				</xsl:call-template>			
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'2'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'3'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'4'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'5'" />
				</xsl:call-template>	
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'6'" />
				</xsl:call-template>		
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'7'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'8'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'9'" />
				</xsl:call-template>
				<xsl:call-template name="digitNavLinkForward">
					<xsl:with-param name="goForward" select="'10'" />
				</xsl:call-template>
				
				<xsl:call-template name="reportNavNext" />
				
			</div>	
		</xsl:if>
	</xsl:template>
	
	<xsl:template name="digitNavLinkBack">
		<xsl:param name="goBack" />
		<xsl:variable name="pageNumber" select="Report/Page - $goBack" />
		<xsl:if test="$pageNumber &gt; 0">
			<a href="{$reportLink}&amp;page={$pageNumber}{$regionParam}{$labelParam}{$payorParam}"><xsl:value-of select="$pageNumber" /></a>
		</xsl:if>
	</xsl:template>

	<xsl:template name="digitNavLinkForward">
		<xsl:param name="goForward" />
		<xsl:variable name="pageNumber" select="Report/Page + $goForward" />
		<xsl:if test="$pageNumber &lt;= Report/NumPages">
			<a href="{$reportLink}&amp;page={$pageNumber}{$regionParam}{$labelParam}{$payorParam}"><xsl:value-of select="$pageNumber" /></a>
		</xsl:if>
	</xsl:template>
	
	
	<xsl:template name="mechReportSwitcher">
	    <xsl:variable name="parsedCommand">
	        <xsl:choose>
	            <xsl:when test="substring($cmd,1,3) = 'ca_'">
	                <xsl:value-of select="substring($cmd,4)" />
	            </xsl:when>
	            <xsl:otherwise>
	                <xsl:value-of select="$cmd" />
	            </xsl:otherwise>
	        </xsl:choose>
	    </xsl:variable>
	    <form action="report" method="get" id="mechReportSwitcher">
	        <select name="c">
	            <option value="ca_{$parsedCommand}">
	                Canadian
	            </option>
	            <option value="{$parsedCommand}">
	                <xsl:if test="$cmd = $parsedCommand">
	                    <xsl:attribute name="selected">selected</xsl:attribute>
	                </xsl:if>
	                United States
	            </option>
	        </select>&#160;<input type="submit" value="Update" />
	    </form> 
	</xsl:template>
	
	
	<xsl:template name="backToStatementsHome">
		<div class="section">
		    <div class="backButton">
		        <input type="button" value="Back to Statements Home" onclick="location.href='statement'" />
		    </div>
		</div>	
	</xsl:template>
	

	<xsl:template name="backToUKMechRun">
		<div class="section">
		    <div class="backButton">
		        <input type="button" value="Back to Statements" onclick="location.href='uk_mech?c=show&amp;UKMechanicalRunID={Params/run_id}'" />
		    </div>
		</div>	
	</xsl:template>


	<xsl:template name="backToMechRun">
		<div class="section">
		    <div class="backButton">
		        <input type="button" value="Back to Statements" onclick="location.href='mechanical?c=show&amp;MechanicalRunID={Params/run_id}&amp;PayorID={Params/payor_id}'" />
		    </div>
		</div>	
	</xsl:template>
	
	
	<xsl:template name="backToCAMechRun">
		<div class="section">
		    <div class="backButton">
		        <input type="button" value="Back to Statements" onclick="location.href='ca_mechanical?c=show&amp;MechanicalRunID={Params/run_id}&amp;PayorID={Params/payor_id}'" />
		    </div>
		</div>	
	</xsl:template>	
	

	<xsl:template name="backToArtistRun">
		<div class="section">
		    <div class="backButton">
		        <input type="button" value="Back to Statements" onclick="location.href='artist_royalty?c=show&amp;RoyaltyRunID={Params/run_id}'" />
		    </div>
		</div>	
	</xsl:template>
	

</xsl:stylesheet>

