<!--                                                                  -->
<!--  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="termCount" select="count(/Root/Form/ArtistContract/TermList/Term)" />

  <xsl:variable name="unitBasedDisabled">
    <xsl:choose>
      <xsl:when test="not(/Root/Params/ArtistContractID) 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?v=3" />
    <form name="contractEdit" id="contractEdit" method="post" action="artist_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:call-template name="openRunStatusMessage" />
      <xsl:call-template name="helpLink" />
      <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) and not(Params/copy)">
        <input type="hidden" name="ArtistContractID" 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">
    								<xsl:if test="not(Params/copy)">
                  		<xsl:attribute name="value"><xsl:value-of select="Form/ArtistContract/Title" /></xsl:attribute>
    								</xsl:if>
                    <xsl:if test="$openRuns = 1">
                      <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
                  </input>
                </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">
    								<xsl:if test="not(Params/copy)">
                  		<xsl:attribute name="value"><xsl:value-of select="Form/ArtistContract/ArtistDescription" /></xsl:attribute>
    								</xsl:if>
                    <xsl:if test="$openRuns = 1">
                      <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
                  </input>
                </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">
                    <xsl:if test="not(Params/copy)">
                  		<xsl:attribute name="value"><xsl:value-of select="Form/ArtistContract/ClientContractID" /></xsl:attribute>
                    </xsl:if>
                    <xsl:if test="$openRuns = 1">
                      <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
                  </input>
                </td>
              </tr>
              <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:if test="$openRuns = 1">
                      <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
                    <xsl:for-each select="Form/PayorList/Payor">
                      <option value="{PayorID}">
                      	<xsl:choose>
                      		<xsl:when test="/Root/Params/copy and IsDefault = 1">
                      			<xsl:attribute name="selected">selected</xsl:attribute>
                      		</xsl:when>
    	                    <xsl:when test="not(/Root/Params/copy) and PayorID = /Root/Form/ArtistContract/PayorID">
    	                      <xsl:attribute name="selected">selected</xsl:attribute>
    	                    </xsl:when>
    	                   </xsl:choose>
                        <xsl:value-of select="substring(Name,1,25)" /><xsl:if test="substring(Name,26,1)">...</xsl:if>
                      </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 colspan="2">
                  <br />*Required field
                </td>
              </tr>
            </table>
          </div>
          <div class="column2">
            <table>
              <tr>
                <td class="leftCol"><label for="Form_ArtistContract_IssueDate">Date Issued:</label></td>
                <td>
                  <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ArtistContract/IssueDate</xsl:with-param>
                    <xsl:with-param name="displayName">Date Issued</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">
                        <xsl:if test="not(Params/copy)">
    	              		<xsl:attribute name="value"><xsl:value-of select="Form/ArtistContract/IssueDate" /></xsl:attribute>
                        </xsl:if>
                      <xsl:if test="$openRuns = 1">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                      </xsl:if>
    	              </input>
                  </span>
                  <a title="Select Issue Date">
                    <img src="/production/images/icons/office/Calendar-(16x16).gif" class="calendarIcon" id="calendarIconIssueDate"/>
                  </a>
    			  <xsl:if test="$openRuns = 0">
                    <xsl:call-template name="calendar">
                    	<xsl:with-param name="fieldID">Form_ArtistContract_IssueDate</xsl:with-param>
                    	<xsl:with-param name="buttonID">calendarIconIssueDate</xsl:with-param>
                    </xsl:call-template>
    			  </xsl:if>
                </td>
              </tr>

              <tr>
                <td class="leftCol"><label for="Form_ArtistContract_TermStart">Term Start:</label></td>
                <td>
                  <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ArtistContract/TermStart</xsl:with-param>
                    <xsl:with-param name="displayName">Term Start</xsl:with-param>
                  </xsl:call-template>
                  <span id="Form_ArtistContract_TermStart_TD">
                    <input type="text" class="dateField" name="Form_ArtistContract_TermStart" id="Form_ArtistContract_TermStart">
                        <xsl:if test="not(Params/copy)">
    	              		<xsl:attribute name="value"><xsl:value-of select="Form/ArtistContract/TermStart" /></xsl:attribute>
                        </xsl:if>
                      <xsl:if test="$openRuns = 1">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                      </xsl:if>
    	              </input>
                  </span>
                  <a title="Select Term Start Date">
                    <img src="/production/images/icons/office/Calendar-(16x16).gif" class="calendarIcon" id="calendarIconTermStart"/>
                  </a>

    			  <xsl:if test="$openRuns = 0">
                    <xsl:call-template name="calendar">
                    	<xsl:with-param name="fieldID">Form_ArtistContract_TermStart</xsl:with-param>
                    	<xsl:with-param name="buttonID">calendarIconTermStart</xsl:with-param>
                    </xsl:call-template>
    			  </xsl:if>
                </td>
              </tr>  


              <tr>
                <td class="leftCol"><label for="Form_ArtistContract_TermEnd">Term End:</label></td>
                <td>
                  <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ArtistContract/TermEnd</xsl:with-param>
                    <xsl:with-param name="displayName">Term End</xsl:with-param>
                  </xsl:call-template>
                  <span id="Form_ArtistContract_TermEnd_TD">
                    <input type="text" class="dateField" name="Form_ArtistContract_TermEnd" id="Form_ArtistContract_TermEnd">
                        <xsl:if test="not(Params/copy)">
    	              		<xsl:attribute name="value"><xsl:value-of select="Form/ArtistContract/TermEnd" /></xsl:attribute>
                        </xsl:if>
                      <xsl:if test="$openRuns = 1">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                      </xsl:if>
    	              </input>
                  </span>
                  <a title="Select Term End Date">
                    <img src="/production/images/icons/office/Calendar-(16x16).gif" class="calendarIcon" id="calendarIconTermEnd"/>
                  </a>
                  
    			  <xsl:if test="$openRuns = 0">
                    <xsl:call-template name="calendar">
                    	<xsl:with-param name="fieldID">Form_ArtistContract_TermEnd</xsl:with-param>
                    	<xsl:with-param name="buttonID">calendarIconTermEnd</xsl:with-param>                	
                    </xsl:call-template>
    			  </xsl:if>
                </td>
              </tr>  

              <tr class="labelTop">
                <td class="leftCol"><label for="Form_ArtistContract_Comments">Comments:</label></td>
                <td>
                  <xsl:call-template name="inlineError">
                    <xsl:with-param name="path">Form/ArtistContract/Comments</xsl:with-param>
                    <xsl:with-param name="displayName">Comments</xsl:with-param>
                  </xsl:call-template>
                  <span id="Form_ArtistContract_Comments_TD">
                    <textarea rows="6" cols="40" name="Form_ArtistContract_Comments" id="Form_ArtistContract_Comments">
                      <xsl:if test="$openRuns = 1">
                        <xsl:attribute name="disabled">disabled</xsl:attribute> 
                      </xsl:if>
                        <xsl:if test="not(Params/copy)">
    	              		<xsl:value-of select="Form/ArtistContract/Comments" />
                        </xsl:if>
    	              </textarea>
                  </span>
                </td>
              </tr>  
                          
            </table>
          </div>
      </div>
    </fieldset>
  </xsl:template>


    <xsl:template name="monthOptions">
        <xsl:param name="selected" />

    	<option value="1">
    		<xsl:if test="$selected = 1">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		1 - January
    	</option>
    	<option value="2">
    		<xsl:if test="$selected = 2">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		2 - February
    	</option>
    	<option value="3">
    		<xsl:if test="$selected = 3">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		3 - March
    	</option>
    	<option value="4">
    		<xsl:if test="$selected = 4">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		4 - April
    	</option>
    	<option value="5">
    		<xsl:if test="$selected = 5">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		5 - May
    	</option>
    	<option value="6">
    		<xsl:if test="$selected = 6">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		6 - June
    	</option>
    	<option value="7">
    		<xsl:if test="$selected = 7">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		7 - July
    	</option>
    	<option value="8">
    		<xsl:if test="$selected = 8">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		8 - August
    	</option>
    	<option value="9">
    		<xsl:if test="$selected = 9">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		9 - September
    	</option>
    	<option value="10">
    		<xsl:if test="$selected = 10">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		10 - October
    	</option>
    	<option value="11">
    		<xsl:if test="$selected = 11">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		11 - November
    	</option>
    	<option value="12">
    		<xsl:if test="$selected = 12">
    			<xsl:attribute name="selected">selected</xsl:attribute>
    		</xsl:if>
    		12 - December
    	</option>
    </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 (more or less than 100%)</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">
	    <xsl:choose>
          <xsl:when test="$openRuns &gt; 0">
          </xsl:when>
          <xsl:otherwise>
	        <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>
  		  </xsl:otherwise>
	    </xsl:choose>
	  </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>
          <th class="deleteCol">Inactive</th>
        </tr>
        <tr class="defaultRow">
          <td class="rowLeft">Default</td>
          <td>All</td>
          <td>All</td>
          <td>All</td>
          <td>All</td>
          <td>
              <input type="hidden" name="Form_ArtistContract_DefaultTerm_ContractTermSourceID" value="5" />            
              % Net Revenue
		  		</td>
          <td>
            <xsl:if test="Form/ArtistContract/DefaultTerm/Rate/@emsg">
                <xsl:attribute name="class">errorInput</xsl:attribute>
            </xsl:if>          
          
            <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="medRateField" name="Form_ArtistContract_DefaultTerm_Rate" id="Form_ArtistContract_DefaultTerm_Rate" value="{Form/ArtistContract/DefaultTerm/Rate}" >
              <xsl:if test="$openRuns = 1">
                <xsl:attribute name="disabled">disabled</xsl:attribute>
              </xsl:if>
			</input>
          </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}" >
                  <xsl:if test="$openRuns = 1">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                  </xsl:if>
			    </input>
		      </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}" >
                  <xsl:if test="$openRuns = 1">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                  </xsl:if>
			    </input>
		      </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}" >
                  <xsl:if test="$openRuns = 1">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                  </xsl:if>
			    </input>
		      </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}" >
                  <xsl:if test="$openRuns = 1">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                  </xsl:if>
			    </input>
		      </td>
		      <td class="deleteCheckbox">
		      	<xsl:variable name="inactive" select="Form/ArtistContract/DefaultTerm/Inactive" />
                <input type="checkbox" class="checkbox" name="Trigger_Form_ArtistContract_DefaultTerm_Inactive" id="Trigger_Form_ArtistContract_DefaultTerm_Inactive" onClick="checkCheckBox(this,'Form_ArtistContract_DefaultTerm_Inactive')">
                  <xsl:if test="$openRuns = 1">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                  </xsl:if>
				  <xsl:if test="$inactive = 1">
				    <xsl:attribute name="checked">checked</xsl:attribute>
				  </xsl:if>
  				  <xsl:if test="Form/ArtistContract/DefaultTerm/HasDependency = 1">
					<xsl:attribute name="disabled">disabled</xsl:attribute>
				  </xsl:if>
				</input>
                <input type="hidden" name="Form_ArtistContract_DefaultTerm_Inactive" id="Form_ArtistContract_DefaultTerm_Inactive" value="{Form/ArtistContract/DefaultTerm/Inactive}" >
                  <xsl:if test="$openRuns = 1">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                  </xsl:if>
                </input>
				<xsl:if test="Form/ArtistContract/DefaultTerm/HasDependency = 1">
					<xsl:call-template name="helpIcon">
						<xsl:with-param name="tip">This term has pending reserves associated with it and cannot be inactivated.	</xsl:with-param>
						<xsl:with-param name="id">contractTermDefault_Tip</xsl:with-param>
					</xsl:call-template>
				</xsl:if>
		      </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="contractTermSourceID" select="ContractTermSourceID" />
		<xsl:variable name="priceLevelID" select="PriceLevelID" />
		<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/ContractTermSourceList/ContractTermSource[ContractTermSourceID = $contractTermSourceID]">
				<xsl:choose>
					<xsl:when test="HasDigital = 1">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>
                    <xsl:if test="$openRuns = 1">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
				</input>

      	        <div class="termPriority" id="{$termRowID}_Display">
					<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="ContractTermSourceID[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>

                <!-- Master and Sync are no longer allowed as new selections for this drop down -->

                <select name="{$termPrefix}ContractTermSourceID" id="{$termPrefix}ContractTermSourceID" onChange="this.options[this.selectedIndex].setAttribute('selected', 'true'); checkSourceFormat(this,'{$termPosition}');" class="contractTermSources">
                    <xsl:if test="$openRuns = 1">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
                    <option value="">Choose...</option>
                    <xsl:for-each select="/Root/Form/ContractTermSourceList/ContractTermSource">
          	            <xsl:choose>
                      		<xsl:when test="ContractTermSourceID = 4 and ContractTermSourceID != $contractTermSourceID"></xsl:when>
                      		<xsl:when test="ContractTermSourceID = 4 and not($contractTermSourceID)"></xsl:when>
                      		<xsl:when test="ContractTermSourceID = 5 and ContractTermSourceID != $contractTermSourceID"></xsl:when>
                      		<xsl:when test="ContractTermSourceID = 5 and not($contractTermSourceID)"></xsl:when>
                      		<xsl:otherwise>
		                        <option value="{ContractTermSourceID}">
		                            <xsl:if test="ContractTermSourceID = $contractTermSourceID">
		                                <xsl:attribute name="selected">selected</xsl:attribute>
		                            </xsl:if>
		                            <xsl:choose>
										<xsl:when test="ParentContractTermSourceID &gt; 1">
											&#160;&#160;&#160;
										</xsl:when>
										<xsl:when test="ParentContractTermSourceID = 1 and (ContractTermSourceID &lt; 4 or ContractTermSourceID = 30)">
											&#160;
										</xsl:when>
										<xsl:when test="ParentContractTermSourceID = 1">
											&#160;&#160;&#160;
										</xsl:when>
									</xsl:choose>
							        <xsl:value-of select="Name" />
		                        </option>
		                    </xsl:otherwise>
		                </xsl:choose>
                    </xsl:for-each>
                </select>
			</td>

            <td>
                <xsl:if test="RegionID[@e]">
                    <xsl:attribute name="class">errorInput</xsl:attribute>
                </xsl:if>
		  	    <input type="hidden" name="{$termPrefix}RegionID" id="{$termPrefix}RegionID" value="{RegionID}" />
	            <xsl:choose>
                    <xsl:when test="$openRuns &gt; 0">
                        <img src="/production/images/icons/office/Addressbook-Disabled-(16x16).gif" height="16" width="16" class="lookupIcon" />
                    </xsl:when>
                    <xsl:otherwise>
    		  	        <a href="javascript:matchTermRegion('{$termPrefix}')" title="Region Lookup" id="{$termPrefix}RegionLookup"><img src="/production/images/icons/office/Addressbook-(16x16).gif" height="16" width="16" class="lookupIcon" /></a>
                    </xsl:otherwise>
                </xsl:choose>
		  	    <div id="{$termPrefix}RegionNameWrapper" class="lookupText">
					<xsl:variable name="regionID" select="RegionID" />
					<xsl:variable name="regionName" select="/Root/Form/RegionList/Region[RegionID = $regionID]/Name" />
		  		    <xsl:choose>
		  			    <xsl:when test="normalize-space(RegionID) and substring($regionName,14,1)">
		  				    <abbr title="{$regionName}"><xsl:value-of select="substring($regionName,1,11)" />...</abbr>
		  			    </xsl:when>
		  			    <xsl:when test="normalize-space(RegionID)">
		  				    <xsl:value-of select="$regionName" />
		  			    </xsl:when>
		  			    <xsl:otherwise>
		  				    (none)
		  			    </xsl:otherwise>
		  		    </xsl:choose>
		  	    </div>
            </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="$openRuns = 1">
                      <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
					<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'); checkSourceFormat(document.getElementById('{$termPrefix}ContractTermSourceID'),'{$termPosition}');">
                    <xsl:if test="$openRuns = 1">
                      <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
					<xsl:if test="$termFormat = 'digital'">
						<xsl:attribute name="disabled">disabled</xsl:attribute>
					</xsl:if>
					<option value="">Choose...</option>
					<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[Type = 1]">
						<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>
					<xsl:for-each select="/Root/Form/PriceLevelList/PriceLevel[Type = 3]">
						<option value="{PriceLevelID}">
							<xsl:if test="PriceLevelID = $priceLevelID">
								<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'); checkRateType(document.getElementById('{$termPrefix}ContractRateTypeID'),'{$termPosition}')" >
                    <xsl:if test="$openRuns = 1 or (HasDependency = 1 and not(/Root/Params/copy))">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
                    <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/ContractTermSourceList/ContractTermSource[ContractTermSourceID = $contractTermSourceID]/ValidRateTypes">
          			            <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="medRateField" name="{$termPrefix}Rate" id="{$termPrefix}Rate" value="{Rate}" onblur="this.setAttribute('value', this.value);" >
                    <xsl:if test="$openRuns = 1 or ContractRateTypeID = 9">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
		        </input>
            </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);" >
                    <xsl:if test="$openRuns = 1 or ContractRateTypeID = 9">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
		        </input>
            </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);" >
                    <xsl:if test="$openRuns = 1 or ContractRateTypeID = 9">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
		        </input>
            </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);" >
                    <xsl:if test="$openRuns = 1 or ContractRateTypeID = 9">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
		        </input>
            </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);" >
                    <xsl:if test="$openRuns = 1 or ContractRateTypeID = 9">
                        <xsl:attribute name="disabled">disabled</xsl:attribute>
                    </xsl:if>
		        </input>
            </td>
            <xsl:if test="$termCount &gt; 0">
      	        <td>
      		        <xsl:attribute name="class">
      			        <xsl:choose>
              				<xsl:when test="Delete[@e] and HasDependency = 1 and not(/Root/Params/copy)">errorInput</xsl:when>
                			<xsl:when test="Delete[@e]">errorInput deleteCheckbox</xsl:when>
                			<xsl:when test="HasDependency = 1 and not(/Root/Params/copy)"></xsl:when>
                			<xsl:otherwise>deleteCheckbox</xsl:otherwise>
        		        </xsl:choose>
        	        </xsl:attribute>
        	        <div class="deleteCheckboxWrapper" style="white-space: nowrap">
      			        <input type="checkbox" name="{$termPrefix}Delete" id="{$termPrefix}Delete" value="1" onBlur="this.setAttribute('checked', this.checked);">
                            <xsl:if test="$openRuns = 1">
                                <xsl:attribute name="disabled">disabled</xsl:attribute>
                            </xsl:if>
      			            <xsl:choose>
								<xsl:when test="HasDependency = 1 and not(/Root/Params/copy)">
									<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 and not(/Root/Params/copy)">
							<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}" >
                <xsl:if test="$openRuns = 1">
                  <xsl:attribute name="disabled">disabled</xsl:attribute>
                </xsl:if>
			  </input>%
            </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:with-param name="lockedRecord" select="$openRuns" />
              </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">
  		<xsl:if test="not(Params/copy)">
  	 		<xsl:attribute name="value"><xsl:value-of select="Form/ArtistContract/ArtistPayeeID" /></xsl:attribute>
  	  </xsl:if>
  	</input>

	<xsl:choose>
      <xsl:when test="$openRuns &gt; 0">
        <img src="/production/images/icons/office/Addressbook-Disabled-(16x16).gif" height="16" width="16" class="lookupIcon" />
      </xsl:when>
      <xsl:otherwise>
	    <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>
      </xsl:otherwise>
    </xsl:choose>

  	<div id="payeeNameWrapper" class="lookupText">
  		<xsl:choose>
  			<xsl:when test="normalize-space(Form/ArtistContract/ArtistPayeeID) and substring(Form/ArtistContract/ArtistPayee/Name,26,1) and not(Params/copy)">
  				<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) and not(Params/copy)">
  				<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="//ContractTermSourceID[@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="//Rate/@emsg">Default rate can not be 0.<br /></xsl:if>
      <xsl:if test="//Delete[@e]">Terms with pending reserves cannot be deleted.<br /></xsl:if>
      <xsl:if test="//Term/RateReduction/@e = 'field_out_of_range'">Rate Reduction must be between <xsl:value-of select="//Term/RateReduction/@minValue" /> and <xsl:value-of select="//Term/RateReduction/@maxValue" />.<br /></xsl:if>
      <xsl:variable name="termStart"><xsl:value-of select="Form/ArtistContract/TermStartYear" /><xsl:value-of select="Form/ArtistContract/TermStartMonth" /></xsl:variable>
      <xsl:variable name="termEnd"><xsl:value-of select="Form/ArtistContract/TermEndYear" /><xsl:value-of select="Form/ArtistContract/TermEndMonth" /></xsl:variable>
      <xsl:if test="$termStart &gt; $termEnd">Term Start cannot be later than Term End.<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 channels = new Object();
    	channels[0] = 'All';
      <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();
    	priceLevels[0] = 'All';
      <xsl:for-each select="/Root/Form/PriceLevelList/PriceLevel[Type != 2]">
        priceLevels[<xsl:value-of select="PriceLevelID" />] = '<xsl:value-of select="Name" />';
      </xsl:for-each>

      var sourceFormats = new Object();
      <xsl:for-each select="/Root/Form/ContractTermSourceList/ContractTermSource">
        sourceFormats[<xsl:value-of select="ContractTermSourceID" />] = '<xsl:value-of select="HasDigital" />';
      </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/ContractTermSourceList/ContractTermSource">
      	var sourceRates<xsl:value-of select="ContractTermSourceID" /> = new Array();
      	<xsl:for-each select="ValidRateTypes">
        	sourceRates<xsl:value-of select="../ContractTermSourceID" />[<xsl:value-of select="@i" />] = <xsl:value-of select="." />;
				</xsl:for-each>
				possibleSourceRates[<xsl:value-of select="ContractTermSourceID" />] = sourceRates<xsl:value-of select="ContractTermSourceID" />;
      </xsl:for-each>

    </script>
  </xsl:template>

</xsl:stylesheet>
