<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:template name="trackerLayout">
    <script src="/test/javascript/validateUpload.js" type="text/javascript"></script>
    <xsl:choose>
      <xsl:when test="$files = 1">
        <xsl:call-template name="trackerChart" />
      </xsl:when>
      <xsl:otherwise>
        <div class="section"><p>Files have not been uploaded for this period.</p></div>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:if test="access/close_period = 1 and period/next_period = '' and $files = 1">
      <form action="#" id="royaltyClose">
	<div class="section">
          <xsl:if test="$filesClosed = ''">
	    <p>At least 1 file must be processed before a period can be closed.</p>
	  </xsl:if>
	  <p>
            <input type="button" value="Close Current Period" onClick="toggleLayer('confirmBox');" id="confirmBoxOpener">
              <xsl:if test="$filesClosed = '' or /Root/Form/RoyaltyRunStatus/CanEdit = 0">
	            <xsl:attribute name="disabled">disabled</xsl:attribute>
	          </xsl:if>
            </input>
	  </p>
        </div>
        <div class="section" id="confirmBox">
          <h2>Are you sure you want to close the current period?</h2>
          <xsl:if test="unprocessed_files != 0">
            <p>There are <strong><xsl:value-of select="unprocessed_files" /></strong> files that still need to be processed.</p>
	  </xsl:if>
	  <table class="buttons">
            <tr>
              <td class="defaultButton"><div class="defaultButtonBG"><input type="submit" value="Yes, close the period" /></div></td>
	      <td><input type="button" value="No, I'm not sure" onclick="toggleLayer('confirmBox');" /></td>
	    </tr>
	  </table>
        </div>
      </form>
    </xsl:if>
    <div>
      <xsl:if test="$files = 1 and access/tracker_upload">
        <xsl:attribute name="class">twoSections</xsl:attribute>
      </xsl:if>
      <xsl:if test="access/tracker_upload = 1">
        <form name="uploadForm" action="/app/tracker" method="post" enctype="multipart/form-data">
  	  <xsl:choose>
	    <xsl:when test="$files = 1">
	      <xsl:attribute name="class">sectionRight</xsl:attribute>
	    </xsl:when>
	    <xsl:otherwise>
              <xsl:attribute name="class">section</xsl:attribute>
	    </xsl:otherwise>
          </xsl:choose>
          <h2>Upload Sales File</h2>
	  <xsl:if test="form/errors = '1'">
            <span id="errorGeneral" class="error">
	      <xsl:for-each select="form/fields/field">
                <xsl:if test="error_type = 'file_upload_unreadable'">
                  Unable to read file.
                </xsl:if>
	        <xsl:if test="error_type = 'file_upload_duplicate'">
	          File has already been uploaded.
	        </xsl:if>
                <xsl:if test="error_type = 'file_upload_invalidtext'">
                  Invalid file type (extension).
                </xsl:if>
                <xsl:if test="error_type = 'file_upload_servererror'">
                  A server error was encountered.  Please try again in a few minutes.
                </xsl:if>
                <xsl:if test="error_type = 'file_upload_noservicematch'">
                  File does not match any known services.  Please contact your account representative.
                </xsl:if>
	      </xsl:for-each>
	    </span>
	  </xsl:if>
          <span id="ERRORfileUpload" class="error"></span>
	  <p>
            <label for="fileUpload">File Name:</label><input type="file" name="fileUpload" id="fileUpload" />
          </p>
          <p>
            <input type="submit" name="submit" id="uploadSubmit" value="Upload" />
          </p>
        </form>
      </xsl:if>
      <xsl:if test="$files = 1">
        <form action="#">
          <xsl:choose>
            <xsl:when test="access/tracker_upload = 1">
              <xsl:attribute name="class">sectionLeft</xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:attribute name="class">section</xsl:attribute>
            </xsl:otherwise>
          </xsl:choose>
          <h2>Download Royalty Data</h2>
          <p>
            <label for="format">Choose format:</label>
            <select name="format" id="format">
              <option>Excel</option>
              <option>Tab Delimited</option>
              <option>XML</option>
            </select>
          </p>
          <p>
            <input type="submit" name="submit" id="downloadSubmit" value="Download" />
          </p>
        </form>
      </xsl:if>
    </div>
  </xsl:template>

  <xsl:template name="manageImportLayout">
    <div class="section">
    <h3>FILENAME Service: SERVICENAME Lines: NUMBER Exceptions: NUMBER</h3>
    <xsl:call-template name="manageImportChart" />
    </div>
    <form class="section" action="/app/manageImport">
      <xsl:call-template name="suggestedAlbumChart" />
      <p>
        <input type="submit" name="Match to Catalog" value="Match to Catalog" />
      </p>
    </form>
    <form class="section" action="/app/manageImport">
      <script src="/test/javascript/validateSearch.js" type="text/javascript"></script>
      <span id="ERRORsearchTerm" class="error"></span>
      <p>
        Search Catalog: <input type="text" name="searchTerm" maxlength="100" /> <input type="submit" name="Go" value="Go" />
      </p>
    </form>
    <div class="section">
      <p>
        <strong>FIELD</strong> contains invalid date.
        <xsl:if test="error/noncorrectable = 1">
        </xsl:if>
      </p>
      <p>
        &#171;<a href="#">Previous</a> <a href="#">Skip</a>&#187;
      </p>
    </div>
  </xsl:template>

  <xsl:template name="streamRevenueLayout">
    <script src="/test/javascript/validateStream.js" type="text/javascript"></script>
    <form class="section" action="javascript:toggleLayer('confirmBox');" name="streamForm">
      <table class="textTable">
	<tr>
	  <td>Filename:</td>
	  <td>FILENAME</td>
        </tr>
        <tr>
          <td>Provider:</td>
          <td>PROVIDER</td>
        </tr>
        <tr>
          <td>Reporting Month:</td>
          <td>MM/YY</td>
        </tr>
        <tr>
          <td>Units:</td>
          <td>NUMBER</td>
        </tr>
      </table>
      <span id="ERRORstreamRevenue" class="error"></span>
      <div id="confirmBoxOpener">
        <p>
          Streaming Revenue for MONTH in USD: <input type="text" name="streamRevenue" />
        </p>
        <table class="buttons">
          <tr>
            <td class="defaultButton"><div class="defaultButtonBG"><input type="submit" value="Update Revenue" onClick="streamConfirm({stream/units})" /></div></td>
            <td><input type="button" value="Cancel" onClick="location.href='/app/tracker'" /></td>
          </tr>
	</table>
      </div>
    </form>
    <form class="section" id="confirmBox">
      <p>
       <span id="streamNumbers"></span>  Update revenue with this amount?
      </p>
      <table class="buttons">
        <tr>
          <td class="defaultButton"><div class="defaultButtonBG"><input type="submit" value="Update" /></div></td>
          <td><input type="button" onClick="toggleLayer('confirmBox');" value="Cancel" /></td>
        </tr>
      </table>
    </form>
  </xsl:template>

  <xsl:template name="finishImportLayout">
    <xsl:choose>
    <xsl:when test="normalize-space(success)">
      <div class="section">
      <xsl:choose>
        <xsl:when test="normalize-space(split)">
          <p>FILENAME split successfully!</p>
          <p>
            FILENAME-a.xls contains the clean sales records.<br />
            FILENAME-b.xls contains the faulty sales records.
          </p>
        </xsl:when>
        <xsl:otherwise>
          <p>FILENAME imported and processed successfully!</p>
        </xsl:otherwise>
      </xsl:choose>
        <p><a href="/app/tracker">Return to Status Tracker</a></p>
      </div>
    </xsl:when>
    <xsl:otherwise>
    <div class="section">
      <table class="textTable">
        <tr>
          <td>Filename:</td>
          <td>FILENAME</td>
        </tr>
        <tr>
          <td>Provider:</td>
          <td>PROVIDER</td>
        </tr>
        <tr>
          <td>Received:</td>
          <td>MM/DD/YY</td>
        </tr>
        <tr>
          <td>Units:</td>
          <td>NUMBER</td>
        </tr>
        <tr>
          <td>Revenu:</td>
          <td>$AMOUNT</td>
        </tr>
        <tr>
          <td>Errors:</td>
          <td><xsl:value-of select="import/errors" /></td>
        </tr>
      </table>
      <span id="ERRORstreamRevenue" class="error"></span>
      <div id="confirmBoxOpener">
        <table class="buttons">
          <tr>
            <td class="defaultButton">
	      <div class="defaultButtonBG">
		<input type="submit" value="Finish Import">
                  <xsl:if test="import/errors > 0">
                    <xsl:attribute name="onclick">toggleLayer('confirmBox');</xsl:attribute>
	          </xsl:if>
	        </input>
	      </div>
	    </td>
          </tr>
        </table>
      </div>
    </div>
    <form class="section" id="confirmBox">
      <p>
        Are you sure you want to split FILENAME?
      </p>
      <p>
        Splitting a file divides it into 2 separate files, one containing all the records with errors and the other containing the records without errors.
      </p>
      <table class="buttons">
        <tr>
          <td class="defaultButton"><div class="defaultButtonBG"><input type="submit" value="Split" /></div></td>
          <td><input type="button" onClick="toggleLayer('confirmBox');" value="Cancel" /></td>
        </tr>
      </table>
    </form>
    </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
