var block_interval = Array();
var topmenus = Array();
var timeout;

function enter_tick()
{
        if (document.getElementById("login_remember").value==1)
        {
                document.getElementById("login_remember").value=0;
                document.getElementById("enter_tick").style.background="url('{THEME}/img/tick.gif') no-repeat left bottom";
        }
        else
        {
                document.getElementById("login_remember").value=1;
                document.getElementById("enter_tick").style.background="url('{THEME}/img/tick1.gif') no-repeat left bottom";
        }
}

function left_toggle(c)
{
        if (document.getElementById("submenu_"+c).style.display=="none")
        {
                document.getElementById("submenu_"+c).style.display = (ie ? "block" : "table-row");
                document.getElementById("submenubutton_"+c).className = "leftmenu_item_selected";
        }
        else
        {
                document.getElementById("submenu_"+c).style.display = "none";
                document.getElementById("submenubutton_"+c).className = "leftmenu_item";
        }
}


function getBounds(element)
{
  var left = element.offsetLeft;
  var top = element.offsetTop;
  for (var parent = element.offsetParent; parent; parent = parent.offsetParent)
  {
    left += parent.offsetLeft - parent.scrollLeft;
    top += parent.offsetTop - parent.scrollTop
  }
  return {left: left, top: top, width: element.offsetWidth, height: element.offsetHeight};
}


function block_hide(id)
{
        if (block_interval[id])
        clearTimeout(block_interval[id]);
        var bounds = getBounds(document.getElementById(id+"_container"));
        var bounds2 = getBounds(document.getElementById(id+"_table"));
        if (bounds['height']>1)
        {
        document.getElementById(id+"_container").style.height=bounds['height']-(bounds['height']>15 ? 15 : 1);
        document.getElementById(id+"_table").style.marginTop=-(bounds2['height']-bounds['height']);
        block_interval[id]=setTimeout("block_hide('"+id+"')", 1);
        }
        else if(bounds['height']==1)
        {
        document.getElementById(id+"_container").style.display="none";
//        document.getElementById(id+"_arrow").className="arrowdown";
                if (window.opera)
                {
                document.getElementById("toget12").style.height="99%";
                document.getElementById("toget22").style.height="99%";
                }
        }
}

function block_show(id)
{
        if (block_interval[id])
        clearTimeout(block_interval[id]);
        var bounds = getBounds(document.getElementById(id+"_container"));
        var bounds2 = getBounds(document.getElementById(id+"_table"));
        if (document.getElementById(id+"_container").style.display=="none")
        {
        document.getElementById(id+"_container").style.display="block";
        document.getElementById(id+"_container").style.height="1px";
        document.getElementById(id+"_table").style.marginTop=-(document.getElementById(id+"_table").offsetHeight);
//        document.getElementById(id+"_arrow").className="arrowup";
        }
        if (bounds['height']<bounds2['height']+1)
        {
        document.getElementById(id+"_container").style.height=bounds['height']+(document.getElementById(id+"_table").offsetHeight-bounds['height']>15 ? 15 : 1);
        document.getElementById(id+"_table").style.marginTop=-(document.getElementById(id+"_table").offsetHeight-bounds['height']);
        block_interval[id]=setTimeout("block_show('"+id+"')", 1);
        }
        else
        {
        
//      document.getElementById("torenew").className="h100 leftcolumn";
//      document.getElementById("torenew").style.height="99.99%";
//      setTimeout('document.getElementById("torenew").style.height="100%"',100);
        }
        
}

function block_hideopen(id)
{
        if (document.getElementById(id+"_container").style.display=="none")
        // показать
        {
                block_show(id);
        }
        else
        // спрятать
        {
                block_hide(id);
        }
}

function opera_fix()
{
        if (!window.opera)
        return;
        document.getElementById("toget12").style.height=document.getElementById("toget11").offsetHeight+"px";
        document.getElementById("toget22").style.height=document.getElementById("toget21").offsetHeight+"px";
        setTimeout("opera_fix()", 10);
}

function showsubmenu(id)
{
        if (document.getElementById("submenu"+id)) document.getElementById("submenu"+id).style.visibility = "visible";
        topmenus[topmenus.length] = id;
        clearTimeout(timeout);
        timeout = setTimeout("hidesubmenu(0)",2000);
}

function hidesubmenu(id)
{
        for (var i=0;i<topmenus.length;i++) if (topmenus[i]!=id)
          if (document.getElementById("submenu"+topmenus[i])) document.getElementById("submenu"+topmenus[i]).style.visibility = "hidden";
        topmenus = Array(); 
        if (id) topmenus[0] = id;
}

function timeclearsubmenu()
{
        clearTimeout(timeout);
}

function timesetsubmenu()
{
        timeout = setTimeout("hidesubmenu(0)",2000);
}

function gebi(id)
{
        return document.getElementById(id);
}

function menu_hideopen(id,selected)
{
        if(gebi('div'+id)&&gebi('div'+id).style.display!='none')
        {
                gebi('div'+id).style.display='none';
                gebi('sign'+id).src='{THEME}/img/plus.gif';
                gebi('cell'+id).className = 'leftmenu_item'+selected;
        }
        else 
        {
                gebi('div'+id).style.display=(ie ? "block" : "table-row");
                gebi('sign'+id).src='{THEME}/img/minus.gif';
                gebi('cell'+id).className = 'leftmenu_item_o'+selected;
        }
}
