<!--                                                                  -->
<!--  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="lockedRecord">
    <xsl:choose>
      <xsl:when test="/Root/Form/LabelContract/Status = 2">1</xsl:when>
      <xsl:when test="/Root/Form/LabelContract/Status = 3">1</xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose> 
  </xsl:variable>

  <xsl:template name="contractShowLayout">
    <xsl:call-template name="contractShow" />
    <xsl:call-template name="buttons" />
    <xsl:call-template name="hiddenFields" />
  </xsl:template>

  <xsl:template name="contractShow">
    <script type="text/javascript" src="/production/javascript/validate/labelContract.js?v=11" />  
    <link href="/production/css/rps/label_contract.css?v=1" media="screen" rel="stylesheet" type="text/css" />
    <div class="section" id="contractShow">
      <xsl:call-template name="openRunStatusMessage" />
      <xsl:call-template name="successMessageGeneral">
        <xsl:with-param name="successMessage">Contract successfully updated!</xsl:with-param>
      </xsl:call-template>
      <div id="mainContractSection">
        <xsl:call-template name="labelContractView" />
      </div>
      <br />
      
      <xsl:for-each select="Form/LabelContract/GroupTermList/GroupTerm"> 
        <xsl:sort select="LabelContractGroupTermID" data-type="number" />
        <div id="groupTerm{LabelContractGroupTermID}Section">
            <xsl:call-template name="termView">
                <xsl:with-param name="term" select="." />
            </xsl:call-template>
        </div>
        <br />
      </xsl:for-each>
      
      <xsl:if test="$openRuns = 0">
          <div id="addGroupTerm">
            <a href="javascript:void(-1)" onClick="addGroupTerm({/Root/Params/LabelContractID})">Add Another Set of Terms...</a>
          </div>
      </xsl:if>      
      
      <br class="superBreak" />
      <br />
    </div>
  </xsl:template>
  
  <xsl:template name="labelContractView">
    <fieldset id="contractView">
      <legend>Contract</legend>    
        <table class="textChart">
          <tbody>
            <tr>
              <th>Contract Title</th>
              <th>Contract ID</th>
              <th>Payor</th>
              <th>Payee</th>
              <th>Issue Date</th>
            </tr>
            <tr class="row1">
              <td><xsl:value-of select="Form/LabelContract/Title" /></td>
              <td><xsl:value-of select="Form/LabelContract/ClientContractID" /></td>
		      <td>
			    <xsl:value-of select="Form/PayorList/Payor[PayorID = /Root/Form/LabelContract/PayorID]/Name" />
			  </td>
              <td>      
              	<a href="/rps/label_payee?LabelPayeeID={Form/LabelContract/LabelPayeeID}&amp;c=show">
              		<xsl:value-of select="Form/LabelContract/LabelPayeeName" />
              	</a>
              </td>
              <td><xsl:value-of select="Form/LabelContract/IssueDate" /></td>
            </tr>
            <tr>
                <td colspan="5" class="right">
                    <xsl:call-template name="lastModifiedCell" />
                    <xsl:if test="$openRuns = 0">
                        <input type="button" value="Edit Contract" onClick="editContractAjax({Params/LabelContractID},'mainContractSection'); return false;" class="bottomButton" />
                    </xsl:if>
                </td>
            </tr>
          </tbody>
        </table>
    </fieldset>
  </xsl:template>  

  <xsl:template name="lastModifiedCell">
    <b>Last Modified:</b>&#160;<xsl:value-of select="Form/LabelContract/ModifiedDate" /><xsl:if test="normalize-space(Form/LabelContract/ModifiedBy)"> by <xsl:value-of select="Form/LabelContract/ModifiedBy" /></xsl:if>
  </xsl:template>


    <xsl:template name="termView">
        <xsl:param name="term" select="Form/GroupTerm" />
        <fieldset class="contractTerms" id="fieldSet{$term/LabelContractGroupTermID}">
            <script type="text/javascript">
                $("#fieldSet<xsl:value-of select="$term/LabelContractGroupTermID" />").parent().attr('id','groupTerm<xsl:value-of select="$term/LabelContractGroupTermID" />Section'); 
            </script>
            <legend>Contract Terms</legend>
            
            <xsl:if test="$term/GroupTermLabelList/GroupTermLabel/LabelContractGroupTermLabelID">
                <table class="textChart labelTable">
                    <tbody>
                        <xsl:for-each select="$term/GroupTermLabelList/GroupTermLabel">
                            <xsl:sort select="LabelName" />
                            <xsl:call-template name="labelRowView" />
                        </xsl:for-each>
                    </tbody>
                </table>
            </xsl:if>
            
            <xsl:if test="not($term/GroupTermLabelList/GroupTermLabel/LabelContractGroupTermLabelID)">
                <br />
                No labels have been associated with this set of terms.<br /><br />
            </xsl:if>            
            
            <xsl:if test="$term/DistributionFee">
                <br class="superBreak" />
                <table class="textChart termTable">
                    <tbody>
                        <tr>
                            <th>Service</th>
                            <th>Country</th>
                            <th>Distribution Fee</th>
                        </tr>
                        <tr class="row1">
                            <td>All</td>
                            <td>All</td>
                            <td><xsl:value-of select="$term/DistributionFee" />%</td>
                        </tr>
                    </tbody>
                </table>
                <xsl:if test="$term/GroupTermExceptionList/GroupTermException/LabelContractGroupTermExceptionID">

	                <div style="font-weight: bold; margin-left: 5px; text-align: left">Except...</div>
	                <hr />                
       
                    <table class="textChart exceptionTable">
                        <tbody>                                      
                            <xsl:for-each select="$term/GroupTermExceptionList/GroupTermException">
                                <xsl:call-template name="exceptionRowView" />
                            </xsl:for-each>                                                       
                        </tbody>
                    </table>      
                </xsl:if>          
            </xsl:if>
            
            <br />
            
            <xsl:if test="$openRuns = 0">
                <div class="singleButton">
                    <input type="button" name="editTerms" value="Edit Terms" onClick="editTermAjax('{$term/LabelContractGroupTermID}','groupTerm{$term/LabelContractGroupTermID}Section'); return false;"  />
                    <input type="button" name="deleteTerms" value="Delete Terms" onClick="confirmDeleteTerm('{$term/LabelContractGroupTermID}','groupTerm{$term/LabelContractGroupTermID}Section'); return false;"  />
                </div>
            </xsl:if>

        </fieldset>
    </xsl:template>

    <xsl:template name="labelRowView">
        <xsl:variable name="termPosition" select="position() - 1" />
        <tr class="row{position() mod 2}" id="label{position()}">
            <td>
                <xsl:value-of select="LabelName" />
            </td>
            <td class="viewCol">
                <a href="/rps/catalog?c=list&amp;label={LabelID}">View Albums</a>
            </td>
        </tr>
    </xsl:template>
    
    <xsl:template name="exceptionRowView">
        <xsl:variable name="termPosition" select="position() - 1" />
        <tr class="row{position() mod 2}" id="exception{position()}">
            <td>
                <xsl:value-of select="ServiceName" />
            </td>
            <td>
                <xsl:value-of select="CountryName" />
            </td>
            <td>
                <xsl:value-of select="DistributionFee" />%
            </td>
        </tr>
    </xsl:template>    

</xsl:stylesheet>
