<!--                                                                  -->
<!--  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">
            <!--<script type="text/javascript" src="/rps/mcpsAdmin.js?v=1" />-->
            <script type="text/javascript" src="/production/javascript/validate/mcpsLicense.js?v=1" />
            <form action="mcps" method="post">
                <xsl:if test="$openRuns = 1">
                    <xsl:attribute name="onSubmit" select="'return false;'" />
                </xsl:if>
                <input type="hidden" name="c" value="edit" />
                <input type="hidden" name="formSubmit" value="1" />
                <xsl:call-template name="helpLink">
                    <xsl:with-param name="helpCommand" select="'show'" />
                </xsl:call-template>
                <xsl:call-template name="openRunStatusMessage" />
                <xsl:call-template name="errorMessageGeneral" />
                <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" />
            </form>
        </div>
    </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>
                    </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>
                    </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="4" 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="Form/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>
    </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="Form/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-fieldset-section">
                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">MCPS Sales Pricing Mode</span>
                        <div class="Form-input-wrapper">
                            <input type="hidden" name="Form_SalesPricingMode_ClientID" value="{Client/ClientID}" />
                            <xsl:variable name="salesPricingMode">
                                <map>
                                    <mapEntry><name>Published Dealer Pricing</name><value>P</value></mapEntry>
                                    <mapEntry><name>Sales Document Pricing</name><value>S</value></mapEntry>
                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$salesPricingMode"/>
                                <xsl:with-param name="id" select="'Form_SalesPricingMode_SalesPricingMode'"/>
                                <xsl:with-param name="name" select="'Form_SalesPricingMode_SalesPricingMode'"/>
                                <xsl:with-param name="active" select="Form/SalesPricingMode/SalesPricingMode"/>
                                <xsl:with-param name="className" select="'Dropdown-fixed'"/>
                                <xsl:with-param name="disabled">
                                    <xsl:if test="$openRuns = 1">true</xsl:if>
                                </xsl:with-param>
                            </xsl:call-template>
                        </div>
                    </label>
                </div>
            </div>
        </fieldset>
    </xsl:template>


    <xsl:template name="exportSettings">
        <xsl:variable name="rowCount" select="count(Form/ExportUpliftList/ExportUplift)" />
        <fieldset class="Form-fieldset Form-fieldset-morespace js-rs-html-content">
            <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:</td>
                        <td><xsl:value-of select="Form/ExportAllowanceList/ExportAllowance/AP1" /></td>
                    </tr>
                    <tr>
                        <td>DVD1:</td>
                        <td><xsl:value-of select="Form/ExportAllowanceList/ExportAllowance/DVD1" /></td>
                    </tr>
                </table>
            </div>
            <div class="Form-fieldset-section">
                <h4>Country Pricing Table</h4>
                <table class="Table" id="exportUplift">
                    <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>
                            <th class="Table-col Table-col-icon">Delete</th>
                        </tr>
                    </thead>
                    <tbody>
                        <xsl:choose>
                            <xsl:when test="$rowCount != 0">
                                <xsl:for-each select="Form/ExportUpliftList/ExportUplift">
                                    <xsl:call-template name="exportUpliftRow">
                                        <xsl:with-param name="upliftID" select="@k" />
                                    </xsl:call-template>
                                </xsl:for-each>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:call-template name="exportUpliftRow" />
                            </xsl:otherwise>
                        </xsl:choose>
                    </tbody>
                </table>
                <xsl:call-template name="addLinkRow">
                    <xsl:with-param name="rowCount" select="$rowCount + 1" />
                </xsl:call-template>
            </div>
        </fieldset>
    </xsl:template>


    <xsl:template name="exportUpliftRow">
        <xsl:param name="upliftID" select="'NEW0'" />
        <xsl:variable name="fieldPrefix">Form_ExportUpliftList_ExportUplift_<xsl:value-of select="$upliftID" />_</xsl:variable>
        <tr class="Table-row Table-row-inputs Table-row-data" data-prefix="{$fieldPrefix}" >
            <input type="hidden" name="{$fieldPrefix}McpsExportUpliftID" value="{McpsExportUpliftID}" />
            <td class="Table-col">
                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item</xsl:text>
                        <xsl:if test="CountryCode[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>
                    </xsl:attribute>
                    <div class="Form-input-wrapper">
                        <xsl:variable name="countryCode" select="CountryCode" />
                        <xsl:variable name="selectCountry">
                            <map>
                                <mapEntry><name>Choose...</name><value></value></mapEntry>
                                <xsl:for-each select="/Root/Form/CountryList/Country">
                                    <mapEntry>
                                        <name><xsl:value-of select="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"><xsl:value-of select="$fieldPrefix" />CountryCode</xsl:with-param>
                            <xsl:with-param name="disabled">
                                <xsl:if test="$openRuns = 1">true</xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="name"><xsl:value-of select="$fieldPrefix" />CountryCode</xsl:with-param>
                            <xsl:with-param name="active" select="$countryCode"/>
                            <xsl:with-param name="className" select="'Dropdown-fixed'"/>
                        </xsl:call-template>
                    </div>
                    <div class="Form-error-text-wrapper">
                        <xsl:if test="//CountryCode[@e]"><p class="Form-error">Country must be selected.</p></xsl:if>
                    </div>
                </div>
            </td>
            <td class="Table-col">

                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item</xsl:text>
                        <xsl:if test="ProductTypeID[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>
                    </xsl:attribute>

                    <div class="Form-input-wrapper">
                        <xsl:variable name="productTypeID" select="ProductTypeID" />
                        <xsl:variable name="selectProduct">
                            <map>
                                <mapEntry><name>Choose...</name><value></value></mapEntry>
                                <mapEntry><name>All Physical</name><value>255</value></mapEntry>
                                <xsl:for-each select="/Root/Form/TypeList/Type[Type = 1]">
                                    <xsl:sort select="Description" />
                                    <mapEntry>
                                        <name><xsl:value-of select="Description" /></name>
                                        <value><xsl:value-of select="ProductTypeID" /></value>
                                    </mapEntry>
                                </xsl:for-each>
                            </map>
                        </xsl:variable>
                        <xsl:call-template name="uiDropdown">
                            <xsl:with-param name="items" select="$selectProduct"/>
                            <xsl:with-param name="id"><xsl:value-of select="$fieldPrefix" />ProductTypeID</xsl:with-param>
                            <xsl:with-param name="disabled">
                                <xsl:if test="$openRuns = 1">true</xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="name"><xsl:value-of select="$fieldPrefix" />ProductTypeID</xsl:with-param>
                            <xsl:with-param name="active" select="$productTypeID"/>
                            <xsl:with-param name="className" select="'Dropdown-fixed'"/>
                        </xsl:call-template>
                    </div>

                    <div class="Form-error-text-wrapper">
                        <xsl:if test="//ProductTypeID/@e = 'field_blank'"><p class="Form-error">Products cannot be blank.</p></xsl:if>
                        <xsl:if test="//ProductTypeID/@e = 'field_invalid'"><p class="Form-error">Products cannot be duplicated for the same country.</p></xsl:if>
                    </div>
                </div>
            </td>
            <td class="Table-col Mcps-rate-input-cell">
                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item</xsl:text>
                        <xsl:if test="Rate[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>
                    </xsl:attribute>
                    <div class="Form-input-wrapper">
                        <input type="text" class="Input Form-input Mcps-rate-input" name="{$fieldPrefix}Rate" id="{$fieldPrefix}Rate" value="{Rate}">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled" select="'disabled'" />
                            </xsl:if>
                        </input>%
                    </div>
                    <div class="Form-error-text-wrapper">
                        <xsl:if test="//Rate/@e = 'field_blank'"><p class="Form-error">Rate cannot be blank.</p></xsl:if>
                        <xsl:if test="//Rate/@e = 'field_invalid'"><p class="Form-error">Rate is invalid.</p></xsl:if>
                    </div>
                </div>
            </td>
            <td class="Table-col Table-col-icon">
                <div class="Form-item">
                    <xsl:attribute name="class">
                        <xsl:text>Form-item</xsl:text>
                        <xsl:if test="Delete[@e]">
                            <xsl:text> Form-item-error</xsl:text>
                        </xsl:if>
                    </xsl:attribute>
                    <div class="Form-input-wrapper">
                        <xsl:call-template name="uiDeleteRowTrigger">
                            <xsl:with-param name="name"><xsl:value-of select="$fieldPrefix" />Delete</xsl:with-param>
                            <xsl:with-param name="id"><xsl:value-of select="$fieldPrefix" />Delete</xsl:with-param>
                            <xsl:with-param name="value" select="'1'" />
                            <xsl:with-param name="disabled"><xsl:if test="$openRuns = 1">true</xsl:if></xsl:with-param>
                            <xsl:with-param name="checked"><xsl:if test="Delete = 1">true</xsl:if></xsl:with-param>
                            <xsl:with-param name="onClick" select="''" />
                        </xsl:call-template>
                    </div>
                </div>
                <div class="Form-error-text-wrapper">
                    <xsl:if test="//Delete[@e]"><p class="Form-error">This row cannot be deleted.</p></xsl:if>
                </div>
            </td>
        </tr>
    </xsl:template>

    <xsl:template name="addLinkRow">
        <xsl:param name="rowCount" select="'1'" />
        <xsl:if test="$openRuns = 0">
            <div id="addLinkRow">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="'Add Another'" />
                    <xsl:with-param name="type" select="'text-inline'"/>
                    <xsl:with-param name="iconLeftType" select="'add'"/>

                    <xsl:with-param name="id" select="'add-mcps-country-pricing-button'"/>
                    <xsl:with-param name="className" select="'Table-add-row-button'"/>
                </xsl:call-template>
            </div>
        </xsl:if>
    </xsl:template>

	<xsl:template name="submitButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Update'"/>
            <xsl:with-param name="name" select="'Update'"/>
            <xsl:with-param name="type" select="'primary'"/>
            <xsl:with-param name="elemType" select="'submit'"/>
            <xsl:with-param name="className" select="'Form-button'"/>
            <xsl:with-param name="disabled">
                <xsl:if test="$openRuns = 1">true/</xsl:if>
            </xsl:with-param>
        </xsl:call-template>
	</xsl:template>

    <xsl:template name="cancelButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Return to Settings'" />
            <xsl:with-param name="type" select="'default'"/>
            <xsl:with-param name="className" select="'Form-button'"/>
            <xsl:with-param name="onClick">location.href='/admin/mcps?c=show'</xsl:with-param>
        </xsl:call-template>
    </xsl:template>

</xsl:stylesheet>
