﻿
//
// This script contains a number of functions for fetching the current
// value(s) of the different question parts.
//

//
// This is a helper used by the PreviousAnswerQuestionPartRenderer to determine whether
// any values in the given array is set to the specified testValue
//
function isAnySet(arr, testValue) {
    for (var i = 0; i < arr.length; i++) {
        if (arr[i].toLowerCase() == testValue.toLowerCase()) {
            return true;
        }
    }
    return false;
}

function Options_GetValue(qpid) {
    var qp = $("div.question-part[qpid=" + qpid + "]");

    // it could either be a <select> or a series of <input>s, we'll handle both
    var select = qp.find("select");
    if (select.size() > 0) {
        select = select.get(0);
        return [select.options[select.selectedIndex].text];
    } else {
        var values = new Array();
        qp.find("input").each(function() {
            if (this.checked) {
                values.push($(this).next("label").text());
            }
        });
        return values;
    }
}

function FreeText_GetValue(qpid) {
    var qp = $("div.question-part[qpid=" + qpid + "]");
    return [qp.find("textarea, input[type=text]").text];
}

function IndividualsFields_GetValue(qpid) {
    //alert("IndividualsFields_GetValue");
    return Array();
}

function Rate_GetValue(qpid) {
    var qp = $("div.question-part[qpid=" + qpid + "]");
    return [qp.find("input[type=hidden]").attr("value")];
}