Select the answers that are least filled in the quotas. They can be more than one.
//surveyscripting.com
function setquotas(qname, qselected, qquestion, qcount) //least filled quota with multiple options
{
var answers = new Array();
for (var z = 1; z <= qcount; ++z)
{
var qualified = f(qselected).categories();
var selected = qualified[0];
var min = 99999999;
for(var i = 0; i < qualified.length; ++i)
{
f(qquestion)[qualified[i]].set('1');
if (qc(qname) < min && !qf(qname))
{
selected = qualified[i];
min = qc(qname);
}
f(qquestion)[qualified[i]].set('0');
}
answers[z] = selected;
f(qselected)[selected].set('0');
}
for (var k = 1; k < answers.length; ++k) { f(qquestion)[answers[k]].set('1'); }
}
//usage: setquotas('segment', 'segment_hidden', 'test', '2');
//qname - quota name
//qselected - the question with the selected answers
//qquestion - the hidden question for the quota
//qcount - least filld quota count