<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" doctype-system="http://www.w3.org/TR/html4/strict.dtd" doctype-public="-//W3C//DTD HTML 4.01//EN" encoding="iso-8859-1" />

  <xsl:template match="root">
    <html>
      <head>
        <title>RoyaltyShare - <xsl:value-of select="$pageName" /></title>
        <link rel="stylesheet" type="text/css" media="all" href="/test/css/main.css" />
        <script src="/test/javascript/main.js" type="text/javascript"></script>
      </head>
      <body>
	<div class="minwidth">
	  <div class="container">
	    <div id="logo" title="RoyaltyShare">
     	      <img src="/test/images/logo.gif" alt="RoyaltyShare" />
            </div>
            <xsl:if test="$action = 'login'">
              <div id="loginTop">&#160;</div>
            </xsl:if>
            <xsl:if test="$action != 'login'">
	      <div id="logout"><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'">
	            <h2><xsl:value-of select="$pageName" /></h2>
		  </xsl:if>
	          <xsl:call-template name="messages" />
                  <xsl:call-template name="whichLayout" />
                  <div class="hack">&#160;</div>
	        </div>
	      </div>
	      <xsl:if test="$action = 'm'">
	        <xsl:for-each select="lists/list">
	          <xsl:if test="name = 'files_by_service'">
	            <xsl:call-template name="statusChart" />
	          </xsl:if>
	        </xsl:for-each>
	      </xsl:if>
 	    </div>
            <xsl:call-template name="footer" />
          </div>
        </div>
      </body>
    </html>
  </xsl:template>

  <xsl:template name="whichLayout">
    <xsl:if test="$action = 'm'">
      <xsl:call-template name="homeLayout" />
    </xsl:if>
    <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 = 'login'">
      <xsl:call-template name="loginLayout" />
    </xsl:if>
    <xsl:if test="$action = 'tracker'">
      <xsl:call-template name="trackerLayout" />
    </xsl:if>
    <xsl:if test="$action = 'manageImport'">
      <xsl:call-template name="manageImportLayout" />
    </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:template>

  <xsl:template name="sublabel">
    <form id="labelDropDown" name="label" onsubmit="labelChange('{$action}','{$period}','','',this.label_id.value);return false" action="#">
      <xsl:choose>
        <xsl:when test="$action = 'm' or $action = 'ss' or $action = 'fs' or $action = 'as' or $action = 'ks'">
          now viewing:
          <select name="label_id">
            <option value="0">
              <xsl:if test="$labelId = '0'">
                <xsl:attribute name="selected">selected</xsl:attribute>
              </xsl:if>
              All Labels
            </option>
            <xsl:for-each select="sublabels/sublabel">
              <option value="{label_id}">
                <xsl:if test="label_id = $labelId">
                  <xsl:attribute name="selected">selected</xsl:attribute>
                </xsl:if>
                <xsl:value-of select="label_name" />
              </option>
            </xsl:for-each>
          </select>
          <input type="submit" value="go" />
        </xsl:when>
        <xsl:otherwise>
          <div id="labelText">now viewing: <xsl:value-of select="label/label_name" /></div>
        </xsl:otherwise>
      </xsl:choose>
    </form>
  </xsl:template>

  <xsl:template name="sectionHeader">
    <div class="sectionHeader">
      <xsl:if test="$action = 'login'">
        <h1>Welcome to RoyaltyShare</h1>
      </xsl:if>
      <xsl:if test="$action != 'login'">
        <div id="navPrev">
          <xsl:choose>
            <xsl:when test="normalize-space(period/previous_period)">
              &#171; <a href="?period={period/previous_period}&amp;label_id={$labelId}">Previous</a>
            </xsl:when>
            <xsl:otherwise>
              &#160;
            </xsl:otherwise>
          </xsl:choose>
        </div>
        <div id="navNext">
          <xsl:choose>
            <xsl:when test="normalize-space(period/next_period)">
              <a href="?period={period/next_period}&amp;label_id={$labelId}">Next</a> &#187;
            </xsl:when>
            <xsl:otherwise>
              &#160;
            </xsl:otherwise>
          </xsl:choose>
        </div>
        <h1>
          <xsl:if test="$tab = 'sales'">
        Q<xsl:value-of select="dates/quarter" />&#160;<xsl:value-of select="dates/start_year" /> (<xsl:value-of select="dates/start_month" />-<xsl:value-of select="dates/end_month" />)
	  </xsl:if>
          <xsl:if test="$tab = 'royalties'">
            <xsl:value-of select="period/start_date/month" />&#160;<xsl:value-of select="period/start_date/day" />, <xsl:value-of select="period/start_date/year" /> -
            <xsl:choose>
	      <xsl:when test="normalize-space(period/next_period)">
	        <xsl:value-of select="period/end_date/month" />&#160;<xsl:value-of select="period/end_date/day" />, <xsl:value-of select="period/end_date/year" />
              </xsl:when>
	      <xsl:otherwise>
		Present (Current)
	      </xsl:otherwise>
            </xsl:choose>
          </xsl:if>
	</h1>
      </xsl:if>
    </div>
  </xsl:template>

  <xsl:template name="footer">
    <div id="footer">
      <p>&#xA9; 2005 RoyaltyShare, Inc. All rights reserved.</p>
    </div>
  </xsl:template>

    <xsl:template name="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_upload_success'">
                            File "<strong><xsl:value-of select="/root/params/fileUploadName" /></strong>" uploaded successfully!
                        </xsl:if>
                    </xsl:with-param>
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>

  <xsl:include href="login.xsl" />
  <xsl:include href="navigation.xsl" />
  <xsl:include href="sales.xsl" />
  <xsl:include href="charts.xsl" />
  <xsl:include href="royalties.xsl" />
  <xsl:include href="variables.xsl" />

</xsl:stylesheet>
