window.addEventListener('click', function(){
var checkboxes = new Array(4);
var states = new Array(4);
var onclick = function() {
var args = new Array(4);
for (var i = 0; i < checkboxes.length; i++) {
var checkbox = checkboxes[i];
if (this === checkbox) {
args[i] = Number(this.checked);
} else {
args[i] = states[i];
checkbox.checked = states[i];
}
}
Polygon.apply(window, args);
};
for (var i = 0; i < checkboxes.length; i++) {
var checkbox = document.getElementById('p' + (i + 1));
checkbox.addEventListener('click', onclick, false);
checkboxes[i] = checkbox;
states[i] = checkbox.checked;
}
}, false);