function manager(page, block, link) {
  if (page) {
    document.forms[0].page.value = page;
  }
  if (block) {
    document.forms[0].block.value = block;
  } else {
    document.forms[0].block.value = '';
  }
  if (link) {
    document.forms[0].link.value = link;
  } else {
    document.forms[0].link.value = '';
  }
  document.forms[0].submit();
}


function addtext() {
  document.forms[0].page.value = 'texts';
  document.forms[0].block.value = 'add';
  document.forms[0].submit();
}


function assist_strings() {
  var index1 = document.forms[0].string1.selectedIndex;
  var index2 = document.forms[0].string2.selectedIndex;
  var string1 = eval ("document.forms[0].string1.options[" + index1 + "].value");
  var string2 = eval ("document.forms[0].string2.options[" + index2 + "].value");
  document.forms[0].strings.value = document.forms[0].strings_first.value + "\n" + string1 + "\n" + string2;
}


function assist_publish () {
  document.forms[0].action = '/cgi-bin/form.pl';
  document.forms[0].type.value = 'poem_new';
  document.forms[0].submit();
}


function assist_select (num) {
  var string = eval ('document.forms[0].strings_' + num + '.value');
  document.forms[0].strings.value = document.forms[0].strings_first.value + "\n" + string;
  document.forms[0].strings.focus();
  self.location = '#chosen';
}


function assist (start) {
  document.forms[0].start.value = start;
  document.forms[0].submit();
}


function goshop (unit) {
  document.forms[0].action = '/cgi-bin/shop/' + unit + '.pl';
  document.forms[0].book_id.value = '';
  document.forms[0].submit();
}


function add_book(book, num) {
  document.forms[0].action = '/cgi-bin/shop/basket.pl';
  document.forms[0].book_id.value = book;
  document.forms[0].submit();
}


function books(num) {
  document.forms[0].action = '/cgi-bin/shop/books.pl';
  document.forms[0].from.value = num;
  document.forms[0].submit();
}


function book_author(author) {
  document.forms[0].action = '/cgi-bin/shop/authors.pl';
  document.forms[0].author.value = author;
  document.forms[0].submit();
}


function menu(type) {
  document.forms[0].type.value = type;
  document.forms[0].submit();
}


function go(unit, topic) {
  if (topic) {
    document.forms[0].active_topic.value = topic;
  }
  document.forms[0].action = '/cgi-bin/' + unit + '.pl';
  document.forms[0].unit.value = unit;
  document.forms[0].rate.value = '';
  document.forms[0].submit();
}


function authors(author) {
  document.forms[0].action = '/cgi-bin/authors.pl';
  document.forms[0].author_login.value = author;
  document.forms[0].submit();
}


function post_poem() {
  document.forms[0].action = '/cgi-bin/form.pl';
  document.forms[0].type.value = 'poem_new';
  document.forms[0].submit();
}


function post_message() {
  document.forms[0].action = '/cgi-bin/form.pl';
  document.forms[0].type.value = 'message_new';
  document.forms[0].submit();
}


function post_rec() {
  document.forms[0].action = '/cgi-bin/form.pl';
  document.forms[0].type.value = 'rec_new';
  document.forms[0].submit();
}


function add_notes(message) {
  document.forms[0].action = '/cgi-bin/form.pl';
  document.forms[0].message.value = message;
  document.forms[0].type.value = 'notes_new';
  document.forms[0].submit();
}


function reverse(unit, rec_author, rec_writer) {
  document.forms[0].action = '/cgi-bin/' + unit + '.pl';
  document.forms[0].type.value = 'reverse';
  if (rec_author) {
    document.forms[0].rec_author.value = rec_author;
  }
  if (rec_writer) {
    document.forms[0].rec_writer.value = rec_writer;
  }
  document.forms[0].submit();
}


function forward(unit, rec_author, rec_writer) {
  document.forms[0].action = '/cgi-bin/' + unit + '.pl';
  document.forms[0].type.value = 'forward';
  if (rec_author) {
    document.forms[0].rec_author.value = rec_author;
  }
  if (rec_writer) {
    document.forms[0].rec_writer.value = rec_writer;
  }
  document.forms[0].submit();
}


function calendar(year, month, day) {
  document.forms[0].year.value  = year;
  document.forms[0].month.value = month;
  document.forms[0].day.value   = day;
  document.forms[0].submit();
}


function encyclopedia(word) {
  document.forms[0].action = '/cgi-bin/encyclopedia.pl';
  document.forms[0].word.value  = word;
  document.forms[0].submit();
}


function bio(word) {
  document.forms[0].action = '/cgi-bin/bio.pl';
  document.forms[0].word.value  = word;
  document.forms[0].submit();
}


function ethymology(word) {
  document.forms[0].action = '/cgi-bin/ethymology.pl';
  document.forms[0].word.value  = word;
  document.forms[0].submit();
}


function list(val) {
  document.forms[0].list.value = val;
  document.forms[0].submit();
}


function cert(link) {
  document.forms[1].link.value = link;
  document.forms[1].page.value = 'cert';
  document.forms[1].submit();
}


function decodeMail(text) {
        var elements = reverseText(text).split('<~>');
        document.write(buildTag(elements[0], elements[1], elements[2]));
}

function buildTag(email, text, title) {
        return '<a href="mailto:' + email + '"' +
                        ((title) ? ' title="' + title + '"' : '') + '>' +
                        ((text) ? text : email) +
                '</a>';
}

function reverseText(text) {
        var str = '';
        for (var i = text.length - 1; i >= 0; i--) str += text.charAt(i);
        return str;
}


function aod(login, type, tr) {
  document.forms[0].login.value = login;
  document.forms[0].type.value = type;
  document.forms[0].tr.value = tr;
  document.forms[0].submit();
}


function afisha(login, type) {
  document.forms[0].login.value = login;
  document.forms[0].type.value = type;
  document.forms[0].submit();
}
