<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="html" encoding="utf-8" />

  <xsl:template match="Root">
    <html>
      <head>
        <meta http-equiv="Pragma" content="no-cache" />
        <meta http-equiv="Cache-Control" content="no-cache" />
        <meta http-equiv="Expires" content="0" />
        <title>RoyaltyShare - <xsl:value-of select="$pageName" /></title>
        <link rel="stylesheet" type="text/css" media="all" href="/production/css/main.css?v=2" />
        <script type="text/javascript" src="/production/javascript/main.js?v=2"></script>
      </head>
      <body>
	<div class="minwidth">
	  <div class="container">
	    <div id="logo"></div>
            <xsl:if test="$action = 'login' or $action = 'forgotpw'">
              <div id="loginTop">&#160;</div>
            </xsl:if>
            <xsl:if test="$action != 'login' and $action != 'forgotpw'">
	      <div id="logout">
                Welcome, <strong><xsl:value-of select="User/FirstName" /></strong> |
                <a>
                  <xsl:attribute name="href">
                  /app/profile<xsl:if test="/Root/App != 'changepw' and /Root/App != 'profile'">?url=<xsl:value-of select="/Root/App"/>%3F<xsl:value-of select="$currentParamListClean"/></xsl:if>
                  </xsl:attribute>
                  Profile</a> | <a href="/app/logout">Log Out</a>
              </div>
              <xsl:call-template name="navigation" />
	    </xsl:if>
  	    <div id="content">
              <xsl:if test="$action = 'm'">
                <xsl:call-template name="greeting" />
              </xsl:if>
              <xsl:call-template name="sectionHeader" />
              <div class="sectionWrap">
              <div class="sectionBody">
	          <xsl:if test="$action != 'login' and $action != 'forgotpw'">
                    <xsl:if test="$view != 'a' and $view != 'k'">
	              <h2><xsl:value-of select="$pageName" /></h2>
                    </xsl:if>
		  </xsl:if>
                  <xsl:choose>
                    <xsl:when test="AccessDenied = 1">
                      <span class="error">You do not have access to this area.</span>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:call-template name="whichLayout" />
                    </xsl:otherwise>
                  </xsl:choose>
                  <div class="hack">&#160;</div>
	        </div>
	      </div>
	      <xsl:if test="$view = '' and $action = 'reports'">
                <xsl:for-each select="Tables/Table[TableName = 'file_summary']">
	          <xsl:call-template name="statusChart" />
                </xsl:for-each>
	      </xsl:if>
 	    </div>
            <xsl:call-template name="footer" />
          </div>
        </div>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="navLinkOptions">
    <xsl:if test="$labelID != ''">&amp;label=<xsl:value-of select="$labelID" /></xsl:if><xsl:if test="$view != ''">&amp;view=<xsl:value-of select="$view" /></xsl:if><xsl:if test="normalize-space(Params/product)">&amp;product=<xsl:value-of select="Params/product" /></xsl:if><xsl:if test="normalize-space(Params/service)">&amp;service=<xsl:value-of select="Params/service" /></xsl:if><xsl:if test="normalize-space(Params/format)">&amp;format=<xsl:value-of select="Params/format" /></xsl:if>
  </xsl:template>

  <xsl:template name="sectionHeader">
    <div class="sectionHeader">
      <xsl:choose>
        <xsl:when test="Params/cmd = 'edit_period' and not(Params/sub_cmd)"></xsl:when>
        <xsl:when test="$action = 'login'">
          <h1>
            <script language="JavaScript">
              if (client == "ked") {
                document.write("Welcome B2B User");
              } else if (client == "demoada") {
                document.write("ADA Members Login");
              } else if (client == "lmmg") {
                document.write("Lumberjack Mordam Members Login");
              } else {
                document.write("Welcome to RoyaltyShare");
              }
            </script>
          </h1>
        </xsl:when>
        <xsl:when test="$action = 'forgotpw'">
          <h1><xsl:value-of select="$pageName" /></h1>
        </xsl:when>
        <xsl:otherwise>
          <div class="navPrev">
            <xsl:choose>
              <xsl:when test="normalize-space(Period/PrevPeriodID)">
                &#171;
                <a>
                  <xsl:choose>
                    <xsl:when test="$action = 'reports'">
                      <xsl:call-template name="argsLink">
                        <xsl:with-param name="baseURL">?period=<xsl:value-of select="Period/PrevPeriodID" /></xsl:with-param>
                        <xsl:with-param name="skip">period</xsl:with-param>
                      </xsl:call-template>
                      Previous <xsl:call-template name="periodName" />
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:attribute name="href">
                        ?period=<xsl:value-of select="Period/PrevPeriodID" /><xsl:call-template name="navLinkOptions" />
                      </xsl:attribute>
                      Previous Period
                    </xsl:otherwise>
                  </xsl:choose>
                </a>
              </xsl:when>
              <xsl:when test="normalize-space(Pages/PrevPage)">
                &#171;
                <a>
                  <xsl:attribute name="href">
                    ?page=<xsl:value-of select="Pages/PrevPage" /><xsl:if test="normalize-space(Params/search)">&amp;search=<xsl:value-of select="Params/search" /></xsl:if>
                    </xsl:attribute>
                  Previous
                </a>
              </xsl:when>
              <xsl:otherwise>
                &#160;
              </xsl:otherwise>
            </xsl:choose>
          </div>
          <div class="navNext">
            <xsl:choose>
              <xsl:when test="normalize-space(Period/NextPeriodID)">
                <a>
                  <xsl:choose>
                    <xsl:when test="$action = 'reports'">
                      <xsl:call-template name="argsLink">
                        <xsl:with-param name="baseURL">?period=<xsl:value-of select="Period/NextPeriodID" /></xsl:with-param>
                        <xsl:with-param name="skip">period</xsl:with-param>
                      </xsl:call-template>
                      Next <xsl:call-template name="periodName" />
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:attribute name="href">
                        ?period=<xsl:value-of select="Period/NextPeriodID" /><xsl:call-template name="navLinkOptions" />
                      </xsl:attribute>
                      Next Period</xsl:otherwise>
                  </xsl:choose>
                </a> &#187;
              </xsl:when>
              <xsl:when test="normalize-space(Pages/NextPage)">
                <a>
                  <xsl:attribute name="href">
                    ?page=<xsl:value-of select="Pages/NextPage" /><xsl:if test="normalize-space(Params/search)">&amp;search=<xsl:value-of select="Params/search" /></xsl:if>
                  </xsl:attribute>
                  Next</a> &#187;
              </xsl:when>
              <xsl:otherwise>
                &#160;
              </xsl:otherwise>
            </xsl:choose>
          </div>
          <h1>
            <xsl:if test="Pages/CurrentPage">
            Page <xsl:value-of select="Pages/CurrentPage" /> of <xsl:value-of select="Pages/TotalPages" />
            </xsl:if>
            <xsl:if test="normalize-space(Period/StartDateDisp/Month) or normalize-space(dates/quarter)">
              <xsl:if test="$tab = 'sales'">
                <xsl:choose>
                  <xsl:when test="$periodType = 'm'">
                    <xsl:value-of select="Period/StartDateDisp/Month" />&#160;<xsl:value-of select="Period/StartDateDisp/Year" />&#160;(Q<xsl:value-of select="Period/Quarter" />)
                  </xsl:when>
                  <xsl:when test="$periodType = 'q'">
                    Q<xsl:value-of select="Period/Quarter" />&#160;<xsl:value-of select="Period/StartDateDisp/Year" /> (<xsl:value-of select="Period/StartDateDisp/Month" />-<xsl:value-of select="Period/EndDateDisp/Month" />)
                  </xsl:when>
                  <xsl:otherwise>
                    <xsl:value-of select="Period/StartDateDisp/Year" /> (<xsl:value-of select="Period/StartDateDisp/Month" />-<xsl:value-of select="Period/EndDateDisp/Month" />)
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:if>
              <xsl:if test="$tab = 'royalties'">
                <xsl:choose>
                  <xsl:when test="Period/Name != ''">
                    <xsl:value-of select="Period/Name" />
                    <xsl:if test="Period/PeriodID = 0"> (Current)</xsl:if>
                  </xsl:when>
	              <xsl:otherwise>
                    <xsl:value-of select="Period/StartDateDisp/Month" />&#160;<xsl:value-of select="Period/StartDateDisp/Day" />, <xsl:value-of select="Period/StartDateDisp/Year" /> -
                    <xsl:choose>
	                  <xsl:when test="normalize-space(Period/NextPeriodID)">
	                    <xsl:value-of select="Period/EndDateDisp/Month" />&#160;<xsl:value-of select="Period/EndDateDisp/Day" />, <xsl:value-of select="Period/EndDateDisp/Year" />
                      </xsl:when>
	                  <xsl:otherwise>
	                  Present (Current)
	                  </xsl:otherwise>
                    </xsl:choose>
	              </xsl:otherwise>
                </xsl:choose>
                <xsl:if test="User/AccessLevel &lt; 3">
                  &#160; <a href="/app/tracker?cmd=edit_period&amp;period={Period/PeriodID}"><img src="/production/images/icons/mini/edit.gif" alt="edit period name" /></a>
                </xsl:if>
              </xsl:if>
            </xsl:if>
	  </h1>
        </xsl:otherwise>
      </xsl:choose>
    </div>
  </xsl:template>

  <xsl:template name="messages">
    <span id="messages">
        <xsl:for-each select="Messages/Message">
            <xsl:if test="Type = 'success'">
                <xsl:call-template name="uiWarning">
                    <xsl:with-param name="type" select="'success'" />
                    <xsl:with-param name="description">
                        <xsl:if test="Code = 'file_deleted'">
                            File "<strong><xsl:value-of select="/Root/DeletedFile" /></strong>" successfully deleted!
                        </xsl:if>
                        <xsl:if test="Code = 'FileUploadSuccess'">
                            File "<strong><xsl:value-of select="/Root/Params/FileUploadName" /></strong>" uploaded successfully!
                        </xsl:if>
                        <xsl:if test="Code = 'user_saved'">
                            <xsl:if test="$action = 'user_edit'">
                                User <strong><xsl:value-of select="/Root/Params/Email" /></strong><xsl:if test="string(/Root/Params/user)"> saved</xsl:if><xsl:if test="/Root/Params/user = ''"> added</xsl:if>!
                            </xsl:if>
                            <xsl:if test="$action = 'profile'">Profile updated!</xsl:if>
                        </xsl:if>
                        <xsl:if test="Code = 'password_changed'">Password successfully <xsl:if test="not(/Root/Params/new)">changed</xsl:if><xsl:if test="/Root/Params/new">saved</xsl:if>!</xsl:if>
                        <xsl:if test="Code = 'notes_edited'">File notes were updated</xsl:if>
                        <xsl:if test="Code = 'period_edited'">Period name was updated</xsl:if>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:if>
            <xsl:if test="Type = 'error'">
                <xsl:call-template name="uiWarning">
                    <xsl:with-param name="type" select="'error'" />
                    <xsl:with-param name="description">
                        <xsl:if test="Code = 'unmatch_failed'">
                            Unable to undo this match.  The match is being used in a closed file.
                        </xsl:if>
                        <xsl:if test="Code = 'no_matches'">
                            <xsl:choose>
                                <xsl:when test="normalize-space(/Root/Params/search)">
                                    No search results found.
                                </xsl:when>
                                <xsl:otherwise>
                                    No matches were found for this sale.
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:if>
                        <xsl:if test="Code = 'finish_failed'">
                            <xsl:choose>
                                <xsl:when test="/Root/ActionCompleted = 'QwikClose'">
                                    Some files could not be finished. It's possible they were changed during the finish operation.<br/>Check the open file listing to determine if any files that needed to be finished have missing or unchecked revenue.<br/>If so, you can finish those files once their revenue is entered and checked.
                                </xsl:when>
                                <xsl:otherwise>
                                    This file cannot be finished.
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:if>
                        <xsl:if test="Code = 'split_failed'">
                            <xsl:choose>
                                <xsl:when test="/Root/ActionCompleted = 'QwikClose'">
                                    Some files could not be finished. It's possible they were changed during the finish operation.<br/>Check the open file listing to determine if any files that needed to be finished have missing or unchecked revenue.<br/>If so, you can finish those files once their revenue is entered and checked.
                                </xsl:when>
                                <xsl:otherwise>
                                    This file cannot be split.
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:if>
                        <xsl:if test="Code = 'invalid_currency'">
                            Invalid currency conversion rate.
                        </xsl:if>
                        <xsl:if test="Code = 'user_save_failed'">
                            Please fix errors in red below.
                        </xsl:if>
                        <xsl:if test="Code = 'email_invalid'">
                            No account found for this e-mail address.
                        </xsl:if>
                        <xsl:if test="Code = 'password_mismatch'">
                            Passwords do not match.
                        </xsl:if>
                        <xsl:if test="Code = 'token_invalid'">
                            This link is no longer valid.<br />Please <a href="/app/forgotpw">try again</a>.
                        </xsl:if>
                        <xsl:if test="Code = 'password_length'">
                            Passwords must be 8-20 characters in length.
                        </xsl:if>
                        <xsl:if test="Code = 'password_unsafe'">
                            Password matches your current password or user name.  Please select a new one.
                        </xsl:if>
                        <xsl:if test="Code = 'password_spaces'">
                            Password cannot contain spaces.
                        </xsl:if>
                        <xsl:if test="Code = 'email_not_found'">
                            This e-mail address does not exist in our system.
                        </xsl:if>
                        <xsl:if test="Code = 'account_already_exists'">
                            This user already has an account with this client.
                        </xsl:if>
                        <xsl:if test="Code = 'import_access_denied'">
                            You are not able to import this user.
                        </xsl:if>
                        <xsl:if test="Code = 'import_failed'">
                            The import has failed.  Please try again in a few minutes.
                        </xsl:if>
                        <xsl:if test="Code = 'file_is_empty'">
                            The file uploaded was empty.  Please try a different file.
                        </xsl:if>
                        <xsl:if test="Code = 'file_not_deleted'">
                            Unable to delete file "<strong><xsl:value-of select="/Root/DeletedFile" /></strong>".
                        </xsl:if>
                        <xsl:if test="Code = 'download_unavailable'">
                            <xsl:choose>
                                <xsl:when test="normalize-space(/Root/Period/NextPeriodID)">
                                    File is not yet ready.  Please try again in a few minutes.
                                </xsl:when>
                                <xsl:otherwise>
                                    File "<strong><xsl:value-of select="/Root/Files/File[FileID = /Root/Params/file]/OrigFileNamePretty" /></strong>" cannot be downloaded at this time.
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:if>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </span>
</xsl:template>

  <xsl:template name="whichLayout">
    <xsl:if test="$action = 'ss' or $action = 's' or $action = 'fs' or $action = 'f'">
      <xsl:call-template name="byLayout" />
    </xsl:if>
    <xsl:if test="$action = 'as' or $action = 'ks'">
      <xsl:call-template name="topSummaryLayout" />
    </xsl:if>
    <xsl:if test="$action = 'a' or $action = 'ks' or $action = 'k'">
      <xsl:call-template name="topDetailLayout" />
    </xsl:if>
    <xsl:if test="$action = 'reports'">
      <xsl:call-template name="reportsLayout" />
    </xsl:if>
    <xsl:if test="$action = 'login'">
      <xsl:call-template name="loginLayout" />
    </xsl:if>
    <xsl:if test="$action = 'tracker'">
      <xsl:call-template name="trackerLayout" />
    </xsl:if>
    <xsl:if test="$action = 'matcher'">
      <xsl:call-template name="matcherLayout" />
    </xsl:if>
    <xsl:if test="$action = 'streamRevenue'">
      <xsl:call-template name="streamRevenueLayout" />
    </xsl:if>
    <xsl:if test="$action = 'finishImport'">
      <xsl:call-template name="finishImportLayout" />
    </xsl:if>
    <xsl:if test="$action = 'users'">
      <xsl:call-template name="userSummaryLayout" />
    </xsl:if>
    <xsl:if test="$action = 'user_edit'">
      <xsl:call-template name="userEntryLayout" />
    </xsl:if>
    <xsl:if test="$action = 'profile'">
      <xsl:call-template name="userEntryLayout" />
    </xsl:if>
    <xsl:if test="$action = 'forgotpw'">
      <xsl:call-template name="forgotLayout" />
    </xsl:if>
    <xsl:if test="$action = 'forgotSuccess'">
      <xsl:call-template name="forgotSuccessLayout" />
    </xsl:if>
    <xsl:if test="$action = 'resetCode'">
      <xsl:call-template name="resetCodeLayout" />
    </xsl:if>
    <xsl:if test="$action = 'resetPasswords'">
      <xsl:call-template name="resetPasswordsLayout" />
    </xsl:if>
    <xsl:if test="$action = 'resetSuccess'">
      <xsl:call-template name="resetSuccessLayout" />
    </xsl:if>
    <xsl:if test="$action = 'contact'">
      <xsl:call-template name="contactLayout" />
    </xsl:if>
    <xsl:if test="$action = 'changepw'">
      <xsl:call-template name="changePWLayout" />
    </xsl:if>
    <xsl:if test="$action = 'import_user'">
      <xsl:call-template name="userImportLayout" />
    </xsl:if>
  </xsl:template>

  <xsl:template name="accessLevelName">
    <xsl:if test="$accessLevelID = 1">RoyaltyShare Admin</xsl:if>
    <xsl:if test="$accessLevelID = 2">RoyaltyShare Account Rep</xsl:if>
    <xsl:if test="$accessLevelID = 3">Admin</xsl:if>
    <xsl:if test="$accessLevelID = 4">Royalty</xsl:if>
    <xsl:if test="$accessLevelID = 5">Label Report</xsl:if>
    <xsl:if test="$accessLevelID = 6">Marketing</xsl:if>
  </xsl:template>

  <xsl:template name="periodName">
    <xsl:choose>
      <xsl:when test="Period/PeriodType = 'Y'">Year</xsl:when>
      <xsl:when test="Period/PeriodType = 'M'">Month</xsl:when>
      <xsl:when test="Period/PeriodType = 'Q'">Quarter</xsl:when>
      <xsl:otherwise>Period</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="argsLink">
    <xsl:param name="skip" select="''" />
    <xsl:param name="skip2" select="''" />
    <xsl:param name="skip3" select="''" />
    <xsl:param name="skip4" select="''" />
    <xsl:param name="skip5" select="''" />
    <xsl:param name="skip6" select="''" />
    <xsl:attribute name="href">
      <xsl:value-of select="$baseURL" />
      <xsl:for-each select="/Root/Params/*">
        <xsl:if test="name() != $skip and name() != $skip2 and name() != $skip3 and name() != $skip4 and name() != $skip5 and name() != $skip6 and name() != 'p'">&amp;<xsl:value-of select="name()" />=<xsl:value-of select="current()" /></xsl:if>
      </xsl:for-each>
    </xsl:attribute>
  </xsl:template>

  <xsl:template name="footer">
    <div id="footer">
      <p>
        <script language="JavaScript">
          if (customLook == 1) {
            document.write("Powered by RoyaltyShare, Inc. &#xA9; 2006 All rights reserved.");
          } else {
            document.write("&#xA9; 2006 RoyaltyShare, Inc. All rights reserved.");
          }
        </script>
      </p>
    </div>
  </xsl:template>

</xsl:stylesheet>
