function toggle_menu(lm_id)
{
  var e = _ge('menu_'+lm_id);

  if (e)
  {
    e.style.display = e.style.display != 'block' ? 'block' : 'none';
  }
}

var cur_table_id = 0;
//var menu_item_h = is_ie4up ? 21 : 20;
var menu_item_h = is_opera ? 20 : 21;

function show_cat(id, position)
{
  if (typeof parents_ar == 'undefined') return;

  var t = _ge('cat_table_'+id);
  var c = _ge('cat_td_'+id);
  var a = _ge('anchor_'+id);

  var parent = parents_ar[id];
  if (!a && parent != -1) a = _ge('anchor_'+parent);

  if (typeof position == 'undefined' || isNaN(position)) position = positions_ar[id];

  if (c) c.style.backgroundColor = '#fff';

  if (a && t)
  {
    var x = getLeft(a);
    var y = getTop(a);

    var x2 = parent != -1 && _ge('cat_table_'+parent) ? getWidth(_ge('cat_table_'+parent)) : 0;
    var y2 = parent != -1 ? 0 : 0;

    var x3;
    if (is_ie4up) x3 = -4; else if (is_opera) x3 = -4; else x3 = -3;
    var y3 = id != 1 ? -3 : -3; // -3:0

    //_ge('dump').innerHTML = y+' '+menu_item_h+' '+position+' '+(positions_ar[id])+' '+id;

    t.style.left = x + x2 + x3 + 180;
    t.style.top = y + y2 + y3 - 5 + menu_item_h * position; // + 23
    t.style.visibility = 'visible';

    if (parents_ar[id]) show_cat(parents_ar[id]);
  }
}

function hide_cat(id)
{
  var t = _ge('cat_table_'+id);
  var c = _ge('cat_td_'+id);

  //_ge('dump').innerHTML = 'id='+id+', cur='+cur_table_id+', p-id='+parents_ar[id]+', p-cur='+parents_ar[cur_table_id];

  if (c) c.style.backgroundColor = '#ABABAB';

  if (t && cur_table_id != id)
  {
    t.style.visibility = 'hidden';

    if (parents_ar[id]) hide_cat(parents_ar[id]);
  }
}

function cat_ontable(id)
{
  var x = cur_table_id;
  cur_table_id = id;

  if (id)
    show_cat(id);
  else
    hide_cat(x);
}

/* popup */

function ad_popup(uri)
{
  window.open(uri,'','width=700,height=400,left=200,top=200');
}

function ad_popunder(uri)
{
  window.open(uri,'','width=700,height=400,left=200,top=200').blur();
  window.focus();
}

function gotocategory()
{
  var e = _ge('goto_cat_sel');

  if (e && e.value) window.location.href = e.value;
}

function check_poll(choices_count)
{
  var prefix = arguments[1] || '';

  if (!poll_choices_ar) return false;

  for (var i = 0; i < poll_choices_ar.length; i++)
  {
    var e = _ge(prefix+'poll_choice_'+poll_choices_ar[i]);
    if (e && e.checked) return true;
  }

  alert('Выберите вариант(ы) ответа, чтобы проголосовать!');
  return false;
}

function show_prev_polls()
{
  var e1 = _ge('show_prev_polls_div');
  var e2 = _ge('poll_rows_div');

  if (e1 && e2)
  {
    e1.style.display = 'none';
    e2.style.display = 'block';
  }

  return false;
}
 addHover = function() {
    var hEls = document.getElementById("jd_menu").getElementsByTagName("LI");
    for (var i=0, len=hEls.length; i<len; i++) {
      hEls[i].onmouseover=function() { this.className+=" iehover"; }
      hEls[i].onmouseout=function() { this.className=this.className.replace(" iehover", ""); }
    }
  }
  if (window.attachEvent && navigator.userAgent.indexOf("Opera")==-1) window.attachEvent("onload", addHover);