<!--                                                                  -->
<!--  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="searchItem" select="/Root/Contract" />

  <xsl:template name="contractSearchLayout">
    <xsl:choose>
      <xsl:when test="Params/_inline">
        <xsl:call-template name="searchFormInline" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="searchResults" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="searchResults">
    <div class="section">
      <xsl:if test="not(Params/_inline)">
        <xsl:attribute name="id">contractSearchFull</xsl:attribute>
      </xsl:if>
			<xsl:choose>
	      <xsl:when test="not(Params/Query) and count(Contract) = 0">
  	      <p>No contracts have been created.</p>
    	  </xsl:when>
				<xsl:otherwise>
					<xsl:call-template name="resultsList" />
				</xsl:otherwise>
			</xsl:choose>
		</div>
    <xsl:if test="(Params/AlbumID or Params/TrackID) and count(Contract) &gt; 0 and Params/Query">
      <xsl:call-template name="buttons" />
    </xsl:if>
	</xsl:template>

	<xsl:template name="resultsList">
    <xsl:if test="Params/Query">
      <h2>Search Results</h2>
    </xsl:if>
    <xsl:call-template name="searchNav" />
    <xsl:call-template name="searchText" />
    <xsl:if test="count($searchItem) != 0">
      <xsl:call-template name="resultsHeader" />
      <div>
        <xsl:if test="Params/_inline and count(Contract) &gt; 9">
          <xsl:attribute name="class">scrollPop</xsl:attribute>
        </xsl:if>
        <xsl:call-template name="contractListTable" />
      </div>
    </xsl:if>
    <xsl:call-template name="searchNav" />
		<xsl:if test="normalize-space(Pagination/Previous) or normalize-space(Pagination/Next)">
	    <br class="superBreak" />
			<br />
		</xsl:if>
  </xsl:template>

  <xsl:template name="contractListTable">
    <table>
      <xsl:attribute name="class">
        <xsl:if test="Params/_inline">textChart textChartBottom textChartResults</xsl:if>
        <xsl:if test="not(Params/_inline)">
          textChart hiOn textChartResults
        </xsl:if>
      </xsl:attribute>
      <xsl:for-each select="$searchItem">
        <xsl:call-template name="contractListTableRow" />   
      </xsl:for-each>
    </table>
  </xsl:template>

  <xsl:template name="contractListTableRow">
    <tr>
      <xsl:variable name="contractID" select="ArtistContractID" />
      <xsl:variable name="disableContract">
        <xsl:for-each select="/Root/AlbumContractList/AlbumContract">
          <xsl:if test="ContractID = $contractID">1</xsl:if>
        </xsl:for-each>
        <xsl:for-each select="/Root/TrackContractList/TrackContract">
          <xsl:if test="ContractID = $contractID">1</xsl:if>
        </xsl:for-each>
      </xsl:variable>
      <xsl:attribute name="class">
        row<xsl:value-of select="position() mod 2" /><xsl:text> </xsl:text><xsl:if test="position() = 1">firstRow</xsl:if><xsl:text> </xsl:text><xsl:if test="$disableContract = 1">disabledRow</xsl:if>
      </xsl:attribute>
      <xsl:if test="/Root/Params/AlbumID or /Root/Params/TrackID">
        <td class="rowLeft selectCol">
          <input type="radio" name="ArtistContractID" value="{ArtistContractID}" onClick="modifyField('selectMatch','enable'); modifyFieldValue('ContractID',this.value);">
            <xsl:if test="$disableContract = 1">
               <xsl:attribute name="disabled">disabled</xsl:attribute>
            </xsl:if>
          </input>
        </td>
      </xsl:if>
      <td class="titleCol">
        <xsl:if test="not(/Root/Params/AlbumID or /Root/Params/TrackID)">
          <xsl:attribute name="class">rowLeft left</xsl:attribute>
        </xsl:if>
				<xsl:choose>
					<xsl:when test="not(/Root/Params/AlbumID or /Root/Params/TrackID)">
        		<a href="contract?ContractID={ArtistContractID}&amp;c=show"><xsl:value-of select="Title" /></a>
        	</xsl:when>
					<xsl:otherwise>
          	<xsl:value-of select="Title" />
					</xsl:otherwise>
				</xsl:choose>
      </td>
			<td class="artistCol"><xsl:value-of select="ArtistDescription" /></td>
			<td class="contractIDCol"><xsl:value-of select="ClientContractID" /></td>
			<xsl:if test="not(/Root/Params/_inline)">
				<xsl:variable name="payorID" select="PayorID" />
				<td class="artistCol"><xsl:value-of select="/Root/PayorList/Payor[PayorID = $payorID]/Name" /></td>
    	  <td class="artistCol"><xsl:value-of select="ArtistPayee/Name" /></td>
			</xsl:if>
      <xsl:if test="not(/Root/Params/AlbumID or /Root/Params/TrackID) and /Root/Access/rps/contract/edit = 1">
        <td class="editCol icon">
          <a href="contract?c=edit&amp;ContractID={ArtistContractID}" title="Edit">
            <img src="/production/images/icons/office/Edit-(16x16).gif" />
          </a>
        </td>
      </xsl:if>
    </tr>
  </xsl:template>

  <xsl:template name="resultsHeader">
    <table class="textChart" id="resultsHeader">
      <tr>
        <xsl:if test="Params/_inline">
          <xsl:attribute name="class">textChartTop</xsl:attribute>
          <th class="rowLeft selectCol">Select</th>
        </xsl:if>
        <th class="titleCol">
          <xsl:if test="not(Params/_inline)">
            <xsl:attribute name="class">rowLeft</xsl:attribute>
          </xsl:if>
          Contract Title
        </th>
				<th class="artistCol">Artist</th>
        <th class="contractIDCol">Contract ID</th>
				<xsl:if test="not(Params/_inline)">
  	      <th class="artistCol">Payor</th>
					<th class="artistCol">Payee</th>
				</xsl:if>
        <xsl:if test="Params/_inline and count(Contract) &gt; 9">
          <th class="scrollCol"></th>
        </xsl:if>
        <xsl:if test="not(Params/_inline) and /Root/Access/rps/contract/edit = 1">
          <th class="editCol">Edit</th>
        </xsl:if>
      </tr>
    </table>
  </xsl:template>

</xsl:stylesheet>
