isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? 1 : 0;
NS4 = (document.layers) ? 1 : 0;
IE4 = (document.all && !isMac) ? 1 : 0;

function shSave(id,sh)
{
  if(!NS4) {
    var visual=getCookie('visual');
    if(visual==null || visual=='undefined') {
      var aVisual=new Array();
    }
    else {
      var aVisual=visual.split(",");
    }
    var was=false;
    for(var i=0; i<aVisual.length; i++) {
      if(aVisual[i]==id.id) {
        if(sh) {
          aVisual.splice(i,1);
          was=true;
          break;
        }
        else {
          was=true;
          break;
        }
      }
    }
    if(!sh && !was) {
      aVisual[aVisual.length]=id.id;
    }
    visual=aVisual.join(',');
    setCookie('visual',visual);
  };
}


function shElement(el,sh)
{
  if(!NS4) {
    if(sh==null) return;
    el.style.display=(sh?'block':'none');
    var id=el.id+'_i';
    if(typeof(document.images[id])!='undefined') {
      document.images[id].src=(!sh?'/images/restore.gif':'/images/minimize.gif');
    }
  };
}


function isDisplayed(el)
{
  if(!NS4) {
    return (el.style.display!='none');
  };
  return null;
}


function toggleMinMax(id)
{
  if(!NS4) {
    var sh=!isDisplayed(id);
    shElement(id,sh);
    shSave(id,sh);
  }
}


function applyShowHide()
{
  var visual=getCookie('visual');
  if(visual==null) {
    return;
  }
  else {
    var aVisual=visual.split(",");
  }
  var id;
  for(var i=0; i<aVisual.length; i++) {
    id=aVisual[i];
    if(eval('typeof('+id+')')!='undefined') {
      shElement(eval(id),false);
    }
  }
}


function initIt()
{
  toMemory("/images/minimize.gif");
  toMemory("/images/restore.gif");
  applyShowHide();
  if(document.getElementById('login')) document.getElementById('login').focus();
}


var savedTop=-1;
var savedPageHeight=-1;
function menuUpdate(id,offset)
{
  var viewTop,viewBottom;
  var pos;

  if(savedTop==-1 || savedPageHeight==-1) {
    savedTop=getPageTop(id);
    savedPageHeight=getPageHeight();
  }
  else {
    viewTop=getPageScrollY();
    viewBottom=viewTop+getWindowHeight();

    pos=0;
    if(viewTop>savedTop) {
      if(viewTop>=savedPageHeight-offset) {
        pos=savedPageHeight-offset-savedTop;
      }
      else {
        pos=viewTop-savedTop;
      }
    }
    else {
      pos=0;
    }
    moveLayerTo(id,0,pos);
  }
  setTimeout('menuUpdate('+id.id+','+offset+')',100);
}


function setCookie(cookie,value)
{
  var date = new Date();
  date.setMonth(date.getMonth()+3);
  var expires = date.toGMTString();

  document.cookie=cookie+"="+escape(value)+"; expires="+expires+"; domain=.abn-ad.com";
}


function getCookie(sName)
{
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  return null;
}


function delCookie(sName)
{
  document.cookie = sName + "=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}


function delAllVisCookies()
{
  var aCookie = document.cookie.split("; ");
  if(confirm('Установить визуальные настройки по-умолчанию?')) {
    for (var i=0; i < aCookie.length; i++)
    {
      var aCrumb = aCookie[i].split("=");
      if(aCrumb[0].indexOf("vis")==0) {
        delCookie(aCrumb[0]);
      }
    }
    alert('Визуальные настройки сброшены');
  }
}


function toMemory(url) {
  var img=new Image;
  img.src=url;
  return (img);
}

function newwin(url,width,height) {
  window.open(url, 'window', 'width='+width+',height='+height+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
}
function spam_protect(object, to, domain){object.href="mailto:"+to+"@"+domain;}