const warningModalHTML = `
`; const modalContainer = document.createElement('div'); modalContainer.innerHTML = warningModalHTML; const warningModal = modalContainer.querySelector('#warning-modal'); document.body.appendChild(warningModal); window.closeWarningModal = function(event) { event.preventDefault(); warningModal.style.display = 'none'; if (window.widgetId !== null) { turnstile.reset(widgetId);};}; window.openWarningModal = function() { warningModal.style.display = 'flex'; }; var apiEndpointURL = 'https://betapi.hollywoodbets.net/api/'; window.resetForm = function(){ window.location.reload(); }; window.startTimer = function(isTimerSet){ var timer = 3 * 60;if(isTimerSet){ timer =-1 } var section = document.querySelector('#timer'); var timerContainer = document.querySelector('#timer-container'); var interval = setInterval(function() { var minutes = Math.floor(timer / 60); var seconds = timer % 60; var displayMinutes = minutes < 10 ? '0' + minutes : minutes; var displaySeconds = seconds < 10 ? '0' + seconds : seconds; section.textContent = displayMinutes + ':' + displaySeconds; timerContainer.style.display = 'flex'; const resendBtn = document.getElementById('resendBtn'); resendBtn.removeEventListener('click', resendOTP);document.querySelector('#resendBtn').removeAttribute('onclick'); document.querySelector('#resendBtn').style.cursor = 'not-allowed'; document.querySelector('#resendSecond').removeAttribute('onclick'); document.querySelector('#resendSecond').style.cursor = 'not-allowed'; if (--timer < 0) { clearInterval(interval); timerContainer.style.display = 'none'; document.querySelector('#resendBtn').style.cursor = 'pointer'; document.querySelector('#resendBtn').addEventListener('click', resendOTP); document.querySelector('#resendSecond').style.cursor = 'pointer'; document.querySelector('#resendSecond').addEventListener('click', resendOTP); } }, 1000); }; window.submitRegistrationForm = function(closeOptModal=false) { document.getElementById('dateOfBirth').value=document.getElementById('yearOfBirth').value+'-'+document.getElementById('monthOfBirth').value+'-'+document.getElementById('dayOfBirth').value;var name = document.getElementById('name').value+' '+document.getElementById('surname').value; var parts = name.split(' ');var initials = ''; for (var i = 0; i < parts.length; i++) {if (parts[i].length > 0 && parts[i] !== '') {initials += parts[i][0]}} document.getElementById('initials').value= initials; var url = document.querySelector('form').action; var formData = new FormData(document.querySelector('form')); formData.append('isOtp',closeOptModal); document.querySelector('.submit-btn').disabled = true; document.querySelector('.submit-btn').innerHTML = 'Processing registration'; fetch(url, {method: 'POST', body: formData}).then(Result => Result.json()).then(dataResult => { if(dataResult.redirect) { if(closeOptModal){closeModal();} window.location.href = dataResult.urlOrMessage} else if(!dataResult.redirect){if(dataResult.urlOrMessage){ document.querySelector('.error-message').innerHTML = dataResult.urlOrMessage; document.querySelector('.error-div').classList.remove('display-none');if(dataResult.requiresVerification){document.querySelector('.otp-button').parentElement.classList.remove('display-none');}; if(!closeOptModal){grecaptcha.reset();}}else {window.location.href = window.location.href} } else {window.location.href = window.location.href} document.querySelector('.submit-btn').disabled = false; document.querySelector('.submit-btn').innerHTML = 'Submit'; }).catch(errorMsg=>{ document.querySelector('.submit-btn').disabled = false; document.querySelector('.submit-btn').innerHTML = 'Submit'; }); }; window.verifyOTP = function() { document.querySelector('#submitButton').disabled = true; var inputs = document.querySelectorAll('.digitInput'); var concatenatedValue = ''; inputs.forEach(function(input) { concatenatedValue += input.value; }); var url = 'VerifyOTP/' + concatenatedValue + '?apiURL=' + apiEndpointURL; fetch(url, {method: 'POST', body: null}).then(response => response.json()).then(dataResult => {var message = dataResult.message; var success = dataResult.success; if(dataResult.exceededAttempts){document.querySelector('#invalidOTPResendBtn').style.display = 'none'; document.querySelector('#invalidOTPResendBtn').style.display = 'none'; document.getElementById('resendBtn').style.display = 'none'; document.querySelector('#maximumAttempts').style.display = ''; setTimeout(resetForm, 6000); } else if(success){ document.querySelector('.otp-button').parentElement.classList.add('display-none');closeModal();navigateToStep(2); }else{document.getElementById('invalidOTPResendBtn').style.display = ''; document.querySelector('#errorMessage').textContent = message.toUpperCase(); var digitInputs = document.querySelectorAll('.digitInput'); digitInputs.forEach(function(input) { input.value = ''; }); var resendButton = document.getElementById('resendBtn'); var resendOTPButton = document.getElementById('invalidOTPResendBtn'); resendButton.style.display = 'none'; resendOTPButton.style.display = ''; var maximumAttempts = document.getElementById('maximumAttempts'); maximumAttempts.style.display = 'none'; } }).catch(error => { console.error('Error:', error); }); }; window.sendOTP = function() { fetch(`SendOTP/${document.querySelector('#Cell').value}?apiURL=${apiEndpointURL}`, { method: 'POST' }) .then(response => response.json()) .then(dataResult => { console.log('dataResult', dataResult); if (dataResult.success) { openOTPModal(); startTimer(true); }else { const errorMessage = document.querySelector('p[id="error-message"]'); errorMessage.innerHTML = dataResult.message; openWarningModal(); } }) .catch(error => console.error('Error:', error)); }; window.resendOTP = function() { startTimer(); var url = 'ResendOTP?apiURL=' + apiEndpointURL ; fetch(url, {method: 'POST', body: null}).then(response => response.json()).then(dataResult => { var digitInputs = document.querySelectorAll('.digitInput'); digitInputs.forEach(function(input) { input.value = ''; }); var message = dataResult.message; var success = dataResult.success; var exceededAttempts = dataResult.exceededAttempts; if(success){ console.log('success!!!!'); }else{ if(exceededAttempts){document.getElementById('invalidOTPResendBtn').style.display = 'none'; var resendButton = document.getElementById('resendBtn'); var resendOTPButton = document.getElementById('invalidOTPResendBtn'); var maximumAttempts = document.getElementById('maximumAttempts'); resendOTPButton.style.display = 'none'; resendButton.style.display = 'none'; maximumAttempts.style.display = ''; setTimeout(resetForm, 5000); }else{ document.getElementById('resendBtn').style.display = 'none'; document.getElementById('invalidOTPResendBtn').style.display = ''; document.querySelector('#errorMessage').textContent = message.toUpperCase(); } } }).catch(error => { console.error('Error:', error); }); }