<!--                                                                  -->
<!--  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:variable name="reportLinkParam">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="reportLinkPreffix"><xsl:value-of select="$reportLinkParam" />&amp;</xsl:variable>
    <xsl:variable name="reportLink">?<xsl:value-of select="$reportLinkParam" /></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">
        <div class="MainBaseSection">
            <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>
        </div>
    </xsl:template>

    <xsl:template name="reportHeading">
        <xsl:param name="showMechSwitcher" select="'false'" />
        <xsl:param name="showDownloadLink" select="'true'" />

        <div class="Table-controls Table-controls-top">
            <xsl:if test="$showMechSwitcher = 'true'">
                <div class="Table-controls-item AuditReport-controls-mech">
                    <xsl:call-template name="mechReportSwitcher" />
                </div>
            </xsl:if>
            <div class="Table-controls-item AuditReport-controls-download">
                <xsl:if test="$showDownloadLink = 'true'">
                    <xsl:call-template name="reportDownloadLink" />
                </xsl:if>
            </div>
            <div class="Table-controls-item Table-controls-item-pagination">
                <xsl:call-template name="reportNav" />
            </div>
        </div>
    </xsl:template>

    <xsl:template name="reportDownloadLink">
        <xsl:call-template name="uiDownloadLink">
            <xsl:with-param name="text" select="'Download Text File'" />
            <xsl:with-param name="url">
                <xsl:value-of select="$reportLink" />
                <xsl:text>&amp;download=1</xsl:text>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

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

    <xsl:template name="reportNav">
        <xsl:if test="Report/NumPages != 1">

            <xsl:variable name="paginagionParams">
                <xsl:value-of select="$regionParam" />
                <xsl:value-of select="$labelParam" />
                <xsl:value-of select="$payorParam" />
            </xsl:variable>

            <xsl:call-template name="uiPagination">
                <xsl:with-param name="lastPage" select="Report/NumPages" />
                <xsl:with-param name="currentPage" select="Report/Page" />
                <xsl:with-param name="searchParams" select="$paginagionParams" />
                <xsl:with-param name="searchPreffix" select="$reportLinkPreffix" />
                <xsl:with-param name="pageSize" select="1" />
            </xsl:call-template>

        </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">
            <div class="Form-group Form-group-horizontal">
                <div class="Form-item">
                    <div class="Form-input-wrapper">
                        <xsl:variable name="mechReportSwitcherItems">
                            <map>
                                <mapEntry>
                                    <name>Canadian</name>
                                    <value>
                                        <xsl:text>ca_</xsl:text>
                                        <xsl:value-of select="$parsedCommand" />
                                    </value>
                                </mapEntry>>
                                <mapEntry>
                                    <name>United States</name>
                                    <value>
                                        <xsl:value-of select="$parsedCommand" />
                                    </value>
                                </mapEntry>
                            </map>
                        </xsl:variable>
                        <xsl:call-template name="uiDropdown">
                            <xsl:with-param name="items" select="$mechReportSwitcherItems"/>
                            <xsl:with-param name="name" select="'c'"/>
                            <xsl:with-param name="active" select="$cmd"/>
                            <xsl:with-param name="className" select="'AuditReport-mech-select'"/>
                        </xsl:call-template>
                    </div>
                </div>
                <div class="Form-item">
                    <div class="Form-input-wrapper">
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="content" select="'Update'" />
                            <xsl:with-param name="elemType" select="'submit'" />
                        </xsl:call-template>
                    </div>
                </div>
            </div>
        </form>
    </xsl:template>

    <xsl:template name="backToStatementsHome">
        <div class="Form-fieldset Form-fieldset-buttons">
            <xsl:call-template name="uiButton">
                <xsl:with-param name="content" select="'Back to Statements Home'" />
                <xsl:with-param name="className" select="'Form-button'" />
                <xsl:with-param name="url" select="'statement'"/>
            </xsl:call-template>
        </div>
    </xsl:template>

    <xsl:template name="backToUKMechRun">
        <div class="Form-fieldset Form-fieldset-buttons">
            <xsl:call-template name="uiButton">
                <xsl:with-param name="content" select="'Back to Statements'" />
                <xsl:with-param name="className" select="'Form-button'" />
                <xsl:with-param name="url">
                    <xsl:text>uk_mech?c=show&amp;UKMechanicalRunID=</xsl:text>
                    <xsl:value-of select="Params/run_id" />
                </xsl:with-param>
            </xsl:call-template>
        </div>
    </xsl:template>

    <xsl:template name="backToMechRun">
        <div class="Form-fieldset Form-fieldset-buttons">
            <xsl:call-template name="uiButton">
                <xsl:with-param name="content" select="'Back to Statements'" />
                <xsl:with-param name="className" select="'Form-button'" />
                <xsl:with-param name="url">
                    <xsl:text>mechanical?c=show&amp;MechanicalRunID=</xsl:text>
                    <xsl:value-of select="Params/run_id" />
                    <xsl:text>&amp;PayorID=</xsl:text>
                    <xsl:value-of select="Params/payor_id" />
                </xsl:with-param>
            </xsl:call-template>
        </div>
    </xsl:template>

    <xsl:template name="backToCAMechRun">
        <div class="Form-fieldset Form-fieldset-buttons">
            <xsl:call-template name="uiButton">
                <xsl:with-param name="content" select="'Back to Statements'" />
                <xsl:with-param name="className" select="'Form-button'" />
                <xsl:with-param name="url">
                    <xsl:text>ca_mechanical?c=show&amp;MechanicalRunID=</xsl:text>
                    <xsl:value-of select="Params/run_id" />
                    <xsl:text>&amp;PayorID=</xsl:text>
                    <xsl:value-of select="Params/payor_id" />
                </xsl:with-param>
            </xsl:call-template>
        </div>
    </xsl:template>

    <xsl:template name="backToArtistRun">
        <div class="Form-fieldset Form-fieldset-buttons">
            <xsl:call-template name="uiButton">
                <xsl:with-param name="content" select="'Back to Statements'" />
                <xsl:with-param name="className" select="'Form-button'" />
                <xsl:with-param name="url">
                    <xsl:text>artist_royalty?c=show&amp;RoyaltyRunID=</xsl:text>
                    <xsl:value-of select="Params/run_id" />
                </xsl:with-param>
            </xsl:call-template>
        </div>
    </xsl:template>

</xsl:stylesheet>

