//Change a value of checkbox named argument 'name' by a value of
//checkbox specified by id.
function checkBy(id, name){
    var pi = document.getElementById(id);
    var cs = document.getElementsByName(name);
    for(var i = 0; i < cs.length; ++i)
        cs[i].checked = pi.checked;
}

//It calls f when a checkbox specified by id is checked. Otherwise g is called.
function whenCheck(id, f, g){
    var ck = document.getElementById(id);
    if(ck.checked)
        f();
    else
        g();
}

//Change a value of disabled attribute of each objs.
function setDisabled(objs, val){
    for(var i = 0; i < objs.length; ++i)
        objs[i].disabled = val;
}

function disableById(id){
    document.getElementById(id).disabled = true;
}

function enableById(id){
    document.getElementById(id).disabled = false;
}

//It turns obj's style display.
function flipDisp(obj){
    if(obj.constructor == String) obj = document.getElementById(obj);
    if(obj.style.display == 'none')
        show(obj);
    else
        hide(obj);
}

function show(obj){
    obj.style.display = '';
}

function hide(obj){
    obj.style.display = 'none';
}

function flipDispById(id){
    flipDisp(document.getElementById(id));
}

function showById(id){
    show(document.getElementById(id));
}

function hideById(id){
    hide(document.getElementById(id));
}

//Displaying indexed obj from objects which are specified by ids and prefix.
function showOneItem(ids, index, prefix){
    for(var i = 0; i < ids.length; ++i){
        id = prefix != undefined ? prefix + ids[i] : ids[i];

        var obj = document.getElementById(id);
        obj.style.display = i == index ? '' : 'none';
    }
}

//Show an html object by a value of select form.
//The object is specified by prefix and language key.
function showByLang(select, langs, prefix){
    var option = select.options[select.selectedIndex];
    showOneItem(langs, langs.indexOf(option.value), prefix);
}

