<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	
	<xsl:variable name="payorCount" select="count(/Root/PayorList/Payor)" />

  <xsl:template name="contractMainLayout">
		<div id="contractMain">
			<div class="section">
			    <table class="landingPage">
			        <tr>
        				<xsl:call-template name="addSection" />
        				<xsl:call-template name="viewSection" />
				    </tr>
				</table>
			</div>
			<xsl:call-template name="searchSection" />
			<xsl:call-template name="recentList" />
		</div>
	</xsl:template>

	<xsl:template name="addSection">
		<td class="landingAdd">
			<h2>Add Contract</h2>
			<table>
				<tr>
					<td>
						<a href="/rps/artist_contract?c=edit" title="Add New Artist/Producer Contract"><img src="/production/images/icons/office/Add-(16x16).gif" height="16" width="16" /></a> <a href="/rps/artist_contract?c=edit">Add New Artist/Producer Contract</a>
						<br /><br />
						<a href="/rps/label_contract?c=edit" title="Add New Label Contract"><img src="/production/images/icons/office/Add-(16x16).gif" height="16" width="16" /></a> <a href="/rps/label_contract?c=edit">Add New Label Contract</a>
					</td>
				</tr>
			</table>
		</td>
	</xsl:template>

	<xsl:template name="viewSection">
		<td class="landingView">
			<h2>View Contracts</h2>
			<table>
				<tr>
					<td>
						<xsl:call-template name="artistContractLink" />
						<xsl:call-template name="labelContractLink" />
					</td>
				</tr>
			</table>
		</td>
	</xsl:template>

	<xsl:template name="searchSection">
		<div class="section landingSearch">
			<table>
				<tr>
					<td>
						<form action="artist_contract" method="get" name="contractLandingSearch" id="contractLandingSearch">
							<input type="hidden" name="c" value="search" />
							<label for="contractSearch">Search: </label>
							<select name="searchType" onChange="updateSearchAction('contractLandingSearch',this.value)">
								<option value="artist_contract">Artist/Producer Contracts</option>
								<option value="label_contract">Label Contracts</option>
							</select>
							<input type="text" name="Query" id="contractSearch" class="searchField" />
							<input type="submit" name="go" value="Go" />
							<br />
							<span class="subtle">Search by contract name, contract ID, or payee name.</span>
						</form>
					</td>	
				</tr>	
			</table>
		</div>
	</xsl:template>

	<xsl:template name="recentList">
		<div class="section">
			<h2>Most Recently Accessed Contracts</h2>
			<xsl:if test="RecentlyViewed/Item">
      	<table class="textChart hiOn">
    	    <tr>
  	        <th>Contract Title</th>
  	        <th>Type</th>
						<th>Artist/Label</th>
        	  <th>Contract ID</th>
						<th>Payor</th>
    	      <th>Payee</th>
						<xsl:if test="/Root/Access/rps/artist_contract/edit = 1 or /Root/Access/rps/label_contract/edit = 1">
  		        <th class="editCol">Edit</th>
						</xsl:if>
	        </tr>
      	  <xsl:for-each select="RecentlyViewed/Item/child::*">
      	  	<xsl:if test="self::ArtistContract">
							<xsl:call-template name="artistContractRow" />
						</xsl:if>
    	  		<xsl:if test="self::LabelContract">
							<xsl:call-template name="labelContractRow" />
						</xsl:if>
  	      </xsl:for-each>
	      </table>
			</xsl:if>
      <xsl:if test="not(RecentlyViewed/Item)">
        <p>No contracts exist in your viewing history.</p>
      </xsl:if>
		</div>
  </xsl:template>

	<xsl:template name="artistContractLink">
		<form action="/rps/artist_contract" method="get">
			<input type="hidden" name="c" value="list" />
			
			<xsl:choose>
				<xsl:when test="$payorCount &gt; 1">
				<label for="payorView">Artist/Producer Contracts: </label> 
					<select name="payor" id="payorView">
						<option value="">All Payors</option>
						<xsl:for-each select="PayorList/Payor">
							<option value="{PayorID}"><xsl:value-of select="substring(Name,1,25)" /><xsl:if test="substring(Name,26,1)">...</xsl:if></option>
						</xsl:for-each>
					</select>
					<input type="submit" name="go" value="Go" />
				</xsl:when>
				<xsl:otherwise>
					<a href="/rps/artist_contract?c=list">Artist/Producer Contracts</a>
				</xsl:otherwise>
			</xsl:choose>
			
			<br />
			<span class="subtle">View all artist/producer contracts<xsl:if test="count(PayorList/Payor) &gt; 1"> or contracts for a specific payor</xsl:if>.</span>
		</form>	
	</xsl:template>
	
	<xsl:template name="labelContractLink">
		<form action="/rps/label_contract" method="get">
			<input type="hidden" name="c" value="list" />
			
			<xsl:choose>
				<xsl:when test="$payorCount &gt; 1">
					<label for="payorView">Label Contracts: </label>
					<select name="payor" id="payorView">
						<option value="">All Payors</option>
						<xsl:for-each select="PayorList/Payor">
							<option value="{PayorID}"><xsl:value-of select="substring(Name,1,25)" /><xsl:if test="substring(Name,26,1)">...</xsl:if></option>
						</xsl:for-each>
					</select>
					<input type="submit" name="go" value="Go" />
				</xsl:when>
				<xsl:otherwise>
					<a href="/rps/label_contract?c=list">Label Contracts</a>
				</xsl:otherwise>
			</xsl:choose>
			
			<br />
			<span class="subtle">View all label contracts<xsl:if test="count(PayorList/Payor) &gt; 1"> or contracts for a specific payor</xsl:if>.</span>
		</form>	
	</xsl:template>

</xsl:stylesheet>
