var checkboxesOpened = false;

function checkboxes_hide(p) {
	var oList = document.getElementById('checkboxes_' + p + '_list');
    foform_restaurerSelectsSousElt(oList.id);
	oList.style.display = 'none';
    checkboxesOpened = false;
}

function checkboxes_hideOpened() {
    if (checkboxesOpened) {
        checkboxes_hide(checkboxesOpened);
    }
}

function checkboxes_setDisplayOther(p, show) {
    if (document.getElementById(p + '_other')) {
	   document.getElementById(p + '_other').style.display = ( show ? "block" : "none");
    }
}

function checkboxes_show(p) {
    checkboxes_hideOpened();
	var oList = document.getElementById('checkboxes_' + p + '_list');
	oList.style.display = "block";
    checkboxesOpened = p;
    foform_cacherSelectsSousElt(oList.id);
}

function checkboxes_setValue(p) {
	var i = 0;
	var oCheckbox, valueId, v;
	var val = '';
	var otherOn = false;
	while (oCheckbox = document.getElementById('checkboxes_' + p + '_checkbox_id_' + i)) {
		if (oCheckbox.checked) {
			v = oCheckbox.value;
			j = v.indexOf(":");
			valueId = v.substring(0, j);
			val +=  valueId + ";";
			if (valueId == "99") {
				otherOn = true;
			}
		}
		i++;
	}
	if (val.length > 0) {
		val = val.substring(0, val.length - 1);
	}
	document.getElementById('checkboxes_' + p + '_hidden_id').value = val;
	checkboxes_setDisplayOther(p, otherOn);
}

function checkboxes_toggle(p) {
	var oList = document.getElementById('checkboxes_' + p + '_list');
	if (oList.style.display == 'none') {
		checkboxes_show(p);
	} else {
		checkboxes_hide(p);
	}
}


