<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<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="presubmit.xsl" />
  <xsl:include href="../shared_layouts/advance.xsl" />
  <xsl:include href="../shared_layouts/expense.xsl" />
  <xsl:include href="../shared_layouts/expense_edit.xsl" />

  <xsl:variable name="contractName">TrackContractID</xsl:variable>
  <xsl:variable name="contractID"><xsl:value-of select="/Root/Params/TrackContractID" /></xsl:variable>

  <xsl:template name="pickLayout">
    <xsl:choose>
      <xsl:when test="$cmd = 'presubmit'">
        <xsl:call-template name="trackPresubmitLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'show'">
        <xsl:call-template name="trackShowLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'advance'">
        <xsl:call-template name="advanceLayout" />
      </xsl:when>
     <xsl:when test="$cmd = 'expense'">
        <xsl:call-template name="expenseLayout" />
      </xsl:when>
      <xsl:when test="$cmd = 'expense_edit'">
        <xsl:call-template name="expenseEditLayout" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="trackEditLayout" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="submitButton">
    <xsl:choose>
      <xsl:when test="$cmd = 'advance'">
        <input name="submit" type="submit" id="submitButton">
          <xsl:attribute name="value">
            <xsl:if test="normalize-space(//AdvanceAccount/AccountID)">Update</xsl:if>
            <xsl:if test="not(normalize-space(//AdvanceAccount/AccountID))">Create</xsl:if>
          </xsl:attribute>
        </input>
      </xsl:when>
      <xsl:when test="$cmd = 'expense_edit'">
        <input name="submit" type="submit" id="submitButton">
          <xsl:if test="$openRuns = 1">
            <xsl:attribute name="disabled">disabled</xsl:attribute>
          </xsl:if>
          <xsl:attribute name="value">
            <xsl:if test="normalize-space(Form/Expense/ExpenseID)">Update</xsl:if>
            <xsl:if test="not(normalize-space(Form/Expense/ExpenseID))">Create</xsl:if>
          </xsl:attribute>
          <xsl:if test="$openRuns = 1 or ((Form/DefaultTerm = 1 or Form/DefaultTerm = 3) and (/Root/Params/PreProcess = 1 or Form/Expense/PreProcess = 1))">
            <xsl:attribute name="disabled">disabled</xsl:attribute>
          </xsl:if>          
        </input>
      </xsl:when>
     <xsl:when test="$cmd = 'expense' or not(Access/rps/track/edit)">
        <xsl:attribute name="class" />
      </xsl:when>
      <xsl:otherwise>
        <input name="submitButton" type="submit" id="submitButton">
          <xsl:choose>
            <xsl:when test="$cmd = 'show'">
              <xsl:attribute name="value">Edit Track</xsl:attribute>
              <xsl:attribute name="onClick">location.href='track?c=edit&amp;TrackID=<xsl:value-of select="Form/Track/TrackID" />'</xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:attribute name="value">
                <xsl:if test="normalize-space(Form/Track/TrackID)">Update</xsl:if>
                <xsl:if test="not(normalize-space(Form/Track/TrackID))">Create</xsl:if>
              </xsl:attribute>
              <xsl:if test="$openRuns = 1">
                <xsl:attribute name="disabled">disabled</xsl:attribute>
              </xsl:if>
            </xsl:otherwise>
          </xsl:choose>
        </input>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="cancelButton">
    <xsl:choose>
      <xsl:when test="$cmd = 'advance' or $cmd = 'expense'">
        <input type="button" name="Back" value="Return to Contract" onClick="location.href='artist_contract?ArtistContractID={Form/TrackContract/ContractID}&amp;c=show'" />
      </xsl:when>
      <xsl:when test="$cmd = 'expense_edit'">
        <xsl:if test="normalize-space(Form/Expense/ExpenseID)">
          <input type="button" name="Delete" value="Delete" onClick="confirmDeleteExpense({Form/Expense/ExpenseID},'track','{$pageName}')" />
        </xsl:if>
        <input type="button" name="Back" value="Return to Expense List" onClick="location.href='?TrackContractID={Params/TrackContractID}&amp;c=expense'" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:if test="$cmd = 'edit' and normalize-space(Form/Track/TrackID)">
          <input name="deleteButton" type="button" value="Delete" onClick="confirmDeleteTrack({Form/Track/TrackID},'{$editMaster}','{$editSong}')">
          <xsl:if test="Form/Track/LinkedLicenses &gt; 0 or Form/Track/LinkedContracts &gt; 0 or $openRuns = 1">
            <xsl:attribute name="disabled">disabled</xsl:attribute>
          </xsl:if>
          </input>
          <xsl:if test="Form/Track/LinkedLicenses &gt; 0 or Form/Track/LinkedContracts &gt; 0">
            <xsl:choose>
              <xsl:when test="Form/Track/LinkedLicenses &gt; 0 and Form/Track/LinkedContracts &gt; 0">
                <xsl:call-template name="helpIcon">
                  <xsl:with-param name="tip">This track has a license and contract associated with it and cannot be deleted.</xsl:with-param>
                </xsl:call-template>
              </xsl:when>
              <xsl:when test="Form/Track/LinkedLicenses &gt; 0">
                <xsl:call-template name="helpIcon">
                  <xsl:with-param name="tip">This track has a license associated with it and cannot be deleted.</xsl:with-param>
                </xsl:call-template>
              </xsl:when>
              <xsl:otherwise>
                <xsl:call-template name="helpIcon">
                  <xsl:with-param name="tip">This track has a contract associated with it and cannot be deleted.</xsl:with-param>
                </xsl:call-template>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
        </xsl:if>
        <xsl:if test="not(normalize-space(Form/Track/TrackID))">
          <input name="submitButton" type="submit" id="addAnotherButton" value="Create and Add Another" onClick="modifyFieldValue('ReturnTo','track?AlbumID={Params/AlbumID}&amp;c=edit&amp;msg=success|form_submit_success')">
              <xsl:if test="$openRuns = 1">
                <xsl:attribute name="disabled">disabled</xsl:attribute>
              </xsl:if>
          </input>
        </xsl:if>
        <input type="button" name="Cancel" value="Return to Album" onClick="location.href='catalog?AlbumID={Form/Album/AlbumID}&amp;c=show'" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
