<!--                                                                  -->
<!--  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/global.xsl" />
  <xsl:include href="edit.xsl" />
  <xsl:include href="show.xsl" />
  <xsl:include href="search.xsl" />
  <xsl:include href="region.xsl" />
  <xsl:include href="deduction.xsl" />
  <xsl:include href="unit_escalation.xsl" />
  <xsl:include href="expense.xsl" />
	<xsl:include href="main.xsl" />
	<xsl:include href="list.xsl" />
	<xsl:include href="license_income.xsl" />

	<xsl:variable name="contractHome">
		<xsl:choose>
			<xsl:when test="/Root/Access/rps/label_contract/main">contract</xsl:when>
			<xsl:otherwise>artist_contract</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>

  <xsl:template name="pickLayout">
    <xsl:choose>
      <xsl:when test="$cmd = 'edit'">
        <xsl:call-template name="contractEditLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'show'">
        <xsl:call-template name="contractShowLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'term'">
        <xsl:call-template name="termLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'region'">
        <xsl:call-template name="regionLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'deduction'">
        <xsl:call-template name="deductionLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'unit_escalation'">
        <xsl:call-template name="unitEscalationLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'expense'">
        <xsl:call-template name="expenseTypeLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'license_income'">
        <xsl:call-template name="licenseIncomeLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'main'">
        <xsl:call-template name="contractMainLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'list'">
        <xsl:call-template name="contractListLayout" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="contractSearchLayout" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="submitButton">
    <xsl:choose>
      <xsl:when test="$cmd = 'edit'">
        <input name="submit" type="submit" id="submitButton">
          <xsl:attribute name="value">
          	<xsl:choose>
            	<xsl:when test="normalize-space(Form/ArtistContract/ArtistContractID) and not(Params/copy)">Update</xsl:when>
            	<xsl:otherwise>Create</xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
          <xsl:if test="$openRuns = 1">
            <xsl:attribute name="disabled">disabled</xsl:attribute>
          </xsl:if>
        </input>
      </xsl:when>
      <xsl:when test="$cmd = 'show'">
        <input type="button" value="Edit Contract" onClick="javascript:location.href='artist_contract?ArtistContractID={Form/ArtistContract/ArtistContractID}&amp;c=edit'">
          <xsl:if test="$lockedRecord = 1">
            <xsl:attribute name="disabled">disabled</xsl:attribute>
          </xsl:if>
        </input>
      </xsl:when>
      <xsl:when test="$cmd = 'term' or $cmd = 'region' or $cmd = 'deduction' or $cmd = 'unit_escalation' or $cmd = 'expense' or $cmd = 'license_income'">
        <input name="submitForm" type="submit" id="submitButton" value="Update" >
          <xsl:if test="$openRuns = 1">
            <xsl:attribute name="disabled">disabled</xsl:attribute>
          </xsl:if>
	    </input>
      </xsl:when>
      <xsl:otherwise>
        <input type="hidden" name="ArtistContractID" id="ContractID" />
        <input type="button" name="selectMatch" id="selectMatch" value="Use this Contract" disabled="true">
          <xsl:attribute name="onClick">
            <xsl:if test="Params/AlbumID">attachContract('catalog',<xsl:value-of select="Params/AlbumID" />); modifyField('selectMatch','disable');</xsl:if>
            <xsl:if test="Params/TrackID">attachContract('track',<xsl:value-of select="Params/TrackID" />); modifyField('selectMatch','disable');</xsl:if>
          </xsl:attribute>
        </input>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="cancelButton">
    <xsl:choose>
      <xsl:when test="$cmd = 'edit' and Params/_inline">
        <input type="button" value="Cancel" onClick="hideInlinePop()" />
      </xsl:when>
      <xsl:when test="$cmd = 'edit' and not(Params/_inline)">
        <xsl:if test="Params/ArtistContractID">
        <input type="button" value="Return to Contract" onClick="location.href='artist_contract?ArtistContractID={Params/ArtistContractID}&amp;c=show'" />
        </xsl:if>
        <xsl:if test="not(Params/ArtistContractID)">
        <input type="button" value="Back to Contracts" onClick="location.href='{$contractHome}'" />
        </xsl:if>
      </xsl:when>
      <xsl:when test="$cmd = 'term' or $cmd = 'region' or $cmd = 'deduction' or $cmd = 'unit_escalation' or $cmd = 'expense' or $cmd = 'license_income'">
        <input type="button" name="Back" value="Return to Contract" onClick="location.href='artist_contract?ArtistContractID={Form/ArtistContract/ArtistContractID}&amp;c=show'" />
      </xsl:when>
      <xsl:when test="$cmd = 'show'">
      	<input type="button" value="Copy Contract" onClick="location.href='artist_contract?copy=1&amp;ArtistContractID={Form/ArtistContract/ArtistContractID}&amp;c=edit'" />
        <input type="button" value="Back to Contracts" onClick="location.href='{$contractHome}'" />
      </xsl:when>
      <xsl:when test="$cmd = 'search' and Params/_inline">
        <input type="button" name="Cancel" value="Cancel" onClick="hideInlinePop()" />
      </xsl:when>
      <xsl:otherwise>
        <input type="button" name="Cancel" value="Return to Album" onClick="location.href='catalog?AlbumID={Params/AlbumID}&amp;c=show'" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>


</xsl:stylesheet>
