Sign up here to get the the best stories of the week and exclusive offers for subscribers.
X
var image_code;
function tnSubmitForm(obj) {
var tn_loader = document.getElementById("tn-loader");
tn_loader.classList.remove("ng-hide");
ga('send', 'event', 'piano-exit-popup', 'piano-exit-popup-signup-confirm', obj.getAttribute('href'));
}
function createCaptcha() {
//clear the contents of captcha div first
document.getElementById('image-captcha').innerHTML = "";
var charsArray =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@!#$%^&*";
var lengthOtp = 6;
var captcha = [];
for (var i = 0; i < lengthOtp; i++) {
//below code will not allow Repetition of Characters
var index = Math.floor(Math.random() * charsArray.length + 1); //get the next character from the array
if (captcha.indexOf(charsArray[index]) == -1)
captcha.push(charsArray[index]);
else i--;
}
image_code = captcha.join("");
/*var canv = document.createElement("canvas");
canv.id = "captcha";
canv.width = 100;
canv.height = 60;
var ctx = canv.getContext("2d");
ctx.font="30px Arial";
ctx.fillText(image_code,10,50);*/
document.getElementById("image-captcha").innerHTML = image_code;
}
function validateCaptcha(e) {
if (e.value == image_code) {
document.getElementById("exit-submit-btn").disabled = false;
document.getElementById("exit-submit-btn").classList.remove("disabled");
} else {
document.getElementById("exit-submit-btn").disabled = true;
document.getElementById("exit-submit-btn").classList.add("disabled");
}
}
window.addEventListener("message", function(e) {
var tn_loader = document.getElementById("tn-loader");
if (void 0 !== e.data.piano) {
var a = e.data.piano;
a.success ? jQuery(".thank-you-pop").toggleClass("ng-hide") : jQuery(".error-msg").text(a.message)
}
}, !1);
createCaptcha();