<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="html" indent="no" doctype-system="" encoding="utf-8" />

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

    <xsl:template name="pickLayout">
        <div class="MainBaseSection">
            <form action="/rps/service" name="serviceEdit" id="serviceEdit" method="post" onSubmit="modifyField('submitButton','disable')">
                <xsl:call-template name="helpLink" />
                <xsl:call-template name="successMessageGeneral">
                    <xsl:with-param name="successMessage">Services successfully updated!</xsl:with-param>
                </xsl:call-template>
                <xsl:call-template name="openRunStatusMessage" />
                <xsl:call-template name="serviceEdit" />
                <xsl:call-template name="buttons" />
            </form>
            <script src="/production/javascript/rps/service.js?v=1" type="text/javascript"></script>
        </div>
    </xsl:template>

    <xsl:template name="serviceEdit">
        <input type="hidden" name="formSubmit" value="1" />
        <input type="hidden" name="c" value="edit" />
        <xsl:call-template name="errorMessageGeneral" />
        <div class="Admin-services-tablewrapper">
            <xsl:if test="/Root/ClientTypes/ClientType[ClientTypeID = 5]/IsClientTypeFlag = 1 or /Root/ClientTypes/ClientType[ClientTypeID = 7]/IsClientTypeFlag = 1">
                <div class="Admin-services-tablecontainer">
                    <h3>Modify Mechanical Royalty Exclusions by Service</h3>
                    <xsl:call-template name="serviceEditTable" />
                </div>
            </xsl:if>
            <xsl:if test="/Root/ClientTypes/ClientType[ClientTypeID = 2]/IsClientTypeFlag = 1">
                <div class="Admin-services-tablecontainer">
                    <xsl:choose>
                        <xsl:when test="count(/Root/Form/ServiceCategoryList/*) &gt; 0">
                            <h3>Modify SoundExchange Category of Sale Artist Royalty Exclusions</h3>
                            <xsl:call-template name="serviceCategoryEditTable" />
                        </xsl:when>
                        <xsl:when test="/Root/ClientTypes/ClientType[ClientTypeID = 5]/IsClientTypeFlag = 0 and /Root/ClientTypes/ClientType[ClientTypeID = 7]/IsClientTypeFlag = 0">
                            <p>Options for managing artist royalty payouts by Category of Sale will appear here once you upload a SoundExchange sales file.</p>
                        </xsl:when>
                    </xsl:choose>
                </div>
            </xsl:if>
        </div>
    </xsl:template>

    <xsl:template name="serviceCategoryEditTable">
        <table class="Table Table-with-highlight">
            <thead>
                <tr class="Table-row Table-row-header">
                    <th class="Table-col Table-col-servicename">Category of Sale</th>
                    <th class="Table-col">Exclude&#160;from Artist&#160;Royalties?</th>
                    <th class="Table-col Table-col-filler"></th>
                </tr>
            </thead>
            <tbody>
                <xsl:for-each select="Form/ServiceCategoryList/ServiceCategory">
                    <xsl:call-template name="serviceCategoryRow" />
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>

    <xsl:template name="serviceCategoryRow">
        <tr class="Table-row Table-row-data">
            <td class="Table-col Table-col-servicename">
                <xsl:value-of select="Desc" />
            </td>
                <td class="Table-col">
                    <xsl:if test="/Root/Access/rps/artist_contract/edit">
                        <input type="hidden" name="Form_ServiceCategoryList_ServiceCategory_{@i}_ExcludeArtist" id="Form_ServiceCategoryList_ServiceCategory_{@i}_ExcludeArtist" value="{ExcludeArtist}" />
                        <xsl:call-template name="uiCheckbox">
                            <xsl:with-param name="disabled">
                                <xsl:if test="$openArtistRuns &gt; 0">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="checked">
                                <xsl:if test="ExcludeArtist = 1">
                                    <xsl:text>true</xsl:text>
                                </xsl:if>
                            </xsl:with-param>
                            <xsl:with-param name="name">Trigger_Form_ServiceCategoryList_ServiceCategory_<xsl:value-of select="@i" />_ExcludeArtist</xsl:with-param>
                            <xsl:with-param name="id">Trigger_Form_ServiceCategoryList_ServiceCategory_<xsl:value-of select="@i" />_ExcludeArtist</xsl:with-param>
                            <xsl:with-param name="onClick">checkCheckBox(this,'Form_ServiceCategoryList_ServiceCategory_<xsl:value-of select="@i" />_ExcludeArtist')</xsl:with-param>
                        </xsl:call-template>
                    </xsl:if>
                </td>
            <td class="Table-col Table-col-filler"></td>
        </tr>
    </xsl:template>

    <xsl:template name="serviceEditTable">
        <table class="Table Table-with-highlight">
            <thead>
                <xsl:choose>
                    <xsl:when test="Access/rps/ca_license/edit and Access/rps/license/edit">
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col"></th>
                            <th class="Table-col" colspan="2">Exclude&#160;Mechanicals?</th>
                            <th class="Table-col"></th>
                        </tr>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col Table-col-servicename">Service</th>
                            <th class="Table-col">Canadian</th>
                            <th class="Table-col">United&#160;States</th>
                            <th class="Table-col Table-col-filler"></th>
                        </tr>
                    </xsl:when>
                    <xsl:otherwise>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col">Service</th>
                            <th class="Table-col">Exclude&#160;Mechanicals?</th>
                            <th class="Table-col Table-col-filler"></th>
                        </tr>
                    </xsl:otherwise>
                </xsl:choose>
            </thead>
            <tbody>
                <xsl:for-each select="Form/ServiceList/Service">
                    <xsl:call-template name="serviceRow" />
                </xsl:for-each>
            </tbody>
        </table>
    </xsl:template>

    <xsl:template name="serviceRow">
        <tr class="Table-row Table-row-data">
            <td class="Table-col Table-col-servicename">
                <xsl:value-of select="ServiceName" />
            </td>
            <xsl:if test="/Root/Access/rps/ca_license/edit">
                <td class="Table-col">
                    <input type="hidden" name="Form_ServiceList_Service_{@i}_ExcludeCAMechanicals" id="Form_ServiceList_Service_{@i}_ExcludeCAMechanicals" value="{ExcludeCAMechanicals}" />
                    <xsl:call-template name="uiCheckbox">
                        <xsl:with-param name="disabled">
                            <xsl:if test="$openCARuns &gt; 0">
                                <xsl:text>true</xsl:text>
                            </xsl:if>
                        </xsl:with-param>
                        <xsl:with-param name="checked">
                            <xsl:if test="ExcludeCAMechanicals = 1">
                                <xsl:text>true</xsl:text>
                            </xsl:if>
                        </xsl:with-param>
                        <xsl:with-param name="name">Trigger_Form_ServiceList_Service_<xsl:value-of select="@i" />_ExcludeCAMechanicals</xsl:with-param>
                        <xsl:with-param name="id">Trigger_Form_ServiceList_Service_<xsl:value-of select="@i" />_ExcludeCAMechanicals</xsl:with-param>
                        <xsl:with-param name="onClick">checkCheckBox(this,'Form_ServiceList_Service_<xsl:value-of select="@i" />_ExcludeCAMechanicals')</xsl:with-param>
                    </xsl:call-template>
                </td>
            </xsl:if>
            <xsl:if test="/Root/Access/rps/license/edit">
                <td class="Table-col">
                    <input type="hidden" name="Form_ServiceList_Service_{@i}_ExcludeMechanicals" id="Form_ServiceList_Service_{@i}_ExcludeMechanicals" value="{ExcludeMechanicals}" />
                    <xsl:call-template name="uiCheckbox">
                        <xsl:with-param name="disabled">
                            <xsl:if test="$openUSRuns &gt; 0">
                                <xsl:text>true</xsl:text>
                            </xsl:if>
                        </xsl:with-param>
                        <xsl:with-param name="checked">
                            <xsl:if test="ExcludeMechanicals = 1">
                                <xsl:text>true</xsl:text>
                            </xsl:if>
                        </xsl:with-param>
                        <xsl:with-param name="name">Trigger_Form_ServiceList_Service_<xsl:value-of select="@i" />_ExcludeMechanicals</xsl:with-param>
                        <xsl:with-param name="id">Trigger_Form_ServiceList_Service_<xsl:value-of select="@i" />_ExcludeMechanicals</xsl:with-param>
                        <xsl:with-param name="onClick">checkCheckBox(this,'Form_ServiceList_Service_<xsl:value-of select="@i" />_ExcludeMechanicals')</xsl:with-param>
                    </xsl:call-template>
                </td>
            </xsl:if>
            <td class="Table-col Table-col-filler"></td>
        </tr>
    </xsl:template>

    <xsl:template name="submitButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="className" select="'Form-button'"/>
            <xsl:with-param name="content" select="'Update'"/>
            <xsl:with-param name="type" select="'primary'"/>
            <xsl:with-param name="name" select="'submit'"/>
            <xsl:with-param name="id" select="'submitButton'"/>
            <xsl:with-param name="elemType" select="'submit'"/>
            <xsl:with-param name="disabled">
                <xsl:if test="(not(Access/rps/ca_license/edit) and $openCARuns &gt; 0) or (not(Access/rps/license/edit) and $openUSRuns &gt; 0) or ($openUSRuns &gt; 0 and $openCARuns &gt; 0) or (/Root/ClientTypes/ClientType[ClientTypeID = 5]/IsClientTypeFlag = 0 and /Root/ClientTypes/ClientType[ClientTypeID = 7]/IsClientTypeFlag = 0 and count(/Root/Form/ServiceCategoryList/*) = 0)">
                    <xsl:text>true</xsl:text>
                </xsl:if>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="cancelButton">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="className" select="'Form-button'"/>
            <xsl:with-param name="content" select="'Back to Admin'"/>
            <xsl:with-param name="url">/rps/display?d=config</xsl:with-param>
        </xsl:call-template>
        <xsl:call-template name="uiButton">
            <xsl:with-param name="name" select="'Back'"/>
            <xsl:with-param name="className" select="'Form-button'"/>
            <xsl:with-param name="content" select="'Cancel'"/>
            <xsl:with-param name="url">/rps/service</xsl:with-param>
        </xsl:call-template>
    </xsl:template>

</xsl:stylesheet>
