/*
 *  This Source Code Form is subject to the terms of the Mozilla Public
 *  License, v. 2.0. If a copy of the MPL was not distributed with this
 *  file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 *  Copyright (c) 2012-2013, Dennis Sun <dlsun@stanford.edu>
 */

var OHMS = (function(OHMS) {

    var MultipleResponseAnswer = function(question, data) {
	this.text = data.text;
	this.choices = data.choices;
	this.compact = data.compact;
	this.solution = data.solution;
	this.max_pts = data.max_pts;
	this.id = Math.random().toString(36).substring(7);
	OHMS.Answer.apply(this, arguments);
    }

    MultipleResponseAnswer.prototype = new OHMS.Answer();

    MultipleResponseAnswer.prototype.create_element = function () {

	this.element = $("<div class='Answer MultipleResponse' />");

	if (this.compact) {
	    for (var i=0; i<this.choices.length; i++) {
		this.element.append("<input type='checkbox' name='"+this.id+"' value="+i+" disabled> " + this.choices[i] + "&nbsp;&nbsp;&nbsp;");
	    }
	} else {
	    for (var i=0; i<this.choices.length; i++) {
		this.element.append("<p><input type='checkbox' name='"+this.id+"' value="+i+" disabled> " + this.choices[i] + "</p>");
	    }
	}
    }

    MultipleResponseAnswer.prototype.show_solution = function () {
        var answers = this.solution.answer.split(",");
        for (var i=0; i<this.choices.length; i++) {
	    this.element.find("input[value="+answers[i]+"]").attr("checked","checked");
        }
    }

    MultipleResponseAnswer.prototype.get_element_by_value = function (value) {
	return this.element.find("[value="+value+"]");
    }

    MultipleChoiceAnswer.prototype.get_value = function () {
	return this.element.find(":checked").val();
    }

    MultipleChoiceAnswer.prototype.set_value = function (value) {
	this.get_element_by_value(value).attr("checked","checked");
    }

    MultipleChoiceAnswer.prototype.unlock_answer = function () {
	this.element.find("input").removeAttr("disabled");
    }

    MultipleChoiceAnswer.prototype.lock_answer = function () {
	this.element.find("input").attr("disabled","disabled");
    }


    OHMS.MultipleChoiceAnswer = MultipleChoiceAnswer;

    return OHMS;

}(OHMS))

@@ -1342,38 +1342,38 @@
 var i=0; i%3Cthis.
-choice
+answer
 s.length; i++) %7B
@@ -1609,37 +1609,39 @@
  %7D%0A%0A    Multiple
-Choic
+Respons
 eAnswer.prototyp
@@ -1668,32 +1668,44 @@
 on () %7B%0A%09return 
+$.makeArray(
 this.element.fin
@@ -1718,19 +1718,60 @@
 ecked%22).
-val
+map(function(i,e) %7B return e.value; %7D)).join
 ();%0A    
@@ -1777,37 +1777,39 @@
  %7D%0A%0A    Multiple
-Choic
+Respons
 eAnswer.prototyp
@@ -1837,25 +1837,119 @@
 n (value) %7B%0A
-%09
+        var values = value.split(',') %0A        for (var i=0; i%3Cthis.values.length; i++) %7B%0A%09    
 this.get_ele
@@ -1967,16 +1967,20 @@
 ue(value
+s%5Bi%5D
 ).attr(%22
@@ -1996,24 +1996,34 @@
 %22checked%22);%0A
+        %7D%0A
     %7D%0A%0A    M
@@ -2021,37 +2021,39 @@
  %7D%0A%0A    Multiple
-Choic
+Respons
 eAnswer.prototyp
@@ -2151,29 +2151,31 @@
     Multiple
-Choic
+Respons
 eAnswer.prot
@@ -2286,29 +2286,31 @@
 HMS.Multiple
-Choic
+Respons
 eAnswer = Mu
@@ -2319,13 +2319,15 @@
 iple
-Choic
+Respons
 eAns

multiple response question finished