function vote_init () {
  var rbs = rjxET("input", "frmVote"), i;
  for (i = 0; i < rbs.length; i++)
    if (rbs[i].type == "radio") {
      rbs[i].onclick = pageVoteClick;
      rbs[i].parentNode.onclick = pageVoteClick;
    }
  rjxE("frmVote").onsubmit = pageVoteSubmit;
  rjxE("fbRes").onclick = pageVoteRes;
  rjxE("fbVote").onclick = pageVoteGo;
}

function pageVoteRes() {
  rjxShow("frmVote", false);
  rjxShow("blkVoteResult", true);
}

function pageVoteGo() {
  rjxShow("frmVote", true);
  rjxShow("blkVoteResult", false);
}

function pageVoteClick () {
  var rbs = rjxET("input", "frmVote"), i,
      th = (this.tagName != "input") ? rjxET("input", this)[0] : this;
  for (i = 0; i < rbs.length; i++)
    rbs[i].checked = false;
  th.checked = true;
}

function pageVoteSubmit () {
  function onOK() {
    var t = this.respText;
    if (t != "OK") {
      if (t.substr(0,4) == "err ") t = rjxUnescape(t.substr(4), "r");
      alert(t);
      rjxShow("fsVote", true);
      return;
    }
    rjxShow("frmVote", false);
    rjxShow("blkVoteResult", true);
  }
  rjxShow("fsVote", false);
  var ar = new rjxAResp(UEG_["MAIN_HOST"]+UEG_["PATH_KERNEL"]+"jx_vote.php", onOK), i,
      rbs = rjxET("input", "frmVote"), ansid = 0, prstr = "";
  for (i = 1; i < rbs.length - 1; i++)
    if (rbs[i].type == "radio") {
      if (rbs[i].checked) {
        ansid = rbs[i].value;
        prstr += "|" + ansid + ";1";
      }  
    }
  prstr = prstr.substr(1);
  ar.addParams({idd: rjxE("fhVoteId").value, qid: ansid, prs: prstr});
  ar.sendRequest();
  return false;
}

rjxAddListener (window, "load", vote_init);
