<?php
if ( ! defined( 'ABSPATH' ) ) exit;
//include_once(dirname(dirname(__FILE__)).'/lib/emailotpauthn-external-class.php');
add_action( 'init', 'emailotpauthn_load_textdomain' );
function emailotpauthn_load_textdomain() {
	load_plugin_textdomain( "email-otp-authenticator", false, dirname( dirname( __FILE__ ) ) . "/languages" );
	global $formtexts;
	if(!isset($formtexts) || empty($formtexts))	emailotpauthn_load_notesntexts();
}

function emailotpauthn_load_notesntexts() {
	global $formtexts;
	$formtexts = array(
		array("Reserved Node","Reserved Node",""), //[0]
		array("Authenticate with OTP","Link Text",esc_html__("Authenticate with OTP","email-otp-authenticator")), //[1]
		array("OTP Verification","Form Titile",esc_html__("OTP Verification","email-otp-authenticator")), //[2]
		array("Send OTP","Button Text",esc_html__("Send OTP","email-otp-authenticator")), //[3]
		array("Verify OTP","Button Text",esc_html__("Verify OTP","email-otp-authenticator")), //[4]
		array("Wrong Action","Settings Notice",esc_html__("Wrong Action","email-otp-authenticator")), //[5]
		array("Enter your email to get the OTP","Label Text",esc_html__("Enter your email to get the OTP","email-otp-authenticator")), //[6]
		array("Get verification OTP at your email {{email address}}","Label Text",esc_html__("Get verification OTP at your email","email-otp-authenticator")), //[7]
		array("Logged in user cannot view or edit their email here.","Warning Notice",esc_html__("Logged in user cannot view or edit their email here.","email-otp-authenticator")), //[8]
		array("You have received new OTP to login at {{website title}}","Email Text",esc_html__("You have received new OTP to login at ","email-otp-authenticator")), //[9]
		array("We have received a one time password request.","Email Text",esc_html__("We have received a one time password request.","email-otp-authenticator")), //[10]
		array("Your new OTP is {{new OTP}}","Email Text",esc_html__("Your new OTP is ","email-otp-authenticator")), //[11]
		array("Website: {{your domain}}","Email Text",esc_html__("Website: ","email-otp-authenticator")), //[12]
		array("This secure OTP is generated by : {{Email OTP Authenticator}}","Email Text",esc_html__("This secure OTP is generated by : ","email-otp-authenticator")), //[13]
		array("Email OTP Authenticator","Email Text",esc_html__("Email OTP Authenticator","email-otp-authenticator")), //[14]
		array("Unacceptable email found. Unable to proceed.","Error Notice",esc_html__("Unacceptable email found. Unable to proceed.","email-otp-authenticator")), //[15]
		array("Wrong action for Logged-in user.","Settings Notice",esc_html__("Wrong action for Logged-in user.","email-otp-authenticator")), //[16]
		array("Wrong action detected. Report to the admin.","Settings Notice",esc_html__("Wrong action detected. Report to the admin.","email-otp-authenticator")), //[17]
		array("Service not activated.","Settings Notice",esc_html__("Service not activated.","email-otp-authenticator")), //[18]
		array("Email already exist.","Warning Notice",esc_html__("Email already exist.","email-otp-authenticator")), //[19]
		array("Email does not exist.","Warning Notice",esc_html__("Email does not exist.","email-otp-authenticator")), //[20]
		array("Request has been cancelled.","Hacking Notice",esc_html__("Request has been cancelled.","email-otp-authenticator")), //[21]
		array("Request has been rejected due to security! Please contact administrator.","Hacking Notice",esc_html__("Request has been rejected due to security! Please contact administrator.","email-otp-authenticator")), //[22]
		array("Validation error","Error Notice",esc_html__("Validation error","email-otp-authenticator")), //[23]
		array("Enter email","Label Text",esc_html__("Enter email","email-otp-authenticator")), //[24]
		array("SEND FROM email id is INACTIVE.","Settings Notice",esc_html__("SEND FROM email id is INACTIVE.","email-otp-authenticator")), //[25]
		array("Email does not match.","Error Notice",esc_html__("Email does not match.","email-otp-authenticator")), //[26]
		array("Resend OTP","Link Text",esc_html__("Resend OTP","email-otp-authenticator")), //[27]
		array("Post insertion failed!, please try again","Website Error",esc_html__("Post insertion failed!, please try again","email-otp-authenticator")), //[28]
		array("Unable to send email. Check SMTP or else.","Website Error",esc_html__("Unable to send email. Check SMTP or else.","email-otp-authenticator")), //[29]
		array("Out of Email Limit!, contact website administrator to reset.","Warning Notice",esc_html__("Out of Email Limit!, contact website administrator to reset.","email-otp-authenticator")), //[30]
		array("Out of Email Limit!, please try again after {{remaining minutes}}","Warning Notice",esc_html__("Out of Email Limit!, please try again after ","email-otp-authenticator")), //[31]
		array("{{remaining minutes}} minute.","Warning Notice",esc_html__(" minute.","email-otp-authenticator")), //[32]
		array("{{remaining minutes}} minutes.","Warning Notice",esc_html__(" minutes.","email-otp-authenticator")), //[33]
		array("OTP sent to your email.","Action Response",esc_html__("OTP sent to your email.","email-otp-authenticator")), //[34]
		array("OTP does not exist. Retry with new OTP.","Error Notice",esc_html__("OTP does not exist. Retry with new OTP.","email-otp-authenticator")), //[35]
		array("User does not match.","Error Notice",esc_html__("User does not match.","email-otp-authenticator")), //[36]
		array("The domain of your email is BLOCKED.","Warning Notice",esc_html__("The domain of your email is BLOCKED.","email-otp-authenticator")), //[37]
		array("The domain of your email is NOT ALLOWED.","Warning Notice",esc_html__("The domain of your email is NOT ALLOWED.","email-otp-authenticator")), //[38]
		array("Your email address is BLOCKED.","Warning Notice",esc_html__("Your email address is BLOCKED.","email-otp-authenticator")), //[39]
		array("This OTP is expired. Try again with new OTP.","Action Response",esc_html__("This OTP is expired. Try again with new OTP.","email-otp-authenticator")), //[40]
		array("Post insertion failed!, Token Key Not Generated.","Plugin Error",esc_html__("Post insertion failed!, Token Key Not Generated.","email-otp-authenticator")), //[41]
		array("You have successfully verified","Action Response",esc_html__("You have successfully verified","email-otp-authenticator")), //[42]
		array("OTP Matched","Action Response",esc_html__("OTP Matched","email-otp-authenticator")), //[43]
		array("Error in registration. Report to admin.","Website Error",esc_html__("Error in registration. Report to admin.","email-otp-authenticator")), //[44]
		array("Successfully Registered... Please Login.","Action Response",esc_html__("Successfully Registered... Please Login.","email-otp-authenticator")), //[45]
		array("You have been Successfully Registered.","Action Response",esc_html__("You have been Successfully Registered.","email-otp-authenticator")), //[46]
		array("Registered but Login failed. Try to Login.","Website Error",esc_html__("Registered but Login failed. Try to Login.","email-otp-authenticator")), //[47]
		array("You did not agree with our terms.","Warning Notice",esc_html__("You did not agree with our terms.","email-otp-authenticator")), //[48]
		array("Not Agree With Terms","Hacking Notice",esc_html__("Not Agree With Terms","email-otp-authenticator")), //[49]
		array("You have successfully logged in","Action Response",esc_html__("You have successfully logged in","email-otp-authenticator")), //[50]
		array("Agree to the terms of use.","Label Text",esc_html__("Agree to the terms of use.","email-otp-authenticator")), //[51]
		array("Unable to authenticate","Error Notice",esc_html__("Unable to authenticate","email-otp-authenticator")), //[52]
		array("OTP Matched but unable to process","Plugin Error",esc_html__("OTP Matched but unable to process","email-otp-authenticator")), //[53]
		array("Wrong OTP Attempts Crossed.","Warning Notice",esc_html__("Wrong OTP Attempts Crossed.","email-otp-authenticator")), //[54]
		array("OTP does not match.","Error Notice",esc_html__("OTP does not match.","email-otp-authenticator")), //[55]
		array("Invalid Email","Error Notice",esc_html__("Invalid Email","email-otp-authenticator")), //[56]
		array("Please accept our Terms of Use.","Error Notice",esc_html__("Please accept our Terms of Use.","email-otp-authenticator")), //[57]
		array("Check your spam mail and inbox again, then resend OTP.","Warning Notice",esc_html__("Check your spam mail and inbox again, then resend OTP.","email-otp-authenticator")), //[58]
		array("Invalid OTP","Error Notice",esc_html__("Invalid OTP","email-otp-authenticator")), //[59]
		array("Agree to the","Label Text",esc_html__("Agree to the","email-otp-authenticator")), //[60]
		array("terms of use","Label Text",esc_html__("terms of use","email-otp-authenticator")), //[61]
		array("Autofill my email","Label Text",esc_html__("Autofill my email","email-otp-authenticator")), //[62]
		array("Back","Button Text",esc_html__("Back","email-otp-authenticator")), //[63]
		array("Enter 6 digit code sent to your email","Label Text",esc_html__("Enter 6 digit code sent to your email","email-otp-authenticator")), //[64]
		array("<b>Error:</b> Invalid username, email address or incorrect password.","2FA Error Notice",esc_html__("Error: Invalid username, email address or incorrect password.","email-otp-authenticator")), //[65]
	);
}

function emailotpauthn_popup_extrnl_boxscript(){
	$emailotpauthnextrnlboxscript = 'function emailotpauthn_separat_box(pelm){
		var eotpa_in1 = $(pelm).find("#eotpa_otc-1")[0];
		var eotpainptdiv = $(pelm).find("#eotpainputdiv")[0];
		if(eotpainptdiv != null){
			var eotpa_ins = eotpainptdiv.querySelectorAll("input");
			var splitNumber = function(e) {
				var data = e.data || e.target.value;
				if(isNaN(data)) return;
				if ( ! data ) return;
				if ( data.length === 1 ) return;
				data = data.replace("-", "").replace(".", "");
				
				popuNext(e.target, data);
				//for (i = 0; i < data.length; i++ ) { eotpa_ins[i].value = data[i]; }
			};
			var popuNext = function(el, data) {
				el.value = data[0]; // Apply first item to first input
				data = data.substring(1); // remove the first char.
				if ( el.nextElementSibling && data.length ) {
					// Do the same with the next element and next data
					popuNext(el.nextElementSibling, data);
				}
			};

			eotpa_ins.forEach(function(input) {
				input.addEventListener("keyup", function(e){
					// Break if Shift, Tab, CMD, Option, Control.
					if (e.keyCode === 16 || e.keyCode == 9 || e.keyCode == 224 || e.keyCode == 18 || e.keyCode == 17) {
						 return;
					}
					
					// On Backspace or left arrow, go to the previous field.
					if ( (e.keyCode === 8 || e.keyCode === 37) && this.previousElementSibling && this.previousElementSibling.tagName === "INPUT" ) {
						this.previousElementSibling.select();
					} else if (e.keyCode !== 8 && this.nextElementSibling) {
						this.nextElementSibling.select();
					}
					
					// If the target is populated to quickly, value length can be > 1
					if ( e.target.value.length > 1 ) {
						splitNumber(e);
					}
					
					eotpa_updateInput(eotpa_ins,pelm);
					if(e.target.id=="eotpa_otc-6" && e.keyCode == 13) {
						$(pelm).find("#submitOtp").click();
					}

				});
				
				input.addEventListener("input", function(e){
					if ( e.target.value.length > 1 ) {
						splitNumber(e);
					}
					eotpa_updateInput(eotpa_ins,pelm);
				});
				
				input.addEventListener("focus", function(e) {
					// If the focus element is the first one, do nothing
					if ( this === eotpa_in1 ) return;
					
					// If value of input 1 is empty, focus it.
					if ( eotpa_in1.value == "" ) {
						eotpa_in1.focus();
					}
					
					// If value of a previous input is empty, focus it.
					// To remove if you don"t wanna force user respecting the fields order.
					if ( this.previousElementSibling.value == "" ) {
						this.previousElementSibling.focus();
					}
				});
			});

			eotpa_in1.addEventListener("input", splitNumber);
		}
	}

	function eotpa_updateInput(eotpa_insp,pelem) {
		var inputValue = Array.from(eotpa_insp).reduce(function (email_otp, input) {
		  email_otp += (input.value.length) ? input.value : "";
		  return email_otp;
		}, "");
		//$(pelem).find("#email_otp")[0].value = inputValue;
		$(pelem).find("#email_otp").val(inputValue);
	}';

	return $emailotpauthnextrnlboxscript;
}

function emailotpauthn_popup_extrnl_jvascript($getextrnlvars){
	global $eotpasettings;
	$emailotpauthnextrnlscript = 'var $ = jQuery;
	function emailotpauthnsubmitidrval(){
		var emailotpauthnsubmitidval = Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2);
		emailotpauthnsubmitidval = emailotpauthnsubmitidval.substring(0,30) + Math.floor(new Date().getTime() / 1000);
		return emailotpauthnsubmitidval;
	}
    function eotpaSetBackgroundImage(iseotpaform=false) {
	  var eotpabgelement = null;
	  if(iseotpaform)
		eotpabgelement = document.getElementById("emailotpauthn_formbg");
	  else
		eotpabgelement = document.getElementById("emailotpauthn_bdrpbg");

	  const imgUrl = window.getComputedStyle(eotpabgelement).getPropertyValue("background-image").replace(/url\([\'"]?(.*?)[\'"]?\)/, "$1");
      const img = new Image();
      img.src = imgUrl;

	  img.onload = function () {
        const screenWidth = window.innerWidth;
        const screenHeight = window.innerHeight;

        const imgWidth = img.width;
        const imgHeight = img.height;

        var repeatStyle = "no-repeat";
		var coveringtyp = "cover";
		
		const imgdetails = ((iseotpaform?"FormBgImg":"BackDropBgImg") + ": ImgWidth=" + imgWidth.toString() + "; ScreenWidth=" + screenWidth.toString() + "; ImgHeight=" + imgHeight.toString() + "; ScreenHeight=" + screenHeight.toString() + ";");

        //alert(imgdetails);
		//eotpabgelement.dataset.imgdtls = imgdetails.toString();
		if ((!iseotpaform && (imgWidth < screenWidth * 0.5 || imgHeight < screenHeight * 0.5)) || (iseotpaform && (imgWidth < screenWidth * 0.3 || imgHeight < screenHeight * 0.3))) {
          repeatStyle = "repeat";
		  coveringtyp = "auto";
        }

		const eotpainlinestyle = document.getElementById("emailotpauthn-inlinecss-inline-css");
		if (eotpainlinestyle && eotpainlinestyle.sheet) {
			const eotpainlinestyleSheet = eotpainlinestyle.sheet;
			for (let i = 0; i < eotpainlinestyleSheet.cssRules.length; i++) {
				const eotpastylerule = eotpainlinestyleSheet.cssRules[i];
				if (eotpastylerule instanceof CSSStyleRule && ((!iseotpaform && eotpastylerule.selectorText === "#emailotpauthn_bdrpbg") || (iseotpaform && eotpastylerule.selectorText === "#emailotpauthn_formbg"))) {
					eotpastylerule.style.backgroundRepeat = repeatStyle;
					eotpastylerule.style.backgroundSize = coveringtyp;
					break;
				}
			}
		}
      };
    }
	jQuery(document).ready(function() {
	// Edit this function before minify this javascript.
		var eotpaoverflowX = "";
		var eotpaoverflowY = "";
		var eotpanodesarry = [];
		function disableeotpasecurityelements(){
			const eotpanodes = document.querySelectorAll("a:not(#emailotpauthnlightbox a), button:not(#emailotpauthnlightbox button), input[type=\'button\']:not(#emailotpauthnlightbox input)");
			eotpanodesarry = [];
			try {
				eotpanodes.forEach((eotpaelem, indx) => {
					if(indx > 99) throw new Error("BreakLoop");
					eotpanodesarry.push(eotpaelem);
					if (eotpaelem.tagName.toLowerCase() === "a") {
						eotpaelem.setAttribute("data-eotpascrtydactvtd", eotpaelem.href);
						eotpaelem.removeAttribute("href");
					} else {
						eotpaelem.disabled = true;
					}
				});
			} catch (_error) {
			}
		}
		function enableeotpasecurityelements(){
			eotpanodesarry.forEach((eotpaelem, indx) => {
				if (eotpaelem.tagName.toLowerCase() === "a") {
					eotpaelem.setAttribute("href", eotpaelem.getAttribute("data-eotpascrtydactvtd"));
					eotpaelem.removeAttribute("data-eotpascrtydactvtd");
				} else {
					eotpaelem.disabled = false;
				}
			});
		}
		function srvrvls(clntvls){
			if(clntvls=="hideautofileml")
				clntvls = "'.esc_html($getextrnlvars["hideautofileml"]).'";
			else if(clntvls=="admin_url")
				clntvls = "'.admin_url('admin-ajax.php').'";
'.(($getextrnlvars["extrnlsection"]>1)?'
			else if(clntvls=="is_logged_in")
				clntvls = "'.esc_html($getextrnlvars["is_logged_in"]).'";
':'').(($getextrnlvars["extrnlsection"]>2)?'
			else if(clntvls=="rgstrshowterms")
				clntvls = "'.esc_html($getextrnlvars["rgstrshowterms"]).'";
			else if(clntvls=="is_2fa_redirect")
				clntvls = "'.esc_html($getextrnlvars["is_2fa_redirect"]).'";
':'').(($getextrnlvars["extrnlsection"]>1)?'
			else if(clntvls=="logged_in_email")
				clntvls = "'.esc_html($getextrnlvars["logged_in_email"]).'";
':'').'
			else
				clntvls = "";

			return clntvls;
		}

		jQuery(document).on("keyup", function(event){
			var pelmnt = $(event.target).closest(".emailotpauthninlinebox");
			if(pelmnt.length < 1){
				pelmnt = $(event.target).closest("#emailotpauthnlightbox");
				if(pelmnt.length < 1) return false;
			}
			if ($(event.target).is("#emailotpauthn-form #email")) {
				if(event.keyCode == 13) {
					$(pelmnt).find("#generateOtp").click();
				}
			} else if ($(event.target).is("#emailotpauthn-form #email_otp")) {
				if(event.keyCode == 13) {
					$(pelmnt).find("#submitOtp").click();
				}
			}
		});
		jQuery(document).on("click", "#emailotpauthn_lightbox .close span", function() { emailotpauthn_popup_close();jQuery("#emailotpauthnlightbox").html("");jQuery("#emailotpauthn_lightbox").hide().fadeOut(1000);});
'.(($getextrnlvars["extrnlsection"]>2)?'
		function emailotpauthn_showhide(){
			const eotpa_vactions = ["verify_user", "verify_all", "ratify_user", "ratify_all"];
			const eotpapopupelms = document.querySelectorAll(".emailotpauthn-popup");
			eotpapopupelms.forEach(eotpapopupelm => {
				var emailotpauthn_action = eotpapopupelm.dataset.emerge_action;
				var emailotpauthn_elemnt = (typeof emailotpauthn_action === "undefined") ? eotpapopupelm.querySelector("a") : eotpapopupelm;
				
				emailotpauthn_action = emailotpauthn_elemnt.dataset.emerge_action;
				emailotpauthn_action = (typeof emailotpauthn_action === "undefined") ? "" : emailotpauthn_action.toLowerCase().trim();

				var isloggedin = srvrvls("is_logged_in");
				if(emailotpauthn_action != ""){
					if(isloggedin == 1 && !eotpa_vactions.includes(emailotpauthn_action)) eotpapopupelm.style.display = "none";
				}
			});
			const eotpainlinelms = document.querySelectorAll(".emailotpauthninlinebox");
			eotpainlinelms.forEach(eotpainlinelm => {
				var emailotpauthn_action = eotpainlinelm.querySelector("#emailotpauthn-form #emailotpauthn_action").value;
				emailotpauthn_action = (typeof emailotpauthn_action === "undefined") ? "" : emailotpauthn_action.toLowerCase().trim();
				var isloggedin = srvrvls("is_logged_in");
				if(emailotpauthn_action != ""){
					if(isloggedin == 1 && !eotpa_vactions.includes(emailotpauthn_action)) eotpainlinelm.style.display = "none";
				}
			});
		}
		emailotpauthn_showhide();
':'').'
		var myhostnem = window.location.hostname;
		var underprocess = false;
		var emailotpauthnsubmitidrtval = emailotpauthnsubmitidrval();
		jQuery(document).on("click", ".generateOtp", function(event) {
			var pelm = $(event.target).closest(".emailotpauthninlinebox");
			if(pelm.length < 1){
				pelm = $(event.target).closest("#emailotpauthnlightbox");
				if(pelm.length < 1) return false;
			}
			if(document.activeElement.id=="email_otp" || document.activeElement.className=="eotpafni") {
				$(pelm).find("#submitOtp").click();
				return false;
			}
			if(underprocess) return false; else underprocess = true;
			var formid = "#emailotpauthn-form";
			event.preventDefault(); //prevent default action 
			$(pelm).find("#emailotpauthnsubmitid").val("A" + emailotpauthnsubmitidrtval);
			var emailid = $(pelm).find("#emailotpauthn-form #email").val();
			var email_otp = $(pelm).find("#emailotpauthn-form #email_otp").val();
			var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if(!regex.test(emailid))
			{
				$(pelm).find(".emailerror").text(" ' . esc_html( $getextrnlvars["extrnltxt_056"] ) . '");
				underprocess = false;
				return false;
			}else{
				//$(pelm).find("#cl-login #email").removeAttr("disabled");
				$(pelm).find(".emailerror").text("");
			}
'.(($getextrnlvars["extrnlsection"]>2)?'
			if($(pelm).find("#showrgstrterms").is(":visible") && ($(pelm).find("#emailotpauthn_action").val()=="register" || $(pelm).find("#emailotpauthn_action").val()=="combine")){
				if($(pelm).find("#showrgstrterms").prop("checked")) {
					$(pelm).find(".emailerror").text("");
				} else {
					$(pelm).find(".emailerror").text(" ' . esc_html( $getextrnlvars["extrnltxt_057"] ) . '");
					underprocess = false;
					return false;
				}
			}
':'').'
			var emps = emailid.split("@");
			var emaila = emps[0].length;
			var emailb = emps[1].length;
			var emailp = emailid.substr(0, 2).concat(emailid.substr(2, emaila - 4).replace(/./g, "*"), emailid.substr(emaila - 2, 2), "@", emailid.substr(emaila + 1, 1), emailid.substr(emaila + 1, emailb - 2).replace(/./g, "*"), emailid.substr(emaila + emailb));
			var emailboxtype = $(pelm).find("#emailotpauthn-form #email").attr("type");
			if( emailboxtype != "password" && $(pelm).find("#rememberemail").prop("checked")){
				window.localStorage.setItem("emailotpauthnemail" + myhostnem,emailid);
				window.localStorage.setItem("emailotpauthncheck" + myhostnem,"checked");
			}
			var post_url = srvrvls("admin_url"); //get form action url - http://localhost/wp/wp-admin/admin-ajax.php
			var request_method = $(pelm).find(formid).attr("method"); //get form GET/POST method
'.(($getextrnlvars["extrnlsection"]>1)?'
			var urlqueryString = window.location.search;
			urlqueryString = urlqueryString.replaceAll("?","").replaceAll("&","=").split("=");
			urlqueryString = urlqueryString.slice(-1)[0];
			if(urlqueryString.length > 20 && urlqueryString.length < 25) urlqueryString = "&urlgets=" + urlqueryString; else urlqueryString = "";
':'').'
			var form_data = $(pelm).find(formid).serialize()+ "&action=emailotpauthnaction&validateotp=0" + '.(($getextrnlvars["extrnlsection"]>1)?'urlqueryString':'""').'; //Encode form elements for submission
			jQuery.ajax({
				url : post_url,
				type: request_method,
				data : form_data,
				cache: false,
				processData: false,
			}).done(function(response){
				var data = JSON.parse(response);
				var divclass = "error text-danger";
				//alert(data.rspnum);
				underprocess = false;
				emailotpauthnsubmitidrtval = emailotpauthnsubmitidrval();
				if(! $(pelm).is(":visible")){
					$(pelm).fadeIn(100);
				}
				if(data.sendotp){
					divclass = "success text-success";
					$(pelm).find("#emailotpauthn_header_submit").hide();
					$(pelm).find("#emailotpauthn_header_verify").show();
					'.(($getextrnlvars["extrnlsection"]==4)?'$(pelm).find("form div:contains(\'Pb:\')").css("margin-top", "-15px");':'').'
					$(pelm).find("#sendotp").hide();
					$(pelm).find("#submitotpsec").show();
					$(pelm).find(".eotpafni").val("");
					$(pelm).find(formid+" #submitotpsec #email_otp").val("");
					$(pelm).find("#submitotpsec #sbmitedemail").text(emailp);
'.(($getextrnlvars["extrnlsection"]>1)?'
					$(pelm).find(".otpestatus").html("");
					if (typeof emailotpauthn_external_js_function === "function") {
						if (emailotpauthn_external_js_function.length == 2)
							emailotpauthn_external_js_function(1,emailid);
						else
							emailotpauthn_external_js_function(1,emailid,data.rspnum,data.response);
					}
					if($(pelm).find(".otpestatus").html() == ""){
':'').'
						$(pelm).find(formid+" .otpestatus").addClass(divclass).show("slow").html("").html(data.message);
'.(($getextrnlvars["extrnlsection"]>1)?'}':'').'
					if (typeof emailotpauthn_separat_box === "function") {
						emailotpauthn_separat_box(pelm);
					}
					var pelmn_email_otp = $(pelm).find(formid+" #submitotpsec #email_otp");
					if(pelmn_email_otp.is(":visible")){
						pelmn_email_otp.focus();
					} else {
						$(pelm).find(formid+" #submitotpsec .eotpafni").focus();
					}
					setTimeout(function(){$(pelm).find(formid+" .otpestatus").html("' . esc_html( $getextrnlvars["extrnltxt_058"] ) . '" + \' <input type="button" class="generateOtp" value="' . esc_html( $getextrnlvars["extrnltxt_027"] ) . '" name="resendotp" />\');},60000);
				}else{
					$(pelm).find(formid+" .emailerror").addClass(divclass).show().html("").html(data.message);
'.(($getextrnlvars["extrnlsection"]>1)?'
					$(pelm).find(".otpestatus").html("");
					if (typeof emailotpauthn_external_js_function === "function") {
						if (emailotpauthn_external_js_function.length == 2)
							emailotpauthn_external_js_function(0,"");
						else
							emailotpauthn_external_js_function(0,"",data.rspnum,data.response);
					}
					if($(pelm).find(".otpestatus").html() == ""){
						$(pelm).find(".otpestatus").html(data.response);
					}
':'').'
					console.log(data.response);
				}
			}).fail(function(jqXHR, textStatus, errorThrown) {
				var ajaxerror = "AJAX ERROR: " + textStatus + " - " + errorThrown;
				jQuery(formid+" .emailerror").addClass(divclass).show().html("").html(ajaxerror);
				jQuery(".otpestatus").html("");
				if(jQuery(".otpestatus").html() == ""){
					jQuery(".otpestatus").html(ajaxerror);
				}
				console.log(ajaxerror);
			});
		});
		//validate otp
'.(($getextrnlvars["extrnlsection"]>1)?'
		/*
		// Use this function in client side javascript to operate the process after successful/failure OTP authentication attempt.
		function emailotpauthn_external_js_function(response_status, user_email, response_code, response_message){
			// response_status = 0 for failure attempt and 1 for successful attempt.
			//if(response_code == 11) jQuery(".otpestatus").html(response_message);
		}
		*/
':'').'
		jQuery(document).on("click", "#submitOtp", function(event){
			var pelm = $(event.target).closest(".emailotpauthninlinebox");
			if(pelm.length < 1){
				pelm = $(event.target).closest("#emailotpauthnlightbox");
				if(pelm.length < 1) return false;
			}
'.(($getextrnlvars["extrnlsection"]>1)?'
			if(underprocess) return false; else underprocess = true;
':'').'
			var formid = "#emailotpauthn-form";
			event.preventDefault(); //prevent default action 
			$(pelm).find("#emailotpauthnsubmitid").val("B" + emailotpauthnsubmitidrtval);
			var emailid = $(pelm).find("#emailotpauthn-form #email").val();
			var email_otp = $(pelm).find("#emailotpauthn-form #email_otp").val();
			var compare=/^[0-9]{6}$/g;
			if(email_otp=="" || !compare.test(email_otp))
			{
				$(pelm).find(".otperror").html(" ' . esc_html( $getextrnlvars["extrnltxt_059"] ) . '");
				underprocess = false;
				return false;
			}else{
				//$(pelm).find("#emailotpauthn-form #email_otp").removeAttr("disabled");
				$(pelm).find(".otperror").html("");
			}
'.(($getextrnlvars["extrnlsection"]>1)?'
			var urlqueryString = window.location.search;
			urlqueryString = urlqueryString.replaceAll("?","").replaceAll("&","=").split("=");
			urlqueryString = urlqueryString.slice(-1)[0];
			if(urlqueryString.length > 20 && urlqueryString.length < 25) urlqueryString = "&urlgets=" + urlqueryString; else urlqueryString = "";
':'').'
			var form_data = $(pelm).find(formid).serialize()+ "&action=emailotpauthnaction&validateotp=1" + '.(($getextrnlvars["extrnlsection"]>1)?'urlqueryString':'""').';
			var pelm_email_otp = $(pelm).find(formid+" #submitotpsec #email_otp");
			pelm_email_otp.val("");
			var post_url = srvrvls("admin_url");
			jQuery.ajax({
				url : post_url,
				type: "POST",
				data : form_data,
				cache: false,             
				processData: false, 
			}).done(function(response){ //
				underprocess = false;
				emailotpauthnsubmitidrtval = emailotpauthnsubmitidrval();
				var data = JSON.parse(response);
				var redirecturl = "";
				$(pelm).find("#submitotpsec #email_otp").val("");
				$(pelm).find(".eotpafni").val("");
				//alert(data.rspnum);
				if(data.status){
					divclass = "success text-success";
'.(($getextrnlvars["extrnlsection"]>1)?'
					$(pelm).find(".otpestatus").html("");
					if (typeof emailotpauthn_external_js_function === "function") {
						var rspstts = data.rspnum;
						if(rspstts == 12)
							rspstts = 2;
						else if(rspstts == 13)
							rspstts = 3;
						else if(rspstts == 21)
							rspstts = 4;
						else
							rspstts = 5;
						if (emailotpauthn_external_js_function.length == 2)
							emailotpauthn_external_js_function(rspstts,emailid);
						else
							emailotpauthn_external_js_function(rspstts,emailid,data.rspnum,data.response);
					}
					if($(pelm).find(".otpestatus").html() == ""){
						$(pelm).find(".otpestatus").html(data.message);
					}
':'
					$(pelm).find(".otpestatus").html(data.message);
').'
					redirecturl = data.redirect;
					if(typeof redirecturl !== "undefined")
					{
						document.location.href = redirecturl;
					}
					emailotpauthn_popup_close();
				}else{
'.(($getextrnlvars["extrnlsection"]>1)?'
					$(pelm).find(".otpestatus").html("");
					if (typeof emailotpauthn_external_js_function === "function") {
						if (emailotpauthn_external_js_function.length == 2)
							emailotpauthn_external_js_function(0,"");
						else
							emailotpauthn_external_js_function(0,"",data.rspnum,data.response);
					}
					if($(pelm).find(".otpestatus").html() == ""){
						$(pelm).find(".otpestatus").html(data.message);
					}
					redirecturl = data.redirect;
					if(typeof redirecturl !== "undefined")
					{
						document.location.href = redirecturl;
					}
':'
					$(pelm).find(".otpestatus").html(data.message);
').'
					if(pelm_email_otp.is(":visible")){
						pelm_email_otp.focus();
					} else {
						$(pelm).find(formid+" #submitotpsec .eotpafni")[0].focus();
					}
				}
			}).fail(function(jqXHR, textStatus, errorThrown) {
				var ajaxerror = "AJAX ERROR: " + textStatus + " - " + errorThrown;
				jQuery(formid+" .emailerror").addClass(divclass).show().html("").html(ajaxerror);
				jQuery(".otpestatus").html("");
				if(jQuery(".otpestatus").html() == ""){
					jQuery(".otpestatus").html(ajaxerror);
				}
				if(pelm_email_otp.is(":visible")){
					pelm_email_otp.focus();
				} else {
					$(pelm).find(formid+" #submitotpsec .eotpafni")[0].focus();
				}
				console.log(ajaxerror);
			});
		});
		jQuery(document).on("click", ".loginback",function(event){
			var pelm = $(event.target).closest(".emailotpauthninlinebox");
			if(pelm.length < 1){
				pelm = $(event.target).closest("#emailotpauthnlightbox");
				if(pelm.length < 1) return false;
			}
'.(($getextrnlvars["extrnlsection"]>1)?'
			underprocess = false;
			var premail = srvrvls("logged_in_email");
			var isloggedin = srvrvls("is_logged_in");
':'').'
			//$(pelm).find("#emailotpauthn-form #email").val("");
			$(pelm).find("#submitotpsec #email_otp").val("");
			$(pelm).find("#emailotpauthnsubmitid").val("");
			$(pelm).find(".eotpafni").val("");
			$(pelm).find(".emailerror").html("");
			$(pelm).find(".otperror").html("");
			$(pelm).find(".otpestatus").html("");
			$(pelm).find("#sendotp").show();
			$(pelm).find("#submitotpsec").hide();
			$(pelm).find("#emailotpauthn_header_verify").hide();
			$(pelm).find("#emailotpauthn_header_submit").show();
			'.(($getextrnlvars["extrnlsection"]==4)?'$(pelm).find("form div:contains(\'Pb:\')").css("margin-top", "-15px");':'').'
'.(($getextrnlvars["extrnlsection"]>1)?'
			if(isloggedin == 0) {
				premail = window.localStorage.getItem("emailotpauthnemail" + myhostnem);
				if(premail == null) premail = "";
			}
			$(pelm).find("#email").val(premail);
':'').'
		});
		jQuery(document).on("click", "#terms_of_use", function(event){
			var parentelement = $(event.target).parent();
			var targetelement = $(parentelement).find("#showrgstrterms");
			targetelement.click();
		});
		jQuery(document).on("click", "#remember_email", function(event){
			var parentelement = $(event.target).parent();
			var targetelement = $(parentelement).find("#rememberemail");
			targetelement.click();
		});
		jQuery(document).on("click", "#rememberemail", function(event){
			if(! $(event.target).prop("checked")) {
				window.localStorage.removeItem("emailotpauthnemail" + myhostnem);
				window.localStorage.removeItem("emailotpauthncheck" + myhostnem);
			}
		});
		jQuery(".emailotpauthn-popup a").click(function(e) {
			if ($("#emailotpauthnlightbox").length < 1) {
				return false;
			}
			if($("#emailotpauthnlightbox #emailotpauthn_content").is(":visible")) {
				return false;
			}
			e.preventDefault();
			var targetelement = $(e.target).closest(".emailotpauthn-popup");
			var putclosebox = ! targetelement.hasClass("noclosebox");
'.(($getextrnlvars["extrnlsection"]>2)?'
			var emailotpauthn_action = targetelement.data("emerge_action");
			var emailotpauthn_elemnt = (typeof emailotpauthn_action === "undefined") ? targetelement.find("a") : targetelement;
			
			var emlotp_data = emailotpauthn_elemnt.data();
			var header_submit = (typeof emlotp_data["header_submit"] === "undefined") ?  "" : $.trim(emlotp_data["header_submit"]);
			var header_verify = (typeof emlotp_data["header_verify"] === "undefined") ?  "" : $.trim(emlotp_data["header_verify"]);
			var button_submit = (typeof emlotp_data["button_submit"] === "undefined") ?  "" : $.trim(emlotp_data["button_submit"]);
			var button_verify = (typeof emlotp_data["button_verify"] === "undefined") ?  "" : $.trim(emlotp_data["button_verify"]);
			var emlotp_action = (typeof emlotp_data["emerge_action"] === "undefined") ?  "" : $.trim(emlotp_data["emerge_action"]);
			header_submit = (header_submit=="") ? "' . esc_html( $getextrnlvars["extrnltxt_002"] ) . '" : header_submit.substring(0,30);
			header_verify = (header_verify=="") ? "' . esc_html( $getextrnlvars["extrnltxt_002"] ) . '" : header_verify.substring(0,30);
			button_submit = (button_submit=="") ? "' . esc_html( $getextrnlvars["extrnltxt_003"] ) . '" : button_submit.substring(0,15);
			button_verify = (button_verify=="") ? "' . esc_html( $getextrnlvars["extrnltxt_004"] ) . '" : button_verify.substring(0,15);
			emlotp_action = (emlotp_action=="") ? "" : emlotp_action.toLowerCase();
			var isshowterm = srvrvls("rgstrshowterms");
':'').'
			var emailotpauthninlineboxs = jQuery("#emailotpauthnBox");
			var emailotpauthn_lightbox_content = "";
			emailotpauthninlineboxs.each(function(vi,vn){
			var isshwnterm = false;
'.(($getextrnlvars["extrnlsection"]>2)?'
				if(emlotp_action == ""){
					$(vn).find("#showrgstrtermsdiv").hide();
				} else {
					if(isshowterm == 1 && (emlotp_action == "register" || emlotp_action == "combine")){
						$(vn).find("#showrgstrtermsdiv").show();
						isshwnterm = true;
					} else {
						$(vn).find("#showrgstrtermsdiv").hide();
					}
				}
				if($(vn).find("#emailotpauthn_header_submit").hasClass("this_code_is_important")==false){
					$(vn).find("#emailotpauthn_header_submit").text(header_submit);
					$(vn).find("#emailotpauthn_header_verify").text(header_verify);
					$(vn).find("#generateOtp").val(button_submit);
					$(vn).find("#submitOtp").val(button_verify);
				}
				$(vn).find("#emailotpauthn_action").val(emlotp_action);
':'').'
				var ishideaeml = srvrvls("hideautofileml");
				if(ishideaeml == 1){
					if(isshwnterm){
						$(vn).find("#showrmbremaildiv").hide();
					} else {
						$(vn).find("#rememberemaildiv").hide();
					}
				}
				$(vn).find("#emailotpauthn-form #email").val("");
				$(vn).find("#submitotpsec #email_otp").val("");
				$(vn).find("#emailotpauthnsubmitid").val("");
				'.(($getextrnlvars["extrnlsection"]==4)?'$(vn).find("form div:contains(\'Pb:\')").css("margin-top", "-15px");':'').'
				$(vn).find(".eotpafni").val("");
				$(vn).find(".emailerror").html("");
				$(vn).find(".otperror").html("");
				$(vn).find(".otpestatus").html("");
				
				var content =$(vn).find("#emailotpauthn_contact").html();
				emailotpauthn_lightbox_content = "<div id=\"emailotpauthn_lightbox\"><div id=\"emailotpauthn_bdrpbg\" data-imgdtls=\"None\"></div><div id=\"emailotpauthn_lightbg\"></div><div id=\"emailotpauthn_content\">";
				if(putclosebox) {
					emailotpauthn_lightbox_content = emailotpauthn_lightbox_content + "<div class=\"close wp-exclude-emoji\"><span>&#x2716;</span></div>";
				}
				emailotpauthn_lightbox_content = emailotpauthn_lightbox_content + content + "</div></div>";
				var defemailadr = window.localStorage.getItem("emailotpauthnemail" + myhostnem);
				var defcheckbox = window.localStorage.getItem("emailotpauthncheck" + myhostnem);
				if(defemailadr == null) defemailadr = "";
				if(defcheckbox == null) defcheckbox = "";
				if (emailotpauthn_lightbox_content.includes(\'type="password"\') ) 
					emailotpauthn_lightbox_content = emailotpauthn_lightbox_content.replace(\'id="rememberemaildiv"\',\'id="rememberemaildiv" style="display:none!important;"\');
				emailotpauthn_lightbox_content = emailotpauthn_lightbox_content.replace(\'id="email" value=""\',\'id="email" value="\' + defemailadr + \'"\');
				emailotpauthn_lightbox_content = emailotpauthn_lightbox_content.replace(\'id="rememberemail"\',\'id="rememberemail" \' + defcheckbox);
				//insert lightbox HTML into page
				if($(vn).find("#generateOtp").val().toLowerCase() == "2fa"){
					jQuery("#emailotpauthnlightbox").append(emailotpauthn_lightbox_content).hide();
				} else {
					emailotpauthn_popup_open();
					jQuery("#emailotpauthnlightbox").append(emailotpauthn_lightbox_content).hide().fadeIn(100);
				}
			});
			/*
			if (typeof emailotpauthn_separat_box === "function") {
				emailotpauthn_separat_box();
			}
			*/
		});
		function emailotpauthn_inlineformload() {
			if ($(".emailotpauthninlinebox").length < 1) {
				return false;
			}
			var emailotpauthninlineboxs = jQuery(".emailotpauthninlinebox");
			emailotpauthninlineboxs.each(function(vi,vn){
				var isshwnterm = false;
'.(($getextrnlvars["extrnlsection"]>2)?'
				var emlotp_action = jQuery(vn).find("#emailotpauthn-form #emailotpauthn_action").val();
				var isshowterm = srvrvls("rgstrshowterms");
				if(emlotp_action == ""){
					$(vn).find("#showrgstrtermsdiv").hide();
				} else {
					if(isshowterm == 1 && (emlotp_action == "register" || emlotp_action == "combine")){
						$(vn).find("#showrgstrtermsdiv").show();
						isshwnterm = true;
					} else {
						$(vn).find("#showrgstrtermsdiv").hide();
					}
				}
':'').'
				var ishideaeml = srvrvls("hideautofileml");
				if(ishideaeml == 1){
					if(isshwnterm){
						$(vn).find("#showrmbremaildiv").hide();
					} else {
						$(vn).find("#rememberemaildiv").hide();
					}
				}
				$(vn).find("#emailotpauthn-form #email").val("");
				$(vn).find("#submitotpsec #email_otp").val("");
				$(vn).find("#emailotpauthnsubmitid").val("");
				'.(($getextrnlvars["extrnlsection"]==4)?'jQuery("form div:contains(\'Pb:\')").css("margin-top", "-15px");':'').'
				$(vn).find(".eotpafni").val("");
				$(vn).find(".emailerror").html("");
				$(vn).find(".otperror").html("");
				$(vn).find(".otpestatus").html("");

				var emailotpauthn_inlinebox_content = "<div id=\"emailotpauthn_content\">" + $(vn).find("#emailotpauthn_contact").html() + "</div>";
				//prompt("",emailotpauthn_inlinebox_content);
				var defemailadr = window.localStorage.getItem("emailotpauthnemail" + myhostnem);
				var defcheckbox = window.localStorage.getItem("emailotpauthncheck" + myhostnem);
				if(defemailadr == null) defemailadr = "";
				if(defcheckbox == null) defcheckbox = "";
				if (emailotpauthn_inlinebox_content.includes(\'type="password"\') ) 
					emailotpauthn_inlinebox_content = emailotpauthn_inlinebox_content.replace(\'id="rememberemaildiv"\',\'id="rememberemaildiv" style="display:none!important;"\');
				emailotpauthn_inlinebox_content = emailotpauthn_inlinebox_content.replace(\'id="email" value=""\',\'id="email" value="\' + defemailadr + \'"\');
				emailotpauthn_inlinebox_content = emailotpauthn_inlinebox_content.replace(\'id="rememberemail"\',\'id="rememberemail" \' + defcheckbox);
				$(vn).find("#emailotpauthn_contact").html(emailotpauthn_inlinebox_content);
				//alert(vi+":"+vn.innerHTML)
			});
			/*
			if (typeof emailotpauthn_separat_box === "function") {
				emailotpauthn_separat_box();
			}
			*/
		}
'.(($getextrnlvars["extrnlsection"]>2)?'
		function emailotpauthn_2faformload() {
			var email2fardrct = srvrvls("is_2fa_redirect");
			if(email2fardrct > 0){
				var email2fa = srvrvls("logged_in_email");
				if(email2fa.length > 1){
					var is_sc_link = false;
					var eotpa2faform = "";
					var eotpa2faspan = document.querySelector(\'.emailotpauthn-popup[data-button_submit="2fa"]\');
					if(eotpa2faspan == null) {
						eotpa2faform = $("#emailotpauthninlinebox2fa");
						if(eotpa2faform.length < 1) return false;
					} else {
						//eotpa2faspan.dataset.emerge_action = "";
						var eotpa2falink = eotpa2faspan.getElementsByTagName("a")[0];
						if(eotpa2falink == null) {
							return false;
						} else {
							is_sc_link = true;
							eotpa2falink.click();
							eotpa2faform = $("#emailotpauthnlightbox");
							if(eotpa2faform.length < 1) return false;
						}
					}
					$(eotpa2faform).find("#emailotpauthn-form #email").val(email2fa);
					$(eotpa2faform).find("#generateOtp").click();
					$(eotpa2faform).find("#emailotpauthn-form #email").attr("type", "password");
					$(eotpa2faform).find("#generateOtp").val("******");
					if(is_sc_link){
						jQuery("#emailotpauthnlightbox").hide().fadeIn(100);
					}else{
						jQuery("#emailotpauthninlinebox2fa").hide().fadeIn(100);
					}
					return true;
				}
			}
			return false;
		}
':'').'
		function emailotpauthn_autopopupload() {
			var eotpa2faspan = document.querySelector(".emailotpauthn-popup.autopopup");
			if(eotpa2faspan != null) {
				var eotpa2falink = eotpa2faspan.getElementsByTagName("a")[0];
				if(eotpa2falink != null) {
					eotpa2falink.click();
					return true;
				}
			}
			return false;
		}
		function emailotpauthn_popup_open() {
'.(($getextrnlvars["hidescrollbars"]==1)?'
			if(!eotpaoverflowX) eotpaoverflowX = document.body.style.overflowX;
			if(!eotpaoverflowY) eotpaoverflowY = document.body.style.overflowY;
			if(!eotpaoverflowX) eotpaoverflowX = window.getComputedStyle(document.body).overflowX;
			if(!eotpaoverflowY) eotpaoverflowY = window.getComputedStyle(document.body).overflowY;
			if(eotpaoverflowX) document.body.style.overflowX = "hidden";
			if(eotpaoverflowY) document.body.style.overflowY = "hidden";
':'
			return true; //to bypass the empty function.
').'
		}
		function emailotpauthn_popup_close() {
'.(($getextrnlvars["hidescrollbars"]==1)?'
			if(eotpaoverflowX) document.body.style.overflowX = eotpaoverflowX;
			if(eotpaoverflowY) document.body.style.overflowY = eotpaoverflowY;
':'').'
			enableeotpasecurityelements();
		}
		function emailotpauthn_auto_2fa_inline_load() {
			emailotpauthn_inlineformload();
'.(($getextrnlvars["extrnlsection"]>2)?'
			var is_autoppup_found = emailotpauthn_2faformload();
':'
			var is_autoppup_found = false;
').'
			if(! is_autoppup_found) is_autoppup_found = emailotpauthn_autopopupload();
			if(is_autoppup_found) {
				emailotpauthn_popup_open();
				disableeotpasecurityelements();
			}
			eotpaSetBackgroundImage(true);
			eotpaSetBackgroundImage();
		}
		emailotpauthn_auto_2fa_inline_load();
	});';
	return $emailotpauthnextrnlscript;
}

function emailotpauthn_getbordercolor($brdrclr){
	$hdn1 = 0;
	$hdn2 = 0;
	$hdn3 = 0;
	$hdn4 = "";
	$rtrnbrdrclr = str_replace("#","",$brdrclr);
	if(strlen($rtrnbrdrclr)==6 || strlen($rtrnbrdrclr)==8){
		$hdn1 = hexdec(substr($rtrnbrdrclr,0,2));
		if($hdn1 > 130) $hdn1 -= 40; else $hdn1 += 40;
		$hdn2 = hexdec(substr($rtrnbrdrclr,2,2));
		if($hdn2 > 130) $hdn2 -= 40; else $hdn2 += 40;
		$hdn3 = hexdec(substr($rtrnbrdrclr,4,2));
		if($hdn3 > 130) $hdn3 -= 40; else $hdn3 += 40;
		if(strlen($rtrnbrdrclr)==8) $hdn4 = substr($rtrnbrdrclr,6,2); else $hdn4 = "FF";
		$rtrnbrdrclr = "#". str_pad(dechex($hdn1),2,"0",STR_PAD_LEFT) . str_pad(dechex($hdn2),2,"0",STR_PAD_LEFT) . str_pad(dechex($hdn3),2,"0",STR_PAD_LEFT) . $hdn4;
	} else {
		$rtrnbrdrclr = "#" . $rtrnbrdrclr;
	}
	return $rtrnbrdrclr;
}
function emailotpauthn_getcolorfrmstyle($stylestr){
	$stylestr = str_replace(" ","",$stylestr);
	$colorpos = stripos($stylestr,";color:");
	$stylestr = substr($stylestr,$colorpos+7);
	$colorpos = stripos($stylestr,";");
	$stylestr = substr($stylestr,0,$colorpos);
	return $stylestr;
}
function emailotpauthn_getopacityfrmclr($colorstr){
	$colorstr = str_replace("#","",$colorstr);
	if(strlen($colorstr) > 6){
		$colorstr = substr($colorstr,6,2);
	} else {
		$colorstr = "ff";
	}
	$colorval = round((hexdec($colorstr)/255)*100);
	return $colorval;
}
function emailotpauthn_popup_extrnl_css($getextrnlvars){
	$inptbrdrclr = emailotpauthn_getbordercolor($getextrnlvars["inptbxcolor"]);
	$butnbrdrclr = emailotpauthn_getbordercolor($getextrnlvars["buttoncolor"]);

	$emailotpauthnextrnlcss = '';
	if(!$getextrnlvars["isoneinputbox"]) $emailotpauthnextrnlcss = '#emailotpauthn_content .eotpafni:-webkit-autofill,#emailotpauthn_content .eotpafni:-webkit-autofill:hover,#emailotpauthn_content .eotpafni:-webkit-autofill:focus,#emailotpauthn_content .eotpafni:-webkit-autofill:active,#emailotpauthn_content .eotpafni {width:1.1em;line-height:1;margin:0px 7px;padding:0px 0px 2px 0px;text-align:center;appearance:textfield;display:inline-block;' . esc_html( $getextrnlvars["inptxtstyle"] ) . 'font-size:2em!important;background:' . esc_html( $getextrnlvars["inptbxcolor"] ) . '!important;border:' . (($getextrnlvars["frmbrdrwdth"]>0 && emailotpauthn_getopacityfrmclr($getextrnlvars["inptbxcolor"])<5)? $getextrnlvars["frmbrdrwdth"] . 'px solid '. $getextrnlvars["frmbrdrcolr"] : '2px solid ' . esc_html( $inptbrdrclr ) ) . ';border-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'6').'px;}';

    $emailotpauthnextrnlcss = '#emailotpauthn_content>*,#emailotpauthn_content>*>*,#emailotpauthn_content>*>*>*,#emailotpauthn_content>*>*>*>*,#emailotpauthn_content>*>*>*>*>*,#emailotpauthn_content>*>*>*>*>*>*{/*all:initial;all:unset;all:revert;*/font-family:Verdana,sans-serif;font-weight:normal;text-decoration:none;}form#emailotpauthn-form{position:relative}#emailotpauthn-body{border-bottom-left-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'25').'px;border-bottom-right-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'25').'px;padding:30px;min-height:200px;background: ' . esc_html( $getextrnlvars["bodybgcolor"] ) . ';'.(($getextrnlvars["poppboxblur"]>0)?'backdrop-filter:blur(' . esc_html( $getextrnlvars["poppboxblur"] ) . 'px);':'').'}#submitotpsec{display:none}' . ( $emailotpauthnextrnlcss ) . '.emailotpauthninlinebox #emailotpauthn_content form label, #emailotpauthn_lightbox #emailotpauthn_content form label,{' . esc_html( $getextrnlvars["bodyxtstyle"] ) . 'display:block;}#email_message,#otp_message,#sbmitedemail{' . esc_html( $getextrnlvars["bodyxtstyle"] ) . 'display:inline-block;}span.loginback{cursor:pointer;z-index:99;top:6px;position:absolute;left:0;padding:2px 15px;' . esc_html( $getextrnlvars["hedrxtstyle"] ) . 'font-size:0.7em!important;}.emailotpauthninlinebox #emailotpauthn_content form .req,#emailotpauthn_lightbox #emailotpauthn_content form .req{color:' . esc_html( $getextrnlvars["frmnoticclr"] ) . ';font-size:' . esc_html( $getextrnlvars["frmnoticsiz"] ) . 'em;display:inline-block}.emailotpauthninlinebox #emailotpauthn_content .eotpafi,#emailotpauthn_lightbox #emailotpauthn_content .eotpafi,.emailotpauthninlinebox #emailotpauthn_content form textarea,#emailotpauthn_lightbox #emailotpauthn_content form textarea{border-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'50').'px;border:' . (($getextrnlvars["frmbrdrwdth"]>0 && emailotpauthn_getopacityfrmclr($getextrnlvars["inptbxcolor"])<5)? $getextrnlvars["frmbrdrwdth"] . 'px solid '. $getextrnlvars["frmbrdrcolr"] : '2px solid ' . esc_html( $inptbrdrclr ) ) . ';' . esc_html( $getextrnlvars["inptxtstyle"] ) . 'display:inline-block!important;width:100%!important;min-height:40px;padding:0 10px}.emailotpauthn-req-fields:-webkit-autofill,.emailotpauthn-req-fields:-webkit-autofill:hover,.emailotpauthn-req-fields:-webkit-autofill:focus,.emailotpauthn-req-fields:-webkit-autofill:active,.input_otp:-webkit-autofill,.input_otp:-webkit-autofill:hover,.input_otp:-webkit-autofill:focus,.input_otp:-webkit-autofill:active,.emailotpauthn-req-fields,.input_otp{text-align:center!important;background:' . esc_html( $getextrnlvars["inptbxcolor"] ) . '!important;}.emailotpauthninlinebox #emailotpauthn_content form input[type=button],#emailotpauthn_lightbox #emailotpauthn_content form input[type=button]{border-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'50').'px;background:' . esc_html( $getextrnlvars["buttoncolor"] ) . ';'.(($getextrnlvars["poppboxblur"]>0)?'backdrop-filter:blur(' . esc_html( $getextrnlvars["poppboxblur"] ) . 'px);':''). esc_html( $getextrnlvars["butnxtstyle"] ) . (($getextrnlvars["isshortbuttons"]>0)?'padding:0px 15px;width:auto!important;':'padding:0 0;width:100%!important;') . 'margin-top:15px;border:' . (($getextrnlvars["frmbrdrwdth"]>0 && emailotpauthn_getopacityfrmclr($getextrnlvars["buttoncolor"])<5)? $getextrnlvars["frmbrdrwdth"] . 'px solid '. $getextrnlvars["frmbrdrcolr"] : '2px solid ' . esc_html( $butnbrdrclr ) ) . ';}.emailotpauthninlinebox #emailotpauthn_content form #submitotpsec input[type=button].generateOtp,#emailotpauthn_lightbox #emailotpauthn_content form #submitotpsec input[type=button].generateOtp{cursor:pointer;text-decoration:underline;background:0 0!important;border:0;color:' . esc_html( $getextrnlvars["frmnoticclr"] ) . '!important;padding:0;outline:0}.emailotpauthninlinebox #emailotpauthn_content form input[type=button]:disabled,#emailotpauthn_lightbox #emailotpauthn_content form input[type=button]:disabled{background:#ccc;cursor:initial}#emailotpauthn_lightbox .close{cursor:pointer;position:absolute;top:12px;right:10px;z-index:9999999}@media (max-width:767px){#emailotpauthn-body{padding:10px}.emailotpauthninlinebox,#emailotpauthn_lightbox{width:90%}.emailotpauthninlinebox #emailotpauthn_content p,#emailotpauthn_lightbox #emailotpauthn_content p{font-size:12px!important}}@media (max-width:800px) and (min-width:501px){.emailotpauthninlinebox,#emailotpauthn_lightbox{width:70%}.emailotpauthninlinebox #emailotpauthn_content p,#emailotpauthn_lightbox #emailotpauthn_content p{font-size:12px!important}}@media (max-width:2200px) and (min-width:801px){.emailotpauthninlinebox,#emailotpauthn_lightbox{width:60%}.emailotpauthninlinebox #emailotpauthn_content p,#emailotpauthn_lightbox #emailotpauthn_content p{font-size:15px!important}}.emailotpauthninlinebox{width:fit-content;height:fit-content;text-align:center;clear:both}.emailotpauthninlinebox #emailotpauthn_content,#emailotpauthn_lightbox #emailotpauthn_content{border-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'25').'px;color:#333;margin:auto;position:relative;padding:0;font-size:15px!important;overflow:initial;min-width:400px;width:450px;max-width:450px}#emailotpauthn_lightbox #emailotpauthn_content{top:50%;transform:translateY(-50%);}'.((strcasecmp($getextrnlvars["popuphorzalign"],"center")==0)?'':('@media screen and (min-width: 501px) {#emailotpauthn_lightbox #emailotpauthn_content{float:'.$getextrnlvars["popuphorzalign"].';margin-'.$getextrnlvars["popuphorzalign"].':'.$getextrnlvars["popupboxmargin"].'%;}}')).'.emailotpauthninlinebox #emailotpauthn_content p,#emailotpauthn_lightbox #emailotpauthn_content p{padding:1%;text-align:left;margin:0!important;line-height:20px}#emailotpauthn_lightbox #emailotpauthn_content .close span{display:block;float:right;text-align:right;' . esc_html( $getextrnlvars["hedrxtstyle"] ) . 'font-size:0.7em!important;margin-top:-4px;height:36px;width:100%}#emailotpauthn_lightbox #emailotpauthn_content .close span:hover,.emailotpauthninlinebox .emailotpauthnmsg:hover,#emailotpauthn_lightbox .emailotpauthnmsg:hover{cursor:pointer}.emailotpauthninlinebox .heading,#emailotpauthn_lightbox .heading{padding:10px 5px;margin:0!important;border-top-left-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'25').'px;border-top-right-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'25').'px;background: ' . esc_html( $getextrnlvars["headercolor"] ) . '!important;'.(($getextrnlvars["poppboxblur"]>0)?'backdrop-filter:blur(' . esc_html( $getextrnlvars["poppboxblur"] ) . 'px);':'').'}.emailotpauthninlinebox .heading h3,#emailotpauthn_lightbox .heading h3{border:none;margin-top:1px;margin-bottom:2px;' . esc_html( $getextrnlvars["hedrxtstyle"] ) . '}span.emailotpauthn-shortcode.emailotpauthn-popup{border:0px solid #ccc;padding:8px 10px;border-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'10').'px} input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { display: none; -webkit-appearance: none; margin: 0; } input[type=number] { -moz-appearance: textfield; }#rememberemaildiv{color:'.emailotpauthn_getcolorfrmstyle($getextrnlvars["bodyxtstyle"]).';Padding-bottom: 20px;width:100%;position:relative;}'.(($getextrnlvars["extrnlsection"]>2)?'#showrgstrtermsdiv{float:left;display:inline-block;}#showrgstrtermsdiv>div,':'').'#showrmbremaildiv>div{float:left;width:15px;height:15px;display:inline-block;}'.(($getextrnlvars["extrnlsection"]>2)?'#showrgstrterms,':'').'#rememberemail{padding:0px!important;min-height:15px!important;margin-top:14px;}'.(($getextrnlvars["extrnlsection"]>2)?'#terms_of_use,':'').'#remember_email{display:inline-block!important;margin-top:17px;margin-left:5px;font-size:small!important;float:left;line-height:12px;}'.(($getextrnlvars["extrnlsection"]>2)?'#terms_of_use>a{text-decoration:none;}':'').'#showrmbremaildiv{float:right;display:inline-block;}#emailotpauthn_content{border: '. $getextrnlvars["frmbrdrwdth"] .'px solid '. $getextrnlvars["frmbrdrcolr"] .'; border-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'25').'px;}.otpestatus{padding-top:10px;}#emailotpauthn_formbg{position:absolute;top:0;left:0;'.(($getextrnlvars["poppopcimeg"]>0 && !empty($getextrnlvars["poppboximeg"]))?'background-image:url("' . esc_url( $getextrnlvars["poppboximeg"] ) . '");':'').'border-radius:'.(($getextrnlvars["iscornrstyl"])?'0':'25').'px;background-size:cover;background-repeat:no-repeat;background-position:center center;width:100%;height:100%;overflow:hidden;z-index:-1;'.(empty($getextrnlvars["poppboximeg"])?'opacity:0;':'opacity:' . esc_html( $getextrnlvars["poppopcimeg"] ) . ';').'}#emailotpauthn_lightbox{position:fixed;top:0;left:0;text-align:center;z-index:999999!important;height:100%;width:100%;}#emailotpauthn_bdrpbg,#emailotpauthn_lightbg{position:absolute;top:0;left:0;clear:both;background-position:center center;width:100%;height:100%;overflow:hidden;}#emailotpauthn_bdrpbg{background-size:cover;background-repeat:no-repeat;'.(($getextrnlvars["bkdrpopcimg"]>0 && !empty($getextrnlvars["backdrpimeg"]))?'background-image:url("' . esc_url( $getextrnlvars["backdrpimeg"] ) . '");':'').(empty($getextrnlvars["backdrpimeg"])?'opacity:0;':'opacity:' . esc_html( $getextrnlvars["bkdrpopcimg"] ) . ';').'z-index:'.(($getextrnlvars["popupbgblur"]>0)?'-1':'-3').';}#emailotpauthn_lightbg{background-color:' . esc_html( $getextrnlvars["poppbgcolor"] ) . ';'.(($getextrnlvars["popupbgblur"]>0)?'backdrop-filter:blur(' . esc_html( $getextrnlvars["popupbgblur"] ) . 'px);':'').'z-index:-2;}.emailerror,.otperror,.otpestatus{font-weight:600!important;}';
	return $emailotpauthnextrnlcss;
}

function emailotpauthn_popup_extrnl_html($getextrnlvars){
	$emailotpauthnextrnlhtml = '';
	if($getextrnlvars["isoneinputbox"])
		$emailotpauthnextrnlhtml = '<input type="number" class="input_otp eotpafi" name="email_otp" id="email_otp" value="" oninput="javascript: if (this.value.length > this.maxLength) this.value = Number(this.value.toString().slice(0, this.maxLength));" maxlength="6">';
	else
		$emailotpauthnextrnlhtml = '<div id="eotpainputdiv"><input type="number" class="eotpafni" pattern="[0-9]*" autocomplete="one-time-code" value="" inputtype="numeric" id="eotpa_otc-1" required><input type="number" class="eotpafni" pattern="[0-9]*" min="0" max="9" maxlength="1" value="" inputtype="numeric" id="eotpa_otc-2" required><input type="number" class="eotpafni" pattern="[0-9]*" min="0" max="9" maxlength="1" value="" inputtype="numeric" id="eotpa_otc-3" required><input type="number" class="eotpafni" pattern="[0-9]*" min="0" max="9" maxlength="1" value="" inputtype="numeric" id="eotpa_otc-4" required><input type="number" class="eotpafni" pattern="[0-9]*" min="0" max="9" maxlength="1" value="" inputtype="numeric" id="eotpa_otc-5" required><input type="number" class="eotpafni" pattern="[0-9]*" min="0" max="9" maxlength="1" value="" inputtype="numeric" id="eotpa_otc-6" required></div><input type="hidden" name="email_otp" id="email_otp">';
	
	$emailotpauthnextrnlhtml = (($getextrnlvars["formtype"]=="inline")?((strcasecmp($getextrnlvars["extrnltxt_003"], "2fa") == 0)?'<div class="emailotpauthninlinebox" id="emailotpauthninlinebox2fa" style="display:none">':'<div class="emailotpauthninlinebox">'):'<div id="emailotpauthnlightbox"></div><div id="emailotpauthnBox" style="display:none">').'<div id="emailotpauthn_contact"><div class="emailotpauthnmsg"></div><form name="clfrom" id="emailotpauthn-form" class="emailotpauthn-section" action="" method="post" novalidate autocomplete="off" role="form" ><div id="emailotpauthn_formbg" data-imgdtls="None"></div><div style="display:none;"><input type="hidden" name="emailotpauthnsecurity" value="' . esc_html( wp_create_nonce("emailotpauthn_filed_once_val") ) . '"><input type="hidden" name="emailotpauthnsubmitid" id="emailotpauthnsubmitid" value=""><input type="hidden" name="emailotpauthnzplussecurity" value="">'.(($getextrnlvars["extrnlsection"]>2)?'<input type="hidden" name="emailotpauthn_action" id="emailotpauthn_action" value="' . esc_html( $getextrnlvars["dflt_action"] ) . '">':'').'</div><div class="heading"><h3 id="emailotpauthn_header_submit">' . esc_html( $getextrnlvars["header_submit"] ) . '</h3><h3 style="display:none;" id="emailotpauthn_header_verify">' . esc_html( $getextrnlvars["header_verify"] ) . '</h3></div><div id="emailotpauthn-body"><div id="sendotp"><label><span id="email_message">' . esc_html( $getextrnlvars["logged_in_title"] ) . '</span><span class="req">*</span><br/><span class="emailerror req"></span>&#8202;</label><input type="' . esc_html( $getextrnlvars["logged_in_boxtype"] ) . '" name="email" id="email" value="' . esc_html( $getextrnlvars["logged_in_email"] ) . '" class="emailotpauthn-req-fields eotpafi" size="40" ' . esc_html( $getextrnlvars["logged_in_readonly"] ) . '><small>' . esc_html( $getextrnlvars["logged_in_message"] ) . '</small> <input type="button" class="emailotpauthn_submit_btn generateOtp eotpafi" id="generateOtp" value="' . esc_html( $getextrnlvars["extrnltxt_003"] ) . '"><br/><div id="rememberemaildiv">'.(($getextrnlvars["extrnlsection"]>2)?'<div id="showrgstrtermsdiv"><div><input class="eotpafi" type="checkbox" name="showrgstrterms" id="showrgstrterms"></div><label id="terms_of_use">' . esc_html( $getextrnlvars["extrnltxt_060"] ) . ' <a href="' . esc_url($getextrnlvars["rgstrtermouurl"]) . '" target="_blank">' . esc_html( $getextrnlvars["extrnltxt_061"] ) . '</a>.</label></div>':'').'<div id="showrmbremaildiv"><div><input class="eotpafi" type="checkbox" id="rememberemail" class="rememberemail"></div><label id="remember_email">' . esc_html( $getextrnlvars["extrnltxt_062"] ) . '</label></div></div></div><div id="submitotpsec"><span id="back_buton" class="loginback" type="button">< ' . esc_html( $getextrnlvars["extrnltxt_063"] ) . '</span> <span class="email-otp"><label><span id="otp_message">' . esc_html( $getextrnlvars["extrnltxt_064"] ) . '</span><br><span id="sbmitedemail"></span><br/><span class="req"><span class="otperror"></span></span>&#8202;</label>' . ( $emailotpauthnextrnlhtml ) . '</span> <div class="emailotpauthn-submit-sec"><input type="button" class="submitOtp eotpafi" id="submitOtp" value="' . esc_html( $getextrnlvars["extrnltxt_004"] ) . '" /><br/><span class="otpestatus req d-inline-block"></span></div></div></div></form></div></div>';
	
	return $emailotpauthnextrnlhtml;
}
?>