<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dyn="http://exslt.org/dynamic" extension-element-prefixes="dyn">
    <xsl:output method="html" indent="no" doctype-system="" encoding="utf-8" />

    <xsl:include href="/app/tools/rps/templates/global.xsl" />

    <xsl:template name="pickLayout">
        <section class="MainBaseSection">
            <link rel="stylesheet" href="/production/css/portal.css?v=1"/>
            <script type="text/javascript" src="/production/javascript/portal.js?v=3"></script>
            <xsl:choose>
                <xsl:when test="$cmd = 'history'">
                    <xsl:call-template name="historyLayout" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:call-template name="defaultLayout" />
                </xsl:otherwise>
            </xsl:choose>
        </section>
    </xsl:template>

    <xsl:template name="onlineJavascripts">
        <!-- Artist Payee -->
        <xsl:variable name="ArtistPayeeType" select="'1'" />
        <xsl:variable name="USPublisherPayeeType" select="'2'" />
        <xsl:variable name="CAPublisherPayeeType" select="'3'" />
        <script type="text/javascript">
            function resendArtistPayeePop() {
                var popHtml = $('#viewArtistPayeeResend').html();
                popHtml += '<form id="resend_artist_payee_form" action="/rps/portal/resend" method="post"><input type="hidden" name="payeeType" value="{$ArtistPayeeType}" /><input type="hidden" name="resend" value="payee" /></form>';
                jsInlinePop(popHtml,"Resend",
                <xsl:choose>
                    <xsl:when test="Artist/OkToResendAll = '1' and (not(normalize-space(Messages/Message/Code)) or Messages/Message/Code != 'form_submit_success')">
                        "$('#resend_artist_payee_form').submit();"
                    </xsl:when>
                    <xsl:otherwise>
                        "failResend(); return false;"
                    </xsl:otherwise>
                </xsl:choose>
                ,'','','Resend Invite');
            }
        </script>
        <script type="text/javascript">
            function resendArtistPayeePopRecipients() {
                var popHtml = $('#viewArtistPayeeResendRecipients').html();
                popHtml += '<form id="resend_artist_payee_recipients_form" action="/rps/portal/resend" method="post"><input type="hidden" name="payeeType" value="{$ArtistPayeeType}" /><input type="hidden" name="resend" value="recipient" /></form>';
                jsInlinePop(popHtml,"Resend",
                <xsl:choose>
                    <xsl:when test="Artist/OkToResendRecipientsAll = '1' and (not(normalize-space(Messages/Message/Code)) or Messages/Message/Code != 'form_submit_success')">
                        "$('#resend_artist_payee_recipients_form').submit();"
                    </xsl:when>
                    <xsl:otherwise>
                        "failResend(); return false;"
                    </xsl:otherwise>
                </xsl:choose>
                ,'','','Resend Invite');
            }
        </script>

        <!-- US Publisher Payee -->
        <script type="text/javascript">
            function resendPublisherPayeePop() {
                var popHtml = $('#viewPublisherPayeeResend').html();
                popHtml += '<form id="resend_publisher_payee_form" action="/rps/portal/resend" method="post"><input type="hidden" name="payeeType" value="{$USPublisherPayeeType}" /><input type="hidden" name="resend" value="payee" /></form>';
                jsInlinePop(popHtml,"Resend",
                <xsl:choose>
                    <xsl:when test="Publisher/OkToResendAll = '1' and (not(normalize-space(Messages/Message/Code)) or Messages/Message/Code != 'form_submit_success')">
                        "$('#resend_publisher_payee_form').submit();"
                    </xsl:when>
                    <xsl:otherwise>
                        "failResend(); return false;"
                    </xsl:otherwise>
                </xsl:choose>
                ,'','','Resend Invite');
            }
        </script>
        <script type="text/javascript">
            function resendPublisherPayeePopRecipients() {
                var popHtml = $('#viewPublisherPayeeResendRecipients').html();
                popHtml += '<form id="resend_publisher_payee_recipients_form" action="/rps/portal/resend" method="post"><input type="hidden" name="payeeType" value="{$USPublisherPayeeType}" /><input type="hidden" name="resend" value="recipient" /></form>';
                jsInlinePop(popHtml,"Resend",
                <xsl:choose>
                    <xsl:when test="Publisher/OkToResendRecipientsAll = '1' and (not(normalize-space(Messages/Message/Code)) or Messages/Message/Code != 'form_submit_success')">
                        "$('#resend_publisher_payee_recipients_form').submit();"
                    </xsl:when>
                    <xsl:otherwise>
                        "failResend(); return false;"
                    </xsl:otherwise>
                </xsl:choose>
                ,'','','Resend Invite');
            }
        </script>
    </xsl:template>

    <xsl:template name="defaultLayout">
        <xsl:call-template name="onlineJavascripts" />

        <xsl:variable name="accessLevel" select="/Root/User/AccessLevel" />
        <div id="viewInvite" title="Portal Invitation" class="PortalPopupContent">
            <div style="text-align: left; padding: 20px;">
                Subject:  Invite for Online Statement Distribution from {Label Name} - {Payee Name}<br/><br/>
                Body:<br/><br/>
                Dear {Payee Name},<br/><br/>
                You've been invited to set up an account for RoyaltyShare's Payee Portal by {Label Name} so you can receive royalty statements online.<br/><br/>
                Go here to create your account now: {link to create account}<br/>
                This invitation link is valid for 30 days.<br/><br/>
                Once you've set up your account, you'll receive notifications when new statements are available.<br/><br/>
                If you have questions about why you're receiving this email, please contact {Payee Portal Label Contact}.<br/><br/>
                Thanks!<br/>
                The RoyaltyShare Support Team<br/><br/>
                <xsl:if test="contains('|1|3|4|', concat('|', $accessLevel, '|'))">
                    <fieldset style="border-top:1px solid #d9d2d0;padding-top:20px"></fieldset>
                    <form id="email_custom_invite_form" action="/rps/portal/email_custom_text" method="post">
                    <input type="hidden" name="invite_flag" value="1"/>
                        <label class="Form-label">
                            <span class="Form-label-caption">Below is a direct message sent on behalf of {Label Name}</span>
                        </label>
                        <div class="Form-input-wrapper">
                            <textarea style="height: 100px" name="form_custom_invite_text"
                                       id="customInviteText"
                                       class="Input Form-input"
                                       placeholder="Text entered here will be included on your behalf within the email body…"
                                       oninput="email_custom_invite_validation(this);">
                                       <xsl:value-of select="PortalEmailCustomText/InviteText" />
                            </textarea>
                        </div>
                    <ul class="Form-error Form-error-inline" id="errorEmailInviteText"></ul>
                        <fieldset class="Form-fieldset-buttons">
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="url">
                              <xsl:text>javascript:hideInlinePop()</xsl:text>
                            </xsl:with-param>
                            <xsl:with-param name="name" select="'Cancel'" />
                            <xsl:with-param name="content">Close</xsl:with-param>
                        </xsl:call-template>&#160;
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="type" select="'primary'" />
                            <xsl:with-param name="id" select="'emailInviteSubmitButton'" />
                            <xsl:with-param name="name" select="'submitButton'" />
                            <xsl:with-param name="elemType" select="'submit'" />
                            <xsl:with-param name="className" select="'Form-button'" />
                            <xsl:with-param name="disabled" select="'true'"/>
                            <xsl:with-param name="content">Save</xsl:with-param>
                        </xsl:call-template>
                        </fieldset>
                    </form>
                </xsl:if>
                </div>
        </div>
        <div id="viewNotification" title="Statement Notification" class="PortalPopupContent">
            <div style="text-align: left; padding: 20px;">
                Subject:  {Label Name} {Run Name} Statements Now Available - {Payee Name}<br/><br/>
                Body:<br/><br/>
                Dear {First Name},<br/><br/>
                Statements are now available for {Label Name}'s {Run Name} royalty run.<br/><br/>
                Go here to view your new statements:  {link}<br/><br/>
                If you have questions about your statements, please contact {Payee Portal Label Contact}.<br/><br/>
                Thanks!<br/>
                The RoyaltyShare Support Team<br/><br/>
                <xsl:if test="contains('|1|3|4|', concat('|', $accessLevel, '|'))">
                    <fieldset style="border-top:1px solid #d9d2d0;padding-top:20px"></fieldset>
                    <form id="email_custom_notification_form" action="/rps/portal/email_custom_text" method="post">
                    <input type="hidden" name="notification_flag" value="1"/>
                        <label class="Form-label">
                            <span class="Form-label-caption">Below is a direct message sent on behalf of {Label Name}</span>
                        </label>
                        <div class="Form-input-wrapper">
                            <textarea style="height: 100px" name="form_custom_notification_text"
                                       id="customNotificationText"
                                       class="Input Form-input"
                                       placeholder="Text entered here will be included on your behalf within the email body…"
                                       oninput="email_custom_notification_validation(this);">
                                       <xsl:value-of select="PortalEmailCustomText/NotificationText" />
                            </textarea>
                        </div>
                    <ul class="Form-error Form-error-inline" id="errorEmailNotificationText"></ul>
                        <fieldset class="Form-fieldset-buttons">
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="url">
                              <xsl:text>javascript:hideInlinePop()</xsl:text>
                            </xsl:with-param>
                            <xsl:with-param name="name" select="'Cancel'" />
                            <xsl:with-param name="content">Close</xsl:with-param>
                        </xsl:call-template>&#160;
                        <xsl:call-template name="uiButton">
                            <xsl:with-param name="type" select="'primary'" />
                            <xsl:with-param name="id" select="'emailNotificationSubmitButton'" />
                            <xsl:with-param name="name" select="'submitButton'" />
                            <xsl:with-param name="elemType" select="'submit'" />
                            <xsl:with-param name="className" select="'Form-button'" />
                            <xsl:with-param name="disabled" select="'true'"/>
                            <xsl:with-param name="content">Save</xsl:with-param>
                        </xsl:call-template>
                        </fieldset>
                    </form>
                    </xsl:if>
            </div>
        </div>

        <div id="viewArtistPayeeResend" title="Resend Invite" class="PortalPopupContent">
            <p>Are you sure you want to resend an invite to <xsl:value-of select="Artist/PayeeStatus/Unconfirmed" /> contact<xsl:if test="Artist/PayeeStatus/Unconfirmed &gt; 1">s</xsl:if>?</p>
        </div>
        <div id="viewArtistPayeeResendRecipients" title="Resend Invite" class="PortalPopupContent">
            <p>Are you sure you want to resend an invite to <xsl:value-of select="Artist/PayeeRecipientStatus/Unconfirmed" /> contact<xsl:if test="Artist/PayeeRecipientStatus/Unconfirmed &gt; 1">s</xsl:if>?</p>
        </div>

        <div id="viewPublisherPayeeResend" title="Resend Invite" class="PortalPopupContent">
            <p>Are you sure you want to resend an invite to <xsl:value-of select="Publisher/PayeeStatus/Unconfirmed" /> contact<xsl:if test="Publisher/PayeeStatus/Unconfirmed &gt; 1">s</xsl:if>?</p>
        </div>
        <div id="viewPublisherPayeeResendRecipients" title="Resend Invite" class="PortalPopupContent">
            <p>Are you sure you want to resend an invite to <xsl:value-of select="Publisher/PayeeRecipientStatus/Unconfirmed" /> contact<xsl:if test="Publisher/PayeeRecipientStatus/Unconfirmed &gt; 1">s</xsl:if>?</p>
        </div>

        <xsl:call-template name="helpLink" />
        <xsl:if test="Messages/Message/Code = 'form_submit_success'">
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Invites have been queued!</xsl:with-param>
            </xsl:call-template>
        </xsl:if>
        <xsl:call-template name="errorMessageBox">
            <xsl:with-param name="errorMessage">Invites cannot be resent at this time.</xsl:with-param>
        </xsl:call-template>
        <xsl:if test="Messages/Message/Code = 'invite_text_saved'">
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Email custom invite message has been saved</xsl:with-param>
            </xsl:call-template>
        </xsl:if>
        <xsl:if test="Messages/Message/Code = 'notification_text_saved'">
            <xsl:call-template name="successMessageGeneral">
                <xsl:with-param name="successMessage">Email custom notification message has been saved</xsl:with-param>
            </xsl:call-template>
        </xsl:if>

        <xsl:if test="/Root/ClientTypes/ClientType[(ClientTypeID = 2 and IsClientTypeFlag = 1)]">
            <xsl:call-template name="artistPayeeTotalSection" />
        </xsl:if>
        <xsl:if test="/Root/ClientTypes/ClientType[(ClientTypeID = 5 and IsClientTypeFlag = 1)]">
            <xsl:call-template name="usPublisherPayeeTotalSection" />
        </xsl:if>

        <section class="Portal-section TextNode">
            <h2>Payee Portal Notifications</h2>
            <p>Click <a href="#" id="openInvite">here</a> to view text for the current invite to the payee portal.</p>
            <p>Click <a href="#" id="openNotification">here</a> to view text for the notification sent to payees and additional statement recipients when new statements are available.</p>
        </section>
        <section class="Portal-section">
            <h2>Payee Portal Label Contact &amp; Display Name</h2>
            <div class="Portal-label-name-edit-item">
                Current payee portal contact for statement inquiries:
                <xsl:if test="normalize-space(Client/ClientEmail)">
                    <span id="currentEmail"><strong id="currentEmailValue"><xsl:value-of select="Client/ClientEmail" /></strong></span>
                </xsl:if>
                <xsl:call-template name="icon">
                    <xsl:with-param name="type" select="'complete'"/>
                    <xsl:with-param name="role" select="'action'" />
                    <xsl:with-param name="id" select="'checkmarkEmail'" />
                    <xsl:with-param name="className" select="'Portal-icon-checkmark'" />
                </xsl:call-template>&#xA0;&#xA0;
                <form id="label_email_form" action="/rps/portal/label" method="post" class="PortalInlineForm">
                    <input class="Input" type="text" name="email" id="displayEmail" maxlength="80" value="{Client/ClientEmail}"/>
                    <span class="Portal-icon-wrapper js-tooltip" title="Save">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'save'"/>
                            <xsl:with-param name="role" select="'action'" />
                            <xsl:with-param name="id" select="'saveEmail'" />
                            <xsl:with-param name="className" select="'Portal-icon'" />
                        </xsl:call-template>
                    </span>
                    <span class="Portal-icon-wrapper js-tooltip" title="Cancel">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'close'"/>
                            <xsl:with-param name="role" select="'action'" />
                            <xsl:with-param name="id" select="'cancelEmail'" />
                            <xsl:with-param name="className" select="'Portal-icon'" />
                        </xsl:call-template>
                    </span>
                </form>
                <a href="#" id="openEmail">
                    <xsl:choose>
                        <xsl:when test="Client/ClientEmail = ''">Add</xsl:when>
                        <xsl:otherwise>Edit</xsl:otherwise>
                    </xsl:choose>
                </a>
                <span class="Form-error Form-error-inline" id="errorEmail"></span>
            </div>
            <div class="Portal-label-name-edit-item">
                <xsl:if test="Client/ClientEmail = ''">
                    <span id="noEmail"> You must add a label contact in order to send invites to your Payees.</span><br/><br/>
                </xsl:if>
                Current label display name in the payee portal:
                <strong id="currentName"><xsl:value-of select="Client/ClientDisplayName" /></strong>
                <xsl:call-template name="icon">
                    <xsl:with-param name="type" select="'complete'"/>
                    <xsl:with-param name="role" select="'action'" />
                    <xsl:with-param name="id" select="'checkmarkName'" />
                    <xsl:with-param name="className" select="'Portal-icon-checkmark'" />
                </xsl:call-template>&#xA0;&#xA0;
                <form id="label_name_form" action="/rps/portal/label" method="post" class="PortalInlineForm">
                    <input class="Input" type="text" name="name" id="displayName" value="{Client/ClientDisplayName}"/>
                    <span class="Portal-icon-wrapper js-tooltip" title="Save">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'save'"/>
                            <xsl:with-param name="role" select="'action'" />
                            <xsl:with-param name="id" select="'saveName'" />
                            <xsl:with-param name="className" select="'Portal-icon'" />
                        </xsl:call-template>
                    </span>
                    <span class="Portal-icon-wrapper js-tooltip" title="Cancel">
                        <xsl:call-template name="icon">
                            <xsl:with-param name="type" select="'close'"/>
                            <xsl:with-param name="role" select="'action'" />
                            <xsl:with-param name="id" select="'cancelName'" />
                            <xsl:with-param name="className" select="'Portal-icon'" />
                        </xsl:call-template>
                    </span>
                </form>
                <a href="#" id="openName">Edit</a>
                <span class="Form-error Form-error-inline" id="errorLabel"></span>
            </div>
        </section>
        <script type="text/javascript">
            <xsl:if test="Messages/Message/Code = 'email_saved'">
                $("#checkmarkEmail").css('display', 'inline-block');
            </xsl:if>
            <xsl:if test="Messages/Message/Code = 'name_saved'">
                $("#checkmarkName").css('display', 'inline-block');
            </xsl:if>
        </script>
    </xsl:template>

    <xsl:template name="historyLayout">
        <h2>Payee Portal History coming soon!</h2><br/>
    </xsl:template>

    <xsl:template name="artistPayeeTotalSection" >
        <section class="Portal-section TextNode">
            <h2>Artist Payee Status</h2>
            <p>
                <strong><xsl:value-of select="Artist/PayeeStatus/TotalManual" /></strong>&#xA0;
                <xsl:choose>
                    <xsl:when test="Artist/PayeeStatus/TotalManual = '1'">Payee has</xsl:when>
                    <xsl:otherwise>Payees have</xsl:otherwise>
                </xsl:choose>
                statement distribution set to Manual
            </p>
            <p>
                <strong><xsl:value-of select="Artist/PayeeStatus/TotalOnline" /></strong>&#xA0;
                <xsl:choose>
                    <xsl:when test="Artist/PayeeStatus/TotalOnline = '1'">Payee has</xsl:when>
                    <xsl:otherwise>Payees have</xsl:otherwise>
                </xsl:choose>
                statement distribution set to be delivered online through the Payee Portal.
            </p>
            <xsl:if test="Artist/PayeeStatus/TotalOnline &gt; 0">
                <div class="Portal-invites-wrapper">
                    <p>
                        <strong><xsl:value-of select="Artist/PayeeStatus/InvitesSent" /></strong>
                        <xsl:choose>
                            <xsl:when test="Artist/PayeeStatus/InvitesSent = '1'">&#xA0;invite</xsl:when>
                            <xsl:otherwise>&#xA0;invites</xsl:otherwise>
                        </xsl:choose>
                        sent
                    </p>
                    <p>
                        <strong>
                            <xsl:value-of select="Artist/PayeeStatus/Unconfirmed" />
                        </strong>
                        waiting on confirmation &#xA0;
                        <xsl:if test="Artist/PayeeStatus/Unconfirmed &gt; 0">
                            <a href="#" id="openArtistPayeeResend">Resend</a>
                        </xsl:if>
                    </p>
                    <p>
                        <strong><xsl:value-of select="Artist/PayeeStatus/Confirmed" /></strong> confirmed
                    </p>
                </div>
            </xsl:if>
            <p>
                There are
                <strong>
                    <xsl:value-of select="Artist/PayeeRecipientStatus/Unconfirmed" />
                </strong>
                additional statement recipients waiting on confirmation
                <xsl:if test="Artist/PayeeRecipientStatus/Unconfirmed &gt; 0">
                    <a href="#" id="openArtistPayeeResendRecipients">Resend</a>
                </xsl:if>
            </p>
            <p>To view the current status of individual payees  and additional statement recipients, run a <a href="/rps/report/show?Group=Payees&amp;Type=Artist+%26+Producer">new Artist/Producer Payees report</a> on the Reports tab.</p>
        </section>
    </xsl:template>

    <xsl:template name="usPublisherPayeeTotalSection" >
        <section class="Portal-section TextNode">
            <h2>US Publisher Payee Status</h2>
            <p>
                <strong><xsl:value-of select="Publisher/PayeeStatus/TotalManual" /></strong>&#xA0;
                <xsl:choose>
                    <xsl:when test="Publisher/PayeeStatus/TotalManual = '1'">Payee has</xsl:when>
                    <xsl:otherwise>Payees have</xsl:otherwise>
                </xsl:choose>
                statement distribution set to Manual
            </p>
            <p>
                <strong><xsl:value-of select="Publisher/PayeeStatus/TotalOnline" /></strong>&#xA0;
                <xsl:choose>
                    <xsl:when test="Publisher/PayeeStatus/TotalOnline = '1'">Payee has</xsl:when>
                    <xsl:otherwise>Payees have</xsl:otherwise>
                </xsl:choose>
                statement distribution set to be delivered online through the Payee Portal.
            </p>
            <xsl:if test="Publisher/PayeeStatus/TotalOnline &gt; 0">
                <div class="Portal-invites-wrapper">
                    <p>
                        <strong><xsl:value-of select="Publisher/PayeeStatus/InvitesSent" /></strong>
                        <xsl:choose>
                            <xsl:when test="Publisher/PayeeStatus/InvitesSent = '1'">&#xA0;invite</xsl:when>
                            <xsl:otherwise>&#xA0;invites</xsl:otherwise>
                        </xsl:choose>
                        sent
                    </p>
                    <p>
                        <strong>
                            <xsl:value-of select="Publisher/PayeeStatus/Unconfirmed" />
                        </strong>
                        waiting on confirmation &#xA0;
                        <xsl:if test="Publisher/PayeeStatus/Unconfirmed &gt; 0">
                            <a href="#" id="openPublisherPayeeResend">Resend</a>
                        </xsl:if>
                    </p>
                    <p>
                        <strong><xsl:value-of select="Publisher/PayeeStatus/Confirmed" /></strong> confirmed
                    </p>
                </div>
            </xsl:if>
            <p>
                There are
                <strong>
                    <xsl:value-of select="Publisher/PayeeRecipientStatus/Unconfirmed" />
                </strong>
                additional statement recipients waiting on confirmation
                <xsl:if test="Publisher/PayeeRecipientStatus/Unconfirmed &gt; 0">
                    <a href="#" id="openPublisherPayeeResendRecipients">Resend</a>
                </xsl:if>
            </p>
            <p>To view the current status of individual payees  and additional statement recipients, run a <a href="/rps/report/show?Group=Payees&amp;Type=US+Publishers">new US Publisher Payees report</a> on the Reports tab.</p>
        </section>
    </xsl:template>

</xsl:stylesheet>
