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

    <xsl:variable name="helpLinkOptions" select="'width=800, height=500, scrollbars=yes, resizable=yes'" />

    <!--
        By default, the help link will be created using the current page's area and command.
        You only have to pass those in if you want to do something different.
        The helpType param is used to style it differently depending on where it shows up on the page.
    -->

    <xsl:template name="helpLink">
        <xsl:param name="helpArea" select="$area" />
        <xsl:param name="helpCommand" select="$cmd" />
        <xsl:param name="helpType" select="'Page'" />
        <xsl:param name="extraParams" />
        <!-- Possible helpType values are Page, Tab, and Section -->
        <div class="{$helpType}HelpLink">
            <a href="javascript:void(0)" onClick="window.open('help?a={$helpArea}&amp;oc={$helpCommand}{$extraParams}','_blank','{$helpLinkOptions}');">(?) Help With This <xsl:value-of select="$helpType" /></a>
        </div>
    </xsl:template>


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


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

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

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

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


    <xsl:template name="helpIcon">
        <xsl:param name="hidden" />
        <xsl:param name="id" />
        <xsl:param name="linkID" />
        <xsl:param name="hide" />
        <xsl:param name="tip" />
        <a title="{$tip}">
            <xsl:if test="normalize-space($linkID)">
                <xsl:attribute name="id"><xsl:value-of select="$linkID" /></xsl:attribute>
            </xsl:if>
            <img class="helpIcon" src="/production/images/icons/office/Help-(Alt-2)-(16x16).gif" height="16" width="16">
                <xsl:if test="$hidden = 1">
                    <xsl:attribute name="class">hidden</xsl:attribute>
                </xsl:if>
                <xsl:if test="normalize-space($id)">
                    <xsl:attribute name="id"><xsl:value-of select="$id" /></xsl:attribute>
                </xsl:if>
                <xsl:if test="normalize-space($hide)">
                    <xsl:attribute name="onMouseOver">setTimeout('modifyField(\'<xsl:value-of select="$hide" />\',\'hide\')',500)</xsl:attribute>
                    <xsl:attribute name="onMouseOut">modifyField('<xsl:value-of select="$hide" />','show')</xsl:attribute>
                </xsl:if>
            </img>
        </a>
    </xsl:template>


	<xsl:template name="labelContractRow">

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

		<tr class="row{position() mod 2}">
			<td><a href="label_contract?LabelContractID={LabelContractID}&amp;c=show"><xsl:value-of select="Title" /></a></td>

			<xsl:if test="$area = 'contract'">
				<td>Label</td>
			</xsl:if>

			<td>

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

			</td>
			<td><xsl:value-of select="ClientContractID" /></td>
			<xsl:variable name="payorID" select="PayorID" />
			<td><xsl:value-of select="/Root/PayorList/Payor[PayorID = $payorID]/Name" /></td>
			<td><xsl:value-of select="LabelPayeeName" /></td>
			<xsl:if test="/Root/Access/rps/label_contract/edit = 1">
				<td class="icon">
					<a href="label_contract?c=edit&amp;LabelContractID={LabelContractID}" title="Edit">
						<img src="/production/images/icons/office/Edit-(16x16).gif" height="16" width="16" />
 					</a>
				</td>
			</xsl:if>
		</tr>

	</xsl:template>


	<xsl:template name="artistContractRow">

		<tr class="row{position() mod 2}">
			<td><a href="artist_contract?ArtistContractID={ArtistContractID}&amp;c=show"><xsl:value-of select="Title" /></a></td>

			<xsl:if test="$area = 'contract'">
				<td>Artist/Producer</td>
			</xsl:if>

			<td>
				<xsl:value-of select="ArtistDescription" />
			</td>
			<td><xsl:value-of select="ClientContractID" /></td>
			<xsl:variable name="payorID" select="PayorID" />
			<td><xsl:value-of select="/Root/PayorList/Payor[PayorID = $payorID]/Name" /></td>
			<td><xsl:value-of select="ArtistPayee/Name" /></td>
			<xsl:if test="/Root/Access/rps/artist_contract/edit = 1">
				<td class="icon">
					<a href="artist_contract?c=edit&amp;ArtistContractID={ArtistContractID}" title="Edit">
						<img src="/production/images/icons/office/Edit-(16x16).gif" height="16" width="16" />
 					</a>
				</td>
			</xsl:if>
		</tr>

	</xsl:template>


    <xsl:template name="liquidationSchedule">
        <xsl:param name="lockedRecord" />
        <xsl:param name="liquidationID" />
        <xsl:param name="liquidationList" />
        <xsl:param name="liquidationPrefix" />
        <table class="textChart liquidationSchedule">
            <tr>
                <th>1</th><th>2</th><th>3</th><th>4</th><th>5</th><th>6</th><th>7</th><th>8</th>
            </tr>
            <tr class="row1">
                <xsl:call-template name="liquidationScheduleInput">
                    <xsl:with-param name="liquidationList" select="$liquidationList" />
                    <xsl:with-param name="liquidationID" select="$liquidationID" />
                    <xsl:with-param name="liquidationPrefix" select="$liquidationPrefix" />
                    <xsl:with-param name="lockedRecord" select="$lockedRecord" />
                    <xsl:with-param name="lsCount">0</xsl:with-param>
                    <xsl:with-param name="lsStop">7</xsl:with-param>
                </xsl:call-template>
            </tr>
        </table>
    </xsl:template>


    <xsl:template name="liquidationScheduleInput">
	    <xsl:param name="liquidationList" />
	    <xsl:param name="liquidationID" />
	    <xsl:param name="liquidationPrefix" />
	    <xsl:param name="lockedRecord" />
	    <xsl:param name="lsCount" />
	    <xsl:param name="lsStop" />
        <td>
            <input type="hidden" name="{$liquidationPrefix}{$lsCount}_ID" value="{$liquidationID}" />
            <input type="hidden" name="{$liquidationPrefix}{$lsCount}_Period" id="{$liquidationPrefix}{$lsCount}_Period" value="{$lsCount + 1}" />
            <input type="text" maxlength="{$liquidationList[@i = $lsCount]/Percent/@maxLength}" name="{$liquidationPrefix}{$lsCount}_Percent" id="{$liquidationPrefix}{$lsCount}_Percent" value="{$liquidationList[@i = $lsCount]/Percent}">
                <xsl:if test="$lockedRecord = 1">
                    <xsl:attribute name="disabled">disabled</xsl:attribute>
                </xsl:if>
            </input>
        </td>
        <xsl:if test="$lsCount != $lsStop">
            <xsl:call-template name="liquidationScheduleInput">
                <xsl:with-param name="lockedRecord" select="$lockedRecord" />
                <xsl:with-param name="liquidationList" select="$liquidationList" />
                <xsl:with-param name="liquidationID" select="$liquidationID" />
                <xsl:with-param name="liquidationPrefix" select="$liquidationPrefix" />
                <xsl:with-param name="lsCount" select="$lsCount + 1" />
                <xsl:with-param name="lsStop" select="$lsStop" />
            </xsl:call-template>
        </xsl:if>
    </xsl:template>


    <xsl:template name="contractView">
        <fieldset id="contractView">
            <legend>Contract</legend>
            <table class="textChart">
                <tbody>
                    <tr>
                        <th>Contract Title</th>
                        <th>Artist</th>
                        <th>Contract ID</th>
			            <th>Payor</th>
                        <th>Payee</th>
                        <th>Date Issued</th>
                        <th>Term Start</th>
                        <th>Term End</th>
                    </tr>
                    <tr class="row1">
                        <td class="rowLeft"><xsl:value-of select="Form/ArtistContract/Title" /></td>
                        <td><xsl:value-of select="Form/ArtistContract/ArtistDescription" /></td>
                        <td><xsl:value-of select="Form/ArtistContract/ClientContractID" /></td>
    			        <td>
    				        <xsl:choose>
    					        <xsl:when test="$cmd = 'edit'">
    						        <xsl:value-of select="Form/PayorList/Payor[PayorID = /Root/Form/ArtistContract/PayorID]/Name" />
    					        </xsl:when>
    					        <xsl:otherwise>
    						        <a href="/rps/payor?PayorID={Form/ArtistContract/PayorID}&amp;c=show"><xsl:value-of select="Form/PayorList/Payor[PayorID = /Root/Form/ArtistContract/PayorID]/Name" /></a>
    					        </xsl:otherwise>
    				        </xsl:choose>
    			        </td>
                        <td>
              	            <xsl:choose>
              		            <xsl:when test="$cmd = 'edit'">
              			            <xsl:value-of select="Form/ArtistContract/ArtistPayee/Name" />
              		            </xsl:when>
              		            <xsl:otherwise>
              			            <a href="/rps/artist_payee?ArtistPayeeID={Form/ArtistContract/ArtistPayeeID}&amp;c=show"><xsl:value-of select="Form/ArtistContract/ArtistPayee/Name" /></a>
              		            </xsl:otherwise>
              	            </xsl:choose>
                        </td>
                        <td><xsl:value-of select="Form/ArtistContract/IssueDate" /></td>
                        <td><xsl:value-of select="Form/ArtistContract/TermStart" /></td>
                        <td><xsl:value-of select="Form/ArtistContract/TermEnd" /></td>
                    </tr>
                </tbody>
            </table>
            <xsl:if test="normalize-space(Form/ArtistContract/Comments)">
                <br /><span class="liquidationHeader"><strong>Comments: </strong><xsl:value-of select="Form/ArtistContract/Comments" /></span><br /><br />
            </xsl:if>
            <xsl:if test="$area = 'contract' and $cmd = 'show'">
                <div class="singleButton">
                    <input type="button" value="Edit Contract" onClick="javascript:location.href='artist_contract?ContractID={Form/ArtistContract/ArtistContractID}&amp;c=edit'" />
                </div>
            </xsl:if>
        </fieldset>
    </xsl:template>


    <xsl:template name="ccompView">
  	    <xsl:param name="ccomp" />
        <fieldset class="ccompView">
            <legend>Controlled Composition Clause</legend>
            <xsl:if test="normalize-space($ccomp/ControlledCompositionID)">
                <table class="textChart">
                    <tbody>
                        <tr>
                            <th>Track Cap</th>
                            <th>Rate Type</th>
                            <th>Rate %</th>
                            <xsl:if test="$ccomp/RateType != '3'">
                                <th>Rate Basis</th>
                            </xsl:if>
                            <xsl:if test="$ccomp/RateType = '3'">
                                <th>Penny Rate</th>
                            </xsl:if>
                            <xsl:if test="$area = 'catalog'">
                                <th>Term Start</th>
                                <th>Term End</th>
                                <th>Album Pool</th>
                            </xsl:if>
                            <th>Lock Date</th>
                        </tr>
                        <tr class="row1">
                            <td><xsl:value-of select="$ccomp/TrackCap" /></td>
                            <td>
                                <xsl:call-template name="rateType">
                                    <xsl:with-param name="rateTypeID" select="$ccomp/RateType" />
                                </xsl:call-template>
                            </td>
                            <td>
                                <xsl:value-of select="$ccomp/RatePercentage" />%
                            </td>
                            <xsl:if test="$ccomp/RateType != '3'">
                                <td>
                                    <xsl:call-template name="rateBasis">
                                        <xsl:with-param name="rateBasisID" select="$ccomp/RateBasis" />
                                    </xsl:call-template>
                                </td>
                            </xsl:if>
                            <xsl:if test="$ccomp/RateType = '3'">
                                <td><xsl:value-of select="$ccomp/PennyRate" /></td>
                            </xsl:if>
                            <xsl:if test="$area = 'catalog'">
                                <td>
                                    <xsl:value-of select="Form/Album/Contract/TermStart" />
                                </td>
                                <td>
                                    <xsl:value-of select="Form/Album/Contract/TermEnd" />
                                </td>
                                <td>
                                    <xsl:value-of select="Form/Album/AlbumPool" />
                                </td>
                            </xsl:if>
                            <td><xsl:value-of select="$ccomp/LockDate" /></td>
                        </tr>
                    </tbody>
                </table>
                <br />
                <xsl:call-template name="liquidationScheduleView">
                    <xsl:with-param name="liquidationSchedule" select="$ccomp/ReserveLiquidationList/ReserveLiquidation" />
                    <xsl:with-param name="reserveRate" select="$ccomp/ReservePercentage" />
                </xsl:call-template>
            </xsl:if>
            <xsl:if test="$area = 'artist_contract'">
                <div class="singleButton">
                    <input type="button">
                        <xsl:choose>
                            <xsl:when test="normalize-space($ccomp/ControlledCompositionID)">
                                <xsl:attribute name="value">Edit Clause</xsl:attribute>
                                <xsl:attribute name="onClick">javascript:location.href='ccomp?CCompID=<xsl:value-of select="$ccomp/ControlledCompositionID" />&amp;c=edit'</xsl:attribute>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:attribute name="value">Add Clause</xsl:attribute>
                                <xsl:attribute name="onClick">javascript:location.href='ccomp?ArtistContractID=<xsl:value-of select="Form/ArtistContract/ArtistContractID" />&amp;c=edit'</xsl:attribute>
                            </xsl:otherwise>
                        </xsl:choose>
                        <xsl:if test="$lockedRecord = 1">
                            <xsl:attribute name="disabled">disabled</xsl:attribute>
                        </xsl:if>
                    </input>
                </div>
            </xsl:if>
            <br />
        </fieldset>
    </xsl:template>


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

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

        <xsl:choose>
            <xsl:when test="normalize-space($scheduleTest)">
                <xsl:if test="$noHeader != 1">
                    <span class="liquidationHeader"><strong>Liquidation Schedule:</strong></span>
                    <xsl:if test="normalize-space($reserveRate)">
                        <div class="reserveRate"><strong>Reserve:</strong>&#160;<xsl:value-of select="$reserveRate" />%</div>
                    </xsl:if>
                </xsl:if>
                <table class="textChart liquidationSchedule">
                    <tbody>
                        <tr>
                            <xsl:for-each select="$liquidationSchedule">
                                <th><xsl:value-of select="@i + 1" /></th>
                            </xsl:for-each>
                        </tr>
                        <tr class="row1">
                            <xsl:for-each select="$liquidationSchedule">
                                <td><xsl:value-of select="Percent" /><xsl:if test="Percent &gt; 0">%</xsl:if></td>
                            </xsl:for-each>
                        </tr>
                    </tbody>
                </table>
            </xsl:when>
            <xsl:when test="$noHeader = 1">Not entered</xsl:when>
            <xsl:otherwise>
                <span class="liquidationHeader">
                    <strong>Liquidation Schedule:</strong> Not entered
                </span>
                <xsl:if test="$area = 'contract' and $cmd = 'show' and normalize-space($reserveRate)">
                    <div class="reserveRate"><strong>Reserve:</strong>&#160;<xsl:value-of select="$reserveRate" />%</div>
                </xsl:if>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <xsl:template name="albumView">
        <fieldset id="albumView">
            <legend>Album</legend>
            <table class="textChart">
                <tbody>
                    <tr>
                        <th>Title</th>
                        <th>Catalog #</th>
                        <th>Artist</th>
                        <xsl:if test="Form/LabelList/Label">
                            <th>Label</th>
                        </xsl:if>
                        <th class="status">Status</th>
                    </tr>
                    <tr class="row1">
                        <td class="rowLeft"><xsl:value-of select="Form/Album/Title" /><xsl:if test="normalize-space(Form/Album/TitleVersion)">&#160;(<xsl:value-of select="Form/Album/TitleVersion" />)</xsl:if></td>
                        <td><xsl:value-of select="Form/Album/CatalogNumber" /></td>
				        <td><xsl:value-of select="Form/Album/ArtistName" /></td>
				        <xsl:if test="Form/LabelList/Label">
	                        <td>
  	                            <xsl:variable name="albumLabelID"><xsl:value-of select="Form/Album/LabelID" /></xsl:variable>
    	                        <xsl:value-of select="/Root/Form/LabelList/Label[LabelID = $albumLabelID]/LabelName" />
      	                    </td>
                        </xsl:if>
                        <td class="status">
					        <xsl:call-template name="albumStatus">
						        <xsl:with-param name="status" select="Form/Album/Status" />
					        </xsl:call-template>
				        </td>
                    </tr>
                </tbody>
           </table>
        </fieldset>
    </xsl:template>


    <xsl:template name="trackView">
        <xsl:param name="track" />
        <xsl:param name="albumTitle" />
        <fieldset>
            <legend>Track</legend>
            <table class="textChart">
                <tbody>
                    <tr>
                        <th class="rowLeft">Track Title</th>
                        <th>Album Title</th>
                        <th>Artist</th>
                    </tr>
                    <tr class="row1">
                        <td class="rowLeft"><xsl:value-of select="$track/Title" /></td>
                        <td><xsl:value-of select="$albumTitle" /></td>
                        <td><xsl:value-of select="$track/ArtistName" /></td>
                    </tr>
                </tbody>
            </table>
        </fieldset>
    </xsl:template>


    <xsl:template name="publisherView">
        <xsl:param name="publisher" />
        <fieldset>
            <legend>Publisher</legend>
            <table class="textChart">
                <tbody>
                    <tr>
                        <th class="rowLeft">Name</th>
                        <th>Type</th>
                        <th>Admin</th>
                        <th>Agent</th>
                    </tr>
                    <tr class="row1">
                        <td class="rowLeft"><xsl:value-of select="$publisher/PublisherName" /><xsl:if test="$publisher/IsAgency != 0"> [Agent]</xsl:if></td>
                        <td>
                            <xsl:choose>
                                <xsl:when test="$publisher/IsAgency = 1">Agency</xsl:when>
                                <xsl:when test="$publisher/IsAdmin = 1">Administrator</xsl:when>
                                <xsl:otherwise>Standard</xsl:otherwise>
                            </xsl:choose>
                        </td>
                        <td><xsl:value-of select="$publisher/AdminName" /></td>
                        <td><xsl:value-of select="$publisher/AgentName" /></td>
                    </tr>
                </tbody>
            </table>
        </fieldset>
    </xsl:template>


  <xsl:template name="payeeView">
    <xsl:param name="payee" />
    <fieldset>
      <legend>Payee</legend>
        <table class="textChart">
          <tbody>
            <tr>
              <th class="rowLeft">Name</th>
              <th>Client Account #</th>
            </tr>
            <tr class="row1">
              <td class="rowLeft"><xsl:value-of select="$payee/Name" /></td>
              <td><xsl:value-of select="$payee/ClientAccountID" /></td>
            </tr>
          </tbody>
        </table>
    </fieldset>
  </xsl:template>


  <xsl:template name="licenseView">
    <xsl:param name="license" />
        <xsl:param name="crossed" select="'0'" />
		<xsl:param name="track" />
		<xsl:param name="licenseTitle" select="'License'" />
        <fieldset>
          <legend><xsl:value-of select="$licenseTitle" /></legend>
            <table class="textChart">
              <tbody>
                <tr>
                  <th class="rowLeft">Track</th>
                  <th>Track Name</th>
                  <th>Product</th>
                  <th>Region</th>
                  <th>Share</th>
                  <th>Publisher</th>
    				<th>Admin</th>
    				<th>Agent</th>
    				<th class="status">Status</th>
                </tr>
                <xsl:choose>
                	<xsl:when test="$crossed = 0">
                		<xsl:for-each select="$license">
                			<xsl:call-template name="licenseViewRow">
                				<xsl:with-param name="track" select="$track" />
                			</xsl:call-template>
                		</xsl:for-each>
                	</xsl:when>
                	<xsl:otherwise>
                		<xsl:for-each select="$license/TrackLicense">
                			<xsl:call-template name="licenseViewRow">
                				<xsl:with-param name="track" select="$track" />
                			</xsl:call-template>
                		</xsl:for-each>
                	</xsl:otherwise>
                </xsl:choose>
              </tbody>
            </table>
        </fieldset>
	</xsl:template>


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


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


    <xsl:template name="contractListRow">

  	    <xsl:param name="type" />

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

        <tr class="row{position() mod 2}">
            <td>
                <a href="artist_contract?ArtistContractID={ArtistContractID}&amp;c=show">
                    <xsl:value-of select="Title" />
                </a>
            </td>
			<td><xsl:value-of select="ArtistDescription" /></td>
			<td><xsl:value-of select="ClientContractID" /></td>
            <xsl:if test="$type != 'Payee'">
      	        <td><xsl:value-of select="ArtistPayee/Name" /></td>
			</xsl:if>
            <td><xsl:value-of select="IssueDate" /></td>
	  	    <xsl:if test="$type = 'Album'">
          	    <td>
                	<xsl:choose>
                  	    <xsl:when test="../IsControlledComp = 1">
                    	    <a href="{$contractArea}?c=attach&amp;{$type}ContractID={dyn:evaluate($contractIDname)}&amp;Form_{$type}Contract_IsControlledComp=0">Stop Using</a>
        	            </xsl:when>
          	            <xsl:when test="HasCComp = 0">N/A</xsl:when>
            	        <xsl:when test="$ccompTest = ''">
              	            <a href="{$contractArea}?c=attach&amp;{$type}ContractID={dyn:evaluate($contractIDname)}&amp;Form_{$type}Contract_IsControlledComp=1">Use</a>
                	    </xsl:when>
        	        </xsl:choose>
          	    </td>
            </xsl:if>
            <xsl:if test="$type = 'Album' or $type = 'Track'">
    	        <td class="icon">
      	    	    <a href="javascript:confirmRemoveContract('{$contractArea}',{dyn:evaluate($contractIDname)})" title="Remove Contract"><img src="/production/images/icons/office/Close-(16x16).gif" height="16" width="16" /></a>
        	  </td>
            </xsl:if>
        </tr>
    </xsl:template>



<!-- Escape URIs -->


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

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

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

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

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

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

<xsl:template name="royaltyRunEndDate">
	<xsl:call-template name="inlineError">
		<xsl:with-param name="path">Form/EndingSaleDate</xsl:with-param>
		<xsl:with-param name="displayName">Ending Sales Date</xsl:with-param>
	</xsl:call-template>
	<input type="text" class="dateField" name="Form_EndingSaleDate" id="Form_EndingSaleDate" value="{Form/EndingSaleDate}" />
	<a title="Select Ending Sales Date">
        <img src="/production/images/icons/office/Calendar-(16x16).gif" height="16" width="16" class="calendarIcon" id="calendarIconLockDate" />
    </a>
    <xsl:call-template name="calendar">
        <xsl:with-param name="fieldID">Form_EndingSaleDate</xsl:with-param>
        <xsl:with-param name="buttonID">calendarIconLockDate</xsl:with-param>
    </xsl:call-template>
    <xsl:call-template name="helpIcon">
    	<xsl:with-param name="tip">
			All closed sales up to and including the ending sales date are eligible for royalty payment.&lt;br&gt;
			Leave blank to pay royalties on all closed sales.
		</xsl:with-param>
    </xsl:call-template>

</xsl:template>


</xsl:stylesheet>
