// refresh current page and try to restore scrolling
function reload_with_scrolling()
{
    ypos = document.body.scrollTop || window.pageYOffset
    xpos = document.body.scrollLeft || window.pageXOffset
    window.location.reload()
    window.scrollTo(xpos, ypos)
}


function want_help_with_translations_request()
{
    // form = document.change_password_form;
    r = Ajax.load_json(Urls['want-help-with-translations'], {});

    r.addCallback(function(doc) {

        if (doc.result == 'ok') {
            alert(gettext('Help with translations request sent. You will be available for translations after moderator approval.'));

            // disable link
            getElement('help_with_translations_anchor').href = '#';
        } else {
            alert(doc);
        }
    })
};

// votes for user trans
Translation = {

    // vote for translation by current user
    vote_for_translation: function(translation_id)
    {
        // form = document.change_password_form;
        r = Ajax.load_json(Urls['vote-for-translation'],
                           {'translation_id': translation_id});

        r.addCallback(function(doc) {
            if (doc.result == 'ok') {

                reload_with_scrolling()

                //document.location = '?'//Translation.translation_votes_url;
            } else {
                alert(doc);
            }

        })
    },

    display_modify_translation_buttons: function(ts_id, display)
    {
        setDisplayForElement(display, 'save_my_translation_' + ts_id)
        setDisplayForElement(display, 'cancel_my_translation_' + ts_id)
    },

    // modify current user translation
    modify_my_translation: function(ts_id)
    {
        text = getElement('my_translation_' + ts_id).value
        r = Ajax.load_json(Urls['modify-translation'],
                           {'ts_id': ts_id,
                            'text': text
                           });

        r.addCallback(function(doc) {
            if (doc.result == 'ok') {
                // hide Save and Cancei buttons
                Translation.display_modify_translation_buttons(ts_id, 'none')

                getElement('my_translation_' + ts_id).focus()
            } else {
                alert(doc.message);
            };
        });
    },

    // cancel my translation modifications
    reset_my_translation: function(ts_id)
    {
        orig_text = getElement('orig_' + ts_id).value

        //getElement('form_' + ts_id)['my_translation_' + ts_id].value = orig_text
        getElement('my_translation_' + ts_id).value = orig_text

        Translation.display_modify_translation_buttons(ts_id, 'none')

    }
}

