/** Adds random parameter to image url */
function imageUrl(url)
{
    res = url + '?rand=' + Math.round(Math.random() * 1000);
    alert(res);
    return res;
}

function openPopup(url, width, height)
{
    var attrs = 
        "location=no,toolbar=no,menubar=no," + 
        "scrollbars=yes,resizable=yes,status=no";
    window.open(url, 'popup', 
        'width=' + width + ',height=' + height + "," + attrs);
}

function chooseComposerWork(type, title)
{
    form = window.opener.document.composer_search;

    if (type == 'recording') {
        form.composer_search_recording.value = title;
    } else if (type == 'writing') {
        form.composer_search_writing.value = title;
    } else if (type == 'opera') {
        form.composer_search_opera.value = title;
    } else {
        form.composer_search_bibliography.value = title;
    }

    self.close();
}

function ifConfirmed(message)
{
    result = confirm(message);
    event.returnValue = result;
    return result;
}

function updateChoice(form)
{
    if (form.name == 'unit_form') {
        var type = radioValue('unit_form', 'series_type');

        var list = form.unit_series_id;
        var input = form.unit_series_signature_str;

        if (type == 'list') {
            list.disabled  = false;
            input.disabled = true;
        } else {
            list.disabled  = true;
            input.disabled = false;
        }
    } else if (form.name == 'move_found') {
        var type = radioValue('move_found', 'choice');

        var first = form.move_to_existing;
        var second = form.move_to_new;

        if (type == 'existing') {
            first.disabled  = false;
            second.disabled = true;
        } else {
            first.disabled  = true;
            second.disabled = false;
        }
    }
}

function updateInputState(name)
{
    var me = event.srcElement;
    var input = me.form.elements[name];

    if (me.value == '') {
        input.disabled = false;
        input.select();
        input.focus();
    } else {
        input.disabled = true;
    }
}


function highlight(obj)
{
    obj.style.backgroundColor = "#BBBB99";
    obj.style.cursor = 'hand';
}

function darklight(obj)
{
    obj.style.backgroundColor = "#EEE8C6";
}
