function Assessment(assessmentPagePool)  {
  var pThis = this;
 
  this.assessmentPagePool = assessmentPagePool;
  this.assessmentPages = new Array();
  if (isValidFunction(cwsObj.user)) {
    this.masteryScore = cwsObj.user.courseMasteryScore;
  }
  else  {
    this.masteryScore = -1;
  }
  this.correctFeedback = "Correct!";
  this.incorrectFeedback = "Incorrect.";
  this.useDefaultFeedback = false;
  this.disableNext = false;
  this.randomize = false;
  this.selectedQuestions = new Array();
  this.score = 0;
  this.assessmentSwf = "assessment";
  this.lockAssessment = true;
  
  if ((this.assessmentPagePool == null) || (this.assessmentPagePool == "") || (typeof this.assessmentPagePool == "undefined")) {
    this.assessmentPagePool = new Array();
  }
  this.setAssessmentPagePool = function(pagePool) {
    this.assessmentPagePool = pagePool;
  }
  this.initialize = function(pages)  {
    var pageIndexes = new Array();
    for (i=0;i<pages.length;i++)  {
      var page = pages[i];
      if (page.inAssessment) {
        pageIndexes[pageIndexes.length] = i;
      }
    }
    if ((this.assessmentPagePool.length > 0) && (this.assessmentPagePool.length >= pageIndexes.length))  {
      if (this.randomize) {
        //randomize list
        this.assessmentPagePool = randomize(this.assessmentPagePool);
      }
      for (i=0;i<pageIndexes.length;i++) {
        var holderPage = pages[pageIndexes[i]];
        var assessmentPage = this.assessmentPagePool[i];
        this.resetQuestion(assessmentPage.question);
        assessmentPage.description = holderPage.description;
        assessmentPage.pageNumber = holderPage.pageNumber;
        if ((assessmentPage.question.questionType != "custom") && (assessmentPage.question.useDefaultTemplate)) {
          if (assessmentPage.pageType == HTML_PAGE_TYPE)  {
            assessmentPage.pageId = "assessment";
          }
          if (assessmentPage.pageType == FLASH_PAGE_TYPE)  {
            assessmentPage.singleContentSwf = this.assessmentSwf;
          }
        }
        assessmentPage.question.questionNumber = i+1;
        pages[pageIndexes[i]] = assessmentPage;
        this.assessmentPages[i] = assessmentPage;
      }
      cwsObj.getCurrentKloObj().getCurrentDisplayType().setPages(pages);
    }
  }
  this.showQuestion = function(page) {
    if (page.pageType == HTML_PAGE_TYPE)  {
      //writeQuestion(page);
    }
  }
  this.selectAnswer = function(answerObj) {
    var kloObj = cwsObj.getCurrentKloObj();
    var question = this.getCurrentQuestion();
    if (question != null) {
      var selectAnswer = question.getAnswerByLetter(answerObj.name);
      if ((question.answered) && (kloObj.getCurrentPage().inAssessment) && (this.lockAssessment)) {
        kloObj.contentWinObj.win.alert("You have already answered this question.");
        answerObj.checked = selectAnswer.selected;
      }
      else  {
        if (question.questionType == "singleSelect")  {
          this.resetAnswerForm();
          selectAnswer.selected = true;
          answerObj.checked = selectAnswer.selected;
        }
        else  {
          selectAnswer.selected = answerObj.checked;
        }
      }
    }
  }
  this.submitQuestion = function(correct,grade)  {
    var kloObj = cwsObj.getCurrentKloObj();
    var page = kloObj.getCurrentPage();
    var question = page.question;
    var answered = false;
    if (question != null) {
      if (question.questionType == "custom")  {
        question.correct = correct;
        answered = true;
      }
      else  {
        question.correct = true;
        for (i=0;i<question.answers.length;i++) {
          var answer = question.answers[i];
          if (answer.selected)  {
            answered = true;
          }
          if (((answer.correct) && (!answer.selected)) || ((!answer.correct) && (answer.selected)))  {
            question.correct = false;
          }
        }
      }
      if (answered) {
        question.answered = true;
        if (page.pageType == HTML_PAGE_TYPE)  {
          doFeedback(question);
        }
        if ((question.mustGetCorrect) && (!question.correct) && (kloObj.getCurrentPage().pageType == HTML_PAGE_TYPE)) {
          this.resetAnswerForm();
        }
        else  {
          if (grade)  {
            this.grade();
          }
          kloObj.enableNext(true);
          if (question.useAlertFeedback)  {
            kloObj.goNext();
          }
        }
      }
      else  {
        kloObj.contentWinObj.win.alert("Please select an answer first!");
      }
    }
  }
  this.submitFlashQuestion = function(selectionList,correct,grade) {
    this.setSelections(selectionList);
    this.submitQuestion(correct,grade);
  }
  this.grade = function() {
    numScored = 0;
    numCorrect = 0;
    for (i=0;i<this.assessmentPages.length;i++) {
      var question = this.assessmentPages[i].question;
      if (question != null) {
        if (question.grade) {
          numScored += 1;
        }
        if (question.correct) {
          numCorrect += 1;
        }
      }
    }
    this.score = 0;
    if (numScored > 0)  {
      this.score = Math.round((numCorrect/numScored) * 100);
    }
    return this.score;
  }
  this.setSelections = function(ansIndexList) {
    var question = this.getCurrentQuestion();
    if (question != null) {
      var selectionArray = ansIndexList.split(",");
      if (selectionArray.length = question.answers.length)  {
        for (i=0;i<selectionArray.length;i++) {
          if (selectionArray[i] == "1") {
            question.answers[i].selected = true;
          }
          else  {
            question.answers[i].selected = false;
          }
        }
      }
    }
  }
  this.getCurrentQuestion = function()  {
    var kloObj = cwsObj.getCurrentKloObj();
    return kloObj.getCurrentPage().question;
  }
  this.getNextDisabled = function() {
    var question = this.getCurrentQuestion();
    if (question != null) {
      if ((question.disableNext) && (!question.answered)) {
        return true;
      }
    }
    return false;
  }
  function randomize(myArray) {
    var returnArray = new Array();
    var selectedIndexes = new Array();
    for (i=0;i<myArray.length;i++)  {
      var index = Math.round(Math.random() * (myArray.length-1));
      while (CwsUtil.itemInArray(index,selectedIndexes))  {
        index = Math.round(Math.random() * (myArray.length-1));
      }
      returnArray[i] = myArray[index];
      selectedIndexes[i] = index;
    }
    return returnArray;
  }
  function doFeedback(question)  {
    var kloObj = cwsObj.getCurrentKloObj();
    if (question.showFeedback)  {
      var answer = null;
      var selectedAnswerIndex = -1;
      for (var i=0;i<question.answers.length;i++) {
        if (question.answers[i].selected) {
          answer = question.answers[i];
          selectedAnswerIndex = i;
          i = question.answers.length;
        }
      }
      if (question.useAlertFeedback)  {
        var correctFeedback = pThis.correctFeedback;
        var incorrectFeedback = pThis.incorrectFeedback;
        if (!pThis.useDefaultFeedback)  {
          if (question.correctFeedback != "") {
            correctFeedback = question.correctFeedback;
          }
          if (question.incorrectFeedback != "") {
            incorrectFeedback = question.incorrectFeedback;
          }
          if (question.questionType == "singleSelect")  {
            if ((answer.feedback != "") && (answer.feedback != null)) {
              correctFeedback = answer.feedback;
              incorrectFeedback = answer.feedback;
            }
          }
        }
        if (question.correct)  {
          kloObj.contentWinObj.win.alert(correctFeedback);
        }
        else  {
          kloObj.contentWinObj.win.alert(incorrectFeedback);
        }
      }
      else  {
        //hide everything
        for (y=0;y<question.answers.length;y++)  {
          var feedbackObjStyle = eval("kloObj.contentWinObj.win." + CwsUtil.getObjStyle("answer_" + y + "_feedback"));
          feedbackObjStyle.display = "none";
        }
        feedbackObjStyle = eval("kloObj.contentWinObj.win." + CwsUtil.getObjStyle("correct_feedback"));
        feedbackObjStyle.display = "none";
        feedbackObjStyle = eval("kloObj.contentWinObj.win." + CwsUtil.getObjStyle("incorrect_feedback"));
        feedbackObjStyle.display = "none";
        //show correct feedback
        if ((answer.feedback != "") && (answer.feedback != null) && (question.questionType == "singleSelect") && (selectedAnswerIndex > -1)) {
          var feedbackObjStyle = eval("kloObj.contentWinObj.win." + CwsUtil.getObjStyle("answer_" + selectedAnswerIndex + "_feedback"));
          feedbackObjStyle.display = "inline";
        }
        else  {
          if (question.correct)  {
            var feedbackObjStyle = eval("kloObj.contentWinObj.win." + CwsUtil.getObjStyle("correct_feedback"));
            feedbackObjStyle.display = "inline";
          }
          else  {
            var feedbackObjStyle = eval("kloObj.contentWinObj.win." + CwsUtil.getObjStyle("incorrect_feedback"));
            feedbackObjStyle.display = "inline";
          }
        }
        var feedbackObjStyle = eval("kloObj.contentWinObj.win." + CwsUtil.getObjStyle("feedbackContainer"));
        feedbackObjStyle.display = "inline";
      }
    }
  }
  this.getCorrectFeedback = function(question)  {
    var feedback = this.correctFeedback;
    if ((!this.useDefaultFeedback) && (question.correctFeedback != ""))  {
      feedback = question.correctFeedback;
    }
    return feedback;
  }
  this.getIncorrectFeedback = function(question)  {
    var feedback = this.incorrectFeedback;
    if ((!this.useDefaultFeedback) && (question.incorrectFeedback != ""))  {
      feedback = question.incorrectFeedback;
    }
    return feedback;
  } 
  this.resetAnswerForm = function()  {
    var answerLetters = new Array("A","B","C","D","E","F");
    var kloObj = cwsObj.getCurrentKloObj();
    var question = this.getCurrentQuestion();
    if (kloObj.getCurrentPage().pageType == HTML_PAGE_TYPE) {
      var formObj = kloObj.contentWinObj.win.document.questForm;
      for (i=0;i<question.answers.length;i++) {
        question.answers[i].selected = false;
        var ansFormObj = eval("formObj." + answerLetters[i]);
        ansFormObj.checked = false;
      }
    } 
  }
  this.resetAnswers = function(question)  {
    for (j=0;j<question.answers.length;j++) {
      question.answers[j].selected = false;
    }
  }
  this.resetQuestion = function(question) {
    question.answered = false;
    question.correct = false;
    this.resetAnswers(question);
  }
  function writeQuestion(page) {
    var kloObj = cwsObj.getCurrentKloObj();
    var question = page.question;
    if (question != null) {
      var answers = question.answers;
      var answerLetters = new Array("A","B","C","D","E","F");
      var type = "radio";
      if (question.questionType == "multiSelect") {
        type = "checkbox";
      }
      var html = "<TABLE width=90%><TR><TD class='reg_text' valign=top><DIR><b>Question:</b><p> " + question.question + "</p>";
      html += "<P><SPAN name='questSpan'><FORM name='questForm' id='questForm'>";
      for (y=0;y<answers.length;y++)  {
        html += "<INPUT Type='" + type + "' onClick='kloObj.assessment.selectAnswer(this);' Name='" + answerLetters[y] + "'>" + answerLetters[y] + ". " + answers[y].answer + "<br>";
      }
      if ((!page.inAssessment) || ((!question.answered) && (page.inAssessment))) {
    	  html += "<P align=right><INPUT Type='button' onClick='kloObj.assessment.submitQuestion(false,false);' value='Submit Question'></P>";
      }
      html += "</FORM></SPAN></P></DIR></TD></TR></TABLE>";
      kloObj.writeHtml(kloObj.contentWinObj.win,html);
    }
  }
}

function Question(questionType, question, answers, imageObj, imagePosition) {
  var answerLetters = new Array("A","B","C","D","E","F");
  
  this.question = question;
  this.instructions = "";
  this.answers = answers;
  this.questionType = questionType;
  this.mustGetCorrect = false;
  this.grade = false;
  this.disableNext = false;
  this.correctFeedback = "Correct!";
  this.incorrectFeedback = "Incorrect.";
  this.answered = false;
  this.correct = false;
  this.showFeedback = true;
  this.referenceKloNums = new Array();
  this.remediationText = "";
  this.questionNumber = 0;
  this.useAlertFeedback = true;
  this.imageObj = imageObj;
  this.imagePosition = "right";
  this.imageValign = "middle";
  this.imageHalign = "center";
  this.useDefaultTemplate = true;
  
  if ((this.answers == null) || (this.answers == "") || (typeof this.answers == "undefined")) {
    this.answers = new Array();
  }
  if (imagePosition != null) {
    this.imagePosition = imagePosition;
  }
  this.addReferenceKloNum = function(kloNum)  {
    this.referenceKloNums[this.referenceKloNums.length] = kloNum;
  }
  this.addAnswer = function(answer) {
    this.answers[this.answers.length] = answer;
  }
  this.getCorrectAnswerIndex = function() {
    for (i=0;i<this.answers.length;i++) {
      if (this.answers[i].correct)  {
        return i;
      }
    }
    return -1;
  }
  this.getCorrectAnswer = function()  {
    var correctAnswerIndex = this.getCorrectAnswerIndex();
    if ((correctAnswerIndex > -1) && (correctAnswerIndex < 6)) {
      return answerLetters[correctAnswerIndex];
    }
    return null;
  }
  this.getAnswerByLetter = function(answerLetter)  {
    for (x=0;x<answerLetters.length;x++)  {
      if (answerLetters[x] == answerLetter) {
        return this.getAnswer(x);
      }
    }
    return null;
  }
  this.getAnswer = function(index)  {
    if (index < this.answers.length)  {
      return this.answers[index];
    }
    return null;
  }
}

function Answer(answer,correct,feedback,imageObj) {
  this.answer = answer;
  this.feedback = feedback;
  this.correct = correct;
  this.selected = false;
  this.imageObj = imageObj;
}
