<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">


    <xsl:template name="editLicenseIncome">
        <script src="/production/javascript/validate/licenseIncomeFile.js?t={$now}" type="text/javascript"></script>

        <form action="/app/tracker" name="licenseIncomeEntry" id="licenseIncomeEntry" method="post" class="Form">
            <input type="hidden" name="c" value="license_income" />
            <input type="hidden" name="formSubmit" value="1" />
            <input type="hidden" name="period" value="0" />
            <input type="hidden" name="file" value="{LicenseIncomeFile/FileID}" />
            <input type="hidden" name="currencySymbol" id="currencySymbol" value="{Client/Locale/CurrencyFormat/Symbol}" />
            <input type="hidden" name="showDelete" id="showDelete" value="{count(LicenseIncomeFile/LicenseIncomeList/LicenseIncome)}" />
            <div class="LicenseIncome">
                <xsl:call-template name="errorMessageGeneral">
                    <xsl:with-param name="className" select="'LicenseIncome-general-errors'" />
                </xsl:call-template>
                <div class="LicenseIncome-header">
                    <div class="LicenseIncome-intro-wrapper">
                        <p class="LicenseIncome-intro-text">Enter license income information here.</p>
                    </div>
                    <div class="LicenseIncome-required-wrapper">
                        <span class="LicenseIncome-required-note">
                            * Required field
                        </span>
                    </div>
                </div>
                <fieldset class="Form-fieldset">
                    <div>
                        <xsl:attribute name="class">Form-item Form-item-required<xsl:if test="Form-error[@e]"><xsl:text> Form-item-error</xsl:text></xsl:if></xsl:attribute>
                        <label class="Form-label">
                            <span class="Form-label-caption">File Name</span>
                            <div class="Form-input-wrapper">
                                <input placeholder="Enter File Name" type="text" name="LicenseIncomeFile_OrigFileName" id="LicenseIncomeFile_OrigFileName" value="{LicenseIncomeFile/OrigFileName}" class="Input Form-input LicenseIncome-name-input"/>
                            </div>
                        </label>
                        <div class="Form-error-text-wrapper">
                            <xsl:call-template name="inlineError">
                                <xsl:with-param name="path">LicenseIncomeFile/OrigFileName</xsl:with-param>
                                <xsl:with-param name="displayName">File Name</xsl:with-param>
                            </xsl:call-template>
                        </div>
                    </div>
                </fieldset>
                <fieldset class="Form-fieldset">
                    <xsl:call-template name="licenseIncomeTable" />
                </fieldset>

                <xsl:call-template name="uiButton">
                    <xsl:with-param name="type" select="'text-inline'" />
                    <xsl:with-param name="content" select="'Add New Line'" />
                    <xsl:with-param name="iconLeftType" select="'add'" />
                    <xsl:with-param name="id" select="'addTextLink'" />
                    <xsl:with-param name="className" select="'LicenseIncome-add-button'" />
                </xsl:call-template>

                <fieldset class="Form-fieldset Form-fieldset-buttons">
                    <xsl:call-template name="licenseIncomeButtons" />
                </fieldset>
            </div>

        </form>
    </xsl:template>


    <xsl:template name="licenseIncomeTable">
        <table class="Table LicenseIncome-table" id="licenseIncomeFileTable">
            <thead>
                <tr class="Table-row Table-row-header">
                    <th class="Table-col" id="numberColumn">#</th>
                    <th class="Table-col Table-col-header " id="dateColumn">Date&#160;*</th>
                    <th class="Table-col" id="unitColumn">Units</th>
                    <th class="Table-col" id="amountColumn">Amount&#160;*</th>
                    <th class="Table-col Table-col-header Table-col-nowrap" id="albumColumn">
                        <span class="Table-col-wrapper">Album</span>
                        <xsl:call-template name="helpIcon">
                            <xsl:with-param name="tip">Either an album or contract must be associated with a transaction line.<xsl:value-of select="$tipBreak" />If a contract is associated, only that contract will get paid out.<xsl:value-of select="$tipBreak" />If no contract is associated, all contracts with that album/track will get paid out.</xsl:with-param>
                        </xsl:call-template>
                    </th>
                    <th class="Table-col" id="trackColumn">Track</th>
                    <th class="Table-col Table-col-header Table-col-nowrap" id="contractColumn">
                        <span class="Table-col-wrapper">Contract&#160;*</span>
                        <xsl:call-template name="helpIcon">
                            <xsl:with-param name="tip">Either an album or contract must be associated with a transaction line.<xsl:value-of select="$tipBreak" />If a contract is associated, only that contract will get paid out.<xsl:value-of select="$tipBreak" />If no contract is associated, all contracts with that album/track will get paid out.</xsl:with-param>
                        </xsl:call-template>
                    </th>
                    <th class="Table-col" id="incomeTypeColumn">Income&#160;Type&#160;*</th>
                    <th class="Table-col Table-col-header Table-col-nowrap" id="memoColumn">
                        <span class="Table-col-wrapper">Memo</span>
                        <xsl:call-template name="helpIcon">
                            <xsl:with-param name="tip">Memos greater than 40 characters in length may be truncated<xsl:value-of select="$tipBreak" />for display in the PDF versions of Artist Royalty Statements.
                            </xsl:with-param>
                        </xsl:call-template>
                    </th>

                    <th class="Table-col Table-col-icon" id="deleteColumn">Delete</th>
                </tr>
            </thead>
            <tbody>
                <xsl:choose>
                    <xsl:when test="LicenseIncomeFile/LicenseIncomeList/LicenseIncome">
                        <xsl:for-each select="LicenseIncomeFile/LicenseIncomeList/LicenseIncome">
                            <xsl:call-template name="licenseIncomeRow" />
                        </xsl:for-each>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:call-template name="licenseIncomeRow" />
                    </xsl:otherwise>
                </xsl:choose>
            </tbody>
        </table>
    </xsl:template>


    <xsl:template name="licenseIncomeRow">

        <xsl:variable name="licensePosition">
            <xsl:choose>
                <xsl:when test="@k"><xsl:value-of select="@k" /></xsl:when>
                <xsl:otherwise>NEW0</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        <xsl:variable name="fieldPrefix">LicenseIncomeFile_LicenseIncomeList_LicenseIncome_<xsl:value-of select="$licensePosition" />_</xsl:variable>

        <tr class="Table-row Table-row-data Table-row-inputs">
            <td class="Table-col">
                <xsl:value-of select="position()" />
            </td>

            <xsl:call-template name="dateField">
                <xsl:with-param name="fieldPrefix" select="$fieldPrefix" />
            </xsl:call-template>

            <xsl:call-template name="unitsField">
                <xsl:with-param name="fieldPrefix" select="$fieldPrefix" />
            </xsl:call-template>

            <xsl:call-template name="amountField">
                <xsl:with-param name="fieldPrefix" select="$fieldPrefix" />
            </xsl:call-template>

            <xsl:call-template name="albumField">
                <xsl:with-param name="fieldPrefix" select="$fieldPrefix" />
                <xsl:with-param name="yuiAttentionIcon" select="$yuiAttentionIcon" />
            </xsl:call-template>

            <xsl:call-template name="trackField">
                <xsl:with-param name="fieldPrefix" select="$fieldPrefix" />
                <xsl:with-param name="yuiAttentionIcon" select="$yuiAttentionIcon" />
            </xsl:call-template>

            <xsl:call-template name="contractField">
                <xsl:with-param name="fieldPrefix" select="$fieldPrefix" />
                <xsl:with-param name="yuiAttentionIcon" select="$yuiAttentionIcon" />
            </xsl:call-template>

            <xsl:call-template name="incomeTypeField">
                <xsl:with-param name="fieldPrefix" select="$fieldPrefix" />
                <xsl:with-param name="yuiAttentionIcon" select="$yuiAttentionIcon" />
            </xsl:call-template>

            <xsl:call-template name="memoField">
                <xsl:with-param name="fieldPrefix" select="$fieldPrefix" />
            </xsl:call-template>

            <xsl:call-template name="deleteField">
                <xsl:with-param name="fieldPrefix" select="$fieldPrefix" />
            </xsl:call-template>
        </tr>
    </xsl:template>


    <xsl:template name="dateField">
        <xsl:param name="fieldPrefix" />
        <td class="Table-col">

            <div>
                <xsl:attribute name="class">Form-item LicenseIncome-data<xsl:if test="Date[@e] or @e = 'date is invalid'"><xsl:text> Form-item-error</xsl:text></xsl:if></xsl:attribute>
                <div class="Form-input-wrapper">

                    <xsl:call-template name="uiDatepicker">
                        <xsl:with-param name="id">
                            <xsl:value-of select="$fieldPrefix" />
                            <xsl:text>Date</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="name">
                            <xsl:value-of select="$fieldPrefix" />
                            <xsl:text>Date</xsl:text>
                        </xsl:with-param>
                        <xsl:with-param name="value" select="Date" />
                        <xsl:with-param name="className" select="'LicenseIncome-table-input'" />
                    </xsl:call-template>
                </div>
                <div class="Form-error-text-wrapper">
                    <xsl:if test="@e = 'date is invalid'">
                        <span class="Form-error">Date is not valid.</span>
                    </xsl:if>

                    <xsl:if test="Date[@e = 'field_blank']">
                        <span class="Form-error">Date cannot be blank.</span>
                    </xsl:if>
                </div>
            </div>
        </td>
    </xsl:template>


    <xsl:template name="unitsField">
        <xsl:param name="fieldPrefix" />
        <td class="Table-col">
            <div class="Form-item">
                <xsl:attribute name="class">Form-item LicenseIncome-units<xsl:if test="Units[@e]"><xsl:text> Form-item-error</xsl:text></xsl:if></xsl:attribute>
                <div class="Form-input-wrapper">
                    <input type="text" name="{$fieldPrefix}Units" id="{$fieldPrefix}Units" value="{Units}" class="Input Form-input LicenseIncome-table-input"/>
                </div>
            </div>
        </td>
    </xsl:template>


    <xsl:template name="amountField">
        <xsl:param name="fieldPrefix" />
        <td class="Table-col">
            <div>
                <xsl:attribute name="class">Form-item LicenseIncome-revenue<xsl:if test="Revenue[@e]"><xsl:text> Form-item-error</xsl:text></xsl:if></xsl:attribute>
                <div class="Form-input-wrapper">
                    <input type="text" name="{$fieldPrefix}Revenue" id="{$fieldPrefix}Revenue" value="{Revenue}" class="Input Form-input LicenseIncome-table-input"/>
                    <span class="Input-currency">
                        <xsl:value-of select="/Root/Client/Locale/CurrencyFormat/Symbol" />
                    </span>
                </div>
                <div class="Form-error-text-wrapper">
                    <xsl:if test="Revenue[@e = 'field_blank']">
                        <span class="Form-error">Amount cannot be blank.</span>
                    </xsl:if>
                    <xsl:if test="Revenue[@e = 'field_invalid']">
                        <span class="Form-error">Amount is not valid.</span>
                    </xsl:if>
                </div>
            </div>
        </td>
    </xsl:template>


    <xsl:template name="albumField">
        <xsl:param name="fieldPrefix" />
        <xsl:param name="yuiAttentionIcon" />
        <td class="Table-col">
            <div id="AC_{$fieldPrefix}Album">
                <xsl:attribute name="class">Form-item LicenseIncome-album<xsl:if test="AlbumID[@e] or @e='album or contract are required'"><xsl:text> Form-item-error</xsl:text></xsl:if></xsl:attribute>
                <div class="Form-input-wrapper">
                    <xsl:variable name="albumValue">
                        <xsl:choose>
                            <xsl:when test="/Root/Params/formSubmit"><xsl:value-of select="AlbumTitle" /></xsl:when>
                            <xsl:when test="normalize-space(AlbumID)">(<xsl:value-of select="CatalogNumber" />) <xsl:value-of select="AlbumTitle" /></xsl:when>
                        </xsl:choose>
                    </xsl:variable>

                    <input type="text" name="{$fieldPrefix}AlbumTitle" id="{$fieldPrefix}AlbumTitle" value="{$albumValue}" title="{$albumValue}" onFocus="updateAlbumSearch('{$fieldPrefix}');" class="Input Form-input LicenseIncome-table-input js-tooltip" />

                    <span id="noMatch_{$fieldPrefix}AlbumTitle" class="yui-ac-warning"></span>
                    <input type="hidden" name="{$fieldPrefix}AlbumID" id="{$fieldPrefix}AlbumID" value="{AlbumID}" />
                    <div id="albumContainer_{$fieldPrefix}"></div>
                </div>

                <div class="Form-error-text-wrapper">
                    <xsl:if test="AlbumID[@e = 'invalid album id']">
                        <span class="Form-error">Album is not valid.</span>
                    </xsl:if>
                    <xsl:if test="@e='album or contract are required'">
                        <span class="Form-error">Album is required.</span>
                    </xsl:if>
                </div>
            </div>

            <script type="text/javascript">
                window['<xsl:value-of select="$fieldPrefix" />AlbumObj'] = new rsAutoCompleteNew({
                    url: "/rps/catalog?c=search_album&amp;limit=10",
                    targetInputName: "<xsl:value-of select="$fieldPrefix" />AlbumTitle",
                    targetInputID: "<xsl:value-of select="$fieldPrefix" />AlbumID",
                    noMatchItem: "noMatch_<xsl:value-of select="$fieldPrefix" />AlbumTitle",
                    noMatchText: "<xsl:value-of select="$yuiAttentionIcon" />",
                    blockName: "Album",
                    itemName: "TitleAndCatalogNumber",
                    itemID: "AlbumID",
                    dependencies: {
                        "dependentField": "<xsl:value-of select="$fieldPrefix" />TrackTitle",
                        "dependentHiddenField": "<xsl:value-of select="$fieldPrefix" />TrackID",
                        "unlockField": "<xsl:value-of select="$fieldPrefix" />LicenseIncomeType",
                    },
                });
                window['<xsl:value-of select="$fieldPrefix" />AlbumObj'].init();
            </script>

        </td>

    </xsl:template>


    <xsl:template name="trackField">
        <xsl:param name="fieldPrefix" />
        <xsl:param name="yuiAttentionIcon" />
        <td class="Table-col">

            <div id="AC_{$fieldPrefix}Track">
                <xsl:attribute name="class">Form-item LicenseIncome-track<xsl:if test="TrackID[@e]"><xsl:text> Form-item-error</xsl:text></xsl:if></xsl:attribute>
                <div class="Form-input-wrapper">

                    <input type="text" name="{$fieldPrefix}TrackTitle" id="{$fieldPrefix}TrackTitle" class="js-tooltip Input Form-input LicenseIncome-table-input" onFocus="updateTrackSearch('{$fieldPrefix}')">
                        <xsl:if test="normalize-space(AlbumID)">
                            <xsl:attribute name="value"><xsl:value-of select="TrackTitle" /></xsl:attribute>
                            <xsl:attribute name="title"><xsl:value-of select="TrackTitle" /></xsl:attribute>
                        </xsl:if>
                        <xsl:if test="not(normalize-space(AlbumID))">
                            <xsl:attribute name="disabled">true</xsl:attribute>
                        </xsl:if>
                    </input>

                    <span id="noMatch_{$fieldPrefix}TrackTitle" class="yui-ac-warning"></span>
                    <input type="hidden" name="{$fieldPrefix}TrackID" id="{$fieldPrefix}TrackID">
                        <xsl:if test="normalize-space(AlbumID)">
                            <xsl:attribute name="value"><xsl:value-of select="TrackID" /></xsl:attribute>
                        </xsl:if>
                    </input>
                    <div id="trackContainer_{$fieldPrefix}"></div>

                    <script type="text/javascript">
                        window['<xsl:value-of select="$fieldPrefix" />TrackObj'] = new rsAutoCompleteNew({
                            url: "/rps/catalog?c=search_track_ajax&amp;limit=10",
                            targetInputName: "<xsl:value-of select="$fieldPrefix" />TrackTitle",
                            targetInputID: "<xsl:value-of select="$fieldPrefix" />TrackID",
                            noMatchItem: "noMatch_<xsl:value-of select="$fieldPrefix" />TrackTitle",
                            noMatchText: "<xsl:value-of select="$yuiAttentionIcon" />",
                            blockName: "Track",
                            itemName: "Title",
                            itemID: "TrackID",
                        });
                        window['<xsl:value-of select="$fieldPrefix" />TrackObj'].init();
                    </script>

                </div>
                <div class="Form-error-text-wrapper">
                    <span class="Form-error">Track is not valid.</span>
                </div>
            </div>
        </td>
    </xsl:template>

    <xsl:template name="contractField">
        <xsl:param name="fieldPrefix" />
        <xsl:param name="yuiAttentionIcon" />
        <td class="Table-col">
            <xsl:variable name="contractValue">
                <xsl:choose>
                    <xsl:when test="/Root/Params/formSubmit"><xsl:value-of select="ContractTitle" /></xsl:when>
                    <xsl:when test="normalize-space(ContractID)">(<xsl:value-of select="ClientContractID" />) <xsl:value-of select="ContractTitle" /></xsl:when>
                </xsl:choose>
            </xsl:variable>

            <div id="AC_{$fieldPrefix}Contract">
                <xsl:attribute name="class">Form-item LicenseIncome-contract<xsl:if test="ContractID[@e] or @e='album or contract are required'"><xsl:text> Form-item-error</xsl:text></xsl:if></xsl:attribute>


                <div class="Form-input-wrapper">

                    <input type="text" name="{$fieldPrefix}ContractTitle" id="{$fieldPrefix}ContractTitle" value="{$contractValue}" title="{$contractValue}" class="Input Form-input LicenseIncome-table-input" onFocus="updateContractSearch('{$fieldPrefix}')"/>

                    <span id="noMatch_{$fieldPrefix}ContractTitle" class="yui-ac-warning"></span>
                    <input type="hidden" name="{$fieldPrefix}ContractID" id="{$fieldPrefix}ContractID" value="{ContractID}" />
                    <div id="contractContainer_{$fieldPrefix}"></div>

                </div>
                <div class="Form-error-text-wrapper">
                    <xsl:if test="@e = 'album or contract are required'">
                        <span class="Form-error">Contract is required</span>
                    </xsl:if>
                    <xsl:if test="ContractID[@e = 'invalid contract id']">
                        <span class="Form-error">Contract is not valid.</span>
                    </xsl:if>
                </div>
            </div>

            <script type="text/javascript">
                window['<xsl:value-of select="$fieldPrefix" />ContractObj'] = new rsAutoCompleteNew({
                    url: "/rps/artist_contract?c=search_artist_contract&amp;limit=10",
                    targetInputName: "<xsl:value-of select="$fieldPrefix" />ContractTitle",
                    targetInputID: "<xsl:value-of select="$fieldPrefix" />ContractID",
                    noMatchItem: "noMatch_<xsl:value-of select="$fieldPrefix" />ContractTitle",
                    noMatchText: "<xsl:value-of select="$yuiAttentionIcon" />",
                    dependencies: {
                        unlockField: "<xsl:value-of select="$fieldPrefix" />LicenseIncomeType",
                    },
                    blockName: "ArtistContract",
                    itemName: "TitleAndClientContractID",
                    itemID: "ArtistContractID",
                });
                window['<xsl:value-of select="$fieldPrefix" />ContractObj'].init();
            </script>

        </td>
    </xsl:template>


    <xsl:template name="incomeTypeField">
        <xsl:param name="fieldPrefix" />
        <xsl:param name="yuiAttentionIcon" />
        <td class="Table-col">

            <div id="AC_{$fieldPrefix}LicenseIncomeSource">
                <xsl:attribute name="class">Form-item LicenseIncome-licenseincomesource<xsl:if test="LicenseIncomeTypeID[@e] or @e='invalid license income type id'"><xsl:text> Form-item-error</xsl:text></xsl:if></xsl:attribute>
                <div class="Form-input-wrapper">

                    <input type="text" name="{$fieldPrefix}LicenseIncomeType" id="{$fieldPrefix}LicenseIncomeType" class="js-tooltip Input Form-input LicenseIncome-table-input" onFocus="updateIncomeTypeSearch('{$fieldPrefix}')">
                        <xsl:if test="not(normalize-space(AlbumID)) and not(normalize-space(ContractID))">
                            <xsl:attribute name="disabled">true</xsl:attribute>
                        </xsl:if>
                        <xsl:if test="(normalize-space(AlbumID)) or (normalize-space(ContractID))">
                            <xsl:attribute name="value"><xsl:value-of select="LicenseIncomeType" /></xsl:attribute>
                            <xsl:attribute name="title"><xsl:value-of select="LicenseIncomeType" /></xsl:attribute>
                        </xsl:if>
                    </input>

                    <span id="noMatch_{$fieldPrefix}LicenseIncomeType" class="yui-ac-warning"></span>
                    <input type="hidden" name="{$fieldPrefix}LicenseIncomeTypeID" id="{$fieldPrefix}LicenseIncomeTypeID">
                        <xsl:if test="(normalize-space(AlbumID)) or (normalize-space(ContractID))">
                            <xsl:attribute name="value"><xsl:value-of select="LicenseIncomeTypeID" /></xsl:attribute>
                        </xsl:if>
                    </input>
                    <div id="licenseIncomeTypeContainer_{$fieldPrefix}"></div>

                </div>
                <div class="Form-error-text-wrapper">
                    <xsl:if test="LicenseIncome[@e='invalid license income type id']">
                        <span class="Form-error">Income Type is not valid.</span>
                    </xsl:if>
                    <xsl:if test="LicenseIncomeTypeID[@e = 'field_blank'] and LicenseIncomeType = ''">
                        <span class="Form-error">Income Type cannot be blank.</span>
                    </xsl:if>
                    <xsl:if test="LicenseIncomeTypeID[@e = 'invalid license income type id']">
                        <span class="Form-error">Income Type is not valid.</span>
                    </xsl:if>
                </div>
            </div>

            <script type="text/javascript">
                window['<xsl:value-of select="$fieldPrefix" />LicenseObj'] = new rsAutoCompleteNew({
                    url: "/rps/artist_contract?c=search_license_income&amp;limit=10",
                    targetInputName: "<xsl:value-of select="$fieldPrefix" />LicenseIncomeType",
                    targetInputID: "<xsl:value-of select="$fieldPrefix" />LicenseIncomeTypeID",
                    noMatchItem: "noMatch_<xsl:value-of select="$fieldPrefix" />LicenseIncomeType",
                    noMatchText: "<xsl:value-of select="$yuiAttentionIcon" />",
                    blockName: "LicenseIncomeType",
                    itemName: "Name",
                    itemID: "LicenseIncomeTypeID",
                });
                window['<xsl:value-of select="$fieldPrefix" />LicenseObj'].init();
            </script>

        </td>
    </xsl:template>

    <xsl:template name="memoField">
        <xsl:param name="fieldPrefix" />

        <td class="Table-col">
            <div class="Form-item">
                <xsl:attribute name="class">Form-item LicenseIncome-memo</xsl:attribute>
                <div class="Form-input-wrapper">
                    <input type="text" name="{$fieldPrefix}Memo" id="{$fieldPrefix}Memo" value="{Memo}" class="Input Form-input LicenseIncome-table-input"/>
                </div>
            </div>
        </td>

    </xsl:template>

    <xsl:template name="deleteField">
        <xsl:param name="fieldPrefix" />

        <xsl:variable name="deleteFieldId">
            <xsl:value-of select="$fieldPrefix" />
            <xsl:text>Delete</xsl:text>
        </xsl:variable>

        <td class="Table-col Table-col-icon">
            <xsl:call-template name="uiDeleteRowTrigger">
                <xsl:with-param name="id" select="$deleteFieldId" />
                <xsl:with-param name="name" select="$deleteFieldId" />
            </xsl:call-template>
        </td>
    </xsl:template>

    <xsl:template name="licenseIncomeButtons">
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" select="'Cancel'"/>
            <xsl:with-param name="url" select="'/app/tracker'" />
            <xsl:with-param name="className" select="'Form-button'"/>
        </xsl:call-template>
        <xsl:call-template name="uiButton">
            <xsl:with-param name="content" 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:call-template>
    </xsl:template>

</xsl:stylesheet>
