/*--
Copyright © 1998, 2012, Oracle and/or its affiliates.  All rights reserved.
--*/

// include lms_init.js
document.write('<script type="text/javascript" src="../../../kpsettings.js"></script>');
document.write('<script type="text/javascript" src="../../../config.js"></script>');
document.write('<script type="text/javascript" src="../../../js/lmsapplet.js"></script>');
document.write('<script type="text/javascript" src="../../../js/lmsresource.js"></script>');
document.write('<script type="text/javascript" src="../../../js/lmscomfactory.js"></script>');
document.write('<script type="text/javascript" src="../../../js/lmscom.js"></script>');
document.write('<script type="text/javascript" src="../../../js/escape.js"></script>');
document.write('<script type="text/javascript" src="../../../js/lms_init.js"></script>');

// callback functions from toc

function lms_LoadAdapterComplete() {
    __Ialert("lms_LoadAdapterComplete() called");

    var lmscom = document.LmsCom;
    lmscom.Begin();
    if (lmscom.assessment_guid)
        lmscom.doSetUPKValue("upk.actual_guid",lmscom.assessment_guid);
    lmscom.OpenQuestionStatus();
    lms_UpdateUI(lmscom.status_obj.getStatus());
    lms_initialized = true;
    setTimeout(lms_store.callbackfunction, 1);
}

// lms_Score
// answer always passed in as an array
function lms_Score(guid, qtype, answer, answerID, result) {
    __alert("lms_Score called with parameters: " + guid + "," + qtype + "," + answer + "," + result);
   
    var lmscom = document.LmsCom;
    var statobj = lmscom.status_obj;
    switch (qtype) {
        case "FillinBlank":
            statobj.setQuestionType("fill-in");
            if (answer)
                statobj.setLearnerResponse(answer[0]);
            break;
        case "Hotspot":
            statobj.setQuestionType("choice");
            if (answer)
                statobj.setLearnerResponse(answer[0]);
            break;
        case "Matching":
            statobj.setQuestionType("matching");
            if (answer) {
                var learnerresponse = "";
                for (var i=0; i<answer.length; i++)
                    if (answer[i])
                        learnerresponse += "[,]" + i + "[.]" + answer[i];
                if (learnerresponse)
                    statobj.setLearnerResponse(learnerresponse.substring(3));
            }
            break;
        case "MultipleChoiceSingleAnswer":
            statobj.setQuestionType("choice");
            if (answer)
                statobj.setLearnerResponse("#" + answerID[0] + "#");
            break;
        case "MultipleChoiceManyAnswer":
            statobj.setQuestionType("choice");
            if (answer) {
                var learnerresponse = "";
                for (var i=0; i<answer.length; i++) {
                    if (i>0)
                        learnerresponse += "[,]";
                    learnerresponse += "#" + answerID[i] + "#"; 
                }
                statobj.setLearnerResponse(learnerresponse);
            }
            break;
        case "TrueFalse":
            statobj.setQuestionType("true-false");
            if (answer)
                statobj.setLearnerResponse(answer[0]);
            break;
        case "UserDefined":
            statobj.setQuestionType("other");
            if (answer)
                statobj.setLearnerResponse(answer[0]);
            break;
        default:
            alert("Unanticipated question type: " + qtype);
            return
    }
    
    if (result == "correct") {
        statobj.setResult(result);
        statobj.setStatus(LMS_PASSED);
    } else if (result == "incorrect") {
        statobj.setResult(result);
        statobj.setStatus(LMS_FAILED);
    } else {    // "donotknow"
        statobj.setResult(null);
        statobj.setStatus(LMS_FAILED);
    }
  
    lmscom.setInteraction(0,document.LmsCom);  
    // report back to the lms now
    lmscom.SaveStatus();
    lmscom.NotifyParent();
}

function lms_GetRemediationMode() {
    __alert("lms_GetRemediationInfo called");
    if (GetTopLevelLmsMode() === "KPT")
        return -1;
    return document.LmsCom.doGetUPKValue("upk.feedback_mode");
}

//----------------------------------------------------------------------------------------------/

var _lms_module_name = "lms_question.js";
var _lms_show_alert = false;
var _lms_show_Ialert = false;