<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<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:include href="/app/tools/admin/templates/global.xsl" />

    <xsl:template name="pickLayout">
        <div class="MainBaseSection">
            <xsl:call-template name="mcpsShowLayout" />
        </div>
    </xsl:template>

    <xsl:template name="mcpsShowLayout">
        <xsl:call-template name="helpLink" />
        <xsl:call-template name="successMessageGeneral">
            <xsl:with-param name="successMessage">MCPS Settings successfully updated!</xsl:with-param>
        </xsl:call-template>
        <xsl:call-template name="defaultRoyaltyRates" />
        <xsl:call-template name="retentionRates" />
        <xsl:call-template name="pricingMode" />
        <xsl:call-template name="exportSettings" />
        <xsl:call-template name="buttons" />
    </xsl:template>

    <xsl:template name="defaultRoyaltyRates">
        <fieldset class="Form-fieldset Form-fieldset-morespace">
            <h2>Default Royalty Rates</h2>
            <table class="Table">
                <thead>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col"></th>
                        <th class="Table-col Table-col-amount Table-col-rightpad"></th>
                        <th class="Table-col Table-col-amount Table-col-rightpad">DVD1</th>
                        <th class="Table-col Table-col-amount Table-col-rightpad"></th>
                        <th class="Table-col Table-col-amount Table-col-rightpad"></th>
                        <th class="Table-col Table-col-amount Table-col-rightpad"></th>
                    </tr>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col"></th>
                        <th class="Table-col Table-col-amount Table-col-rightpad">AP1</th>
                        <th class="Table-col Table-col-amount Table-col-rightpad">Cat A</th>
                        <th class="Table-col Table-col-amount Table-col-rightpad">Cat B</th>
                        <th class="Table-col Table-col-amount Table-col-rightpad">Cat C</th>
                        <th class="Table-col Table-col-amount Table-col-rightpad">AVP</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col Table-col-heading">Dealer&#160;Sales</td>
                        <xsl:call-template name="defaultRateRow">
                            <xsl:with-param name="saleChannelID">1</xsl:with-param>
                        </xsl:call-template>
                    </tr>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col Table-col-heading">Retail&#160;Sales</td>
                        <xsl:call-template name="defaultRateRow">
                            <xsl:with-param name="saleChannelID">2</xsl:with-param>
                        </xsl:call-template>
                    </tr>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col Table-col-heading">Deletions</td>
                        <td colspan="5" class="Table-col Table-col-common">All - 10% of gross sales</td>
                    </tr>
                </tbody>
            </table>
        </fieldset>
    </xsl:template>

    <xsl:template name="defaultRateRow">
        <xsl:param name="saleChannelID" />
        <xsl:variable name="defaultRate" select="McpsSettings/DefaultRoyaltyRateList/DefaultRoyaltyRate[McpsSaleChannelID = $saleChannelID]" />
        <td class="Table-col Table-col-amount Table-col-rightpad">
            <xsl:value-of select="$defaultRate/AP1Rate" />%
        </td>
        <td class="Table-col Table-col-amount Table-col-rightpad">
            <xsl:value-of select="$defaultRate/CatARate" />%
        </td>
        <td class="Table-col Table-col-amount Table-col-rightpad">
            <xsl:value-of select="$defaultRate/CatBRate" />%
        </td>
        <td class="Table-col Table-col-amount Table-col-rightpad">
            <xsl:value-of select="$defaultRate/CatCRate" />%
        </td>
        <td class="Table-col Table-col-amount Table-col-rightpad">
            <xsl:value-of select="$defaultRate/CatAVPRate" />%
        </td>
    </xsl:template>

    <xsl:template name="retentionRates">
        <fieldset class="Form-fieldset Form-fieldset-morespace">
            <h2>MCPS Retention Rates</h2>
            <table class="Table">
                <tbody>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col Table-col-heading">Period</td>
                        <td class="Table-col Table-col-heading Table-col-amount Table-col-rightpad">1</td>
                        <td class="Table-col Table-col-heading Table-col-amount Table-col-rightpad">2</td>
                        <td class="Table-col Table-col-heading Table-col-amount Table-col-rightpad">3</td>
                        <td class="Table-col Table-col-heading Table-col-amount Table-col-rightpad">4</td>
                    </tr>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col Table-col-heading">Standard</td>
                        <xsl:call-template name="retentionRateRow">
                            <xsl:with-param name="retentionCategoryID">1</xsl:with-param>
                        </xsl:call-template>
                    </tr>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col Table-col-heading">TV&#160;Advertised</td>
                        <xsl:call-template name="retentionRateRow">
                            <xsl:with-param name="retentionCategoryID">2</xsl:with-param>
                        </xsl:call-template>
                    </tr>
                </tbody>
            </table>
        </fieldset>
    </xsl:template>

    <xsl:template name="retentionRateRow">
        <xsl:param name="retentionCategoryID" />
        <xsl:variable name="retentionRate" select="McpsSettings/RetentionRateList/RetentionRate[McpsLicenseRetentionCategoryID = $retentionCategoryID]" />
        <td class="Table-col Table-col-amount Table-col-rightpad">
            <xsl:value-of select="$retentionRate/Period1" />%
        </td>
        <td class="Table-col Table-col-amount Table-col-rightpad">
            <xsl:value-of select="$retentionRate/Period2" />%
        </td>
        <td class="Table-col Table-col-amount Table-col-rightpad">
            <xsl:value-of select="$retentionRate/Period3" />%
        </td>
        <td class="Table-col Table-col-amount Table-col-rightpad">
            <xsl:value-of select="$retentionRate/Period4" />%
        </td>
    </xsl:template>

    <xsl:template name="pricingMode">
        <fieldset class="Form-fieldset Form-fieldset-morespace">
            <h2>MCPS Pricing</h2>
            <div class="Form-label-caption">MCPS Sales Pricing Mode</div>
            <div>
                <xsl:choose>
                    <xsl:when test="McpsSettings/SalesPricingMode/SalesPricingMode = 'S'">
                        Sales Document Pricing
                    </xsl:when>
                    <xsl:otherwise>
                        Published Dealer Pricing
                    </xsl:otherwise>
                </xsl:choose>
            </div>
        </fieldset>
    </xsl:template>

    <xsl:template name="exportSettings">
        <fieldset class="Form-fieldset Form-fieldset-morespace">
            <h2>MCPS Export Settings</h2>
            <div class="Form-fieldset-section">
                <div class="Form-label-caption">MCPS Export Allowance</div>
                <table id="exportAllowance">
                    <tr>
                        <td>AP1:&#160;</td>
                        <td><xsl:value-of select="McpsSettings/ExportAllowanceList/ExportAllowance/AP1" /></td>
                    </tr>
                    <tr>
                        <td>DVD1:&#160;</td>
                        <td><xsl:value-of select="McpsSettings/ExportAllowanceList/ExportAllowance/DVD1" /></td>
                    </tr>
                </table>
            </div>
            <div class="Form-fieldset-section">
                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">Now Viewing</span>
                        <div class="Form-input-wrapper">
                            <xsl:variable name="selectCountry">
                                <map>
                                    <mapEntry><name>All</name><value>ALL</value></mapEntry>
                                    <xsl:for-each select="McpsSettings/ExportUpliftCountryList/ExportUpliftCountry">
                                        <xsl:variable name="countryCode" select="." />
                                        <mapEntry>
                                            <name><xsl:value-of select="/Root/CountryList/Country[CountryCode = $countryCode]/Name" /></name>
                                            <value><xsl:value-of select="$countryCode" /></value>
                                        </mapEntry>
                                    </xsl:for-each>
                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$selectCountry"/>
                                <xsl:with-param name="id" select="'country_code'"/>
                                <xsl:with-param name="name" select="'country_code'"/>
                                <xsl:with-param name="className" select="'Dropdown-fixed Dropdown-inline'"/>
                                <xsl:with-param name="active" select="/Root/McpsSettings/CountryCode"/>
                            </xsl:call-template>
                            <xsl:call-template name="uiButton">
                                <xsl:with-param name="content" select="'Update'" />
                                <xsl:with-param name="type" select="'default'"/>
                                <xsl:with-param name="className" select="'Form-button'"/>
                                <xsl:with-param name="onClick">location.href='?c=show&amp;country_code='+document.getElementById('country_code').value</xsl:with-param>
                            </xsl:call-template>
                        </div>
                    </label>
                </div>
            </div>
            <div class="Form-fieldset-section">
                <h4>Country Pricing Table</h4>
                <xsl:if test="not(McpsSettings/ExportUpliftList/ExportUplift)">
                    <p>No rates have been entered<xsl:if test="normalize-space(Params/CountryCode)"> for the selected country</xsl:if>.</p>
                </xsl:if>
                <xsl:if test="McpsSettings/ExportUpliftList/ExportUplift">
                    <table class="Table">
                        <thead>
                            <tr class="Table-row Table-row-header">
                                <th class="Table-col">Country</th>
                                <th class="Table-col">Product</th>
                                <th class="Table-col">Rate</th>
                            </tr>
                        </thead>
                        <tbody>
                            <xsl:for-each select="McpsSettings/ExportUpliftList/ExportUplift">
                                <xsl:call-template name="exportUpliftRow" />
                            </xsl:for-each>
                        </tbody>
                    </table>
                </xsl:if>
            </div>
        </fieldset>
    </xsl:template>

    <xsl:template name="exportUpliftRow">
        <tr class="Table-row Table-row-data">
            <td class="Table-col">
                <xsl:variable name="countryCode" select="CountryCode" />
                <xsl:value-of select="/Root/CountryList/Country[CountryCode = $countryCode]/Name" />
            </td>
            <td class="Table-col">
                <xsl:variable name="productTypeID" select="ProductTypeID" />
                <xsl:choose>
                    <xsl:when test="/Root/TypeList/Type/ProductTypeID = $productTypeID">
                        <xsl:value-of select="/Root/TypeList/Type[ProductTypeID = $productTypeID]/Description" />
                    </xsl:when>
                    <xsl:otherwise>All Physical Products</xsl:otherwise>
                </xsl:choose>
            </td>
            <td class="Table-col">
                <xsl:value-of select="Rate" />%
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="submitButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Edit Settings'"/>
            <xsl:with-param name="name" select="'Edit'"/>
            <xsl:with-param name="type" select="'primary'"/>
            <xsl:with-param name="className" select="'Form-button'"/>
            <xsl:with-param name="onClick">location.href='/admin/mcps?c=edit'</xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="cancelButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Back to Admin'" />
            <xsl:with-param name="type" select="'default'"/>
            <xsl:with-param name="className" select="'Form-button'"/>
            <xsl:with-param name="onClick">location.href='/rps/display?d=config'</xsl:with-param>
        </xsl:call-template>
    </xsl:template>

</xsl:stylesheet>
