var checkbox_unselected = 0;
var checkbox_selected   = 1;

var checkbox_prefix = "checkbox";
var checkbox_on		= checkbox_prefix + "_on";
var checkbox_off	= checkbox_prefix + "_off";

var button_checkbox_selected = function(button, value) {
	// valeur prototype -> voir prototype.js
	if (button.cvalue == undefined) return;

	if (value == checkbox_selected) {
		button.className = button.className.replace(checkbox_off, checkbox_on);
		button.cvalue = checkbox_selected;
	}
	else {
		button.className = button.className.replace(checkbox_on, checkbox_off);
		button.cvalue = checkbox_unselected;
	}
};

var button_checkbox = function() {
	/*
		sur click du button_checkbox
	*/
	if (this.blur) this.blur();

	// valeur prototype -> voir prototype.js
	if (this.cvalue == undefined) return;
	
	// modification -> inversement de la valeur
	var value = (this.cvalue != checkbox_unselected ? checkbox_unselected : checkbox_selected);
	button_checkbox_selected(this, value);
	if (this.onchange) this.onchange();
};

var td_checkbox = function() {
	/*
		sur click de la ligne (tous les td) du button_checkbox
		un seul button_checkbox par ligne : buttons[0]
	*/
	if (this.blur) this.blur();
	var button = this.parentNode.getElementsByTagName("button");
	button[0].onclick();
};

var set_button_checkbox = function() {
	var buttons = document.getElementsByTagName("button");
	for (i = 0; i < buttons.length; i++) {
		if (buttons[i].className.indexOf(checkbox_prefix) >= 0) {
			
			/* gestion prototype -> voir prototype.js
			*/
			proto_ie(buttons[i]);

			// sur click du button_checkbox
			buttons[i].onclick = button_checkbox;
		}
	}
	var tds = document.getElementsByTagName("td");
	for (i = 0; i < tds.length; i++) {
		if (tds[i].className.indexOf(checkbox_prefix) >= 0) {
			// sur click de la ligne (tous les td) du button_checkbox
			tds[i].onclick = td_checkbox;
		}
	}
};
