<!--                                                                  -->
<!--  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:output method="html" indent="no" doctype-system="http://www.w3.org/TR/html4/strict.dtd"     doctype-public="-//W3C//DTD HTML 4.01//EN" encoding="utf-8" />

    <xsl:include href="/app/tools/rps/templates/ajax_request.xsl" />


    <xsl:template name="pickLayout">
        <xsl:call-template name="catalogContractView" />
    </xsl:template>

    <xsl:template name="catalogContractView">

		<xsl:call-template name="openRunStatusMessage" />
		<xsl:call-template name="albumContracts" />

		<br />

 		<xsl:call-template name="trackContracts" />

    </xsl:template>


	<xsl:template name="albumContracts">
	    <xsl:call-template name="helpLink">
            <xsl:with-param name="helpType">Tab</xsl:with-param>
        </xsl:call-template>
		<fieldset>
			<legend>Album Contracts</legend>

			<table class="textChart">

				<xsl:variable name="albumContracts" select="Form/AlbumContractList/AlbumContract" />
				<xsl:if test="normalize-space($albumContracts)">

					<tr>
						<th>Contract Title</th>
						<th>Artist</th>
						<th>Contract ID</th>
						<th>Payee</th>
						<th>Issue Date</th>
						<th>Controlled Composition</th>
						<th>Actions</th>
					</tr>

					<xsl:for-each select="$albumContracts">
				    <tr class="row{position() mod 2}">
				      <td>
				        <a href="artist_contract?ArtistContractID={Contract/ArtistContractID}&amp;c=show">
				          <xsl:value-of select="Contract/Title" />
				        </a>
				      </td>
                      <td><xsl:value-of select="Contract/ArtistDescription" /></td>
                      <td><xsl:value-of select="Contract/ClientContractID" /></td>
                      <td><xsl:value-of select="Contract/ArtistPayee/Name" /></td>
				      <td><xsl:value-of select="Contract/IssueDate" /></td>
			      	  <td>
			        	<xsl:choose>
			        	  <xsl:when test="IsControlledComp = 1 or IsCAControlledComp = 1">In Use</xsl:when>  
			  	          <xsl:when test="Contract/HasCComp = 0">Unavailable</xsl:when>
			    	      <xsl:otherwise>Available</xsl:otherwise>
				        </xsl:choose>
			  	      </td>
				      <td>
			        	<xsl:choose>
                            <xsl:when test="IsControlledComp = 1 or IsCAControlledComp = 1">
                                N/A
                                <!--
                                <xsl:call-template name="helpIcon">
                                    <xsl:with-param name="tip">A contract selected for use with controlled composition mechanical licenses cannot be inactivated or removed.</xsl:with-param>
                                </xsl:call-template>
                                -->
                            </xsl:when>
			  	            <xsl:when test="CanDelete = 1 and Status = 1">
         			        	<xsl:choose>
			        	        <xsl:when test="$openRuns &gt; 0">
									Remove
								</xsl:when>
								<xsl:otherwise>
	    		  	    	        <a href="javascript:confirmRemoveContract('catalog',{AlbumContractID})" title="Remove Contract">Remove</a>
    			        	    </xsl:otherwise>
         			        	</xsl:choose>
                            </xsl:when>
			    	        <xsl:otherwise>
			        	        <xsl:choose>
			  	                    <xsl:when test="Status = 1">
                			        	<xsl:choose>
	         		        	          <xsl:when test="$openRuns &gt; 0">
								            Inactivate
										  </xsl:when>
								          <xsl:otherwise>
			  	    	                    <a href="javascript:confirmInactivateContract('catalog',{AlbumContractID})" title="Inactivate Contract">Inactivate</a>
								          </xsl:otherwise>
								        </xsl:choose>
			  	                    </xsl:when>
			  	                    <xsl:when test="Status = 2">
                			        	<xsl:choose>
	         		        	          <xsl:when test="$openRuns &gt; 0">
								            Reactivate
										  </xsl:when>
								          <xsl:otherwise>
			  	    	                    <a href="javascript:confirmReactivateContract('catalog',{AlbumContractID})" title="Reactivate Contract">Reactivate</a>
								          </xsl:otherwise>
								        </xsl:choose>
			  	                    </xsl:when>
			    	                <xsl:otherwise> </xsl:otherwise>
				                </xsl:choose>
			    	        </xsl:otherwise>
				        </xsl:choose>
			    	  </td>
				    </tr>
					</xsl:for-each>

				</xsl:if>

				<tr>
					<td colspan="7" class="right">
						<input type="button" id="addContractButton" value="Attach Contract" class="bottomButton" onClick="displayInline('artist_contract?c=search&amp;AlbumID={Params/AlbumID}&amp;_inline=1')" >
						    <xsl:if test="$openRuns &gt; 0">
    		                    <xsl:attribute name="disabled">disabled</xsl:attribute>
    		                </xsl:if>
						</input>
					</td>
				</tr>

			</table>

		</fieldset>
	</xsl:template>


	<xsl:template name="trackContracts">
		<fieldset>
			<legend>Track Contracts</legend>
			<table class="textChart">

				<xsl:variable name="trackContracts" select="Form/TrackList/Track/TrackContractList/TrackContract" />
				<xsl:if test="normalize-space($trackContracts)">
					<tr>
						<th>Track</th>
						<th>Track Name</th>
						<th>Contract Title</th>
						<th>Artist</th>
						<th>Contract ID</th>
						<th>Payee</th>
						<th>Issue Date</th>
						<th>Actions</th>
					</tr>

					<xsl:for-each select="Form/TrackList/Track[normalize-space(TrackContractList)]">
						<xsl:variable name="rowClass">row<xsl:value-of select="position() mod 2" /></xsl:variable>
						<xsl:for-each select="TrackContractList/TrackContract">
					    <tr class="{$rowClass}">
					    	<td>
					    		<xsl:if test="@i = 0">
					    			<xsl:if test="../../TrackOrder &lt; 10">0</xsl:if><xsl:value-of select="../../TrackOrder" />
					    		</xsl:if>
					    	</td>
					    	<td>
					    		<xsl:if test="@i = 0">
					    			<xsl:value-of select="../../Title" />
					    		</xsl:if>
					    	</td>
					      <td>
					        <a href="artist_contract?ArtistContractID={Contract/ArtistContractID}&amp;c=show">
					          <xsl:value-of select="Contract/Title" />
					        </a>
					      </td>
								<td><xsl:value-of select="Contract/ArtistDescription" /></td>
								<td><xsl:value-of select="Contract/ClientContractID" /></td>
					     	<td><xsl:value-of select="Contract/ArtistPayee/Name" /></td>
					      <td><xsl:value-of select="Contract/IssueDate" /></td>
					      <td>
			        	    <xsl:choose>
			  	                <xsl:when test="CanDelete = 1 and Status = 1">
                			        <xsl:choose>
	         		        	        <xsl:when test="$openRuns &gt; 0">
								            Remove
										</xsl:when>
								        <xsl:otherwise>
			  	    	                    <a href="javascript:confirmRemoveContract('track',{TrackContractID})" title="Remove Contract">Remove</a>
								        </xsl:otherwise>
							        </xsl:choose>
                                </xsl:when>
			    	            <xsl:otherwise>
			        	            <xsl:choose>
			  	                        <xsl:when test="Status = 1">
                			        	    <xsl:choose>
	         		        	              <xsl:when test="$openRuns &gt; 0">
								                Inactivate
										      </xsl:when>
								              <xsl:otherwise>
			  	    	                        <a href="javascript:confirmInactivateContract('track',{TrackContractID})" title="Inactivate Contract">Inactivate</a>
								              </xsl:otherwise>
   						                    </xsl:choose>
			  	                        </xsl:when>
			  	                        <xsl:when test="Status = 2">
                			        	    <xsl:choose>
	         		        	              <xsl:when test="$openRuns &gt; 0">
								                Reactivate
										      </xsl:when>
								              <xsl:otherwise>
			  	    	                        <a href="javascript:confirmReactivateContract('track',{TrackContractID})" title="Reactivate Contract">Reactivate</a>
								              </xsl:otherwise>
   						                    </xsl:choose>
			  	                        </xsl:when>
			    	                    <xsl:otherwise> </xsl:otherwise>
				                    </xsl:choose>
			    	            </xsl:otherwise>
				            </xsl:choose>
				    	  </td>
					    </tr>
						</xsl:for-each>
					</xsl:for-each>

				</xsl:if>

				<xsl:choose>
					<xsl:when test="Form/TrackList/Track">
						<tr>
							<td colspan="8" class="right">
								Select Track:
								<select name="trackID" id="trackID">
						            <xsl:if test="$openRuns &gt; 0">
    		                            <xsl:attribute name="disabled">disabled</xsl:attribute>
    		                        </xsl:if>
									<option value="">Choose...</option>
									<xsl:for-each select="Form/TrackList/Track">
										<option value="{TrackID}"><xsl:value-of select="Title" /></option>
									</xsl:for-each>
								</select>
								<input type="button" id="addContractButton" value="Attach Contract" class="bottomButton" onClick="attachTrackContract()" >
						            <xsl:if test="$openRuns &gt; 0">
    		                            <xsl:attribute name="disabled">disabled</xsl:attribute>
    		                        </xsl:if>
								</input>
							</td>
						</tr>
					</xsl:when>
					<xsl:otherwise>
						<p class="emptyMessage">This album has no tracks.</p>
						<br />
					</xsl:otherwise>
				</xsl:choose>

			</table>
		</fieldset>
	</xsl:template>


</xsl:stylesheet>
