function xor()
{
    var b = false;
    for( var j = 0; j <arguments.length; j++ )
    {
        if( arguments[ j ] && !b ) b = true;
        else if( arguments[ j ] && b ) return false;
    }
    return b;
};

function check_value(b, value){
	window[value].setVisibility(b);
	$("#legenda-" + value).toggle();
}

// marca o checkbox todas se seus filhos estiverem todos marcados, ou desmarca se um dos filhos estiver desmarcado
function controla_todas(classe){
	v = true;
	lista = $("."+classe).get();
	for(i=0;i<lista.length;i++)
		if(!lista[i].checked)
			v=false;
	$("#"+classe).attr('checked',v);
}

// marca ou desmarca todos checkbox que tiverem o nome classe igual ao "id" passado
function check_all(check, id){
	lista = $("."+id).get();
	for(i=0;i<lista.length;i++){		
		if (xor(lista[i].checked, check)) {
			check_value(check,lista[i].value);
			lista[i].checked=check;
		}		
	}
}

