/*
*  @autor: Piotr Wiecaszek
*  @date: 07.2013
*/


$(document).ready(function(){
    
//    clearAndEnableCheckbox();
    
//    populateQuizResultDivs();
    
});

var Qtext = { };

Qtext.checkAnswers = function(o) {
    
    var answers = o.find('.qtext-answers-list li.qtext-answer');
    var attemptsVal = questionsarray[o.attr("actionkey")]["attempts"];
    var attempts = "0";
    var showSigns = (typeof o.attr('fsign') === 'string' && o.attr('fsign') === 'true' );
    
    // check attempts value, i = infinite, n = no attempts, number = go along
    if (attemptsVal === "0"){
        // attemps: infinite
        attempts = 'infinite';
    }        
    else if (attemptsVal === 'n'){
        // attepmps: NONE
        return false;
    }        
    else {
        attempts = parseInt(attemptsVal);
    }

    var feedbackDiv = $('#insideFrame').contents().find('.feedback-overlay');
    
    var line_number = answers.push();
    var line_passed_number = 0;

    var checked_ans = [];
    
    // iterate through every question line
    answers.each(function(){
        var line = $(this);
        
        var lineID = $(this).attr('answer');

        var line_answer_number = $(this).find('span.qtext-txt[atype="input"], span.qtext-txt[atype="select"]').push();
        var good_answer_counter = 0;

        
        // iterate throught every select or input in actual line
        $(this).find('span.qtext-txt[atype="input"], span.qtext-txt[atype="select"]').each(function() {
            var that = $(this);
            
            var inputID = that.attr('subanswer');
            var inputType = that.attr('atype');
            
            // get list of all good answers for input
            var good_answers = questionsarray[o.attr("actionkey")]["answers"][lineID][inputID]["pa"];
            
            var user_input = null;
            if (inputType === "input") {
                var cs = (that.attr('cs') === 'true');

                // get user input value
                user_input = $(this).find('input[type="text"]').val().trim();
                var checked_input = $(this).find('input[type="text"]');

                oob = {
                    ans: user_input,
                    line: parseInt($(this).parent().attr('ansid'))
                }

                checked_ans.push(oob);

                
                $.each(good_answers, function(key, val) {
                    // jesli pytanie jest case sensitive to zwracaj uwage na wielkosc liter
                    var answer_check = key;
                    if (!cs) {
                        answer_check = key.toLowerCase();
                        user_input = user_input.toLowerCase();
                    }

                    if (user_input === answer_check) {
                        // oznacz odpowiedz jako prawidlowa
                        if (showSigns){
                            checked_input.css({
                                                outline: '1px solid #0F9C00',
                                                background: '#0F9C00',
                                                color: '#fff'
                                            });
                        }
                        good_answer_counter++;
                        return false;
                    } else {
                        // oznacz odpowiedz jako zla
                        if (showSigns){
                            checked_input.css({
                                                outline: '1px solid #FF7878',
                                                background: '#FF7878',
                                                color: '#fff'
                                            });
                        }
                    } 
                });
            }
            else if (inputType === "select") {

                var select_box = $(this).find('select');
                user_input = $(this).find('select option:selected').text().trim();
                
                oob = {
                    ans: user_input,
                    line: parseInt($(this).parent().attr('ansid'))
                }

                checked_ans.push(oob);

                $.each(good_answers, function(key, val) {
                    if (user_input === key) {
                        if (val === 1) {
                            // oznacz jesli odpowiedz jest prawidlowa
                            good_answer_counter++;
                            if (showSigns){
                                select_box.css({
                                                outline: '1px solid #0F9C00',
                                                background: '#0F9C00',
                                                color: '#fff'
                                            });
                            }
                            return false;
                        } else {
                            // oznacz jesli odpowiedz jest zla
                            if (showSigns){
                                select_box.css({
                                                outline: '1px solid #FF7878',
                                                background: '#FF7878',
                                                color: '#fff'
                                            });
                            }
                        }
                    }
                    
                });
                
            }
        });
        
        if (line_answer_number === good_answer_counter) {
            
            line_passed_number++;
            if (showSigns){
                line.removeClass('bad-line-answer').addClass('good-line-answer');
            }
        } else {
            if (showSigns){
                line.removeClass('good-line-answer').addClass('bad-line-answer');
            }
        }
        
        
    });


/* ================== FAOO ====================== */
                // feedbackDiv.find('.feedback-button')
                //                 .text('Ok')
                //                 .css('margin-right', '0px');
/* ================== FAOO end ====================== */
    
    var isPassed = false;
    if (line_number === line_passed_number) {
        if (showSigns){
            o.find('.qtext-header').append('<p class="question-completed">&#x2713;</p>');
        }
        
        offlineScore += parseInt(questionsarray[o.attr("actionkey")]["qScorePass"]);

        var j = 0;
        $.each(mypointstatus[page-1], function(key2, value2) {
                if (o.attr('actionkey') === mypointstatus[page-1][j][0]) {
                        mypointstatus[page-1][j][3] = 1;
                        isPassed = true;
                }
                j++;
        });

        var goodFeedback = o.attr('feedback-good');
        if(goodFeedback === ''){
            goodFeedback = lang['POINTS_FEEDBACK_GOOD'];
        }

        feedbackDiv.find('.feedback-button').attr('actionkey', o.attr('actionkey'));
        feedbackDiv.find('.feedback-back').removeClass('feedback-back-bad').addClass('feedback-back-good');
        feedbackDiv.find('.feedback-text').text(goodFeedback);
        feedbackDiv.find('.feedback-avatar').removeClass('feedback-avatar-bad').addClass('feedback-avatar-good');
        if (parseInt(questionsarray[o.attr("actionkey")]["qScorePass"]) !== 0) {
            feedbackDiv.find('.feedback-text').append('<p class="question-score-info">'+ lang['POINTS_FEEDBACK_1'] + ' ' + parseInt(questionsarray[o.attr("actionkey")]["qScorePass"]) + ' '+ lang['POINTS_FEEDBACK_2'] +' ' + offlineScore + ' ' + lang['POINTS_FEEDBACK_3'] + '</p>');
        }
        
        
        if (typeof o.attr('feedbacks') === 'string' && o.attr('feedbacks') === 'true' ){
            feedbackDiv.fadeIn('slow');
        } else {
            $('#insideFrame').contents().find('.feedback-button').trigger('mouseup');
        }
        
        o.find('input, a, select, .qtext-submit').addClass('disabled-btn').prop('disabled', true);
        
        // odswiez quiz results diva
        $('#insideFrame').contents().find('.quiz-results-wrapper').each(function(){
            populateQuizResultDivs($(this));
        });
        
        

    } else {
        var badFeedback = o.attr('feedback-bad');

        if(badFeedback === ''){
            badFeedback = lang['POINTS_FEEDBACK_BAD'];
        }
        
        feedbackDiv.find('.feedback-back').removeClass('feedback-back-good').addClass('feedback-back-bad');
        feedbackDiv.find('.feedback-text').text(badFeedback);
        feedbackDiv.find('.feedback-avatar').removeClass('feedback-avatar-good').addClass('feedback-avatar-bad');
        

        if (attempts !== 'infinite'){

            attempts--;
            if (attempts === 0){
                attempts = "n";
                o.find('input, a, select, .qtext-submit').addClass('disabled-btn').prop('disabled', true);

                if(isPassed === false){
                    if (showSigns){
                        o.find('.qtext-header').append('<p class="question-failed">&#x2717;</p>');
                    }
                    var j = 0;
                    $.each(mypointstatus[page-1], function(key2, value2) {
                            if (o.attr('actionkey') === mypointstatus[page-1][j][0]) {
                                    mypointstatus[page-1][j][3] = 2;
                            }
                            j++;
                    });

                    // dodaj / odejmij punkty do offlineScora za nie zaliczenie pytania
                    offlineScore += parseInt(questionsarray[o.attr("actionkey")]["qScoreFail"]);

                    // pokaż odpowiednia ilosc punktow w feedbacku
                    if (parseInt(questionsarray[o.attr("actionkey")]["qScoreFail"]) !== 0) {
                        feedbackDiv.find('.feedback-text').append('<p class="question-score-info">'+ lang['POINTS_FEEDBACK_1'] + ' ' + parseInt(questionsarray[o.attr("actionkey")]["qScoreFail"]) + ' '+ lang['POINTS_FEEDBACK_2'] +' ' + offlineScore + ' ' + lang['POINTS_FEEDBACK_3'] + '</p>');
                    }
                    // odswiez quiz results diva
                    $('#insideFrame').contents().find('.quiz-results-wrapper').each(function(){
                        populateQuizResultDivs($(this));
                    });
                }


            } else {
                feedbackDiv.find('.feedback-text').append('<p class="question-score-info">'+ lang['ATTEMPTS_FEEDBACK'] +' '+ attempts +'</p>');
            }

            questionsarray[o.attr("actionkey")]["attempts"] = String(attempts);

        }
        
        if (typeof o.attr('feedbacks') === 'string' && o.attr('feedbacks') === 'true' ){
            feedbackDiv.fadeIn('slow');
        } else {
            $('#insideFrame').contents().find('.feedback-button').trigger('mouseup');
        }
    }


    if (typeof quiz[o.attr("actionkey")] == 'undefined') {
        quiz[o.attr("actionkey")] = {
            u: {
                answer: {},
                attempts: 0,
                pass: ''
            }
        };
    }

    quiz[o.attr("actionkey")]['u']['attempts']++;
    quiz[o.attr("actionkey")]['u']['answer'][quiz[o.attr("actionkey")]['u']['attempts']] = checked_ans;
    quiz[o.attr("actionkey")]['u']['pass'] = isPassed;
    
    saveSuspendData();

    var returnObj = {
        pass: isPassed,
        end: attempts
    };

    return returnObj;
};


Qtext.answer_all_questions_first = function() {

    var divimg = $('#insideFrame').contents().find('#divimg');
    var first_answer_div = divimg.find('#answer-questions-first');

    if (first_answer_div.push() === 0) {
        first_answer_div = $('<div id="answer-questions-first"><span>'+lang['ANSWER_QUESTIONS_FIRST']+'</span></div>');
        divimg.append(first_answer_div);
    }

     first_answer_div.show('drop', {direction: 'up', distance: 15}, 400);

     setTimeout(function(){
        first_answer_div.hide('drop', {direction: 'up', distance: 15}, 400);
     }, 2000);

}

function check_and_show_attempts(){
    
    
    $('#insideFrame').contents().find('.quiz-multiple-wrapper').each(function(){
            if ($(this).find('.question-failed').push() > 0)
                $(this).find('.question-attempts-view').html('noattemts');
            else if ($(this).find('.question-completed').push() > 0)
                $(this).find('.question-attempts-view').hide();
            else
                $(this).find('.question-attempts-view').html(questionsarray[$(this).attr("actionkey")]["attempts"]);
                
        });
}



function populateQuizResultDivs(object){
//    alert(' &&&& LAUNCHED: populateQuizResultDivs()');
    
    
    var currObj = $('#insideFrame').contents().find(object);
        
    currObj.find('.result-info-wrapper p').each(function(){
        if ( $(this).css('opacity') != 1 )
            $(this).hide();
    });
    
    var scorm_score_raw = '',
        passed_failed_text = '',
        percentage_score = 0;
    
    currObj.find('.result-max-score span.result-value').text(scorm_score_max);
    currObj.find('.result-required-score span.result-value').text(scorm_score_required);
    
    if (lmsConnected) {
        scorm_score_raw = offlineScore;
        
        currObj.find('.result-your-score span.result-value').text(scorm_score_raw);
        
        if (scorm_score_raw == 0) {
            percentage_score = 0;
        } else {
            percentage_score = parseInt((scorm_score_raw / scorm_score_required) * 100);
        }
        
        if(percentage_score > 100)
            percentage_score = 100;
        
        if(percentage_score <= 0)
            percentage_score = 0;
        
        
        currObj.find('.result-percentage-score span.result-value').text( percentage_score + '%');
        
        if( scorm_score_raw < scorm_score_required )
            passed_failed_text = currObj.attr('info-bad');
        else
            passed_failed_text = currObj.attr('info-good');
        
        currObj.find('.result-info strong').text(passed_failed_text);

    } else {
        currObj.find('.result-your-score span.result-value').text(offlineScore);

        if (offlineScore == 0) {
            percentage_score = 0;
        } else {
            percentage_score = parseInt((offlineScore / scorm_score_required) * 100);
        }
        
        if(percentage_score > 100)
            percentage_score = 100;
        
        if(percentage_score <= 0)
            percentage_score = 0;
        
        currObj.find('.result-percentage-score span.result-value').text(percentage_score + '%');
        
        if( offlineScore < scorm_score_required )
            passed_failed_text = currObj.attr('info-bad');
        else
            passed_failed_text = currObj.attr('info-good');
        
        currObj.find('.result-info strong').text(passed_failed_text);
    }
}


function clearAndEnableCheckbox(){

//    var iframe = $('#insideFrame');


//    iframe.load(function(){
        $('#insideFrame').contents().find('.quiz-multiple-wrapper').find('input').each(function(){
            $(this).prop('disabled', false);
            $(this).next().prop('disabled', false);
            $(this).prop('checked', false);
        });
        
        $('#insideFrame').contents().find('.feedback-button').click(function(){
            console.log('bbbb');
            $('#insideFrame').contents().find('.feedback-overlay').fadeOut('slow');
        });
        
        // multiple choice question Submit btn handle
        $('#insideFrame').contents().find('.question-submit-btn').on('click', function(){
            var question = $(this).parent();
            
            if (!($(this).hasClass('disabled-btn'))) {
                checkAnswers(question);
            }
            
        });
        
                
        // Qtext choice question Submit btn handle
        $('#insideFrame').contents().find('.qtext-submit').on('click', function(){
            var question = $(this).parent().parent();
            
            if (!($(this).hasClass('disabled-btn'))) {
                Qtext.checkAnswers(question);
            }
            
        });
        
        // load swf objects on screen
        $('#insideFrame').contents().find('.div-point-swf').each(function(){
            
            $this = $(this);
            
            // if swf is on question based api
            if ($this.attr('isquestion') == 'true') {
                
                $this.flash({
                    swf         : 'swf/' + $this.attr('actionkey') + '/' + $this.attr('swffile'),
                    height      : $this.height(),
                    width       : $this.width(),
                    flashvars   : {
                            actionkey   : $this.attr('actionkey'),
                            attempts    : questionsarray[$this.attr("actionkey")]["attempts"],
                            pointspass  : parseInt($this.attr('score-pass')),
                            pointsfail  : parseInt($this.attr('score-fail')),
                            swfsoundmute: mutepage
                    }
                });
                    
            }
            // if it's a normal swf
            else {
                $this.flash({
                    swf         : 'swf/' + $this.attr('actionkey') + '/' + $this.attr('swffile'),
                    height      : $this.height(),
                    width       : $this.width(),
                    flashvars   : {
                            actionkey   : $this.attr('actionkey'),
                            swfsoundmute: mutepage
                    }
                });
            }
            
                
        });
        
//    });

}


//============================================== Multiple answers Question methods ===============================================
    
    
function checkAnswers(question){
    var answers = question.find('.multiple-answer');
    var goodAnswers = 0;
    var attemptsVal = questionsarray[question.attr("actionkey")]["attempts"];
    var attempts = "0";
    var showSigns = (typeof question.attr('fsign') === 'string' && question.attr('fsign') === 'true' );
    
    // check attempts value, i = infinite, n = no attempts, number = go along
    if (attemptsVal == "0"){
        attempts = 'infinite';
    }        
    else if (attemptsVal == 'n'){
        return false;
    }        
    else {
        attempts = parseInt(attemptsVal);
    }
     
    if (answers.find('input:checked').push() === 0) {
        
        Qtext.answer_all_questions_first();
        return;
    }

    var checked_ans = { };
    var i = 0;
    
    answers.each(function(){
        
        var myanswer = '';
        
        if ($(this).find('input').is(':checked')){
            myanswer = 'true';
            checked_ans[$(this).attr('id')] = $(this).text();
        }else{
            myanswer = 'false';
        }
        
        
        if (myanswer == questionsarray[question.attr("actionkey")]["answers"][i]){
            goodAnswers++;
        }else{
            // do smth when answer is not valid
        }
        
        i++;
    });
    
    var feedbackDiv = $('#insideFrame').contents().find('.feedback-overlay');


/* ================== FAOO ====================== */
                // feedbackDiv.find('.feedback-button')
                //                 .text('Ok')
                //                 .css('margin-right', '0px');
/* ================== FAOO end ====================== */
    
    var isPassed = false;
    if(goodAnswers == i){
        var goodFeedback = question.attr('feedback-good');
        
        
        if(goodFeedback == ''){
            goodFeedback = lang['POINTS_FEEDBACK_GOOD'];
        }
        
        feedbackDiv.find('.feedback-button').attr('actionkey', question.attr('actionkey'));
        feedbackDiv.find('.feedback-back').removeClass('feedback-back-bad').addClass('feedback-back-good');
        feedbackDiv.find('.feedback-text').text(goodFeedback);
        feedbackDiv.find('.feedback-avatar').removeClass('feedback-avatar-bad').addClass('feedback-avatar-good');
        
        question.find('input, a').addClass('disabled-btn').prop('disabled', true);
        
        if (showSigns){
            question.find('.question-header').append('<p class="question-completed">&#x2713;</p>');
        }
        var j = 0;
        $.each(mypointstatus[page-1], function(key2, value2) {
                if (question.attr('actionkey') == mypointstatus[page-1][j][0]) {
                        mypointstatus[page-1][j][3] = 1;
                        isPassed = true;
                }
                j++;
        });
         
        
        offlineScore += parseInt(questionsarray[question.attr("actionkey")]["qScorePass"]);
        
        if (parseInt(questionsarray[question.attr("actionkey")]["qScorePass"]) !== 0) {
            feedbackDiv.find('.feedback-text').append('<p class="question-score-info">'+ lang['POINTS_FEEDBACK_1'] + ' ' + parseInt(questionsarray[question.attr("actionkey")]["qScorePass"]) + ' '+ lang['POINTS_FEEDBACK_2'] +' ' + offlineScore + ' ' + lang['POINTS_FEEDBACK_3'] + '</p>');
        }
        // odswiez quiz results diva
        $('#insideFrame').contents().find('.quiz-results-wrapper').each(function(){
            populateQuizResultDivs($(this));
        });
	
        if (typeof question.attr('feedbacks') === 'string' && question.attr('feedbacks') === 'true' ){
            feedbackDiv.fadeIn('slow');
        } else {
            $('#insideFrame').contents().find('.feedback-button').trigger('mouseup');
        }
    }else{
        
        var badFeedback = question.attr('feedback-bad');
        
        if(badFeedback == ''){
            badFeedback = lang['POINTS_FEEDBACK_BAD'];
        }
        
        feedbackDiv.find('.feedback-back').removeClass('feedback-back-good').addClass('feedback-back-bad');
        feedbackDiv.find('.feedback-text').text(badFeedback);
        feedbackDiv.find('.feedback-avatar').removeClass('feedback-avatar-good').addClass('feedback-avatar-bad');
        
        if (attempts != 'infinite'){
            attempts--;


            if (attempts == 0){
                attempts = "n";
                question.find('input, a').addClass('disabled-btn').prop('disabled', true);

                if(isPassed == false){
                    if (showSigns){
                        question.find('.question-header').append('<p class="question-failed">&#x2717;</p>');
                    }
                    var j = 0;
                    $.each(mypointstatus[page-1], function(key2, value2) {
                            if (question.attr('actionkey') == mypointstatus[page-1][j][0]) {
                                    mypointstatus[page-1][j][3] = 2;
                            }
                            j++;
                    });

                    // dodaj punkty do offlineScora
                    offlineScore += parseInt(questionsarray[question.attr("actionkey")]["qScoreFail"]);
                    
                    // odswiez quiz results diva
                    $('#insideFrame').contents().find('.quiz-results-wrapper').each(function(){
                        populateQuizResultDivs($(this));
                    });

                    // pokaż odpowiednia ilosc punktow w feedbacku
                    if (parseInt(questionsarray[question.attr("actionkey")]["qScoreFail"])) {
                        feedbackDiv.find('.feedback-text').append('<p class="question-score-info">'+ lang['POINTS_FEEDBACK_1'] + ' ' + parseInt(questionsarray[question.attr("actionkey")]["qScoreFail"]) + ' '+ lang['POINTS_FEEDBACK_2'] +' ' + offlineScore + ' ' + lang['POINTS_FEEDBACK_3'] + '</p>');
                    }



                }
            } else {
/* ================== FAOO ====================== */
                feedbackDiv.find('.feedback-text').append('<p class="question-score-info">'+ lang['ATTEMPTS_FEEDBACK'] +' '+ attempts +'</p>');
/* ================== FAOO end ====================== */
            }

            questionsarray[question.attr("actionkey")]["attempts"] = String(attempts);

        }
        
        
        
        
        if (typeof question.attr('feedbacks') === 'string' && question.attr('feedbacks') === 'true' ){
            feedbackDiv.fadeIn('slow');
        } else {
            $('#insideFrame').contents().find('.feedback-button').trigger('mouseup');
        }
    }
    


    if (typeof quiz[question.attr("actionkey")] == 'undefined') {
        quiz[question.attr("actionkey")] = {
            u: {
                answer: {},
                attempts: 0,
                pass: ''
            }
        };
    }

    quiz[question.attr("actionkey")]['u']['attempts']++;
    quiz[question.attr("actionkey")]['u']['answer'][quiz[question.attr("actionkey")]['u']['attempts']] = checked_ans;
    quiz[question.attr("actionkey")]['u']['pass'] = isPassed;

    question.find('.question-attempts-view').html(questionsarray[question.attr("actionkey")]["attempts"]);
    $('#insideFrame').contents().find('.feedback-button').trigger('mouseup');
    saveSuspendData();
    
    var returnObj = {
        pass: isPassed,
        end: attempts
    };

    return returnObj;

    //return true;
}






//============================================== SWF QUESTIONS METHODS ===============================================

/*
 *  @data[0] = actionkey
 *  @data[1] = attempts
 *  @data[2] = points_pass
 *  @data[3] = points_fail
 *  @passfail = var from flash 'pass' or 'fail'
 */
function swfQuestionHandler(data, passfail){
    var dataArray = data.split(',');
    
    var dataObject = {
        actionkey       : dataArray[0],
        attempts        : dataArray[1],
        points_pass     : dataArray[2],
        points_fail     : dataArray[3]
    }
    var item_swf;
    // jesli zostala przezana zmienna passfail inna niz '' to zalicz / niezalicz i uruchom animacje
    if (passfail != ''){
        // ustaw cwiczenie na odwiedzone w timeline_tab
        for (var item in timeline_tab[page-1][timeline_row]) {
            
            if (timeline_tab[page-1][timeline_row][item][0] == dataObject.actionkey) {

                
                timeline_tab[page-1][timeline_row][item][5] = 1;
                swfCalculatePoints(dataObject, passfail);

                var j = 0;
                // ustaw cwiczenie na zaliczone / niezaliczone (1 / 2) w tablicy mypointstatus
                $.each(mypointstatus[page-1], function(key2, value2) {
                        if (dataObject['actionkey'] == mypointstatus[page-1][j][0]) {
                            if(passfail == 'pass')
                                mypointstatus[page-1][j][3] = 1;
                            else if (passfail == 'fail')
                                mypointstatus[page-1][j][3] = 2;
                            
                            
                        }
                        j++;
                });
                
                item_swf = item;
            }
        }
        
        
        // pobierz index aktualnego SWF'a
        var index = timeline_tab[page-1][timeline_row][item_swf];

        // sprawdz timeline_row czy wszystkie punkty już są zaliczone,
        // jeśli tak to uruchom animację wyjścia 
        if (check_timeline_row(timeline_row)) {
            $.each(timeline_tab[page-1][timeline_row], function (key, index) {
                if (index[3] != 'none') {
                    if (index[3].split('-')[0] != 'js') {
                        $('#insideFrame').contents().find('*[actionkey="'+index[0]+'"]').addClass(index[3]);
                    } else {
                        $('#insideFrame').contents().find('*[actionkey="'+index[0]+'"]').hide(index[3].split('-')[1], { direction: index[2].split('-')[2] },  '', 1300);
                    }
                }
            });

            timeline_row++;
            handle_animations(timeline_transition[timeline_row], page);
        }
    }
    // jesli zmienna jest pusta to tylko odswiez liczbe prob w tablicy
    else
    {
        //questionsarray[dataObject.actionkey]["attempts"] = String(dataObject.attempts);
    }
    
    // odswiez liczbe prob w tablicy
    questionsarray[dataObject.actionkey]["attempts"] = String(dataObject.attempts);
    saveSuspendData();
    
}


/*
 *  Passed object:
 *  @data['actionkey']  = actionkey,
 *  @data['attempts']   = attempts,
 *  @data['points_pass']     = points for pass
 *  @data['points_fail']     = points for fail
 * 
 *  @option: string, 'pass' or 'fail'
 */
function swfCalculatePoints(data, option){
    
    
    // initialize score variable and set to to pass score or fail depending on option var
    var score = 0;
    if(option == 'pass')
        score = data['points_pass'];
    else if (option == 'fail')
        score = data['points_fail'];
    

    // sumuj punkty dla punktacji scorma i offline
    offlineScore += parseInt(score);
    
    // zapisz nowa ilosc punktow w scormie
    saveSuspendData();

}

