var locamail=locamail||{},grecaptcha=grecaptcha||{};locamail.login=function(a){"use strict";var i;function o(a){return/^[a-z0-9_\-\.]{1,}@[a-z0-9_\-\.]{1,}\.[a-z]{1,}(\*[a-z_\-\.]{1,})*$/.test(a)}return i={forgotPasswordButton:"#forgotpass"},a(document).ready((function(){a.validator.methods.email=function(a,i){return this.optional(i)||o(a)},a("#loginform").validate({errorClass:"redborder",errorPlacement:function(a,i){a.addClass("errormessage"),"_user"===i.attr("name")?a.insertAfter("#userid"):"_pass"===i.attr("name")?a.insertAfter("#pwdid"):a.insertAfter(i)},highlight:function(i,o){"rcmloginuser"===i.id&&a("#userid").addClass(o),"rcmloginpwd"===i.id&&a("#pwdid").addClass(o)},unhighlight:function(i,o){"rcmloginuser"===i.id&&a("#userid").removeClass(o),"rcmloginpwd"===i.id&&a("#pwdid").removeClass(o)},wrapper:"span",rules:{_user:{required:{depends:function(){return a(this).val(a.trim(a(this).val())),!0}},email:!rcmail.env.domain},_pass:{required:!0}},messages:{_user:{required:rcmail.labels["locamail_translate.emptyemail"],email:rcmail.labels["locamail_translate.wrongdomain"]},_pass:{required:rcmail.labels["locamail_translate.emptypass"]}}})})),a("#submitloginform").on("click",(function(i){a("#loginform").validate(),a("#loginform").valid()||i.preventDefault()})),{init:function(){locaweb_utils.togglePassword(a("#showpass")),locamail.login._goToForgotPassword(),locamail.login._goBackLoginPage(),locamail.login._redirectToLogin(),locamail.login._verifyHasBanner(),locamail.login._submitForgotPassword(),locamail.login._removeAdvertsingFromDomain(),locamail.login._addEventListeners(),locamail.login.resendToken(),locamail.login.clickAlternativeEmailRadio()},changeSaveButton:function(){var i=a(".item-bar").hasClass("strong"),o=a("#recover-password-submit");o.attr("disabled","disabled"),i&&o.removeAttr("disabled")},resendToken:function(){a("#resend-token-button").on("click",(function(){a(this).addClass("lm-hide"),a("#wait-receive-token").removeClass("lm-hide"),rcmail.http_post("plugin.LocawebForgotPassword.resendTokenEmail",{_email:rcmail.env.email_user})}))},clickAlternativeEmailRadio:function(){a("#alternativeemail, #uncknowemail").on("click",(function(){a("#recover-pass").removeAttr("disabled")}))},_addRecaptcha:function(a){grecaptcha.execute(rcmail.env.recaptcha_site_key_v3,{action:"pre_forgot_password"}).then((function(i){a+="&_token="+i,rcmail.redirect(a)}),(function(){rcmail.log("Error on Recaptcha v3"),rcmail.redirect(a)}))},_isEmail:o,_goToForgotPassword:function(){a(i.forgotPasswordButton).on("click",(function(){locamail.login._addRecaptcha("./?_task=login&_action=plugin.LocawebForgotPassword.preForgotPassword")}))},_goBackLoginPage:function(){a("#backloginpage").on("click",(function(){rcmail.redirect("./?_task=login")}))},_redirectToLogin:function(){a("#back-to-webmail-button").on("click",(function(){rcmail.redirect("./?_task=login")}))},_verifyHasBanner:function(){"block"===a(".lm-login-banner").css("display")?(a(".lm-login-container").removeClass("no-banner").addClass("banner"),a(".lm-logo-label").removeClass("lm-hide")):a(".lm-login-container").removeClass("banner").addClass("no-banner")},_submitForgotPassword:function(){a("#preforgotpasswordform").on("submit",(function(){var i=a("#rcmloginuser"),e=i.val();rcmail.env.domain&&!o(e)&&i.val(e+"@"+rcmail.env.domain)}))},_removeAdvertsingFromDomain:function(){rcmail.env.domain&&(a(".lm-login-has-advertsing").removeClass("lm-login-has-advertsing"),a("#login-advertising-section").remove())},_addEventListeners:function(){rcmail.addEventListener("plugin.changeSaveButton",locamail.login.changeSaveButton)}}}(jQuery),rcmail.addEventListener("init",(function(){locamail.login.init()}));