<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/appuser/templates/global.xsl" />

    <xsl:include href="/app/tools/appuser/templates/passwordtoggle.xsl" />

    <xsl:template name="pickLayout">
        <xsl:if test="/Root/Portal = 1">
            <link href="/production/css/portal_login.css" media="screen" rel="stylesheet" type="text/css"></link>
        </xsl:if>
        <script src="/production/javascript/jquery/jquery-3.6.0.min.js"></script>
	    <xsl:choose>
            <xsl:when test="Form/ClientList/Client/ClientID">
                <xsl:call-template name="selectClientLayout" />
            </xsl:when>
            <xsl:when test="ForceUpdate">
                <xsl:call-template name="interstitial" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="mainLayout" />
            </xsl:otherwise>
	    </xsl:choose>
    </xsl:template>

    <xsl:template name="interstitial">
        <script type="text/javascript">
        x = document.getElementsByClassName("Layout-header-title");
        x[0].innerText="RoyaltyShare Security Update";
        </script>
        <p class="warningGeneral messageBox">
RoyaltyShare has updated its password management procedures and policies.<br/><br/>
As part of these changes, you will be required to set a new password based on updated requirements.  If you have access to multiple RoyaltyShare client sites, you will only need to change the password once and it will apply to all other accounts.<br/><br/>
Go <a href="/{$app}/login?c=changepw">here</a> to change your password.
<br/><br/>
If you have questions contact the RoyaltyShare support team at
<a href="mailto:support@royaltyshare.com">support@royaltyshare.com</a>.
        </p>
    </xsl:template>

    <xsl:template name="mainLayout">
        <xsl:if test="Params/portal">
            <span class="error">
                <p class="warningGeneral messageBox">Payee Portal user? Go <a href="https://portal.royaltyshare.com/">here</a> to log in. </p>
            </span>
        </xsl:if>

        <xsl:if test="ForceChange">
            <span class="error">
                <p class="warningGeneral messageBox">
</p>
            </span>
        </xsl:if>

        <div id="loginNotes1" class="Login-notes">
            <p>
                <strong>RoyaltyShare customers,</strong><br/>
                please enter your email address and password to access your account:
            </p>
        </div>

        <form id="login" name="login" action="/rps/login" method="post">
            <input type="hidden" name="submit" value="1" />
            <input type="hidden" name="redirect">
                <xsl:attribute name="value">
                    <xsl:choose>
                        <xsl:when test="normalize-space(Params/redirect)">
                            <xsl:value-of select="Params/redirect" />
                        </xsl:when>
                        <xsl:otherwise></xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
            </input>
            <script src="/production/javascript/validateLogin.js?v=1" type="text/javascript"></script>
            <xsl:choose>
                <xsl:when test="/Root/Form/Email/@e = 'user_locked'">
                    <xsl:call-template name="uiWarning">
                        <xsl:with-param name="type" select="'error'" />
                        <xsl:with-param name="className" select="'Login-general-error'" />
                        <xsl:with-param name="description">
                            <xsl:text>User locked out.  Please try again in 30 minutes.</xsl:text>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when test="/Root/Form/*[@e = 'failed_logins']">
                    <xsl:call-template name="uiWarning">
                        <xsl:with-param name="type" select="'error'" />
                        <xsl:with-param name="className" select="'Login-general-error'" />
                        <xsl:with-param name="description">
                            <xsl:text>Too many failed logins.</xsl:text>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when test="/Root/Form/Password[@e = 'token_invalid']">
                    <xsl:call-template name="uiWarning">
                        <xsl:with-param name="type" select="'error'" />
                        <xsl:with-param name="className" select="'Login-general-error'" />
                        <xsl:with-param name="description">
                            <xsl:text>Login session timeout.</xsl:text>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:when>
                <xsl:when test="/Root//*[@e]">
                    <xsl:call-template name="uiWarning">
                        <xsl:with-param name="type" select="'error'" />
                        <xsl:with-param name="className" select="'Login-general-error'" />
                        <xsl:with-param name="description">
                            <xsl:text>Invalid Email or Password.</xsl:text>
                        </xsl:with-param>
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                </xsl:otherwise>
            </xsl:choose>

            <fieldset>
                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">E-mail</span>
                        <div class="Form-input-wrapper">
                            <input type="text" class="Input Form-input" id="Form_Email" name="Form_Email" value="{Form/Email}" placeholder="Enter Your E-mail" />
                            <div class="Form-error-text-wrapper">
                                <span class="Form-error" id="ERRORForm_Email"></span>
                            </div>
                        </div>
                    </label>
                </div>
                <div class="Form-item">
                    <label class="Form-label">
                        <span class="Form-label-caption">Password</span>
                        <div class="Form-input-wrapper">
                            <input type="password" class="Input Form-input" id="Form_Password" name="Form_Password" placeholder="Enter Your Password" />
                            <div class="Form-error-text-wrapper">
                                <span class="Form-error" id="ERRORForm_Password"></span>
                            </div>
                        </div>
                    </label>
                </div>
            </fieldset>
            <xsl:call-template name="passwordToggleLogic"/>

            <p class="Restore-copy">
                <xsl:choose>
                    <xsl:when test="/Root/Portal = 1">
                        <a href="https://portal.royaltyshare.com/password/reset">Forgot Your Password?</a>
                    </xsl:when>
                    <xsl:otherwise>
                        <a href="/rps/forgotpw">Forgot Your Password?</a>
                    </xsl:otherwise>
                </xsl:choose>
            </p>

            <fieldset class="Form-fieldset Form-fieldset-buttons">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="'Login'" />
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="elemType" select="'submit'" />
                </xsl:call-template>
            </fieldset>

        </form>

        <div id="loginNotes3" class="Login-notes">
            <p>If you are not yet a RoyaltyShare customer, please <a href="http://www.royaltyshare.com/about-royalty-share/">click here</a> for more information on RoyaltyShare's unique services.</p>
            <p>If you experience problems while attempting to log in, please contact <a href="mailto:support@royaltyshare.com">customer support</a>.</p>
        </div>
        <div id="loginNotes2" class="Login-notes">
            <p><strong>Payee portal users,</strong><br/>Please go <a href="https://portal.royaltyshare.com/">here</a> to login and access your statements.</p>
        </div>
        <script language="JavaScript">
            if (typeof urlArray != 'undefined') {
                if (urlArray[2] === "login.royaltyshare.com") {
                    toggleLayer('loginNotes1');
                    toggleLayer('loginNotes2');
                    toggleLayer('loginNotes3');
                }
            }
        </script>


        <xsl:variable name="focusField">
            <xsl:choose>
                <xsl:when test="normalize-space(Form/Email)">Form_Password</xsl:when>
                <xsl:otherwise>Form_Email</xsl:otherwise>
            </xsl:choose>
        </xsl:variable>

        <script type="text/javascript">document.forms["login"].elements["<xsl:value-of select="$focusField" />"].focus();</script>

    </xsl:template>

    <xsl:template name="selectClientLayout">
        <form id="selectClient" name="selectLabel" method="post" action="/rps/login">
            <script src="/production/javascript/validateClient.js?v=1" type="text/javascript"></script>
            <input type="hidden" name="Form_Email" value="{Params/Email}" />
            <input type="hidden" name="Form_Password" value="{Params/Password}" />
            <input type="hidden" name="submit" value="1" />
            <input type="hidden" name="token" value="{Params/token}" />
            <p>You have successfully logged in but your account is associated with multiple labels.</p>
            <fieldset>
                <div class="Form-item">
                    <label class="Form-label">
                        <div class="Form-input-wrapper">
                            <xsl:variable name="selectClientList">
                                <map>
                                    <mapEntry><name>Choose...</name><value>0</value></mapEntry>
                                    <xsl:for-each select="Form/ClientList/Client">
                                        <mapEntry>
                                            <name><xsl:value-of select="ClientName" /></name>
                                            <value><xsl:value-of select="ClientID" /></value>
                                        </mapEntry>
                                    </xsl:for-each>
                                </map>
                            </xsl:variable>
                            <xsl:call-template name="uiDropdown">
                                <xsl:with-param name="items" select="$selectClientList"/>
                                <xsl:with-param name="id" select="'Form_ClientID'"/>
                                <xsl:with-param name="name" select="'Form_ClientID'"/>
                                <xsl:with-param name="active" select="AX"/>
                                <xsl:with-param name="className" select="'Form_ClientID_Select'"/>
                            </xsl:call-template>
                            <div class="Form-error-text-wrapper">
                                <span class="Form-error" id="ERRORForm_ClientID"></span>
                            </div>
                        </div>
                    </label>
                </div>
            </fieldset>
            <fieldset class="Form-fieldset Form-fieldset-buttons">
                <xsl:call-template name="uiButton">
                    <xsl:with-param name="content" select="'Go'" />
                    <xsl:with-param name="type" select="'primary'" />
                    <xsl:with-param name="className" select="'Form-button'" />
                    <xsl:with-param name="elemType" select="'submit'" />
                </xsl:call-template>
            </fieldset>
            <p>You can skip this step in the future by entering the label URL directly (e.g. labelname.royaltyshare.com).</p>
        </form>
    </xsl:template>

</xsl:stylesheet>
