if(typeof OTP=="undefined")var OTP=new function(){this.send=function(telnumber,token){if($("#telefono").val().length==0){$("#phoneMessage").show().html("
"+frasi.otp["telefonoMancante"]+"
");return}if(telnumber==$("#telefono"+"_old").val()){$("#phoneMessage").show().html("
"+frasi.otp["cambiareTelefono"]+"
");return}if(!this.validate(telnumber)){$("#phoneMessage").show().html("
"+frasi.otp["formatoTelefono"]+"
");return}$("#otpresult").html("").removeClass("invalid").removeClass("text-success"); $('[name="otpnum"]').val("");$("#checkotp").show();$("#phoneMessage").hide().html("");$("#otpSpinner").removeClass("hidden");$.ajax({url:"/wmsbackend.php",method:"POST",data:{cmd:"sendOTP",number:telnumber,captchaTokenWl:token},success:function(ret){$("#otpSpinner").addClass("hidden");var noModal=true;if(typeof ret!="undefined"&&ret!=""){var msg=JSON.parse(ret);if(msg.result){$("#confirmTel").html($("#telefono").val());$('[name="otpnum"]').first().trigger("focus");$("#phoneCheck").show();$("#telefono"+ "_otp").val(telnumber);noModal=false}else $("#phoneMessage").html("
"+msg.message+"
").show();if(msg.num&&msg.num>0)numTrySms=msg.num}else $("#phoneMessage").html("
"+frasi.otp["erroreInvioCodice"]+"
").show();onLoadCallback(noModal)},error:function(ret){$("#otpSpinner").addClass("hidden");$("#phoneMessage").html("
"+frasi.otp["erroreInvioCodice"]+"
").show()}})};this.verify=function(code,g_recaptcha_response){if(code.length==0){$("#otpresult").html(frasi.otp["codiceMancante"]).addClass("invalid"); return}if($("#telefono").closest(".form-group").find("span.invalid").is(":visible"))return;$("#otpresult").html("").removeClass("invalid").removeClass("text-success");$.ajax({url:"/wmsbackend.php",method:"POST",data:{cmd:"verifyOTP",code:code},success:function(ret){if(typeof ret!="undefined"&&ret!=""){var msg=JSON.parse(ret);if(msg.result){$("#phoneOtp").hide();$("#telefono").attr("readOnly",true).val($("#confirmTel").html());$("#telefono"+"_old").val($("#confirmTel").html());$("#phoneMod").show(); $("#otpchecknum").show();$("#otpresult").html(msg.message).addClass("text-success");setTimeout(function(){$("#otpModal").modal("hide")},1E3);$("#checkotp").hide();$("#otpDisclaimer").hide();$("#phoneCheck").hide();$("#telefonoValidato").hide();$("#toValidate").hide();var $nextStep=$('[name="nextStep"]');if($nextStep.length>0&&$nextStep.val()!="")$("#checkotp").closest("form").trigger("submit");$(".recaptcha").hide()}else $("#otpresult").html(msg.message).addClass("invalid")}else $("#otpresult").html(frasi.otp["erroreVerificaCodice"]).addClass("invalid")}, error:function(ret){$("#otpresult").html(frasi.otp["erroreVerificaCodice"]).addClass("invalid")}})};this.validate=function(number){var pattern=/\+\d*/;return pattern.exec(number)==number&&number.length>=10}};