var revealWaitHandle = null; var wasWinner = false; var prize_name_if_spintowin = false; var loser_number = 0; var winner_number = 0; var camp_sub_id = 0; function showWinnerScratchImg() { $('#boximg').attr('src', $('#scratchtowin_img_winner').val()); $('#boximg').show(); } function showLoserScratchImg() { $('#boximg').attr('src', $('#scratchtowin_img_loser').val()); $('#boximg').show(); } $(document).ready(function () { button_sound_obj = document.getElementById('buttonsoundaudio'); winner_sound_obj = document.getElementById('winnersoundaudio'); loser_sound_obj = document.getElementById('losersoundaudio'); visit_sound_obj = document.getElementById('visitsoundaudio'); $(".numberbutton").click(function () { if (enable_button_sound == '1') { playButtonSound(); } /* * get other sounds ready */ if (enable_winner_sound == '1') { getWinnerSoundReady(); } if (enable_loser_sound == '1') { getLoserSoundReady(); } }); if ('0' == '0') { $("#errormodal").modal({ escapeClose: false, clickClose: false, showClose: false }); } $(window).bind("orientationchange", function (evt) { updateCreativeLandPort(); alignRefreshDiv(); console.log('orientationchange: '); if (spinToWin == '1') { if (isMobile.any()) { if (isPortrait()) { console.log('isPortrait: 1'); $('#wheel_holder').css({'margin-left': '0%'}); // 13% } else { console.log('Landscape: 1'); $('#wheel_holder').css({'margin-left': '5%'}); } } } }); updateCreativeLandPort(); /* * * align images in html editor * */ $('#winnermessagediv').find('img').each(function (e) { $(this).css({'max-width': '100%'}); }); $('#losermessagediv').find('img').each(function (e) { $(this).css({'max-width': '100%'}); }); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('aAa: 2'); } internetConnectionDetect(); changeInSettingsDetect(); if (scratchToWin == '1') { } if (spinToWin == '1') { resetWheelZoom(); } if ('592' == '181') { } fetchCreative(); }); function fetchCreative() { // contest_img_landscape $.ajax({ url: "https://engagesnap.com/accounts/ajax.php", data: {fetchCreative: '1', campaign_id: '592'}, type: 'POST', success: function (res) { var obj = JSON.parse(res); if (obj['success'] == '1') { contest_img_landscape = obj['contest_img_landscape']; if ('1' == '1') { $('#creativediv').css({'background-image': "url(" + contest_img_landscape + ")"}); } else if ('0' == '1') { $('#maindiv').css({'background-image': "url(" + contest_img_landscape + ")"}); } else if ('0' == '1') { $('#contestil').attr('src', contest_img_landscape); } window.setTimeout(function () { fetchCreative(); }, 120000); } }, error: function (e) { window.setTimeout(function () { fetchCreative(); }, 3000); } }); } $(".numberbutton").mousedown(function () { $(this).addClass("shadowpush"); $(this).addClass("hovercolor"); setTimeout(function () { $(".numberbutton").removeClass("shadowpush"); $(".numberbutton").removeClass("hovercolor"); }, 200); }); /* * Sound functions */ function getWinnerSoundReady() { winner_sound_obj = winner_sound_obj.cloneNode(true); winner_sound_obj.volume = 0.0; try { if (!isMobile.iOS()) { winner_sound_obj.play(); } } catch (err) { console.log("catch err: " + err); } } function getLoserSoundReady() { loser_sound_obj = loser_sound_obj.cloneNode(true); loser_sound_obj.volume = 0.0; try { if (!isMobile.iOS()) { loser_sound_obj.play(); } } catch (err) { console.log("catch err: " + err); } } function getVisitSoundReady() { visit_sound_obj = visit_sound_obj.cloneNode(true); visit_sound_obj.volume = 0.0; try { if (!isMobile.iOS()) { visit_sound_obj.play(); } } catch (err) { console.log("catch err: " + err); } } function playWinnerSound() { winner_sound_obj.volume = 0.50; try { winner_sound_obj.currentTime = 0; winner_sound_obj.play(); } catch (err) { console.error("playWinnerSound(): " + err); } } function playLoserSound() { loser_sound_obj.volume = 0.50; loser_sound_obj.currentTime = 0; try { loser_sound_obj.play(); } catch (err) { console.error("playLoserSound(): " + err); } } function playVisitSound() { visit_sound_obj.volume = 0.50; visit_sound_obj.currentTime = 0; try { visit_sound_obj.play(); } catch (err) { console.error("playVisitSound(): " + err); } } function playButtonSound() { button_sound_obj = document.getElementById('buttonsoundaudio'); try { button_sound_obj.pause(); } catch (err) { console.error("playButtonSound()1: " + err); } button_sound_obj.volume = 0.50; button_sound_obj.autoPlay = false; button_sound_obj.preLoad = true; button_sound_obj.currentTime = 0; try { button_sound_obj.cloneNode(true).play(); } catch (err) { console.error("playButtonSound()2: " + err); } } function stopWinnerSound() { try { winner_sound_obj.currentTime = 0; } catch (err) { console.error("stopWinnerSound(): " + err); } } function stopLoserSound() { try { loser_sound_obj.currentTime = 0; } catch (err) { console.error("stopLoserSound(): " + err); } } function stopVisitSound() { try { visit_sound_obj.volume = 0.0; visit_sound_obj.currentTime = 0; } catch (err) { console.error("stopLoserSound(): " + err); } } /* * Sound functions */ function updateCreativeLandPort() { if (isMobile.any()) { if (window.innerHeight > window.innerWidth) { } else { $('#creativediv').css('background-image', 'url("' + contest_img_portrait + '")'); } } else { } } var outputnumber = contest_phone_mask; var outputnumberarr = outputnumber.split(''); function buttonClicked(obj) { if (is_email_contest == '1') { buttonClickedEmail(obj); return; } var button_number = $(obj).attr('data-number'); if (button_number == '<') { var prevText = $('#phonenumber').text(); if (prevText != 'Enter Your Mobile Number') { var prevText = prevText.slice(0, -1); outputnumberarr = addHashToLastNumber(outputnumberarr); outputnumber = convertToString(outputnumberarr); $('#phonenumber').text(outputnumber); $('#delbtn').css({'background': 'red'}); if (outputnumber == contest_phone_mask) { $('#phonenumberdiv').css({'background': '#f7f7f7'}); $('#phonenumber').text('Enter Your Mobile Number'); $('#delbtn').css({'background': bg_color_button}); } } if (prevText == '') { $('#phonenumberdiv').css({'background': '#f7f7f7'}); prevText = 'Enter Your Mobile Number'; $('#phonenumber').text(prevText); $('#delbtn').css({'background': bg_color_button}); } } else if (button_number == 'go') { var numberintext = $('#phonenumber').text(); doGoLogic(numberintext); } else { var prevText = $('#phonenumber').text(); if (prevText == 'Enter Your Mobile Number') { prevText = ''; } var indexofhash = outputnumberarr.indexOf('#'); outputnumberarr[indexofhash] = button_number; outputnumber = convertToString(outputnumberarr); outputnumberarr = outputnumber.split(''); var newText = prevText + '' + button_number; $('#phonenumber').text(outputnumber); $('#delbtn').css({'background': 'red'}); } removeFocus(obj); if (getHashCount($('#phonenumber').text()) <= 0 && $('#phonenumber').text() != 'Enter Your Mobile Number' && $('#phonenumber').text() != '') { $('#gobtn').css({'background': 'green'}); } else { $('#gobtn').css({'background': bg_color_button}); } } function buttonClickedEmail(obj) { var button_number = $(obj).attr('data-number'); if (button_number == '<') { var prevText = $('#phonenumber').text(); if (prevText != 'Enter Your Mobile Number') { var prevText = prevText.slice(0, -1); outputnumberarr = trimLastChar(outputnumberarr); outputnumber = convertToString(outputnumberarr); $('#phonenumber').text(outputnumber); $('#delbtn').css({'background': 'red'}); if (outputnumber == '') { $('#phonenumberdiv').css({'background': '#f7f7f7'}); $('#phonenumber').text('Enter Your Mobile Number'); $('#delbtn').css({'background': bg_color_button}); } } if (prevText == '') { $('#phonenumberdiv').css({'background': '#f7f7f7'}); prevText = 'Enter Your Mobile Number'; $('#phonenumber').text(prevText); $('#delbtn').css({'background': bg_color_button}); } } else if (button_number == 'go') { var numberintext = $('#phonenumber').text(); doGoLogic(numberintext); } else { var prevText = $('#phonenumber').text(); if (prevText == 'Enter Your Mobile Number') { prevText = ''; } outputnumberarr.push(button_number); outputnumber = convertToString(outputnumberarr); outputnumberarr = outputnumber.split(''); $('#phonenumber').text(outputnumber); $('#delbtn').css({'background': 'red'}); } removeFocus(obj); if (getHashCount($('#phonenumber').text()) <= 0 && $('#phonenumber').text() != 'Enter Your Mobile Number' && $('#phonenumber').text() != '') { $('#gobtn').css({'background': 'green'}); } else { $('#gobtn').css({'background': bg_color_button}); } } function removeFocus(obj) { $(obj).blur(); $(obj).hideFocus = true; } var resObjGlobal = null; var xhrlcloser = null; var isEnteringOtherNumber = false; function doGoLogic(numberintext) { $('#phonenumberdiv').css({'border': '4px solid rgba(191, 189, 189, 0.5)', 'background': '#F7F7F7'}); if (is_email_contest == '1') { if (numberintext == 'Enter Your Mobile Number' || !validateEmail(numberintext)) { $('#phonenumberdiv').css({'background': '#ff9696'}); return true; } } else { if (numberintext == 'Enter Your Mobile Number' || getHashCount(numberintext) > 0) { $('#phonenumberdiv').css({'background': '#ff9696'}); return true; } } if (splashTimer !== null) { clearTimeout(splashTimer); } var onlynumber = getOnlyumberFromString(numberintext); if (is_email_contest == '1') { onlynumber = numberintext; } onlynumber = onlynumber.split(' ').join(''); if (isEnteringOtherNumber) { resObjGlobal.numberintext = onlynumber; resObjGlobal.mobile_number = onlynumber; numberConfYes(); hideAllDivs(); $("#losermessagediv").show(); return; } var data = new FormData(); data.append("checkwinnerorloser", '1'); data.append("campaign_id", '592'); data.append("only_one_entry", only_one_entry); data.append("user_id", '224'); data.append("scratch_to_win", '1'); data.append("spin_to_win", '0'); data.append("slot_machine", '0'); data.append("numberintext", onlynumber); data.append("is_email_contest", is_email_contest); data.append("referrer", referrer); $.ajax({ type: 'POST', url: "https://engagesnap.com/accounts/ajax.php", data: data, cache: false, contentType: false, processData: false, success: function (res) { console.log(res); var obj = JSON.parse(res); wasWinner = obj['is_winner'] == '1'; if (scratchToWin == '1') { campaign_send_wl_queue_id = -1; hideAllDivs(); $('#scratchtowindiv').show(); if (obj['is_winner'] == '1') { camp_sub_id = obj['subscriber_id']; showWinnerScratchImg(); showNumberPlateAgain(); campaign_send_wl_queue_id = obj['campaign_send_wl_queue_id']; wasWinner = true; showScratchCard('//engagesnap.com/accounts_assets/images/stw_winner_img_61ace2d3a8bf0.png'); } else if (obj['is_winner'] == '0') { camp_sub_id = obj['subscriber_id']; showLoserScratchImg(); showNumberPlateAgain(); campaign_send_wl_queue_id = obj['campaign_send_wl_queue_id']; wasWinner = false; showScratchCard('//engagesnap.com/accounts_assets/images/stw_loser_img_61ace2d3a8fde.png'); } else if (obj['is_winner'] == '2') { actionWaitTimeNotOver(); } else if (obj['is_winner'] == '3') { actionOnlyOneEntry(); } } else if (spinToWin == '1') { campaign_send_wl_queue_id = -1; hideAllDivs(); var obj = JSON.parse(res); prize_name_if_spintowin = obj['prize_name']; loser_number = obj['loser_number']; winner_number = obj['position_number']; rurl = obj['rurl']; if (obj['is_winner'] == '1') { camp_sub_id = obj['subscriber_id']; campaign_send_wl_queue_id = obj['campaign_send_wl_queue_id']; prize_id_sptwin = obj['prize_id']; console.log('prize_id_sptwin: ' + prize_id_sptwin); wasWinner = true; showSpinToWin(wasWinner); if (revealWaitHandle !== null) { clearTimeout(revealWaitHandle); revealWaitHandle = null; } showNumberPlateAgain(); } else if (obj['is_winner'] == '0') { camp_sub_id = obj['subscriber_id']; campaign_send_wl_queue_id = obj['campaign_send_wl_queue_id']; wasWinner = false; showSpinToWin(wasWinner); if (revealWaitHandle !== null) { clearTimeout(revealWaitHandle); revealWaitHandle = null; } showNumberPlateAgain(); } else if (obj['is_winner'] == '2') { actionWaitTimeNotOver(); } else if (obj['is_winner'] == '3') { actionOnlyOneEntry(); } } else if (slot_machine == '1') { campaign_send_wl_queue_id = -1; hideAllDivs(); var obj = JSON.parse(res); prize_name_if_spintowin = obj['prize_name']; loser_number = obj['loser_number']; winner_number = obj['position_number']; rurl = obj['rurl']; if (obj['is_winner'] == '1') { camp_sub_id = obj['subscriber_id']; campaign_send_wl_queue_id = obj['campaign_send_wl_queue_id']; prize_id_sptwin = obj['prize_id']; console.log('prize_id_sptwin: ' + prize_id_sptwin); wasWinner = true; showSlotMachine(1); if (revealWaitHandle !== null) { clearTimeout(revealWaitHandle); revealWaitHandle = null; } showNumberPlateAgain(); } else if (obj['is_winner'] == '0') { camp_sub_id = obj['subscriber_id']; campaign_send_wl_queue_id = obj['campaign_send_wl_queue_id']; wasWinner = false; showSlotMachine(0); if (revealWaitHandle !== null) { clearTimeout(revealWaitHandle); revealWaitHandle = null; } showNumberPlateAgain(); } else if (obj['is_winner'] == '2') { actionWaitTimeNotOver(); } else if (obj['is_winner'] == '3') { actionOnlyOneEntry(); } } else if (loyalty_checkin == '1') { var obj = JSON.parse(res); if (obj['success'] == '1') { camp_sub_id = obj['subscriber_id']; hideAllDivs(); $("#winnermessagediv").fadeIn(300); showRefreshDiv(); if (enable_winner_sound == '1') { playWinnerSound(); } window.setTimeout(function () { handleRefresh(); hideAllDivs(); $("#numberplate").fadeIn(300); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('b: 3'); } if (enable_winner_sound == '1') { stopWinnerSound(); } /* * reset zoom */ $("#controlepaneldiv").css({'zoom': (100) + '%'}); }, Number('10') * 1000); } else if (obj['success'] == '0') { console.log('losermodalhandle'); camp_sub_id = obj['subscriber_id']; hideAllDivs(); $("#losermessagediv").fadeIn(300); $("#losermessagediv").html(obj['punch_fail_message_text']); showRefreshDiv(); if (obj['visits_reach_sound'] == '1' && Number(obj['customer_visits_remaining']) <= 0 && obj['visits_reach_sound_url'] != '') { playVisitSound(); } else { if (enable_loser_sound == '1') { playLoserSound(); } } resObjGlobal = obj; if (obj.hasOwnProperty("ask_to_join")) { if (obj['ask_to_join'] == '1') { $('#losermessagediv').append(''); } } resetTimerTimoutsLoyaltyCheckin(); } else if (obj['success'] == '2') { actionWaitTimeNotOver(); } else if (obj['success'] == '3') { // only one entry allowed actionOnlyOneEntry(); } } else { var obj = JSON.parse(res); if (obj['is_winner'] == '1') { console.log('winnermodalhandle'); camp_sub_id = obj['subscriber_id']; hideAllDivs(); $("#winnermessagediv").fadeIn(300); showRefreshDiv(); /* * play winner sound */ if (enable_winner_sound == '1') { playWinnerSound(); } window.setTimeout(function () { handleRefresh(); hideAllDivs(); $("#numberplate").fadeIn(300); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('aAa: 3'); } /* * stop winner sound */ if (enable_winner_sound == '1') { stopWinnerSound(); } /* * reset zoom */ $("#controlepaneldiv").css({'zoom': (100) + '%'}); }, Number('10') * 1000); } else if (obj['is_winner'] == '0') { console.log('losermodalhandle'); camp_sub_id = obj['subscriber_id']; hideAllDivs(); $("#losermessagediv").fadeIn(300); showRefreshDiv(); /* * play loser sound */ if (enable_loser_sound == '1') { playLoserSound(); } window.setTimeout(function () { handleRefresh(); hideAllDivs(); $("#numberplate").fadeIn(300); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('aAa: 4'); } /* * stop loser sound */ if (enable_loser_sound == '1') { stopLoserSound(); } /* * reset zoom */ $("#controlepaneldiv").css({'zoom': (100) + '%'}); }, Number('10') * 1000); } else if (obj['is_winner'] == '2') { actionWaitTimeNotOver(); } else if (obj['is_winner'] == '3') { actionOnlyOneEntry(); } } $('#winnermessagediv').html(obj['contest_winner_message']); resetNumberInput(); } }); } function onLoserDisplayTimeout() { handleRefresh(); hideAllDivs(); $("#numberplate").fadeIn(300); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('bb: 4'); } if (enable_loser_sound == '1') { stopLoserSound(); } stopVisitSound(); $("#controlepaneldiv").css({'zoom': (100) + '%'}); } function resetTimerTimoutsLoyaltyCheckin() { if (xhrlcloser !== null) { clearTimeout(xhrlcloser); console.log('clearTimeout(xhrlcloser)'); } totalSeconds = contest_hide_alert_after; xhrlcloser = window.setTimeout(function () { onLoserDisplayTimeout(); }, Number('10') * 1000); } function joinNowClicked() { $('#losermessagediv').html(resObjGlobal['number_conf_text']); $('#losermessagediv').append(''); $('#losermessagediv').append(''); resetTimerTimoutsLoyaltyCheckin(); } function numberConfYes() { resetTimerTimoutsLoyaltyCheckin(); $('#losermessagediv').html(resObjGlobal['creating_acc_text']); $.ajax({ url: "https://engagesnap.com/accounts/ajax.php", data: {save_card_pdf: '1', punch_card_id: resObjGlobal['punch_card_id'], mobile_number: resObjGlobal['mobile_number'], email: resObjGlobal['email'], name: resObjGlobal['name'], password: resObjGlobal['password'], white_label: '1'}, type: 'POST', success: function (res) { var obj = JSON.parse(res); if (obj['success'] == '1') { $('#losermessagediv').html(resObjGlobal['acc_created_text']); window.setTimeout(function () { isEnteringOtherNumber = false; doGoLogic(resObjGlobal['numberintext']); }, 3000); } } }); } function numberConfNo() { resetTimerTimoutsLoyaltyCheckin(); $('#losermessagediv').html(resObjGlobal['number_conf_no_inst']); window.setTimeout(function () { hideAllDivs(); $("#numberplate").fadeIn(300); isEnteringOtherNumber = true; resetTimerTimoutsLoyaltyCheckin(); }, 5000); } var actionOnScratchDoneV = false; function actionOnScratchDone() { console.log("actionOnScratchDone"); if (actionOnScratchDoneV == true) { return; } actionOnScratchDoneV = true; console.log('actionOnScratchDone'); if (revealWaitHandle !== null) { clearTimeout(revealWaitHandle); revealWaitHandle = null; } showRefreshDiv(); if (wasWinner) { /* * play winner sound */ if (enable_winner_sound == '1') { playWinnerSound(); } } else { /* * play loser sound */ if (enable_loser_sound == '1') { playLoserSound(); } } window.setTimeout(function () { handleRefresh(); hideAllDivs(); $("#numberplate").fadeIn(300); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('aAa: 5'); } /* * stop winner sound */ if (enable_winner_sound == '1') { stopWinnerSound(); } /* * stop loser sound */ if (enable_loser_sound == '1') { stopLoserSound(); } /* * reset zoom */ $("#controlepaneldiv").css({'zoom': (100) + '%'}); }, Number('10') * 1000); if (scratchToWin == '1') { window.setTimeout(function () { }, Number(contest_hide_alert_after) * 1000); } if (is_email_contest == '1') { $.post('https://engagesnap.com/accounts/ajax.php', {'send_queued_wl_email': '1', 'campaign_send_wl_queue_id': campaign_send_wl_queue_id}, function (res) { console.log('send_queued_wl_email: ' + res); }); } else { $.post('https://engagesnap.com/accounts/ajax.php', {'send_queued_wl_msg': '1', 'campaign_send_wl_queue_id': campaign_send_wl_queue_id}, function (res) { console.log('send_queued_wl_msg: ' + res); }); } } function actionWaitTimeNotOver() { hideAllDivs(); $('#contest_wait_message_div').fadeIn(); showRefreshDiv(); window.setTimeout(function () { hideAllDivs(); $("#numberplate").fadeIn(300); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('aAa: 6'); } /* * reset zoom */ $("#controlepaneldiv").css({'zoom': (100) + '%'}); }, Number('10') * 1000); } function validateEmail(email) { var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); } function actionOnlyOneEntry() { hideAllDivs(); $('#only_one_entry_text_div').fadeIn(); showRefreshDiv(); window.setTimeout(function () { hideAllDivs(); $("#numberplate").fadeIn(300); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('aAa: 7'); } /* * reset zoom */ $("#controlepaneldiv").css({'zoom': (100) + '%'}); }, Number('10') * 1000); } function showNumberPlateAgain() { revealWaitHandle = window.setTimeout(function () { hideAllDivs(); $("#numberplate").fadeIn(300); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('aAa: 8'); } /* * stop winner sound */ if (enable_winner_sound == '1') { stopWinnerSound(); } /* * stop loser sound */ if (enable_loser_sound == '1') { stopLoserSound(); } /* * reset zoom */ $("#controlepaneldiv").css({'zoom': (100) + '%'}); }, Number(scratchToRevealDisplayDuration) * 1000); } function hideAllDivs() { $("#numberplate").hide(); $("#winnermessagediv").hide(); $("#losermessagediv").hide(); $("#refreshingdiv").hide(); $("#contest_wait_message_div").hide(); $("#only_one_entry_text_div").hide(); $('#scratchtowindiv').hide(); $('#spintowindiv').hide(); $('#slotmachinediv').hide(); } function showRefreshDiv() { $("#refreshingdiv").fadeIn(300); window.setTimeout(function () { $("#spintowindiv").hide(); }, 500); runRefreshSecondsCountdown(true); alignRefreshDiv(); } function convertToString(arr) { var out = ''; for (var i = 0; i < arr.length; i++) { out = out + arr[i]; } return out; } function addHashToLastNumber(arr2) { var arr = arr2; var indexOfLastNumber = -1; for (var i = 0; i < arr.length; i++) { if (!isNaN(arr[i]) && arr[i] != ' ') { indexOfLastNumber = i; } } if (indexOfLastNumber >= 0) { arr[indexOfLastNumber] = '#'; } return arr; } function trimLastChar(arr2) { var arr = arr2; var arrtrim = new Array(); for (var i = 0; i < arr.length - 1; i++) { arrtrim[i] = arr[i]; } return arrtrim; } function getHashCount(numberintext) { var hashCount = 0; var arr = numberintext.split(''); for (var i = 0; i < arr.length; i++) { if (arr[i] == '#') { hashCount = hashCount + 1; } } return hashCount; } function getOnlyumberFromString(str) { var numberstr = ''; var arr = str.split(''); for (var i = 0; i < arr.length; i++) { if (!isNaN(arr[i])) { numberstr = numberstr + arr[i]; } } if (numberstr == '') { return str; } else { return numberstr; } } function runRefreshSecondsCountdown(firsttimerun) { if (firsttimerun) { totalSeconds = contest_hide_alert_after; } if (totalSeconds <= 0) { return; } $('#refreshcount').text('' + totalSeconds); totalSeconds = totalSeconds - 1; window.setTimeout(function () { runRefreshSecondsCountdown(false); }, 1000); } function alignRefreshDiv() { var height_self = $('#refreshingdiv').outerHeight(); var height = height_self; if ($('#winnermessagediv').is(":visible")) { var myheight = 0; $('#winnermessagediv').children().each(function (e) { var childheight = $(this).outerHeight(); myheight = myheight + childheight; }); height = myheight; } if ($('#losermessagediv').is(":visible")) { var myheight = 0; $('#losermessagediv').children().each(function (e) { var childheight = $(this).outerHeight(); myheight = myheight + childheight; }); height = myheight; } if ($('#contest_wait_message_div').is(":visible")) { var myheight = 0; $('#contest_wait_message_div').children().each(function (e) { var childheight = $(this).outerHeight(); myheight = myheight + childheight; }); height = myheight; } if ($('#only_one_entry_text_div').is(":visible")) { var myheight = 0; $('#only_one_entry_text_div').children().each(function (e) { var childheight = $(this).outerHeight(); myheight = myheight + childheight; }); height = myheight; } if (scratchToWin == '1') { height = height - $('#scratch-container').innerHeight() / 6; } if (spinToWin == '1') { // if (isMobile.any()) { // height = height + $('#chart').innerHeight() / 7.3; // console.log('chart M: ' + height); // } else { // height = height + $('#chart').innerHeight(); // console.log('chart: ' + height); // } } $("#refreshingdiv").css({'margin-top': (height) + 'px'}); } function playButtonClicked(obj) { $('#modal_splash').fadeOut(splashFadeOutTime); /* * run 3 minute check if user fills the number */ var waittime = Number(splash_pause) * 60 * 1000; if (scratchToWin == '1') { if (Number(scratchToRevealDisplayDuration) > waittime) { waittime = scratchToRevealDisplayDuration; } } splashTimer = window.setTimeout(function () { if (wasdisconnected != true) { if (spinToWin != '1') { redisplaysplash(); } } }, waittime); removeFocus(obj); } function redisplaysplash() { $('#phonenumberdiv').css({'background': '#f7f7f7'}); resetNumberInput(); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('aAa: 1'); } } function resetNumberInput() { $('#phonenumber').text('Enter Your Mobile Number'); outputnumber = contest_phone_mask; outputnumberarr = outputnumber.split(''); $('#delbtn').css({'background': bg_color_button}); $('#gobtn').css({'background': bg_color_button}); } var animationTimer = null; function animatePlayButton(clearOldAnim) { if (clearOldAnim == true) { if (animationTimer !== null) { clearTimeout(animationTimer); } } $('#click_to_play_btn').removeClass(play_button_computed_class); if (scratchToWin == '1') { $('#s2w_img').removeClass(play_button_computed_class); } window.setTimeout(function () { $('#click_to_play_btn').addClass(play_button_computed_class); if (scratchToWin == '1') { $('#s2w_img').addClass(play_button_computed_class); } }, splashFadeInTime); animationTimer = window.setTimeout(function () { animatePlayButton(false); }, (recycleAnimAfterEverySeconds) * 1000); } var xhrinternet = null; function internetConnectionDetect() { if (xhrinternet != null) { xhrinternet.abort(); } xhrinternet = $.ajax({ type: "GET", url: "https://engagesnap.com/accounts/ajax.php?internetConnectionDetect=1", success: function (msg) { if (wasdisconnected) { $('#interneterrormodalclose').click(); console.log("wasdisconnected"); redisplaysplash(); wasdisconnected = false; } }, error: function (XMLHttpRequest, textStatus, errorThrown) { wasdisconnected = true; $('#modal_splash').hide(); $('#interneterrormodalclose').click(); $("#interneterrormodal").modal({ escapeClose: false, clickClose: false, showClose: false }); } }); window.setTimeout(function () { internetConnectionDetect(); }, 10000); } function adjustZoom() { var wh = $(window).height(); var dh = $(document).height(); if (dh > wh) { var per = (wh / dh) * 100; $("#controlepaneldiv").css({'zoom': per + '%'}); } } function handleRefresh() { if (rurl != '') { window.location.href = rurl; return; } if ('0' == '1') { if ('0' == '1') { if ('' != '') { window.location.href = ''; } } else { if (wasWinner) { if ('https://txt-2.com/0tmW' != '') { window.location.href = 'https://txt-2.com/0tmW'; } } else { if ('https://txt-2.com/0zJT' != '') { window.location.href = 'https://txt-2.com/0zJT'; } } } } } var xhrprivacy = null; function openPrivacyModal() { $("#privacymodal").modal({ escapeClose: false, showClose: false }); if (xhrprivacy != null) { clearTimeout(xhrprivacy); } xhrprivacy = window.setTimeout(function () { $('#privacymodalclose').click(); }, (Number(('10') * 1000) * 3)); } var xhrchange = null; function changeInSettingsDetect() { if (xhrchange != null) { xhrchange.abort(); } xhrchange = $.ajax({ type: "GET", url: "https://engagesnap.com/accounts/ajax.php?changeInSettingsDetect=1&campaign_id=592&last_change_was=" + campaign_last_change, success: function (res) { var obj = JSON.parse(res); if (obj['did_change'] == '1') { window.location.reload(); } } }); window.setTimeout(function () { changeInSettingsDetect(); }, 5 * 60000); } function callback(d) { actionOnScratchDone(); } function percent(p) { } function showScratchCard(background_img) { actionOnScratchDoneV = false; $('#scratchcard').remove(); $('#scratchtowindiv').append('
'); var scratchcardOverlayWidth = $('#scratchcard').width(); var thickness = (scratchcardOverlayWidth / 100) * 5; createScratchCard({ "container": document.getElementById("scratchcard"), "background": background_img, "foreground": "//engagesnap.com/accounts_assets/images/stw_overlay_img_61ace2d3a8609.png", "percent": Number(scratch_reveal_percentage), "coin": "https://engagesnap.com/accounts_assets/scratchtowin2/images/coin2.png", "thickness": thickness, "counter": "percent", "callback": "callback" }); } function isPortrait() { return window.innerHeight > window.innerWidth; } $(window).on('resize', function () { if (spinToWin == '1') { resetWheelZoom(); } }); function showSlotMachine(run_for_winner) { $('#slotmachinediv').html(''); $.post('https://engagesnap.com/accounts/slot_machine.php', {get_slot_machine: '1', campaign_id: '592', run_for_winner: run_for_winner}, function (res) { $('#slotmachinediv').html(res); readyMachine(); }); $('#slotmachinediv').show(); } function actionOnSlotMachineDone() { console.log("actionOnSlotMachineDone"); showRefreshDiv(); if (wasWinner) { /* * play winner sound */ if (enable_winner_sound == '1') { playWinnerSound(); } } else { /* * play loser sound */ if (enable_loser_sound == '1') { playLoserSound(); } } if (revealWaitHandle !== null) { clearTimeout(revealWaitHandle); revealWaitHandle = null; } revealWaitHandle = window.setTimeout(function () { handleRefresh(); hideAllDivs(); $("#numberplate").fadeIn(300); if (enable_splash == '1') { if (!$('#modal_splash').is(':visible')) { $('#modal_splash').fadeIn(splashFadeInTime); } animatePlayButton(true); console.log('aAa: 5'); } /* * stop winner sound */ if (enable_winner_sound == '1') { stopWinnerSound(); } /* * stop loser sound */ if (enable_loser_sound == '1') { stopLoserSound(); } /* * reset zoom */ $("#controlepaneldiv").css({'zoom': (100) + '%'}); }, Number('10') * 1000); if (is_email_contest == '1') { $.post('https://engagesnap.com/accounts/ajax.php', {'send_queued_wl_email': '1', 'campaign_send_wl_queue_id': campaign_send_wl_queue_id}, function (res) { console.log('send_queued_wl_email: ' + res); }); } else { $.post('https://engagesnap.com/accounts/ajax.php', {'send_queued_wl_msg': '1', 'campaign_send_wl_queue_id': campaign_send_wl_queue_id, prize_id_sptwin: prize_id_sptwin}, function (res) { console.log('send_queued_wl_msg'); console.log({'send_queued_wl_msg': '1', 'campaign_send_wl_queue_id': campaign_send_wl_queue_id, prize_id_sptwin: prize_id_sptwin}); console.log('Res: ' + res); prize_id_sptwin = '0'; }); } }