<!--                                                                  -->
<!--  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">
			<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 = '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 at least 12 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_history'">
							Password cannot be one of previous 24 passwords.  Please select a new one.
						</xsl:if>
						<xsl:if test="Code = 'user_locked'">
							Account locked out. Please contact client services.
						</xsl:if>
						<xsl:if test="Code = 'password_expired'">
							Password expired and must be changed.
						</xsl:if>
						<xsl:if test="Code = 'password_invalid'">
							Password invalid.
						</xsl:if>
						<xsl:if test="Code = 'failed_logins'">
							Account locked due to too many failed logins.
						</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>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:if>
            <xsl:if test="Type = 'info'">
                <xsl:call-template name="uiWarning">
                    <xsl:with-param name="type" select="'info'" />
                    <xsl:with-param name="description">
                        <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:with-param>
                </xsl:call-template>
            </xsl:if>
		</xsl:for-each>
	</xsl:template>

	<xsl:template name="errorMessageGeneral">
		<xsl:param name="className" select="''"/>
		<xsl:param name="hidden" select="''"/>
		<xsl:variable name="errorMessageGeneralText">
			<xsl:choose>
				<xsl:when test="Form/Track/@e = 'track_has_sales'">
					This track has sales records associated with it and cannot be deleted.
				</xsl:when>
				<xsl:when test="Form/Track/@e = 'track_has_licenses'">
					This track has 1 or more licenses associated with it and cannot be deleted.
				</xsl:when>
				<xsl:when test="Form/Track/@e = 'track_has_contracts'">
					This track has 1 or more contracts associated with it and cannot be deleted.
				</xsl:when>
				<xsl:when test="/Root//*[@e] or /Root//*[@emsg]">
					Please fix the errors below.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'form_submit_error'">
					A problem was encountered.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'password_mismatch'">
					Passwords did not match.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'password_length'">
					Passwords must be at least 12 characters in length.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'password_unsafe'">
					Password matches your current password or user name.  Please select a new one.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'password_history'">
					Password cannot be one of previous 24 passwords.  Please select a new one.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'user_locked'">
					Account locked out. Please contact client services.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'password_expired'">
					Password expired and must be changed.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'password_invalid'">
					Password invalid.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'failed_logins'">
					Account locked due to too many failed logins.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'delete_error' and $area = 'price'">
					This price cannot be deleted.
				</xsl:when>
				<xsl:when test="Messages/Message/Code = 'delete_error' and ($area = 'license' or $area = 'ca_license')">
					This license cannot be deleted.
				</xsl:when>
				<xsl:otherwise></xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:call-template name="uiWarning">
			<xsl:with-param name="id">
				<xsl:if test="Params/_inline">errorGeneralPop</xsl:if>
				<xsl:if test="not(Params/_inline)">errorGeneral</xsl:if>
			</xsl:with-param>
			<xsl:with-param name="type" select="'error'" />
			<xsl:with-param name="className" select="$className" />
			<xsl:with-param name="hidden">
				<xsl:choose>
					<xsl:when test="$errorMessageGeneralText != ''">
						<xsl:text>false</xsl:text>
					</xsl:when>
					<xsl:otherwise>
						<xsl:text>true</xsl:text>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
			<xsl:with-param name="description" select="$errorMessageGeneralText" />
		</xsl:call-template>
	</xsl:template>

	<xsl:template name="errorMessageBox">
		<xsl:param name="errorMessage" />
		<xsl:if test="Messages/Message/Type = 'error'">
			<xsl:call-template name="uiWarning">
				<xsl:with-param name="type" select="'error'" />
				<xsl:with-param name="description" select="$errorMessage"/>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="successMessageGeneral">
		<xsl:param name="successMessage" />
		<xsl:if test="Messages/Message/Type = 'success'">
			<xsl:call-template name="uiWarning">
				<xsl:with-param name="id" select="'successGeneralMessageBox'" />
				<xsl:with-param name="type" select="'success'" />
				<xsl:with-param name="description">
					<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>
				</xsl:with-param>
			</xsl:call-template>
		</xsl:if>
	</xsl:template>

	<xsl:template name="successMessageLarge">
		<xsl:param name="successMessage" />
		<xsl:if test="Messages/Message/Type = 'success'">
			<xsl:call-template name="uiWarning">
				<xsl:with-param name="type" select="'success'" />
				<xsl:with-param name="description">
					<xsl:value-of select="$successMessage" />
				</xsl:with-param>
			</xsl:call-template>
		</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>
		<div class="Form-error-text-wrapper">
			<span id="ERROR{$name}" class="Form-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>
		</div>
	</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 = 'required_for_distribution'"> required for online distribution.</xsl:when>
			<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_access_level'"> belongs to an account with a higher access level.</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="$errorCode = 'isbn10_wrong_length'"> must be 10 characters.</xsl:when>
			<xsl:when test="$errorCode = 'isbn13_wrong_length'"> must be 13 characters.</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="Warning Warning Warning-type-danger-warning">
			<div class="Warning-icon-wrapper">
				<xsl:call-template name="icon">
					<xsl:with-param name="size" select="'big'" />
					<xsl:with-param name="type" select="'attention'" />
				</xsl:call-template>
			</div>
			<div class="Warning-content">
				<h5 class="Warning-title">
					Warning
				</h5>
				<div class="Warning-description">
					<p>Data is unable to be modified because of completed royalty run(s) in the following area(s):</p>
					<xsl:if test="normalize-space($runArea1)">
						<p class="Warning-paragraph">
							<a href="/rps/{$runArea1}">
								<xsl:call-template name="areaToName">
									<xsl:with-param name="runArea" select="$runArea1" />
								</xsl:call-template>
							</a>
						</p>
					</xsl:if>
					<xsl:if test="normalize-space($runArea2)">
						<p class="Warning-paragraph">
							<a href="/rps/{$runArea2}">
								<xsl:call-template name="areaToName">
									<xsl:with-param name="runArea" select="$runArea2" />
								</xsl:call-template>
							</a>
						</p>
					</xsl:if>
					<xsl:if test="normalize-space($runArea3)">
						<p class="Warning-paragraph">
							<a href="/rps/{$runArea3}">
								<xsl:call-template name="areaToName">
									<xsl:with-param name="runArea" select="$runArea3" />
								</xsl:call-template>
							</a>
						</p>
					</xsl:if>
					<xsl:if test="normalize-space($runArea4)">
						<p class="Warning-paragraph">
							<a href="/rps/{$runArea4}">
								<xsl:call-template name="areaToName">
									<xsl:with-param name="runArea" select="$runArea4" />
								</xsl:call-template>
							</a>
						</p>
					</xsl:if>
					<xsl:if test="normalize-space($runArea5)">
						<p class="Warning-paragraph">
							<a href="/rps/{$runArea5}">
								<xsl:call-template name="areaToName">
									<xsl:with-param name="runArea" select="$runArea5" />
								</xsl:call-template>
							</a>
						</p>
					</xsl:if>
					<p class="Warning-paragraph">The completed royalty runs must be either committed, invalidated, or deleted. Action can be taken through the links above.</p>
				</div>
			</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:stylesheet>
