PageSourceSearch

https://lifebliss.online/wp-content/plugins/quiz-maker/public/js/quiz-maker-public.js?ver=1791597016

js lifebliss.online collected 2026-10-10 01:50:52 UTC 343,251 bytes, 5,766 lines download raw bytes

1(function ($) {
2    'use strict';
3    $(document).ready(function () {
4        $.fn.goTo = function(myOptions) {
5            var QuizAnimationTop = (myOptions.quiz_animation_top && myOptions.quiz_animation_top != 0) ? parseInt(myOptions.quiz_animation_top) : 100;
6
7            myOptions.quiz_enable_animation_top = myOptions.quiz_enable_animation_top ? myOptions.quiz_enable_animation_top : 'on';
8            var EnableQuizAnimationTop = ( myOptions.quiz_enable_animation_top && myOptions.quiz_enable_animation_top == 'on' ) ? true : false;
9            if( EnableQuizAnimationTop ){
10                $('html, body').animate({
11                    scrollTop: $(this).offset().top - QuizAnimationTop + 'px'
12                }, 'slow');
13            }
14            return this; // for chaining...
15        }
16        if (!String.prototype.trim) {
17            (function() {
18                String.prototype.trim = function() {
19                    return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
20                };
21            })();
22        }
23
24        $(document).find('.for_quiz_rate_avg.ui.rating').rating('disable');
25
26        var ays_quiz_container, ays_quiz_container_id, quizId; //flag to prevent quick multi-click glitches
27        var myOptions, myQuizOptions, explanationTimeout;
28        var emailValivatePattern = /^[a-zA-Z0-9\._+-]+@[a-zA-Z0-9\._-]+\.\w{2,}$/;
29        var aysThisQuizBullets = null;
30        var aysThisQuizQuestionsFirstPass = true;
31        var AYS_MS_PER_SECONDS = 1000;
32        var aysDurationInSeconds = 2;
33        if( typeof window.aysQuizBullets == 'undefined' ){
34            window.aysQuizBullets = [];
35        }
36
37        if( typeof window.aysQuizQuestionTimers == 'undefined' ){
38            window.aysQuizQuestionTimers = [];
39        }
40
41        if( typeof window.aysSeeResultConfirmBox == 'undefined' ){
42            window.aysSeeResultConfirmBox = [];
43        }
44
45        if( typeof window.aysEarlyFinishConfirmBox == 'undefined' ){
46            window.aysEarlyFinishConfirmBox = [];
47        }
48
49
50        window.aysTimerInterval = null;
51        window.countdownTimeForShowInterval = null;
52        window.aysQuizStartDate = null;
53        window.voiceAction = false;
54
55        function aysQuizResizeIframe(iframe) {
56            iframe.height = iframe.contentWindow.document.body.scrollHeight + 40;
57            window.requestAnimationFrame(function(){ aysQuizResizeIframe(iframe) });
58        }
59
60        $(document).find('.ays-quiz-container[data-is-embed="1"]').each(function () {
61            if (Number(this.dataset.isAmp) === 0 && Number(this.dataset.isEmbed) === 1) {
62                // var iframes = window.parent.document.querySelectorAll('iframe[id^="aysQuizIframe"]');
63                // if( iframes ) {
64                //     for (var i = 0; i < iframes.length; i++) {
65                //         aysQuizResizeIframe(iframes[i]);
66                //     }
67                // }
68            }
69        });
70
71        if( $(document).find('.ays-quiz-container[data-is-amp="1"]').length > 0 ) {
72            aysResizeiFrame();
73        }
74
75        function time_limit(e) {
76            quizId = $(e.target).parents('.ays-quiz-container').find('input[name="ays_quiz_id"]').val();
77            myOptions = JSON.parse(atob(window.aysQuizOptions[quizId]));
78
79            var isTriggeredByResumeButton = e.params && e.params.triggeredBy && e.params.triggeredBy === 'resume_button';
80            if (!isTriggeredByResumeButton) {
81                if(checkQuizPassword(e, myOptions, false) === false){
82                    return false;
83                }
84            }
85
86            if(typeof myOptions.answers_rw_texts == 'undefined'){
87                myOptions.answers_rw_texts = 'on_passing';
88            }
89            if(typeof myOptions.make_questions_required == 'undefined'){
90                myOptions.make_questions_required = 'off';
91            }
92            var quizOptionsName = 'quizOptions_'+quizId;
93            myQuizOptions = [];
94            if(typeof window[quizOptionsName] !== 'undefined'){
95                for(var i in window[quizOptionsName]){
96                    if(window[quizOptionsName].hasOwnProperty(i)){
97                        myQuizOptions[i] = (JSON.parse(window.atob(window[quizOptionsName][i])));
98                    }
99                }
100            }
101            
102            if(typeof window.aysSeeResultConfirmBox !== 'undefined'){
103                window.aysSeeResultConfirmBox[ quizId ] = false;
104            }
105
106            if(typeof window.aysEarlyFinishConfirmBox !== 'undefined'){
107                window.aysEarlyFinishConfirmBox[ quizId ] = false;
108            }
109
110            var container = $(e.target).parents('.ays-quiz-container');
111            if ($(this).parents('.step').next().find('.information_form').length === 0 ){
112                var quizMusic = container.find('audio.ays_quiz_music');
113                if(quizMusic.length !== 0){                
114                    var soundEls = $(document).find('.ays_music_sound');
115                    container.find('.ays_music_sound').removeClass('ays_display_none');
116                    if(!isPlaying(quizMusic.get(0))){
117                        container.find('audio.ays_quiz_music')[0].play();
118                        audioVolumeIn($(e.target).parents('.ays-quiz-container').find('audio.ays_quiz_music')[0]);
119                    }
120                }
121                container.find('.ays-live-bar-wrap').css({'display': 'block'});
122                container.find('.ays-live-bar-percent').css({'display': 'inline-block'});
123                container.find('input.ays-start-date').val(GetFullDateTime());
124                window.aysQuizStartDate = GetFullDateTime();
125            }
126            if ($(this).parents('.step').next().find('.information_form').length === 0 && myOptions.enable_timer == 'on') {
127                var questionCountPerPage = myOptions.question_count_per_page && myOptions.question_count_per_page === 'on';
128                var displayALlQuestion = myOptions.quiz_display_all_questions && myOptions.quiz_display_all_questions === 'on';
129                if( displayALlQuestion ){
130                    myOptions.quiz_timer_type = 'quiz_timer';
131                } else if ( questionCountPerPage ) {
132                    myOptions.quiz_timer_type = 'quiz_timer';
133                }
134
135                var timerType = myOptions.quiz_timer_type ? myOptions.quiz_timer_type : 'quiz_timer';
136                if( timerType === 'quiz_timer' ){
137                    quizTimer( container );
138                }
139            }else{
140                $(this).parents('.step').next().find('.information_form').find('.ays_next.action-button').on('click', function () {
141                    if($(this).parents('.step').find('.information_form').find('.ays_next.action-button').hasClass('ays_start_allow')){
142                        time_limit(e);                        
143                    }
144                });
145            }
146        }
147            
148        $(document).on('click', '.ays-quiz-question-title-text-to-speech-icon', function(){
149            window.voiceAction = !window.voiceAction;
150            var questionText = atob($(this).attr('data-question'));
151            if ('speechSynthesis' in window) {
152                
153                var voices = quizGetVoices();
154                var voice = voices[0];
155                var language = 'en';
156                var rate = 1, pitch = 1, volume = 1;
157
158                if (voices.length !== 0) {
159                    voices.forEach((item, index) => {
160                        if (item.name == $(this).attr('data-voice')) {
161                            voice = voices[index];
162                            language = voice.lang;
163                        }
164                    });
165                }
166
167                if(window.voiceAction){
168                    listenQuestionText(questionText, voice, language, rate, pitch, volume, 'play' );
169                }
170                else{
171                    listenQuestionText(questionText, voice, language, rate, pitch, volume, 'cancel' );                        
172                }
173            }else{
174                console.log('Speech Synthesis Not Supported');
175            }
176        });
177        
178        $(document).find('.ays_next.start_button').on('click', time_limit);
179        
180        $(document).find('.ays_next.start_button').on('click', function(e){
181
182            if (typeof $(this).attr("data-enable-leave-page") !== 'undefined') {
183                $(this).attr("data-enable-leave-page",true);
184            }
185
186            var isTriggeredByResumeButton = e.params && e.params.triggeredBy && e.params.triggeredBy === 'resume_button';
187            if (!isTriggeredByResumeButton) {
188                if(checkQuizPassword(e, myOptions, false) === false){
189                    return false;
190                }
191            }
192
193            // Enable the Show/Hide toggle
194            myOptions.quiz_bg_img_during_the_quiz = (myOptions.quiz_bg_img_during_the_quiz) ? myOptions.quiz_bg_img_during_the_quiz : 'off';
195            var quiz_bg_img_during_the_quiz =(myOptions.quiz_bg_img_during_the_quiz && myOptions.quiz_bg_img_during_the_quiz == 'on') ? true : false;
196
197            ays_quiz_container_id = $(this).parents(".ays-quiz-container").attr("id");
198            ays_quiz_container = $('#'+ays_quiz_container_id);
199            
200            aysResetQuiz( ays_quiz_container );
201            aysQuizStopYoutubeIframe( ays_quiz_container );
202
203            ays_quiz_container.css('padding-bottom', '0px');
204            var ancnoxneriQanak = $(this).parents('.ays-questions-container').find('.ays_quizn_ancnoxneri_qanak');
205            var aysQuizReteAvg = $(this).parents('.ays-questions-container').find('.ays_quiz_rete_avg');
206            var next_sibilings_count = $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page').val();
207
208            var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
209            if(isRequiredQuestion === true && !( parseInt( next_sibilings_count ) > 0 ) ){
210                ays_quiz_container.find('div[data-question-id]').each(function(){
211                    var thisStep = $(this);
212                    if(!thisStep.find('input.ays_next').hasClass('ays_display_none')){
213                        thisStep.find('input.ays_next').attr('disabled', 'disabled');
214                    }else if(!thisStep.find('i.ays_next_arrow').hasClass('ays_display_none')){
215                        thisStep.find('i.ays_next_arrow').attr('disabled', 'disabled');
216                    }
217
218                    if(!thisStep.find('input.ays_early_finish').hasClass('ays_display_none')){
219                        thisStep.find('input.ays_early_finish').attr('disabled', 'disabled');
220                    }else if(!thisStep.find('i.ays_early_finish').hasClass('ays_display_none')){
221                        thisStep.find('i.ays_early_finish').attr('disabled', 'disabled');
222                    }
223                });
224            }
225
226            if( ays_quiz_container.find('.enable_min_selection_number').length > 0 ){
227                ays_quiz_container.find('.enable_min_selection_number').each(function(){
228                    var thisStep = $(this).parents('.step');
229                    thisStep.find('input.ays_next').attr('disabled', 'disabled');
230                    thisStep.find('i.ays_next_arrow').attr('disabled', 'disabled');
231
232                    thisStep.find('input.ays_early_finish').attr('disabled', 'disabled');
233                    thisStep.find('i.ays_early_finish').attr('disabled', 'disabled');
234                });
235            }
236
237            ays_quiz_container.find('div[data-question-id][data-type="custom"], div[data-question-id][data-type="upload_file"]').each(function(){
238                $(this).find('i.ays_clear_answer').addClass('ays_display_none');
239                $(this).find('input.ays_clear_answer').addClass('ays_display_none');
240            });
241
242            setTimeout(function(){
243                ays_quiz_container.css('border-radius', myOptions.quiz_border_radius + 'px');
244                ays_quiz_container.find('.step').css('border-radius', myOptions.quiz_border_radius + 'px');
245            }, 400);
246            
247            aysAnimateStep(ays_quiz_container.data('questEffect'), aysQuizReteAvg);
248            aysAnimateStep(ays_quiz_container.data('questEffect'), ancnoxneriQanak);
249            
250            if ($(this).parents('.step').next().find('.information_form').length === 0 ){
251
252                $(this).parents('.ays-quiz-wrap').find('.ays-quiz-questions-nav-wrap').slideDown(500);
253                var questions_count = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').length;
254                var curent_number = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').index($(this).parents('div[data-question-id]')) + 1;
255                if(questions_count <= parseInt(next_sibilings_count)){
256                    next_sibilings_count = questions_count;
257                }
258                if(parseInt(next_sibilings_count) > 0 &&
259                   ($(this).parents('.step').attr('data-question-id') || 
260                    $(this).parents('.step').next().attr('data-question-id'))){
261                    var final_width = ((parseInt(next_sibilings_count)) / questions_count * 100) + "%";
262                    if($(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
263                        $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(parseInt(next_sibilings_count)));
264                    }else{                
265                        $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
266                    }
267                    $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 1000);
268                }else{
269                    var final_width = ((curent_number+1) / questions_count * 100) + "%";
270                    if($(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
271                        $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+1));
272                    }else{                
273                        $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
274                    }
275                    $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 1000);
276                }
277            }
278
279            if ( ays_quiz_container.hasClass('ays_quiz_hide_bg_on_start_page') ) {
280                ays_quiz_container.removeClass('ays_quiz_hide_bg_on_start_page');
281            }
282
283            if( quiz_bg_img_during_the_quiz ){
284                if ( !ays_quiz_container.hasClass('ays_quiz_hide_bg_during_quiz') ) {
285                    ays_quiz_container.addClass('ays_quiz_hide_bg_during_quiz');
286                }
287            }
288
289            aysQuizBullets[quizId] = createPagination($(this).parents('.ays-quiz-wrap').find('.ays-quiz-questions-nav-wrap'), 1);
290            aysThisQuizBullets = aysQuizBullets[quizId];
291            aysThisQuizBullets._navPage(0);
292
293        });
294
295        $(document).on('focus', '.ays-quiz-container input', function () {
296            $(window).on('keydown', function (event) {
297                var _this = $(event.target);
298                var submitFlag = true;
299                var quizLoginForm = $(event.target).parents('.ays_quiz_login_form');
300                if( quizLoginForm.length > 0 ){
301                    submitFlag = false;
302                }
303                if (event.keyCode === 13) {
304                    if( submitFlag ){
305                        return false;
306                    }
307                }
308            });
309        });
310
311        $(document).on('blur', '.ays-quiz-container input', function () {
312            $(window).off('keydown');
313        });
314        
315        $.each($(document).find('.ays_block_content'), function () {
316            if ($(document).find('.ays_block_content').length != 0) {
317                var ays_block_element = $(this).parents().eq(2);
318                ays_block_element.find('input.ays-start-date').val(GetFullDateTime());
319                ays_block_element.find('div.ays-quiz-timer').slideUp(500);
320                var timer = parseInt(ays_block_element.find('div.ays-quiz-timer').attr('data-timer'));
321                var timerInTitle = ays_block_element.find('div.ays-quiz-timer').data('showInTitle');
322                var tabTitle = document.title;
323                setTimeout(function(){
324                if (timer !== NaN) {
325                    timer += 2;
326                    if (timer !== undefined) {
327                        var countDownDate = new Date().getTime() + (timer * 1000);
328                        var x = setInterval(function () {
329                            var now = new Date().getTime();
330                            var distance = countDownDate - Math.
330ceil(now/1000)*1000;
331                            var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
332                            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
333                            var seconds = Math.floor((distance % (1000 * 60)) / 1000);
334                            var timeForShow = "";
335                            if(hours <= 0){
336                                hours = null;
337                            }else if (hours < 10) {
338                                hours = '0' + hours;
339                            }
340                            if (minutes < 10) {
341                                minutes = '0' + minutes;
342                            }
343                            if (seconds < 10) {
344                                seconds = '0' + seconds;
345                            }
346                            timeForShow =  ((hours==null)? "" : (hours + ":")) + minutes + ":" + seconds;
347                            if(distance <=1000){
348                                timeForShow = ((hours==null) ? "" : "00:") + "00:00";
349                                ays_block_element.find('div.ays-quiz-timer').html(timeForShow);
350                                if(timerInTitle){
351                                    document.title = timeForShow + " - " + tabTitle ;
352                                }
353                            }else{
354                                ays_block_element.find('div.ays-quiz-timer').html(timeForShow);
355                                if(timerInTitle){
356                                    document.title = timeForShow + " - " + tabTitle ;
357                                }
358                            }
359                            ays_block_element.find('div.ays-quiz-timer').slideDown(500);
360                            var ays_block_element_redirect_url = ays_block_element.find('.ays_redirect_url').text();
361                            if (distance <= 1) {
362                                clearInterval(x);
363                                var totalSteps = ays_block_element.find('div.step').length;
364                                var currentStep = ays_block_element.eq(2).find('div.step.active-step');
365                                var currentStepIndex = ays_block_element.eq(2).find('div.step.active-step').index();
366                                if (currentStep.hasClass('ays_thank_you_fs') === false) {
367                                    var steps = totalSteps - 3;
368                                    ays_block_element.find('div.step').each(function (index) {
369                                        if (index >= (currentStepIndex - 1) && index <= steps) {
370                                            $(this).remove();
371                                        }
372                                    });
373                                    // window.location = ays_block_element_redirect_url;
374                                    if (window.location != window.parent.location) {
375                                        parent.location = ays_block_element_redirect_url;
376                                    } else {
377                                        window.location = ays_block_element_redirect_url;
378                                    }
379                                }
380                            }
381                        }, 1000);
382                    }
383                }
384                }, 1000);
385            }
386        });
387        
388        $(document).find('button.ays_check_answer').on('click', function (e) {
389            var quizId = $(this).parents('.ays-quiz-container').find('input[name="ays_quiz_id"]').val();
390            var thisAnswerOptions;
391            var quizContainer = $(e.target).parents('.ays-quiz-container');
392            var parentStep = $(this).parents('.step');
393            var right_answer_sound = quizContainer.find('.ays_quiz_right_ans_sound').get(0);
394            var wrong_answer_sound = quizContainer.find('.ays_quiz_wrong_ans_sound').get(0);
395            var questionId = $(this).parents('.step').data('questionId');
396            var questionType = $(this).parents('.step').attr('data-type');
397            var finishAfterWrongAnswer = (myOptions.finish_after_wrong_answer && myOptions.finish_after_wrong_answer == "on") ? true : false;
398            var showOnlyWrongAnswer = (myOptions.show_only_wrong_answer && myOptions.show_only_wrong_answer == "on") ? true : false;
399            var explanationTime = myOptions.explanation_time && myOptions.explanation_time != "" ? parseInt(myOptions.explanation_time) : 4;
400            var next_sibilings_count = quizContainer.find('.ays_question_count_per_page').val();
401            var enableNextButton = (myOptions.enable_next_button && myOptions.enable_next_button == 'on') ? true : false;
402            var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
403
404            // Strong calculation of answers score
405            myOptions.checkbox_score_by = ( myOptions.checkbox_score_by ) ? myOptions.checkbox_score_by : 'off';
406            var checkbox_score_by = (myOptions.checkbox_score_by && myOptions.checkbox_score_by == "on") ? true : false;
407
408            // Display all questions on one page
409            myOptions.quiz_display_all_questions = ( myOptions.quiz_display_all_questions ) ? myOptions.quiz_display_all_questions : 'off';
410            var quiz_display_all_questions = (myOptions.quiz_display_all_questions && myOptions.quiz_display_all_questions == "on") ? true : false;
411
412            var disableQuestions = false;
413            if( parseInt( next_sibilings_count ) > 0 || quiz_display_all_questions == true ){
414                disableQuestions = true;
415            }
416
417            var ans_right_wrong_icon = (myOptions.ans_right_wrong_icon && myOptions.ans_right_wrong_icon != "") ? myOptions.ans_right_wrong_icon : "default";
418
419            var correct_img_URL = "";
420            var wrong_img_URL   = "";
421            if( ans_right_wrong_icon == "default"){
422                correct_img_URL = quizLangObj.AYS_QUIZ_PUBLIC_URL + "/images/correct.png";
423                wrong_img_URL   = quizLangObj.AYS_QUIZ_PUBLIC_URL + "/images/wrong.png";
424            } else if( ans_right_wrong_icon == "none" ){
425                correct_img_URL = "";
426                wrong_img_URL   = "";
427            } else {
428                correct_img_URL = quizLangObj.AYS_QUIZ_PUBLIC_URL + "/images/correct-"+ ans_right_wrong_icon +".png";
429                wrong_img_URL   = quizLangObj.AYS_QUIZ_PUBLIC_URL + "/images/wrong-"+ ans_right_wrong_icon +".png";
430            }
431
432            var correct_img_URL_HTML = "";
433            var wrong_img_URL_HTML   = "";
434            if (correct_img_URL != "") {
435                correct_img_URL_HTML = "<img class='ays-quiz-check-button-right-wrong-icon' data-type='"+ans_right_wrong_icon+"' src='"+ correct_img_URL +"'>"
436            }
437
438            if (wrong_img_URL != "") {
439                wrong_img_URL_HTML = "<img class='ays-quiz-check-button-right-wrong-icon' data-type='"+ ans_right_wrong_icon +"' src='"+ wrong_img_URL +"'>"
440            }
441
442            thisAnswerOptions = myQuizOptions[questionId];
443
444            var fill_in_blank_flag = true;
445            if( questionType == 'fill_in_blank' ){
446                var fillInBlankUserAnswers = parentStep.find('.ays-text-input');
447                
448                var fillInBlankUserAnswersEmptyCount = 0;
449                if(fillInBlankUserAnswers.length > 0){
450                    for (var i = 0; i < fillInBlankUserAnswers.length; i++) {
451                        var current_input_val = $(fillInBlankUserAnswers[i]).val();
452                        if( current_input_val == '' ){
453                            fillInBlankUserAnswersEmptyCount++;
454                        }
455                    }
456                }
457
458                if( fillInBlankUserAnswers.length === fillInBlankUserAnswersEmptyCount ){
459                    fill_in_blank_flag = false;
460                }
461
462                if( isRequiredQuestion ){
463                    if( fillInBlankUserAnswersEmptyCount > 0 ){
464                        fill_in_blank_flag = false;
465                        ays_quiz_is_question_required( parentStep );
466                    }
467                }
468            }
469
470            var checkbox_flag = true;
471            if( questionType == 'checkbox' ){
472                var checkboxUserAnswers = parentStep.find('.ays-quiz-answers .ays-field input:checked');
473                
474                if( checkboxUserAnswers.length == 0 ){
475                    checkbox_flag = false;
476                }
477
478                var checkedMinSelCount = aysCheckMinimumCountCheckbox( parentStep, myQuizOptions );
479
480                if( !checkedMinSelCount ){
481                    checkbox_flag = false;
482                    ays_quiz_is_question_min_count( parentStep, !checkedMinSelCount );
483                }
484            }
485
486            if($(this).parent().find('.ays-text-input').val() !== "" && fill_in_blank_flag && checkbox_flag){
487                if ($(e.target).parents('form[id^="ays_finish_quiz"]').hasClass('enable_correction')) {
488                    if($(e.target).parents('.step').hasClass('not_influence_to_score')){
489                        return false;
490                    }
491                    $(this).css({
492                        animation: "bounceOut .5s",
493                    });
494                    setTimeout(function(){
495                        $(e.target).parent().find('.ays-text-input').css('width', '100%');
496                        $(e.target).css("display", "none");
497                    },480);
498                    $(e.target).parent().find('.ays-text-input').css('background-color', '#eee');
499                    $(this).parent().find('.ays-text-input').attr('disabled', 'disabled');
500                    $(this).attr('disabled', 'disabled');
501                    $(this).off('change');
502                    $(this).off('click');
503                    $(this).parents('.ays-field').addClass('ays-answered-text-input');
504
505                    var input = $(this).parent().find('.ays-text-input');
506                    var type = input.attr('type');
507
508                    var userAnsweredText = "";
509                    if( questionType != 'fill_in_blank' && questionType != 'checkbox' ){
510                        var userAnsweredText = input.val().trim();
511                    }
512
513                    // Enable case sensitive text
514                    var enable_case_sensitive_text = (thisAnswerOptions.enable_case_sensitive_text && thisAnswerOptions.enable_case_sensitive_text != "") ? thisAnswerOptions.enable_case_sensitive_text : false;
515
516                    var trueAnswered = false;
517
518                    var thisQuestionAnswer = "";
519                    var displayingQuestionAnswer = "";
520                    if( questionType != 'fill_in_blank' && questionType != 'checkbox' ){
521                        var thisQuestionAnswer = aysEscapeHtmlDecode( thisAnswerOptions.question_answer ).aysStripSlashes().toLowerCase();
522                        var displayingQuestionAnswer = thisAnswerOptions.question_answer;
523
524                        if( type == 'text' || type == 'short_text' || type == 'fill_in_blank' ){
525                            if ( enable_case_sensitive_text ) {
526                                thisQuestionAnswer = aysEscapeHtmlDecode( thisAnswerOptions.question_answer ).aysStripSlashes();
527                            }
528                        }
529                    }
530
531                    if(type == 'date'){
532                        var correctDate = new Date(thisAnswerOptions.question_answer),
533                            correctDateYear = correctDate.getFullYear(),
534                            correctDateMonth = correctDate.getMonth(),
535                            correctDateDay = correctDate.getDate();
536                        var userDate = new Date(userAnsweredText),
537                            userDateYear = userDate.getFullYear(),
538                            userDateMonth = userDate.getMonth(),
539                            userDateDay = userDate.getDate();
540                        if(correctDateYear == userDateYear && correctDateMonth == userDateMonth && correctDateDay == userDateDay){
541                            trueAnswered = true;
542                        }
543                    }else if(questionType == 'fill_in_blank'){
544
545                        var fillInBlankAnswers = $(this).parents('.step').find('div.ays_quiz_question input[type="text"].ays-text-input.ays-quiz-fill-in-blank-input');
546
547                        trueAnswered = checkFillInTheBlankQuestion( fillInBlankAnswers, questionId, $(this), correct_img_URL_HTML, wrong_img_URL_HTML );
548
549                        parentStep.find('.ays_next').prop('disabled', false);
550                        parentStep.find('.ays_early_finish').prop('disabled', false);
551                        parentStep.find('.ays_previous').prop('disabled', false);
552
553                    }else if(questionType == 'checkbox'){
554
555                        var checkboxAnswers = $(this).parents('.step').find('div.ays-quiz-answers .ays-field');
556
557                        for (var i = 0; i < checkboxAnswers.length; i++) {
558                            var _checkbox_this = $(checkboxAnswers[i]).find('input[name^="ays_questions"]');
559                            _checkbox_this.addClass('ays-quiz-check-button-clicked');
560                            checkCheckboxRadioQuestion(e, _checkbox_this);
561                        }
562
563                        var userAnsweredWrongCount = parentStep.find('div.ays-quiz-answers .ays-field.checked_answer_div.wrong_div input:checked').length;
564                        var userAnsweredRightCount = parentStep.find('div.ays-quiz-answers .ays-field.checked_answer_div.correct_div input:checked').length;
565                        var correctAnswersCount    = parentStep.find('input[name="ays_answer_correct[]"][value="1"]').length;
566
567                        parentStep.find('.ays_next').prop('disabled', false);
568                        parentStep.find('.ays_early_finish').prop('disabled', false);
569                        parentStep.find('.ays_previous').prop('disabled', false);
570
571
572                        if ( checkbox_score_by ) {
573                            trueAnswered = true;
574                            if( userAnsweredWrongCount > 0 ){
575                                trueAnswered = false;
576                            } else if( correctAnswersCount != userAnsweredRightCount ){
577                                trueAnswered = false;
578                            }
579                        } else {
580                            trueAnswered = false;
581                            if( userAnsweredRightCount > userAnsweredWrongCount ){
582                                trueAnswered = true;
583                            }
584
585                            if( (correctAnswersCount - userAnsweredRightCount) > userAnsweredRightCount ){
586                                trueAnswered = false;
587                            }
588                        }
589
590                    }else if(type != 'number'){
591                        thisQuestionAnswer = thisQuestionAnswer.split('%%%');
592                        displayingQuestionAnswer = displayingQuestionAnswer.split('%%%');
593                        for(var i = 0; i < thisQuestionAnswer.length; i++){
594                            if ( enable_case_sensitive_text ) {
595                                if(userAnsweredText == thisQuestionAnswer[i].trim()){
596                                    trueAnswered = true;
597                                    break;
598                                }
599                            } else {
600                                if(userAnsweredText.toLowerCase() == thisQuestionAnswer[i].trim()){
601                                    trueAnswered = true;
602                                    break;
603                                }
604                            }
605                        }
606                    }else{
607                        if(type == 'number'){
608                            if(userAnsweredText.toLowerCase().replace(/\.([^0]+)0+$/,".$1") == thisQuestionAnswer.trim().replace(/\.([^0]+)0+$/,".$1")){
609                                trueAnswered = true;
610                            }
611                        } else {
612                            if(userAnsweredText.toLowerCase() == thisQuestionAnswer.trim()){
613                                trueAnswered = true;
614                            }
615                        }
616                    }
617
618                    if(trueAnswered){
619                        if((right_answer_sound)){
620                            resetPlaying([right_answer_sound, wrong_answer_sound]);
621                            setTimeout(function(){
622                                right_answer_sound.play();
623                            }, 10);
624                        }
625                        $(this).parent().find('.ays-text-input').css('background-color', 'rgba(39,174,96,0.5)');
626                        $(this).parent().find('input[name="ays_answer_
626correct[]"]').val(1);
627
628                        if (correct_img_URL_HTML != "") {
629                            $(this).parent().append(correct_img_URL_HTML);
630                        }
631
632                        if(! $(this).parents('.step').hasClass('not_influence_to_score')){
633                            $(this).parents('.step').find('.right_answer_text').slideDown(250);
634                        }
635
636                        if( aysThisQuizBullets !== null ){
637                            var thisQuestionID = $(e.target).parents('div[data-question-id]').data('questionId');
638                            var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
639                            thisBullet.attr('disabled', 'disabled');
640                            thisBullet.addClass('ays_quiz_correct_answer');
641                            if (!thisBullet.parent().hasClass('ays-quiz-questions-nav-item-last-question')) {
642                                thisBullet.parent().addClass('ays_quiz_checked_answer_div');
643                            }
644                        }
645                    }else{
646                        if((wrong_answer_sound)){
647                            resetPlaying([right_answer_sound, wrong_answer_sound]);
648                            setTimeout(function(){
649                                wrong_answer_sound.play();
650                            }, 10);
651                        }
652                        $(this).parent().find('.ays-text-input').css('background-color', 'rgba(243,134,129,0.8)');
653                        $(this).parent().find('input[name="ays_answer_correct[]"]').val(0);
654
655                        if (wrong_img_URL_HTML != "") {
656                            $(this).parent().append(wrong_img_URL_HTML);
657                        }
658
659                        if( aysThisQuizBullets !== null ){
660                            var thisQuestionID = $(e.target).parents('div[data-question-id]').data('questionId');
661                            var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
662                            thisBullet.attr('disabled', 'disabled');
663                            thisBullet.addClass('ays_quiz_wrong_answer');
664                            if (!thisBullet.parent().hasClass('ays-quiz-questions-nav-item-last-question')) {
665                                thisBullet.parent().addClass('ays_quiz_checked_answer_div');
666                            }
667                        }
668
669                        if(showOnlyWrongAnswer === false && questionType != 'checkbox'){
670                            var rightAnswerText = '<div class="ays-text-right-answer">';
671
672                            if(type == 'date'){
673                                var correctDate = new Date(thisAnswerOptions.question_answer),
674                                    correctDateYear = correctDate.getUTCFullYear(),
675                                    correctDateMonth = (correctDate.getUTCMonth() + 1) < 10 ? "0"+(correctDate.getUTCMonth() + 1) : (correctDate.getUTCMonth() + 1),
676                                    correctDateDay = (correctDate.getUTCDate() < 10) ? "0"+correctDate.getUTCDate() : correctDate.getUTCDate();
677                                rightAnswerText += [correctDateMonth, correctDateDay, correctDateYear].join('/');
678                            }else if(type != 'number'){
679                                // rightAnswerText += thisQuestionAnswer[0];
680                                rightAnswerText += displayingQuestionAnswer[0];
681                            }else{
682                                // rightAnswerText += thisQuestionAnswer;
683                                rightAnswerText += displayingQuestionAnswer;
684                            }
685
686                            rightAnswerText += '</div>';
687                            $(this).parents('.ays-quiz-answers').append(rightAnswerText);
688                            $(this).parents('.ays-quiz-answers').find('.ays-text-right-answer').slideDown(500);
689                        }
690
691                        if(! $(this).parents('.step').hasClass('not_influence_to_score')){
692                            $(this).parents('.step').find('.wrong_answer_text').slideDown(250);
693                        }
694
695                        if(finishAfterWrongAnswer){
696                            $(this).parents('div[data-question-id]').find('.ays_
696next').attr('disabled', 'disabled');
697                            $(this).parents('div[data-question-id]').find('.ays_early_finish').attr('disabled', 'disabled');
698                            $(this).parents('div[data-question-id]').find('.ays_previous').attr('disabled', 'disabled');
699                            if( disableQuestions ){
700                                quizContainer.find('div[data-question-id]').css('pointer-events', 'none');
701                            }
702                            explanationTimeout = setTimeout(function(){
703                                window.aysEarlyFinishConfirmBox[ quizId ] = true;
704                                goToLastPage(e);
705                            }, explanationTime * 1000);
706                        }
707                        if(finishAfterWrongAnswer){
708                            if( aysThisQuizBullets !== null ){
709                                aysThisQuizBullets.baseElement.find('.ays_questions_nav_question').each(function(){
710                                    var thisBullet = $(this);
711                                    thisBullet.attr('disabled', 'disabled');
712                                });
713                            }
714                        }
715                    }
716                    var showExplanationOn = (myOptions.show_questions_explanation && myOptions.show_questions_explanation != "") ? myOptions.show_questions_explanation : "on_results_page";
717                    if(showExplanationOn == 'on_passing' || showExplanationOn == 'on_both'){
718                        if(! $(this).parents('.step').hasClass('not_influence_to_score')){
719                            $(this).parents('.step').find('.ays_questtion_explanation').slideDown(250);
720                        }
721                    }
722
723                    explanationTimeout = setTimeout(function(){
724                        if ( quiz_display_all_questions && isRequiredQuestion && !enableNextButton ) {
725                            var existsEmtpyQuestions = ays_quiz_is_question_empty( quizContainer.find('div[data-question-id]') );
726                            if ( existsEmtpyQuestions ) {
727                                quizContainer.find('input.ays_finish').trigger('click');
728                            }
729                        }
730                    }, explanationTime * 1000);
731
732                    stopQuestionTimer(quizContainer, questionId, quizId);
733                }
734            }
735        });
736
737        $(document).find('textarea.ays_question_limit_length, input.ays_question_limit_length').on('keyup keypress', function(e) {
738            var $this = $(this);
739            var questionId = $this.attr('data-question-id');
740            var container = $this.parents('.ays-field').next('.ays_quiz_question_text_conteiner');
741            var box = container.find('.ays_quiz_question_text_message');
742            var questionTextMessage = container.find('.ays_quiz_question_text_message_span');
743
744            if (questionId !== null && questionId != '') {
745
746                // Maximum length of a text field
747                var enable_question_text_max_length = (myQuizOptions[questionId].enable_question_text_max_length && myQuizOptions[questionId].enable_question_text_max_length != "") ? myQuizOptions[questionId].enable_question_text_max_length : false;
748
749                // Length
750                var question_text_max_length = (myQuizOptions[questionId].question_text_max_length && myQuizOptions[questionId].question_text_max_length != "") ? parseInt(myQuizOptions[questionId].question_text_max_length) : '';
751
752                // Limit by
753                var question_limit_text_type = (myQuizOptions[questionId].question_limit_text_type && myQuizOptions[questionId].question_limit_text_type != "") ? myQuizOptions[questionId].question_limit_text_type : 'characters';
754
755                // Show word/character counter
756                var question_enable_text_message = (myQuizOptions[questionId].question_enable_text_message && myQuizOptions[questionId].question_enable_text_message != '') ? myQuizOptions[questionId].question_enable_text_message : false;
757
758                var remainder = '';
759                if(question_text_max_length != '' && question_text_max_length != 0){
760                    switch ( question_limit_text_type ) {
761                        case 'characters':
762                            var tval = $this.val();
763                            var tlength = tval.length;
764                            var set = question_text_max_length;
765                            var remain = parseInt(set - tlength);
766                            if (remain <= 0 && e.which !== 0 && e.charCode !== 0) {
767                                $this.val((tval).substring(0, tlength - 1));
768                            }
769                            if (e.type=="keyup") {
770                                var tval = $this.val().trim();
771                                if(tval.length > 0 && tval != null){
772                                    var wordsLength = this.value.split('').length;
773                                    if (wordsLength > question_text_max_length) {
774                                        var trimmed = tval.split('', question_text_max_length).join("");
775                                        $this.val(trimmed);
776                                    }
777                                }
778                            }
779                            remainder = remain;
780                            break;
781                        case 'words':
782                            if (e.type=="keyup") {
783                                var tval = $this.val().trim();
784                                if(tval.length > 0 && tval != null){
785                                    var wordsLength = this.value.match(/\S+/g).length;
786                                    if (wordsLength > question_text_max_length) {
787                                        var trimmed = tval.split(/\s+/, question_text_max_length).join(" ");
788                                        $this.val(trimmed + " ");
789                                    }
790                                    remainder = question_text_max_length - wordsLength;
791                                }
792                            }
793                            break;
794                        default:
795                            break;
796                    }
797                    if (e.type=="keyup") {
798                        if ( question_enable_text_message ) {
799                            if(question_text_max_length != '' && question_text_max_length != 0){
800                                if (remainder <= 0) {
801                                    remainder = 0;
802                                    if (! box.hasClass('ays_quiz_question_text_error_message') ) {
803                                        box.addClass('ays_quiz_question_text_error_message')
804                                    }
805                                }else{
806                                    if ( box.hasClass('ays_quiz_question_text_error_message') ) {
807                                        box.removeClass('ays_quiz_question_text_error_message')
808                                    }
809                                }
810                                if (tval.length == 0 || tval == null) {
811                                    if ( box.hasClass('ays_quiz_question_text_error_message') ) {
812                                        box.removeClass('ays_quiz_question_text_error_message')
813                                    }
814                                    remainder = question_text_max_length;
815                                }
816
817                                questionTextMessage.html( remainder );
818                            }
819                        }
820                    }
821                }
822            }
823        });
824
825        $(document).on('click', '.enable_max_selection_number input[type="checkbox"]', function(e) {
826            var $this = $(this);
827
828            var parent = $this.parents('.step');
829            var questionId = parent.attr('data-question-id');
830            questionId = parseInt( questionId );
831
832            var checkedCount = parent.find('.ays-field input[type="checkbox"]:checked').length;
833
834            if (questionId !== null && questionId != '' && typeof myQuizOptions[questionId] != 'undefined') {
835
836                // Maximum length of a text field
837                var enable_max_selection_number = (myQuizOptions[questionId].enable_max_selection_number && myQuizOptions[questionId].enable_max_selection_number != "") ? myQuizOptions[questionId].enable_max_selection_number : false;
838
839                // Length
840                var max_selection_number = (myQuizOptions[questionId].max_selection_number && myQuizOptions[questionId].max_selection_number != "") ? parseInt(myQuizOptions[questionId].max_selection_number) : '';
841
842                if( enable_max_selection_number === true && max_selection_number != '' ){
843
844                    if( max_selection_number < checkedCount ){
845                        return false;
846                    }
847                }
848            }
849
850        });
851
852        $(document).on('click', '.enable_min_selection_number input[type="checkbox"]', function(e) {
853            var $this = $(this);
854            var this_current_fs = $this.parents('.step[data-question-id]');
855            var enableArrows = $this.parents(".ays-questions-container").find(".ays_qm_enable_arrows").val();
856            var questions = $(this).parents('form.ays-quiz-form').find('.step[data-question-id]');
857            var next_sibilings_count = $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page').val();
858            var current_fs_indexes = [];
859
860            var thisIndex = 0;
861            for( var j = 0; j < Math.floor( questions.length / parseInt( next_sibilings_count ) ); j++ ){
862                thisIndex += parseInt( next_sibilings_count );
863                current_fs_indexes.push( thisIndex - 1 );
864            }
865
866            var thisStepIndex = 0;
867            var thisQuestionStepIndex = questions.index( $this.parents('.step[data-question-id]') );
868            for( var k = 0; k < current_fs_indexes.length; k++ ){
869                if( thisQuestionStepIndex <= current_fs_indexes[k] ){
870                    thisStepIndex = current_fs_indexes[k];
871                    break;
872                }
873            }
874
875            if( thisStepIndex == 0 ){
876                thisStepIndex = questions.length - 1;
877            }
878
879            var current_fs_index = questions.index( questions.eq( thisStepIndex ) );
880
881            // Display all questions on one page
882            myOptions.quiz_display_all_questions = ( myOptions.quiz_display_all_questions ) ? myOptions.quiz_display_all_questions : 'off';
883            var quiz_display_all_questions = (myOptions.quiz_display_all_questions && myOptions.quiz_display_all_questions == "on") ? true : false;
884
885            if ( quiz_display_all_questions ) {
886                next_sibilings_count = questions.length;
887            }
888
889
890            var buttonsDiv = $(this).parents('form.ays-quiz-form').find('.step[data-question-id]').eq( thisStepIndex ).find('.ays_buttons_div');
891            if($(this).parents('.step').attr('data-question-id')){
892                if( parseInt( next_sibilings_count ) > 0 && ( $(this).parents('.step').attr('data-question-id') || $(this).parents('.step').next().attr('data-question-id') ) ){
893                    var sliceStart = current_fs_index - parseInt( next_sibilings_count ) < 0 ? 0 : current_fs_index - parseInt( next_sibilings_count ) + 1;
894                    this_current_fs = questions.slice( sliceStart, current_fs_index + 1 );
895                }else{
896                    this_current_fs = $(this).parents('.step[data-question-id]');
897                    buttonsDiv = this_current_fs.find('.ays_buttons_div');
898                }
899            }else{
900                this_current_fs = $(this).parents('.step[data-question-id]');
901                buttonsDiv = this_current_fs.find('.ays_buttons_div');
902            }
903
904            this_current_fs.each(function(){
905                var checkedMinSelCount = aysCheckMinimumCountCheckbox( $(this), myQuizOptions );
906
907                // if( ays_quiz_is_question_min_count( $(this), !checkedMinSelCount ) === true ){
908                    if( checkedMinSelCount == true ){
909                        if(enableArrows){
910                            buttonsDiv.find('i.ays_next_arrow').removeAttr('disabled');
911                            buttonsDiv.find('i.ays_next_arrow').prop('disabled', false);
912                            buttonsDiv.find('i.ays_early_finish').prop('disabled', false);
913                        }else{
914                            buttonsDiv.find('input.ays_next').removeAttr('disabled');
915                            buttonsDiv.find('input.ays_next').prop('disabled', false);
916                            buttonsDiv.find('input.ays_early_finish').prop('disabled', false);
917                        }
918                    }else{
919                        if(enableArrows){
920                            buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled');
921                            buttonsDiv.find('i.ays_next_arrow').prop('disabled', true);
922                            buttonsDiv.find('i.ays_early_finish').prop('disabled', true);
923                        }else{
924                            buttonsDiv.find('input.ays_next').attr('disabled', 'disabled');
925                            buttonsDiv.find('input.ays_next').prop('disabled', true);
926                            buttonsDiv.find('input.ays_early_finish').prop('disabled', true);
927                        }
928                    }
929                // }else{
930                //     if(enableArrows){
931                //         buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled');
932                //         buttonsDiv.find('i.ays_next_arrow').prop('disabled', true);
933                //         buttonsDiv.find('i.ays_early_finish').prop('disabled', true);
934                //     }else{
935                //         buttonsDiv.find('input.ays_next').attr('disabled', 'disabled');
936                //         buttonsDiv.find('input.ays_next').prop('disabled', true);
937                //         buttonsDiv.find('input.ays_early_finish').prop('disabled', true);
938                //         return false;
939                //     }
940                // }
941            });
942        });
943
944        // on('keyup keypress') old event
945        $(document).find('input.ays_question_number_limit_length').on('focusout', function(e) {
946            var $this = $(this);
947            var questionId = $this.parents('.step[data-question-id]').attr('data-question-id');
948            var parent = $this.parents('.ays-abs-fs');
949
950            if (questionId !== null && questionId != '') {
951                var questionOptions = myQuizOptions[questionId];
952
953                // Maximum length of a number field
954                var enable_question_number_max_length = (questionOptions.enable_question_number_max_length && questionOptions.enable_question_number_max_length != "") ? questionOptions.enable_question_number_max_length : false;
955
956                // Length
957                var question_number_max_length = (typeof questionOptions.question_number_max_length != 'undefined' && questionOptions.question_number_max_length !== "") ? parseInt(questionOptions.question_number_max_length) : '';
958
959                // Minimum length of a number field
960                var enable_question_number_min_length = (questionOptions.enable_question_number_min_length && questionOptions.enable_question_number_min_length != "") ? questionOptions.enable_question_number_min_length : false;
961
962                // Length
963                var question_number_min_length = (typeof questionOptions.question_number_min_length != 'undefined' && questionOptions.question_number_min_length !== "") ? parseInt(questionOptions.question_number_min_length) : '';
964
965                // Show error message
966                var enable_question_number_error_message = (questionOptions.enable_question_number_error_message && questionOptions.enable_question_number_error_message != "") ? questionOptions.enable_question_number_error_message : false;
967
968                // Message
969                var question_number_error_message = (questionOptions.question_number_error_message && questionOptions.question_number_error_message != "") ? questionOptions.question_number_error_message : '';
970
971                if ( enable_question_number_max_length ) {
972                    if(question_number_max_length !== ''){
973                        var tval = $this.val().trim();
974                        var inputVal = parseInt( tval );
975
976                        if( ! isNaN(inputVal) ){
977                            if ( inputVal > question_number_max_length ) {
978                                $this.val(question_number_max_length);
979                            }
980
981                            if (e.type=="keyup") {
982                                if ( inputVal > question_number_max_length ) {
983                                    $this.val(question_number_max_length);
984                                }
985                            }
986                        }
987                    }
988                }
989
990                if ( enable_question_number_min_length ) {
991                    if(question_number_min_length !== ''){
992                        var tval = $this.val().trim();
993                        var inputVal = parseInt( tval );
994                        if( ! isNaN(inputVal) ){
995                            if ( inputVal < question_number_min_length ) {
996                                $this.val(question_number_min_length);
997                            }
998
999                            if (e.type=="keyup") {
1000                                if ( inputVal < question_number_min_length ) {
1001                                    $this.val(question_number_min_length);
1002                                }
1003                            }
1004                        }
1005                    }
1006                }
1007
1008                if ( enable_question_number_error_message ) {
1009                    if ( question_number_error_message != "" ) {
1010                        var tval = $this.val().trim();
1011                        var inputVal = tval;
1012
1013                        var errorMessageBox = parent.find('.ays-quiz-number-error-message');
1014
1015                        if ( tval != "" ) {
1016
1017                            if ( isNaN( +inputVal ) ) {
1018                                if ( errorMessageBox.hasClass('ays_display_none') ) {
1019                                    errorMessageBox.removeClass('ays_display_none');
1020                                }
1021                            } else if ( tval.indexOf("e") > -1 ) {
1022                                if ( errorMessageBox.hasClass('ays_display_none') ) {
1023                                    errorMessageBox.removeClass('ays_display_none');
1024                                }
1025                            } else if ( tval.slice(-1) == "e" ) {
1026                                if ( errorMessageBox.hasClass('ays_display_none') ) {
1027                                    errorMessageBox.removeClass('ays_display_none');
1028                                }
1029                            } else {
1030                                if ( ! errorMessageBox.hasClass('ays_display_none') ) {
1031                                    errorMessageBox.addClass('ays_display_none');
1032                                }
1033                            }
1034                        } else {
1035                            if ( ! errorMessageBox.hasClass('ays_display_none') ) {
1036                                errorMessageBox.addClass('ays_display_none');
1037                            }
1038                        }
1039                    }
1040                }
1041            }
1042        });
1043
1044        $(document).on('change', 'input[name^="ays_questions"]', function (e) {
1045            var _this = $(this);
1046
1047            checkCheckboxRadioQuestion(e, _this);
1048
1049        });
1050
1051        $(document).on('change', 'textarea[name^="ays_questions"], input[type="text"][name^="ays_questions"], input[type="number"][name^="ays_questions"], input[type="date"][name^="ays_questions"]', function (e) {
1052            if( $(e.target).val().length > 0 ){
1053                if( aysThisQuizBullets !== null ){
1054                    var thisQuestionID = $(e.target).parents('div[data-question-id]').data('questionId');
1055                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
1056                    thisBullet.parents('.ays-quiz-questions-nav-item').addClass('ays-quiz-questions-nav-item-answered');
1057                    $(e.target).parents('div[data-question-id]').removeClass('ays-has-error');
1058                    thisBullet.removeClass('ays-has-error');
1059                }
1060            }else{
1061                if( aysThisQuizBullets !== null ){
1062                    var thisQuestionID = $(e.target).parents('div[data-question-id]').data('questionId');
1063                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
1064                    thisBullet.parents('.ays-quiz-questions-nav-item').removeClass('ays-quiz-questions-nav-item-answered');
1065                }
1066            }
1067        });
1068
1069        $(document).on('input', 'textarea[name^="ays_questions"], input[name^="ays_questions"]', function (e) {
1070
1071            var _this = $(this);
1072            var parentStep = _this.parents('.step');
1073            var questionType = parentStep.attr('data-type');
1074
1075            if( $(e.target).val().length > 0 ){
1076                if( aysThisQuizBullets !== null ){
1077                    var thisQuestionID = $(e.target).parents('div[data-question-id]').data('questionId');
1078                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
1079                    thisBullet.parents('.ays-quiz-questions-nav-item').addClass('ays-quiz-questions-nav-item-answered');
1080                    $(e.target).parents('div[data-question-id]').removeClass('ays-has-error');
1081                    thisBullet.removeClass('ays-has-error');
1082                }
1083            }else{
1084                if( aysThisQuizBullets !== null ){
1085                    var thisQuestionID = $(e.target).parents('div[data-question-id]').data('questionId');
1086                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
1087                    thisBullet.parents('.ays-quiz-questions-nav-item').removeClass('ays-quiz-questions-nav-item-answered');
1088                }
1089            }
1090
1091            if(typeof myOptions != 'undefined'){
1092                var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
1093                if(isRequiredQuestion === true){
1094                    if( questionType === 'fill_in_blank' ){
1095                        var fill_in_blank_answers = parentStep.find('.ays-quiz-fill-in-blank-input');
1096
1097                        var fill_in_blank_flag = true;
1098                        if(fill_in_blank_answers.length > 0){
1099                            for (var i = 0; i < fill_in_blank_answers.length; i++) {
1100                                var current_input_val = $(fill_in_blank_answers[i]).val();
1101                                if( current_input_val == '' ){
1102                                    fill_in_blank_flag = false;
1103                                    break;
1104                                }
1105                            }
1106                        }
1107
1108                        if( fill_in_blank_flag ){
1109                            if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
1110                                $(e.target).parents('div[data-question-id]').find('input.ays_next').removeAttr('disabled');
1111                                $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').removeAttr('disabled');
1112                            }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1113                                $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').removeAttr('disabled');
1114                                $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').removeAttr('disabled');
1115                            }
1116                        }else{
1117                            if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
1118                                $(e.target).parents('div[data-question-id]').find('input.ays_next').attr('disabled', true);
1119                                $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').attr('disabled', true);
1120                            }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1121                                $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').attr('disabled', true);
1122                                $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').attr('disabled', true);
1123                            }
1124                        }
1125                    } else {
1126                        if($(e.target).attr('type') === 'text' ||
1127                           $(e.target).attr('type') === 'number' ||
1128                           $(e.target).attr('type') === 'date'){
1129                            if($(e.target).val() != ''){
1130                                if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
1131                                    $(e.target).parents('div[data-question-id]').find('input.ays_next').removeAttr('disabled');
1132                                    $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').removeAttr('disabled');
1133                                }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1134                                    $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').removeAttr('disabled');
1135                                    $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').removeAttr('disabled');
1136                                }
1137                            }else{
1138                                if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
1139                                    $(e.target).parents('div[data-question-id]').find('input.ays_next').attr('disabled', true);
1140                                    $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').attr('disabled', true);
1141                                }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
1142                                    $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').attr('disabled', true);
1143                                    $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').attr('disabled', true);
1144                                }
1145                            }
1146                        }
1147                    }
1148                }
1149            }
1150        });
1151
1152        $(document).on('input', '.information_form input[name="ays_user_name"]', function(){
1153            if ($(this).attr('type') !== 'hidden') {
1154                $(this).removeClass('ays_red_border');
1155                $(this).removeClass('ays_green_border');
1156                if($(this).val() != ''){
1157                    $(this).addClass('ays_green_border');
1158                } else {
1159                    $(this).addClass('ays_red_border');
1160                }
1161            }
1162        });
1163
1164        $(document).on('input', '.information_form input[name="ays_user_phone"]', function(){
1165            if ($(this).attr('type') !== 'hidden') {
1166                $(this).removeClass('ays_red_border');
1167                $(this).removeClass('ays_green_border');
1168                if($(this).val() != ''){
1169                    if (!validatePhoneNumber($(this).get(0))) {
1170                        $(this).addClass('ays_red_border');
1171                    }else{
1172                        $(this).addClass('ays_green_border');
1173                    }
1174                }
1175            }
1176        });
1177        
1178        $(document).on('input', 'input.ays_quiz_password', function(e){
1179            var $this = $(this);
1180            var startButton = $this.parents('.ays-quiz-container').find('input.start_button');
1181            if($this.val() != ''){
1182                startButton.removeAttr('disabled');
1183            }else{
1184                startButton.attr('disabled', 'disabled');
1185            }
1186        });
1187
1188        $(document).on('click', '.ays-quiz-password-toggle', function(e){
1189            var $this  = $(this);
1190
1191            var parent = $this.parents('.ays-quiz-password-toggle-visibility-box');
1192            var passwordInput = parent.find('.ays_quiz_password');
1193
1194            var visibilityOn  = parent.find('.ays-quiz-password-toggle-visibility');
1195            var visibilityOff = parent.find('.ays-quiz-password-toggle-visibility-off');
1196
1197            if( $this.hasClass('ays-quiz-password-toggle-visibility-off') ) {
1198                passwordInput.attr('type', 'text');
1199
1200                if ( visibilityOn.hasClass('ays_display_none') ) {
1201                    visibilityOn.removeClass('ays_display_none');
1202                }
1203
1204                if ( ! visibilityOff.hasClass('ays_display_none') ) {
1205                    visibilityOff.addClass('ays_display_none');
1206                }
1207
1208            } else if( $this.hasClass('ays-quiz-password-toggle-visibility') ) {
1209                passwordInput.attr('type', 'password');
1210
1211                if ( ! visibilityOn.hasClass('ays_display_none') ) {
1212                    visibilityOn.addClass('ays_display_none');
1213                }
1214
1215                if ( visibilityOff.hasClass('ays_display_none') ) {
1216                    visibilityOff.removeClass('ays_display_none');
1217                }
1218            }
1219        });
1220
1221        setTimeout(function(){
1222            $(document).find('input.ays_quiz_password').val('');
1223        }, 500);
1224
1225        $(document).on('input', '.information_form input[name="ays_user_email"], .information_form input[type="email"]', function(){
1226            if ($(this).attr('type') !== 'hidden') {
1227                $(this).removeClass('ays_red_border');
1228                $(this).removeClass('ays_green_border');
1229                if($(this).val() != ''){
1230                    if (!(emailValivatePattern.test($(this).val().trim()))) {
1231                        $(this).addClass('ays_red_border');
1232                    }else{
1233                        $(this).addClass('ays_green_border');
1234                    }
1235                }
1236            }
1237        });
1238
1239        $(document).find('.ays-text-field .ays-text-input').each(function(ev){
1240            $(this).on('keydown', function(e){
1241                myOptions.enable_enter_key = !( myOptions.enable_enter_key ) ? "on" : myOptions.enable_enter_key;
1242                var enableEnterKey = (myOptions.enable_enter_key && myOptions.enable_enter_key == "on") ? true : false;
1243                var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
1244                var isKeyboardNavigation = (myOptions.quiz_enable_keyboard_navigation && myOptions.quiz_enable_keyboard_navigation == "on") ? true : false;
1245                if(enableEnterKey || isKeyboardNavigation){
1246                    if (e.keyCode === 13 && !e.shiftKey) {
1247                        if(animating){
1248                            return false;
1249                        }
1250                        if(isRequiredQuestion === true){
1251                            if($(this).val() == ''){
1252                                return false;
1253                            }
1254                        }
1255                        if($(this).parents('.step').find('input.ays_finish.action-button').length > 0){
1256                            $(this).parents('.step').find('input.ays_finish.action-button').trigger('click');
1257                        }else{
1258                            $(this).parents('.step').find('input.ays_next.action-button').trigger('click');
1259                        }
1260                        $(this).trigger('blur');
1261                        return false;
1262                    }
1263                }
1264            });
1265        });
1266
1267        $(document).find('.ays_next').on('click', function(e, triggeredBy){
1268            if (triggeredBy === 'save_button') {
1269                return;
1270            }
1271
1272            e.preventDefault();
1273            var quizId = $(this).parents('.ays-quiz-container').find('input[name="ays_quiz_id"]').val();
1274
1275            var isTriggeredByResumeButton = e.params && e.params.triggeredBy && e.params.triggeredBy === 'resume_button';
1276            if (!isTriggeredByResumeButton) {
1277                if(checkQuizPassword(e, myOptions, true) === false){
1278                    return false;
1279                }
1280            }
1281
1282            if ( typeof window.aysSeeResultConfirmBox[ quizId ] != 'undefined' && window.aysSeeResultConfirmBox[ quizId ] ) {
1283                window.aysSeeResultConfirmBox[ quizId ] = false;
1284                return false;
1285            }
1286
1287            if(typeof explanationTimeout != 'undefined'){
1288                clearTimeout(explanationTimeout);
1289            }
1290
1291            ays_quiz_container = $(this).parents(".ays-quiz-container");
1292            aysQuizStopYoutubeIframe(ays_quiz_container);
1293            if (!($(this).hasClass('start_button'))) {
1294                if ($(this).parents('.step').find('input[required]').length !== 0 || 
1295                    $(this).parents('.step').find('select.ays_quiz_form_input[required]').length !== 0) {
1296                    var empty_inputs = 0;
1297                    var required_inputs = $(this).parents('.step').find('input[required]');
1298                    $(this).parents('.step').find('.ays_red_border').removeClass('ays_red_border');
1299                    $(this).parents('.step').find('.ays_green_border').removeClass('ays_green_border');
1300                    for (var i = 0; i < required_inputs.length; i++) {
1301                        switch(required_inputs.eq(i).attr('type')){
1302                            case "checkbox": {
1303                                if(required_inputs.eq(i).prop('checked') === false){
1304                                    required_inputs.eq(i).addClass('ays_red_border');
1305                                    required_inputs.eq(i).addClass('shake');
1306                                    empty_inputs++;
1307                                }else{
1308                                    required_inputs.eq(i).addClass('ays_green_border');
1309                                }
1310                                break;
1311                            }
1312                            case "email": {
1313                                if (!(emailValivatePattern.test(required_inputs.eq(i).val().trim()))) {
1314                                    required_inputs.eq(i).addClass('ays_red_border');
1315                                    required_inputs.eq(i).addClass('shake');
1316                                    empty_inputs++;
1317                                }else{
1318                                    required_inputs.eq(i).addClass('ays_green_border');
1319                                }
1320                                break;
1321                            }
1322                            case "tel": {
1323                                if (!validatePhoneNumber(required_inputs.eq(i).get(0))) {
1324                                    required_inputs.eq(i).addClass('ays_red_border');
1325                                    required_inputs.eq(i).addClass('shake');
1326                                    empty_inputs++;
1327                                }else{
1328                                    required_inputs.eq(i).addClass('ays_green_border');
1329                                }
1330                                break;
1331                            }
1332                            case "file": {
1333                                var fileParentDiv = required_inputs.eq(i).parents('.ays-quiz-upload-type-main');
1334                                var hiddenInputFileValue = fileParentDiv.find('.ays-quiz-upload-ready-url-link').val();
1335                                if (! hiddenInputFileValue ) {
1336                                    fileParentDiv.addClass('ays_red_border');
1337                                    fileParentDiv.addClass('shake');
1338                                    empty_inputs++;
1339                                }else{
1340                                    fileParentDiv.addClass('ays_green_border');
1341                                }
1342                                break;
1343                            }
1344                            default:{
1345                                if (required_inputs.eq(i).val().trim() === '' &&
1346                                    required_inputs.eq(i).attr('type') !== 'hidden') {
1347                                    required_inputs.eq(i).addClass('ays_red_border');
1348                                    required_inputs.eq(i).addClass('shake');
1349                                    empty_inputs++;
1350                                }else{
1351                                    required_inputs.eq(i).addClass('ays_green_border');
1352                                }
1353                                break;
1354                            }
1355                        }
1356                    }
1357                    var empty_inputs2 = 0;
1358                    var phoneInput = $(this).parents('.step').find('input[name="ays_user_phone"]');
1359                    var emailInput = $(this).parents('.step').find('input[name="ays_user_email"]');
1360                    var selectAttr = $(this).parents('.step').find('select.ays_quiz_form_input[required]');
1361                    if(phoneInput.val() != ''){
1362                        phoneInput.removeClass('ays_red_border');
1363                        phoneInput.removeClass('ays_green_border');
1364                        if (!validatePhoneNumber(phoneInput.get(0))) {
1365                            if (phoneInput.attr('type') !== 'hidden') {
1366                                phoneInput.addClass('ays_red_border');
1367                                phoneInput.addClass('shake');
1368                                empty_inputs2++;
1369                            }
1370                        }else{
1371                            phoneInput.addClass('ays_green_border');
1372                        }
1373                    }
1374                    if(emailInput.val() != ''){
1375                        emailInput.removeClass('ays_red_border');
1376                        emailInput.removeClass('ays_green_border');
1377                        if (!(emailValivatePattern.test(emailInput.val().trim()))) {
1378                            if (emailInput.attr('type') !== 'hidden') {
1379                                emailInput.addClass('ays_red_border');
1380                                emailInput.addClass('shake');
1381                                empty_inputs++;
1382                            }
1383                        }else{
1384                            emailInput.addClass('ays_green_border');
1385                        }
1386                    }
1387
1388                    for (var i = 0; i < selectAttr.length; i++) {
1389                        if(selectAttr.eq(i).val() == ''){
1390                            selectAttr.eq(i).removeClass('ays_red_border');
1391                            selectAttr.eq(i).removeClass('ays_green_border');
1392
1393                            selectAttr.eq(i).addClass('ays_red_border');
1394                            selectAttr.eq(i).addClass('shake');
1395                            empty_inputs++;
1396                        }else{
1397                            selectAttr.eq(i).removeClass('ays_red_border');
1398                        }
1399                    }
1400                    var errorFields = $(this).parents('.step').find('.ays_red_border');
1401                    if (empty_inputs2 !== 0 || empty_inputs !== 0) {
1402                        setTimeout(function(){
1403                            errorFields.each(function(){
1404                                $(this).removeClass('shake');
1405                            });
1406                        }, 500);
1407                        setTimeout(function(){
1408                            required_inputs.each(function(){
1409                                $(this).removeClass('shake');
1410                            });
1411                        }, 500);
1412                        return false;
1413                    }else{
1414                        $(this).addClass('ays_start_allow');
1415                    }
1416                }else{
1417                    if ($(this).parents('.step').find('.information_form').length !== 0 ){
1418                        var empty_inputs = 0;
1419                        var phoneInput = $(this).parents('.step').find('input[name="ays_user_phone"]');
1420                        var emailInput = $(this).parents('.step').find('input[name="ays_user_email"]');
1421                        var emailInputs = $(this).parents('.step').find('input[type="email"]');
1422                        if(phoneInput.val() != ''){
1423                            phoneInput.removeClass('ays_red_border');
1424                            phoneInput.removeClass('ays_green_border');
1425                            if (!validatePhoneNumber(phoneInput.get(0))) {
1426                                if (phoneInput.attr('type') !== 'hidden') {
1427                                    phoneInput.addClass('ays_red_border');
1428                                    phoneInput.addClass('shake');
1429                                    empty_inputs++;
1430                                }
1431                            }else{
1432                                phoneInput.addClass('ays_green_border');
1433                            }
1434                        }
1435                        if(emailInput.val() != ''){
1436                            emailInput.removeClass('ays_red_border');
1437                            emailInput.removeClass('ays_green_border');
1438                            if (!(emailValivatePattern.test(emailInput.val().trim()))) {
1439                                if (emailInput.attr('type') !== 'hidden') {
1440                                    emailInput.addClass('ays_red_border');
1441                                    emailInput.addClass('shake');
1442                                    empty_inputs++;
1443                                }
1444                            }else{
1445                                emailInput.addClass('ays_green_border');
1446                            }
1447                        }
1448                        emailInputs.each(function(){
1449                            var thisEmailInput = $(this);
1450                            if(thisEmailInput.val() != ''){
1451                                thisEmailInput.removeClass('ays_red_border');
1452                                thisEmailInput.removeClass('ays_green_border');
1453                                if (!(emailValivatePattern.test(thisEmailInput.val().trim()))) {
1454                                    thisEmailInput.addClass('ays_red_border');
1455                                    thisEmailInput.addClass('shake');
1456                                    empty_inputs++;
1457                                }else{
1458                                    thisEmailInput.addClass('ays_green_border');
1459                                }
1460                            }
1461                        });
1462                        var errorFields = $(this).parents('.step').find('.ays_red_border');
1463                        if (empty_inputs !== 0) {
1464                            setTimeout(function(){
1465                                errorFields.each(function(){
1466                                    $(this).removeClass('shake');
1467                                });
1468                            }, 500);
1469                            return false;
1470                        }
1471                        $(this).addClass('ays_start_allow');
1472                    }
1473                }
1474            }
1475            
1476            if (animating) return false;
1477            animating = true;
1478            current_fs = $(this).parents('.step');
1479            next_fs = $(this).parents('.step').next();
1480
1481            var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
1482            var enableNavigationBar = (myOptions.enable_navigation_bar && myOptions.enable_navigation_bar == "on") ? true : false;
1483            var quizDisableInputFocusing = (myOptions.quiz_disable_input_focusing && myOptions.quiz_disable_input_focusing == "on") ? true : false;
1484            var timerMainContainer = ays_quiz_container.find('.ays_quiz_timer_container');
1485            var timerType = myOptions.quiz_timer_type ? myOptions.quiz_timer_type : 'quiz_timer';
1486
1487            if( current_fs.find('.information_form').length === 0 && !($(this).hasClass('ays_finish')) && !($(this).hasClass('start_button')) ) {
1488                if (myOptions.enable_timer && myOptions.enable_timer === 'on') {
1489                    if (myOptions.quiz_timer_type && myOptions.quiz_timer_type === 'question_timer') {
1490                        if (window.aysQuizQuestionTimers && window.aysQuizQuestionTimers[quizId]) {
1491                            if (myOptions.enable_navigation_bar && myOptions.enable_navigation_bar === 'on') {
1492                                if (myOptions.make_questions_required && myOptions.make_questions_required === "on") {
1493                                    var qid = checkQuestionTimer(ays_quiz_container, quizId);
1494                                    if (qid === false) {
1495                                        for (var questionID in window.aysQuizQuestionTimers[quizId]) {
1496                                            stopQuestionTimer(ays_quiz_container, questionID, quizId);
1497                                        }
1498                                        timerMainContainer.addClass('ays-quiz-timer-end-for-required')
1499                                    }
1500                                }
1501                            }
1502                        }
1503                    }
1504                }
1505            }
1506
1507            if ( typeof window.aysEarlyFinishConfirmBox[ quizId ] != 'undefined' && ! window.aysEarlyFinishConfirmBox[ quizId ] ) {
1508                if( ! timerMainContainer.hasClass('ays-quiz-timer-end-for-required') ){
1509                    if(isRequiredQuestion === true){
1510                        if(next_fs.find('.information_form').length === 0){
1511                            if ( $(this).hasClass("ays_finish") ) {
1512                                if ( enableNavigationBar ) {
1513                                    ays_quiz_is_question_required( ays_quiz_container.find('.step') );
1514                                    if( ays_quiz_container.hasClass('ays-quiz-has-error') ){
1515                                        return false;
1516                                    }
1517                                }
1518                            }
1519                        } else {
1520                            var questions_count = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').length;
1521                            var curent_number = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').index($(this).parents('div[data-question-id]'))+1;
1522                            var questionCountPerPage = myOptions.question_count_per_page && myOptions.question_count_per_page === 'on' ? true : false;
1523
1524                            // Display all questions on one page
1525                            myOptions.quiz_display_all_questions = ( myOptions.quiz_display_all_questions ) ? myOptions.quiz_display_all_questions : 'off';
1526                            var quiz_display_all_questions = (myOptions.quiz_display_all_questions && myOptions.quiz_display_all_questions == "on") ? true : false;
1527
1528                            if(questions_count === curent_number){
1529                                if ( enableNavigationBar ) {
1530
1531                                    ays_quiz_is_question_required( ays_quiz_container.find('.step') );
1532                                    if( ays_quiz_container.hasClass('ays-quiz-has-error') ){
1533                                        return false;
1534                                    }
1535                                } else if( questionCountPerPage ){
1536                                    ays_quiz_is_question_required( ays_quiz_container.find('.step') );
1537                                    if( ays_quiz_container.hasClass('ays-quiz-has-error') ){
1538                                        return false;
1539                                    }
1540                                } else if( quiz_display_all_questions ){
1541                                    ays_quiz_is_question_required( ays_quiz_container.find('.step') );
1542                                    if( ays_quiz_container.hasClass('ays-quiz-has-error') ){
1543                                        return false;
1544                                    }
1545                                }
1546                            }
1547                        }
1548                    }
1549                }
1550            }
1551
1552            if (!($(this).hasClass('start_button')) && $(this).parents('.step').find('.information_form').length === 0  && ! window.aysEarlyFinishConfirmBox[ quizId ]) {
1553                if( $(this).parents('form.ays-quiz-form').find('div[data-question-id]').index($(this).parents('.step'))+1 === $(this).parents('form.ays-quiz-form').find('div[data-question-id]').length ){
1554                    var minSelHasError = 0;
1555                    var minSelQuestions;
1556                    var checkbox_current_fs = $(this).parents('form.ays-quiz-form').find('.step[data-type="checkbox"]');
1557                    var buttonsDiv2 = $(this).parents('.step').find('.ays_buttons_div');
1558                    // var last_fs = $(this).parents('form').find('.step[data-question-id]').last();
1559                   // if(($(this).hasClass('ays_finish')) == false){
1560                   //     minSelQuestions = next_siblings;
1561                   // }else{
1562                        minSelQuestions = checkbox_current_fs;
1563                   // }
1564                    var checkboxMinCountAndNavigationFlag = false;
1565                    for( var k = 0; k < minSelQuestions.length; k++ ){
1566                        if( $( minSelQuestions[k] ).find('.enable_min_selection_number').length > 0 ){
1567                            var checkedMinSelCount = aysCheckMinimumCountCheckbox( $( minSelQuestions[k] ), myQuizOptions );
1568                            if( ays_quiz_is_question_min_count( $( minSelQuestions[k] ), !checkedMinSelCount ) === true ){
1569                                if( checkedMinSelCount == true ){
1570                                    if(enableArrows){
1571                                        buttonsDiv2.find('i.ays_next_arrow').removeAttr('disabled');
1572                                        buttonsDiv2.find('i.ays_next_arrow').prop('disabled', false);
1573                                    }else{
1574                                        buttonsDiv2.find('input.ays_next').removeAttr('disabled');
1575                                        buttonsDiv2.find('input.ays_next').prop('disabled', false);
1576                                    }
1577                                }else{
1578                                    if(enableArrows){
1579                                        // buttonsDiv2.find('i.ays_next_arrow').attr('disabled', 'disabled');
1580                                        buttonsDiv2.find('i.ays_next_arrow').prop('disabled', false);
1581                                        buttonsDiv2.find('i.ays_next_arrow').removeClass('ays_display_none');
1582                                    }else{
1583                                        // buttonsDiv2.find('input.ays_next').attr('disabled', 'disabled');
1584                                        buttonsDiv2.find('input.ays_next').prop('disabled', false);
1585                                        buttonsDiv2.find('input.ays_next').removeClass('ays_display_none');
1586                                    }
1587                                    minSelHasError++;
1588                                    if( myOptions.enable_timer && myOptions.enable_timer === 'on' ) {  
1589                                        if( myOptions.quiz_timer_type && ( myOptions.quiz_timer_type === 'question_timer' || myOptions.quiz_timer_type === 'quiz_timer') ){
1590
1591                                            var c_qid = checkChecboxQuestionTimerForSubmitQuiz(ays_quiz_container, quizId, $( minSelQuestions[k] ));
1592                                            if (c_qid !== false) {
1593                                                checkboxMinCountAndNavigationFlag = true;
1594                                                // ays_quiz_container.find('.ays_questions_nav_question[data-id="' + c_qid + '"]').trigger('click');
1595                                            }else if( c_qid === false && minSelHasError > 0 ) {
1596                                                checkboxMinCountAndNavigationFlag = true;
1597                                            }
1598                                        }
1599                                    }
1600                                }
1601                            }else{
1602                                if(enableArrows){
1603                                    // buttonsDiv2.find('i.ays_next_arrow').attr('disabled', 'disabled');
1604                                    buttonsDiv2.find('i.ays_next_arrow').prop('disabled', false);
1605                                    buttonsDiv2.find('i.ays_next_arrow').removeClass('ays_display_none');
1606                                }else{
1607                                    // buttonsDiv2.find('input.ays_next').attr('disabled', 'disabled');
1608                                    buttonsDiv2.find('input.ays_next').prop('disabled', false);
1609                                    buttonsDiv2.find('input.ays_next').removeClass('ays_display_none');
1610                                }
1611                                minSelHasError++;
1612                                if( myOptions.enable_timer && myOptions.enable_timer === 'on' ) {
1613                                    if( myOptions.quiz_timer_type && ( myOptions.quiz_timer_type === 'question_timer' || myOptions.quiz_timer_type === 'quiz_timer') ){
1614
1615                                        var c_qid = checkChecboxQuestionTimerForSubmitQuiz(ays_quiz_container, quizId, $( minSelQuestions[k] ));
1616                                        if (c_qid !== false) {
1617                                            checkboxMinCountAndNavigationFlag = true;
1618                                            // ays_quiz_container.find('.ays_questions_nav_question[data-id="' + c_qid + '"]').trigger('click');
1619                                        }else if( c_qid === false && minSelHasError > 0 ) {
1620                                            checkboxMinCountAndNavigationFlag = true;
1621                                        }
1622                                    }
1623                                }
1624                            }
1625                        }
1626                    }
1627
1628                    if( minSelHasError > 0 ){
1629                        return false;
1630                    }
1631                    else if( checkboxMinCountAndNavigationFlag ){
1632                        return false;
1633                    }
1634                }
1635                
1636            }
1637
1638            if( current_fs.find('.information_form').length != 0 && !($(this).hasClass('ays_finish'))){
1639                $(this).parents('.ays-quiz-wrap').find('.ays-quiz-questions-nav-wrap').slideDown(500);
1640            }
1641
1642            if( next_fs.find('.information_form').length != 0 ){
1643                stopQuestionTimer( ays_quiz_container, current_fs.data('questionId'), quizId );
1644                $(this).parents('.ays-quiz-wrap').find('.ays-quiz-questions-nav-wrap').slide
1644Up(500);
1645                timerMainContainer.slideUp(500);
1646            }
1647
1648            var questions_count = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').length;
1649            var curent_number = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').index($(this).parents('div[data-question-id]')) + 1;
1650            var next_sibilings_count = $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page').val();
1651
1652            var isQuestionPerPageCustom = (myOptions.question_count_per_page_type && myOptions.question_count_per_page_type == "custom") ? true : false;
1653            var customPerPageValue = (myOptions.question_count_per_page_custom_order && myOptions.question_count_per_page_custom_order != "") ? myOptions.question_count_per_page_custom_order : "";
1654            var customPerPageRequiredFlag = true;
1655            if(next_fs.find('.information_form').length === 0){
1656                if(isRequiredQuestion === true && !$(this).hasClass('ays-quiz-after-timer-end')){
1657                    if( ays_quiz_container.hasClass('ays-quiz-has-error') ){
1658                        var customPerPageRequiredFlag = false;
1659                    }
1660                }
1661                if( isQuestionPerPageCustom && customPerPageValue != "" && customPerPageRequiredFlag ){
1662                    var custom_next_sibilings_count = $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_next').val();
1663                    var custom_prev_sibilings_count = $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_prev').val();
1664                    var questions_count_new = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').length;
1665                    if( typeof custom_next_sibilings_count != "undefined" && custom_next_sibilings_count != "" ){
1666                        var custom_next_sibilings_count_arr = custom_next_sibilings_count.split(',');
1667                        if (custom_next_sibilings_count_arr !== undefined && custom_next_sibilings_count_arr.length > 0) {
1668                            next_sibilings_count = parseInt( custom_next_sibilings_count_arr[0] );
1669                            $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page').val(next_sibilings_count);
1670
1671                            var shift_number = custom_next_sibilings_count_arr.shift();
1672                            var custom_prev_sibilings_count_arr = new Array();
1673                            if( typeof custom_prev_sibilings_count == 'undefined' || custom_prev_sibilings_count == "" ){
1674                                $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_prev').val(next_sibilings_count);
1675                            } else {
1676                                var custom_prev_sibilings_count_arr = custom_prev_sibilings_count.split(",");
1677                                custom_prev_sibilings_count_arr.push(shift_number);
1678
1679                                var custom_prev_sibilings_count_arr_new = custom_prev_sibilings_count_arr.join(",");
1680                                $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_prev').val(custom_prev_sibilings_count_arr_new);
1681                            }
1682
1683                            if( custom_next_sibilings_count_arr.length > 0 ){
1684                                var custom_next_sibilings_count_new_val = custom_next_sibilings_count_arr.join(',');
1685                                $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_next').val(custom_next_sibilings_count_new_val);
1686                            } else {
1687
1688                                var sum_prev_quesiton = 0;
1689                                for (var ii = 0; ii < custom_prev_sibilings_count_arr.length; ii++ ) {
1690                                    sum_prev_quesiton += parseInt( custom_prev_sibilings_count_arr[ii] );
1691                                }
1692                                var last_page_questions_count = parseInt(questions_count_new) - parseInt(sum_prev_quesiton);
1693                                if( last_page_questions_count != 0 ) {
1694                                    $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_next').val(last_page_questions_count);
1695                                } else {
1696                                    $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_next').val("");
1697                                }
1698                            }
1699                            var next_sibilings_count = $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page').val();
1700                        }
1701                    }
1702                }
1703
1704            }
1705
1706            // Display all questions on one page
1707            myOptions.quiz_display_all_questions = ( myOptions.quiz_display_all_questions ) ? myOptions.quiz_display_all_questions : 'off';
1708            var quiz_display_all_questions = (myOptions.quiz_display_all_questions && myOptions.quiz_display_all_questions == "on") ? true : false;
1709
1710            // Enable finish button
1711            myOptions.enable_early_finish = ( myOptions.enable_early_finish ) ? myOptions.enable_early_finish : 'off';
1712            var enable_early_finish = (myOptions.enable_early_finish && myOptions.enable_early_finish == "on") ? true : false;
1713
1714            var enableNextButton = (myOptions.enable_next_button && myOptions.enable_next_button == 'on') ? true : false;
1715
1716            if ( quiz_display_all_questions ) {
1717                next_sibilings_count = questions_count;
1718            }
1719
1720            if(parseInt(next_sibilings_count)>0 && ($(this).parents('.step').attr('data-question-id') || $(this).parents('.step').next().attr('data-question-id'))){
1721                if(parseInt(next_sibilings_count) >= questions_count){
1722                    next_sibilings_count = questions_count;
1723                }
1724
1725                var current_fs_index = $(this).parents('form.ays-quiz-form').find('.step').index($(this).parents('.step'));
1726                var new_current_fs_index = $(this).parents('form.ays-quiz-form').find('.step').index($(this).parents('form.ays-quiz-form').find('.step.active-step'));
1727                var next_fs_index = $(this).parents('form.ays-quiz-form').find('.step').index(next_fs);
1728
1729                if($(this).parents('.step').attr('data-question-id')){
1730                    if( isQuestionPerPageCustom && customPerPageValue != ""){
1731                        current_fs = $(this).parents('form.ays-quiz-form').find('.step').slice(parseInt(new_current_fs_index) - 1,next_fs_index);
1732                    } else {
1733                        current_fs = $(this).parents('form.ays-quiz-form').find('.step').slice(current_fs_index-parseInt(next_sibilings_count),current_fs_index+1);
1734                    }
1735                }else{
1736                    current_fs = $(this).parents('.step');
1737                }
1738                if(questions_count === curent_number){
1739                    if(current_fs.hasClass('.information_form').length !== 0){
1740                        current_fs.find('.ays_next').eq(current_fs.find('.ays_next').length-1).addClass('ays_timer_end');
1741                        current_fs.parents('.ays-quiz-container').find('.ays-quiz-timer').slideUp(500);
1742                        $(this).parents('.ays-quiz-container').find('input.ays-quiz-end-date').val(GetFullDateTime());
1743                    }
1744
1745                    var timer2 = parseInt(ays_quiz_container.find('div.ays-quiz-timer').attr('data-timer'));
1746                    if (!isNaN(timer2) && myOptions.timer !== undefined) {
1747                        if (myOptions.timer === timer2 && timer2 !== 0) {
1748                            var myStartDate = new Date(Date.now() - aysDurationInSeconds * AYS_MS_PER_SECONDS);
1749                            var countdownEndTime = myStartDate.aysCustomFormat( "#YYYY#-#MM#-#DD# #hhhh#:#mm#:#ss#" );
1750                            $(this).parents('.ays-quiz-container').find('input.ays-quiz-end-date').val(countdownEndTime);
1751                        } else {
1752                            $(this).parents('.ays-quiz-container').find('input.ays-quiz-end-date').val(GetFullDateTime());
1753                        }
1754                    } else {
1755                        $(this).parents('.ays-quiz-container').find('input.ays-quiz-end-date').val(GetFullDateTime());
1756                    }
1757                }
1758                
1759
1760                if(curent_number != questions_count){
1761                    if(($(this).hasClass('ays_finish')) == false){
1762                        if (!($(this).hasClass('start_button')) && ays_quiz_is_question_required( current_fs )) {
1763                            var count_per_page = Math.floor(questions_count/parseInt(next_sibilings_count));
1764                            var nextCountQuestionsPerPage = questions_count-curent_number;
1765                            var current_width = $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').width();
1766                            var final_width = ((curent_number+parseInt(next_sibilings_count)) / questions_count * 100) + "%";
1767                            if(nextCountQuestionsPerPage < parseInt(next_sibilings_count)){
1768                                final_width = ((curent_number+nextCountQuestionsPerPage) / questions_count * 100) + "%";
1769                            }
1770                            if($(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
1771                                if(nextCountQuestionsPerPage < parseInt(next_sibilings_count)){
1772                                    $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+parseInt(nextCountQuestionsPerPage)));
1773                                }else{
1774                                    $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+parseInt(next_sibilings_count)));
1775                                }
1776                            }else{
1777                                $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
1778                            }
1779                            $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 1000);
1780                        }
1781                    }
1782                }else{
1783                    $(this).parents('.ays-quiz-container').find('.ays-live-bar-wrap').removeClass('rubberBand').addClass('bounceOut');
1784                    setTimeout(function () {
1785                        $(e.target).parents('.ays-quiz-container').find('.ays-live-bar-wrap').css('display','none');
1786                    },300)
1787                }
1788                var next_siblings = $(this).parents('.step').nextAll('.step').slice(0,parseInt(next_sibilings_count));
1789
1790                if($(this).parents('form.ays-quiz-form').find('div[data-question-id]').index($(this).parents('.step'))+1 !== $(this).parents('form').find('div[data-question-id]').length) {
1791                    for (var z = 0; z < next_siblings.length; z++) {
1792                        if (next_siblings.eq(z).attr('data-question-id') === undefined) {
1793                            next_siblings.splice(z);
1794                        }
1795                    }
1796                }else{
1797                    if(next_siblings.length !== 1) {
1798                        next_siblings.splice(next_siblings.length - 1);
1799                    }
1800                }
1801
1802                if ($(this).parents('form.ays-quiz-form').hasClass('enable_correction')) {
1803                    next_siblings.find('input[name^="ays_questions"]').each(function(){
1804                        if ($(this).parents('.ays-quiz-answers').find('.correct').length === 0 &&
1805                            $(this).parents('.ays-quiz-answers').find('.wrong').length === 0 &&
1806                            $(this).parents('.ays-quiz-answers').find('.ays-answered-text-input').length === 0) {
1807                            $(this).attr('disabled', false);
1808                        }
1809                    });
1810                }
1811
1812                for(var i=0 ;i<next_siblings.length-1;i++){
1813                    var nextQuestionType = next_siblings.eq(i).find('input[name^="ays_questions"]').attr('type');
1814                    var buttonsDiv = next_siblings.eq(i).find('.ays_buttons_div');
1815                    next_siblings.eq(i).find('.ays_previous').remove();
1816                    if(i === next_siblings.length-1 && next_siblings.eq(i).find('textarea[name^="ays_questions"]').attr('type')==='text'){
1817                        buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1818                        continue;
1819                    }
1820                    if(i === next_siblings.length-1 && nextQuestionType === 'checkbox'){
1821                        buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1822                        continue;
1823                    }
1824                    if(i === next_siblings.length-1 && nextQuestionType === 'number'){
1825                        buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1826                        continue;
1827                    }
1828                    if(i === next_siblings.length-1 && nextQuestionType === 'text'){
1829                        buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1830                        continue;
1831                    }
1832                    if(i === next_siblings.length-1 && nextQuestionType === 'date'){
1833                        buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1834                        continue;
1835                    }
1836                    if(nextQuestionType === 'upload_file'){
1837                        buttonsDiv.find('input.ays_clear_answer').addClass('ays_display_none');
1838                    }
1839                    next_siblings.eq(i).find('.ays_next').remove();
1840                    next_siblings.eq(i).find('.ays_early_finish').remove();
1841                    next_siblings.eq(i).find('.ays_save_button').remove();
1842                }
1843
1844                // for(var i=0 ;i<next_siblings.length;i++){
1845                    // if ( i !== 0 ) {
1846                        // next_siblings.eq(i).find('.ays-export-quiz-button-container').remove();
1847                //     }
1848                // }
1849
1850                if ( quiz_display_all_questions ) {
1851                    next_siblings.find('.ays_previous').remove();
1852                }
1853
1854                if(current_fs.hasClass('ays-abs-fs')){
1855                    current_fs = $(this).parents('.step');
1856                    next_fs = $(this).parents('.step').next();
1857                    current_fs.removeClass('active-step');
1858                    var counterClass = "";
1859                    switch(ays_quiz_container.data('questEffect')){
1860                        case "shake":
1861                            counterClass = ays_quiz_container.data('questEffect');
1862                        break;
1863                        case "fade":
1864                            counterClass = "fadeIn";
1865                        break;
1866                        case "none":
1867                            counterClass = "";
1868                        break;
1869                        default:
1870                            counterClass = ays_quiz_container.data('questEffect');
1871                        break;
1872                    }
1873                    next_fs.find('.ays-question-counter').addClass(counterClass);
1874                }
1875
1876                var nextQuestionType = next_siblings.eq(next_siblings.length-1).find('input[name^="ays_questions"]').attr('type');
1877                var buttonsDiv = next_siblings.eq(next_siblings.length-1).find('.ays_buttons_div');
1878                var enableArrows = $(document).find(".ays-questions-container .ays_qm_enable_arrows").val();
1879                if(myOptions.enable_arrows){
1880                    enableArrows = myOptions.enable_arrows == 'on' ? true : false;
1881                }else{
1882                    enableArrows = parseInt(enableArrows) == 1 ? true : false;
1883                }
1884
1885                if ( ! enable_early_finish ) {
1886                    buttonsDiv.find('i.ays_early_finish').addClass('ays_display_none');
1887                    buttonsDiv.find('input.ays_early_finish').addClass('ays_display_none');
1888                }
1889                
1890                var nextArrowIsDisabled = buttonsDiv.find('.ays_next_arrow').hasClass('ays_display_none');
1891                var nextButtonIsDisabled = buttonsDiv.find('.ays_next').hasClass('ays_display_none');
1892
1893                if(next_siblings.eq(next_siblings.length-1).find('textarea[name^="ays_questions"]').attr('type')==='text' && nextArrowIsDisabled && nextButtonIsDisabled){
1894                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1895                }
1896                if(next_siblings.eq(next_siblings.length-1).find('textarea[name^="ays_questions"]').attr('type') === 'text' && enableArrows){
1897                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
1898                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
1899                }
1900
1901
1902                if(nextQuestionType === 'checkbox' && nextArrowIsDisabled && nextButtonIsDisabled){
1903                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1904                }
1905                if(nextQuestionType === 'checkbox' && enableArrows){
1906                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
1907                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
1908                }
1909                if(nextQuestionType === 'number' && nextArrowIsDisabled && nextButtonIsDisabled){
1910                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1911                }
1912                if(nextQuestionType === 'number' && enableArrows){
1913                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
1914                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
1915                }
1916                if(nextQuestionType === 'text' && nextArrowIsDisabled && nextButtonIsDisabled){
1917                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1918                }
1919                if(nextQuestionType === 'text' && enableArrows){
1920                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
1921                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
1922                }
1923                if(nextQuestionType === 'date' && nextArrowIsDisabled && nextButtonIsDisabled){
1924                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1925                }
1926                if(nextQuestionType === 'date' && enableArrows){
1927                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
1928                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
1929                }
1930                if(nextQuestionType === 'matching' && nextArrowIsDisabled && nextButtonIsDisabled){
1931                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1932                }
1933                if(nextQuestionType === 'matching' && enableArrows){
1934                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
1935                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
1936                }
1937                if(nextQuestionType === 'upload_file' && nextArrowIsDisabled && nextButtonIsDisabled){
1938                    buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1939                }
1940                if(nextQuestionType === 'upload_file' && enableArrows){
1941                    buttonsDiv.find('input.ays_next').addClass('ays_display_none');
1942                    buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
1943                }
1944                
1945                var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
1946
1947                if(isRequiredQuestion === true && !$(this).hasClass('ays-quiz-after-timer-end')){
1948                    if(next_siblings.find('.information_form').length === 0){
1949                        var existsEmtpyQuestions = ays_quiz_is_question_required( current_fs );
1950
1951                        // Check if all questions in current_fs are answered
1952                        var allQuestionsAnswered = true;
1953                        current_fs.find('.ays-quiz-answers').each(function() {
1954                            var questionType = $(this).parents('.step').data('type');
1955                            if (questionType === 'radio' || questionType === 'checkbox') {
1956                                if ($(this).find('input:checked').length === 0) {
1957                                    allQuestionsAnswered = false;
1958                                }
1959                            } else if (questionType === 'text' || questionType === 'short_text' || questionType === 'number') {
1960                                if ($(this).find('input').val().trim() === '') {
1961                                    allQuestionsAnswered = false;
1962                                }
1963                            }
1964                        });
1965
1966                        if (allQuestionsAnswered) {
1967                            current_fs.addClass('ays-filled-required-qestions');
1968                        }
1969
1970                        if( ! next_siblings.hasClass('ays-filled-required-qestions') && !allQuestionsAnswered ){
1971                            if(enableArrows){
1972                                buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled');
1973                            }else{
1974                                buttonsDiv.find('input.ays_next').attr('disabled', 'disabled');
1975                            }
1976                        }
1977
1978                        if ( next_siblings.eq( next_siblings.length - 1 ).hasClass('ays-custom-step') ) {
1979                            var customQuestionStep = next_siblings.eq( next_siblings.length - 1 );
1980                            if(enableArrows){
1981                                customQuestionStep.find('i.ays_next_arrow').removeAttr('disabled');
1982                                buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
1983                            }else{
1984                                customQuestionStep.find('input.ays_next').removeAttr('disabled');
1985                                buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
1986                            }
1987                        }
1988
1989                        if( existsEmtpyQuestions === false ){
1990                            return false;
1991                        }else{
1992                            current_fs.addClass('ays-filled-required-qestions');
1993                        }
1994                    } else if ( next_siblings.find('.information_form').length > 0 ) {
1995                        if ( !($(this).hasClass('start_button')) && quiz_display_all_questions && !enableNextButton ) {
1996                            var quizContainer = $(e.target).parents('.ays-quiz-container');
1997                            var existsEmtpyQuestions = ays_quiz_is_question_required( quizContainer.find('div[data-question-id]') );
1998                            
1999                            if( ! next_siblings.hasClass('ays-filled-required-qestions') ){
2000                                if(enableArrows){
2001                                    buttonsDiv.find('i.ays_next_arrow.ays_finish').prop('disabled', false);
2002                                }else{
2003                                    buttonsDiv.find('input.ays_next.ays_finish').prop('disabled', false);
2004                                }
2005                            }
2006
2007                            if( existsEmtpyQuestions === false ){
2008                                return false;
2009                            }else{
2010                                current_fs.addClass('ays-filled-required-qestions');
2011                            }
2012                        }
2013                    }
2014                }
2015
2016                if (!($(this).hasClass('start_button'))) {
2017                    var minSelHasError = 0;
2018                    var minSelQuestions = next_siblings;
2019                   // if(($(this).hasClass('ays_finish')) == false){
2020                   //     minSelQuestions = next_siblings;
2021                   // }else{
2022                        minSelQuestions = current_fs;
2023                   // }
2024
2025                    for( var k = 0; k < minSelQuestions.length; k++ ){
2026                        if( $( minSelQuestions[k] ).find('.enable_min_selection_number').length > 0 ){
2027                            var checkedMinSelCount = aysCheckMinimumCountCheckbox( $( minSelQuestions[k] ), myQuizOptions );
2028                            if( ays_quiz_is_question_min_count( $( minSelQuestions[k] ), !checkedMinSelCount ) === true ){
2029                                if( checkedMinSelCount == true ){
2030                                    if(enableArrows){
2031                                        buttonsDiv.find('i.ays_next_arrow').removeAttr('disabled');
2032                                        buttonsDiv.find('i.ays_next_arrow').prop('disabled', false);
2033                                    }else{
2034                                        buttonsDiv.find('input.ays_next').removeAttr('disabled');
2035                                        buttonsDiv.find('input.ays_next').prop('disabled', false);
2036                                    }
2037                                }else{
2038                                    if(enableArrows){
2039                                        buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled');
2040                                        buttonsDiv.find('i.ays_next_arrow').prop('disabled', true);
2041                                        buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
2042                                    }else{
2043                                        buttonsDiv.find('input.ays_next').attr('disabled', 'disabled');
2044                                        buttonsDiv.find('input.ays_next').prop('disabled', true);
2045                                        buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2046                                    }
2047                                    minSelHasError++;
2048                                }
2049                            }else{
2050                                if(enableArrows){
2051                                    buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled');
2052                                    buttonsDiv.find('i.ays_next_arrow').prop('disabled', true);
2053                                    buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
2054                                }else{
2055                                    buttonsDiv.find('input.ays_next').attr('disabled', 'disabled');
2056                                    buttonsDiv.find('input.ays_next').prop('disabled', true);
2057                                    buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2058                                }
2059                                minSelHasError++;
2060                            }
2061                        }
2062                    }
2063
2064                    if( minSelHasError > 0 ){
2065                        return false;
2066                    }
2067                }
2068
2069                ays_quiz_container.find('.active-step').removeClass('active-step');
2070                next_siblings.eq(0).addClass('active-step');
2071                aysAnimateStep(ays_quiz_container.data('questEffect'), current_fs, next_siblings);
2072
2073                if( !quizDisableInputFocusing ){
2074                    next_siblings.eq(0).find('.ays-text-input:first-child').trigger( "focus" );
2075
2076                    next_siblings.eq(0).find('.ays-text-input:first-child').trigger( "focus" );
2077                    if ( ! next_siblings.eq(0).find('.ays-text-input:first-child').is(":focus") ) {
2078                        setTimeout(function(e){
2079                            next_siblings.eq(0).find('.ays-text-input:first-child').trigger( "focus" );
2080                        },1001);
2081                    }
2082                }
2083
2084                setTimeout(function(){
2085                    if(next_siblings.find('.ays-text-field').length > 0){
2086                        if(next_siblings.find('.ays-text-field').width() < 250){
2087                            next_siblings.find('.ays-text-field').css({
2088                                'flex-wrap': 'wrap',
2089                                'justify-content': 'center',
2090                                'padding': '5px'
2091                            });
2092                            next_siblings.find('.ays-text-field').find('input.ays-text-input').css('margin-bottom', '5px');
2093                        }
2094                    }
2095                },2000);
2096            }else{
2097                current_fs = $(this).parents('.step');
2098                next_fs = $(this).parents('.step').next();
2099                var isResumed = false;
2100                if (e.params && e.params.triggeredBy && e.params.triggeredBy === 'resume_button') {
2101                    if (myOptions.enable_save_and_resume && myOptions.enable_save_and_resume === 'on') {
2102                        if ( next_fs.find('.information_form').length === 0 ) {
2103                            next_fs = e.params.questionElement;
2104                            isResumed = true;
2105                        } else {
2106                            next_fs.find('.information_form .ays_next.action-button').attr('data-triggered-by', 'resume_button')
2107                        }
2108                    }
2109                } else if (current_fs.find('.information_form .ays_next.action-button').data('triggeredBy') === 'resume_button') {
2110                    next_fs = window.aysQuizResumedCurrentQuestion || next_fs;
2111                    isResumed = true;
2112                }
2113
2114                if( aysThisQuizBullets !== null ){
2115                    var thisQuestionID = next_fs.data('questionId');
2116                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]').parents('.ays-quiz-questions-nav-item');
2117                    aysThisQuizBullets._navPage(thisBullet.index());
2118                }
2119
2120                var questions_count = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').length;
2121                // var curent_number = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').index(next_fs);
2122                var curent_number = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').index($(this).parents('div[data-question-id]'))+1;
2123                if(questions_count === curent_number){
2124                    if(current_fs.hasClass('.information_form').length !== 0){
2125                        current_fs.find('.ays_next').addClass('ays_timer_end');
2126                        current_fs.parents('.ays-quiz-container').find('.ays-quiz-timer').slideUp(500);
2127                        $(this).parents('.ays-quiz-container').find('input.ays-quiz-end-date').val(GetFullDateTime());
2128                    }
2129
2130                    var timer2 = parseInt(ays_quiz_container.find('div.ays-quiz-timer').attr('data-timer'));
2131                    if (!isNaN(timer2) && myOptions.timer !== undefined) {
2132                        if (myOptions.timer === timer2 && timer2 !== 0) {
2133                            var myStartDate = new Date(Date.now() - aysDurationInSeconds * AYS_MS_PER_SECONDS);
2134                            var countdownEndTime = myStartDate.aysCustomFormat( "#YYYY#-#MM#-#DD# #hhhh#:#mm#:#ss#" );
2135                            $(this).parents('.ays-quiz-container').find('input.ays-quiz-end-date').val(countdownEndTime);
2136                        } else {
2137                            $(this).parents('.ays-quiz-container').find('input.ays-quiz-end-date').val(GetFullDateTime());
2138                        }
2139                    } else {
2140                        $(this).parents('.ays-quiz-container').find('input.ays-quiz-end-date').val(GetFullDateTime());
2141                    }
2142                }
2143                if(curent_number != questions_count){
2144                    if(($(this).hasClass('ays_finish')) == false){
2145                        if (!($(this).hasClass('start_button')) || isResumed) {
2146                            var current_width = $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').width();
2147                            var final_width = ((curent_number+1) / questions_count * 100) + "%";
2148                            if($(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
2149                                $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+1));
2150                            }else{
2151                                $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
2152                            }
2153                            $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 1000);
2154                        }
2155                    }
2156                }else{
2157                    $(this).parents('.ays-quiz-container').find('.ays-live-bar-wrap').removeClass('rubberBand').addClass('bounceOut');
2158                    setTimeout(function () {
2159                        $(e.target).parents('.ays-quiz-container').find('.ays-live-bar-wrap').css('display','none');
2160                    },300)
2161                }
2162                if (current_fs.hasClass('ays-abs-fs')) {
2163                    current_fs = $(this).parents('.step');
2164                    next_fs = $(this).parents('.step').next();
2165                    var counterClass = "";
2166                    switch(ays_quiz_container.data('questEffect')){
2167                        case "shake":
2168                            counterClass = ays_quiz_container.data('questEffect');
2169                        break;
2170                        case "fade":
2171                            counterClass = "fadeIn";
2172                        break;
2173                        case "none":
2174                            counterClass = "";
2175                        break;
2176                        default:
2177                            counterClass = ays_quiz_container.data('questEffect');
2178                        break;
2179                    }
2180                    next_fs.find('.ays-question-counter').addClass(counterClass);
2181                }
2182                current_fs.removeClass('active-step');
2183                next_fs.addClass('active-step');
2184                var nextQuestionType = next_fs.find('input[name^="ays_questions"]').attr('type');
2185                var buttonsDiv = next_fs.find('.ays_buttons_div');
2186                var enableArrows = $(document).find(".ays-questions-container .ays_qm_enable_arrows").val();
2187
2188                if(myOptions.enable_arrows){
2189                    enableArrows = myOptions.enable_arrows == 'on' ? true : false;
2190                }else{
2191                    enableArrows = parseInt(enableArrows) == 1 ? true : false;
2192                }
2193                var nextArrowIsDisabled = buttonsDiv.find('i.ays_next_arrow').hasClass('ays_display_none');
2194                var nextButtonIsDisabled = buttonsDiv.find('input.ays_next').hasClass('ays_display_none');
2195
2196                if(next_fs.find('textarea[name^="ays_questions"]').attr('type')==='text' && nextArrowIsDisabled && nextButtonIsDisabled){
2197                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2198                }
2199                if(next_fs.find('textarea[name^="ays_questions"]').attr('type')==='text' && enableArrows){
2200                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2201                   buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
2202                }
2203
2204
2205                if(nextQuestionType === 'checkbox' && nextArrowIsDisabled && nextButtonIsDisabled){
2206                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2207                }
2208                if(nextQuestionType === 'checkbox' && enableArrows){
2209                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2210                   buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
2211                }
2212
2213                if(nextQuestionType === 'number' && nextArrowIsDisabled && nextButtonIsDisabled){
2214                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2215                }
2216                if(nextQuestionType === 'number' && enableArrows){
2217                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2218                   buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
2219                }
2220
2221                if(nextQuestionType === 'text' && nextArrowIsDisabled && nextButtonIsDisabled){
2222                   next_fs.find('.ays_buttons_div').find('input.ays_next').removeClass('ays_display_none');
2223                }
2224                if(nextQuestionType === 'text' && enableArrows){
2225                   next_fs.find('.ays_buttons_div').find('input.ays_next').addClass('ays_display_none');
2226                   next_fs.find('.ays_buttons_div').find('i.ays_next_arrow').removeClass('ays_display_none');
2227                }
2228
2229                if(nextQuestionType === 'date' && nextArrowIsDisabled && nextButtonIsDisabled){
2230                    buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2231                }
2232                if(nextQuestionType === 'date' && enableArrows){
2233                    buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2234                    buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2235                }
2236                if(next_fs.data('type') === 'matching' && nextArrowIsDisabled && nextButtonIsDisabled){
2237                    buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2238                }
2239                if(next_fs.data('type') === 'matching' && enableArrows){
2240                    buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2241                    buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2242                }
2243                if(next_fs.data('type') === 'upload_file' && nextArrowIsDisabled && nextButtonIsDisabled){
2244                    buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2245                }
2246                if(next_fs.data('type') === 'upload_file' && enableArrows){
2247                    buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2248                    buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2249                }
2250
2251                var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
2252                var checkUserAnswered = false;
2253                if (next_fs.find('.ays-quiz-answers .ays-field textarea').length) {
2254                    nextQuestionType = 'text';
2255                }
2256
2257                if (next_fs.data('type') === 'matching') {
2258                    nextQuestionType = 'matching';
2259                } else if (next_fs.find('.ays-quiz-answers .ays-field select.ays-select').length) {
2260                    nextQuestionType = 'select';
2261                }
2262                
2263                if ( next_fs.hasClass('ays-custom-step') ) {
2264                    nextQuestionType = 'custom';
2265                }
2266
2267                switch (nextQuestionType){
2268                    case "radio":
2269                        checkUserAnswered = next_fs.find('.ays-quiz-answers .ays-field input[type="'+ nextQuestionType +'"]').is(':checked');
2270                    break;
2271                    case "checkbox":
2272                        checkUserAnswered = next_fs.find('.ays-quiz-answers .ays-field input[type="'+ nextQuestionType +'"]').is(':checked');
2273                    break;
2274                    case "number":
2275                        var questionTypeVal = next_fs.find('.ays-quiz-answers .ays-field input[type="'+ nextQuestionType +'"]').val().length;
2276                        if (questionTypeVal !== 0) {
2277                            checkUserAnswered = true;
2278                        }
2279                    break;
2280                    case "text":
2281                        var questionTypeVal = next_fs.find('.ays-quiz-answers .ays-field textarea, .ays-quiz-answers .ays-field input[type="text"]').val();
2282                        if (questionTypeVal !== '') {
2283                            checkUserAnswered = true;
2284                        }
2285                    break;
2286                    case "date":
2287                        var questionTypeVal = next_fs.find('.ays-quiz-answers .ays-field input[type="'+ nextQuestionType +'"]').val().length;
2288                        if (questionTypeVal !== 0) {
2289                            checkUserAnswered = true;
2290                        }
2291                    break;
2292                    case "select":
2293                        var questionTypeEl = next_fs.find('.ays-quiz-answers .ays-field select.ays-select option[data-chisht]');
2294                        questionTypeEl.each(function(){
2295                            var questionTypeVal = $(this).attr('selected');
2296                            if (questionTypeVal) {
2297                                checkUserAnswered = true;
2298                            }
2299                        });
2300                    break;
2301                    case "matching":
2302                        var questionTypeEl = next_fs.find('.ays-quiz-answers .ays-field select.ays-select option');
2303                        var checkedCount = 0;
2304                        var choicesCount = next_fs.find('.ays-quiz-answers .ays-field.ays-matching-field-option').length;
2305                        questionTypeEl.each(function(){
2306                            var questionTypeVal = $(this).attr('selected');
2307                            if (questionTypeVal) {
2308                                checkedCount++;
2309                            }
2310                        });
2311                        if( checkedCount === choicesCount ) {
2312                            checkUserAnswered = true;
2313                        }
2314                    break;
2315                    case "custom":
2316                        checkUserAnswered = true;
2317                    case "upload_file":
2318                        var questionTypeVal = next_fs.find('.ays-quiz-answers .ays-upload-field .ays-quiz-upload-ready-url-link').val();
2319                        if (questionTypeVal !== '') {
2320                            checkUserAnswered = true;
2321                        }
2322                    break;
2323                    default:
2324                        checkUserAnswered = next_fs.find('.ays-quiz-answers .ays-field input[type="'+ nextQuestionType +'"]').prop('ckecked');
2325                    break;
2326                }
2327                if(isRequiredQuestion === true){
2328                    if(next_fs.find('.information_form').length === 0){
2329                        var newNextQuestionType = next_fs.attr('data-type');
2330
2331                        if(enableArrows){
2332                            if (! checkUserAnswered) {
2333                                buttonsDiv.find('i.ays_next_arrow').attr('disabled', 'disabled');
2334                            }else{
2335                                if( nextQuestionType == 'custom' ){
2336                                    buttonsDiv.find('i.ays_next').removeAttr('disabled');
2337                                    buttonsDiv.find('i.ays_finish').removeAttr('disabled');
2338                                }
2339                                if( newNextQuestionType !== "fill_in_blank" ){
2340                                    buttonsDiv.find('i.ays_early_finish').removeAttr('disabled');
2341                                }
2342                            }
2343                        }else{
2344                            if (! checkUserAnswered) {
2345                                buttonsDiv.find('input.ays_next').attr('disabled', 'disabled');
2346                            }else{
2347                                if( nextQuestionType == 'custom' ){
2348                                    buttonsDiv.find('input.ays_next').removeAttr('disabled');
2349                                    buttonsDiv.find('input.ays_finish').removeAttr('disabled');
2350                                }
2351                                if( newNextQuestionType !== "fill_in_blank" ){
2352                                    buttonsDiv.find('input.ays_early_finish').removeAttr('disabled');
2353                                }
2354                            }
2355                        }
2356                    }
2357                }
2358
2359                var isAnimate = true;
2360                var timerType = myOptions.quiz_timer_type ? myOptions.quiz_timer_type : 'quiz_timer';
2361                if( isRequiredQuestion && myOptions.enable_timer && myOptions.enable_timer === 'on' && timerType === 'question_timer' ) {
2362                    var qid = checkQuestionTimer(ays_quiz_container, quizId);
2363                    if ($(this).hasClass('ays_finish') && qid !== false) {
2364                        isAnimate = false;
2365                    }
2366                }
2367
2368                if ( isAnimate ) {
2369                    aysAnimateStep(ays_quiz_container.data('questEffect'), current_fs, next_fs);
2370                }
2371
2372                if( !quizDisableInputFocusing  ){
2373                    next_fs.find('.ays-text-input:first-child').trigger( "focus" );
2374                    if ( ! next_fs.find('.ays-text-input:first-child').is(":focus") ) {
2375                        setTimeout(function(e){
2376                            next_fs.find('.ays-text-input:first-child').trigger( "focus" );
2377                        },1001);
2378                    }
2379                }
2380
2381                setTimeout(function(){
2382                    if(next_fs.find('.ays-text-field').length > 0){
2383                        if(next_fs.find('.ays-text-field').width() < 250){
2384                            next_fs.find('.ays-text-field').css({
2385                                'flex-wrap': 'wrap',
2386                                'justify-content': 'center',
2387                                'padding': '5px'
2388                            });
2389                            next_fs.find('.ays-text-field').find('input.ays-text-input').css('margin-bottom', '5px');
2390                        }
2391                    }
2392                },2000);
2393            }
2394            if( $(this).parents('.ays-questions-container').length > 0 ){
2395                if($(document).scrollTop() >= $(this).parents('.ays-questions-container').offset().top || $(this).parents('.ays-questions-container').offset().top > 500){
2396                    ays_quiz_container.goTo( myOptions );
2397                }
2398            }
2399            if(current_fs.find('audio').length > 0){
2400                current_fs.find('audio').each(function(e, el){
2401                    el.pause();
2402                });
2403            }
2404            if(current_fs.find('video').length > 0){
2405                current_fs.find('video').each(function(e, el){
2406                    el.pause();
2407                });
2408            }
2409
2410            //Current
2411            if(current_fs.find('audio').length > 0){
2412                var sound_src = next_fs.find('audio').attr('src');
2413                if (typeof sound_src !== 'undefined'){
2414                    var audio = next_fs.find('audio').get(0);
2415                    audio.pause();
2416                    audio.currentTime = 0;
2417                }
2418            }
2419
2420            //Next
2421            var enableAudioAutoplay = (myOptions.enable_audio_autoplay && myOptions.enable_audio_autoplay == 'on') ? true : false;
2422            if(next_fs.find('audio').length > 0){
2423                if(enableAudioAutoplay){
2424                    var sound_src = next_fs.find('audio').attr('src');
2425                    if (typeof sound_src !== 'undefined'){
2426                        var audio = next_fs.find('audio').get(0);
2427                        audio.currentTime = 0;
2428                        audio.play();
2429                    }
2430                }
2431            }
2432
2433            if ('speechSynthesis' in window) {
2434                speechSynthesis.cancel();
2435            }
2436
2437            //Custom type
2438            //Checking Next button and Arrows fields
2439            var enableNextButton = (myOptions.enable_next_button && myOptions.enable_next_button == 'off') ? true : false;
2440            var enableArrows = (myOptions.enable_arrows && myOptions.enable_arrows == 'on') ? true : false;
2441            if(enableNextButton){
2442                if(next_fs.hasClass('ays-custom-step')){
2443                    if (enableArrows) {
2444                        next_fs.find('.ays_buttons_div i.ays_next.action-button.ays_arrow').removeClass('ays_display_none');
2445                    }else{
2446                        next_fs.find('.ays_buttons_div input.ays_next.action-button').removeClass('ays_display_none');
2447                    }
2448                }
2449            }
2450
2451            setTimeout(function (){
2452                questionTimer( next_fs, next_fs.data('questionId') );
2453            }, 1);
2454            aysResizeiFrame();
2455        });
2456
2457
2458        $(document).find('.ays_questions_nav_question').on('click', function(e){
2459            e.preventDefault();
2460            var questionId = $(this).data('id');
2461            ays_quiz_container = $(this).parents(".ays-quiz-wrap").find(".ays-quiz-container");
2462
2463            if (animating) return false;
2464            animating = true;
2465            current_fs = ays_quiz_container.find('div.active-step[data-question-id]');
2466            next_fs = ays_quiz_container.find('div[data-question-id="'+questionId+'"]');
2467
2468            var quizDisableInputFocusing = (myOptions.quiz_disable_input_focusing && myOptions.quiz_disable_input_focusing == "on") ? true : false;
2469
2470                current_fs.removeClass('active-step');
2471                next_fs.addClass('active-step');
2472                var nextQuestionType = next_fs.find('input[name^="ays_questions"]').attr('type');
2473                var buttonsDiv = next_fs.find('.ays_buttons_div');
2474                var enableArrows = $(document).find(".ays-questions-container .ays_qm_enable_arrows").val();
2475
2476                var questions_count = $(this).parents('.ays-quiz-wrap').find('div[data-question-id]').length;
2477                var curent_number = $(this).parents('.ays-quiz-wrap').find('div[data-question-id]').index( ays_quiz_container.find('div[data-question-id="'+questionId+'"]') );
2478
2479                var current_width = $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').width();
2480                var final_width = ((curent_number+1) / questions_count * 100) + "%";
2481
2482                if( ays_quiz_container.find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
2483                    ays_quiz_container.find('.ays-live-bar-percent').text(parseInt(curent_number+1));
2484                }else{
2485                    ays_quiz_container.find('.ays-live-bar-percent').text(parseInt(final_width));
2486                }
2487                ays_quiz_container.find('.ays-live-bar-fill').animate({'width': final_width}, 1000);
2488
2489                if ( next_fs.hasClass('ays-custom-step') ) {
2490                    nextQuestionType = 'custom';
2491                }
2492
2493                if(myOptions.enable_arrows){
2494                    enableArrows = myOptions.enable_arrows == 'on' ? true : false;
2495                }else{
2496                    enableArrows = parseInt(enableArrows) == 1 ? true : false;
2497                }
2498                var nextArrowIsDisabled = buttonsDiv.find('.ays_next_arrow').hasClass('ays_display_none');
2499                var nextButtonIsDisabled = buttonsDiv.find('.ays_next').hasClass('ays_display_none');
2500
2501                if(next_fs.find('textarea[name^="ays_questions"]').attr('type')==='text' && nextArrowIsDisabled && nextButtonIsDisabled){
2502                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2503                }
2504                if(next_fs.find('textarea[name^="ays_questions"]').attr('type')==='text' && enableArrows){
2505                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2506                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2507                }
2508
2509
2510                if(nextQuestionType === 'checkbox' && nextArrowIsDisabled && nextButtonIsDisabled){
2511                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2512                }
2513                if(nextQuestionType === 'checkbox' && enableArrows){
2514                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2515                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2516                }
2517
2518                if(nextQuestionType === 'number' && nextArrowIsDisabled && nextButtonIsDisabled){
2519                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2520                }
2521                if(nextQuestionType === 'number' && enableArrows){
2522                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2523                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2524                }
2525
2526                if(nextQuestionType === 'text' && nextArrowIsDisabled && nextButtonIsDisabled){
2527                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2528                }
2529                if(nextQuestionType === 'text' && enableArrows){
2530                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2531                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2532                }
2533
2534                if(nextQuestionType === 'short_text' && nextArrowIsDisabled && nextButtonIsDisabled){
2535                   buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2536                }
2537                if(nextQuestionType === 'short_text' && enableArrows){
2538                   buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2539                   buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2540                }
2541
2542                if(nextQuestionType === 'date' && nextArrowIsDisabled && nextButtonIsDisabled){
2543                    buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2544                }
2545                if(nextQuestionType === 'date' && enableArrows){
2546                    buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2547                    buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2548                }
2549
2550                if(next_fs.data('type') === 'upload_file' && nextArrowIsDisabled && nextButtonIsDisabled){
2551                    buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2552                    console.log('asd')
2553                }
2554                if(next_fs.data('type') === 'upload_file' && enableArrows){
2555                    console.log('qwe')
2556                    buttonsDiv.find('input.ays_next').addClass('ays_display_none');
2557                    buttonsDiv.find('.ays_next_arrow').removeClass('ays_display_none');
2558                }
2559
2560                if(enableArrows){
2561                    if( nextQuestionType == 'custom' ){
2562                        buttonsDiv.find('i.ays_next').removeAttr('disabled');
2563                        buttonsDiv.find('i.ays_finish').removeAttr('disabled');
2564                        buttonsDiv.find('i.ays_early_finish').removeAttr('disabled');
2565                    }
2566                }else{
2567                    if( nextQuestionType == 'custom' ){
2568                        buttonsDiv.find('input.ays_next').removeAttr('disabled');
2569                        buttonsDiv.find('input.ays_finish').removeAttr('disabled');
2570                        buttonsDiv.find('input.ays_early_finish').removeAttr('disabled');
2571                    }
2572                }
2573
2574                aysAnimateStep(ays_quiz_container.data('questEffect'), current_fs, next_fs);
2575
2576                if( !quizDisableInputFocusing ){
2577                    next_fs.find('.ays-text-input:first-child').trigger( "focus" );
2578                }
2579
2580                setTimeout(function(){
2581                    if(next_fs.find('.ays-text-field').length > 0){
2582                        if(next_fs.find('.ays-text-field').width() < 250){
2583                            next_fs.find('.ays-text-field').css({
2584                                'flex-wrap': 'wrap',
2585                                'justify-content': 'center',
2586                                'padding': '5px'
2587                            });
2588                            next_fs.find('.ays-text-field').find('input.ays-text-input').css('margin-bottom', '5px');
2589                        }
2590                    }
2591                },2000);
2592            // }
2593
2594            // if($(document).scrollTop() >= $(this).parents('.ays-questions-container').offset().top || $(this).parents('.ays-questions-container').offset().top > 500){
2595            //     ays_quiz_container.goTo();
2596            // }
2597            if(current_fs.find('audio').length > 0){
2598                current_fs.find('audio').each(function(e, el){
2599                    el.pause();
2600                });
2601            }
2602            if(current_fs.find('video').length > 0){
2603                current_fs.find('video').each(function(e, el){
2604                    el.pause();
2605                });
2606            }
2607
2608            questionTimer( next_fs, next_fs.data('questionId') );
2609        });
2610
2611        $(document).find('.ays_previous').on("click", function(e){
2612            ays_quiz_container = $(this).parents(".ays-quiz-container");
2613            aysQuizStopYoutubeIframe(ays_quiz_container);
2614
2615            var enableArrows = ays_quiz_container.find(".ays-questions-container .ays_qm_enable_arrows").val();
2616            if(myOptions.enable_arrows){
2617                enableArrows = myOptions.enable_arrows == 'on' ? true : false;
2618            }else{
2619                enableArrows = parseInt(enableArrows) == 1 ? true : false;
2620            }
2621
2622            if(typeof explanationTimeout != 'undefined'){
2623                clearTimeout(explanationTimeout);
2624
2625                var thisButtonsDiv = $(this).parents(".ays_buttons_div");
2626                setTimeout(function(){
2627                    if (thisButtonsDiv.find('input.ays_next').hasClass('ays_display_none') &&
2628                        thisButtonsDiv.find('i.ays_next_arrow').hasClass('ays_display_none')) {
2629                        if(enableArrows){
2630                            thisButtonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
2631                        }else{
2632                            thisButtonsDiv.find('input.ays_next').removeClass('ays_display_none');
2633                        }
2634                    }
2635                }, 1000);
2636            }
2637
2638            if(animating) return false;
2639            animating = true;
2640
2641            var next_sibilings_count = ays_quiz_container.find('.ays_question_count_per_page').val();
2642
2643            var isQuestionPerPageCustom = (myOptions.question_count_per_page_type && myOptions.question_count_per_page_type == "custom") ? true : false;
2644            var customPerPageValue = (myOptions.question_count_per_page_custom_order && myOptions.question_count_per_page_custom_order != "") ? myOptions.question_count_per_page_custom_order : "";
2645            var quizDisableInputFocusing = (myOptions.quiz_disable_input_focusing && myOptions.quiz_disable_input_focusing == "on") ? true : false;
2646
2647            if( isQuestionPerPageCustom && customPerPageValue != ""){
2648                var custom_next_sibilings_count = $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_next').val();
2649                var custom_prev_sibilings_count = $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_prev').val();
2650                var questions_count_new = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').length;
2651                if( typeof custom_prev_sibilings_count != "undefined" && custom_prev_sibilings_count != "" ){
2652                    var custom_prev_sibilings_count_arr = custom_prev_sibilings_count.split(',');
2653                    var custom_next_sibilings_count_arr = custom_next_sibilings_count.split(',');
2654                    if (custom_prev_sibilings_count_arr !== undefined && custom_prev_sibilings_count_arr.length > 0) {
2655                        var pop_number = custom_prev_sibilings_count_arr.pop();
2656                        next_sibilings_count = parseInt( custom_prev_sibilings_count_arr[ custom_prev_sibilings_count_arr.length - 1 ] );
2657
2658                        $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page').val(next_sibilings_count)
2659
2660                        if( typeof custom_prev_sibilings_count == 'undefined' || custom_prev_sibilings_count == "" ){
2661                            $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_prev').val(next_sibilings_count);
2662                        } else {
2663                            var custom_prev_sibilings_count_arr = custom_prev_sibilings_count.split(",");
2664                            custom_prev_sibilings_count_arr.pop();
2665
2666                            var custom_prev_sibilings_count_arr_new = custom_prev_sibilings_count_arr.join(",");
2667                            $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_prev').val(custom_prev_sibilings_count_arr_new);
2668                        }
2669
2670                        custom_next_sibilings_count_arr = custom_next_sibilings_count_arr.filter(word => word != "");
2671
2672                        if( custom_next_sibilings_count_arr.length > 0 ){
2673                            custom_next_sibilings_count_arr.unshift(pop_number);
2674                            var custom_next_sibilings_count_new_val = custom_next_sibilings_count_arr.join(',');
2675                            $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_next').val(custom_next_sibilings_count_new_val);
2676                        } else {
2677
2678                            var sum_prev_quesiton = 0;
2679                            for (var ii = 0; ii < custom_prev_sibilings_count_arr.length; ii++ ) {
2680                                sum_prev_quesiton += parseInt( custom_prev_sibilings_count_arr[ii] );
2681                            }
2682                            var last_page_questions_count = parseInt(questions_count_new) - parseInt(sum_prev_quesiton);
2683                            if( last_page_questions_count != 0 ) {
2684                                $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_next').val(last_page_questions_count);
2685                            } else {
2686                                $(this).parents('form.ays-quiz-form').find('.ays_question_count_per_page_custom_next').val("");
2687                            }
2688                        }
2689                    }
2690                }
2691            }
2692
2693            if(parseInt(next_sibilings_count)>0 && ($(this).parents('.step').attr('data-question-id') || $(this).parents('.step').next().attr('data-question-id'))){
2694                var questions_count = ays_quiz_container.find('div[data-question-id]').length;
2695                var curent_number_of_this = ays_quiz_container.find('div[data-question-id]').index($(this).parents('div[data-question-id]')) + 1;
2696                var curent_number = ays_quiz_container.find('div[data-question-id]').index($(this).parents('div[data-question-id]')) - parseInt(next_sibilings_count) + 1;
2697                var count_per_page = questions_count%parseInt(next_sibilings_count);
2698                var nextCountQuestionsPerPage = questions_count-curent_number;
2699                if(count_per_page > 0 && curent_number_of_this == questions_count){
2700                    curent_number = ays_quiz_container.find('div[data-question-id]').index($(this).parents('div[data-question-id]')) - count_per_page + 1;
2701                }
2702
2703                var current_first_fs_index = ays_quiz_container.find('div[data-question-id]').index(ays_quiz_container.find('.active-step').eq(0));
2704                var next_fs = ays_quiz_container.find('div[data-question-id]').slice((current_first_fs_index - parseInt(next_sibilings_count)), current_first_fs_index);
2705
2706                var new_current_fs_index = $(this).parents('form.ays-quiz-form').find('.step').index($(this).parents('form.ays-quiz-form').find('.step.active-step'));
2707                var next_fs_index = $(this).parents('form.ays-quiz-form').find('.step').index(next_fs);
2708
2709                if (!($(this).hasClass('start_button'))) {
2710                    var current_width = $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').width();
2711                    var final_width = ((curent_number) / questions_count * 100) + "%";
2712                    if($(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
2713                        $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number));
2714                    }else{
2715                        $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
2716                    }
2717                    $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 1000);
2718                }
2719                var current_fs_index = ays_quiz_container.find('div[data-question-id]').index(ays_quiz_container.find('.active-step').eq(0));
2720
2721                if($(this).parents('.step').attr('data-question-id')){
2722                    if( isQuestionPerPageCustom && customPerPageValue != ""){
2723                        if( custom_next_sibilings_count_arr.length == 0 ){
2724                            current_fs = ays_quiz_container.find('div[data-question-id]').slice(current_fs_index,questions_count);
2725                        } else {
2726                            current_fs = ays_quiz_container.find('div[data-question-id]').slice(current_fs_index,current_fs_index+parseInt(pop_number)+1);
2727                        }
2728                    } else {
2729                        current_fs = ays_quiz_container.find('div[data-question-id]').slice(current_fs_index,current_fs_index+parseInt(next_sibilings_count));
2730                    }
2731
2732                    // current_fs = ays_quiz_container.find('div[data-question-id]').slice(current_fs_index,current_fs_index+parseInt(next_sibilings_count));
2733                }else{
2734                    current_fs = $(this).parents('.step');
2735                }
2736
2737                var buttonsDiv = next_fs.find('.ays_buttons_div');
2738                var enableArrows = $(document).find(".ays-questions-container .ays_qm_enable_arrows").val();
2739                if(myOptions.enable_arrows){
2740                    enableArrows = myOptions.enable_arrows == 'on' ? true : false;
2741                }else{
2742                    enableArrows = parseInt(enableArrows) == 1 ? true : false;
2743                }
2744
2745                if (buttonsDiv.find('input.ays_next').hasClass('ays_display_none') &&
2746                    buttonsDiv.find('i.ays_next_arrow').hasClass('ays_display_none')) {
2747                    if(enableArrows){
2748                        buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
2749                    }else{
2750                        buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2751                    }
2752                }
2753
2754                ays_quiz_container.find('div[data-question-id]').eq(current_fs_index).removeClass('active-step');
2755                next_fs.eq(0).addClass('active-step')
2756                if ($(this).parents('form.ays-quiz-form').hasClass('enable_correction')) {
2757                    if (next_fs.find('.correct').length !== 0 || $(this).parents('div[data-question-id]').prev().find('.wrong').length !== 0) {
2758                        next_fs.find('input[name^="ays_questions"]').on('click',function () {
2759                            var is_user_answer_correct = $(this).parent().find('.correct').length;
2760                            var is_user_answer_wrong = $(this).parent().find('.wrong').length;
2761                            if (is_user_answer_correct !== 0 || is_user_answer_wrong !== 0) {
2762                                return false;
2763                            }
2764                        });
2765                    }
2766                }
2767
2768                if ($(this).parents('form.ays-quiz-form').hasClass('enable_correction')) {
2769                    next_fs.find('input[name^="ays_questions"]').each(function(){
2770                        if ($(this).parents('.ays-quiz-answers').find('.correct').length === 0 &&
2771                            $(this).parents('.ays-quiz-answers').find('.wrong').length === 0 &&
2772                            $(this).parents('.ays-quiz-answers').find('.ays-answered-text-input').length === 0) {
2773                            $(this).attr('disabled', false);
2774                        }
2775                    });
2776                }
2777                
2778                aysAnimateStep(ays_quiz_container.data('questEffect'), current_fs, next_fs);
2779                if( !quizDisableInputFocusing ){
2780                    next_fs.eq(0).find('.ays-text-input:first-child').trigger( "focus" );
2781                    
2782                    next_fs.eq(0).find('.ays-text-input:first-child').trigger( "focus" );
2783                    if ( ! next_fs.eq(0).find('.ays-text-input:first-child').is(":focus") ) {
2784                        setTimeout(function(e){
2785                            next_fs.eq(0).find('.ays-text-input:first-child').trigger( "focus" );
2786                        },1001);
2787                    }
2788                }
2789            }else{
2790                if ($(this).parents('div[data-question-id]').prev().find('.correct').length === 0 &&
2791                    $(this).parents('div[data-question-id]').prev().find('.wrong').length === 0 &&
2792                    $(this).parents('div[data-question-id]').prev().find('.ays-answered-text-input').length === 0) {
2793                    $(this).parents('div[data-question-id]').prev().find('input[name^="ays_questions"]').attr('disabled', false);
2794                }else{
2795                    $(this).parents('div[data-question-id]').prev().find('input[name^="ays_questions"]').attr('disabled', true);
2796                    if( $(this).parents('div[data-question-id]').prev().find('input[name^="ays_questions"]').attr('type') == 'checkbox' ){
2797                        $(this).parents('div[data-question-id]').prev().find('input[name^="ays_questions"]').attr('disabled', false);
2798                        $(this).parents('div[data-question-id]').prev().find('input[name^="ays_questions"][type="radio"]').on('click',function () {
2799                            return false;
2800                        });
2801                    }
2802                }
2803
2804                current_fs = $(this).parents('.step');
2805                next_fs = $(this).parents('.step').prev();
2806
2807
2808                if( aysThisQuizBullets !== null ){
2809                    var thisQuestionID = next_fs.data('questionId');
2810                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]').parents('.ays-quiz-questions-nav-item');
2811                    aysThisQuizBullets._navPage(thisBullet.index());
2812                }
2813
2814                var buttonsDiv = next_fs.find('.ays_buttons_div');
2815
2816                if (buttonsDiv.find('input.ays_next').hasClass('ays_display_none') &&
2817                    buttonsDiv.find('i.ays_next_arrow').hasClass('ays_display_none')) {
2818                    if(enableArrows){
2819                        buttonsDiv.find('i.ays_next_arrow').removeClass('ays_display_none');
2820                        buttonsDiv.find('i.ays_next_arrow').removeAttr('disabled');
2821                        buttonsDiv.find('i.ays_early_finish').removeAttr('disabled');
2822                        buttonsDiv.find('i.ays_next_arrow').removeProp('disabled');
2823                        buttonsDiv.find('i.ays_early_finish').removeProp('disabled');
2824                    }else{
2825                        buttonsDiv.find('input.ays_next').removeClass('ays_display_none');
2826                        buttonsDiv.find('input.ays_next').removeAttr('disabled');
2827                        buttonsDiv.find('input.ays_early_finish').removeAttr('disabled');
2828                        buttonsDiv.find('input.ays_next').removeProp('disabled');
2829                        buttonsDiv.find('input.ays_early_finish').removeProp('disabled');
2830                    }
2831                }
2832
2833                if (current_fs.hasClass('ays-abs-fs')) {
2834                    current_fs = $(this).parents('.step');
2835                    next_fs = $(this).parents('.step').prev();
2836                    var counterClass = "";
2837                    switch(ays_quiz_container.data('questEffect')){
2838                        case "shake":
2839                            counterClass = ays_quiz_container.data('questEffect');
2840                        break;
2841                        case "fade":
2842                            counterClass = "fadeIn";
2843                        break;
2844                        case "none":
2845                            counterClass = "";
2846                        break;
2847                        default:
2848                            counterClass = ays_quiz_container.data('questEffect');
2849                        break;
2850                    }
2851                    next_fs.find('.ays-question-counter').addClass(counterClass);
2852                }
2853                current_fs.removeClass('active-step');
2854                next_fs.addClass('active-step');
2855
2856                var questions_count = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').length;
2857                var curent_number = $(this).parents('form.ays-quiz-form').find('div[data-question-id]').index($(this).parents('div[data-question-id]'))-1;
2858                if(curent_number != questions_count){
2859                    if(($(this).hasClass('ays_finish')) == false){
2860                        if (!($(this).hasClass('start_button'))) {
2861                            var current_width = $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').width();
2862                            var final_width = ((curent_number+1) / questions_count * 100) + "%";
2863                            if($(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
2864                                $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(curent_number+1));
2865                            }else{
2866                                $(this).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(parseInt(final_width));
2867                            }
2868                            $(this).parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({'width': final_width}, 1000);
2869                        }
2870                    }
2871                }else{
2872                    $(this).parents('.ays-quiz-container').find('.ays-live-bar-wrap').removeClass('rubberBand').addClass('bounceOut');
2873                    setTimeout(function () {
2874                        $(e.target).parents('.ays-quiz-container').find('.ays-live-bar-wrap').css('display','none');
2875                    },300)
2876                }
2877                aysAnimateStep(ays_quiz_container.data('questEffect'), current_fs, next_fs);
2878
2879                if( !quizDisableInputFocusing ){
2880                    next_fs.find('.ays-text-input:first-child').trigger( "focus" );
2881
2882                    next_fs.find('.ays-text-input:first-child').trigger( "focus" );
2883                    if ( ! next_fs.find('.ays-text-input:first-child').is(":focus") ) {
2884                        setTimeout(function(e){
2885                            next_fs.find('.ays-text-input:first-child').trigger( "focus" );
2886                        },1001);
2887                    }
2888                }
2889            }
2890            if( $(this).parents('.ays-questions-container').length > 0 ){
2891                if($(document).scrollTop() >= $(this).parents('.ays-questions-container').offset().top || $(this).parents('.ays-questions-container').offset().top > 500){
2892                    ays_quiz_container.goTo( myOptions );
2893                }
2894            }
2895            if(current_fs.find('audio').length > 0){
2896                current_fs.find('audio').each(function(e, el){
2897                    el.pause();
2898                });
2899            }
2900            if(current_fs.find('video').length > 0){
2901                current_fs.find('video').each(function(e, el){
2902                    el.pause();
2903                });
2904            }
2905
2906            //Current
2907            if(current_fs.find('audio').length > 0){
2908                var sound_src = next_fs.find('audio').attr('src');
2909                if (typeof sound_src !== 'undefined'){
2910                    var audio = next_fs.find('audio').get(0);
2911                    audio.pause();
2912                    audio.currentTime = 0;
2913                }
2914            }
2915
2916            //Previous
2917            var enableAudioAutoplay = (myOptions.enable_audio_autoplay && myOptions.enable_audio_autoplay == 'on') ? true : false;
2918            if(next_fs.find('audio').length > 0){
2919                if(enableAudioAutoplay){
2920                    var sound_src = next_fs.find('audio').attr('src');
2921                    if (typeof sound_src !== 'undefined'){
2922                        var audio = next_fs.find('audio').get(0);
2923                        audio.currentTime = 0;
2924                        audio.play();
2925                    }
2926                }
2927            }
2928
2929            if ('speechSynthesis' in window) {
2930                speechSynthesis.cancel();
2931            }
2932
2933            questionTimer( next_fs, next_fs.data('questionId') );
2934            aysResizeiFrame();
2935        });
2936
2937        // $(document).find('.ays-quiz-container input').on('focus',function () {
2938        //     $(window).on('keydown',function (event) {
2939        //         if(event.keyCode === 13){
2940        //             return false;
2941        //         }
2942        //     });
2943        // });
2944
2945        // $(document).find('.ays-quiz-container input').on('blur',function () {
2946        //     $(window).off('keydown');
2947        // });
2948        
2949        $(document).on('click', '.ays-quiz-container .ays_question_hint', function (e) {
2950            e.preventDefault();
2951            $(e.target).parents('.ays-quiz-container').find('.ays_music_sound').toggleClass('z_index_0');
2952            $(e.target).parent().find('.ays_question_hint_text').toggleClass('show_hint');
2953            if($(e.target).parent().find('.ays_question_hint_text').hasClass('show_hint')){
2954                $(window).on('click', function(ev){
2955                    if( ! ( $(ev.target).hasClass('ays_question_hint_text') || $(ev.target).hasClass('ays_question_hint') ) ){
2956                        $(e.target).parent().find('.ays_question_hint_text').removeClass('show_hint');
2957                        $(e.target).parents('.ays-quiz-container').find('.ays_music_sound').removeClass('z_index_0');
2958                    }
2959                });
2960            }
2961        });
2962
2963        $(document).on('click', '.ays-quiz-container .ays-export-quiz-button-container .ays-export-quiz-button-more-icon-box', function (e) {
2964            e.preventDefault();
2965
2966            var _this = $(this);
2967            var parent = $(e.target).parents('.ays-export-quiz-button-container');
2968            parent.find('.ays-export-quiz-button-more-box').toggleClass('show-more-buttons');
2969        });
2970
2971        $(document).on('click' , function(e){
2972            if( !$(e.target).hasClass('ays-export-quiz-button-more-icon-box') && $(e.target).parents('.ays-export-quiz-button-container').length == 0 ){
2973                if($(e.target).closest('.ays-export-quiz-button-more-box').length != 0){
2974                } 
2975                else{
2976                    if( $(document).find(".ays-export-quiz-button-more-box").hasClass('show-more-buttons') ) {
2977                        $(document).find('.ays-export-quiz-button-more-box').removeClass('show-more-buttons');
2978                    }
2979                }
2980            }
2981        });
2982
2983        $(document).on('click', '.ays-field', function() {
2984            if ($(this).find(".select2").hasClass('select2-container--open')) {
2985                $(this).find('b[role="presentation"]').removeClass('ays_fa ays_fa_chevron_down');
2986                $(this).find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_up');
2987            } else {
2988                $(this).find('b[role="presentation"]').removeClass('ays_fa ays_fa_chevron_up');
2989                $(this).find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
2990            }
2991        });
2992
2993        $(document).find('select.ays-select').on("select2:selecting", function(e){
2994            $(this).parents('.ays-quiz-container').find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
2995        });
2996        
2997        $(document).find('select.ays-select').on("select2:opening", function(e){
2998            var _this = $(this)
2999            setTimeout(function (){
3000                _this.parents('.ays-quiz-container').css('z-index', 1);
3001                _this.parents('.step').css('z-index', 9999); // tid=31559
3002            }, 1);
3003        });
3004
3005        $(document).find('select.ays-select').on("select2:closing", function(e){
3006            $(this).parents('.ays-quiz-container').find('b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
3007            $(this).parents('.ays-quiz-container').css('z-index', 'initial');
3008            $(this).parents('.step').css('z-index', 'initial');
3009        });
3010        
3011        $(document).find('select.ays-select').on("select2:select", function(e){
3012            var quizContainer = $(e.target).parents('.ays-quiz-container');
3013            var quizId = $(this).parents('.ays-quiz-container').find('input[name="ays_quiz_id"]').val();
3014
3015            var _this = $(this);
3016            var parentStep = _this.parents('.step');
3017            var quizForm = quizContainer.find('form.ays-quiz-form');
3018            var questionId = parentStep.data('questionId');
3019            var questionType = parentStep.data('type');
3020
3021            var right_answer_sound = quizContainer.find('.ays_quiz_right_ans_sound').get(0);
3022            var wrong_answer_sound = quizContainer.find('.ays_quiz_wrong_ans_sound').get(0);
3023            var finishAfterWrongAnswer = (myOptions.finish_after_wrong_answer && myOptions.finish_after_wrong_answer == "on") ? true : false;
3024            var showOnlyWrongAnswer = (myOptions.show_only_wrong_answer && myOptions.show_only_wrong_answer == "on") ? true : false;
3025            var explanationTime = myOptions.explanation_time && myOptions.explanation_time != "" ? parseInt(myOptions.explanation_time) : 4;
3026            var next_sibilings_count = quizContainer.find('.ays_question_count_per_page').val();
3027            var enableNextButton = (myOptions.enable_next_button && myOptions.enable_next_button == 'on') ? true : false;
3028            var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
3029            var thankYouStep = quizContainer.find('div.step.ays_thank_you_fs');
3030            var infoFormLast = thankYouStep.prev().find('div.information_form');
3031
3032            // Strong calculation of answers score
3033            myOptions.checkbox_score_by = ( myOptions.checkbox_score_by ) ? myOptions.checkbox_score_by : 'off';
3034            var checkbox_score_by = (myOptions.checkbox_score_by && myOptions.checkbox_score_by == "on") ? true : false;
3035
3036            // Display all questions on one page
3037            myOptions.quiz_display_all_questions = ( myOptions.quiz_display_all_questions ) ? myOptions.quiz_display_all_questions : 'off';
3038            var quiz_display_all_questions = (myOptions.quiz_display_all_questions && myOptions.quiz_display_all_questions == "on") ? true : false;
3039
3040            var disableQuestions = false;
3041            if( parseInt( next_sibilings_count ) > 0 || quiz_display_all_questions == true ){
3042                disableQuestions = true;
3043            }
3044
3045            myOptions.quiz_waiting_time = ( myOptions.quiz_waiting_time ) ? myOptions.quiz_waiting_time : "off";
3046            var quizWaitingTime = (myOptions.quiz_waiting_time && myOptions.quiz_waiting_time == "on") ? true : false;
3047
3048            myOptions.enable_next_button = ( myOptions.enable_next_button ) ? myOptions.enable_next_button : "off";
3049            var quizNextButton = (myOptions.enable_next_button && myOptions.enable_next_button == "on") ? true : false;
3050
3051            if ( quizWaitingTime && !quizNextButton) {
3052                explanationTime += 2;
3053            }
3054            var data = e.params.data;
3055            var this_select_value = data.id;
3056            $(this).find("option").removeAttr("selected");
3057            $(this).find('option[value="'+this_select_value+'"]').attr("selected", true);
3058
3059            var quizWaitingCountDownDate = new Date().getTime() + (explanationTime * 1000);
3060            var thisAnswerOptions = myQuizOptions[questionId];
3061
3062            var selectOptions = _this.children("option[data-chisht]");
3063            for(var j = 0; j < selectOptions.length; j++){
3064                var currnetSelectOption = $(selectOptions[j]);
3065                var _answerId = currnetSelectOption.val();
3066
3067                if( typeof questionId != "undefined" && questionId !== null && quizForm.hasClass('enable_correction') ){
3068
3069                    var thisQuestionCorrectAnswer = myQuizOptions[questionId].question_answer.length <= 0 ? new Array() : myQuizOptions[questionId].question_answer;
3070                    var ifCorrectAnswer = thisQuestionCorrectAnswer[_answerId] == '' ? '' : thisQuestionCorrectAnswer[_answerId];
3071
3072                    if( typeof ifCorrectAnswer != "undefined" ){
3073                        parentStep.find('.ays-field input[data-id="'+ _answerId +'"][name="ays_answer_
3073correct[]"]').val(ifCorrectAnswer);
3074                        currnetSelectOption.attr('data-chisht', ifCorrectAnswer);
3075                    }
3076                }
3077            }
3078
3079            if( questionType === 'matching' ){
3080                var choice = thisAnswerOptions.question_answer[ this_select_value ];
3081                var choicesCount = $(e.target).parents('div[data-question-id]').find('.ays-field.ays-matching-field-option').length;
3082                var answeredChoicesCount = 0; //$(e.target).parents('div[data-question-id]').find('.ays-field.ays-matching-field-option select option:selected').length;
3083                $(e.target).parents('div[data-question-id]').find('.ays-field.ays-matching-field-option').each( function ( index, item ) {
3084                    if( $(item).find( 'select.ays-select option[selected]' ).length > 0 ) {
3085                        answeredChoicesCount++;
3086                    }
3087                } );
3088            }
3089
3090            $(this).parent().find('.ays-select-field-value').attr("value", questionType === 'matching' ? choice : this_select_value);
3091            if($(this).parents(".ays-questions-container").find('form[id^="ays_finish_quiz"]').hasClass('enable_correction')) {
3092                var chishtPatasxan = $(this).find('option[selected="selected"]').data("chisht");
3093                var answerIsCorrect = chishtPatasxan == 1;
3094
3095                if( questionType === 'matching' ){
3096                    var answerId = $(this).parents('.ays-matching-field-match').data('answerId');
3097                    answerIsCorrect = Number( answerId ) === Number( choice );
3098                }
3099
3100                if (answerIsCorrect) {
3101                    if((right_answer_sound)){
3102                        resetPlaying([right_answer_sound, wrong_answer_sound]);
3103                        setTimeout(function(){
3104                            right_answer_sound.play();
3105                        }, 10);
3106                    }
3107                    $(this).parents('.ays-field').addClass('correct_div checked_answer_div');
3108                    $(this).parents('.ays-field').find('.select2-selection__rendered').css("background-color", "rgba(0, 128, 0, 0.6)");
3109                } else {
3110                    if((wrong_answer_sound)){
3111                        resetPlaying([right_answer_sound, wrong_answer_sound]);
3112                        setTimeout(function(){
3113                            wrong_answer_sound.play();
3114                        }, 10);
3115                    }
3116                    $(this).parents('.ays-field').addClass('wrong_div checked_answer_div');
3117                    $(this).parents('.ays-field').find('.select2-selection__rendered').css("background-color", "rgba(255, 2, 2, 0.6)");
3118                    if(showOnlyWrongAnswer === false){
3119                        var rightAnswerText = '<div class="ays-text-right-answer">';
3120
3121                        if ( questionType === 'matching' ) {
3122                            rightAnswerText += $(this).parents('.ays-matching-field-option').find('.ays-matching-field-choice').text();
3123                            rightAnswerText += ' -> ' + getObjectKey( thisAnswerOptions.question_answer, answerId, 'number' );
3124                        } else {
3125                            rightAnswerText += $(this).find('option[data-chisht="1"]').html();
3126                        }
3127
3128                        rightAnswerText += '</div>';
3129                        $(this).parents('.ays-quiz-answers').append(rightAnswerText);
3130                        $(this).parents('.ays-quiz-answers').find('.ays-text-right-answer').css("text-align", "left");
3131                        $(this).parents('.ays-quiz-answers').find('.ays-text-right-answer').slideDown(500);
3132                    }
3133                }
3134                var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + questionId + '"]');
3135
3136                var isProcessToShowRWTexts = false;
3137                var isProcessToShowColors = false;
3138                var correctChoicesCount = $(e.target).parents('div[data-question-id]').find('.correct_div').length;
3139                var wrongChoicesCount = $(e.target).parents('div[data-question-id]').find('.wrong_div').length;
3140                var ifStatement = answerIsCorrect;
3141                if( questionType === 'matching' ) {
3142                    ifStatement = correctChoicesCount >= wrongChoicesCount;
3143                    answeredChoicesCount = $(e.target).parents('div[data-question-id]').find('.checked_answer_div').length;
3144                    if( choicesCount === answeredChoicesCount ) {
3145                        isProcessToShowRWTexts = true;
3146                        isProcessToShowColors = true;
3147                    }
3148                } else {
3149                    isProcessToShowColors = true;
3150                }
3151
3152                if (isProcessToShowColors){
3153                    if (ifStatement){
3154                        if( aysThisQuizBullets !== null ){
3155                            thisBullet.attr('disabled', 'disabled');
3156                            thisBullet.addClass('ays_quiz_correct_answer');
3157                            if (!thisBullet.parent().hasClass('ays-quiz-questions-nav-item-last-question')) {
3158                                thisBullet.parent().addClass('ays_quiz_checked_answer_div');
3159                            }
3160                        }
3161                    }else{
3162                        if( aysThisQuizBullets !== null ){
3163                            thisBullet.attr('disabled', 'disabled');
3164                            thisBullet.addClass('ays_quiz_wrong_answer');
3165                            if (!thisBullet.parent().hasClass('ays-quiz-questions-nav-item-last-question')) {
3166                                thisBullet.parent().addClass('ays_quiz_checked_answer_div');
3167                            }
3168                        }
3169                    }
3170                }
3171
3172                parentStep.removeClass('ays-has-error');
3173                thisBullet.removeClass('ays-has-error');
3174
3175                if ( questionType === 'matching' ) {
3176                    if ( isProcessToShowRWTexts === true ) {
3177                        if (myOptions.answers_rw_texts && (myOptions.answers_rw_texts == 'on_passing' || myOptions.answers_rw_texts == 'on_both')) {
3178
3179                            if(checkbox_score_by){
3180                                if ( wrongChoicesCount > 0 ) {
3181                                    $(e.target).parents('div[data-question-id]').find('.wrong_answer_text').slideDown(500);
3182                                } else {
3183                                    $(e.target).parents('div[data-question-id]').find('.right_answer_text').slideDown(500);
3184                                }
3185                            } else {
3186                                if ( correctChoicesCount > wrongChoicesCount ) {
3187                                    $(e.target).parents('div[data-question-id]').find('.right_answer_text').slideDown(500);
3188                                } else {
3189                                    $(e.target).parents('div[data-question-id]').find('.wrong_answer_text').slideDown(500);
3190                                }
3191                            }
3192                        }
3193                    }
3194                } else {
3195                    if (myOptions.answers_rw_texts && (myOptions.answers_rw_texts == 'on_passing' || myOptions.answers_rw_texts == 'on_both')) {
3196                        if (answerIsCorrect) {
3197                            $(e.target).parents('div[data-question-id]').find('.right_answer_text').slideDown(500);
3198                        } else {
3199                            $(e.target).parents('div[data-question-id]').find('.wrong_answer_text').slideDown(500);
3200                        }
3201                    }
3202                }
3203
3204                if(finishAfterWrongAnswer && ! answerIsCorrect ){
3205                    $(e.target).parents('div[data-question-id]').find('.ays_
3205next').attr('disabled', 'disabled');
3206                    $(e.target).parents('div[data-question-id]').find('.ays_early_finish').attr('disabled', 'disabled');
3207                    $(e.target).parents('div[data-question-id]').find('.ays_previous').attr('disabled', 'disabled');
3208                    if( disableQuestions ){
3209                        quizContainer.find('div[data-question-id]').css('pointer-events', 'none');
3210                    }
3211                    if( aysThisQuizBullets !== null ){
3212                        aysThisQuizBullets.baseElement.find('.ays_questions_nav_question').each(function(){
3213                            var thisBullet = $(this);
3214                            thisBullet.attr('disabled', 'disabled');
3215                        });
3216                    }
3217                }
3218                if ( questionType !== 'matching' ) {
3219                    explanationTimeout = setTimeout(function () {
3220                        if (ifStatement) {
3221                            if ($(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
3222                                $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
3223                                $(e.target).parents('div[data-question-id]').find('.ays_next').trigger('click');
3224                            } else if (quiz_display_all_questions && isRequiredQuestion && !enableNextButton) {
3225                                var existsEmtpyQuestions = ays_quiz_is_question_empty(quizContainer.find('div[data-question-id]'));
3226                                if (existsEmtpyQuestions) {
3227                                    if (infoFormLast.length == 0) {
3228                                        quizContainer.find('input.ays_finish').trigger('click');
3229                                    } else {
3230                                        quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
3231                                    }
3232                                }
3233                            }
3234                        } else {
3235                            if (finishAfterWrongAnswer) {
3236                                window.aysEarlyFinishConfirmBox[quizId] = true;
3237                                goToLastPage(e);
3238                            } else {
3239                                if ($(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
3240                                    $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
3241                                    $(e.target).parents('div[data-question-id]').find('.ays_next').trigger('click');
3242                                } else if (quiz_display_all_questions && isRequiredQuestion && !enableNextButton) {
3243                                    var existsEmtpyQuestions = ays_quiz_is_question_empty(quizContainer.find('div[data-question-id]'));
3244                                    if (existsEmtpyQuestions) {
3245                                        if (infoFormLast.length == 0) {
3246                                            quizContainer.find('input.ays_finish').trigger('click');
3247                                        } else {
3248                                            quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
3249                                        }
3250                                    }
3251                                }
3252                            }
3253                        }
3254                    }, explanationTime * 1000);
3255
3256                    if (quizWaitingTime && !quizNextButton) {
3257                        window.countdownTimeForShowInterval = setInterval(function () {
3258                            countdownTimeForShow( parentStep, quizWaitingCountDownDate );
3259                        }, 1000);
3260                    }
3261                }
3262
3263                var showExplanationOn = (myOptions.show_questions_explanation && myOptions.show_questions_explanation != "") ? myOptions.show_questions_explanation : "on_results_page";
3264                if(showExplanationOn == 'on_passing' || showExplanationOn == 'on_both'){
3265                    if ( questionType === 'matching' ) {
3266                        if (isProcessToShowRWTexts === true) {
3267                            if (!$(this).parents('.step').hasClass('not_influence_to_score')) {
3268                                $(this).parents('.step').find('.ays_questtion_explanation').slideDown(250);
3269                            }
3270                        }
3271                    }else {
3272                        if (!$(this).parents('.step').hasClass('not_influence_to_score')) {
3273                            $(this).parents('.step').find('.ays_questtion_explanation').slideDown(250);
3274                        }
3275                    }
3276                }
3277                $(this).attr("disabled", true);
3278
3279                if ( isProcessToShowColors ) {
3280                    stopQuestionTimer(quizContainer, questionId, quizId);
3281                }
3282            }else{
3283                if ($(this).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
3284                    $(this).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
3285                    $(this).parents('div[data-question-id]').find('.ays_
3285next').trigger('click');
3286                }
3287                var bulletsStatement = $(this).find('option:selected').length !== 0;
3288                if ( questionType === 'matching' ) {
3289                    bulletsStatement = answeredChoicesCount === choicesCount;
3290                }
3291
3292                if( bulletsStatement ){
3293                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + questionId + '"]');
3294                    thisBullet.parents('.ays-quiz-questions-nav-item').addClass('ays-quiz-questions-nav-item-answered');
3295                }else{
3296                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + questionId + '"]');
3297                    thisBullet.parents('.ays-quiz-questions-nav-item').removeClass('ays-quiz-questions-nav-item-answered');
3298                }
3299
3300            }
3301
3302            if(isRequiredQuestion === true){
3303                var buttonsStatement = $(this).find('option:selected').length !== 0;
3304                if ( questionType === 'matching' ) {
3305                    buttonsStatement = answeredChoicesCount === choicesCount;
3306                }
3307
3308                if( buttonsStatement ){
3309                    if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
3310                        $(e.target).parents('div[data-question-id]').find('input.ays_next').removeAttr('disabled');
3311                        $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').removeAttr('disabled');
3312                    }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
3313                        $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').removeAttr('disabled');
3314                        $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').removeAttr('disabled');
3315                    }
3316                }else{
3317                    if (!$(e.target).parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
3318                        $(e.target).parents('div[data-question-id]').find('input.ays_next').attr('disabled', true);
3319                        $(e.target).parents('div[data-question-id]').find('input.ays_early_finish').attr('disabled', true);
3320                    }else if(!$(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
3321                        $(e.target).parents('div[data-question-id]').find('i.ays_next_arrow').attr('disabled', true);
3322                        $(e.target).parents('div[data-question-id]').find('i.ays_early_finish').attr('disabled', true);
3323                    }
3324                }
3325            }
3326
3327            // $(this).find("option").removeAttr("selected");
3328            // $(this).find("option[value='"+this_select_value+"']").attr("selected", true);
3329        });
3330
3331        function aysSelectDropdownCheck(select){
3332            var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
3333            if(isRequiredQuestion === true){
3334                if(select.val() != ''){
3335                    if (!select.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
3336                        select.parents('div[data-question-id]').find('input.ays_next').removeAttr('disabled');
3337                        select.parents('div[data-question-id]').find('input.ays_early_finish').removeAttr('disabled');
3338                    }else if(!select.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
3339                        select.parents('div[data-question-id]').find('i.ays_next_arrow').removeAttr('disabled');
3340                        select.parents('div[data-question-id]').find('i.ays_early_finish').removeAttr('disabled');
3341                    }
3342                }else{
3343                    if (!select.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
3344                        select.parents('div[data-question-id]').find('input.ays_next').attr('disabled', true);
3345                        select.parents('div[data-question-id]').find('input.ays_early_finish').attr('disabled', true);
3346                    }else if(!select.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
3347                        select.parents('div[data-question-id]').find('i.ays_next_arrow').attr('disabled', true);
3348                        select.parents('div[data-question-id]').find('i.ays_early_finish').attr('disabled', true);
3349                    }
3350                }
3351            }
3352        }
3353
3354        // var shareButtons = document.querySelectorAll(".ays-share-btn.ays-to-share");
3355        $(document).on('click', ".ays-share-btn.ays-to-share", function (event){
3356            var width = 650,
3357                height = 450;
3358
3359            event.preventDefault();
3360
3361            window.open(this.href, quizLangObj.shareDialog, 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width='+width+',height='+height+',top='+(screen.height/2-height/2)+',left='+(screen.width/2-width/2));
3362        });
3363
3364        // if (shareButtons) {
3365        //     [].forEach.call(shareButtons, function(button) {
3366        //         button.addEventListener("click", function(event) {
3367        //             var width = 650,
3368        //                 height = 450;
3369
3370        //             event.preventDefault();
3371
3372        //             window.open(this.href, quizLangObj.shareDialog, 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,width='+width+',height='+height+',top='+(screen.height/2-height/2)+',left='+(screen.width/2-width/2));
3373        //         });
3374        //     });
3375        // }
3376
3377        $(document).find('.ays-quiz-container').map(function () {
3378            $(this).find('div[data-question-id]').eq(0).find('.ays_previous').css({'display':'none'});
3379            var next_sibilings_count = parseInt($(this).find('.ays_question_count_per_page').val());
3380            if(next_sibilings_count>0){
3381                $(this).find('div[data-question-id]').eq(next_sibilings_count-1).find('.ays_previous').css({'display':'none'});
3382            }
3383        });
3384
3385        $(document).on('click', '.ays_finish.action-button.ays_arrow', function (e, triggeredBy) {
3386            if (triggeredBy === 'save_button') {
3387                return;
3388            }
3389
3390            $(this).parents('.ays_buttons_div').find('input.ays_next.action-button').trigger('click');
3391        });
3392
3393        $(document).find('div[data-question-id]').map(function () {
3394            $(this).find('.ays-quiz-answers .ays-field').map(function () {
3395                if($(this).find('label[for^="ays-answer"]').eq(1).find('img').length !== 0){
3396                    $(this).find('label[for^="ays-answer"]').eq(0).addClass('ays_empty_before_content');
3397                    if($(this).find('label[for^="ays-answer"]').eq(0).text().length === 0){
3398                        $(this).find('label[for^="ays-answer"]').eq(0).css('background','transparent');
3399                    }
3400                }
3401            });
3402        });
3403        
3404        $(document).on('click', '.ays_finish.action-button', function (e, triggeredBy) {
3405            if (triggeredBy === 'save_button') {
3406                return;
3407            }
3408
3409            var ays_quiz_container_id = $(this).parents(".ays-quiz-container").attr("id");
3410            var ays_quiz_container = $('#'+ays_quiz_container_id);
3411            var quizId = $(this).parents(".ays-quiz-container").find('input[name="ays_quiz_id"]').val();
3412            if ( typeof window.aysEarlyFinishConfirmBox != 'undefined') {
3413                if ( typeof window.aysEarlyFinishConfirmBox[ quizId ] != 'undefined' ) {
3414                    if( window.aysSeeResultConfirmBox[ quizId ] == true ){
3415                        $(this).addClass("ays_timer_end");
3416                    }
3417                }
3418            }
3419            if (typeof $(this).parents('.ays-quiz-container').find('.ays_
3419next.start_button').attr("data-enable-leave-page") !== 'undefined') {
3420                if(! $(this).parents('.ays-quiz-container').find('.step.active-step .ays-abs-fs.ays-end-page').hasClass('information_form')){
3421                    $(this).parents('.ays-quiz-container').find('.ays_next.start_button').attr("data-enable-leave-page",false);
3422                }
3423            }
3424            aysQuizStopYoutubeIframe( ays_quiz_container );
3425        });
3426        
3427        $(document).on('click', '.ays_early_finish.action-button', function (e) {
3428            e.preventDefault();
3429            var quizId = $(this).parents('.ays-quiz-container').find('input[name="ays_quiz_id"]').val();
3430
3431            if (typeof $(this).parents('.ays-quiz-container').find('.ays_next.start_button').attr("data-enable-leave-page") !== 'undefined') {
3432                if(! $(this).parents('.ays-quiz-container').find('.step .ays-abs-fs.ays-end-page').hasClass('information_form')){
3433                    $(this).parents('.ays-quiz-container').find('.ays_next.start_button').attr("data-enable-leave-page",false);
3434                }
3435            }
3436            var confirm;
3437            if (myOptions.enable_early_finsh_comfirm_box && myOptions.enable_early_finsh_comfirm_box == "off") {
3438                confirm = true;
3439            }else{
3440                confirm = window.confirm(quizLangObj.areYouSure);
3441            }
3442            if(confirm){
3443                clearTimeout(explanationTimeout);
3444                window.aysEarlyFinishConfirmBox[ quizId ] = true;
3445                var totalSteps = $(e.target).parents().eq(3).find('div.step').length;
3446                var currentStep = $(e.target).parents().eq(3).find('div.step.active-step');
3447                var thankYouStep = $(e.target).parents().eq(3).find('div.step.ays_thank_you_fs');
3448                var infoFormLast = thankYouStep.prev().find('div.information_form');
3449                var questions_count = $(e.target).parents('form.ays-quiz-form').find('div[data-question-id]').length;
3450                $(this).parents('.ays-quiz-container').find('.ays_finish.action-button').addClass("ays_timer_end");
3451                if($(e.target).parents('.ays-quiz-container').find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
3452                    $(e.target).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(questions_count);
3453                }else{
3454                    $(e.target).parents('.ays-quiz-container').find('.ays-live-bar-fill').animate({
3455                        width: '100%'
3456                    });
3457                    $(e.target).parents('.ays-quiz-container').find('.ays-live-bar-percent').text(100);
3458                }
3459                currentStep.parents('.ays-quiz-container').find('.ays-quiz-timer').slideUp();
3460                setTimeout(function () {
3461                    currentStep.parents('.ays-quiz-container').find('.ays-quiz-timer').parent().hide();
3462                },300);
3463                if(infoFormLast.length == 0){
3464                    if (currentStep.hasClass('ays_thank_you_fs') === false) {
3465                        var steps = totalSteps - 3;
3466                        $(e.target).parents().eq(3).find('div.step').each(function (index) {
3467                            if ($(this).hasClass('ays_thank_you_fs')) {
3468                                $(this).addClass('active-step')
3469                            }else{
3470                                $(this).css('display', 'none');
3471                            }
3472                        });
3473                        $(e.target).parents().eq(3).find('input.ays_finish').trigger('click');
3474                    }
3475                }else{
3476                    currentStep.parents('.ays-quiz-container').find('.ays-quiz-timer').parent().hide();
3477                    $(e.target).parents('.ays-quiz-container').find('.ays-live-bar-wrap').removeClass('rubberBand').addClass('bounceOut');
3478                    setTimeout(function () {
3479                        $(e.target).parents('.ays-quiz-container').find('.ays-live-bar-wrap').css('display','none');
3480                    },300);
3481                    aysAnimateStep($(e.target).parents('.ays-quiz-container').data('quest-effect'), currentStep, infoFormLast.parent());
3482                    $(e.target).parents().eq(3).find('div.step').each(function (index) {
3483                        $(this).css('display', 'none');
3484                        $(this).removeClass('active-step')
3485                    });
3486                    infoFormLast.parent().css('display', 'flex');
3487                    infoFormLast.parent().addClass('active-step');
3488                    
3489                    $(this).parents(".ays-quiz-container").find('.ays_finish.action-button').addClass("ays_timer_end");
3490                    $(this).parents('.ays-quiz-wrap').find('.ays-quiz-questions-nav-wrap').slide
3490Up(500);
3491                }
3492
3493                if( $(this).parents('.ays-questions-container').length > 0 ){
3494                    if($(document).scrollTop() >= $(this).parents('.ays-questions-container').offset().top || $(this).parents('.ays-questions-container').offset().top > 500){
3495                        $(this).parents(".ays-quiz-container").goTo( myOptions );
3496                    }
3497                }
3498            }
3499        });
3500
3501        $(document).on('click', '.action-button.ays_restart_training_button', function () {
3502            window.location.href = window.location.href + ( window.location.search ? '&' : '?' ) + 'reset_quiz=1';
3503        });
3504
3505        $(document).on('click', '.action-button.ays_restart_button', function () {
3506            // if (window.location != window.parent.location) {
3507            //     parent.location.reload();
3508            // } else {
3509                window.location.reload();
3510            // }
3511        });
3512
3513        $(document).on('click', '.action-button.ays-quiz-exit-button', function (e) {
3514            if (window.location != window.parent.location) {
3515                var ays_quiz_exit_url = $(this).attr('href');
3516                if ( typeof ays_quiz_exit_url != "undefined" && ays_quiz_exit_url != "" ) {
3517                    e.preventDefault();
3518                    parent.location = ays_quiz_exit_url;
3519                }
3520            }
3521        });
3522        
3523        $(document).on('click', '.action-button.ays_clear_answer', function () {
3524            var $this = $(this);
3525            var activeStep = $this.parents('.step');
3526            var inputs = activeStep.find('input[name^="ays_questions[ays-question-"]:checked');
3527            var checked_answer_divs = activeStep.find('div.ays-field.checked_answer_div');
3528            var ays_text_field = activeStep.find('div.ays-field.ays-text-field');
3529            var ays_select_field = activeStep.find('div.ays-field.ays-select-field, div.ays-matching-field');
3530            inputs.removeAttr('checked');
3531            inputs.prop('checked', false);
3532            if (myOptions.make_questions_required && myOptions.make_questions_required == "on") {
3533                inputs.trigger('change');
3534            }
3535            // inputs.trigger('change');
3536            checked_answer_divs.removeClass('checked_answer_div');
3537            ays_text_field.find('.ays-text-input').val('');
3538            ays_text_field.find('.ays-text-input').trigger('input');
3539            if(ays_select_field.find('select.ays-select').length > 0){
3540                ays_select_field.find('select.ays-select').val(null).trigger('change');
3541                ays_select_field.find('select.ays-select option').removeAttr('selected');
3542                var thisQuestionID = ays_select_field.parents('div[data-question-id]').data('questionId');
3543                var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
3544                thisBullet.parents('.ays-quiz-questions-nav-item').removeClass('ays-quiz-questions-nav-item-answered');
3545                aysSelectDropdownCheck(ays_select_field.find('select.ays-select'));
3546            }
3547
3548            var currentQuestionID = $(this).parents('div[data-question-id]').data('questionId');
3549            var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + currentQuestionID + '"]');
3550            if(thisBullet){
3551                thisBullet.parent().removeClass('ays-quiz-questions-nav-item-answered');
3552            }
3553        });
3554        
3555        $(document).on('click', '.ays_music_sound', function() {
3556            var $this = $(this);
3557            var quizCoutainer = $this.parents('.ays-quiz-container');
3558            var audioEls = $(document).find('audio.ays_quiz_music');
3559            var soundEls = $(document).find('.ays_music_sound');
3560            var audioEl = quizCoutainer.find('audio.ays_quiz_music').get(0);
3561            if($this.hasClass('ays_sound_active')){
3562                audioEl.volume = 0;
3563                $this.find('.ays_fa').addClass('ays_fa_volume_off').removeClass('ays_fa_volume_up');
3564                $this.removeClass('ays_sound_active');
3565            } else {
3566                audioEl.volume = 1;
3567                $this.find('.ays_fa').addClass('ays_fa_volume_up').removeClass('ays_fa_volume_off');
3568                $this.addClass('ays_sound_active');
3569            }
3570        });
3571
3572        function goToLastPage(e){
3573            clearTimeout(explanationTimeout);
3574            clearInterval(window.aysTimerInterval);
3575            var container = $(e.target).parents('.ays-quiz-container');
3576            var totalSteps = container.find('div.step').length;
3577            var currentStep = container.find('div.step.active-step');
3578            var thankYouStep = container.find('div.step.ays_thank_you_fs');
3579            var infoFormLast = thankYouStep.prev().find('div.information_form');
3580            var questions_count = $(e.target).parents('form.ays-quiz-form').find('div[data-question-id]').length;
3581            if(container.find('.ays-live-bar-percent').hasClass('ays-live-bar-count')){
3582                container.find('.ays-live-bar-percent').text(questions_count);
3583            }else{
3584                container.find('.ays-live-bar-fill').animate({
3585                    width: '100%'
3586                });
3587                container.find('.ays-live-bar-percent').text(100);
3588            }
3589            container.find('.ays-quiz-timer').slideUp();
3590            setTimeout(function () {
3591                container.find('.ays-quiz-timer').parent().hide();
3592            },300);
3593
3594            if(infoFormLast.length == 0){
3595                if (currentStep.hasClass('ays_thank_you_fs') === false) {
3596                    var steps = totalSteps - 3;
3597                    container.find('div.step').each(function (index) {
3598                        if ($(this).hasClass('ays_thank_you_fs')) {
3599                            $(this).addClass('active-step')
3600                        }else{
3601                            $(this).css('display', 'none');
3602                        }
3603                    });
3604                    container.find('input.ays_finish').trigger('click');
3605                }
3606            }else{
3607                container.find('.ays-quiz-timer').parent().hide();
3608                container.find('.ays-live-bar-wrap').removeClass('rubberBand').addClass('bounceOut');
3609                setTimeout(function () {
3610                    container.find('.ays-live-bar-wrap').css('display','none');
3611                },300);
3612                aysAnimateStep(container.data('quest-effect'), currentStep, infoFormLast.parent());
3613                container.find('div.step').each(function (index) {
3614                    $(this).css('display', 'none');
3615                    $(this).removeClass('active-step')
3616                });
3617                infoFormLast.parent().css('display', 'flex');
3618                infoFormLast.parent().addClass('active-step');
3619
3620                $(e.target).parents('.ays-quiz-wrap').find('.ays-quiz-questions-nav-wrap').slide
3620Up(500);
3621            }
3622        }
3623
3624        function ays_formatState (ays_state) {
3625            if(!ays_state.id) {
3626                return aysEscapeHtml(ays_state.text);
3627            }
3628            var baseUrl = $(ays_state.element).data('nkar');
3629            if(baseUrl != ''){
3630                var ays_state = $(
3631                    '<span><img src=' + baseUrl + ' class="ays_answer_select_image" /> ' + aysEscapeHtml(ays_state.text) + '</span>'
3632                );
3633            }else{
3634                var ays_state = $('<span>' + aysEscapeHtml(ays_state.text) + '</span>');
3635            }
3636            return ays_state;
3637        }
3638
3639        $(document).find('.ays-quiz-container').each(function(){
3640            var $this = $(this);
3641            var selectEl = $this.find('select.ays-select');
3642            selectEl.each(function(){
3643                $(this).select2({
3644                    placeholder: quizLangObj.selectPlaceholder,
3645                    dropdownParent: $(this).parents('.ays-abs-fs'),
3646                    templateResult: ays_formatState
3647                });
3648            });
3649        });
3650
3651        $(document).find('.ays-quiz-container b[role="presentation"]').addClass('ays_fa ays_fa_chevron_down');
3652
3653        function aysResetQuiz ($quizContainer){
3654            var cont = $quizContainer.find('div[data-question-id]');
3655            cont.find('input[type="text"], textarea, input[type="number"], input[type="url"], input[type="email"]').each(function(){
3656                $(this).val('');
3657            });
3658            cont.find('select').each(function(){
3659                $(this).val('');
3660            });
3661            cont.find('select.ays-select').each(function(){
3662                $(this).val(null).trigger('change');
3663            });
3664            cont.find('select option').each(function(){
3665                $(this).removeAttr('selected');
3666            });
3667            cont.find('input[type="radio"], input[type="checkbox"]').each(function(){
3668                $(this).removeAttr('checked');
3669            });
3670        }
3671
3672        window.addEventListener("beforeunload", function (e) {
3673            var startButton = $(document).find('.ays-quiz-container .ays_next.start_button');
3674            var flag = false;
3675            for (var i = 0; i < startButton.length; i++) {
3676                var startBtn = startButton.eq(i).attr('data-enable-leave-page');
3677                if(typeof startBtn != undefined && startBtn === 'true'){
3678                    flag = true;
3679                    break;
3680                }
3681            }
3682
3683            if(flag){
3684                event.preventDefault();
3685                speechSynthesis.cancel();
3686                return true;
3687            }else{
3688                return null;
3689            }
3690        });
3691
3692        window.onbeforeunload =  function (e) {
3693            var startButton = $(document).find('.ays-quiz-container .ays_next.start_button');
3694            var flag = false;
3695            for (var i = 0; i < startButton.length; i++) {
3696                var startBtn = startButton.eq(i).attr('data-enable-leave-page');
3697                if(typeof startBtn != undefined && startBtn === 'true'){
3698                    flag = true;
3699                    break;
3700                }
3701            }
3702            if(flag){
3703                event.preventDefault();
3704                speechSynthesis.cancel();
3705                return true;
3706            }else{
3707                return null;
3708            }
3709        }
3710
3711        if( $(document).find('.ays-quiz-container').length > 0 ){
3712            var ays_quiz_autostart_interval = setInterval( function() {
3713                if (document.readyState === 'complete') {
3714                    var firstQuiz = $(document).find('.ays-quiz-container').first();
3715                    if( firstQuiz.find('input[name="ays_quiz_id"]').length > 0 ){
3716                        var fisrtQuizId = firstQuiz.find('input[name="ays_quiz_id"]').val();
3717                        var fisrtQuizOptions = JSON.parse(atob(window.aysQuizOptions[fisrtQuizId]));
3718
3719                        var questions_count = firstQuiz.find('div[data-question-id]').length;
3720
3721                        if(typeof fisrtQuizOptions.enable_autostart == 'undefined'){
3722                            fisrtQuizOptions.enable_autostart = 'off';
3723                        }
3724
3725                        if(typeof fisrtQuizOptions.enable_password == 'undefined'){
3726                            fisrtQuizOptions.enable_password = 'off';
3727                        }
3728
3729                        if( fisrtQuizOptions.enable_autostart == 'on' && fisrtQuizOptions.enable_password == 'off' ){
3730                            if ( questions_count > 0 ) {
3731                                var quizFirstPage = firstQuiz.find(".ays-questions-container div.step").first();
3732
3733                                if( quizFirstPage.hasClass('active-step') ){
3734                                    if(quizFirstPage.find('.ays_buttons_div .ays_next.start_button').length > 0 ){
3735                                        setTimeout(function(){
3736                                            firstQuiz.find('.ays_
3736next.start_button').trigger('click');
3737                                        }, 500);
3738                                    }
3739                                }
3740                            }
3741
3742                        }
3743                    }
3744                    clearInterval(ays_quiz_autostart_interval);
3745                }
3746            }, 500);
3747        }
3748
3749        $(document).find('.ays_next.start_button.ays_quiz_enable_loader, .ays_resume_button.ays_quiz_enable_loader').each(function(e){
3750            var $this = $(this);
3751            var container = $(this).parents('.ays-quiz-container');
3752
3753            var ays_quiz = setInterval( function() {
3754                if (document.readyState === 'complete') {
3755                    var isResume = $this.hasClass('ays_resume_button');
3756                    var buttonText = isResume ? quizLangObj.resumeButtonText : quizLangObj.startButtonText;
3757                    if (buttonText == null || buttonText === '' ) {
3758                        buttonText = isResume ? quizLangObj.defaultResumeButtonText : quizLangObj.defaultStartButtonText;
3759                    }
3760
3761                    container.find('.ays_quiz_start_button_loader_container').addClass('ays_display_none');
3762                    if ( $this.hasClass('ays_quiz_enable_loader') ) {
3763                        $this.removeClass('ays_quiz_enable_loader');
3764                    }
3765                    $this.prop('disabled', false);
3766                    $this.val( buttonText );
3767                    clearInterval(ays_quiz);
3768                }
3769            }, 500);
3770        });
3771
3772        $(document).find('.show_timer_countdown').each(function(e){
3773            // Countdown date
3774            var countDownEndDate = $(this).data('timer_countdown');
3775            var quiz_id = $(this).parents(".ays-quiz-container").attr("id");
3776            if (countDownEndDate != '' && countDownEndDate != undefined) {
3777                var showM = $(this).parents('.step').data('messageExist');
3778                ays_countdown_datetime(countDownEndDate, !showM, quiz_id);
3779            }
3780        });
3781
3782        $(document).find('.ays_resume_button').each(function(e){
3783            var currentUrl = new URL(window.location.href);
3784            var isResumeQuiz = currentUrl.searchParams.get('ays-resume-quiz') === 'yes';
3785            if (isResumeQuiz) {
3786                $(this).trigger('click');
3787            }
3788        });
3789
3790        document.addEventListener('fullscreenchange', function(event) {
3791            if (!document.fullscreenElement) {
3792                var eventTarget = event.target
3793                if( $( eventTarget ).hasClass('ays-quiz-container') ){
3794                    aysQuizFullScreenDeactivate( eventTarget );
3795                }
3796            }
3797        }, false);
3798
3799        $(document).on('click', '.ays-quiz-open-full-screen, .ays-quiz-close-full-screen', function() {
3800            var quiz_container = $(this).parents('.ays-quiz-container').get(0);
3801            toggleFullscreen(quiz_container);
3802        });
3803
3804        $(document).on('click', '.action-button.ays_chain_next_quiz_button', function () {
3805            if (window.location != window.parent.location) {
3806                parent.location.reload();
3807            } else {
3808                window.location.reload();
3809            }
3810        });
3811
3812        $(document).on('click', '.action-button.ays_chain_see_result_button', function () {
3813            if (window.location != window.parent.location) {
3814                parent.location.reload();
3815            } else {
3816                window.location.reload();
3817            }
3818        });
3819
3820        $(document).on('change', '.ays-quiz-res-toggle-checkbox', function(){
3821            var _this  = $(this);
3822            var parent = _this.parents('.ays_quiz_results');
3823            var elements = parent.find('.step.ays_question_result');
3824
3825            if (_this.prop('checked')) {
3826                if (  elements.hasClass('ays_display_none') ) {
3827                    elements.removeClass('ays_display_none');
3828                }
3829            }else{
3830                elements.addClass('ays_display_none');             
3831            }
3832        });
3833
3834        $(document).on('keydown', function(e) {
3835            var keyboardBox = $(document).find(".ays-quiz-container.ays-quiz-keyboard-active");
3836
3837            if(e.keyCode === 9 && keyboardBox.length > 0){
3838                $(document).find(".ays-select-field *:not(.dropdown-wrapper,.select2-selection__arrow, .select2-selection__placeholder, .ays_fa.ays_fa_chevron_down)").attr("tabindex" , "0")
3839            }
3840
3841            if(e.keyCode === 27){
3842                var zoomPopup = $(document).find('.ays-quiz-question-image-lightbox-container');
3843                if( zoomPopup.length > 0 ){
3844                    zoomPopup.hide();
3845                }
3846
3847                var questionReportPopup = $(document).find('div[id*="ays-quiz-question-report-modal"]');
3848                if( questionReportPopup.length > 0 ){
3849                    questionReportPopup.hide();
3850                }
3851            }
3852
3853            if($(e.target).hasClass("ays-quiz-keyboard-active")){
3854                if (e.keyCode === 32) {
3855                    e.preventDefault();
3856                    $(e.target).find('label.ays-quiz-keyboard-label').trigger("click");
3857                }
3858
3859
3860                if (e.keyCode === 13) {
3861                    e.preventDefault();
3862                    var checked_inputs = $(e.target).parents(".ays-quiz-answers").find('input
3862:checked');
3863                    if(checked_inputs.length > 0){
3864                        $(e.target).parents('.step.active-step').find(".ays_next").trigger('click');
3865                    }
3866                    else{
3867                        $(e.target).trigger('click');
3868                    }
3869
3870                }
3871            }
3872        });
3873
3874        $(document).on('click', '.ays-image-question-img .ays-quiz-question-image-zoom', function(e) {
3875            var _this = $(this);
3876
3877            var dataSrc = _this.attr('data-ays-src');
3878            var keyboardBox = _this.parents(".ays-quiz-container.ays-quiz-keyboard-active");
3879            var keyboardClass = "";
3880            var keyboardTabindex = "";
3881
3882            if(keyboardBox.length > 0){
3883                keyboardClass = "ays-quiz-keyboard-active";
3884                keyboardTabindex = "tabindex='0'";
3885            }
3886
3887            if (dataSrc != null && dataSrc != "") {
3888                var aysImagesOverlayBox = $(document).find('.ays-quiz-question-image-lightbox-container');
3889                var lightboxContainer = "";
3890                if (aysImagesOverlayBox.length > 0 )  {
3891                    var mainDiv = document.querySelector(".ays-quiz-question-image-lightbox-container");
3892                    var createdImgTag = document.querySelector(".ays-quiz-question-image-lightbox-img");
3893
3894                    createdImgTag.src = dataSrc;
3895                    mainDiv.style.display = "flex";
3896                } else {
3897                    var bodyTag = document.getElementsByTagName("body")[0];
3898
3899                    lightboxContainer += '<div class="ays-quiz-question-image-lightbox-container" style="display: flex;">';
3900
3901                        lightboxContainer += '<div class="ays-quiz-question-image-lightbox-img-box">';
3902                            lightboxContainer += '<img class="ays-quiz-question-image-lightbox-img" src="'+ dataSrc +'" style="z-index: 102;">';
3903                        lightboxContainer += '</div>';
3904                        lightboxContainer += '<span class="ays-quiz-question-image-lightbox-close-button '+ keyboardClass +'" '+ keyboardTabindex +'>×</span>';
3905
3906                    lightboxContainer += '</div>';
3907
3908                    $(document).find('html > body').append(lightboxContainer);
3909
3910                    var mainDiv = $(document).find(".ays-quiz-question-image-lightbox-container");
3911                    mainDiv.css({
3912                        'display': 'flex'
3913                    });
3914                }
3915            }
3916        });
3917
3918
3919        $(document).on('click', '.ays-quiz-question-image-lightbox-close-button', function() {
3920            var _this = $(this);
3921            var parent = _this.parents(".ays-quiz-question-image-lightbox-container");
3922
3923            parent.css({
3924                'display': 'none'
3925            });
3926        });
3927
3928        $(document).on('click', '.ays-quiz-question-image-lightbox-container', function(e){
3929            var modalBox = $(e.target).attr('class');
3930            var _this = $(this);
3931
3932            if (typeof modalBox != 'undefined' &&  modalBox == 'ays-quiz-question-image-lightbox-container') {
3933                _this.css({
3934                    'display': 'none'
3935                });
3936            }
3937        });
3938
3939        $(document).on('click', '.ays-navbar-bookmark', function(e) {
3940            var _this = $(this);
3941            var parent = _this.parents('div.ays-quiz-container');
3942            var thisQuestion = _this.parents('div[data-question-id]');
3943            var questionId = thisQuestion.data('questionId');
3944            var highlighted = ($(this).attr('highlighted') === 'true');
3945            var navbarItem = parent.find('.ays-quiz-questions-nav-wrap .ays_questions_nav_question[data-id="' + questionId + '"]');
3946            var src = $(this).attr('src');
3947
3948            if (!highlighted) {
3949                _this.parents('.ays-quiz-questions-nav-bookmark-box').find('.ays-navbar-bookmark-value').val('marked');
3950                $(this).attr('highlighted', true).attr('src', src.replace('empty', 'filled'));
3951                navbarItem.find('.ays-quiz-navbar-highlighted-notice').show();
3952            } else {
3953                $(this).attr('highlighted', false).attr('src', src.replace('filled', 'empty'));
3954                navbarItem.find('.ays-quiz-navbar-highlighted-notice').hide();
3955                _this.parents('.ays-quiz-questions-nav-bookmark-box').find('.ays-navbar-bookmark-value').removeAttr('value');
3956            }
3957        });
3958
3959        $(document).on('click', '.ays-quiz-open-report-window', function() {
3960            var _this = $(this);
3961            var parent = _this.parents('div.ays-quiz-container');
3962
3963            if (_this.parents('div.step.active-step').length > 0) {
3964                var question = _this.parents('div.step.active-step');
3965            } else {
3966                var question = _this.parents('div.step.ays_question_result');
3967
3968            }
3969
3970            if( question.length == 0 ){
3971                var question = _this.parents('div.step');
3972            }
3973
3974            var questionId = question.attr('data-question-id');
3975
3976            var reportsModal = parent.find('div.ays-modal-reports');
3977
3978            reportsModal.fadeIn(200, function() {
3979                reportsModal.find('textarea#ays-quiz-question-report-textarea').val('');
3980                reportsModal.find('input.ays-quiz-report-question-id').val(questionId);
3981            });
3982        });
3983        
3984        $(document).find('.ays-close-reports-window').on('click', function() {
3985            var _this = $(this);
3986            var parent = _this.parents('div.ays-quiz-container');
3987            var reportsModal = parent.find('div.ays-modal-reports');
3988
3989            reportsModal.fadeOut(200);
3990        });
3991
3992        $(document).on('keypress', '.ays_quiz_form_input_number_type', function(e) {
3993            if( navigator.userAgent.toLowerCase().includes('firefox') ){
3994                return e.charCode >= 48 && e.charCode <= 57;
3995            }
3996        });
3997
3998        $(document).on('click', '#ays-quiz-download-pdf', function(e) {
3999            e.preventDefault();
4000            var quizId = $(this).data('quiz-id');
4001            var loadingPopup = createLoadingPopup();
4002        
4003            var container = document.createElement('div');
4004            container.style.width = '100%';
4005            container.style.backgroundColor = 'white';
4006            container.style.padding = '20px';
4007        
4008            var element = $(`#ays-quiz-container-${quizId}`);
4009            var clone = element.clone();
4010        
4011            clone.find('button').remove();
4012            clone.find('.ays_quiz_rete').remove();
4013            clone.find('.ays-quiz-results-toggle-block').remove();
4014            clone.find('.ays_detailed_result_column_chart_column_empty, .ays_user_corrects_count_pie_chart_container').css({
4015                'max-height': '400px',
4016            });
4017          
4018                    
4019            clone.css({
4020                'display': 'block', 
4021                'opacity': '1',
4022                'position': 'relative',
4023                'pointer-events': 'auto',
4024                'transform': 'none'
4025            });
4026        
4027            $(container).append(clone);
4028            $(document.body).append(container);
4029        
4030            waitForImagesToLoad(container).then(() => {
4031                quiz_do_html2pdf(container, 'quiz_results.pdf').then(function() {
4032                    $(container).remove();
4033                    loadingPopup.remove();
4034                });
4035            }).catch(error => {
4036                $(container).remove();
4037                loadingPopup.remove();
4038            });
4039        });
4040
4041        $(window).on('resize', function() {
4042            var answersContainer = $(document).find('.ays-quiz-answers');
4043            var fields = $(document).find('.ays-field');
4044
4045            var newClassArr = $(document).find('.ays_quiz_answer_view_class_mobile');
4046
4047            var quizContainers = $(document).find('.ays-quiz-container');
4048
4049            if(quizContainers.length > 0){
4050                quizContainers.each(function(ev){
4051                    // var newClass = $(this).val();
4052                    // var ays_quiz_container_id = $(this).parents(".ays-quiz-container").attr("id");
4053                    var ays_quiz_container = $(this);
4054                    var quiz_id = ays_quiz_container.attr('data-quiz-id');
4055
4056                    var newClassArr = ays_quiz_container.find('.ays_quiz_answer_view_class_mobile');
4057
4058                    var newClass = '';
4059                    if( newClassArr.length > 0 ){
4060                        newClass = newClassArr.val();
4061                    }
4062
4063                    var answersContainer = ays_quiz_container.find('.ays-quiz-answers');
4064                    var fields = ays_quiz_container.find('.ays-field');
4065
4066                    if ($(window).width() <= 768) {
4067                        // Mobile view
4068                        
4069                        if (newClass === 'ays_list_view_container' || newClass === 'ays_grid_view_container') {
4070                            // Store the original class if not already stored
4071                            if (!answersContainer.data('original-class')) {
4072                                if (answersContainer.hasClass('ays_list_view_container')) {
4073                                    answersContainer.data('original-class', 'ays_list_view_container');
4074                                } else if (answersContainer.hasClass('ays_grid_view_container')) {
4075                                    answersContainer.data('original-class', 'ays_grid_view_container');
4076                                }
4077                            }
4078                            
4079                            // Apply mobile class to answersContainer
4080                            if (answersContainer.hasClass('ays_list_view_container')) {
4081                                answersContainer.removeClass('ays_list_view_container');
4082                            } else if (answersContainer.hasClass('ays_grid_view_container')) {
4083                                answersContainer.removeClass('ays_grid_view_container');
4084                            }
4085                            answersContainer.addClass(newClass);
4086        
4087                            // Apply mobile class to .ays-field
4088                            if (newClass === 'ays_grid_view_container') {
4089                                fields.removeClass('ays_list_view_item').addClass('ays_grid_view_item');
4090                            } else if (newClass === 'ays_list_view_container') {
4091                                fields.removeClass('ays_grid_view_item').addClass('ays_list_view_item');
4092                            }
4093                        }
4094                    } else {
4095                        // Desktop view - revert to original class
4096                        var originalClass = answersContainer.data('original-class');
4097                        if (originalClass) {
4098                            // Remove mobile class from answersContainer
4099                            if (answersContainer.hasClass('ays_list_view_container')) {
4100                                answersContainer.removeClass('ays_list_view_container');
4101                            } else if (answersContainer.hasClass('ays_grid_view_container')) {
4102                                answersContainer.removeClass('ays_grid_view_container');
4103                            }
4104                            
4105                            // Restore original class to answersContainer
4106                            answersContainer.addClass(originalClass);
4107        
4108                            // Restore original class to .ays-field
4109                            if (originalClass === 'ays_grid_view_container') {
4110                                fields.removeClass('ays_list_view_item').addClass('ays_grid_view_item');
4111                            } else if (originalClass === 'ays_list_view_container') {
4112                                fields.removeClass('ays_grid_view_item').addClass('ays_list_view_item');
4113                            }
4114                        }
4115                    }
4116                });
4117                
4118            }
4119        }).trigger('resize');
4120
4121        function quizTimer( container ){
4122            container.find('div.ays-quiz-timer').hide(800);
4123            var timer = parseInt(container.find('div.ays-quiz-timer').attr('data-timer'));
4124            var pageTitle = $(document).find('title');
4125            var pageTitleText = $(document).find('title').html();
4126            var timeForShow = "";
4127
4128            // Display all questions on one page
4129            myOptions.quiz_timer_red_warning = ( myOptions.quiz_timer_red_warning ) ? myOptions.quiz_timer_red_warning : 'off';
4130            var quiz_timer_red_warning = (myOptions.quiz_timer_red_warning && myOptions.quiz_timer_red_warning == "on") ? true : false;
4131
4132            if (!isNaN(timer) && myOptions.timer !== undefined) {
4133                if (myOptions.timer === timer && timer !== 0) {
4134                    timer += 2;
4135                    if (timer !== undefined) {
4136                        var countDownDate = new Date().getTime() + (timer * 1000);
4137                        var timerFlag = false;
4138
4139                        // Message before timer
4140                        var quiz_message_before_timer = (myOptions.quiz_message_before_timer && myOptions.quiz_message_before_timer != "") ? ( myOptions.quiz_message_before_timer ) : '';
4141
4142                        if ( quiz_message_before_timer != '' ) {
4143                            quiz_message_before_timer = quiz_message_before_timer.replace(/(["'])/g, "\\$1") + " ";
4144                            $(document).find('html > head').append('<style> #ays-quiz-container-'+ quizId +' div.ays-quiz-timer.ays-quiz-message-before-timer:before{content: "'+ quiz_message_before_timer +'"; }</style>');
4145                        }
4146
4147                        window.aysTimerInterval = setInterval(function () {
4148                            var now = new Date().getTime();
4149                            var distance = countDownDate - Math.
4149ceil(now/1000)*1000;
4150                            var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
4151                            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
4152                            var seconds = Math.floor((distance % (1000 * 60)) / 1000);
4153                            var sec = seconds;
4154                            var min = minutes;
4155                            var hour = hours;
4156                            if(hours <= 0){
4157                                hours = null;
4158                            }else if (hours < 10) {
4159                                hours = '0' + hours;
4160                            }
4161                            if (minutes < 10) {
4162                                minutes = '0' + minutes;
4163                            }
4164                            if (seconds < 10) {
4165                                seconds = '0' + seconds;
4166                            }
4167                            timeForShow =  ((hours==null)? "" : (hours + ":")) + minutes + ":" + seconds;
4168                            if(distance <=1000){
4169                                timeForShow =  ((hours==null) ? "" : "00:") + "00:00";
4170                                container.find('div.ays-quiz-timer').html(timeForShow);
4171                                if(myOptions.quiz_timer_in_title == 'on'){
4172                                    pageTitle.html( timeForShow + " - " + pageTitleText );
4173                                }
4174                            }else{
4175                                container.find('div.ays-quiz-timer').html(timeForShow);
4176                                if(myOptions.quiz_timer_in_title == 'on'){
4177                                    pageTitle.html( timeForShow + " - " + pageTitleText );
4178                                }
4179                            }
4180
4181                            if ( quiz_timer_red_warning ) {
4182                                var distanceSec = Math.floor(distance / 1000);
4183                                var timerPercentage = Math.floor(( timer - distanceSec ) * 100);
4184                                var percentage = Math.floor( timerPercentage / timer );
4185
4186                                if ( percentage >= 90 && ! timerFlag ) {
4187                                    var timerContainer = container.find('section.ays_quiz_timer_container');
4188                                    timerFlag = true;
4189
4190                                    if ( ! timerContainer.hasClass( 'ays_quiz_timer_red_warning' ) ) {
4191                                        timerContainer.addClass( 'ays_quiz_timer_red_warning' );
4192                                    }
4193                                }
4194                            }
4195
4196                            container.find('.ays_quiz_timer_container').show();
4197                            container.find('div.ays-quiz-timer').show(500);
4198                            if(container.find('.ays-quiz-timer').length === 0){
4199                                clearInterval(window.aysTimerInterval);
4200                                if(myOptions.quiz_timer_in_title == 'on'){
4201                                    pageTitle.html( pageTitleText );
4202                                }
4203                                container.find('.ays_quiz_timer_container').slideUp(500);
4204                            }
4205                            if(container.find('.ays_finish.action-button').hasClass("ays_timer_end") ||
4206                                container.find('.ays_next.action-button').hasClass("ays_timer_end")){
4207                                clearInterval(window.aysTimerInterval);
4208                                if(myOptions.quiz_timer_in_title == 'on'){
4209                                    pageTitle.html( pageTitleText );
4210                                }
4211                                container.find('.ays_quiz_timer_container').slideUp(500);
4212                            }
4213
4214                            if(hour == 0 && min == 0 && sec < 1){
4215                                container.find('.ays_buttons_div > *:not(input.ays_finish)').off('click');
4216                            }
4217
4218                            if (distance <= 1) {
4219                                clearInterval(window.aysTimerInterval);
4220                                if(! container.find('div.ays-quiz-after-timer').hasClass('empty_after_timer_text')){
4221                                    container.find('.ays_quiz_timer_container').css({
4222                                        'position': 'static',
4223                                        'height': '100%',
4224                                    });
4225                                    container.find('.ays_quiz_timer_container').show();
4226                                    container.find('div.ays-quiz-timer').slideUp();
4227                                    container.find('div.ays-quiz-after-timer').addClass("ays-quiz-timer-end");
4228                                    container.find('.ays_quiz_timer_container').addClass("ays-quiz-timer-end-for-required");
4229                                    container.find('div.ays-quiz-after-timer').slideDown(500);
4230                                }else{
4231                                    container.find('.ays_quiz_timer_container').slideUp(500);
4232                                    container.find('.ays_quiz_timer_container').addClass("ays-quiz-timer-end-for-required");
4233                                }
4234
4235                                if(myOptions.quiz_timer_in_title == 'on'){
4236                                    pageTitle.html( pageTitleText );
4237                                }
4238                                var totalSteps = container.find('div.step').length;
4239                                var currentStep = container.find('div.step.active-step');
4240                                var thankYouStep = container.find('div.step.ays_thank_you_fs');
4241                                var infoFormLast = thankYouStep.prev().find('div.information_form');
4242
4243                                var myStartDate = new Date(Date.now() - aysDurationInSeconds * AYS_MS_PER_SECONDS);
4244                                var countdownEndTime = myStartDate.aysCustomFormat( "#YYYY#-#MM#-#DD# #hhhh#:#mm#:#ss#" );
4245
4246                                container.find('input.ays-quiz-end-date').val(countdownEndTime);
4247                                if(infoFormLast.length == 0){
4248                                    if (currentStep.hasClass('ays_thank_you_fs') === false) {
4249                                        var steps = totalSteps - 3;
4250                                        container.find('div.step').each(function (index) {
4251                                            if ($(this).hasClass('ays_thank_you_fs')) {
4252                                                $(this).addClass('active-step')
4253                                            }else{
4254                                                $(this).css('display', 'none');
4255                                            }
4256                                        });
4257                                        // aysAnimateStep(ays_quiz_container.data('questEffect'), currentStep, ays_quiz_container.find('.step.ays_thank_you_fs'));
4258                                        var ays_finish_button = container.find('input.ays_finish');
4259                                        if(ays_finish_button.prop('disabled')){
4260                                            ays_finish_button.prop('disabled', false);
4261                                        }
4262                                        ays_finish_button.addClass('ays-quiz-after-timer-end');
4263                                        ays_finish_button.trigger('click');
4264                                    }
4265                                }else{
4266                                    if(container.find('div.ays-quiz-after-timer').hasClass('empty_after_timer_text')){
4267                                        container.find('.ays-quiz-timer').parent().slideUp(500);
4268                                    }
4269                                    container.find('.ays-live-bar-wrap').removeClass('rubberBand').addClass('bounceOut');
4270                                    container.find('.ays-live-bar-percent').removeClass('rubberBand').addClass('bounceOut');
4271                                    setTimeout(function () {
4272                                        container.find('.ays-live-bar-wrap').css('display','none');
4273                                        container.find('.ays-live-bar-percent').css('display','none');
4274                                    },300);
4275                                    aysAnimateStep(ays_quiz_container.data('questEffect'), currentStep, infoFormLast.parent());
4276                                    container.find('div.step').each(function (index) {
4277                                        $(this).css('display', 'none');
4278                                        $(this).removeClass('active-step')
4279                                    });
4280                                    infoFormLast.parent().css('display', 'flex');
4281                                    infoFormLast.parent().addClass('active-step');
4282                                    var ays_finish_button = container.find('input.ays_finish');
4283                                    ays_finish_button.addClass('ays-quiz-after-timer-end');
4284                                }
4285                                container.parents('.ays-quiz-wrap').find('.ays-quiz-questions-nav-wrap').slide
4285Up(500);
4286                            }
4287                        }, 1000);
4288                    }
4289                } else {
4290                    alert('Wanna cheat??');
4291                    if (window.location != window.parent.location) {
4292                        parent.location.reload();
4293                    } else {
4294                        window.location.reload();
4295                    }
4296                }
4297            }
4298        }
4299
4300        function checkQuestionTimer( container ){
4301            if( window.aysQuizQuestionTimers[quizId] ) {
4302                var questions = container.find('div[data-question-id]');
4303                var remainingQuestionsEmpty = [];
4304                for (var i = 0; i < questions.length; i++) {
4305                    var questionID = questions[i].dataset.questionId;
4306
4307                    if(
4308                        window.aysQuizQuestionTimers[quizId][questionID]
4309                        &&
4310                        (
4311                            window.aysQuizQuestionTimers[quizId][questionID].ended === true
4312                            ||
4313                            window.aysQuizQuestionTimers[quizId][questionID].stopped === true
4314                        )
4315                    ) {
4316                        continue;
4317                    } else {
4318                        if ( ays_quiz_is_question_empty( $(questions[i]) ) === false ) {
4319                            remainingQuestionsEmpty.push({
4320                                item: $(questions[i]),
4321                                id: questionID
4322                            });
4323                        }
4324                    }
4325                }
4326
4327                if( remainingQuestionsEmpty.length > 0 ){
4328                    return remainingQuestionsEmpty[0].id;
4329                }else{
4330                    return false;
4331                }
4332            }
4333            return false;
4334        }
4335
4336        function stopQuestionTimer( container, questionID, quizId ){
4337            if( myOptions.enable_timer && myOptions.enable_timer === 'on' ) {
4338                if (myOptions.quiz_timer_type && myOptions.quiz_timer_type === 'question_timer') {
4339                    if (window.aysQuizQuestionTimers && window.aysQuizQuestionTimers[quizId]) {
4340                        if ( window.aysQuizQuestionTimers[quizId][questionID] ) {
4341                            // clearInterval(window.aysQuizQuestionTimers[quizId][questionID].timeout);
4342                            window.aysQuizQuestionTimers[quizId][questionID].stopped = true;
4343                            var qid = checkQuestionTimer( container, quizId );
4344                            if (qid === false) {
4345                                container.find('input.ays_finish').addClass('ays-quiz-after-timer-end');
4346                            }
4347                        }
4348                    }
4349                }
4350            }
4351        }
4352
4353        function questionTimer( questionContainer, questionID ){
4354            var container = questionContainer.parents('.ays-quiz-container');
4355            if( ! questionID ){
4356                return;
4357            }
4358
4359            if( myOptions.enable_timer && myOptions.enable_timer !== 'on' ){
4360                return;
4361            }
4362
4363            if (myOptions.quiz_timer_type && myOptions.quiz_timer_type !== 'question_timer') {
4364                return;
4365            }
4366
4367            if ( ! window.aysQuizQuestionTimers || ! window.aysQuizQuestionTimers[quizId] ) {
4368                return;
4369            }
4370
4371            if ( questionContainer.data('type') === 'custom' ) {
4372                for (var i in window.aysQuizQuestionTimers[quizId]) {
4373                    clearInterval(window.aysQuizQuestionTimers[quizId][i].timeout);
4374                    clearInterval(window.aysQuizQuestionTimers[quizId][i].switchTimeout);
4375                    window.aysQuizQuestionTimers[quizId][i].active = false;
4376                }
4377
4378                container.find('div.ays-quiz-after-timer').slideDown(500);
4379                container.find('div.ays-quiz-timer').slideUp(500);
4380                container.find('.ays_quiz_timer_container').removeClass("ays-quiz-timer-end-for-required");
4381                questionContainer.find('.ays-quiz-answers').css({
4382                    'pointer-events': 'none'
4383                });
4384                container.find('.ays_quiz_timer_container').slideUp(500);
4385
4386                var qid = checkQuestionTimer( container );
4387                if (qid === false) {
4388                    container.find('input.ays_finish').addClass('ays-quiz-after-timer-end');
4389                }
4390            }
4391
4392            if ( ! window.aysQuizQuestionTimers[quizId][questionID] ) {
4393                return;
4394            }
4395
4396            for ( var i in window.aysQuizQuestionTimers[quizId] ){
4397                if( window.aysQuizQuestionTimers[quizId][i].active ){
4398                    clearInterval( window.aysQuizQuestionTimers[quizId][i].timeout );
4399                    clearInterval( window.aysQuizQuestionTimers[quizId][i].switchTimeout );
4400                    window.aysQuizQuestionTimers[quizId][i].active = false;
4401                }
4402            }
4403
4404            container.find('div.ays-quiz-timer').html("--:--");
4405            var timeForShow = "";
4406
4407            var isRequiredQuestion = myOptions.make_questions_required && myOptions.make_questions_required === "on";
4408            var enablePrevButton = myOptions.enable_previous_button && myOptions.enable_previous_button === 'on';
4409            var enableNextButton = myOptions.enable_next_button && myOptions.enable_next_button === 'on';
4410            var enableClearAnswer = myOptions.enable_clear_answer && myOptions.enable_clear_answer === 'on';
4411            var enableArrows = myOptions.enable_arrows && myOptions.enable_arrows === 'on';
4412
4413            clearInterval(explanationTimeout);
4414
4415            var qid = checkQuestionTimer( container );
4416            if (qid === false) {
4417                container.find('input.ays_finish').addClass('ays-quiz-after-timer-end');
4418                container.find('input.ays_finish').addClass('ays_timer_end');
4419            }
4420
4421            if ( window.aysQuizQuestionTimers[quizId][questionID].ended === true ) {
4422                if (enableNextButton) {
4423                    if (enableArrows) {
4424                        questionContainer.find('i.ays_next_arrow').removeAttr('disabled');
4425                    } else {
4426                        questionContainer.find('input.ays_next').removeAttr('disabled');
4427                    }
4428                }
4429
4430                if( isRequiredQuestion ){
4431                    if (enableArrows) {
4432                        if (!questionContainer.find('i.ays_next_arrow').hasClass('ays_display_none')){
4433                            questionContainer.find('i.ays_next_arrow').removeAttr('disabled');
4434                        }
4435                    } else {
4436                        if (!questionContainer.find('input.ays_next').hasClass('ays_display_none')){
4437                            questionContainer.find('input.ays_next').removeAttr('disabled');
4438                        }
4439                    }
4440                }
4441
4442                if( enableClearAnswer ){
4443                    if (enableArrows) {
4444                        questionContainer.find('i.ays_clear_answer').attr('disabled', 'disabled');
4445                    } else {
4446                        questionContainer.find('input.ays_clear_answer').attr('disabled', 'disabled');
4447                    }
4448                }
4449            }
4450
4451            if ( myOptions.timer !== undefined ) {
4452                var timer = Number( myOptions.timer );
4453                if(
4454                    window.aysQuizQuestionTimers[quizId][questionID].timeout !== null
4455                    &&
4456                    window.aysQuizQuestionTimers[quizId][questionID].timer !== null
4457                ) {
4458                    timer = window.aysQuizQuestionTimers[quizId][questionID].timer;
4459                }
4460
4461                if( window.aysQuizQuestionTimers[quizId][questionID].ended === false ) {
4462                    if ( timer <= 0 ){
4463                        window.aysQuizQuestionTimers[quizId][questionID].ended = true;
4464                        if (enableNextButton) {
4465                            if (enableArrows) {
4466                                questionContainer.find('i.ays_next_arrow').removeAttr('disabled');
4467                            } else {
4468                                questionContainer.find('input.ays_next').removeAttr('disabled');
4469                            }
4470                        }
4471                    }
4472                }
4473
4474                if (
4475                    window.aysQuizQuestionTimers[quizId][questionID].ended === true
4476                    &&
4477                    window.aysQuizQuestionTimers[quizId][questionID].stopped === false
4478                ) {
4479                    questionContainer.find('.ays-quiz-answers').css({
4480                        'pointer-events': 'none'
4481                    });
4482                    questionContainer.find('[name^="ays_questions"]').attr('disabled', 'disabled');
4483                    questionContainer.find('select.ays-select').select2('close');
4484                    container.find('.ays_quiz_timer_container').removeClass("ays-quiz-timer-end-for-required");
4485                    container.find('div.ays-quiz-timer').slideUp();
4486
4487                    if ( ! container.find('div.ays-quiz-after-timer').hasClass('empty_after_timer_text') ) {
4488                        container.find('.ays_quiz_timer_container').css({
4489                            'position': 'static',
4490                            'height': '100%',
4491                        });
4492
4493                        container.find('.ays_quiz_timer_container').slideDown(500);
4494                        container.find('div.ays-quiz-after-timer').slideDown(500);
4495                    } else {
4496                        container.find('.ays_quiz_timer_container').slideUp(500);
4497                        container.find('div.ays-quiz-after-timer').slideUp(500);
4498                    }
4499                } else if (
4500                    window.aysQuizQuestionTimers[quizId][questionID].ended === true
4501                    &&
4502                    window.aysQuizQuestionTimers[quizId][questionID].stopped === true
4503                ) {
4504                    container.find('.ays_quiz_timer_container').slideUp();
4505                } else {
4506                    container.find('div.ays-quiz-after-timer').slideUp();
4507                    container.find('div[data-question-id="'+ questionID +'"]').find('.ays-quiz-answers').removeAttr('style');
4508                }
4509
4510                if ( !isNaN(timer) && timer !== 0 ) {
4511                    timer += 2;
4512                    var countDownDate = new Date().getTime() + (timer * 1000);
4513
4514                    // Message before timer
4515                    var quiz_message_before_timer = (myOptions.quiz_message_before_timer && myOptions.quiz_message_before_timer !== "") ? (myOptions.quiz_message_before_timer) : '';
4516                    if (quiz_message_before_timer !== '') {
4517                        quiz_message_before_timer = quiz_message_before_timer.replace(/(["'])/g, "\\$1") + " ";
4518                        $(document).find('html > head').append('<style> #ays-quiz-container-' + quizId + ' div.ays-quiz-timer.ays-quiz-message-before-timer:before{content: "' + quiz_message_before_timer + '"; }</style>');
4519                    }
4520
4521                    if ( ! window.aysQuizQuestionTimers[quizId][questionID].ended ) {
4522                        window.aysQuizQuestionTimers[quizId][questionID].active = true;
4523                        window.aysQuizQuestionTimers[quizId][questionID].timeout = setInterval(function () {
4524
4525                            var now = new Date().getTime();
4526                            var distance = countDownDate - Math.
4526ceil(now / 1000) * 1000;
4527                            var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
4528                            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
4529                            var seconds = Math.floor((distance % (1000 * 60)) / 1000);
4530                            window.aysQuizQuestionTimers[quizId][questionID].timer = Math.floor(distance / 1000);
4531
4532                            if (hours <= 0) {
4533                                hours = null;
4534                            } else if (hours < 10) {
4535                                hours = '0' + hours;
4536                            }
4537                            if (minutes < 10) {
4538                                minutes = '0' + minutes;
4539                            }
4540                            if (seconds < 10) {
4541                                seconds = '0' + seconds;
4542                            }
4543
4544                            timeForShow = ((hours == null) ? "" : (hours + ":")) + minutes + ":" + seconds;
4545                            if (distance <= 1000) {
4546                                timeForShow = ((hours == null) ? "" : "00:") + "00:00";
4547                            }
4548
4549                            if( window.aysQuizQuestionTimers[quizId][questionID].stopped === true ){
4550                                if (distance <= 1) {
4551                                    container.find('div.ays-quiz-after-timer').slideDown(500);
4552                                    container.find('div.ays-quiz-timer').slideUp(500);
4553                                    container.find('.ays_quiz_timer_container').removeClass("ays-quiz-timer-end-for-required");
4554                                    questionContainer.find('.ays-quiz-answers').css({
4555                                        'pointer-events': 'none'
4556                                    });
4557
4558                                    if( enableClearAnswer ){
4559                                        if (enableArrows) {
4560                                            questionContainer.find('i.ays_clear_answer').attr('disabled', 'disabled');
4561                                        } else {
4562                                            questionContainer.find('input.ays_clear_answer').attr('disabled', 'disabled');
4563                                        }
4564                                    }
4565
4566
4567                                    clearInterval(window.aysQuizQuestionTimers[quizId][questionID].timeout);
4568                                    window.aysQuizQuestionTimers[quizId][questionID].active = false;
4569                                    window.aysQuizQuestionTimers[quizId][questionID].ended = true;
4570                                    window.aysQuizQuestionTimers[quizId][questionID].timer = -1;
4571                                    container.find('.ays_quiz_timer_container').slideUp(500);
4572
4573                                    var qid = checkQuestionTimer( container );
4574                                    if (qid === false) {
4575                                        container.find('input.ays_finish').addClass('ays-quiz-after-timer-end');
4576                                    }
4577                                    return;
4578                                }
4579                            }
4580
4581                            container.find('div.ays-quiz-timer').html(timeForShow);
4582                            container.find('.ays_quiz_timer_container').show(500);
4583
4584                            container.find('div.ays-quiz-timer').show(500);
4585
4586                            if (container.find('.ays-quiz-timer').length === 0) {
4587                                clearInterval(window.aysQuizQuestionTimers[quizId][questionID].timeout);
4588                                window.aysQuizQuestionTimers[quizId][questionID].active = false;
4589                                container.find('.ays_quiz_timer_container').slideUp(500);
4590                            }
4591
4592                            if (distance <= 1) {
4593                                clearInterval(window.aysQuizQuestionTimers[quizId][questionID].timeout);
4594                                window.aysQuizQuestionTimers[quizId][questionID].active = false;
4595                                window.aysQuizQuestionTimers[quizId][questionID].ended = true;
4596
4597                                questionContainer.find('.ays-quiz-answers').css({
4598                                    'pointer-events': 'none'
4599                                })
4600
4601                                if (!container.find('div.ays-quiz-after-timer').hasClass('empty_after_timer_text')) {
4602                                    container.find('.ays_quiz_timer_container').css({
4603                                        'position': 'static',
4604                                        'height': '100%',
4605                                    });
4606
4607                                    container.find('.ays_quiz_timer_container').show();
4608                                    container.find('div.ays-quiz-timer').slideUp();
4609                                    container.find('div.ays-quiz-after-timer').addClass("ays-quiz-timer-end");
4610                                    container.find('.ays_quiz_timer_container').addClass("ays-quiz-timer-end-for-required");
4611                                    container.find('div.ays-quiz-after-timer').slideDown(500);
4612                                } else {
4613                                    container.find('.ays_quiz_timer_container').slideUp(500);
4614                                    container.find('.ays_quiz_timer_container').addClass("ays-quiz-timer-end-for-required");
4615                                }
4616
4617                                questionContainer.find('[name^="ays_questions"]').attr('disabled', 'disabled');
4618                                questionContainer.find('[name^="ays_questions"]').trigger('blur');
4619                                questionContainer.find('select.ays-select').trigger('blur');
4620                                questionContainer.find('select.ays-select').select2('close');
4621
4622                                if( isRequiredQuestion === true ){
4623                                    if( aysThisQuizBullets !== null ) {
4624                                        var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + questionID + '"]');
4625                                        thisBullet.removeClass('ays-has-error');
4626                                    }
4627                                    questionContainer.removeClass('ays-has-error');
4628
4629                                    if( enableNextButton ){
4630                                        if( enableArrows ){
4631                                            questionContainer.find('i.ays_next_arrow').removeAttr('disabled');
4632                                        }else{
4633                                            questionContainer.find('input.ays_next').removeAttr('disabled');
4634                                        }
4635
4636                                        if( myOptions.enable_navigation_bar && myOptions.enable_navigation_bar === 'on' ) {
4637                                            if ( questionContainer.find('input.ays_next').hasClass('ays_finish') ) {
4638                                                aysThisQuizQuestionsFirstPass = false;
4639                                            }
4640
4641                                            if( aysThisQuizQuestionsFirstPass === false ) {
4642                                                var qid = checkQuestionTimer(container);
4643                                                if (qid === false) {
4644                                                    container.find('input.ays_finish').addClass('ays-quiz-after-timer-end');
4645                                                }
4646                                            }
4647                                        }
4648
4649                                    } else {
4650                                        var isNeedToSwitch = true;
4651                                        if( enableArrows ){
4652                                            if (!questionContainer.find('i.ays_next_arrow').hasClass('ays_display_none')){
4653                                                isNeedToSwitch = false;
4654                                            }
4655                                        }else{
4656                                            if (!questionContainer.find('input.ays_next').hasClass('ays_display_none')){
4657                                                isNeedToSwitch = false;
4658                                            }
4659                                        }
4660
4661                                        if( myOptions.enable_navigation_bar && myOptions.enable_navigation_bar === 'on' ) {
4662                                            if ( questionContainer.find('input.ays_next').hasClass('ays_finish') ) {
4663                                                aysThisQuizQuestionsFirstPass = false;
4664                                            }
4665
4666                                            if( aysThisQuizQuestionsFirstPass === false ) {
4667                                                isNeedToSwitch = false;
4668
4669                                                var qid = checkQuestionTimer(container);
4670                                                if (qid !== false) {
4671                                                    container.find('.ays_questions_nav_question[data-id="' + qid + '"]').trigger('click');
4672                                                } else {
4673                                                    container.find('input.ays_finish').addClass('ays-quiz-after-timer-end');
4674                                                    questionContainer.css('display', 'none');
4675                                                    container.find('.ays_quiz_timer_container').slideUp(500);
4676                                                    container.find('input.ays_finish').trigger('click');
4677                                                }
4678                                            }
4679                                        }
4680                                        if( isNeedToSwitch ) {
4681                                            window.aysQuizQuestionTimers[quizId][questionID].switchTimeout = setTimeout(function () {
4682                                                questionContainer.find('input.ays_next').trigger('click');
4683                                            }, 1500 );
4684                                        }
4685                                    }
4686
4687                                    if (enableArrows) {
4688                                        if (!questionContainer.find('i.ays_next_arrow').hasClass('ays_display_none')){
4689                                            questionContainer.find('i.ays_next_arrow').removeAttr('disabled');
4690                                        }
4691                                    } else {
4692                                        if (!questionContainer.find('input.ays_next').hasClass('ays_display_none')){
4693                                            questionContainer.find('input.ays_next').removeAttr('disabled');
4694                                        }
4695                                    }
4696
4697                                    if( enableClearAnswer ){
4698                                        if (enableArrows) {
4699                                            questionContainer.find('i.ays_clear_answer').attr('disabled', 'disabled');
4700                                        } else {
4701                                            questionContainer.find('input.ays_clear_answer').attr('disabled', 'disabled');
4702                                        }
4703                                    }
4704                                }else{
4705                                    if( enableNextButton ){
4706                                        if( enableArrows ){
4707                                            questionContainer.find('i.ays_next_arrow').removeAttr('disabled');
4708                                        }else{
4709                                            questionContainer.find('input.ays_next').removeAttr('disabled' );
4710                                        }
4711
4712                                        if( myOptions.enable_navigation_bar && myOptions.enable_navigation_bar === 'on' ) {
4713                                            if ( questionContainer.find('input.ays_next').hasClass('ays_finish') ) {
4714                                                aysThisQuizQuestionsFirstPass = false;
4715                                            }
4716
4717                                            if( aysThisQuizQuestionsFirstPass === false ) {
4718                                                var qid = checkQuestionTimer(container);
4719                                                if (qid === false) {
4720                                                    container.find('input.ays_finish').addClass('ays-quiz-after-timer-end');
4721                                                }
4722                                            }
4723                                        }
4724
4725                                    } else {
4726                                        var isNeedToSwitch = true;
4727                                        if (enableArrows) {
4728                                            if (!questionContainer.find('i.ays_next_arrow').hasClass('ays_display_none')) {
4729                                                isNeedToSwitch = false;
4730                                            }
4731                                        } else {
4732                                            if (!questionContainer.find('input.ays_next').hasClass('ays_display_none')) {
4733                                                isNeedToSwitch = false;
4734                                            }
4735                                        }
4736
4737                                        if (myOptions.enable_navigation_bar && myOptions.enable_navigation_bar === 'on') {
4738                                            if (questionContainer.find('input.ays_next').hasClass('ays_finish')) {
4739                                                aysThisQuizQuestionsFirstPass = false;
4740                                            }
4741
4742                                            if (aysThisQuizQuestionsFirstPass === false) {
4743                                                isNeedToSwitch = false;
4744
4745                                                var qid = checkQuestionTimer(container);
4746                                                if (qid !== false) {
4747                                                    container.find('.ays_questions_nav_question[data-id="' + qid + '"]').trigger('click');
4748                                                } else {
4749                                                    container.find('input.ays_finish').addClass('ays-quiz-after-timer-end');
4750                                                    questionContainer.css('display', 'none');
4751                                                    container.find('.ays_quiz_timer_container').slideUp(500);
4752                                                    container.find('input.ays_finish').trigger('click');
4753                                                }
4754                                            }
4755                                        }
4756
4757                                        if (isNeedToSwitch) {
4758                                            window.aysQuizQuestionTimers[quizId][questionID].switchTimeout = setTimeout(function () {
4759                                                questionContainer.find('input.ays_next').trigger('click');
4760                                            }, 1500);
4761                                        }
4762                                    }
4763
4764                                    if( myOptions.enable_navigation_bar && myOptions.enable_navigation_bar === 'on' ) {
4765                                        if ( questionContainer.find('input.ays_next').hasClass('ays_finish') ) {
4766                                            aysThisQuizQuestionsFirstPass = false;
4767                                        }
4768
4769                                        if( aysThisQuizQuestionsFirstPass === false ) {
4770                                            var qid = 
4770checkQuestionTimer(container);
4771                                            if (qid === false) {
4772                                                container.find('input.ays_finish').addClass('ays-quiz-after-timer-end');
4773                                            }
4774                                        }
4775                                    }
4776
4777                                    if( enableClearAnswer ){
4778                                        if (enableArrows) {
4779                                            questionContainer.find('i.ays_clear_answer').attr('disabled', 'disabled');
4780                                        } else {
4781                                            questionContainer.find('input.ays_clear_answer').attr('disabled', 'disabled');
4782                                        }
4783                                    }
4784                                }
4785                            }
4786                        }, 1000);
4787                    }
4788                }
4789            }
4790        }
4791
4792        function checkFillInTheBlankQuestion( fillInBlankAnswers, questionId, _this, correct_img_URL_HTML, wrong_img_URL_HTML ){
4793            var trueAnswered = false;
4794
4795            var showOnlyWrongAnswer = (myOptions.show_only_wrong_answer && myOptions.show_only_wrong_answer == "on") ? true : false;
4796
4797            var question_original_html = _this.parents('.step').find('.ays_quiz_question');
4798            var question_original_html_clone = question_original_html.clone(true, true);
4799
4800            question_original_html_clone.find('.ays_buttons_div').remove();
4801
4802            if( fillInBlankAnswers.length > 0 ){
4803
4804                for(var i=0; i < fillInBlankAnswers.length; i++){
4805                    var userAnsweredText = fillInBlankAnswers.eq(i).val().trim();
4806                    var answerID = fillInBlankAnswers.eq(i).attr('data-answer-id');
4807                    var questionId = fillInBlankAnswers.eq(i).parents('.step').data('questionId');
4808
4809                    var trueAnswered = false;
4810
4811                    // Enable case sensitive text
4812                    var enable_case_sensitive_text = (myQuizOptions[questionId].enable_case_sensitive_text && myQuizOptions[questionId].enable_case_sensitive_text != "") ? myQuizOptions[questionId].enable_case_sensitive_text : false;
4813
4814                    var thisQuestionCorrectAnswer_Arr = myQuizOptions[questionId].question_answer.length > 0 ? "" : myQuizOptions[questionId].question_answer;
4815
4816                    var thisQuestionCorrectAnswer = thisQuestionCorrectAnswer_Arr[answerID];
4817                    var thisQuestionAnswer = thisQuestionCorrectAnswer.toLowerCase();
4818
4819                    if ( enable_case_sensitive_text ) {
4820                        thisQuestionAnswer = thisQuestionCorrectAnswer;
4821                    }
4822
4823                    thisQuestionAnswer = aysEscapeHtmlDecode( thisQuestionAnswer ).aysStripSlashes().split('%%%');
4824                    for(var i_answer = 0; i_answer < thisQuestionAnswer.length; i_answer++){
4825                        if ( enable_case_sensitive_text ) {
4826                            if(userAnsweredText == thisQuestionAnswer[i_answer].trim()){
4827                                trueAnswered = true;
4828                                break;
4829                            }
4830                        } else {
4831                            if(userAnsweredText.toLowerCase() == thisQuestionAnswer[i_answer].trim()){
4832                                trueAnswered = true;
4833                                break;
4834                            }
4835                        }
4836                    }
4837
4838                    if(trueAnswered){
4839                        fillInBlankAnswers.eq(i).next().val(1);
4840                    }else{
4841                        fillInBlankAnswers.eq(i).next().val(0);
4842                        if(thisQuestionCorrectAnswer == ''){
4843                            fillInBlankAnswers.eq(i).attr('chishtpatasxan', '-');
4844                        }else{
4845                            fillInBlankAnswers.eq(i).attr('chishtpatasxan', thisQuestionCorrectAnswer);
4846                        }
4847                    }
4848
4849                    fillInBlankAnswers.eq(i).removeAttr('disabled');
4850
4851                }
4852
4853                var if_fill_in_blank_empty = false;
4854                var fill_in_blank_empty_arr = new Array();
4855                var is_user_answer_correct = true;
4856                var fillInBlankAnswers_last = false;
4857                for (var i = 0; i < fillInBlankAnswers.length; i++) {
4858                    var fill_in_blank_answer = $( fillInBlankAnswers[i] );
4859                    // fill_in_blank_answer.next().remove();
4860                    // fill_in_blank_answer.next().next().remove();
4861                    fill_in_blank_answer.attr('disabled', 'disabled');
4862                    var fillInBlankAnswers_last = false;
4863                    if( (fillInBlankAnswers.length - 1) == i ){
4864                        var fillInBlankAnswers_last = true;
4865                    }
4866
4867                    if( fill_in_blank_answer.val() == '' ){
4868                        fill_in_blank_empty_arr.push('empty');
4869                    }
4870
4871                    if( fill_in_blank_empty_arr.length == fillInBlankAnswers.length ){
4872                        if_fill_in_blank_empty = true;
4873                    }
4874
4875                    if(if_fill_in_blank_empty && fillInBlankAnswers_last){
4876                        if(showOnlyWrongAnswer === false){
4877                            // var rightAnswerText = '<div class="ays-text-right-answer">';
4878                            // var thisQuestionAnswer = fill_in_blank_answer.attr('chishtpatasxan');
4879                            // if(typeof thisQuestionAnswer != 'undefined'){
4880                            //     thisQuestionAnswer = aysEscapeHtmlDecode( thisQuestionAnswer ).aysStripSlashes();
4881                            //     thisQuestionAnswer = thisQuestionAnswer.split('%%%');
4882                            // }else{
4883                            //     thisQuestionAnswer = [''];
4884                            // }
4885                            // rightAnswerText += thisQuestionAnswer[0].trim();
4886
4887                            // rightAnswerText += '</div>';
4888                            // if(fill_in_blank_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').length == 0){
4889                            //     fill_in_blank_answer.parents('.ays-quiz-answers').append(rightAnswerText);
4890                            // }
4891                            // fill_in_blank_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({
4892                            //     'display': 'block'
4893                            // });
4894                        }
4895                        // fill_in_blank_answer.css('background-color', 'rgba(243,134,129,0.4)');
4896                        // fill_in_blank_answer.parents('.ays-abs-fs').find('.ays_quiz_question_text_conteiner').addClass('ays_display_none');
4897
4898                        // if (wrong_img_URL_HTML != "") {
4899                        //     var if_img_exists = fill_in_blank_answer.parent().find(".ays-quiz-check-button-right-wrong-icon");
4900                        //     if ( if_img_exists.length <= 0 ) {
4901                        //         fill_in_blank_answer.parent().append(wrong_img_URL_HTML);
4902                        //     }
4903                        // }
4904
4905                        // var _fill_in_blank_answer_parent = fill_in_blank_answer.parents('.ays-abs-fs');
4906
4907                        // _fill_in_blank_answer_parent.html(fieldset_html);
4908                        // _fill_in_blank_answer_parent.find('.ays_fieldset').append(ays_quiz_question_html);
4909                        // // _fill_in_blank_answer_parent.find('.ays_fieldset').append(fill_in_blank_answer);
4910                        // _fill_in_blank_answer_parent.find('.ays_fieldset').append(ays_quiz_question_img_html);
4911                        // // _fill_in_blank_answer_parent.find('.ays_fieldset').append(fill_in_blank_answer.parents('.ays-quiz-answers'));
4912                        
4913                        // for (var j = 0; j < question_parts_arr.length; j++) {
4914                        //     _fill_in_blank_answer_parent.find('.ays_fieldset').append( question_parts_arr[j] );
4915                        // }
4916
4917                        // _fill_in_blank_answer_parent.parents('.ays-abs-fs').css({
4918                        //     'padding': '7px'
4919                        // });
4920                    }else{
4921                        if(parseInt(fill_in_blank_answer.next().val()) == 1){
4922                            fill_in_blank_answer.css('background-color', 'rgba(39,174,96,0.5)');
4923                            fill_in_blank_answer.css('width', 'auto');
4924
4925                        }else{
4926                            fill_in_blank_answer.css('background-color', 'rgba(243,134,129,0.4)');
4927                            fill_in_blank_answer.css('width', 'auto');
4928
4929                            if( is_user_answer_correct ){
4930                                is_user_answer_correct = false;
4931                            }
4932
4933                            if(showOnlyWrongAnswer === false){
4934                                // var rightAnswerText = '<div class="ays-text-right-answer">';
4935                                // var thisQuestionAnswer = fill_in_blank_answer.attr('chishtpatasxan');
4936                                // if(typeof thisQuestionAnswer != 'undefined'){
4937                                //     thisQuestionAnswer = aysEscapeHtmlDecode( thisQuestionAnswer ).aysStripSlashes();
4938                                //     thisQuestionAnswer = thisQuestionAnswer.split('%%%');
4939                                // }else{
4940                                //     thisQuestionAnswer = [''];
4941                                // }
4942                                // rightAnswerText += thisQuestionAnswer[0].trim();
4943
4944                                // rightAnswerText += '</div>';
4945                                // if(fill_in_blank_answer.parents('.ays_quiz_question').find('.ays-text-right-answer').length == 0){
4946                                //     fill_in_blank_answer.parents('.ays_quiz_question').append(rightAnswerText);
4947                                // }
4948                                // fill_in_blank_answer.parents('.ays-quiz-answers').find('.ays-text-right-answer').css({
4949                                //     'display': 'block'
4950                                // });
4951                                fill_in_blank_answer.parents('.ays-abs-fs').find('.ays_quiz_question_text_conteiner').addClass('ays_display_none');
4952                            }
4953                        }
4954                    }
4955
4956                    if(!is_user_answer_correct){ // tid=29147
4957                        trueAnswered = false;
4958                    }
4959                }
4960
4961                if( fillInBlankAnswers_last ){
4962                    if( is_user_answer_correct === true ){
4963                        // answerIsRight = true;
4964                        trueAnswered = true;
4965                        if (correct_img_URL_HTML != "") {
4966                            var if_img_exists = $( fillInBlankAnswers[0] ).parents('.ays_quiz_question').find(".ays-quiz-check-button-right-wrong-icon");
4967                            if ( if_img_exists.length <= 0 ) {
4968                                $( fillInBlankAnswers[0] ).parent().append(correct_img_URL_HTML);
4969                            }
4970                        }
4971                    } else {
4972                        if (wrong_img_URL_HTML != "") {
4973                            var if_img_exists = $( fillInBlankAnswers[0] ).parents('.ays_quiz_question').find(".ays-quiz-check-button-right-wrong-icon");
4974                            if ( if_img_exists.length <= 0 ) {
4975                                $( fillInBlankAnswers[0] ).parent().append(wrong_img_URL_HTML);
4976                            }
4977                        }
4978
4979                        var thisAnswerOptions = myQuizOptions[questionId];
4980                        var thisQuestionAnswer = (typeof myQuizOptions[questionId].question_answer != 'undefined') ? myQuizOptions[questionId].question_answer : new Array();
4981
4982                        var rightAnswerTextStart = "";
4983                        var rightAnswerTextEnd = "";
4984                        rightAnswerTextStart += '<div class="ays-quiz-answers" style="pointer-events: none;">';
4985                            rightAnswerTextStart += '<div class="ays-text-right-answer" style="display: block;">';
4986
4987                            rightAnswerTextEnd += '<div';
4988                        rightAnswerTextEnd += '<div';
4989
4990                        if(typeof thisQuestionAnswer != 'undefined'){
4991                            var only_question_original_html_clone = $( rightAnswerTextStart + question_original_html_clone.html() + rightAnswerTextEnd);
4992
4993                            for( var answerId in thisQuestionAnswer ) {
4994
4995                                var rightAnswerText = aysEscapeHtmlDecode( thisQuestionAnswer[answerId] ).aysStripSlashes();
4996                                rightAnswerText = rightAnswerText.split('%%%');
4997                                rightAnswerText = rightAnswerText[0].trim();
4998
4999                                var rightAnswerHTML = $('<strong class="ays-quiz-fill-in-blank-input-right-wrong-answer">'+ rightAnswerText +'</strong>');
5000
5001                                var fill_in_blank_answer_input = only_question_original_html_clone.find('.ays-quiz-fill-in-blank-input[data-answer-id="'+ answerId +'"]');
5002
5003                                fill_in_blank_answer_input.replaceWith( rightAnswerHTML );
5004                            }
5005
5006                            fill_in_blank_answer.parents('.ays_quiz_question').append(only_question_original_html_clone);
5007                            fill_in_blank_answer.parents('.ays_quiz_question').find('script').remove();
5008
5009                        }
5010                    }
5011                }
5012            }
5013
5014            return trueAnswered;
5015        }
5016
5017        function checkCheckboxRadioQuestion(e, _this) {
5018
5019            var quizContainer = _this.parents('.ays-quiz-container');
5020            var quizId = _this.parents('.ays-quiz-container').find('input[name="ays_quiz_id"]').val();
5021
5022            var parentStep = _this.parents('.step');
5023            var questionID = parentStep.data('questionId');
5024            var questionType = parentStep.attr('data-type');
5025            var answerId = _this.val();
5026
5027            var quizForm = quizContainer.find('form.ays-quiz-form');
5028
5029            var checkboxQuestionTypeFlag = true;
5030            if( questionType == 'checkbox' && quizForm.hasClass('enable_correction') ){
5031                if( !_this.hasClass('ays-quiz-check-button-clicked') ){
5032                    checkboxQuestionTypeFlag = false;
5033                }
5034            }
5035
5036            if( typeof questionID != "undefined" && questionID !== null && quizForm.hasClass('enable_correction') ){
5037
5038                var thisQuestionCorrectAnswer = myQuizOptions[questionID].question_answer.length <= 0 ? array() : myQuizOptions[questionID].question_answer;
5039                var ifCorrectAnswer = thisQuestionCorrectAnswer[answerId] == '' ? '' : thisQuestionCorrectAnswer[answerId];
5040                if( typeof ifCorrectAnswer != "undefined" ){
5041                    _this.parents('.ays-field').find('input[name="ays_answer_
5041correct[]"]').val(ifCorrectAnswer);
5042
5043                    if( ifCorrectAnswer == '0' && questionType === 'checkbox' && quizForm.hasClass('enable_correction') ){
5044                        if( _this.hasClass('ays-quiz-check-button-clicked') ){
5045                            
5046                            if( _this.parents('.ays-field').find('input:checked').length == 0 ){
5047                                _this.parents('.ays-field').css({
5048                                    'pointer-events': 'none'
5049                                });
5050                                return false;
5051                            }
5052                        }
5053                    }
5054
5055                    if( ifCorrectAnswer == '0' && questionType === 'radio' && _this.parents('form.ays-quiz-form').hasClass('enable_correction') ){
5056
5057                        for (var question_answer_ID in thisQuestionCorrectAnswer) {
5058                            var UserAnswered_true_or_false = thisQuestionCorrectAnswer[question_answer_ID];
5059                            parentStep.find('.ays-quiz-answers .ays-field input[value="'+ question_answer_ID +'"]').prev().val(UserAnswered_true_or_false);
5060                        }
5061                    }
5062                }
5063            }
5064
5065            if(typeof myOptions != 'undefined'){
5066                var isRequiredQuestion = (myOptions.make_questions_required && myOptions.make_questions_required == "on") ? true : false;
5067                var isRequiredQuestion2 = true;
5068                if(isRequiredQuestion2 === true){
5069                    if(_this.attr('type') === 'radio' || _this.attr('type') === 'checkbox'){
5070                        if(_this.parents('div[data-question-id]').find('input[name^="ays_questions"]:checked').length != 0){
5071                            if ( _this.attr('type') === 'checkbox' ) {
5072                                var checkedMinSelCount = aysCheckMinimumCountCheckbox( _this.parents('div[data-question-id]'), myQuizOptions );
5073
5074                                if( checkedMinSelCount == true ){
5075                                    if (!_this.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
5076                                        _this.parents('div[data-question-id]').find('input.ays_next').removeAttr('disabled');
5077                                        _this.parents('div[data-question-id]').find('input.ays_early_finish').removeAttr('disabled');
5078
5079                                    }else if(!_this.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5080                                        _this.parents('div[data-question-id]').find('i.ays_next_arrow').removeAttr('disabled');
5081                                        _this.parents('div[data-question-id]').find('i.ays_early_finish').removeAttr('disabled');
5082                                    }
5083                                }else{
5084                                    if (!_this.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
5085
5086                                        _this.parents('div[data-question-id]').find('input.ays_next').attr('disabled', 'disabled');
5087                                        _this.parents('div[data-question-id]').find('input.ays_early_finish').attr('disabled', 'disabled');
5088
5089                                    }else if(!_this.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5090                                        _this.parents('div[data-question-id]').find('i.ays_next_arrow').attr('disabled', 'disabled');
5091                                        _this.parents('div[data-question-id]').find('i.ays_early_finish').attr('disabled', 'disabled');
5092                                    }
5093                                }
5094                            } else {
5095                                if (!_this.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
5096                                    _this.parents('div[data-question-id]').find('input.ays_next').removeAttr('disabled');
5097                                    _this.parents('div[data-question-id]').find('input.ays_early_finish').removeAttr('disabled');
5098
5099                                }else if(!_this.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5100                                    _this.parents('div[data-question-id]').find('i.ays_next_arrow').removeAttr('disabled');
5101                                    _this.parents('div[data-question-id]').find('i.ays_early_finish').removeAttr('disabled');
5102                                }
5103                            }
5104                        }else{
5105                            if( isRequiredQuestion ){
5106                                if (!_this.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none')){
5107
5108                                    _this.parents('div[data-question-id]').find('input.ays_next').attr('disabled', 'disabled');
5109                                    _this.parents('div[data-question-id]').find('input.ays_early_finish').attr('disabled', 'disabled');
5110
5111                                }else if(!_this.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5112                                    _this.parents('div[data-question-id]').find('i.ays_next_arrow').attr('disabled', 'disabled');
5113                                    _this.parents('div[data-question-id]').find('i.ays_early_finish').attr('disabled', 'disabled');
5114                                }
5115                            }
5116                        }
5117                    }
5118                }
5119            }
5120
5121            var isRequiredQuestion = myOptions.make_questions_required && myOptions.make_questions_required === "on";
5122
5123            if(_this.parents('.step').hasClass('not_influence_to_score')){
5124                if(_this.attr('type') === 'radio') {
5125                    _this.parents('.ays-quiz-answers').find('.checked_answer_div').removeClass('checked_answer_div');
5126                    _this.parents('.ays-field').addClass('checked_answer_div');
5127                }
5128                if(_this.attr('type') === 'checkbox') {
5129                    if(!_this.parents('.ays-field').hasClass('checked_answer_div')){
5130                        _this.parents('.ays-field').addClass('checked_answer_div');
5131                    }else{
5132                        _this.parents('.ays-field').removeClass('checked_answer_div');
5133                    }
5134                } 
5135                var checked_inputs = _this.parents().eq(1).find('input:checked');
5136                if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') && checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5137                    if (checked_inputs.attr('type') === 'radio') {
5138                        checked_inputs.parents('div[data-question-id]').find('.ays_next').trigger('click');                    
5139                    }
5140                }
5141                if (_this.parents().eq(4).hasClass('enable_correction')) {                    
5142                    if (checked_inputs.attr('type') === "radio") {
5143                        _this.parents('div[data-question-id]').find('input[name^="ays_questions"]').attr('disabled', true);
5144                        _this.parents('div[data-question-id]').find('input[name^="ays_questions"]').off('change');
5145                    } else if (checked_inputs.attr('type') === "checkbox") {
5146                        _this.attr('disabled', true);
5147                        _this.off('change');
5148                    }
5149                }
5150                return false;
5151            }
5152            if (_this.parents().eq(4).hasClass('enable_correction') && checkboxQuestionTypeFlag) {
5153                var right_answer_sound = quizContainer.find('.ays_quiz_right_ans_sound').get(0);
5154                var wrong_answer_sound = quizContainer.find('.ays_quiz_wrong_ans_sound').get(0);
5155                var finishAfterWrongAnswer = (myOptions.finish_after_wrong_answer && myOptions.finish_after_wrong_answer == "on") ? true : false;
5156                var showOnlyWrongAnswer = (myOptions.show_only_wrong_answer && myOptions.show_only_wrong_answer == "on") ? true : false;
5157                var explanationTime = myOptions.explanation_time && myOptions.explanation_time != "" ? parseInt(myOptions.explanation_time) : 4;
5158                var showExplanationOn = (myOptions.show_questions_explanation && myOptions.show_questions_explanation != "") ? myOptions.show_questions_explanation : "on_results_page";
5159                var next_sibilings_count = quizContainer.find('.ays_question_count_per_page').val();
5160                var enableNextButton = (myOptions.enable_next_button && myOptions.enable_next_button == 'on') ? true : false;
5161                var thankYouStep = quizContainer.find('div.step.ays_thank_you_fs');
5162                var infoFormLast = thankYouStep.prev().find('div.information_form');
5163                // Display all questions on one page
5164                myOptions.quiz_display_all_questions = ( myOptions.quiz_display_all_questions ) ? myOptions.quiz_display_all_questions : 'off';
5165                var quiz_display_all_questions = (myOptions.quiz_display_all_questions && myOptions.quiz_display_all_questions == "on") ? true : false;
5166
5167                var disableQuestions = false;
5168                if( parseInt( next_sibilings_count ) > 0 || quiz_display_all_questions == true ){
5169                    disableQuestions = true;
5170                }
5171
5172                myOptions.quiz_waiting_time = ( myOptions.quiz_waiting_time ) ? myOptions.quiz_waiting_time : "off";
5173                var quizWaitingTime = (myOptions.quiz_waiting_time && myOptions.quiz_waiting_time == "on") ? true : false;
5174
5175                myOptions.enable_next_button = ( myOptions.enable_next_button ) ? myOptions.enable_next_button : "off";
5176                var quizNextButton = (myOptions.enable_next_button && myOptions.enable_next_button == "on") ? true : false;
5177
5178                if ( quizWaitingTime && !quizNextButton ) {
5179                    explanationTime += 2;
5180                }
5181
5182                var quizWaitingCountDownDate = new Date().getTime() + (explanationTime * 1000);
5183
5184                if (_this.parents().eq(1).find('input[name="ays_answer_
5184correct[]"]').length !== 0) {
5185                    var checked_inputs = _this.parents().eq(1).find('input:checked');
5186                    if (checked_inputs.attr('type') === "radio") {
5187                        checked_inputs.nextAll().addClass('answered');
5188                        checked_inputs.parent().addClass('checked_answer_div');
5189                        if (checked_inputs.prev().val() == 1){
5190                            checked_inputs.nextAll().addClass('correct')
5191                            checked_inputs.parent().addClass('correct_div');
5192
5193                            if( aysThisQuizBullets !== null ){
5194                                var thisQuestionID = _this.parents('div[data-question-id]').data('questionId');
5195                                var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
5196                                thisBullet.attr('disabled', 'disabled');
5197                                thisBullet.addClass('ays_quiz_correct_answer');
5198                                if (!thisBullet.parent().hasClass('ays-quiz-questions-nav-item-last-question')) {
5199                                    thisBullet.parent().addClass('ays_quiz_checked_answer_div');
5200                                }
5201                            }
5202                        }else{
5203                            checked_inputs.nextAll().addClass('wrong');
5204                            checked_inputs.parent().addClass('wrong_div');
5205
5206                            if( aysThisQuizBullets !== null ){
5207                                var thisQuestionID = _this.parents('div[data-question-id]').data('questionId');
5208                                var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
5209                                thisBullet.attr('disabled', 'disabled');
5210                                thisBullet.addClass('ays_quiz_wrong_answer');
5211                                if (!thisBullet.parent().hasClass('ays-quiz-questions-nav-item-last-question')) {
5212                                    thisBullet.parent().addClass('ays_quiz_checked_answer_div');
5213                                }
5214                            }
5215                        }
5216
5217                        if (checked_inputs.prev().val() == 1) {
5218                            _this.parents('.ays-field').addClass('correct_div checked_answer_div');
5219                            _this.next('label').addClass('correct answered');
5220
5221                            if(myOptions.answers_rw_texts && (myOptions.answers_rw_texts == 'on_passing' || myOptions.answers_rw_texts == 'on_both' || myOptions.answers_rw_texts == 'disable' || myOptions.answers_rw_texts == 'on_results_page')){
5222                                if(! _this.parents('.step').hasClass('not_influence_to_score')){
5223                                    _this.parents().eq(3).find('.right_answer_text').slideDown(250);
5224                                }
5225                                explanationTimeout = setTimeout(function(){
5226                                    if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
5227                                        checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5228                                        if( quiz_display_all_questions && isRequiredQuestion && !enableNextButton ) {
5229                                            var existsEmtpyQuestions = ays_quiz_is_question_empty( quizContainer.find('div[data-question-id]') );
5230                                            if ( existsEmtpyQuestions ) {
5231                                                if(infoFormLast.length == 0){
5232                                                    quizContainer.find('input.ays_finish').trigger('click');
5233                                                } else {
5234                                                    quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
5235                                                }
5236                                            }
5237                                        } else {
5238                                            checked_inputs.parents('div[data-question-id]').find('.ays_
5238next').trigger('click');
5239                                        }
5240                                    } else if( quiz_display_all_questions && isRequiredQuestion && !enableNextButton ) {
5241                                        var existsEmtpyQuestions = ays_quiz_is_question_empty( quizContainer.find('div[data-question-id]') );
5242                                        if ( existsEmtpyQuestions ) {
5243                                            if(infoFormLast.length == 0){
5244                                                quizContainer.find('input.ays_finish').trigger('click');
5245                                            } else {
5246                                                quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
5247                                            }
5248                                        }
5249                                    }
5250
5251                                }, explanationTime * 1000);
5252                                if (quizWaitingTime && !quizNextButton) {
5253                                    window.countdownTimeForShowInterval = setInterval(function () {
5254                                        countdownTimeForShow( parentStep, quizWaitingCountDownDate );
5255                                    }, 1000);
5256                                }
5257                            }else{
5258                                explanationTimeout = setTimeout(function(){
5259                                    if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
5260                                        checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5261                                        if( quiz_display_all_questions && isRequiredQuestion && !enableNextButton ) {
5262                                            var existsEmtpyQuestions = ays_quiz_is_question_empty( quizContainer.find('div[data-question-id]') );
5263                                            if ( existsEmtpyQuestions ) {
5264                                                if(infoFormLast.length == 0){
5265                                                    quizContainer.find('input.ays_finish').trigger('click');
5266                                                } else {
5267                                                    quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
5268                                                }
5269                                            }
5270                                        } else {
5271                                            checked_inputs.parents('div[data-question-id]').find('.ays_next').trigger('click');
5272                                        }
5273                                    } else if( quiz_display_all_questions && isRequiredQuestion && !enableNextButton ) {
5274                                        var existsEmtpyQuestions = ays_quiz_is_question_empty( quizContainer.find('div[data-question-id]') );
5275                                        if ( existsEmtpyQuestions ) {
5276                                            if(infoFormLast.length == 0){
5277                                                quizContainer.find('input.ays_finish').trigger('click');
5278                                            } else {
5279                                                quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
5280                                            }
5281                                        }
5282                                    }
5283                                }, explanationTime * 1000);
5284                                if (quizWaitingTime && !quizNextButton) {
5285                                    window.countdownTimeForShowInterval = setInterval(function () {
5286                                        countdownTimeForShow( parentStep, quizWaitingCountDownDate );
5287                                    }, 1000);
5288                                }
5289                            }
5290                            if((right_answer_sound)){
5291                                resetPlaying([right_answer_sound, wrong_answer_sound]);
5292                                setTimeout(function(){
5293                                    right_answer_sound.play();
5294                                }, 10);
5295                            }
5296                        }
5297                        else {
5298                            if(showOnlyWrongAnswer === false){
5299                                _this.parents('.ays-quiz-answers').find('input[name="ays_answer_
5299correct[]"][value="1"]').parent().addClass('correct_div checked_answer_div');
5300                                _this.parents('.ays-quiz-answers').find('input[name="ays_answer_correct[]"][value="1"]').nextAll().addClass('correct answered');
5301                                _this.parents('.ays-field').addClass('wrong_div');
5302                            }
5303
5304                            if(myOptions.answers_rw_texts && (myOptions.answers_rw_texts == 'on_passing' || myOptions.answers_rw_texts == 'on_both' || myOptions.answers_rw_texts == 'disable' || myOptions.answers_rw_texts == 'on_results_page')){
5305                                if(! _this.parents('.step').hasClass('not_influence_to_score')){
5306                                    _this.parents().eq(3).find('.wrong_answer_text').slideDown(250);
5307                                }
5308                                if(finishAfterWrongAnswer){
5309                                    checked_inputs.parents('div[data-question-id]').find('.ays_next').attr('disabled', 'disabled');
5310                                    checked_inputs.parents('div[data-question-id]').find('.ays_early_finish').attr('disabled', 'disabled');
5311                                    checked_inputs.parents('div[data-question-id]').find('.ays_previous').attr('disabled', 'disabled');
5312                                    if( disableQuestions ){
5313                                        quizContainer.find('div[data-question-id]').css('pointer-events', 'none');
5314                                    }
5315                                }
5316                                explanationTimeout = setTimeout(function(){
5317                                    if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
5318                                        checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5319                                        if(finishAfterWrongAnswer){
5320                                            window.aysEarlyFinishConfirmBox[ quizId ] = true;
5321                                            goToLastPage(e);
5322                                        } else if( quiz_display_all_questions && isRequiredQuestion && !enableNextButton ) {
5323                                                var existsEmtpyQuestions = ays_quiz_is_question_empty( quizContainer.find('div[data-question-id]') );
5324                                                if ( existsEmtpyQuestions ) {
5325                                                    if(infoFormLast.length == 0){
5326                                                        quizContainer.find('input.ays_finish').trigger('click');
5327                                                    } else {
5328                                                        quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
5329                                                    }
5330                                                }
5331                                        } else{
5332                                            if ( isRequiredQuestion ) {
5333                                                var existsEmtpyQuestions = ays_quiz_is_question_empty( checked_inputs.parents('div[data-question-id]') );
5334                                                if ( existsEmtpyQuestions ) {
5335                                                    checked_inputs.parents('div[data-question-id]').find('.ays_next').trigger('click');
5336                                                }
5337                                            } else {
5338                                                checked_inputs.parents('div[data-question-id]').find('.ays_next').trigger('click');
5339                                            }
5340                                        }
5341                                    }else{
5342                                        if(finishAfterWrongAnswer){
5343                                            window.aysEarlyFinishConfirmBox[ quizId ] = true;
5344                                            goToLastPage(e);
5345                                        } 
5346                                        else if( quiz_display_all_questions && isRequiredQuestion && !enableNextButton ) {
5347                                            var existsEmtpyQuestions = ays_quiz_is_question_empty( quizContainer.find('div[data-question-id]') );
5348                                            if ( existsEmtpyQuestions ) {
5349                                                if(infoFormLast.length == 0){
5350                                                    quizContainer.find('input.ays_finish').trigger('click');
5351                                                } else {
5352                                                    quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
5353                                                }
5354                                            }
5355                                        }
5356                                    }
5357                                }, explanationTime * 1000);
5358                                if (quizWaitingTime && !quizNextButton) {
5359                                    window.countdownTimeForShowInterval = setInterval(function () {
5360                                        countdownTimeForShow( parentStep, quizWaitingCountDownDate );
5361                                    }, 1000);
5362                                }
5363                            }else{
5364                                if(finishAfterWrongAnswer){
5365                                    if( disableQuestions ){
5366                                        quizContainer.find('div[data-question-id]').css('pointer-events', 'n
5366one');
5367                                    }
5368                                }
5369
5370                                if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
5371                                    checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5372                                    if(finishAfterWrongAnswer){
5373                                        window.aysEarlyFinishConfirmBox[ quizId ] = true;
5374                                        goToLastPage(e);
5375                                    } else if( quiz_display_all_questions && isRequiredQuestion && !enableNextButton ) {
5376                                        explanationTimeout = setTimeout(function(){
5377                                            var existsEmtpyQuestions = ays_quiz_is_question_empty( quizContainer.find('div[data-question-id]') );
5378                                            if ( existsEmtpyQuestions ) {
5379                                                if(infoFormLast.length == 0){
5380                                                    quizContainer.find('input.ays_finish').trigger('click');
5381                                                } else {
5382                                                    quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
5383                                                }
5384                                            }
5385                                        }, explanationTime * 1000);
5386                                        if (quizWaitingTime && !quizNextButton) {
5387                                            window.countdownTimeForShowInterval = setInterval(function () {
5388                                                countdownTimeForShow( parentStep, quizWaitingCountDownDate );
5389                                            }, 1000);
5390                                        }
5391                                    } else{
5392                                        explanationTimeout = setTimeout(function(){
5393                                            if ( isRequiredQuestion ) {
5394                                                var existsEmtpyQuestions = ays_quiz_is_question_empty( checked_inputs.parents('div[data-question-id]') );
5395                                                if ( existsEmtpyQuestions ) {
5396                                                    checked_inputs.parents('div[data-question-id]').find('.ays_next').trigger('click');
5397                                                }
5398                                            } else {
5399                                                checked_inputs.parents('div[data-question-id]').find('.ays_next').trigger('click');
5400                                            }
5401                                        }, explanationTime * 1000);
5402                                    }
5403                                }else{
5404                                    if(finishAfterWrongAnswer){
5405                                        window.aysEarlyFinishConfirmBox[ quizId ] = true;
5406                                        goToLastPage(e);
5407                                    } 
5408                                    else if( quiz_display_all_questions && isRequiredQuestion && !enableNextButton ) {
5409                                        explanationTimeout = setTimeout(function(){
5410                                            var existsEmtpyQuestions = ays_quiz_is_question_empty( quizContainer.find('div[data-question-id]') );
5411                                            if ( existsEmtpyQuestions ) {
5412                                                if(infoFormLast.length == 0){
5413                                                    quizContainer.find('input.ays_finish').trigger('click');
5414                                                } else {
5415                                                    quizContainer.find('div[data-question-id] input.ays_next.action-button').trigger('click');
5416                                                }
5417                                            }
5418                                        }, explanationTime * 1000);
5419                                        if (quizWaitingTime && !quizNextButton) {
5420                                            window.countdownTimeForShowInterval = setInterval(function () {
5421                                                countdownTimeForShow( parentStep, quizWaitingCountDownDate );
5422                                            }, 1000);
5423                                        }
5424                                    }
5425                                }
5426                            }
5427                            if((wrong_answer_sound)){
5428                                resetPlaying([right_answer_sound, wrong_answer_sound]);
5429                                setTimeout(function(){
5430                                    wrong_answer_sound.play();
5431                                }, 10);
5432                            }
5433                            if(finishAfterWrongAnswer){
5434                                if( aysThisQuizBullets !== null ){
5435                                    aysThisQuizBullets.baseElement.find('.ays_questions_nav_question').each(function(){
5436                                        var thisBullet = $(this);
5437                                        thisBullet.attr('disabled', 'disabled');
5438                                    });
5439                                }
5440                            }
5441                        }
5442
5443                        if(showExplanationOn == 'on_passing' || showExplanationOn == 'on_both'){
5444                            if(! _this.parents('.step').hasClass('not_influence_to_score')){
5445                                _this.parents().eq(3).find('.ays_questtion_explanation').slideDown(250);
5446                            }
5447                        }
5448                        _this.parents('div[data-question-id]').find('input[name^="ays_questions"]').attr('disabled', true);
5449                        _this.parents('div[data-question-id]').find('input[name^="ays_questions"]').off('change');
5450                        _this.parents('div[data-question-id]').find('.ays-field').css({
5451                            'pointer-events': 'none'
5452                        });
5453
5454                    }else if(checked_inputs.attr('type') === "checkbox"){
5455                        checked_inputs = _this;
5456                        if( _this.parents().eq(1).find('input:checked').length > 0 ){
5457                            if( aysThisQuizBullets !== null ){
5458                                var thisQuestionID = _this.parents('div[data-question-id]').data('questionId');
5459                                var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
5460                                thisBullet.parents('.ays-quiz-questions-nav-item').addClass('ays-quiz-questions-nav-item-answered');
5461                            }
5462                        }
5463
5464                        if (checked_inputs.length === 1) {
5465                            checked_inputs.parent().addClass('checked_answer_div');
5466                            if(checked_inputs.prev().val() == 1){
5467                                if((right_answer_sound)){
5468                                    resetPlaying([right_answer_sound, wrong_answer_sound]);
5469                                    setTimeout(function(){
5470                                        right_answer_sound.play();
5471                                    }, 10);
5472                                }
5473                                checked_inputs.parents('.ays-field').addClass('correct_div checked_answer_div');
5474                                checked_inputs.nextAll().addClass('correct answered');
5475                            }else{
5476                                if((wrong_answer_sound)){
5477                                    resetPlaying([right_answer_sound, wrong_answer_sound]);
5478                                    setTimeout(function(){
5479                                        wrong_answer_sound.play();
5480                                    }, 10);
5481                                }
5482                                if(finishAfterWrongAnswer){
5483                                    window.aysEarlyFinishConfirmBox[ quizId ] = true;
5484                                    goToLastPage(e);
5485                                    if( disableQuestions ){
5486                                        quizContainer.find('div[data-question-id]').css('pointer-events', 'none');
5487                                    }
5488                                    if( aysThisQuizBullets !== null ){
5489                                        aysThisQuizBullets.baseElement.find('.ays_questions_nav_question').each(function(){
5490                                            var thisBullet = $(this);
5491                                            thisBullet.attr('disabled', 'disabled');
5492                                        });
5493                                    }
5494                                }
5495                                checked_inputs.parent().addClass('wrong_div');
5496                                checked_inputs.nextAll().addClass('wrong answered');
5497                            }
5498                        }else{
5499                            for (var i = 0; i < checked_inputs.length; i++) {
5500                                if(checked_inputs.eq(i).prev().val() == 1){
5501                                    if((right_answer_sound)){
5502                                        resetPlaying([right_answer_sound, wrong_answer_sound]);
5503                                        setTimeout(function(){
5504                                            right_answer_sound.play();
5505                                        }, 10);
5506                                    }
5507                                    checked_inputs.eq(i).nextAll().addClass('correct answered');
5508                                    checked_inputs.eq(i).parent().addClass('correct_div');
5509                                    checked_inputs.eq(i).parent().addClass('checked_answer_div');
5510                                }else{
5511                                    if((wrong_answer_sound)){
5512                                        resetPlaying([right_answer_sound, wrong_answer_sound]);
5513                                        setTimeout(function(){
5514                                            wrong_answer_sound.play();
5515                                        }, 10);
5516                                    }
5517                                    if(finishAfterWrongAnswer){
5518                                        window.aysEarlyFinishConfirmBox[ quizId ] = true;
5519                                        goToLastPage(e);
5520                                        if( disableQuestions ){
5521                                            quizContainer.find('div[data-question-id]').css('pointer-events', 'n
5521one');
5522                                        }
5523                                    }
5524                                    checked_inputs.eq(i).parent().addClass('checked_answer_div');
5525                                    checked_inputs.eq(i).nextAll().addClass('wrong answered');
5526                                    checked_inputs.eq(i).parent().addClass('wrong_div');
5527                                }
5528                            }
5529                            if(checked_inputs.eq(i).prev().val() == 1){
5530                                checked_inputs.eq(i).next().addClass('correct answered');
5531                                if((right_answer_sound)){
5532                                    resetPlaying([right_answer_sound, wrong_answer_sound]);
5533                                    setTimeout(function(){
5534                                        right_answer_sound.play();
5535                                    }, 10);
5536                                }
5537                            }else{
5538                                checked_inputs.eq(i).next().addClass('wrong answered');
5539                                if((wrong_answer_sound)){
5540                                    resetPlaying([right_answer_sound, wrong_answer_sound]);
5541                                    setTimeout(function(){
5542                                        wrong_answer_sound.play();
5543                                    }, 10);
5544                                }
5545                                if(finishAfterWrongAnswer){
5546                                    if( aysThisQuizBullets !== null ){
5547                                        aysThisQuizBullets.baseElement.find('.ays_questions_nav_question').each(function(){
5548                                            var thisBullet = $(this);
5549                                            thisBullet.attr('disabled', 'disabled');
5550                                        });
5551                                    }
5552                                }
5553                            }
5554                        }
5555
5556                        _this.attr('disabled', true);
5557                        _this.off('change');
5558                    }
5559                }
5560
5561                if( parentStep.data('type') === 'radio' ) {
5562                    stopQuestionTimer(quizContainer, questionID, quizId);
5563                }
5564
5565                if( aysThisQuizBullets !== null ) {
5566                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + questionID + '"]');
5567                    thisBullet.removeClass('ays-has-error');
5568                }
5569                parentStep.removeClass('ays-has-error');
5570            }else{
5571                if(_this.attr('type') === 'radio') {
5572                    _this.parents('.ays-quiz-answers').find('.checked_answer_div').removeClass('checked_answer_div');
5573                    _this.parents('.ays-field').addClass('checked_answer_div');
5574                }
5575                if(_this.attr('type') === 'checkbox') {
5576                    if(!_this.parents('.ays-field').hasClass('checked_answer_div')){
5577                        _this.parents('.ays-field').addClass('checked_answer_div');
5578                    }else{
5579                        _this.parents('.ays-field').removeClass('checked_answer_div');
5580                    }
5581                } 
5582                var checked_inputs = _this.parents().eq(1).find('input:checked');
5583                if( checked_inputs.length > 0 ){
5584                    if( aysThisQuizBullets !== null ){
5585                        var thisQuestionID = _this.parents('div[data-question-id]').data('questionId');
5586                        var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
5587                        thisBullet.parents('.ays-quiz-questions-nav-item').addClass('ays-quiz-questions-nav-item-answered');
5588                    }
5589                }else{
5590                    if( aysThisQuizBullets !== null ){
5591                        var thisQuestionID = _this.parents('div[data-question-id]').data('questionId');
5592                        var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + thisQuestionID + '"]');
5593                        thisBullet.parents('.ays-quiz-questions-nav-item').removeClass('ays-quiz-questions-nav-item-answered');
5594                    }
5595                }
5596
5597                if (checked_inputs.parents('div[data-question-id]').find('input.ays_next').hasClass('ays_display_none') &&
5598                    checked_inputs.parents('div[data-question-id]').find('i.ays_next_arrow').hasClass('ays_display_none')) {
5599                    if (checked_inputs.attr('type') === 'radio') {
5600                        checked_inputs.parents('div[data-question-id]').find('input.ays_next').trigger('click');
5601                    }
5602                }
5603
5604                if ( myOptions.enable_timer && myOptions.enable_timer === 'on' ) {
5605                    if (myOptions.quiz_timer_type && myOptions.quiz_timer_type === 'question_timer') {
5606                        if (window.aysQuizQuestionTimers && window.aysQuizQuestionTimers[quizId]) {
5607                            if( isRequiredQuestion ) {
5608                                if (ays_quiz_is_question_empty(quizContainer.find('div[data-question-id]')) === true) {
5609                                    for (var questionId in window.aysQuizQuestionTimers[quizId]) {
5610                                        stopQuestionTimer(quizContainer, questionId, quizId);
5611                                    }
5612                                }
5613                            }else{
5614                                // for (var questionId in window.aysQuizQuestionTimers[quizId]) {
5615                                //     stopQuestionTimer(quizContainer, questionId);
5616                                // }
5617                            }
5618                        }
5619                    }
5620                }
5621
5622                if( aysThisQuizBullets !== null ) {
5623                    var thisBullet = aysThisQuizBullets.baseElement.find('.ays_questions_nav_question[data-id="' + questionID + '"]');
5624                    thisBullet.removeClass('ays-has-error');
5625                }
5626            }
5627        }
5628    });
5629
5630    function show_hide_rows(page) {
5631
5632        var rows = jQuery('table.ays-add-questions-table tbody tr');
5633        rows.each(function (index) {
5634            jQuery(this).css('display', 'none');
5635        });
5636        var counter = page * 5 - 4;
5637        for (var i = counter; i < (counter + 5); i++) {
5638            rows.eq(i - 1).css('display', 'table-row');
5639        }
5640    }
5641
5642    function createPagination(pagination, pageShow) {
5643        // (pagination, pageShow)
5644        function aysPagination(baseElement, pageShow) {
5645            this.baseElement = baseElement;
5646            this.pageShow = pageShow
5647            this.pageNow = 1
5648            var pages = this.baseElement.parents('.ays-quiz-wrap').find('div[data-question-id]').length;
5649            var pageNum = 0;
5650            var pageOffset = 0;
5651
5652            this._initNav = function() {
5653                var _this = this;
5654                if( _this.baseElement.hasClass('ays-quiz-questions-nav-with-controls') ){
5655                    var pagePos = (this.baseElement.width()/2) - (parseInt(this.baseElement.find('.ays-quiz-questions-nav-item:first-child').css('width'))/2);
5656                    _this.baseElement.find('div.ays-quiz-questions-nav-content').css({
5657                        'margin-left': pagePos,
5658                    });
5659                }
5660
5661                //init events
5662                var toPage;
5663                _this.baseElement.on('click', '.ays-quiz-questions-nav-item a.ays_questions_nav_question', function (e) {
5664                    toPage = jQuery(this).parents('.ays-quiz-questions-nav-item').index();
5665                    _this._navPage(toPage);
5666
5667                    if ('speechSynthesis' in window) {
5668                        speechSynthesis.cancel();
5669                    }
5670                });
5671
5672                if( _this.baseElement.hasClass('ays-quiz-questions-nav-with-controls') ){
5673                    _this.baseElement.on('click', '.ays-quiz-questions-nav-go-left', function (e) {
5674                        _this._navScroll(_this.pageNow, 'left');
5675                    });
5676
5677                    _this.baseElement.on('click', '.ays-quiz-questions-nav-go-right', function (e) {
5678                        _this._navScroll(_this.pageNow, 'right');
5679                    });
5680                }
5681            }
5682
5683            this._navPage = function(toPage) {
5684                this.pageNow = toPage;
5685                var sel = jQuery('.ays-quiz-questions-nav-item', this.baseElement), w = sel.first().outerWidth()+10,
5686                    diff = toPage - pageNum;
5687                var src = $(document).find('.ays-navbar-bookmark').attr('src');
5688
5689                if (toPage >= 0 && toPage <= pages - 1) {
5690                    sel.removeClass('ays-quiz-questions-nav-item-active').eq(toPage).addClass('ays-quiz-questions-nav-item-active');
5691                    if (sel.eq(toPage).find('.ays-quiz-navbar-highlighted-notice').length > 0) {
5692                        if (sel.eq(toPage).find('.ays-quiz-navbar-highlighted-notice').css('display') == 'none') {
5693                            $(document).find('.ays-navbar-bookmark').attr('highlighted', false).attr('src', src.replace('filled', 'empty'));
5694                        } else {
5695                            $(document).find('.ays-navbar-bookmark').attr('highlighted', true).attr('src', src.replace('empty', 'filled'));
5696                        }
5697                    }
5698
5699                    this.baseElement.find('[disabled]').removeAttr('disabled');
5700                    sel.eq(toPage).attr('disabled', 'disabled');
5701                    sel.eq(toPage).find('a.ays_questions_nav_question').attr('disabled', 'disabled');
5702                    pageNum = toPage;
5703                } else {
5704                    return false;
5705                }
5706
5707                if (toPage <= (pages - (this.pageShow + (diff > 0 ? 0 : 1))) && toPage >= 0) {
5708                    pageOffset = pageOffset + -w * diff;
5709                } else {
5710                    pageOffset = (toPage > 0) ? -w * (pages - this.pageShow) : 0;
5711                }
5712
5713                if( this.baseElement.hasClass('ays-quiz-questions-nav-with-controls') ){
5714                    sel.parent().css('left', pageOffset + 'px');
5715                }
5716            }
5717
5718            this._navScroll = function(toPage, dir) {
5719
5720                if(dir === 'left'){
5721                    toPage -= 3;
5722                }
5723
5724                if(dir == 'right'){
5725                    toPage += 3;
5726                }
5727
5728                if(toPage > pages - 1){
5729                    toPage = pages - 1;
5730                }
5731
5732                if(toPage < 0){
5733                    toPage = 0;
5734                }
5735
5736                this.pageNow = toPage;
5737
5738                var sel = jQuery('.ays-quiz-questions-nav-item', this.baseElement),
5739                    w = sel.first().outerWidth()+10,
5740                    diff = toPage - pageNum;
5741
5742                if (toPage >= 0 && toPage <= pages - 1) {
5743                    pageNum = toPage;
5744                } else {
5745                    return false;
5746                }
5747
5748                if (toPage <= (pages - (this.pageShow + (diff > 0 ? 0 : 1))) && toPage >= 0) {
5749                    pageOffset = pageOffset + -w * diff;
5750                } else {
5751                    pageOffset = (toPage > 0) ? -w * (pages - this.pageShow) : 0;
5752                }
5753
5754                sel.parent().css('left', pageOffset + 'px');
5755            }
5756
5757            this._initNav();
5758
5759            return this;
5760        }
5761        var bullets = new aysPagination(pagination, pageShow);
5762        
5763        return bullets;
5764    }
5765
5766})( jQuery );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.