<!--                                                                  -->
<!--  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:variable name="helpLinkOptions" select="'width=800, height=500, scrollbars=yes, resizable=yes'" />

    <xsl:template name="buttons">
        <xsl:param name="type" select="''" />
        <fieldset class="Form-fieldset Form-fieldset-buttons">
            <xsl:attribute name="class">
                <xsl:text>Form-fieldset Form-fieldset-buttons</xsl:text>
                <xsl:if test="$type != ''">
                    <xsl:text> Form-fieldset-buttons-</xsl:text>
                    <xsl:value-of select="$type" />
                </xsl:if>
            </xsl:attribute>
            <div class="Form-fieldset-buttons-wrapper">
                <xsl:variable name="accessLevel" select="/Root/User/AccessLevel" />
                <xsl:if test="Area = 'artist_contract' and Cmd = 'edit' and not(Params/copy) and Params/ArtistContractID and contains('|1|3|4|8|', concat('|', $accessLevel, '|'))">
                    <xsl:call-template name="deleteButton">
                        <xsl:with-param name="className" select="'Form-button-left'" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:if test="Area = 'product' and Cmd = 'edit' and Params/ProductID and /Root/Access/rps/product/delete = 1">
                    <xsl:call-template name="deleteButton">
                        <xsl:with-param name="className" select="'Form-button-left'" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:if test="Area = 'catalog' and Cmd = 'edit' and Params/AlbumID and contains('|1|3|4|8|12|', concat('|', $accessLevel, '|'))">
                    <xsl:call-template name="deleteButton">
                        <xsl:with-param name="className" select="'Form-button-left'" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:if test="Area = 'publisher' and Cmd = 'edit' and Params/PublisherID and /Root/Access/rps/publisher/delete = 1">
                    <xsl:call-template name="deleteButton">
                        <xsl:with-param name="className" select="'Form-button-left'" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:if test="Area = 'ca_publisher' and Cmd = 'edit' and Params/PublisherID and /Root/Access/rps/ca_publisher/delete = 1">
                    <xsl:call-template name="deleteButton">
                        <xsl:with-param name="className" select="'Form-button-left'" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:if test="Area = 'artist_payee' and Cmd = 'edit' and Params/ArtistPayeeID and /Root/Access/rps/artist_payee/delete = 1">
                    <xsl:call-template name="deleteButton">
                        <xsl:with-param name="className" select="'Form-button-left'" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:call-template name="cancelButton">
                    <xsl:with-param name="className" select="'Form-button'" />
                </xsl:call-template>
                <xsl:call-template name="submitButton">
                    <xsl:with-param name="className" select="'Form-button'" />
                </xsl:call-template>
            </div>
        </fieldset>
    </xsl:template>

    <xsl:template name="buttonsWithoutBox">
        <table class="buttons">
            <tr>
                <td class="defaultButton"><xsl:call-template name="submitButton" /></td>
                <td><xsl:call-template name="cancelButton" /></td>
            </tr>
        </table>
    </xsl:template>

    <xsl:variable name="dateFormat" select="translate(/Root/Client/Locale/DateTimeFormat/DateFormat, 'MD', 'md')" />

    <xsl:variable name="calendarDateFormat">%<xsl:value-of select="substring($dateFormat, 1, 2)" />%<xsl:value-of select="substring($dateFormat, 3, 2)" />%<xsl:value-of select="substring($dateFormat, 5, 1)" /></xsl:variable>

    <xsl:template name="calendar">
        <xsl:param name="fieldID" />
        <xsl:param name="buttonID" />
        <script type="text/javascript">
            Calendar.setup({
                inputField: "<xsl:value-of select="$fieldID" />",     // id of the input field
                ifFormat: "<xsl:value-of select="$calendarDateFormat" />",     // format of the input field (even if hidden, this format will be honored)
                daFormat: "<xsl:value-of select="$calendarDateFormat" />",// format of the displayed date
                button: "<xsl:value-of select="$buttonID" />",  // trigger button (well, IMG in our case)
                align: "Tl", // alignment (defaults to "Bl")
                singleClick: true
            });
        </script>
    </xsl:template>

    <xsl:template name="labelContractRow">
        <xsl:variable name="labelNames">
            <xsl:for-each select="TermList/Term">
                <xsl:value-of select="LabelName" /><xsl:if test="position() != last()">, </xsl:if>
            </xsl:for-each>
        </xsl:variable>

        <tr class="Table-row Table-row-data">
            <td class="Table-col ContractMain-col-title"><a href="label_contract?LabelContractID={LabelContractID}&amp;c=show"><xsl:value-of select="Title" /></a></td>

            <xsl:if test="$area = 'contract'">
                <td class="Table-col ContractMain-col-type">Label</td>
            </xsl:if>

            <td class="Table-col ContractMain-col-artist-label">
                <xsl:choose>
                    <xsl:when test="substring($labelNames,31,1)">
                        <abbr>
                            <xsl:attribute name="title">
                                <xsl:for-each select="TermList/Term">
                                    <xsl:value-of select="LabelName" />
                                    <xsl:if test="position() != last()">, </xsl:if>
                                    <xsl:if test="(position() mod 2) = 0">&lt;br&gt;</xsl:if>
                                </xsl:for-each>
                            </xsl:attribute>
                            <xsl:value-of select="substring($labelNames,1,30)" />...
                        </abbr>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$labelNames" />
                    </xsl:otherwise>
                </xsl:choose>

            </td>
            <td class="Table-col ContractMain-col-id"><xsl:value-of select="ClientContractID" /></td>
            <xsl:variable name="payorID" select="PayorID" />
            <td class="Table-col ContractMain-col-payor"><xsl:value-of select="/Root/PayorList/Payor[PayorID = $payorID]/Name" /></td>
            <td class="Table-col ContractMain-col-payee"><xsl:value-of select="LabelPayeeName" /></td>
            <xsl:if test="/Root/Access/rps/label_contract/edit = 1">
                <td class="Table-col Table-col-icon ContractMain-col-edit">
                    <xsl:call-template name="uiEditTrigger">
                        <xsl:with-param name="url">
                            <xsl:text>label_contract?c=edit&amp;LabelContractID=</xsl:text>
                            <xsl:value-of select="LabelContractID" />
                        </xsl:with-param>
                    </xsl:call-template>
                </td>
            </xsl:if>
        </tr>
    </xsl:template>

    <xsl:template name="artistContractRow">
        <tr class="Table-row Table-row-data">
            <td class="Table-col ContractMain-col-title"><a href="artist_contract?ArtistContractID={ArtistContractID}&amp;c=show"><xsl:value-of select="Title" /></a></td>

            <xsl:if test="$area = 'contract'">
                <td class="Table-col ContractMain-col-type">Artist/Producer</td>
            </xsl:if>

            <td class="Table-col ContractMain-col-artist-label">
                <xsl:value-of select="ArtistDescription" />
            </td>
            <td class="Table-col ContractMain-col-id"><xsl:value-of select="ClientContractID" /></td>
            <xsl:variable name="payorID" select="PayorID" />
            <td class="Table-col ContractMain-col-payor"><xsl:value-of select="/Root/PayorList/Payor[PayorID = $payorID]/Name" /></td>
            <td class="Table-col ContractMain-col-payee"><xsl:value-of select="ArtistPayee/Name" /></td>
            <xsl:if test="/Root/Access/rps/artist_contract/edit = 1">
                <td class="Table-col Table-col-icon ContractMain-col-edit">
                    <xsl:call-template name="uiEditTrigger">
                        <xsl:with-param name="url">
                            <xsl:text>artist_contract?c=edit&amp;ArtistContractID=</xsl:text>
                            <xsl:value-of select="ArtistContractID" />
                        </xsl:with-param>
                    </xsl:call-template>
                </td>
            </xsl:if>
        </tr>
    </xsl:template>


    <xsl:template name="liquidationSchedule">
        <xsl:param name="lockedRecord" />
        <xsl:param name="liquidationID" />
        <xsl:param name="liquidationList" />
        <xsl:param name="liquidationPrefix" />
        <div class="Form-group-horizontal">
            <xsl:call-template name="liquidationScheduleInput">
                <xsl:with-param name="liquidationList" select="$liquidationList" />
                <xsl:with-param name="liquidationID" select="$liquidationID" />
                <xsl:with-param name="liquidationPrefix" select="$liquidationPrefix" />
                <xsl:with-param name="lockedRecord" select="$lockedRecord" />
                <xsl:with-param name="lsCount">0</xsl:with-param>
                <xsl:with-param name="lsStop">7</xsl:with-param>
            </xsl:call-template>
        </div>
    </xsl:template>


    <xsl:template name="liquidationScheduleInput">
        <xsl:param name="liquidationList" />
        <xsl:param name="liquidationID" />
        <xsl:param name="liquidationPrefix" />
        <xsl:param name="lockedRecord" />
        <xsl:param name="lsCount" />
        <xsl:param name="lsStop" />

        <div class="Form-item">
            <label class="Form-label">
                <span class="Form-label-caption"><xsl:value-of select="$lsCount + 1" /></span>
                <div class="Form-input-wrapper">
                    <input type="hidden" name="{$liquidationPrefix}{$lsCount}_ID" value="{$liquidationID}" />
                    <input type="hidden" name="{$liquidationPrefix}{$lsCount}_Period" id="{$liquidationPrefix}{$lsCount}_Period" value="{$lsCount + 1}" />
                    <input type="text" maxlength="{$liquidationList[@i = $lsCount]/Percent/@maxLength}" name="{$liquidationPrefix}{$lsCount}_Percent" id="{$liquidationPrefix}{$lsCount}_Percent" value="{$liquidationList[@i = $lsCount]/Percent}" class="Form-input Input Form-short-number-field">
                        <xsl:if test="$lockedRecord = 1">
                            <xsl:attribute name="disabled">disabled</xsl:attribute>
                        </xsl:if>
                    </input>
                </div>
            </label>
        </div>

        <xsl:if test="$lsCount != $lsStop">
            <xsl:call-template name="liquidationScheduleInput">
                <xsl:with-param name="lockedRecord" select="$lockedRecord" />
                <xsl:with-param name="liquidationList" select="$liquidationList" />
                <xsl:with-param name="liquidationID" select="$liquidationID" />
                <xsl:with-param name="liquidationPrefix" select="$liquidationPrefix" />
                <xsl:with-param name="lsCount" select="$lsCount + 1" />
                <xsl:with-param name="lsStop" select="$lsStop" />
            </xsl:call-template>
        </xsl:if>
    </xsl:template>


    <xsl:template name="contractView">
        <fieldset id="contractView" class="Form-fieldset">
            <div class="ControlsHeader">
                <h3 class="ControlsHeader-text">Contract</h3>
                <xsl:if test="$area = 'contract' and $cmd = 'show'">
                    <xsl:call-template name="uiButton">
                        <xsl:with-param name="id" select="'submitButton'" />
                        <xsl:with-param name="content" select="'Edit Contract'" />
                        <xsl:with-param name="url">
                            <xsl:text>artist_contract?ContractID=</xsl:text>
                            <xsl:value-of select="Form/ArtistContract/ArtistContractID" />
                            <xsl:text>&amp;c=edit</xsl:text>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:if>
            </div>
            <table class="Table Table-with-highlight">
                <thead>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col">Contract Title</th>
                        <th class="Table-col">Artist</th>
                        <th class="Table-col">Contract ID</th>
                        <th class="Table-col">Payor</th>
                        <th class="Table-col">Payee</th>
                        <th class="Table-col">Date Issued</th>
                        <th class="Table-col">Term Start</th>
                        <th class="Table-col">Term End</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="Table-row Table-row-data row1">
                        <td class="Table-col rowLeft"><xsl:value-of select="Form/ArtistContract/Title" /></td>
                        <td class="Table-col"><xsl:value-of select="Form/ArtistContract/ArtistDescription" /></td>
                        <td class="Table-col"><xsl:value-of select="Form/ArtistContract/ClientContractID" /></td>
                        <td class="Table-col">
                            <xsl:choose>
                                <xsl:when test="$cmd = 'edit'">
                                    <xsl:value-of select="Form/PayorList/Payor[PayorID = /Root/Form/ArtistContract/PayorID]/Name" />
                                </xsl:when>
                                <xsl:otherwise>
                                    <a href="/rps/payor?PayorID={Form/ArtistContract/PayorID}&amp;c=show"><xsl:value-of select="Form/PayorList/Payor[PayorID = /Root/Form/ArtistContract/PayorID]/Name" /></a>
                                </xsl:otherwise>
                            </xsl:choose>
                        </td>
                        <td class="Table-col">
                            <xsl:choose>
                                <xsl:when test="$cmd = 'edit'">
                                    <xsl:value-of select="Form/ArtistContract/ArtistPayee/Name" />
                                </xsl:when>
                                <xsl:otherwise>
                                    <a href="/rps/artist_payee?ArtistPayeeID={Form/ArtistContract/ArtistPayeeID}&amp;c=show"><xsl:value-of select="Form/ArtistContract/ArtistPayee/Name" /></a>
                                </xsl:otherwise>
                            </xsl:choose>
                        </td>
                        <td class="Table-col"><xsl:value-of select="Form/ArtistContract/IssueDate" /></td>
                        <td class="Table-col"><xsl:value-of select="Form/ArtistContract/TermStart" /></td>
                        <td class="Table-col"><xsl:value-of select="Form/ArtistContract/TermEnd" /></td>
                    </tr>
                </tbody>
            </table>
            <xsl:if test="normalize-space(Form/ArtistContract/Comments)">
                <div class="Table-annotation"><strong>Comments: </strong><xsl:value-of select="Form/ArtistContract/Comments" /></div>
            </xsl:if>
        </fieldset>
    </xsl:template>


    <xsl:template name="ccompView">
        <xsl:param name="ccomp" />

        <fieldset class="Form-fieldset">
            <div>
                <xsl:attribute name="class">
                    <xsl:text>ControlsHeader</xsl:text>
                    <xsl:if test="not(normalize-space($ccomp/ControlledCompositionID))">
                        <xsl:text> ControlsHeader-separated</xsl:text>
                    </xsl:if>
                </xsl:attribute>
                <h3 class="ControlsHeader-text">Controlled Composition Clause</h3>
                <xsl:if test="$area = 'artist_contract'">
                    <xsl:choose>
                        <xsl:when test="normalize-space($ccomp/ControlledCompositionID)">
                            <xsl:call-template name="uiButton">
                                <xsl:with-param name="content" select="'Edit Clause'" />
                                <xsl:with-param name="url">
                                    <xsl:text>ccomp?CCompID=</xsl:text>
                                    <xsl:value-of select="$ccomp/ControlledCompositionID" />
                                    <xsl:text>&amp;c=edit</xsl:text>
                                </xsl:with-param>
                                <xsl:with-param name="disabled">
                                    <xsl:if test="$lockedRecord = 1">
                                        <xsl:text>true</xsl:text>
                                    </xsl:if>
                                </xsl:with-param>
                            </xsl:call-template>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:call-template name="uiButton">
                                <xsl:with-param name="content" select="'Add Clause'" />
                                <xsl:with-param name="url">
                                    <xsl:text>ccomp?ArtistContractID=</xsl:text>
                                    <xsl:value-of select="Form/ArtistContract/ArtistContractID" />
                                    <xsl:text>&amp;c=edit</xsl:text>
                                </xsl:with-param>
                                <xsl:with-param name="disabled">
                                    <xsl:if test="$lockedRecord = 1">
                                        <xsl:text>true</xsl:text>
                                    </xsl:if>
                                </xsl:with-param>
                            </xsl:call-template>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:if>
            </div>
            <xsl:if test="normalize-space($ccomp/ControlledCompositionID)">
                <table class="Table Table-with-highlight">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col">Track Cap</th>
                            <th class="Table-col">Rate Type</th>
                            <th class="Table-col">Rate %</th>
                            <xsl:if test="$ccomp/RateType != '3'">
                                <th class="Table-col">Rate Basis</th>
                            </xsl:if>
                            <xsl:if test="$ccomp/RateType = '3'">
                                <th class="Table-col">Penny Rate</th>
                            </xsl:if>
                            <xsl:if test="$area = 'catalog'">
                                <th class="Table-col">Term Start</th>
                                <th class="Table-col">Term End</th>
                                <th class="Table-col">Album Pool</th>
                            </xsl:if>
                            <th class="Table-col">Lock Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="Table-row Table-row-data">
                            <td class="Table-col"><xsl:value-of select="$ccomp/TrackCap" /></td>
                            <td class="Table-col">
                                <xsl:call-template name="rateType">
                                    <xsl:with-param name="rateTypeID" select="$ccomp/RateType" />
                                </xsl:call-template>
                            </td>
                            <td class="Table-col">
                                <xsl:value-of select="$ccomp/RatePercentage" />%
                            </td>
                            <xsl:if test="$ccomp/RateType != '3'">
                                <td class="Table-col">
                                    <xsl:call-template name="rateBasis">
                                        <xsl:with-param name="rateBasisID" select="$ccomp/RateBasis" />
                                    </xsl:call-template>
                                </td>
                            </xsl:if>
                            <xsl:if test="$ccomp/RateType = '3'">
                                <td class="Table-col"><xsl:value-of select="$ccomp/PennyRate" /></td>
                            </xsl:if>
                            <xsl:if test="$area = 'catalog'">
                                <td class="Table-col">
                                    <xsl:value-of select="Form/Album/Contract/TermStart" />
                                </td>
                                <td class="Table-col">
                                    <xsl:value-of select="Form/Album/Contract/TermEnd" />
                                </td>
                                <td class="Table-col">
                                    <xsl:value-of select="Form/Album/AlbumPool" />
                                </td>
                            </xsl:if>
                            <td class="Table-col"><xsl:value-of select="$ccomp/LockDate" /></td>
                        </tr>
                    </tbody>
                </table>
            </xsl:if>
        </fieldset>

        <xsl:if test="normalize-space($ccomp/ControlledCompositionID)">
            <fieldset class="Form-fieldset">
                <xsl:call-template name="liquidationScheduleView">
                    <xsl:with-param name="liquidationSchedule" select="$ccomp/ReserveLiquidationList/ReserveLiquidation" />
                    <xsl:with-param name="reserveRate" select="$ccomp/ReservePercentage" />
                </xsl:call-template>
            </fieldset>
        </xsl:if>
    </xsl:template>


    <xsl:template name="liquidationScheduleView">
        <xsl:param name="noHeader" />
        <xsl:param name="reserveRate" />
        <xsl:param name="liquidationSchedule" />

        <xsl:variable name="scheduleTest">
            <xsl:for-each select="$liquidationSchedule">
                <xsl:if test="normalize-space(Percent)"><xsl:value-of select="Percent" /></xsl:if>
            </xsl:for-each>
        </xsl:variable>

        <xsl:choose>
            <xsl:when test="normalize-space($scheduleTest)">
                <xsl:if test="$noHeader != 1">
                    <div class="ControlsHeader">
                        <h3 class="ControlsHeader-text">Liquidation Schedule:</h3>
                        <xsl:if test="normalize-space($reserveRate)">
                            <div class="Reserve-rate">
                                <h3 class="Reserve-rate-title">Reserve:</h3>
                                &#160;
                                <span class="Reserve-rate-value"><xsl:value-of select="$reserveRate" />%</span>
                            </div>
                        </xsl:if>
                    </div>
                </xsl:if>
                <table class="Table Table-with-highlight">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <xsl:for-each select="$liquidationSchedule">
                                <th class="Table-col"><xsl:value-of select="@i + 1" /></th>
                            </xsl:for-each>
                        </tr>
                    </thead>
                    <tbody>
                        <tr class="Table-row Table-row-data">
                            <xsl:for-each select="$liquidationSchedule">
                                <td class="Table-col"><xsl:value-of select="Percent" /><xsl:if test="Percent &gt; 0">%</xsl:if></td>
                            </xsl:for-each>
                        </tr>
                    </tbody>
                </table>
            </xsl:when>
            <xsl:when test="$noHeader = 1">Not entered</xsl:when>
            <xsl:otherwise>
                <span class="liquidationHeader">
                    <h3>Liquidation Schedule</h3>
                    <section class="Table-empty-results">
                        <p>Not entered</p>
                    </section>
                </span>
                <xsl:if test="$area = 'contract' and $cmd = 'show' and normalize-space($reserveRate)">
                    <div class="Reserve-rate">
                        <h3 class="Reserve-rate-title">Reserve:</h3>
                        &#160;
                        <span class="Reserve-rate-value"><xsl:value-of select="$reserveRate" />%</span>
                    </div>
                </xsl:if>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <xsl:template name="albumView">
        <section class="PageShow-section" id="albumView">
            <h2>Album</h2>
            <table class="Table">
                <thead>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col">Title</th>
                        <th class="Table-col">Catalog #</th>
                        <th class="Table-col">Artist</th>
                        <xsl:if test="Form/LabelList/Label">
                            <th class="Table-col">Label</th>
                        </xsl:if>
                        <th class="Table-col">Status</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col"><xsl:value-of select="Form/Album/Title" /><xsl:if test="normalize-space(Form/Album/TitleVersion)">&#160;(<xsl:value-of select="Form/Album/TitleVersion" />)</xsl:if></td>
                        <td class="Table-col"><xsl:value-of select="Form/Album/CatalogNumber" /></td>
                        <td class="Table-col"><xsl:value-of select="Form/Album/ArtistName" /></td>
                        <xsl:if test="Form/LabelList/Label">
                            <td class="Table-col">
                                <xsl:variable name="albumLabelID"><xsl:value-of select="Form/Album/LabelID" /></xsl:variable>
                                <xsl:value-of select="/Root/Form/LabelList/Label[LabelID = $albumLabelID]/LabelName" />
                            </td>
                        </xsl:if>
                        <td class="Table-col">
                            <xsl:call-template name="albumStatus">
                                <xsl:with-param name="status" select="Form/Album/Status" />
                            </xsl:call-template>
                        </td>
                    </tr>
                </tbody>
            </table>
        </section>
    </xsl:template>

    <xsl:template name="trackView">
        <xsl:param name="track" />
        <xsl:param name="albumTitle" />
        <section class="PageShow-section">
            <h2>Track</h2>
            <table class="Table">
                <thead>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col">Track Title</th>
                        <th class="Table-col">Album Title</th>
                        <th class="Table-col">Artist</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col"><xsl:value-of select="$track/Title" /></td>
                        <td class="Table-col"><xsl:value-of select="$albumTitle" /></td>
                        <td class="Table-col"><xsl:value-of select="$track/ArtistName" /></td>
                    </tr>
                </tbody>
            </table>
        </section>
    </xsl:template>

    <xsl:template name="publisherView">
        <xsl:param name="publisher" />
        <section class="PageShow-section">
            <h2>Publisher</h2>
            <table class="Table">
                <thead>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col">Name</th>
                        <th class="Table-col">Type</th>
                        <th class="Table-col">Admin</th>
                        <th class="Table-col">Agent</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col"><xsl:value-of select="$publisher/PublisherName" /><xsl:if test="$publisher/IsAgency != 0"> [Agent]</xsl:if></td>
                        <td class="Table-col">
                            <xsl:choose>
                                <xsl:when test="$publisher/IsAgency = 1">Agency</xsl:when>
                                <xsl:when test="$publisher/IsAdmin = 1">Administrator</xsl:when>
                                <xsl:otherwise>Standard</xsl:otherwise>
                            </xsl:choose>
                        </td>
                        <td class="Table-col"><xsl:value-of select="$publisher/AdminName" /></td>
                        <td class="Table-col"><xsl:value-of select="$publisher/AgentName" /></td>
                    </tr>
                </tbody>
            </table>
        </section>
    </xsl:template>


    <xsl:template name="payeeView">
        <xsl:param name="payee" />
        <section class="PageShow-section">
            <h2>Payee</h2>
            <table class="Table">
                <thead>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col">Name</th>
                        <th class="Table-col">Client Account #</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="Table-row Table-row-data">
                        <td class="Table-col"><xsl:value-of select="$payee/Name" /></td>
                        <td class="Table-col"><xsl:value-of select="$payee/ClientAccountID" /></td>
                    </tr>
                </tbody>
            </table>
        </section>
    </xsl:template>


    <xsl:template name="licenseView">
        <xsl:param name="license" />
        <xsl:param name="crossed" select="'0'" />
        <xsl:param name="track" />
        <xsl:param name="licenseTitle" select="'License'" />
        <section class="PageShow-section LicenseView-common-table">
            <h2><xsl:value-of select="$licenseTitle" /></h2>
            <table class="Table">
                <thead>
                    <tr class="Table-row Table-row-header">
                        <th class="Table-col">Track</th>
                        <th class="Table-col">Track Name</th>
                        <th class="Table-col">Product</th>
                        <th class="Table-col">Region</th>
                        <th class="Table-col">Share</th>
                        <th class="Table-col">Publisher</th>
                        <th class="Table-col">Admin</th>
                        <th class="Table-col">Agent</th>
                        <th class="Table-col">Status</th>
                    </tr>
                </thead>
                <tbody>
                    <xsl:choose>
                        <xsl:when test="$crossed = 0">
                            <xsl:for-each select="$license">
                                <xsl:call-template name="licenseViewRow">
                                    <xsl:with-param name="track" select="$track" />
                                </xsl:call-template>
                            </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:for-each select="$license/TrackLicense">
                                <xsl:call-template name="licenseViewRow">
                                    <xsl:with-param name="track" select="$track" />
                                </xsl:call-template>
                            </xsl:for-each>
                        </xsl:otherwise>
                    </xsl:choose>
                </tbody>
            </table>
        </section>
    </xsl:template>


    <xsl:template name="licenseViewRow">
        <xsl:param name="track" />
        <tr class="Table-row Table-row-data">
            <td class="Table-col">
                <xsl:if test="$track/TrackOrder &lt; 10">0</xsl:if><xsl:value-of select="$track/TrackOrder" />
            </td>
            <td class="Table-col"><xsl:value-of select="$track/Title" /></td>
            <td class="Table-col">
                <xsl:call-template name="productTypeName">
                    <xsl:with-param name="productTypeID" select="ProductTypeID" />
                    <xsl:with-param name="typeList" select="/Root/Form/TypeList" />
                </xsl:call-template>
            </td>
            <td class="Table-col">
                <xsl:if test="normalize-space(RegionID) and RegionID != 0">
                    <xsl:variable name="regionID" select="RegionID" />
                    <xsl:value-of select="/Root/Form/RegionList/Region[RegionID = $regionID]/Name" />
                </xsl:if>
            </td>
            <td class="Table-col"><xsl:value-of select="Share" />%</td>
            <td class="Table-col">
                <xsl:choose>
                    <xsl:when test="Type = 4">Public Domain</xsl:when>
                    <xsl:otherwise><xsl:value-of select="Publisher/PublisherName" /></xsl:otherwise>
                </xsl:choose>
            </td>
            <td class="Table-col">
                <xsl:if test="Type != 4"><xsl:value-of select="Publisher/AdminName" /></xsl:if>
            </td>
            <td class="Table-col">
                <xsl:if test="Type != 4"><xsl:value-of select="Publisher/AgentName" /></xsl:if>
            </td>
            <td class="Table-col">
                <xsl:if test="Inactive = 1">Inactive</xsl:if>
                <xsl:if test="Inactive = 0">Active</xsl:if>
            </td>
        </tr>
    </xsl:template>


    <xsl:template name="contractList">
        <xsl:param name="ccompTest" />
        <xsl:param name="contracts" />
        <xsl:param name="type" />
        <section class="PageShow-section" id="contractViewTable">
            <h2>Contracts</h2>
            <table class="Table">
                <xsl:if test="$contracts">
                    <thead>
                        <tr class="Table-row Table-row-header">
                            <th class="Table-col">Contract Title</th>
                            <th class="Table-col">Artist</th>
                            <th class="Table-col">Contract ID</th>
                            <xsl:if test="$type != 'Payee'">
                                <th class="Table-col">Payee</th>
                            </xsl:if>
                            <th class="Table-col">Issue Date</th>
                            <xsl:if test="$type = 'Album'">
                                <th class="Table-col">Controlled Composition</th>
                            </xsl:if>
                            <xsl:if test="$type = 'Album' or $type = 'Track'">
                                <th class="Table-col Table-col-icon">Remove</th>
                            </xsl:if>
                        </tr>
                    </thead>
                </xsl:if>
                <tbody>
                    <xsl:if test="$contracts">
                        <xsl:for-each select="$contracts">
                            <xsl:call-template name="contractListRow">
                                <xsl:with-param name="type" select="$type" />
                                <xsl:with-param name="ccompTest" select="$ccompTest" />
                            </xsl:call-template>
                        </xsl:for-each>
                    </xsl:if>
                    <xsl:if test="$type = 'Album' or $type = 'Track'">
                        <tr class="Table-row Table-row-data">
                            <td colspan="9" class="Table-col">
                                <xsl:variable name="attachID">Form/<xsl:value-of select="$type" />/<xsl:value-of select="$type" />ID</xsl:variable>
                                <input type="button" id="addContractButton" value="Attach Contract" class="bottomButton" onClick="displayInline('artist_contract?c=search&amp;{$type}ID={dyn:evaluate($attachID)}&amp;_inline=1')" />
                            </td>
                        </tr>
                    </xsl:if>
                </tbody>
            </table>
        </section>
    </xsl:template>


    <xsl:template name="contractListRow">

        <xsl:param name="type" />

        <xsl:variable name="contractIDname">../<xsl:value-of select="$type" />ContractID</xsl:variable>
        <xsl:variable name="contractArea">
            <xsl:if test="$type = 'Album'">catalog</xsl:if>
            <xsl:if test="$type = 'Track'">track</xsl:if>
        </xsl:variable>

        <tr class="Table-row Table-row-data">
            <td class="Table-col">
                <a href="artist_contract?ArtistContractID={ArtistContractID}&amp;c=show">
                    <xsl:value-of select="Title" />
                </a>
            </td>
            <td class="Table-col"><xsl:value-of select="ArtistDescription" /></td>
            <td class="Table-col"><xsl:value-of select="ClientContractID" /></td>
            <xsl:if test="$type != 'Payee'">
                <td class="Table-col"><xsl:value-of select="ArtistPayee/Name" /></td>
            </xsl:if>
            <td class="Table-col"><xsl:value-of select="IssueDate" /></td>
            <xsl:if test="$type = 'Album'">
                <td class="Table-col">
                    <xsl:choose>
                        <xsl:when test="../IsControlledComp = 1">
                            <a href="{$contractArea}?c=attach&amp;{$type}ContractID={dyn:evaluate($contractIDname)}&amp;Form_{$type}Contract_IsControlledComp=0">Stop Using</a>
                        </xsl:when>
                        <xsl:when test="HasCComp = 0">N/A</xsl:when>
                        <xsl:when test="$ccompTest = ''">
                            <a href="{$contractArea}?c=attach&amp;{$type}ContractID={dyn:evaluate($contractIDname)}&amp;Form_{$type}Contract_IsControlledComp=1">Use</a>
                        </xsl:when>
                    </xsl:choose>
                </td>
            </xsl:if>
            <xsl:if test="$type = 'Album' or $type = 'Track'">
                <td class="Table-col Table-col-icon">
                    <a href="javascript:confirmRemoveContract('{$contractArea}',{dyn:evaluate($contractIDname)})" title="Remove Contract" class="js-tooltip">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'remove'" />
                            <xsl:with-param name="role" select="'action'" />
                        </xsl:call-template>
                    </a>
                </td>
            </xsl:if>
        </tr>
    </xsl:template>



    <!-- Escape URIs -->


    <!-- According to the RFC, non-ascii chars will be utf-8 encoded and escaped
    with %s by the xslt-engine when in a 'uri' attribute or by the browser
    if the xlst-engine doesn't. This is ok, but not enough since we still
    won't have working RFC822 (email) Froms! since they need =s.
    However, as there is nothing I can do about this, I will just hope for
    the best if an xslt engine doesn't have uri-escape. -->
    <xsl:variable name="ascii-charset"> !&quot;#$%&amp;&apos;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~&#127;</xsl:variable>
    <xsl:variable name="uri-ok">-_.!~*&apos;()0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz</xsl:variable>
    <xsl:variable name="hex">0123456789ABCDEFabcdef</xsl:variable>

    <xsl:template name="do-escape-uri">
        <xsl:param name="str"/>
        <xsl:param name="allow-utf8"/>

        <xsl:if test="$str">
            <xsl:variable name="first-char" select="substring($str,1,1)"/>
            <xsl:choose>
                <xsl:when test="$first-char = '%' and string-length($str) &gt;= 3 and contains($hex, substring($str,2,1)) and contains($hex, substring($str,3,1))">
                    <!-- The percent char is ok IF it followed by a valid hex pair -->
                    <xsl:value-of select="$first-char"/>
                </xsl:when>
                <xsl:when test="contains($uri-ok, $first-char)">
                    <!-- This char is ok inside urls -->
                    <xsl:value-of select="$first-char"/>
                </xsl:when>
                <xsl:when test="not(contains($ascii-charset, $first-char))">
                    <!-- Non-ascii output raw based on utf8 allowed or not -->
                    <xsl:choose>
                        <xsl:when test="$allow-utf8">
                            <xsl:value-of select="$first-char"/>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:text>%3F</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:when>
                <xsl:otherwise>
                    <!-- URL escape this char -->
                    <xsl:variable name="ascii-value" select="string-length(substring-before($ascii-charset,$first-char)) + 32"/>
                    <xsl:text>%</xsl:text>
                    <xsl:value-of select="substring($hex,floor($ascii-value div 16) + 1,1)"/>
                    <xsl:value-of select="substring($hex,$ascii-value mod 16 + 1,1)"/>
                </xsl:otherwise>
            </xsl:choose>

            <xsl:call-template name="do-escape-uri">
                <xsl:with-param name="str" select="substring($str,2)"/>
                <xsl:with-param name="allow-utf8" select="$allow-utf8"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

    <xsl:template name="my-escape-uri">
        <xsl:param name="str"/>
        <xsl:param name="allow-utf8"/>

        <xsl:choose>
            <xsl:when test="0">
                <!--<xsl:value-of select="escape-uri($str, true())"/>-->
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="do-escape-uri">
                    <xsl:with-param name="str" select="$str"/>
                    <xsl:with-param name="allow-utf8" select="$allow-utf8"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

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

            </xsl:attribute>
            <label class="Form-label">
                <span class="Form-label-caption">
                    Ending Sales Date
                    <xsl:call-template name="helpIcon">
                        <xsl:with-param name="tip">
                            All closed sales up to and including the ending sales date are eligible for royalty payment.&lt;br&gt;
                            Leave blank to pay royalties on all closed sales.
                        </xsl:with-param>
                    </xsl:call-template>
                </span>
                <div class="Form-input-wrapper">
                    <xsl:call-template name="uiDatepicker">
                        <xsl:with-param name="id" select="'Form_EndingSaleDate'" />
                        <xsl:with-param name="name" select="'Form_EndingSaleDate'" />
                        <xsl:with-param name="value" select="Form/EndingSaleDate" />
                        <xsl:with-param name="format" select="'MM/DD/YYYY'" />
                    </xsl:call-template>

                    <xsl:if test="Form/EndDate/@required = 1">
                        <script type="text/javascript">
                            requireField('Form_EndDate','End Date cannot be blank.<br />');
                        </script>
                    </xsl:if>
                </div>
            </label>
            <xsl:call-template name="inlineError">
                <xsl:with-param name="path">Form/EndingSaleDate</xsl:with-param>
                <xsl:with-param name="displayName">Ending Sales Date</xsl:with-param>
            </xsl:call-template>
        </div>
    </xsl:template>

    <xsl:template name="checkForNewSales">
        <script type="text/javascript">
            addNewSalesCheck();

            var periodCloseDate = <xsl:value-of select="Form/PeriodCloseDate/@raw" /><xsl:value-of select="translate(substring(Form/PeriodCloseDate/@day, 4),':','')" />;
            var payorCommitDate = new Object();
            <xsl:for-each select="Form/PayorList/Payor">
                <xsl:if test="normalize-space(CommitDate)">
                    payorCommitDate[<xsl:value-of select="PayorID" />] = <xsl:value-of select="CommitDate/@raw" /><xsl:value-of select="translate(substring(CommitDate/@day, 4),':','')" />;
                </xsl:if>
            </xsl:for-each>
        </script>
    </xsl:template>

</xsl:stylesheet>
