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

    <xsl:variable name="termCount" select="count(/Root/Form/ArtistContract/TermList/Term)" />

    <xsl:variable name="unitBasedDisabled">
        <xsl:choose>
            <xsl:when test="not(/Root/Params/ContractID) or /Root/Form/ArtistContract/UnitBasedEnabled = 1">0</xsl:when>
            <xsl:otherwise>1</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:template name="contractEditLayout">
        <script type="text/javascript" src="/production/javascript/validateContractNew.js?t={$now}" />
        <form name="contractEdit" id="contractEdit" method="post" action="contract">
            <xsl:if test="$termCount &gt; 0">
                <input type="hidden" name="showDelete" id="showDelete" value="1" />
            </xsl:if>
            <xsl:call-template name="contractEdit" />
            <xsl:call-template name="buttons" />
        </form>
        <xsl:call-template name="termArraysAndObjects" />

    </xsl:template>

    <xsl:template name="contractEdit">
        <div class="section">
            <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="edit" />
            <xsl:if test="normalize-space(Form/ArtistContract/ArtistContractID)">
                <input type="hidden" name="ContractID" value="{Form/ArtistContract/ArtistContractID}" />
            </xsl:if>
            <xsl:if test="//*[@e]">
                <xsl:call-template name="errorMessageGeneral" />
                <xsl:call-template name="contractEditTermErrors" />
            </xsl:if>
            <xsl:call-template name="mainContractEdit" />
            <br />
            <xsl:call-template name="contractTermEdit" />
            <br />
            <xsl:call-template name="reserveEdit" />
            <br clear="both" /><br />
        </div>
    </xsl:template>

    <xsl:template name="mainContractEdit">
        <fieldset>
            <legend>Contract</legend>
            <p class="formHeader">Enter contract information here.</p>
            <hr />
            <div class="insideFieldset">
                <div class="column1">
                    <table>
                        <tr>
                            <td class="leftCol"><label for="Form_ArtistContract_Title">*Contract Title:</label></td>
                            <td>
                                <xsl:call-template name="inlineError">
                                    <xsl:with-param name="path">Form/ArtistContract/Title</xsl:with-param>
                                    <xsl:with-param name="displayName">Title</xsl:with-param>
                                </xsl:call-template>
                                <input type="text" class="contractTitleField" name="Form_ArtistContract_Title" id="Form_ArtistContract_Title" value="{Form/ArtistContract/Title}" />
                            </td>
                        </tr>
                        <tr>
                            <td class="leftCol"><label for="Form_ArtistContract_ArtistDescription">Artist:</label></td>
                            <td>
                                <xsl:call-template name="inlineError">
                                    <xsl:with-param name="path">Form/ArtistContract/ArtistDescription</xsl:with-param>
                                    <xsl:with-param name="displayName">Artist</xsl:with-param>
                                </xsl:call-template>
                                <input class="artistNameField" name="Form_ArtistContract_ArtistDescription" id="Form_ArtistContract_ArtistDescription" type="text" value="{Form/ArtistContract/ArtistDescription}" />&#160;<span id="Form_ArtistContract_ArtistDescriptionFlag"></span>
                            </td>
                        </tr>
                        <tr>
                            <td class="leftCol"><label for="Form_ArtistContract_ClientContractID">Contract ID:</label></td>
                            <td>
                                <xsl:call-template name="inlineError">
                                    <xsl:with-param name="path">Form/ArtistContract/ClientContractID</xsl:with-param>
                                    <xsl:with-param name="displayName">Contract ID</xsl:with-param>
                                </xsl:call-template>
                                <input type="text" name="Form_ArtistContract_ClientContractID" id="Form_ArtistContract_ClientContractID" value="{Form/ArtistContract/ClientContractID}" />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <br />*Required field
                            </td>
                        </tr>
                    </table>
                </div>
                <div class="column2">
                    <table>
                        <tr>
                            <td class="leftCol"><label for="Form_ArtistContract_PayorID">Payor:</label></td>
                            <td>
                                <xsl:call-template name="inlineError">
                                    <xsl:with-param name="path">Form/ArtistContract/PayorID</xsl:with-param>
                                    <xsl:with-param name="displayName">Payor</xsl:with-param>
                                </xsl:call-template>
                                <select name="Form_ArtistContract_PayorID" id="Form_ArtistContract_PayorID">
                                    <xsl:for-each select="Form/PayorList/Payor">
                                        <option value="{PayorID}">
                                            <xsl:if test="PayorID = /Root/Form/ArtistContract/PayorID">
                                                <xsl:attribute name="selected">selected</xsl:attribute>
                                            </xsl:if>
                                            <xsl:value-of select="Name" />
                                        </option>
                                    </xsl:for-each>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="leftCol"><label for="PayeeName">*Payee:</label></td>
                            <td>
                                <xsl:call-template name="inlineError">
                                    <xsl:with-param name="path">Form/ArtistContract/ArtistPayeeID</xsl:with-param>
                                    <xsl:with-param name="displayName">Payee</xsl:with-param>
                                </xsl:call-template>
                                <xsl:call-template name="payeeField" />
                            </td>
                        </tr>
                        <tr>
                            <td class="leftCol"><label for="Form_ArtistContract_IssueDate">Issue Date:</label></td>
                            <td>
                                <xsl:call-template name="inlineError">
                                    <xsl:with-param name="path">Form/ArtistContract/IssueDate</xsl:with-param>
                                    <xsl:with-param name="displayName">Issue Date</xsl:with-param>
                                </xsl:call-template>
                                <span id="Form_ArtistContract_IssueDate_TD">
                                    <input type="text" class="dateField" name="Form_ArtistContract_IssueDate" id="Form_ArtistContract_IssueDate" value="{Form/ArtistContract/IssueDate}" />
                                </span>
                                <a title="Select Issue Date">
                                    <img src="/production/images/icons/office/Calendar-(16x16).gif" class="calendarIcon" id="calendarIconIssueDate"/>
                                </a>
                                <script type="text/javascript">
                                    Calendar.setup({
                                        inputField     :    "Form_ArtistContract_IssueDate",     // id of the input field
                                        ifFormat       :    "%m/%d/%Y",     // format of the input field (even if hidden, this format will be honored)
                                        daFormat       :    "%m/%d/%Y",// format of the displayed date
                                        button         :    "calendarIconIssueDate",  // trigger button (well, IMG in our case)
                                        align          :    "Tl",           // alignment (defaults to "Bl")
                                        singleClick    :    true
                                    });
                                </script>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </fieldset>
    </xsl:template>

    <xsl:template name="contractTermEdit">
        <a name="terms" />
        <fieldset class="termEdit">
            <legend>Contract Terms</legend>
            <p class="formHeader">Configure your contract terms here.</p>
            <hr />
            <table class="textChart" id="termTable">
                <tbody>
                    <tr>
                        <th class="rowLeft priorityCol">Priority</th>
                        <th class="sourceCol">Source</th>
                        <th class="regionCol">Region</th>
                        <th class="channelCol">Channel</th>
                        <th class="priceCol">Price</th>
                        <th class="rateTypeCol">Rate Type</th>
                        <th class="rateCol">Rate</th>
                        <th class="rateRedCol">Rate
                            <xsl:call-template name="helpIcon">
                                <xsl:with-param name="tip">% of Rate Payable</xsl:with-param>
                            </xsl:call-template>
                            <br />Reduction
                        </th>
                        <th class="percentSalesCol">% of Sales</th>
                        <th class="packagingCol">Pack-<br />aging</th>
                        <th class="freeCol">Free<br />Goods</th>
                        <xsl:if test="$termCount &gt; 0">
                            <th class="deleteCol">Delete</th>
                        </xsl:if>
                    </tr>
                    <xsl:choose>
                        <xsl:when test="$termCount &gt; 0">
                            <xsl:for-each select="Form/ArtistContract/TermList/Term">
                                <xsl:call-template name="termRowEdit" />
                            </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:call-template name="termRowEdit" />
                        </xsl:otherwise>
                    </xsl:choose>
                </tbody>
            </table>

            <xsl:variable name="addLink">
                <xsl:choose>
                    <xsl:when test="$termCount = 0">javascript:addTerm(1)</xsl:when>
                    <xsl:otherwise>javascript:addTerm('<xsl:value-of select="Form/ArtistContract/TermList/Term/@k" />')</xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <div class="insideFieldset">
                <p class="addLink">
                    <a href="{$addLink}" title="Add Another Term" id="addImageLink">
                        <img src="/production/images/icons/office/Add-(16x16).gif" height="16" width="16" />
                    </a> <a href="{$addLink}" id="addTextLink">Add Another Term</a>
                </p>
            </div>

            <table class="textChart" id="defaultTermTable">
                <tbody>
                    <tr>
                        <th class="rowLeft priorityCol">Priority</th>
                        <th class="sourceCol">Source</th>
                        <th class="regionCol">Region</th>
                        <th class="channelCol">Channel</th>
                        <th class="priceCol">Price</th>
                        <th class="rateTypeCol">Rate Type</th>
                        <th class="rateCol">Rate</th>
                        <th class="rateRedCol">Rate<br />Reduction</th>
                        <th class="percentSalesCol">% of Sales</th>
                        <th class="packagingCol">Pack-<br />aging</th>
                        <th class="freeCol">Free<br />Goods</th>
                    </tr>
                    <tr class="defaultRow">
                        <td class="rowLeft">Default</td>
                        <td>All</td>
                        <td>All</td>
                        <td>All</td>
                        <td>All</td>
                        <td>
                            <select name="Form_ArtistContract_DefaultTerm_IncomeSourceID" id="Form_ArtistContract_DefaultTerm_IncomeSourceID">
                                <option value="5" selected="selected">% Net Revenue</option>
                            </select>
                        </td>
                        <td>
                            <xsl:if test="normalize-space(Form/ArtistContract/DefaultTerm/ArtistContractTermID)">
                                <input type="hidden" name="Form_ArtistContract_DefaultTerm_ArtistContractTermID" value="{Form/ArtistContract/DefaultTerm/ArtistContractTermID}" />
                            </xsl:if>
                            <input type="text" class="smallRateField" name="Form_ArtistContract_DefaultTerm_Rate" id="Form_ArtistContract_DefaultTerm_Rate" value="{Form/ArtistContract/DefaultTerm/Rate}" />
                        </td>
                        <td class="percent">
                            <xsl:variable name="rateReduction" select="Form/ArtistContract/DefaultTerm/RateReduction" />
                            <xsl:value-of select="$rateReduction" />
                            <input type="hidden" name="Form_ArtistContract_DefaultTerm_RateReduction" value="{$rateReduction}" />
                        </td>
                        <td class="percent">
                            <xsl:variable name="percentOfSales" select="Form/ArtistContract/DefaultTerm/PercentageOfSales" />
                            <xsl:value-of select="$percentOfSales" />
                            <input type="hidden" name="Form_ArtistContract_DefaultTerm_PercentageOfSales" value="{$percentOfSales}" />
                        </td>
                        <td class="percent">
                            <xsl:variable name="packaging" select="Form/ArtistContract/DefaultTerm/PackagingDeduction" />
                            <xsl:value-of select="$packaging" />
                            <input type="hidden" name="Form_ArtistContract_DefaultTerm_PackagingDeduction" value="{$packaging}" />
                        </td>
                        <td class="percent">
                            <xsl:variable name="freeGoods" select="Form/ArtistContract/DefaultTerm/FreeGoodsDeduction" />
                            <xsl:value-of select="$freeGoods" />
                            <input type="hidden" name="Form_ArtistContract_DefaultTerm_FreeGoodsDeduction" value="{$freeGoods}" />
                        </td>
                    </tr>
                </tbody>
            </table>
        </fieldset>
    </xsl:template>

    <xsl:template name="termRowEdit">
        <xsl:variable name="termPosition">
            <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="incomeSourceID" select="IncomeSourceID" />
        <xsl:variable name="termRowID">contractTerm_<xsl:value-of select="$termPosition" /></xsl:variable>
        <xsl:variable name="termPrefix">Form_ArtistContract_TermList_Term_<xsl:value-of select="$termPosition" />_</xsl:variable>
        <xsl:variable name="termFormat">
            <xsl:for-each select="/Root/Form/IncomeSourceList/IncomeSource[IncomeSourceID = $incomeSourceID]">
                <xsl:choose>
                    <xsl:when test="Format = 2 or Format = 3">digital</xsl:when>
                    <xsl:otherwise>physical</xsl:otherwise>
                </xsl:choose>
            </xsl:for-each>
        </xsl:variable>
        <tr class="row{position() mod 2}" id="{$termRowID}">
            <td class="priorityCell">
                <input type="hidden" name="{$termPrefix}Priority" id="{$termPrefix}Priority">
                    <xsl:attribute name="value">
                        <xsl:if test="Priority">
                            <xsl:value-of select="Priority"/>
                        </xsl:if>
                        <xsl:if test="not(Priority)">
                            <xsl:value-of select="position()" />
                        </xsl:if>
                    </xsl:attribute>
                </input>

                <div class="termPriority" id="{$termRowID}_PriorityDisplay">
                    <xsl:if test="Priority">
                        <xsl:value-of select="Priority" />
                    </xsl:if>
                    <xsl:if test="not(Priority)">1</xsl:if>
                </div>
                <div class="moveUp">
                    <a href="javascript:moveRowUp('{$termRowID}','termTable','{$termPrefix}Priority')" title="Move Up" id="{$termRowID}_Up">
                        <xsl:if test="position() = 1">
                            <xsl:attribute name="style">display: none</xsl:attribute>
                        </xsl:if>
                        <img src="/production/images/icons/move_up.gif" height="9" width="15" />
                    </a>
                </div>
                <div class="moveDown">
                    <a href="javascript:moveRowDown('{$termRowID}','termTable','{$termPrefix}Priority')" title="Move Down" id="{$termRowID}_Down">
                        <xsl:if test="position() = last()">
                            <xsl:attribute name="style">display: none</xsl:attribute>
                        </xsl:if>
                        <img src="/production/images/icons/move_down.gif" height="9" width="15" />
                    </a>
                </div>

            </td>
            <td>
                <xsl:if test="IncomeSourceID[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
                <select name="{$termPrefix}IncomeSourceID" id="{$termPrefix}IncomeSourceID" onChange="checkSourceFormat(this,'{$termPosition}');">
                    <option value="">Choose...</option>
                    <xsl:for-each select="/Root/Form/IncomeSourceList/IncomeSource">
                        <option value="{IncomeSourceID}">
                            <xsl:if test="IncomeSourceID = $incomeSourceID">
                                <xsl:attribute name="selected">selected</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="Name" />
                        </option>
                    </xsl:for-each>
                </select>
            </td>
            <td>
                <xsl:if test="RegionID[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>

                <input class="termField" name="ArtistContract_TermList_Term_{$termPosition}_RegionName" id="ArtistContract_TermList_Term_{$termPosition}_RegionName" type="text" onchange="clearRegion()" onKeyPress="return checkRegionInput(event.keyCode)">
                    <xsl:attribute name="value">
                        <xsl:variable name="regionID" select="RegionID" />
                        <xsl:value-of select="/Root/Form/RegionList/Region[RegionID = $regionID]/Name" />
                    </xsl:attribute>
                </input>&#160;<a href="javascript:matchRegion()" title="Region Lookup"><img src="/production/images/icons/office/Search (16x16).png" height="16" width="16" class="inlineSearchIcon" /></a>
                <input type="hidden" name="{$termPrefix}RegionID" id="{$termPrefix}RegionID" value="{RegionID}" />

            </td>
            <td>
                <xsl:if test="ChannelID[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
                <select name="{$termPrefix}ChannelID" id="{$termPrefix}ChannelID" onChange="this.options[this.selectedIndex].setAttribute('selected', 'true');">
                    <xsl:if test="$termFormat = 'digital'">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
                    <option value="">Choose...</option>
                    <option value="0">
                        <xsl:if test="ChannelID = 0 and $termFormat != 'digital'">
                            <xsl:attribute name="selected">selected</xsl:attribute>
                        </xsl:if>
                        All
                    </option>
                    <xsl:variable name="channelID" select="ChannelID" />
                    <xsl:for-each select="/Root/Form/ChannelList/Channel">
                        <option value="{ChannelID}">
                            <xsl:if test="ChannelID = $channelID and $termFormat != 'digital'">
                                <xsl:attribute name="selected">selected</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="Name" />
                        </option>
                    </xsl:for-each>
                </select>
            </td>
            <td>
                <xsl:if test="PriceLevelID[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
                <select name="{$termPrefix}PriceLevelID" id="{$termPrefix}PriceLevelID" onChange="this.options[this.selectedIndex].setAttribute('selected', 'true');">
                    <xsl:if test="$termFormat = 'digital'">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
                    <option value="">Choose...</option>
                    <xsl:variable name="priceLevelID" select="PriceLevelID" />
                    <option value="0">
                        <xsl:if test="PriceLevelID = 0 and $termFormat != 'digital'">
                            <xsl:attribute name="selected">selected</xsl:attribute>
                        </xsl:if>
                        All
                    </option>
                    <xsl:for-each select="/Root/Form/PriceLevelList/PriceLevel">
                        <option value="{PriceLevelID}">
                            <xsl:if test="PriceLevelID = $priceLevelID and $termFormat != 'digital'">
                                <xsl:attribute name="selected">selected</xsl:attribute>
                            </xsl:if>
                            <xsl:value-of select="Name" />
                        </option>
                    </xsl:for-each>
                </select>
            </td>
            <td>
                <xsl:if test="ContractRateTypeID[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
                <select name="{$termPrefix}ContractRateTypeID" id="{$termPrefix}ContractRateTypeID" onChange="this.options[this.selectedIndex].setAttribute('selected', 'true');" >
                    <xsl:variable name="contractRateTypeID" select="ContractRateTypeID" />
                    <xsl:choose>
                        <xsl:when test="not(ArtistContractTermID)">
                            <option value="">Choose...</option>
                            <xsl:for-each select="/Root/Form/ContractRateTypeList/ContractRateType">
                                <option value="{ContractRateTypeID}">
                                    <xsl:value-of select="Name" />
                                </option>
                            </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>
                            <option value="">Choose...</option>
                            <xsl:for-each select="/Root/Form/IncomeSourceList/IncomeSource[IncomeSourceID = $incomeSourceID]/ValidRateTypes/ContractRateTypeID">
                                <xsl:variable name="rateID" select="." />
                                <xsl:variable name="rateName" select="/Root/Form/ContractRateTypeList/ContractRateType[ContractRateTypeID = $rateID]/Name" />
                                <xsl:if test="$rateName">
                                    <option value="{$rateID}">
                                        <xsl:if test="$contractRateTypeID = $rateID">
                                            <xsl:attribute name="selected">selected</xsl:attribute>
                                        </xsl:if>
                                        <xsl:value-of select="$rateName" />
                                    </option>
                                </xsl:if>
                            </xsl:for-each>
                        </xsl:otherwise>
                    </xsl:choose>
                </select>
            </td>
            <td>
                <xsl:if test="Rate[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
                <input type="text" class="smallRateField" name="{$termPrefix}Rate" id="{$termPrefix}Rate" value="{Rate}" onblur="this.setAttribute('value', this.value);" />
            </td>
            <td>
                <xsl:if test="RateReduction[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
                <input type="text" class="smallRateField" name="{$termPrefix}RateReduction" id="{$termPrefix}RateReduction" value="{RateReduction}" onblur="this.setAttribute('value', this.value);" />
            </td>
            <td>
                <xsl:if test="PercentageOfSales[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
                <input type="text" class="percentWholeField" name="{$termPrefix}PercentageOfSales" id="{$termPrefix}PercentageOfSales" value="{PercentageOfSales}" onblur="this.setAttribute('value', this.value);" />
            </td>
            <td>
                <xsl:if test="PackagingDeduction[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
                <input type="text" class="percentWholeField" name="{$termPrefix}PackagingDeduction" id="{$termPrefix}PackagingDeduction" value="{PackagingDeduction}" onblur="this.setAttribute('value', this.value);" />
            </td>
            <td>
                <xsl:if test="FreeGoodsDeduction[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
                <input type="text" class="percentWholeField" name="{$termPrefix}FreeGoodsDeduction" id="{$termPrefix}FreeGoodsDeduction" value="{FreeGoodsDeduction}" onblur="this.setAttribute('value', this.value);" />
            </td>
            <xsl:if test="$termCount &gt; 0">
                <td>
                    <xsl:attribute name="class">
                        <xsl:choose>
                            <xsl:when test="Delete[@e] and HasDependency = 1">errorInput</xsl:when>
                            <xsl:when test="Delete[@e]">errorInput deleteCheckbox</xsl:when>
                            <xsl:when test="HasDependency = 1"></xsl:when>
                            <xsl:otherwise>deleteCheckbox</xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <div class="deleteCheckboxWrapper">
                        <input type="checkbox" name="{$termPrefix}Delete" id="{$termPrefix}Delete" value="1" onBlur="this.setAttribute('checked', this.checked);">
                            <xsl:choose>
                                <xsl:when test="HasDependency = 1">
                                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                                </xsl:when>
                                <xsl:when test="Delete = 1">
                                    <xsl:attribute name="checked">checked</xsl:attribute>
                                </xsl:when>
                            </xsl:choose>
                        </input>
                        <xsl:if test="HasDependency = 1">
                            <xsl:call-template name="helpIcon">
                                <xsl:with-param name="tip">This term has pending reserves associated with it and cannot be deleted.	</xsl:with-param>
                                <xsl:with-param name="id"><xsl:value-of select="$termRowID" />_Tip</xsl:with-param>
                            </xsl:call-template>
                        </xsl:if>
                    </div>
                </td>
            </xsl:if>
        </tr>
    </xsl:template>

    <xsl:template name="reserveEdit">
        <fieldset class="reserveEdit">
            <legend>Reserves</legend>
            <p class="formHeader">Reserves are applied to physical sales.</p>
            <hr />
            <div class="insideFieldset">
                <table class="singleColumn">
                    <tr>
                        <td class="leftCol"><label for="Form_ArtistContract_ReserveRate">Reserve Rate:</label></td>
                        <td>
                            <xsl:call-template name="inlineError">
                                <xsl:with-param name="path">Form/ArtistContract/ReserveRate</xsl:with-param>
                                <xsl:with-param name="displayName">Reserve Rate</xsl:with-param>
                            </xsl:call-template>
                            <input type="text" name="Form_ArtistContract_ReserveRate" class="percentField" id="Form_ArtistContract_ReserveRate" value="{Form/ArtistContract/ReserveRate}" />%
                        </td>
                    </tr>
                    <tr>
                        <td class="leftCol"><label for="Form_ArtistContract_ReserveLiquidationList">Liquidation Schedule:</label></td>
                        <td class="liquidation">
                            <xsl:call-template name="inlineError">
                                <xsl:with-param name="path">Form/ArtistContract/ReserveLiquidationList</xsl:with-param>
                                <xsl:with-param name="displayName">Liquidation Schedule</xsl:with-param>
                            </xsl:call-template>
                            <xsl:call-template name="liquidationSchedule">
                                <xsl:with-param name="liquidationPrefix">Form_ArtistContract_ReserveLiquidationList_ReserveLiquidation_</xsl:with-param>
                                <xsl:with-param name="liquidationList" select="Form/ArtistContract/ReserveLiquidationList/ReserveLiquidation" />
                                <xsl:with-param name="liquidationID" select="Form/ArtistContract/ArtistContractID" />
                            </xsl:call-template>
                        </td>
                    </tr>
                    <tr>
                        <td class="leftCol"><label for="Form_ArtistContract_DigitalReservesEnabled">Digital Reserves:</label></td>
                        <td class="containsCheckBox">
                            <xsl:call-template name="inlineError">
                                <xsl:with-param name="path">Form/ArtistContract/DigitalReservesEnabled</xsl:with-param>
                                <xsl:with-param name="displayName">Digital Reserve</xsl:with-param>
                            </xsl:call-template>
                            <input type="checkbox" class="checkbox" name="Trigger_Form_ArtistContract_DigitalReservesEnabled" id="Trigger_Form_ArtistContract_DigitalReservesEnabled" onClick="checkCheckBox(this,'Form_ArtistContract_DigitalReservesEnabled')">
                                <xsl:if test="Form/ArtistContract/DigitalReservesEnabled = 1">
                                    <xsl:attribute name="checked">checked</xsl:attribute>
                                </xsl:if>
                            </input>
                            <input type="hidden" name="Form_ArtistContract_DigitalReservesEnabled" id="Form_ArtistContract_DigitalReservesEnabled" value="{Form/ArtistContract/DigitalReservesEnabled}" />
                            <xsl:call-template name="helpIcon">
                                <xsl:with-param name="tip">Checking this box allows you to apply reserves to digital download sales.</xsl:with-param>
                            </xsl:call-template>
                        </td>
                    </tr>
                </table>
            </div>
        </fieldset>
    </xsl:template>

    <xsl:template name="payeeField">
        <input type="hidden" name="Form_ArtistContract_ArtistPayeeID" id="Form_ArtistContract_ArtistPayeeID" value="{Form/ArtistContract/ArtistPayeeID}" />
        <a href="javascript:matchPayee()" title="Payee Lookup" id="payeeLookup"><img src="/production/images/icons/office/Addressbook-(16x16).gif" height="16" width="16" class="lookupIcon" /></a>
        <div id="payeeNameWrapper" class="lookupText">
            <xsl:choose>
                <xsl:when test="normalize-space(Form/ArtistContract/ArtistPayeeID) and substring(Form/ArtistContract/ArtistPayee/Name,26,1)">
                    <abbr title="{Form/ArtistContract/ArtistPayee/Name}"><xsl:value-of select="substring(Form/ArtistContract/ArtistPayee/Name,1,25)" />...</abbr>
                </xsl:when>
                <xsl:when test="normalize-space(Form/ArtistContract/ArtistPayeeID)">
                    <xsl:value-of select="Form/ArtistContract/ArtistPayee/Name" />
                </xsl:when>
                <xsl:otherwise>
                    None
                </xsl:otherwise>
            </xsl:choose>
        </div>


    </xsl:template>

    <xsl:template name="contractEditTermErrors">
        <div class="error">
            <xsl:if test="//Priority[@e]">Priority cannot be blank.<br /></xsl:if>
            <xsl:if test="//IncomeSourceID[@e]">Source must be selected.<br /></xsl:if>
            <xsl:if test="//RegionID[@e]">Region must be looked up.<br /></xsl:if>
            <xsl:if test="//ChannelID[@e]">Channel must be selected.<br /></xsl:if>
            <xsl:if test="//PriceLevelID[@e]">Price must be selected.<br /></xsl:if>
            <xsl:if test="//ContractRateTypeID/@e = 'field_blank'">Rate Type must be selected.<br /></xsl:if>
            <xsl:if test="//ContractRateTypeID/@e = 'field_invalid'">Rate Type must be set to '% Net Revenue'.<br /></xsl:if>
            <xsl:if test="//Rate[@e]">Rate cannot be blank.<br /></xsl:if>
            <xsl:if test="//Delete[@e]">Terms with pending reserves cannot be deleted.<br /></xsl:if>
            <br />
        </div>
    </xsl:template>

    <xsl:template name="termArraysAndObjects">
        <script type="text/javascript">
            // setting up some arrays and objects for use with other functions on this page

            var incomeSources = new Object();
            <xsl:for-each select="/Root/Form/IncomeSourceList/IncomeSource">
                incomeSources[<xsl:value-of select="IncomeSourceID" />] = '<xsl:value-of select="Name" />';
            </xsl:for-each>

            var channels = new Object();
            <xsl:for-each select="/Root/Form/ChannelList/Channel">
                channels[<xsl:value-of select="ChannelID" />] = '<xsl:value-of select="Name" />';
            </xsl:for-each>

            var priceLevels = new Object();
            <xsl:for-each select="/Root/Form/PriceLevelList/PriceLevel">
                priceLevels[<xsl:value-of select="PriceLevelID" />] = '<xsl:value-of select="Name" />';
            </xsl:for-each>

            var sourceFormats = new Object();
            <xsl:for-each select="/Root/Form/IncomeSourceList/IncomeSource">
                sourceFormats[<xsl:value-of select="IncomeSourceID" />] = '<xsl:value-of select="Format" />';
            </xsl:for-each>

            var rateTypes = new Object();
            <xsl:for-each select="/Root/Form/ContractRateTypeList/ContractRateType">
                rateTypes[<xsl:value-of select="ContractRateTypeID" />] = '<xsl:value-of select="Name" />';
            </xsl:for-each>

            var rateTypeIDs = new Array(<xsl:for-each select="/Root/Form/ContractRateTypeList/ContractRateType">'<xsl:value-of select="ContractRateTypeID" />'<xsl:if test="position() != last()">,</xsl:if></xsl:for-each>);

            // setting up an array of possible rate types for each income source
            var possibleSourceRates = new Object();
            <xsl:for-each select="/Root/Form/IncomeSourceList/IncomeSource">
                var sourceRates<xsl:value-of select="IncomeSourceID" /> = new Array();
                <xsl:for-each select="ValidRateTypes/ContractRateTypeID">
                    sourceRates<xsl:value-of select="../../IncomeSourceID" />[<xsl:value-of select="@i" />] = <xsl:value-of select="." />;
                </xsl:for-each>
                possibleSourceRates[<xsl:value-of select="IncomeSourceID" />] = sourceRates<xsl:value-of select="IncomeSourceID" />;
            </xsl:for-each>

        </script>
    </xsl:template>

</xsl:stylesheet>


