<!--                                                                  -->
<!--  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">

	<!-- message stuff (error, success, misc.) -->

  <xsl:template name="messages">
    <xsl:for-each select="Messages/Message">
			<div class="section">
	      <xsl:if test="Type = 'error'">
	        <p class="error">
	          <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
                    <xsl:choose>
                      <xsl:when test="/Root/Sale/MediaType = 1">audio</xsl:when>
                      <xsl:when test="/Root/Sale/MediaType = 2">video</xsl:when>
                      <xsl:otherwise></xsl:otherwise>
                    </xsl:choose>
                    matches were found for this sale.
	              </xsl:otherwise>
	            </xsl:choose>
	          </xsl:if>
	          <xsl:if test="Code = 'split_failed'">
	            This file cannot be split.
	          </xsl:if>
	          <xsl:if test="Code = 'invalid_distributionfee'">
	            Distribution fee must be entered as a whole number.
	          </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_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>
	        </p>
	      </xsl:if>
				<br />
			</div>
    </xsl:for-each>
  </xsl:template>


  <xsl:template name="errorMessageGeneral">
    <span class="error">
      <xsl:attribute name="id">
        <xsl:if test="Params/_inline">errorGeneralPop</xsl:if>
        <xsl:if test="not(Params/_inline)">errorGeneral</xsl:if>
      </xsl:attribute>
      <xsl:choose>
      	<xsl:when test="Form/Track/@e = 'track_has_sales'">
      		<p class="errorGeneral bigMessageBox">This track has sales records associated with it and cannot be deleted.</p>
      	</xsl:when>
      	<xsl:when test="Form/Track/@e = 'track_has_licenses'">
      		<p class="errorGeneral bigMessageBox">This track has 1 or more licenses associated with it and cannot be deleted.</p>
      	</xsl:when>
      	<xsl:when test="Form/Track/@e = 'track_has_contracts'">
      		<p class="errorGeneral bigMessageBox">This track has 1 or more contracts associated with it and cannot be deleted.</p>
      	</xsl:when>
        <xsl:when test="/Root//*[@e] or /Root//*[@emsg]">
          <p class="errorGeneral messageBox">Please fix the errors below.</p>
        </xsl:when>
        <xsl:when test="Messages/Message/Code = 'form_submit_error'">
          <p class="errorGeneral messageBox">A problem was encountered.</p>
        </xsl:when>
        <xsl:when test="Messages/Message/Code = 'password_mismatch'">
          <p class="errorGeneral messageBox">Passwords did not match.</p>
        </xsl:when>
        <xsl:when test="Messages/Message/Code = 'delete_error' and $area = 'price'">
          <p class="errorGeneral messageBox">This price cannot be deleted.</p>
        </xsl:when>
        <xsl:when test="Messages/Message/Code = 'delete_error' and ($area = 'license' or $area = 'ca_license')">
          <p class="errorGeneral messageBox">This license cannot be deleted.</p>
        </xsl:when>        
      </xsl:choose>
    </span>
  </xsl:template>


  <xsl:template name="errorMessageBox">
    <xsl:param name="errorMessage" />
    <xsl:if test="Messages/Message/Type = 'error'">
      <p class="errorGeneral messageBox">
      	<xsl:value-of select="$errorMessage" />
      </p>
    </xsl:if>
  </xsl:template>


  <xsl:template name="successMessageGeneral">
    <xsl:param name="successMessage" />
    <xsl:if test="Messages/Message/Type = 'success'">
      <p class="successGeneral messageBox" id="successGeneralMessageBox">
        <xsl:choose>
          <xsl:when test="Messages/Message/Code = 'form_make_default_success'">
            Defaults Saved!
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$successMessage" />
          </xsl:otherwise>
       </xsl:choose>
      </p>
    </xsl:if>
  </xsl:template>
  
  <xsl:template name="successMessageLarge">
    <xsl:param name="successMessage" />
    <xsl:if test="Messages/Message/Type = 'success'">
      <p class="successGeneral bigMessageBox">
      	<xsl:value-of select="$successMessage" />
      </p>
    </xsl:if>
  </xsl:template>  


  <xsl:template name="inlineError">
    <xsl:param name="displayName" />
    <xsl:param name="path" />
    <xsl:variable name="name"><xsl:value-of select="translate($path,'/','_')" /></xsl:variable>
    <span id="ERROR{$name}" class="error">
      <xsl:if test="dyn:evaluate($path)[@e]">
        <xsl:value-of select="$displayName" /> <xsl:call-template name="fieldError"><xsl:with-param name="errorCode" select="dyn:evaluate($path)/@e" /><xsl:with-param name="path" select="$path" /></xsl:call-template>
      </xsl:if>
    </span>
  </xsl:template>


  <xsl:template name="fieldError">
    <xsl:param name="path" />
    <xsl:param name="errorCode" />
  	<xsl:variable name="field" select="dyn:evaluate($path)" />
  	<xsl:choose>
	    <xsl:when test="$errorCode = 'field_invalid_state'"> must be a 2-character code.</xsl:when>
	    <xsl:when test="$errorCode = 'field_invalid'"> is invalid.</xsl:when>
	    <xsl:when test="$errorCode = 'field_blank'"> cannot be blank.</xsl:when>
	    <xsl:when test="$errorCode = 'field_out_of_range'"> must be
	    	<xsl:choose>
	    		<xsl:when test="$field/@minValue and $field/@maxValue">
	    			between <xsl:value-of select="$field/@minValue" /> and <xsl:value-of select="$field/@maxValue" />.
					</xsl:when>
	    		<xsl:when test="$field/@minValue">
	    			at least <xsl:value-of select="$field/@minValue" />.
					</xsl:when>
		    	<xsl:when test="$field/@maxValue">
	    			no more than <xsl:value-of select="$field/@maxValue" />.
					</xsl:when>
	    	</xsl:choose>
	    </xsl:when>
	    <xsl:when test="$errorCode = 'field_duplicate'">&#160;<xsl:value-of select="$field" /> already exists.  Please enter a different identifier.</xsl:when>
	    <xsl:when test="$errorCode = 'field_too_short'"> is too short.</xsl:when>
	    <xsl:when test="$errorCode = 'field_too_long'"> is too long.</xsl:when>
	    <xsl:when test="$errorCode = 'phone_bad_format'"> must contain at least 10 digits and begin with a number or '('.</xsl:when>
	    <xsl:when test="$errorCode = 'email_not_available'"> is already in use for another account.</xsl:when>
	    <xsl:when test="$errorCode = 'email_address_invalid'"> is not valid.</xsl:when>
	    <xsl:when test="$errorCode = 'email_invalid'"> is not valid.</xsl:when>
	    <xsl:when test="$errorCode = 'email_not_found'">  does not exist in our system.</xsl:when>
	    <xsl:when test="$errorCode = 'account_exists'"> is for an account that already exists.</xsl:when>
			<xsl:when test="$errorCode = 'required_fields'"> is required.</xsl:when>
			<xsl:when test="$errorCode = 'upc_inuse'"> in use by another album.</xsl:when>
			<xsl:when test="$errorCode = 'upc_required'"> is required.</xsl:when>
			<xsl:when test="$errorCode = 'upc_invalid'"> is not valid.</xsl:when>
			<xsl:when test="$errorCode = 'field_numeric'"> must be 1-10 digits.</xsl:when>
			<xsl:when test="$field/@emsg">&#160;<xsl:value-of select="$field/@emsg" /></xsl:when>
		</xsl:choose>
    <br />
  </xsl:template>
  

    <xsl:template name="openRunMessage">
        <xsl:param name="runArea1" />
        <xsl:param name="runArea2" /> 
        <xsl:param name="runArea3" /> 
        <xsl:param name="runArea4" /> 
        <xsl:param name="runArea5" /> 

        <div class="warningGeneral messageBox openRunMessage">
            <div>                                    
          	    Data is unable to be modified because of completed royalty run(s) in the following area(s):
          	    <br />
          	    <xsl:if test="normalize-space($runArea1)">
          	        <a href="/rps/{$runArea1}">
              	        <xsl:call-template name="areaToName">
              	            <xsl:with-param name="runArea" select="$runArea1" />
              	        </xsl:call-template>
          	        </a>
          	        <br />
          	    </xsl:if>
          	    <xsl:if test="normalize-space($runArea2)">
          	        <a href="/rps/{$runArea2}">
              	        <xsl:call-template name="areaToName">
              	            <xsl:with-param name="runArea" select="$runArea2" />
              	        </xsl:call-template>
          	        </a>
          	        <br />
          	    </xsl:if>          	    
          	    <xsl:if test="normalize-space($runArea3)">
          	        <a href="/rps/{$runArea3}">
              	        <xsl:call-template name="areaToName">
              	            <xsl:with-param name="runArea" select="$runArea3" />
              	        </xsl:call-template>
          	        </a>
          	        <br />
          	    </xsl:if>      
          	    <xsl:if test="normalize-space($runArea4)">
          	        <a href="/rps/{$runArea4}">
              	        <xsl:call-template name="areaToName">
              	            <xsl:with-param name="runArea" select="$runArea4" />
              	        </xsl:call-template>
          	        </a>
          	        <br />
          	    </xsl:if>      
          	    <xsl:if test="normalize-space($runArea5)">
          	        <a href="/rps/{$runArea5}">
              	        <xsl:call-template name="areaToName">
              	            <xsl:with-param name="runArea" select="$runArea5" />
              	        </xsl:call-template>
          	        </a>
          	        <br />
          	    </xsl:if>      
          	    <br />    	    
          	    The completed royalty runs must be either committed, invalidated, or deleted.
                Action can be taken through the links above.       
            </div>
        </div> 
        
    </xsl:template> 
    
    
    <xsl:template name="areaToName">
        <xsl:param name="runArea" />
        <xsl:choose>
            <xsl:when test="$runArea = 'mechanical'">United States Mechanical</xsl:when>
            <xsl:when test="$runArea = 'ca_mechanical'">Canadian Mechanical</xsl:when>
            <xsl:when test="$runArea = 'uk_mech'">United Kingdom Mechanical</xsl:when>
            <xsl:when test="$runArea = 'artist_royalty'">Artist Royalties</xsl:when>
            <xsl:when test="$runArea = 'label_royalty'">Label Royalties</xsl:when>
        </xsl:choose>    
    </xsl:template>
    
    
    <xsl:template name="openRunMessageHelper">     
        <xsl:param name="usMechRuns" select="'0'" />  
        <xsl:param name="caMechRuns" select="'0'" />  
        <xsl:param name="ukMechRuns" select="'0'" />
        <xsl:param name="artistRuns" select="'0'" />
        <xsl:param name="labelRuns" select="'0'" />

        <xsl:call-template name="openRunMessage">
            <xsl:with-param name="runArea1">
                <xsl:if test="$caMechRuns != 0">ca_mechanical</xsl:if>
            </xsl:with-param>
            <xsl:with-param name="runArea2">
                <xsl:if test="$usMechRuns != 0">mechanical</xsl:if>
            </xsl:with-param>
            <xsl:with-param name="runArea3">
                <xsl:if test="$ukMechRuns != 0">uk_mech</xsl:if>
            </xsl:with-param>
            <xsl:with-param name="runArea4">
                <xsl:if test="$artistRuns != 0">artist_royalty</xsl:if>
            </xsl:with-param>
            <xsl:with-param name="runArea5">
                <xsl:if test="$labelRuns != 0">label_royalty</xsl:if>
            </xsl:with-param>
        </xsl:call-template>
    
    </xsl:template>


    <xsl:template name="errorRunMessage">

        <div class="warningGeneral messageBox openRunMessage">
            <div>                                          	    
                A royalty run has encountered an error. 
                <br />
          	    <br />    	    
          	    This requires the assistance of the RoyaltyShare Support team, and you will be unable to create new royalty runs until this error is resolved.  For more information, please contact <a href="mailto:support@royaltyshare.com">RoyaltyShare Support</a>.
            </div>
        </div> 
        
    </xsl:template> 
        

</xsl:stylesheet>
