<!--                                                                  -->
<!--  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"
                xmlns:set="http://exslt.org/sets" extension-element-prefixes="dyn set">

    <xsl:variable name="licenseIncomeCount" select="count(Root/Form/ArtistContractLicenseIncomeList/ArtistContractLicenseIncome)"/>

    <xsl:template name="licenseIncomeLayout">
        <form name="licenseIncomeSource" id="licenseIncomeSource" method="post" action="artist_contract">
            <xsl:call-template name="licenseIncomeEdit"/>
            <xsl:call-template name="buttons"/>
        </form>
        <div class="hidden">
            <xsl:call-template name="licenseIncomeRowTemplate"/>
        </div>
    </xsl:template>

    <xsl:template name="licenseIncomeEdit">
        <xsl:call-template name="openRunStatusMessage"/>
        <xsl:if test="Params/_inline">
            <input type="hidden" name="_inline" value="1"/>
        </xsl:if>
        <input type="hidden" name="formSubmit" value="1"/>
        <input type="hidden" name="c" value="license_income"/>
        <input type="hidden" name="ArtistContractID" value="{Params/ArtistContractID}"/>
        <input type="hidden" name="licenseIncomeCount" id="licenseIncomeCount" value="{$licenseIncomeCount}"/>
        <div class="Form-header">
            <p>Enter license income source information here.</p>
        </div>
        <xsl:if test="//*[@e]">
            <xsl:call-template name="licenseIncomeErrors"/>
        </xsl:if>
        <xsl:call-template name="licenseIncomeSection"/>
    </xsl:template>

    <xsl:template name="licenseIncomeSection">
        <table class="Table Table-with-highlight" id="licenseIncomeSourceTable">
            <thead>
                <tr class="Table-row Table-row-header">
                    <th class="Table-col">Income Type</th>
                    <th class="Table-col">Net Revenue Rate</th>
                    <xsl:if test="$licenseIncomeCount &gt; 0">
                        <th class="Table-col deleteCol">Delete</th>
                    </xsl:if>
                </tr>
            </thead>
            <tbody>
                <xsl:choose>
                    <xsl:when test="$licenseIncomeCount &gt; 0">
                        <xsl:for-each select="Form/ArtistContractLicenseIncomeList/ArtistContractLicenseIncome">
                            <xsl:call-template name="licenseIncomeRow" />
                        </xsl:for-each>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:call-template name="licenseIncomeRow"/>
                    </xsl:otherwise>
                </xsl:choose>
            </tbody>
        </table>

        <xsl:if test="$openRuns = 0">
            <xsl:call-template name="uiButton">
                <xsl:with-param name="id" select="'addTextLink'" />
                <xsl:with-param name="className" select="'Table-add-row-button'" />
                <xsl:with-param name="iconLeftType" select="'add'" />
                <xsl:with-param name="content" select="'Add Another License Income Source'" />
                <xsl:with-param name="type" select="'text-inline'" />
                <xsl:with-param name="size" select="'large'" />
                <xsl:with-param name="onClick" select="'ContractPage.addLicenseIncome();'" />
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

    <xsl:template name="licenseIncomeRow">
        <xsl:variable name="licenseIncomePosition" select="position() - 1"/>
        <xsl:variable name="fieldPrefix">Form_ArtistContractLicenseIncomeList_ArtistContractLicenseIncome_<xsl:value-of select="$licenseIncomePosition"/>_</xsl:variable>

        <tr class="Table-row Table-row-data Table-row-inputs" id="licenseIncome{$licenseIncomePosition}">
            <td class="Table-col">
				<div class="Form-group Form-group-horizontal Form-group-horizontal-up">
					<xsl:if test="/Root/Form/ArtistContractLicenseIncomeTypeList/LicenseIncomeType/LicenseIncomeTypeID">
		                <div class="Form-item Form-item-standart">

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

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

                                    <xsl:variable name="LicenseIncomeTypeOptions">
                                        <map>
                                            <mapEntry>
                                                <name>Choose...</name>
                                                <value></value>
                                            </mapEntry>
                                            <xsl:for-each select="/Root/Form/ArtistContractLicenseIncomeTypeList/LicenseIncomeType">
                                                <xsl:sort select="Name"/>
                                                <mapEntry>
                                                    <name><xsl:value-of select="Name" /></name>
                                                    <value><xsl:value-of select="LicenseIncomeTypeID" /></value>
                                                </mapEntry>
                                            </xsl:for-each>
                                        </map>
                                    </xsl:variable>

                                    <xsl:call-template name="uiDropdown">
                                        <xsl:with-param name="items" select="$LicenseIncomeTypeOptions"/>
                                        <xsl:with-param name="id">
                                            <xsl:value-of select="$fieldPrefix"/>
                                            <xsl:text>LicenseIncomeTypeID</xsl:text>
                                        </xsl:with-param>
                                        <xsl:with-param name="name">
                                            <xsl:value-of select="$fieldPrefix"/>
                                            <xsl:text>LicenseIncomeTypeID</xsl:text>
                                        </xsl:with-param>
                                        <xsl:with-param name="active" select="LicenseIncomeTypeID"/>
                                        <xsl:with-param name="disabled">
                                            <xsl:if test="$openRuns = 1 or Inactive = 1">true</xsl:if>
                                        </xsl:with-param>
                                    </xsl:call-template>

		                        </div>
		                    </label>

                            <xsl:call-template name="inlineError">
		                        <xsl:with-param name="path">LicenseIncomeTypeID</xsl:with-param>
                                <xsl:with-param name="displayName">Income Type</xsl:with-param>
                            </xsl:call-template>
		                </div>
                        <span class="Or-separator">OR</span>
					</xsl:if>

                    <div class="Form-item Form-item-standart">
                        <xsl:if test="NewLicenseIncomeType[@e]">
                            <xsl:attribute name="class">Form-item Form-item-standart Form-item-error</xsl:attribute>
                        </xsl:if>
                        <label class="Form-label">
                            <div class="Form-input-wrapper">
                                <input type="text" class="Input Form-input" name="{$fieldPrefix}NewLicenseIncomeType" id="{$fieldPrefix}NewLicenseIncomeType" value="{NewLicenseIncomeType}">
                                    <xsl:if test="$openRuns = 1 or Inactive = 1">
                                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                                    </xsl:if>
                                </input>
                            </div>
                        </label>
                        <xsl:call-template name="inlineError">
		                    <xsl:with-param name="path">NewLicenseIncomeType</xsl:with-param>
		                    <xsl:with-param name="displayName">Income Type</xsl:with-param>
		                </xsl:call-template>
                    </div>

				</div>
            </td>

            <td class="Table-col">
                <div class="Form-item Form-item-standart">
                    <xsl:if test="Percent[@e]">
                        <xsl:attribute name="class">Form-item Form-item-standart Form-item-error</xsl:attribute>
                    </xsl:if>
                    <label class="Form-label">
                        <div class="Form-input-wrapper Form-input-wrapper-compound">
                            <input type="text" class="Input Form-input" name="{$fieldPrefix}Percent" id="{$fieldPrefix}Percent" value="{Percent}">
                                <xsl:if test="$openRuns = 1 or Inactive = 1">
                                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                                </xsl:if>
                            </input>
                            <div class="Form-input-additive">%</div>
                        </div>
                    </label>
                    <xsl:call-template name="inlineError">
                        <xsl:with-param name="path">Percent</xsl:with-param>
                        <xsl:with-param name="displayName">Net Revenue Rate</xsl:with-param>
                    </xsl:call-template>
                </div>
            </td>
            <xsl:if test="$licenseIncomeCount &gt; 0">
                <td class="Table-col Table-col-icon">
                    <xsl:if test="normalize-space(ArtistContractLicenseIncomeID) and Inactive != 1">
                        <div class="Form-item Form-item-inline">
                            <label class="Form-label">
                                <div class="Form-input-wrapper">
                                    <xsl:call-template name="uiDeleteRowTrigger">
                                        <xsl:with-param name="id">
                                            <xsl:value-of select="$fieldPrefix"/>
                                            <xsl:text>Delete</xsl:text>
                                        </xsl:with-param>
                                        <xsl:with-param name="name">
                                            <xsl:value-of select="$fieldPrefix"/>
                                            <xsl:text>Delete</xsl:text>
                                        </xsl:with-param>
                                        <xsl:with-param name="disabled">
                                            <xsl:if test="$openRuns = 1 or Inactive = 1">true</xsl:if>
                                        </xsl:with-param>
                                    </xsl:call-template>
                                </div>
                            </label>
                        </div>
                    </xsl:if>
                </td>
            </xsl:if>
        </tr>
    </xsl:template>

    <xsl:template name="licenseIncomeRowTemplate">
        <xsl:variable name="fieldPrefix">Form_ArtistContractLicenseIncomeList_ArtistContractLicenseIncome_{0}_</xsl:variable>

        <table class="Table" id="licenseIncomeRowTemplate">
            <tbody>
                <tr class="Table-row Table-row-data Table-row-inputs" id="licenseIncome{0}">
                    <td class="Table-col">
                        <div class="Form-group Form-group-horizontal">
                            <xsl:if test="/Root/Form/ArtistContractLicenseIncomeTypeList/LicenseIncomeType/LicenseIncomeTypeID">
                                <div class="Form-item Form-item-standart">
                                    <label class="Form-label">
                                        <div class="Form-input-wrapper">
                                            <select id="{$fieldPrefix}LicenseIncomeTypeID" name="{$fieldPrefix}LicenseIncomeTypeID">
                                                <option value="">Choose...</option>
                                                <xsl:for-each select="/Root/Form/ArtistContractLicenseIncomeTypeList/LicenseIncomeType">
                                                    <xsl:sort select="Name"/>
                                                    <option value="{LicenseIncomeTypeID}">
                                                        <xsl:value-of select="Name" />
                                                    </option>
                                                </xsl:for-each>
                                            </select>
                                        </div>
                                    </label>
                                </div>
                                <span class="Or-separator">OR</span>
                            </xsl:if>
                            <div class="Form-item Form-item-standart">
                                <label class="Form-label">
                                    <div class="Form-input-wrapper">
                                        <input type="text" class="Input Form-input" name="{$fieldPrefix}NewLicenseIncomeType" id="{$fieldPrefix}NewLicenseIncomeType" />
                                    </div>
                                </label>
                            </div>
                        </div>
                    </td>
                    <td class="Table-col">
                        <div class="Form-item Form-item-standart">
                            <label class="Form-label">
                                <div class="Form-input-wrapper Form-input-wrapper-compound">
                                    <input type="text" class="Input Form-input" name="{$fieldPrefix}Percent" id="{$fieldPrefix}Percent" />
                                    <div class="Form-input-additive">%</div>
                                </div>
                            </label>
                        </div>
                    </td>
                    <xsl:if test="$licenseIncomeCount &gt; 0">
                        <td class="Table-col Table-col-icon" />
                    </xsl:if>
                </tr>
            </tbody>
        </table>
    </xsl:template>

    <xsl:template name="licenseIncomeErrors">
        <xsl:choose>
            <xsl:when test="//ArtistContractLicenseIncomeList[@e = 'field_duplicate']">
                <xsl:call-template name="uiWarning">
                    <xsl:with-param name="type" select="'error'" />
                    <xsl:with-param name="description">Each income type can only be used once.</xsl:with-param>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="errorMessageGeneral" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
</xsl:stylesheet>
