
var XLPopup = {};

XLPopup.PresetColorGray = "#EBEBEB";
XLPopup.PresetColorGreen = "#5DD146";
XLPopup.PresetColorWhite = "#FFFFFF";
XLPopup.Area = false;
XLPopup.Visible = false;
XLPopup.TimerCodeId = -1;
XLPopup.AutoHide = false;
XLPopup.LastMouseOverMode = false;
XLPopup.LastMouseOverModeTime = false;
XLPopup.AutoHideSender = false;
XLPopup.AutoHideSenderOnMouseOver = false;
XLPopup.AutoHideSenderOnMouseOut = false;

XLPopup.DocumentHeightOfCreateTime = false;
XLPopup.CallBackBlockPanelClickCode = false;


XLPopup.CallBackBlockPanelClick = function ()
{
  if(!XLCommon.IsEmpty(XLPopup.CallBackBlockPanelClickCode))
  {
    eval(XLPopup.CallBackBlockPanelClickCode);
  }
}


XLPopup.Create = function (Preset, AutoHideSender)
{
  if(XLPopup.Visible) return false;
  XLPopup.DocumentHeightOfCreateTime = document.body.scrollHeight;
  
  
  var Offset = false;
  var Color = false;
  var Ie6 = !XLCommon.IsEmpty(XLConst.BrowserIe6);
  switch(Preset)
  {
    case "gray":
      Offset = 12;
      Color = XLPopup.PresetColorGray;
      break;
    case "green":
      Offset = 13;
      Color = XLPopup.PresetColorGreen;
      break;
    case "white":
      Offset = 10;
      Color = XLPopup.PresetColorWhite;
      break;
    default:
      return false;
  }
  if(!Ie6) Offset++;
  if(XLCommon.IsEmpty(XLPopup.Area))
  {
    XLPopup.Area = document.createElement("span");
    XLPopup.Area.setAttribute("id", "xlpopup-border");
    XLPopup.Area.style.position = "absolute";
    XLPopup.Area.style.zIndex = "2000";
    XLPopup.Area.style.top = "0";
    XLPopup.Area.style.left = "0";
    XLPopup.Area.style.margin = "0";
    XLPopup.Area.style.padding = "0";
    XLPopup.Area.style.display = "none";
    
    
    if(Ie6)
    {
      XLPopup.Area.style.width = "10px";
    }
    
    document.body.appendChild(XLPopup.Area);
  }
  else
  {
    XLPopup.Area.style.display = "none";
  }
  XLPopup.Area.innerHTML = "";
  XLPopup.LastMouseOverMode = false;
  XLPopup.LastMouseOverModeTime = false;
  if(XLCommon.IsEmpty(AutoHideSender))
  {
    XLPopup.Area.setAttribute("onmouseover", "");
    XLPopup.Area.setAttribute("onmouseout", "");
    XLPopup.AutoHide = false;
  }
  else
  {
    XLPopup.Area.onmouseover = function () { XLPopup.AutoHideUpdateInformation('over'); }
    XLPopup.Area.onmouseout = function () { XLPopup.AutoHideUpdateInformation('out'); }
    XLPopup.AutoHide = true;
    XLPopup.AutoHideSender = AutoHideSender;
    XLPopup.AutoHideSenderOnMouseOver = XLPopup.AutoHideSender.onmouseover;
    XLPopup.AutoHideSenderOnMouseOut = XLPopup.AutoHideSender.onmouseout;
    XLPopup.AutoHideSender.onmouseover = function () { XLPopup.AutoHideUpdateInformation('over'); }
    XLPopup.AutoHideSender.onmouseout = function () { XLPopup.AutoHideUpdateInformation('out'); }
  }
  var d1 = document.createElement("div");
  var d2 = document.createElement("div");
  var d3 = document.createElement("div");
  var d4 = document.createElement("div");
  var d5 = document.createElement("div");
  var d6 = document.createElement("div");
  var d7 = document.createElement("div");
  var d8 = document.createElement("div");
  var d9 = document.createElement("div");
  var d10 = document.createElement("div");
  var d11 = document.createElement("div");
  var d12 = document.createElement("div");
  var d13 = document.createElement("div");
  var d14 = document.createElement("div");
  var d15 = document.createElement("div");
  var d16 = document.createElement("div");
  var d17 = document.createElement("div");
  var d18 = document.createElement("div");
  var d19 = document.createElement("div");
  var d20 = document.createElement("div");
  var d21 = document.createElement("table");
  
  var d22 = document.createElement("tbody");
  var d23 = document.createElement("tr");
  var d24 = document.createElement("td");
  d1.style.background = "url('images/popup/" + Preset + "/corner-top-left.png') no-repeat top left";
  d1.className = "withpng";
  d1.appendChild(d2);
  d2.style.background = "url('images/popup/" + Preset + "/corner-top-right.png') no-repeat top right";
  d2.className = "withpng";
  d2.appendChild(d3);
  d3.style.background = "url('images/popup/" + Preset + "/corner-bottom-right.png') no-repeat bottom right";
  d3.className = "withpng";
  d3.appendChild(d4);
  d4.style.background = "url('images/popup/" + Preset + "/corner-bottom-left.png') no-repeat bottom left";
  d4.className = "withpng";

  d4.appendChild(d5);
  d4.style.paddingLeft = Offset + "px";
  d4.style.paddingRight = Offset + "px";
  d5.appendChild(d6);
  d6.style.background = "url('images/popup/" + Preset + "/gradient-top.png') repeat-x top left";
  d6.className = "withpng";
  d6.appendChild(d7);
  d7.style.marginLeft = "-" + Offset + "px";
  d7.style.marginRight = "-" + Offset + "px";
  d7.appendChild(d8);

  d8.appendChild(d9);
  d8.style.paddingLeft = Offset + "px";
  d8.style.paddingRight = Offset + "px";
  d9.appendChild(d10);
  d10.style.background = "url('images/popup/" + Preset + "/gradient-bottom.png') repeat-x bottom left";
  d10.className = "withpng";
  d10.appendChild(d11);
  d11.style.marginLeft = "-" + Offset + "px";
  d11.style.marginRight = "-" + Offset + "px";
  d11.appendChild(d12);

  d12.style.border = "0px";
  d12.style.paddingTop = Offset + "px";
  d12.style.paddingBottom = Offset + "px";
  d12.appendChild(d13);
  d13.style.border = "0px";
  d13.style.paddingLeft = Offset + "px";
  d13.style.background = "url('images/popup/" + Preset + "/gradient-left.png') repeat-y top left";
  d13.className = "withpng";
  d13.appendChild(d14);
  d14.style.border = "0px";
  d14.style.paddingRight = Offset + "px";
  d14.style.background = "url('images/popup/" + Preset + "/gradient-right.png') repeat-y top right";
  d14.className = "withpng";
  d14.appendChild(d20);
  d20.appendChild(d21);
  d21.cellSpacing = "0";
  d21.cellPadding = "0";
  d21.appendChild(d22);
  d22.appendChild(d23);
  d23.appendChild(d24);
  d24.setAttribute("id", "xlpopup");
  d24.style.backgroundColor = Color;
  
  XLPopup.Area.appendChild(d1);
  return true;
}


XLPopup.Show = function (FocusElementAfterShowId, InsertVerticalBeam)
{
  XLSite.BlockPanelHide();
  if(XLPopup.AutoHide)
  {
    XLPopup.TimerCodeId = XLTimer.AddCode('XLPopup.AutoHideFunction()');
  }
  else
  {
    XLSite.BlockPanelShow();
  }
  XLPopup.Area.style.display = "block";
  XLPopup.Visible = true;
  XLSite.InitBlockPanel();
  if(!XLCommon.IsEmpty(InsertVerticalBeam))
  {
    XLCommon.GetElement("mainarea-beam").innerHTML = "<img src = 'xlcms/images/point-trans.gif' height = '" + XLPopup.Area.offsetHeight + "' width = '1'/>";
    XLSite.InitBlockPanel();
  }
  if(!XLCommon.IsEmpty(FocusElementAfterShowId))
  {
    var fo = new Array();
    if(typeof(FocusElementAfterShowId) == "string")
    {
      fo[fo.length] = FocusElementAfterShowId;
    }
    else if(typeof(FocusElementAfterShowId) == "object")
    {
      fo = FocusElementAfterShowId;
    }
    for(var i = 0; i < fo.length; i++)
    {
      if(!XLCommon.IsEmpty(XLCommon.GetElement(fo[i])))
      {
        XLCommon.GetElement(fo[i]).focus();
        XLCommon.GetElement(fo[i]).focus();
        break;
      }
    }
  }
  
}


XLPopup.Hide = function ()
{
  XLPopup.Area.style.display = "none";
  XLSite.BlockPanelHide();
  XLPopup.CallBackBlockPanelClickCode = false;
  XLCommon.GetElement("mainarea-beam").innerHTML = "";
  XLPopup.Visible = false;
  if(XLPopup.AutoHide)
  {
    XLTimer.DelCode(XLPopup.TimerCodeId);
  }
  if(!XLCommon.IsEmpty(XLPopup.AutoHideSender))
  {
    XLPopup.AutoHideSender.onmouseover = XLPopup.AutoHideSenderOnMouseOver;
    XLPopup.AutoHideSender.onmouseout = XLPopup.AutoHideSenderOnMouseOut;
  }
  XLPopup.AutoHideSender = false;
}


XLPopup.AutoHideFunction = function ()
{
  var now = new Date();
  now = now.getTime();
  
  if(now > XLPopup.LastMouseOverModeTime + 100 && XLPopup.LastMouseOverMode == "out" && !XLXO.IsDataSending())
  {
    XLPopup.Hide();
  }
}


XLPopup.AutoHideUpdateInformation = function (Mode)
{
  
  XLPopup.LastMouseOverMode = Mode;
  var now = new Date();
  now = now.getTime();
  XLPopup.LastMouseOverModeTime = now;
}


XLPopup.ScrollUp = function ()
{
  
  
  if(!XLPopup.AutoHide && document.body.offsetHeight > XLPopup.Area.offsetHeight)
  {
    var ST = (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    if(XLCommon.GetElementPosition(XLPopup.Area).y + XLPopup.Area.offsetHeight - ST > document.body.offsetHeight)
    {
      var step = 20;
      var from = ST;
      var to = XLCommon.GetElementPosition(XLPopup.Area).y + XLPopup.Area.offsetHeight - document.body.offsetHeight;
      if(from > to)
      {
        var tmp = from; from = to; to = tmp;
      }
      for(var i = from + step; i < to; i += step)
      {
        window.scroll(0, i);
      }
      window.scroll(0, to);
    }
  }
}

XLPopup.CorrectDocumentHeight = function (ScrollUp)
{
  var HeightDelta = document.body.scrollHeight - XLPopup.DocumentHeightOfCreateTime;
  
  if(HeightDelta > 0)
  {
    HeightDelta += 55;
    
    XLCommon.GetElement("mainarea-beam").innerHTML = "<img src = 'xlcms/images/point-trans.gif' height = '" + HeightDelta + "' width = '1'/>";
  }
  if(!XLCommon.IsEmpty(ScrollUp)) XLPopup.ScrollUp();
  while(XLCommon.GetElement("mainarea").offsetHeight < document.body.scrollHeight)
  {
    
    HeightDelta += 10;
    XLCommon.GetElement("mainarea-beam").innerHTML = "<img src = 'xlcms/images/point-trans.gif' height = '" + HeightDelta + "' width = '1'/>";
  }
  
}



var XLSiteConst = {};

XLSiteConst.ErrorLoginSymbols = "registration-login-error-symbols";
XLSiteConst.ErrorLoginLength = "registration-login-error-length";
XLSiteConst.ErrorLoginFormat = "registration-login-error-format";
XLSiteConst.ErrorLoginExists = "registration-login-error-exists";
XLSiteConst.ErrorLoginEmpty = "registration-login-error-empty";
XLSiteConst.ErrorPasswordLoginMatch = "registration-password-error";
XLSiteConst.ErrorPasswordMismatch = "registration-password-error-mismatch";
XLSiteConst.ErrorPasswordEmpty = "registration-password-error-empty";
XLSiteConst.ErrorEmailWrong = "registration-email-error-wrong";
XLSiteConst.ErrorEmailExists = "registration-email-error-exists";
XLSiteConst.ErrorEmailEmpty = "registration-email-error-empty";
XLSiteConst.ErrorEmailMailRu = "registration-email-error-mailru";
XLSiteConst.ErrorCaptchaSymbols = "registration-captcha-error-symbols";
XLSiteConst.ErrorCaptchaEmpty = "registration-captcha-error-empty";
XLSiteConst.ErrorServer = "registration-error";
XLSiteConst.ErrorKabinetEmail = "kabinet-email-error";
XLSiteConst.ErrorKabinetEmailEmpty = "kabinet-email-error-empty";
XLSiteConst.ErrorKabinetEmailExists = "kabinet-email-error-exists";
XLSiteConst.ErrorKabinetEmailPassword = "kabinet-email-error-password";
XLSiteConst.ErrorKabinetEmailPasswordEmpty = "kabinet-email-error-password-empty";
XLSiteConst.ErrorKabinetPasswordEmpty = "kabinet-password-error-empty";
XLSiteConst.ErrorKabinetPasswordLength = "kabinet-password-error-length";
XLSiteConst.ErrorKabinetPasswordPassword = "kabinet-password-error-password";
XLSiteConst.ErrorKabinetPasswordMismatch = "kabinet-password-error-mismatch";



var XLSiteFirms = {};


XLSiteFirms.GetResult = function (Result, Data)
{
  if(Result == "OK")
  {
  }
  else
  {
    switch(Data.Action)
    {
      case "getfirmschapters":
        
        XLCommon.GetElement("firms-area").innerHTML = Result;
        
        if(!XLCommon.IsEmpty(XLCommon.GetElement("firms-browser-title")))
        {
          var sch = XLCommon.GetElement("firms-server-get-sch").innerHTML.Trim();
          if(document.location.href.indexOf("#") >= 0 || sch != "")
          {
            if(XLConst.IsBrowserGecko)
            {
              document.location = document.location.href.replace(/^([^\/]+)\/\/([^\/]+)\/(.*)$/g, "$1//$2/firms/#") + sch;
            }
          }
          document.title = XLCommon.GetElement("firms-browser-title").innerHTML;
        }
        break;
      case "getbankcard":
      case "getfirmcard":
        XLCommon.GetElement("xlpopup-firmcard-body").innerHTML = Result;
        XLPopup.CorrectDocumentHeight(true);
        XLSite.InitBlockPanel();
        XLPopup.CallBackBlockPanelClickCode = "XLPopup.Hide();"
        break;
      case "getfirm":
        
        XLSiteFirms.ExpandFirmComplete(Data.Gid, Result, Data.NextFirmNumber);
        break;
      default:
        alert(Result);
        break;
    }
  }
}


XLSiteFirms.LoadChapters = function (GidOrSch)
{
  if(!XLXO.IsDataSending())
  {
    XLCommon.GetElement("firms-loading").innerHTML = XLConst.StringLoading;
    XLCommon.CommonFormClear("getfirmschapters");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", GidOrSch);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteFirms.GetResult, {Action: "getfirmschapters"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSiteFirms.ExpandFirm = function (Gid, NextFirmNumber)
{
  if(!XLXO.IsDataSending())
  {
    XLCommon.GetElement("firms-" + Gid + "-arrow-arrow").style.display = "none";
    XLCommon.GetElement("firms-" + Gid + "-arrow-loading").style.display = "block";
    XLCommon.CommonFormClear("getfirm");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
    var Data = {Action: "getfirm", Gid: Gid};
    if(!XLCommon.IsEmpty(NextFirmNumber))
    {
      Data.NextFirmNumber = NextFirmNumber;
    }
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteFirms.GetResult, Data, XLCommon.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSiteFirms.ExpandFirmComplete = function (Gid, Body, NextFirmNumber)
{
  XLCommon.GetElement("firms-" + Gid + "-button-plus").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-button-minus").style.display = "block";
  XLCommon.GetElement("firms-" + Gid + "-arrow-loading").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-arrow-arrow").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-name").style.fontWeight = "bold";
  XLCommon.GetElement("firms-" + Gid + "-button").style.backgroundColor = "#EBEBEB";
  XLCommon.GetElement("firms-" + Gid + "-name").style.backgroundColor = "#EBEBEB";
  XLCommon.GetElement("firms-" + Gid + "-name-a").onclick = function () { XLSiteFirms.CollapseFirm(Gid); return false; };
  XLCommon.GetElement("firms-" + Gid + "-arrow").style.backgroundColor = "#EBEBEB";
  XLCommon.GetElement("firms-" + Gid).style.borderTop = "1px solid #C2C2C2";
  XLCommon.GetElement("firms-" + Gid).style.borderLeft = "1px solid #C2C2C2";
  XLCommon.GetElement("firms-" + Gid).style.borderRight = "1px solid #C2C2C2";
  XLCommon.GetElement("firms-" + Gid + "-body").innerHTML = Body;
  XLCommon.GetElement("firms-" + Gid + "-body").style.display = "block";
  XLSite.Initialize();
  if(!XLCommon.IsEmpty(NextFirmNumber))
  {
    var nextfirm = XLCommon.GetElement("firms-firm-number-" + NextFirmNumber);
    if(!XLCommon.IsEmpty(nextfirm))
    {
      XLSiteFirms.ExpandFirm(nextfirm.getAttribute("firmkey"), NextFirmNumber + 1);
    }
    else
    {
      XLSite.BlockPanelHide();
    }
  }
  return true;
}


XLSiteFirms.ExpandLoadedFirm = function (Gid)
{
  XLCommon.GetElement("firms-" + Gid + "-arrow-arrow").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-arrow-loading").style.display = "block";
  XLCommon.GetElement("firms-" + Gid + "-button-plus").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-button-minus").style.display = "block";
  XLCommon.GetElement("firms-" + Gid + "-arrow-loading").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-arrow-arrow").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-name").style.fontWeight = "bold";
  XLCommon.GetElement("firms-" + Gid + "-button").style.backgroundColor = "#EBEBEB";
  XLCommon.GetElement("firms-" + Gid + "-name").style.backgroundColor = "#EBEBEB";
  XLCommon.GetElement("firms-" + Gid + "-name-a").onclick = function () { XLSiteFirms.CollapseFirm(Gid); return false; };
  XLCommon.GetElement("firms-" + Gid + "-arrow").style.backgroundColor = "#EBEBEB";
  XLCommon.GetElement("firms-" + Gid).style.borderTop = "1px solid #C2C2C2";
  XLCommon.GetElement("firms-" + Gid).style.borderLeft = "1px solid #C2C2C2";
  XLCommon.GetElement("firms-" + Gid).style.borderRight = "1px solid #C2C2C2";
  XLCommon.GetElement("firms-" + Gid + "-body").style.display = "block";
}


XLSiteFirms.CollapseFirm = function (Gid)
{
  XLCommon.GetElement("firms-" + Gid + "-body").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-arrow-loading").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-arrow-arrow").style.display = "block";
  XLCommon.GetElement("firms-" + Gid + "-name").style.fontWeight = "";
  XLCommon.GetElement("firms-" + Gid + "-button-minus").style.display = "none";
  XLCommon.GetElement("firms-" + Gid + "-button-plus").style.display = "block";
  XLCommon.GetElement("firms-" + Gid + "-button").style.backgroundColor = "white";
  XLCommon.GetElement("firms-" + Gid + "-name").style.backgroundColor = "white";
  XLCommon.GetElement("firms-" + Gid + "-button-plus-image").onclick = function () { XLSiteFirms.ExpandLoadedFirm(Gid); return false; };
  XLCommon.GetElement("firms-" + Gid + "-name-a").onclick = function () { XLSiteFirms.PopupFirmViewShow(Gid, XLCommon.GetElement("firms-" + Gid + "-name-a")); return false; };
  XLCommon.GetElement("firms-" + Gid + "-arrow").style.backgroundColor = "white";
  XLCommon.GetElement("firms-" + Gid).style.borderTop = "1px solid #D6D6D6";
  XLCommon.GetElement("firms-" + Gid).style.borderLeft = "";
  XLCommon.GetElement("firms-" + Gid).style.borderRight = "";
  return true;
}


XLSiteFirms.ExpandAll = function ()
{
  var first = XLCommon.GetElement("firms-firm-number-1");
  if(!XLCommon.IsEmpty(first))
  {
    XLSite.BlockPanelShow();
    XLSiteFirms.ExpandFirm(first.getAttribute("firmkey"), 2);
  }
}



XLSiteFirms.TestUrl = function (Force)
{
  if(!XLConst.IsBrowserGecko) return false;
  var url = document.location.href.replace(/^(.*)#(.*)$/g, "$2");
  if(url == document.location.href) url = "";
  
  if(!XLCommon.IsEmpty(XLCommon.GetElement("firms-server-get-sch")))
  {
    if(XLCommon.GetElement("firms-server-get-sch").innerHTML.Trim() != url || !XLCommon.IsEmpty(Force))
    {
      XLSiteFirms.LoadChapters(url);
    }
    setTimeout("XLSiteFirms.TestUrl()", 100);
  }
  return true;
}


XLSiteFirms.SetUrl = function (Url)
{
  if(XLConst.IsBrowserGecko)
  {
    document.location = document.location.href.replace(/^([^\/]+)\/\/([^\/]+)\/(.*)$/g, "$1//$2/firms/#") + Url;
  }
  else
  {
    XLSiteFirms.LoadChapters(Url);
  }
}


XLSiteFirms.PopupFirmViewShow = function (Gid, Sender)
{
  if(!XLXO.IsDataSending())
  {
    if(XLPopup.Create("white")) 
    {
      XLCommon.GetElement("xlpopup").innerHTML = "";
      
      var d = document.createElement("div")
      d.setAttribute("id", "xlpopup-firmcard-body")
      d.style.padding = "4px 9px 9px 9px";
      d.style.fontSize = "8pt";
      d.innerHTML = "<table width = '610' cellspacing = '0' cellpadding = '0' border = '0'><tr><td>" + XLConst.StringLoading + "</td></tr></table>";
      
      XLCommon.GetElement("xlpopup").appendChild(d);
      
      
      
      if(Sender.offsetWidth + XLCommon.GetElementPosition(Sender).x > 700)
      {
        XLPopup.Area.style.left = Sender.offsetWidth + XLCommon.GetElementPosition(Sender).x - 643;
      }
      else
      {
        XLPopup.Area.style.left = XLCommon.GetElementPosition(Sender).x - 6;
      }
      XLPopup.Area.style.top = XLCommon.GetElementPosition(Sender).y + 8;
      XLPopup.Show(); 
      
      XLCommon.CommonFormClear("getfirmcard");
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteFirms.GetResult, {Action: "getfirmcard"}, XLCommon.CommonForm))
      {
        return true;
      }
    }
  }
}


XLSiteFirms.PopupBankViewShow = function (Gid, Sender)
{
  if(!XLXO.IsDataSending())
  {
    if(XLPopup.Create("white")) 
    {
      XLCommon.GetElement("xlpopup").innerHTML = "";
      
      var d = document.createElement("div")
      d.setAttribute("id", "xlpopup-firmcard-body")
      d.style.padding = "4px 9px 9px 9px";
      d.style.fontSize = "8pt";
      d.innerHTML = "<table width = '450' cellspacing = '0' cellpadding = '0' border = '0'><tr><td>" + XLConst.StringLoading + "</td></tr></table>";
      
      XLCommon.GetElement("xlpopup").appendChild(d);
      
      
      
      if(Sender.offsetWidth + XLCommon.GetElementPosition(Sender).x > 700)
      {
        XLPopup.Area.style.left = Sender.offsetWidth + XLCommon.GetElementPosition(Sender).x - 643;
      }
      else
      {
        XLPopup.Area.style.left = XLCommon.GetElementPosition(Sender).x - 6;
      }
      XLPopup.Area.style.top = XLCommon.GetElementPosition(Sender).y + 8;
      XLPopup.Show(); 
      
      XLCommon.CommonFormClear("getbankcard");
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteFirms.GetResult, {Action: "getbankcard"}, XLCommon.CommonForm))
      {
        return true;
      }
    }
  }
}



var XLSitePrivate = {};


XLSitePrivate.GetResult = function (Result, Data)
{
  if(Result == "OK")
  {
    switch(Data.Action)
    {
      case "clearconsultantstatistics":
        document.location.reload();
        break;
    }
  }
  else
  {
    switch(Data.Action)
    {
      default:
        alert(Result);
        break;
    }
  }
}


XLSitePrivate.ClearStatistics = function (Gid)
{
  if(!XLXO.IsDataSending())
  {
    if(confirm("Вы уверены?"))
    {
      
      XLCommon.CommonFormClear("clearconsultantstatistics");
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSitePrivate.GetResult, {Action: "clearconsultantstatistics"}, XLCommon.CommonForm))
      {
        return true;
      }
    }
  }
}



var XLSiteForums = {};

XLSiteForums.SelectedId = false; 


XLSiteForums.GetResult = function (Result, Data)
{
  if(Result == "OK")
  {
    switch(Data.Action)
    {
      case "login":
        break;
      case "moancomment":
        alert("Ваша жалоба принята");
        break;
      case "clearmoancomments":
        document.location.reload();
        break;
    }
  }
  else
  {
    switch(Data.Action)
    {
      case "delcomment":
      case "addcomment":
      case "movetheme":
        Result = new String(Result);
        if(Result.replace(/OK:(.+)/g, "") == "")
        {
          if(!XLCommon.IsEmpty(Data.ReloadOnly))
          {
            document.location.reload();
          }
          else
          {
            document.location = XLConst.SiteRoot + Result.substring(3);
          }
          return false;
        }
        else
        {
          alert(Result);
        }
        break;
      case "loaduseraccounts":
        
        if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup")))
        {
          XLCommon.GetElement("xlpopup").innerHTML = Result;
        }
        break;
      case "getforumchapters":
        
        
        if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-chapter")))
        {
          var OKD = "if(event.keyCode == XLConst.KeyCodeEscape) { XLPopup.Hide(); return false; }";
          XLCommon.GetElement("xlpopup-chapter-div").innerHTML = "<select name = 'chapter' style = 'width: 650px; ' id = 'xlpopup-chapter' onkeyup = '" + OKD + "'>" + Result + "</select>";
        }
        break;
      default:
        alert(Result);
        break;
    }
    if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-send")))
    {
      XLCommon.GetElement("xlpopup-send").disabled = false;
    }
  }
}



XLSiteForums.SelectComment = function (Identifier, Force)
{
  if(!XLCommon.IsEmpty(XLSiteForums.SelectedId) && !XLCommon.IsEmpty(XLCommon.GetElement(XLSiteForums.SelectedId)))
  {
    XLCommon.GetElement(XLSiteForums.SelectedId).style.backgroundColor = "";
  }
  if(!XLCommon.IsEmpty(Identifier) && !XLCommon.IsEmpty(XLCommon.GetElement(Identifier)))
  {
    XLCommon.GetElement(Identifier).style.backgroundColor = "#EDFEDF";
    XLSiteForums.SelectedId = Identifier;
    if(
      (!XLCommon.IsEmpty(document.documentElement.scrollTop) && document.documentElement.scrollTop > XLCommon.GetElementPosition(XLCommon.GetElement(Identifier)).y) ||
      (!XLCommon.IsEmpty(window.scrollY) && window.scrollY > XLCommon.GetElementPosition(XLCommon.GetElement(Identifier)).y) ||
      !XLCommon.IsEmpty(Force)
    )
    {
      window.scroll(0, XLCommon.GetElementPosition(XLCommon.GetElement(Identifier)).y);
    }
  }
}


XLSiteForums.PopupNewCommentShow = function (Sender, Theme, Gid)
{
  if(Sender && XLPopup.Create("gray")) 
  {
    XLCommon.GetElement("xlpopup").innerHTML = "";
    
    var OKD = "if(event.keyCode == XLConst.KeyCodeEscape) { XLPopup.Hide(); return false; }";
    var mf = document.createElement("form")
    mf.onsubmit = function (event) { XLSiteForums.PopupNewCommentSubmit(Gid); return false; };
    mf.style.padding = "10px 10px 0 10px";
    mf.setAttribute("id", "xlpopup-form");
    
    mf.style.backgroundColor = XLPopup.PresetColorGray;
    if(XLCommon.IsEmpty(XLConst.EnteredGid))
    {
      var d = document.createElement("div")
      d.innerHTML = "Чтобы писать сообщения от своего имени, получать уведомления об ответах<br/>и не вводить символы в защите от спама, необходимо войти на сайт или <a href = '/registration' target = '_blank'>зарегистрироваться</a>";
      d.style.padding = "0 0 10px 0";
      mf.appendChild(d);
    }
    
    if(!XLCommon.IsEmpty(Theme))
    {
      var d = document.createElement("div")
      d.innerHTML = "Заголовок темы";
      d.style.padding = "0 0 3px 0";
      mf.appendChild(d);
      var d = document.createElement("div")
      d.style.padding = "0 0 10px 0";
      d.innerHTML = "<input name = 'caption' style = 'width: 650px;' id = 'xlpopup-caption' onkeyup = '" + OKD + "' maxlength = '250'>";
      mf.appendChild(d);
      var d = document.createElement("div")
      d.innerHTML = "Текст";
      mf.appendChild(d);
    }
    var d = document.createElement("div")
    d.style.padding = "0 0 10px 0";
    d.innerHTML = "<textarea name = 'text' style = 'width: 650px; height: 200px;' id = 'xlpopup-text' onkeyup = '" + OKD + "'>";
    mf.appendChild(d);
    if(XLCommon.IsEmpty(XLConst.EnteredGid))
    {
      var d = document.createElement("div")
      d.innerHTML = "Введите символы, указанные на картинке";
      d.style.padding = "0 0 3px 0";
      mf.appendChild(d);
      var d = document.createElement("div")
      d.style.padding = "0 0 10px 0";
      d.style.verticalAlign = "top";
      d.innerHTML = "<table cellpadding = '0' cellspacing = '0' border = '0' style = 'border-collapse: collapse;'><tr><td align = 'left' valign = 'top'><input id = 'xlpopup-captcha' style = 'width: 100px;'></td><td align = 'left' valign = 'top'>&nbsp;&nbsp;&nbsp;</td><td align = 'left' valign = 'top'><img class = 'captcha' id = 'xlpopup-captcha-image' src = '?ac=captcha'></td><td align = 'left' valign = 'top'>&nbsp;&nbsp;&nbsp;</td><td align = 'left' valign = 'top' class = 'comment-small'>Если символы<br>видны неразборчиво,<br><a class = 'small' href = '#update' onclick = \"XLCommon.GetElement('xlpopup-captcha-image').setAttribute('src', '?ac=captcha&rnd=' + XLCommon.Random(1, 1000000)); return false;\">обновите картинку</a></td></tr></table>";
      mf.appendChild(d);
    }
    var d = document.createElement("div");
    d.style.paddingTop = "10px";
    var b1 = document.createElement("button");
    b1.setAttribute("type", "submit");
    b1.setAttribute("id", "xlpopup-send");
    b1.innerHTML = "Отправить";
    b1.onclick = function (event) { XLSiteForums.PopupNewCommentSubmit(Gid); return false; };
    var b2 = document.createElement("button");
    b2.setAttribute("type", "button");
    b2.innerHTML = "Отмена";
    b2.onclick = function (event) { XLPopup.Hide(); return false; };
    b2.style.marginLeft = "10px";
    d.appendChild(b1);
    d.appendChild(b2);
    mf.appendChild(d);
    
    XLCommon.GetElement("xlpopup").appendChild(mf);
    var sx = XLCommon.GetElementPosition(Sender).x;
    var sy = XLCommon.GetElementPosition(Sender).y;
    XLPopup.Area.style.left = (sx - 10) + "px";
    XLPopup.Area.style.top = (sy + 5) + "px";
    var cbbpcc = "";
    cbbpcc += "var e1 = (!XLCommon.IsEmpty(XLCommon.GetElement('xlpopup-caption')) ? XLCommon.GetElement('xlpopup-caption').value.Trim() == '' : true);";
    cbbpcc += "var e2 = (!XLCommon.IsEmpty(XLCommon.GetElement('xlpopup-text')) ? XLCommon.GetElement('xlpopup-text').value.Trim() == '' : true);";
    cbbpcc += "var e3 = (!XLCommon.IsEmpty(XLCommon.GetElement('xlpopup-captcha')) ? XLCommon.GetElement('xlpopup-captcha').value.Trim() == '' : true);";
    cbbpcc += "if(e1 && e2 && e3) XLPopup.Hide();";
    XLPopup.Show(new Array("xlpopup-caption", "xlpopup-text")); 
    XLPopup.CallBackBlockPanelClickCode = cbbpcc;
    XLPopup.CorrectDocumentHeight(true);
    XLSite.InitBlockPanel();
  }
}


XLSiteForums.PopupNewCommentSubmit = function (Gid)
{
  if(!XLCommon.GetElement("xlpopup-send").disabled)
  {
    if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-caption")))
    {
      if(XLCommon.GetElement("xlpopup-caption").value.Trim() == "")
      {
        alert("Необходимо указать заголовок");
        return false;
      }
    }
    if(XLCommon.GetElement("xlpopup-text").value.Trim() == "")
    {
      alert("Нужен текст");
      return false;
    }
    if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-captcha")))
    {
      if(XLCommon.GetElement("xlpopup-captcha").value.Trim() == "")
      {
        alert("Введите символы, указанные на картинке");
        return false;
      }
    }
    if(!XLXO.IsDataSending())
    {
      XLCommon.CommonFormClear("addcomment");
      if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-caption")))
      {
        XLCommon.FormSetNameValue(XLCommon.CommonForm, "caption", XLCommon.GetElement("xlpopup-caption").value.Trim());
      }
      if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-captcha")))
      {
        XLCommon.FormSetNameValue(XLCommon.CommonForm, "captcha", XLCommon.GetElement("xlpopup-captcha").value.Trim());
      }
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "text", XLCommon.GetElement("xlpopup-text").value.Trim());
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteForums.GetResult, {Action: "addcomment"}, XLCommon.CommonForm))
      {
        XLCommon.GetElement("xlpopup-send").disabled = true;
        return true;
      }
    }
  }
  return false;
}


XLSiteForums.DeleteComment = function (Gid, ReloadOnly)
{
  if(confirm("Вы уверены в этом?"))
  {
    if(!XLXO.IsDataSending())
    {
      XLCommon.CommonFormClear("delcomment");
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteForums.GetResult, {Action: "delcomment", ReloadOnly: ReloadOnly}, XLCommon.CommonForm))
      {
        return true;
      }
    }
  }
  return false;
}


XLSiteForums.ClearMoanComments = function ()
{
  if(!XLXO.IsDataSending())
  {
    XLCommon.CommonFormClear("clearmoancomments");
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteForums.GetResult, {Action: "clearmoancomments"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSiteForums.MoanComment = function (Gid)
{
  if(!XLXO.IsDataSending())
  {
    XLCommon.CommonFormClear("moancomment");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteForums.GetResult, {Action: "moancomment"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSiteForums.PopupThemeReplaceShow = function (Sender, Gid, ReloadOnly)
{
  if(Sender && XLPopup.Create("gray") && !XLXO.IsDataSending()) 
  {
    XLCommon.GetElement("xlpopup").innerHTML = "";
    
    var OKD = "if(event.keyCode == XLConst.KeyCodeEscape) { XLPopup.Hide(); return false; }";
    var mf = document.createElement("form")
    mf.onsubmit = function () { XLSiteForums.PopupThemeReplaceSubmit(Gid, !XLCommon.IsEmpty(ReloadOnly)); return false; }
    mf.style.padding = "10px 10px 10px 10px";
    var d = document.createElement("div")
    d.style.padding = "0 0 10px 0";
    d.setAttribute("id", "xlpopup-chapter-div");
    d.innerHTML = "<select name = 'chapter' style = 'width: 650px; ' id = 'xlpopup-chapter' onkeyup = '" + OKD + "' disabled><option selected>Загрузка...</option></select>";
    mf.appendChild(d);
    var d = document.createElement("div");
    d.style.paddingTop = "10px";
    var b1 = document.createElement("button");
    b1.setAttribute("type", "submit");
    b1.setAttribute("id", "xlpopup-send");
    b1.innerHTML = "Переместить";
    var b2 = document.createElement("button");
    b2.setAttribute("type", "button");
    b2.innerHTML = "Отмена";
    b2.onclick = function () { XLPopup.Hide(); return false; }
    b2.style.marginRight = "10px";
    d.appendChild(b1);
    d.innerHTML += "&nbsp;";
    d.appendChild(b2);
    mf.appendChild(d);
    
    XLCommon.GetElement("xlpopup").appendChild(mf);
    var sx = XLCommon.GetElementPosition(Sender).x;
    var sy = XLCommon.GetElementPosition(Sender).y;
    XLPopup.Area.style.left = (sx - 10) + "px";
    XLPopup.Area.style.top = (sy + 5) + "px";
    XLPopup.Show(); 
    XLPopup.CallBackBlockPanelClickCode = "if(!XLXO.IsDataSending()) XLPopup.Hide();";
    
    
    XLCommon.CommonFormClear("getforumchapters");
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteForums.GetResult, {Action: "getforumchapters"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSiteForums.PopupThemeReplaceSubmit = function (Gid, ReloadOnly)
{
  if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-chapter")))
  {
    if(XLCommon.GetElement("xlpopup-chapter").value <= 0)
    {
      alert("Необходимо выбрать раздел");
      return false;
    }
    if(!XLXO.IsDataSending() && confirm("Вы уверены, что хотите перенести эту тему?"))
    {
      XLCommon.CommonFormClear("movetheme");
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "chapterkey", XLCommon.GetElement("xlpopup-chapter").value);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteForums.GetResult, {Action: "movetheme", ReloadOnly: ReloadOnly}, XLCommon.CommonForm))
      {
        XLCommon.GetElement("xlpopup-send").disabled = true;
        return true;
      }
    }
  }
  return false;
}


XLSiteForums.PopupUserAccountsShow = function (Sender, Gid)
{
  if(Sender && XLPopup.Create("white", Sender) && !XLXO.IsDataSending()) 
  {
    XLCommon.GetElement("xlpopup").innerHTML = "";
    
    var d = document.createElement("div")
    d.style.padding = "0 0 0 0";
    d.innerHTML = XLConst.StringLoading;
    
    XLCommon.GetElement("xlpopup").appendChild(d);
    var sx = XLCommon.GetElementPosition(Sender).x;
    var sy = XLCommon.GetElementPosition(Sender).y;
    XLPopup.Area.style.left = (sx - 5) + "px";
    XLPopup.Area.style.top = (sy - 5) + "px";
    XLPopup.Show(); 
    XLCommon.CommonFormClear("loaduseraccounts");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteForums.GetResult, {Action: "loaduseraccounts"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
  return false;
}



var XLSiteVote = {};

XLSiteVote.TimerTimePoint = 0;
XLSiteVote.TimerCodeId = -1;
XLSiteVote.TimerLeft = 18;


XLSiteVote.GetResult = function (Result, Data)
{
  if(Result == "OK")
  {
    switch(Data.Action)
    {
      case "sendvote":
        alert("Ваш голос учтен");
        document.location.reload();
        break;
      case "sharephoto":
        document.location = XLConst.Base + "photovote/players";
        break;
    }
  }
  else
  {
    switch(Data.Action)
    {
      case "sendvote":
        alert(Result);
        break;
      default:
        alert(Result);
        break;
    }
  }
}


XLSiteVote.PopupRegistrationShow = function (Sender)
{
  if(Sender && XLPopup.Create("white", Sender) && !XLXO.IsDataSending()) 
  {
    XLCommon.GetElement("xlpopup").innerHTML = "";
    
    var d = document.createElement("div")
    d.style.padding = "0 5px 0 5px";
    d.innerHTML = "<nobr>Для участия в конкурсе необходимо</nobr><br/><nobr><a href = '" + XLConst.Base + "registration'>зарегистрироваться</a> на сайте.</nobr><br/><nobr>Это займет совсем немного времени.</nobr>";
    
    XLCommon.GetElement("xlpopup").appendChild(d);
    var sx = XLCommon.GetElementPosition(Sender).x;
    var sy = XLCommon.GetElementPosition(Sender).y;
    XLPopup.Area.style.left = (sx - 5) + "px";
    XLPopup.Area.style.top = (sy + 18) + "px";
    XLPopup.Show(); 
  }
  return false;
}


XLSiteVote.LoadPhotoScroll = function ()
{
  
  
  var y1 = (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  var y2 = XLCommon.GetElement("index-bottom").offsetTop;
  if(y1 < y2 && y2 > 0)
  {
    var step = 20;
    for(var i = y1 + step; i < y2; i += step)
    {
      window.scroll(0, i);
    }
    window.scroll(0, y2);
  }
}


XLSiteVote.SendPhoto = function ()
{
  XLCommon.GetElement("photoloading").innerHTML = XLConst.StringLoading;
  document.forms.photovotefile.submit();
}


XLSiteVote.SharePhoto = function ()
{
  if(!XLXO.IsDataSending())
  {
    
    XLCommon.CommonFormClear("sharephoto");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "comment", document.forms.photovotefile.comment.value);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteVote.GetResult, {Action: "sharephoto"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
}


XLSiteVote.Vote = function ()
{
  if(!XLXO.IsDataSending())
  {
    
    XLCommon.CommonFormClear("sendvote");
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSiteVote.GetResult, {Action: "sendvote"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
}

XLSiteVote.CorrectHeights = function ()
{
  var h = 0;
  for(var i = 1; true; i++)
  {
    var e = XLCommon.GetElement("player-number-" + i);
    if(!XLCommon.IsEmpty(e))
    {
      h = (h < e.offsetHeight ? e.offsetHeight : h);
    }
    else
    {
      break;
    }
  }
  
  if(h > 0)
  {
    for(var i = 1; true; i++)
    {
      var e = XLCommon.GetElement("player-number-" + i);
      if(!XLCommon.IsEmpty(e))
      {
        e.style.height = h + "px";
      }
      else
      {
        break;
      }
    }
  }
}


XLSiteVote.StartVoiceTimer = function ()
{
  XLSiteVote.TimerTimePoint = new Date().getTime();
  XLCommon.GetElement("photovote-voice-button-alt").innerHTML = "Проголосовать за фотографию можно будет через " + XLSiteVote.TimerLeft + " сек.";
  XLCommon.GetElement("photovote-voice-button-off").style.display = "block";
  XLSiteVote.TimerCodeId = XLTimer.AddCode('XLSiteVote.TimerFunction()');
}


XLSiteVote.TimerFunction = function ()
{
  if(new Date().getTime() > XLSiteVote.TimerTimePoint + 1000)
  {
    XLSiteVote.TimerTimePoint = new Date().getTime();
    XLSiteVote.TimerLeft--;
    if(XLSiteVote.TimerLeft <= 0)
    {
      XLTimer.DelCode(XLSiteVote.TimerCodeId);
      XLCommon.GetElement("photovote-voice-button-off").style.display = "none";
      XLCommon.GetElement("photovote-voice-button").style.display = "block";
    }
    else
    {
      XLCommon.GetElement("photovote-voice-button-alt").innerHTML = "Проголосовать за фотографию можно будет через " + XLSiteVote.TimerLeft + " сек.";
    }
  }
}



var XLSite = {};

XLSite.CommonForm = document.createElement("form"); XLSite.CommonForm.setAttribute("method", "post"); 
XLSite.BlockPanel = false;
XLSite.PopupPhotosWidth = 300;
XLSite.MainAreaMinWidth = 930;
XLSite.MainAreaMaxWidth = 1200;


XLSite.CorrectWidth = function ()
{
  var ScrollWidth = 100;
  if(XLConst.ScreenWidth > 0 && document.body.offsetWidth > 0) 
  {
    if(XLCommon.IsEmpty(XLCommon.GetElement("mainareawidth")))
    {
      if(document.body.offsetWidth - ScrollWidth <= XLSite.MainAreaMinWidth) 
      {
        document.write("<img id = 'mainareawidth' src = 'xlcms/images/point-trans.gif' width = '" + XLSite.MainAreaMinWidth + "' height = '1'/>");
      }
      else if(document.body.offsetWidth - ScrollWidth < XLSite.MainAreaMaxWidth) 
      {
        document.write("<img id = 'mainareawidth' src = 'xlcms/images/point-trans.gif' width = '" + (document.body.offsetWidth - ScrollWidth) + "' height = '1'/>");
      }
      else
      {
        document.write("<img id = 'mainareawidth' src = 'xlcms/images/point-trans.gif' width = '" + XLSite.MainAreaMaxWidth + "' height = '1'/>");
      }
    }
    else if(XLConst.ScreenWidth > XLSite.MainAreaMaxWidth) 
    {
      if(document.body.offsetWidth - ScrollWidth <= XLSite.MainAreaMinWidth) 
      {
        XLCommon.GetElement("mainareawidth").setAttribute("width", XLSite.MainAreaMinWidth);
      }
      else if(document.body.offsetWidth - ScrollWidth < XLSite.MainAreaMaxWidth) 
      {
        XLCommon.GetElement("mainareawidth").setAttribute("width", document.body.offsetWidth - ScrollWidth);
      }
      else
      {
        XLCommon.GetElement("mainareawidth").setAttribute("width", XLSite.MainAreaMaxWidth);
      }
    }
  }
}


XLSite.GetResult = function (Result, Data)
{
  if(Result == "OK")
  {
    switch(Data.Action)
    {
      case "feedback":
        XLPopup.Hide();
        alert("Спасибо. Ваше сообщение отправлено");
        break;
      case "subscriptionviewed":
        var area = XLCommon.GetElement("kabinet-comment-" + Data.ObjectKey);
        if(!XLCommon.IsEmpty(area))
        {
          var elems = area.getElementsByTagName("*");
          for(var i = 0; i < elems.length; i++)
          {
            if(elems.item(i).tagName.toUpperCase() == "A")
            {
              if(new String(elems.item(i).className).toUpperCase() == "SMALL")
              {
                elems.item(i).className = "kabinet-comments-viewed-small";
              }
              else
              {
                elems.item(i).className = "kabinet-comments-viewed";
              }
            }
            else if(elems.item(i).tagName.toUpperCase() == "DIV" && new String(elems.item(i).className).toUpperCase() == "KABINET-COMMENTS-NORMAL")
            {
              elems.item(i).className = "kabinet-comments-viewed";
            }
          }
        }
        break;
      case "clearkabinetcomments":
      case "login":
      case "logoff":
        document.location.reload();
        break;
      case "kabinet":
        XLCommon.GetElement("kabinet-button-save").disabled = false;
        alert("Данные сохранены успешно");
        break;
      case "kabinet-email":
        XLCommon.GetElement("kabinet-email-area").innerHTML = "Адрес e-mail успешно изменен. Осталось подтвердить новый адрес. Вам уже отправлено письмо с подтверждением.<br>Обычно письмо приходит сразу же, но иногда может немного задержаться. Ссылка подтверждения в письме действительна в течение трех дней.";
        break;
      case "kabinet-password":
        XLCommon.GetElement("kabinet-password-area").innerHTML = "Ваш пароль успешно изменен.";
        break;
      case "kabinet-photo-delete":
        XLCommon.GetElement("kabinet-photo-loading").innerHTML = "";
        XLCommon.GetElement("kabinet-photo").style.display = "none";
        break;
      case "newpass":
        document.location = XLConst.SiteRoot + "newpass/sent";
        break;
      case "newpass-password":
        document.location = XLConst.SiteRoot + "kabinet";
        break;
    }
  }
  else
  {
    if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-send"))) XLCommon.GetElement("xlpopup-send").disabled = false;
    if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-enter"))) XLCommon.GetElement("xlpopup-enter").disabled = false;
    if(!XLCommon.IsEmpty(XLCommon.GetElement("kabinet-button-save"))) XLCommon.GetElement("kabinet-button-save").disabled = false;
    if(!XLCommon.IsEmpty(XLCommon.GetElement("kabinet-options-button-save"))) XLCommon.GetElement("kabinet-options-button-save").disabled = false;
    if(!XLCommon.IsEmpty(XLCommon.GetElement("registration-loading"))) XLCommon.GetElement("registration-loading").innerHTML = "";
    switch(Data.Action)
    {
      case "getrandompresent":
        var Result = new String(Result);
        var d = XLCommon.GetElement("present-random");
        if(!XLCommon.IsEmpty(d))
        {
          d.innerHTML = Result;
        }
        break;
      case "loadrategraphics":
        var Result = new String(Result);
        var d = XLCommon.GetElement("ratedynamics");
        if(!XLCommon.IsEmpty(d))
        {
          d.innerHTML = Result;
        }
        break;
      case "loadbankratebody":
        var Result = new String(Result);
        var d = XLCommon.GetElement("bankratesbody");
        if(!XLCommon.IsEmpty(d))
        {
          d.innerHTML = Result;
        }
        
        break;
      case "unsubscriptuserobject":
      case "subscriptuserobject":
        var Result = new String(Result);
        if(Result == "unsubscripted") 
        {
          if(XLCommon.IsEmpty(XLCommon.GetElement("subscription-" + Data.ObjectKey + "-off")))
          {
            document.location.reload();
            break;
          }
          XLCommon.GetElement("subscription-" + Data.ObjectKey + "-off").style.display = "none";
          XLCommon.GetElement("subscription-" + Data.ObjectKey + "-on").style.display = "inline";
        }
        else if(Result == "subscripted") 
        {
          if(XLCommon.IsEmpty(XLCommon.GetElement("subscription-" + Data.ObjectKey + "-off")))
          {
            document.location.reload();
            break;
          }
          XLCommon.GetElement("subscription-" + Data.ObjectKey + "-on").style.display = "none";
          XLCommon.GetElement("subscription-" + Data.ObjectKey + "-off").style.display = "inline";
        }
        else
        {
          alert(Result);
        }
        break;
      case "getdiscountcardrubrics":
        var d = XLCommon.GetElement("discountcardrubricsandoffers");
        if(!XLCommon.IsEmpty(d))
        {
          d.innerHTML = Result;
        }
        break;
      case "loadgalleryphoto":
      case "loadfirmphotos":
      case "loaduserphotos":
        var d = XLCommon.GetElement("xlpopup-photos-view");
        if(!XLCommon.IsEmpty(d))
        {
          
          d.innerHTML = Result;
          XLSite.PopupPhotosCorrect();
        }
        break;
      case "addcomment":
        alert(Result);
        break;
      case "gettreecomments":
        var d = XLCommon.GetElement(Data.CommentId);
        if(!XLCommon.IsEmpty(d))
        {
          d.innerHTML = "";
          d.style.padding = "0 0 0 20px";
          d.innerHTML = Result;
        }
        break;
      case "newpass":
        XLSite.RegistrationError(Result);
        break;
      case "newpass-password":
        var Result = new String(Result);
        
        XLSite.KabinetPasswordError(Result);
        break;
      case "registration":
        var Result = new String(Result);
        if(Result.IndexOf(":") >= 0) 
        {
          var R = Result.split(":");
          document.location = XLConst.SiteRoot + "registration/sent/" + R[1];
        }
        else
        {
          XLSite.RegistrationError(Result);
        }
        break;
      case "kabinet-email":
        var Result = new String(Result);
        XLSite.KabinetEmailError(Result);
        break;
      case "kabinet-password":
        var Result = new String(Result);
        XLSite.KabinetPasswordError(Result);
        break;
      case "kabinet-photos":
      case "kabinet-photos-delete":
        var photos = XLCommon.GetElement("kabinet-photos");
        XLCommon.GetElement("kabinet-photos-loading").innerHTML = "";
        if(Result.Trim().substr(0, 1) == '<')
        {
          photos.innerHTML = Result;
          XLCommon.GetElement("kabinet-photos-load").style.display = (XLCommon.IsEmpty(XLCommon.GetElement("kabinet-photos-number-3")) ? "block" : "none");
        }
        else
        {
          alert(Result);
        }
        break;
      case "kabinet-photo-delete":
        if(Result.replace(/^([0-9a-f]+)$/g, "") == "")
        {
          document.title = Result;
        }
        else
        {
          alert(Result);
        }
        break;
      case "getarticlebody":
        var Result = new String(Result);
        var d = XLCommon.GetElement("xlpopup-article-body");
        if(!XLCommon.IsEmpty(d))
        {
          d.innerHTML = Result;
        }
        break;
      default:
        alert(Result);
        break;
    }
  }
}



XLSite.CommonFormClear = function (Action)
{
  if(!XLCommon.IsEmpty(XLSite.CommonForm))
  {
    XLSite.CommonForm.innerHTML = "<input name = 'action' value = '" + Action + "'>";
    return true;
  }
  return false;
}


XLSite.PopupEnterShow = function (Sender)
{
  if(Sender && XLPopup.Create("green")) 
  {
    var OKU = "if(event.keyCode == XLConst.KeyCodeEscape) { XLPopup.Hide(); return false; }";
    var PopupHtml = "";
    XLCommon.GetElement("xlpopup").innerHTML = "";
    
    PopupHtml += "<form style = 'padding: 0; margin: 0;' onsubmit = 'XLSite.PopupEnterSubmit(); return false;'>";
    PopupHtml += "<table cellpadding = '0' cellspacing = '0' border = '0'><tbody>";
    PopupHtml += "<tr><td><img src = 'xlcms/images/point-trans.gif' width = '30' height = '1'></td><td></td><td align = 'right' valign = 'top' style = 'font-size: 8pt; color: white;'>Вход&nbsp;&nbsp;<br><img src = 'xlcms/images/point-trans.gif' width = '30' height = '1'></td></tr>";
    PopupHtml += "<tr><td></td><td><div style = 'padding: 0 0 4px 0; color: white;'>Логин</div><input name = 'login' style = 'width: 262px;' id = 'xlpopup-login' onkeyup = '" + OKU + "'></td><td></td></tr>";
    PopupHtml += "<tr><td></td><td><div style = 'padding: 10px 0 4px 0; color: white;'>Пароль</div><input name = 'password' type = 'password' style = 'width: 262px;' id = 'xlpopup-password' onkeyup = '" + OKU + "'></td><td></td></tr>";
    PopupHtml += "<tr><td></td><td><div style = 'padding: 10px 0 0 0;'><input type = 'checkbox' id = 'xlpopup-checkbox' style = 'padding: 0; margin: 0; border: 0;' onkeyup = '" + OKU + "'>&nbsp;<label for = 'xlpopup-checkbox' style = 'color: white;'>Запомнить меня на этом компьютере</label></div></td><td></td></tr>";
    PopupHtml += "<tr><td></td><td><div style = 'padding-top: 10px; margin-bottom: 20px;'><button id = 'xlpopup-enter' type = 'submit' style = 'margin-right: 10px;' onkeyup = '" + OKU + "'>Войти</button><button style = 'margin-right: 10px;' onclick = 'XLPopup.Hide(); return false;' onkeyup = '" + OKU + "'>Закрыть</button><a href = '" + XLConst.SiteRoot + "newpass' style = 'color: white;' onkeyup = '" + OKU + "'>Забыли пароль?</a></div></td><td></td></tr>";
    PopupHtml += "</tbody></table>";
    PopupHtml += "</form>";
    
    XLCommon.GetElement("xlpopup").innerHTML = PopupHtml;
    var sx = XLCommon.GetElementPosition(Sender).x;
    var sy = XLCommon.GetElementPosition(Sender).y;
    XLPopup.Area.style.left = (sx - 302) + "px";
    XLPopup.Area.style.top = (sy - 11) + "px";
    XLPopup.Show("xlpopup-login"); 
    XLPopup.CallBackBlockPanelClickCode = "if(XLCommon.GetElement('xlpopup-login').value.Trim() == '' && XLCommon.GetElement('xlpopup-password').value.Trim() == '') XLPopup.Hide();";
    
  }
}


XLSite.PopupEnterSubmit = function ()
{
  XLCommon.GetElement("xlpopup-enter").disabled = true;
  if(XLCommon.GetElement("xlpopup-login").value.Trim() == "" || XLCommon.GetElement("xlpopup-password").value == "")
  {
    alert("Необходимо указать и логин и пароль");
    XLCommon.GetElement("xlpopup-enter").disabled = false;
  }
  else if(!XLXO.IsDataSending())
  {
    XLSite.CommonFormClear("login");
    XLCommon.FormSetNameValue(XLSite.CommonForm, "login", XLCommon.GetElement("xlpopup-login").value.Trim());
    XLCommon.FormSetNameValue(XLSite.CommonForm, "password", XLCommon.GetElement("xlpopup-password").value);
    if(XLCommon.GetElement("xlpopup-checkbox").checked)
    {
      XLCommon.FormSetNameValue(XLSite.CommonForm, "remember", true);
    }
    if(!XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "login"}, XLSite.CommonForm))
    {
      XLCommon.GetElement("xlpopup-enter").disabled = false;
    }
  }
  else
  {
    XLCommon.GetElement("xlpopup-enter").disabled = false;
  }
  return false;
}


XLSite.Logoff = function ()
{
  if(!XLXO.IsDataSending())
  {
    XLSite.CommonFormClear("logoff");
    
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "logoff"}, XLSite.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSite.LogoffAnywhere = function ()
{
  if(!XLXO.IsDataSending())
  {
    XLSite.CommonFormClear("logoff-anywhere");
    
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "logoff"}, XLSite.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSite.Registration = function ()
{
  XLSite.RegistrationError("");
  var l = XLCommon.GetElement("registration-login");
  var p1 = XLCommon.GetElement("registration-password1");
  var p2 = XLCommon.GetElement("registration-password2");
  var e = XLCommon.GetElement("registration-email");
  var c = XLCommon.GetElement("registration-captcha");
  var r = XLCommon.GetElement("registration-referer");
  if(!XLXO.IsDataSending())
  {
    XLCommon.GetElement("registration-button-apply").disabled = false;
    XLSite.CommonFormClear("registration");
    XLCommon.FormSetNameValue(XLSite.CommonForm, "login", l.value.Trim());
    XLCommon.FormSetNameValue(XLSite.CommonForm, "password1", p1.value);
    XLCommon.FormSetNameValue(XLSite.CommonForm, "password2", p2.value);
    XLCommon.FormSetNameValue(XLSite.CommonForm, "email", e.value);
    XLCommon.FormSetNameValue(XLSite.CommonForm, "captcha", c.value);
    XLCommon.FormSetNameValue(XLSite.CommonForm, "referer", r.value);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "registration"}, XLSite.CommonForm))
    {
      XLCommon.GetElement("registration-button-apply").disabled = true;
      XLCommon.GetElement("registration-loading").innerHTML = XLConst.StringLoading;
    }
  }
  return false;
}


XLSite.NewPassword = function ()
{
  var e = XLCommon.GetElement("registration-email");
  var c = XLCommon.GetElement("registration-captcha");
  if(!XLXO.IsDataSending())
  {
    XLCommon.GetElement("registration-button-apply").disabled = false;
    XLSite.CommonFormClear("newpass");
    XLCommon.FormSetNameValue(XLSite.CommonForm, "email", e.value);
    XLCommon.FormSetNameValue(XLSite.CommonForm, "captcha", c.value);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "newpass"}, XLSite.CommonForm))
    {
      XLCommon.GetElement("registration-button-apply").disabled = true;
      XLCommon.GetElement("registration-loading").innerHTML = XLConst.StringLoading;
    }
  }
  return false;
}


XLSite.RegistrationError = function (Error)
{
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorLoginSymbols))) XLCommon.GetElement(XLSiteConst.ErrorLoginSymbols).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorLoginLength))) XLCommon.GetElement(XLSiteConst.ErrorLoginLength).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorLoginFormat))) XLCommon.GetElement(XLSiteConst.ErrorLoginFormat).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorLoginExists))) XLCommon.GetElement(XLSiteConst.ErrorLoginExists).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorLoginEmpty))) XLCommon.GetElement(XLSiteConst.ErrorLoginEmpty).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorPasswordLoginMatch))) XLCommon.GetElement(XLSiteConst.ErrorPasswordLoginMatch).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorPasswordMismatch))) XLCommon.GetElement(XLSiteConst.ErrorPasswordMismatch).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorPasswordEmpty))) XLCommon.GetElement(XLSiteConst.ErrorPasswordEmpty).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorEmailWrong))) XLCommon.GetElement(XLSiteConst.ErrorEmailWrong).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorEmailMailRu))) XLCommon.GetElement(XLSiteConst.ErrorEmailMailRu).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorEmailExists))) XLCommon.GetElement(XLSiteConst.ErrorEmailExists).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorEmailEmpty))) XLCommon.GetElement(XLSiteConst.ErrorEmailEmpty).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorCaptchaSymbols))) XLCommon.GetElement(XLSiteConst.ErrorCaptchaSymbols).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorCaptchaEmpty))) XLCommon.GetElement(XLSiteConst.ErrorCaptchaEmpty).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorServer))) XLCommon.GetElement(XLSiteConst.ErrorServer).style.display = "none";
  if(new String(Error).Trim() != "")
  {
    var Errors = Error.split(",");
    for(var i = 0; i < Errors.length; i++)
    {
      if(!XLCommon.IsEmpty(XLCommon.GetElement(Errors[i].Trim()))) XLCommon.GetElement(Errors[i].Trim()).style.display = "block";
    }
    if(!XLCommon.IsEmpty(XLCommon.GetElement("registration-button-apply"))) XLCommon.GetElement("registration-button-apply").disabled = false;
  }
}
XLSite.KabinetEmailError = function (Error)
{
  XLCommon.GetElement(XLSiteConst.ErrorKabinetEmail).style.display = "none";
  XLCommon.GetElement(XLSiteConst.ErrorKabinetEmailEmpty).style.display = "none";
  XLCommon.GetElement(XLSiteConst.ErrorKabinetEmailExists).style.display = "none";
  XLCommon.GetElement(XLSiteConst.ErrorKabinetEmailPassword).style.display = "none";
  XLCommon.GetElement(XLSiteConst.ErrorKabinetEmailPasswordEmpty).style.display = "none";
  var Errors = Error.split(",");
  for(var i = 0; i < Errors.length; i++)
  {
    XLCommon.GetElement(Errors[i].Trim()).style.display = "block";
  }
  XLCommon.GetElement("kabinet-button-email-apply").disabled = false;
}
XLSite.KabinetPasswordError = function (Error)
{
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorKabinetPasswordEmpty))) XLCommon.GetElement(XLSiteConst.ErrorKabinetPasswordEmpty).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorKabinetPasswordLength))) XLCommon.GetElement(XLSiteConst.ErrorKabinetPasswordLength).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorKabinetPasswordPassword))) XLCommon.GetElement(XLSiteConst.ErrorKabinetPasswordPassword).style.display = "none";
  if(!XLCommon.IsEmpty(XLCommon.GetElement(XLSiteConst.ErrorKabinetPasswordMismatch))) XLCommon.GetElement(XLSiteConst.ErrorKabinetPasswordMismatch).style.display = "none";
  var Errors = Error.split(",");
  for(var i = 0; i < Errors.length; i++)
  {
    XLCommon.GetElement(Errors[i].Trim()).style.display = "block";
  }
  XLCommon.GetElement("kabinet-button-password-apply").disabled = false;
}


XLSite.KabinetSave = function ()
{
  var bd = XLCommon.GetElement("kabinet-burn-day");
  var bm = XLCommon.GetElement("kabinet-burn-month");
  var by = XLCommon.GetElement("kabinet-burn-year");
  if(bd.value + bm.value + by.value != "" && (bd.value == "" || bm.value == "" || by.value == ""))
  {
    alert("Дата введена неверно");
    return false;
  }
  var b = bd.value + bm.value + by.value;
  if(!XLXO.IsDataSending())
  {
    var fn = XLCommon.GetElement("kabinet-firstname");
    var sn = XLCommon.GetElement("kabinet-secondname");
    var sm = XLCommon.GetElement("kabinet-sex-male");
    var sf = XLCommon.GetElement("kabinet-sex-female");
    var t = XLCommon.GetElement("kabinet-town");
    var p = XLCommon.GetElement("kabinet-phones");
    var i = XLCommon.GetElement("kabinet-icq");
    var s = XLCommon.GetElement("kabinet-sites");
    var a = XLCommon.GetElement("kabinet-about");
    var bs = XLCommon.GetElement("kabinet-button-save");
    XLSite.CommonFormClear("kabinet");
    XLCommon.FormSetNameValue(XLSite.CommonForm, "name", fn.value.Trim());
    XLCommon.FormSetNameValue(XLSite.CommonForm, "surname", sn.value.Trim());
    XLCommon.FormSetNameValue(XLSite.CommonForm, "sex", sm.checked ? "male" : (sf.checked ? "female" : ""));
    XLCommon.FormSetNameValue(XLSite.CommonForm, "burn", b == "" ? "" : by.value + "-" + (bm.value < 10 ? "0" + bm.value : bm.value) + "-" + (bd.value < 10 ? "0" + bd.value : bd.value));
    XLCommon.FormSetNameValue(XLSite.CommonForm, "town", t.value.Trim());
    XLCommon.FormSetNameValue(XLSite.CommonForm, "phones", p.value.Trim());
    XLCommon.FormSetNameValue(XLSite.CommonForm, "icq", i.value.Trim());
    XLCommon.FormSetNameValue(XLSite.CommonForm, "sites", s.value.Trim());
    XLCommon.FormSetNameValue(XLSite.CommonForm, "about", a.value.Trim());
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "kabinet"}, XLSite.CommonForm))
    {
      bs.disabled = true; 
    }
  }
}


XLSite.KabinetEmailSave = function ()
{
  var e = XLCommon.GetElement("kabinet-email-new");
  var p = XLCommon.GetElement("kabinet-email-password");
  var bs = XLCommon.GetElement("kabinet-button-email-apply");
  if(!XLXO.IsDataSending())
  {
    XLSite.CommonFormClear("kabinet-email");
    XLCommon.FormSetNameValue(XLSite.CommonForm, "email", e.value.Trim());
    XLCommon.FormSetNameValue(XLSite.CommonForm, "password", p.value);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "kabinet-email"}, XLSite.CommonForm))
    {
      bs.disabled = true; 
    }
  }
}


XLSite.KabinetPasswordSave = function ()
{
  var p1 = XLCommon.GetElement("kabinet-password-new1");
  var p2 = XLCommon.GetElement("kabinet-password-new2");
  var p = XLCommon.GetElement("kabinet-password-current");
  var bs = XLCommon.GetElement("kabinet-button-password-apply");
  if(!XLXO.IsDataSending())
  {
    XLSite.CommonFormClear("kabinet-password");
    XLCommon.FormSetNameValue(XLSite.CommonForm, "password1", p1.value);
    XLCommon.FormSetNameValue(XLSite.CommonForm, "password2", p2.value);
    XLCommon.FormSetNameValue(XLSite.CommonForm, "password", p.value);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "kabinet-password"}, XLSite.CommonForm))
    {
      bs.disabled = true; 
    }
  }
}



XLSite.NewPasswordSave = function ()
{
  var p1 = XLCommon.GetElement("kabinet-password-new1");
  var p2 = XLCommon.GetElement("kabinet-password-new2");
  var bs = XLCommon.GetElement("kabinet-button-password-apply");
  if(!XLXO.IsDataSending())
  {
    XLSite.CommonFormClear("newpass-password");
    XLCommon.FormSetNameValue(XLSite.CommonForm, "password1", p1.value);
    XLCommon.FormSetNameValue(XLSite.CommonForm, "password2", p2.value);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "newpass-password"}, XLSite.CommonForm))
    {
      bs.disabled = true; 
    }
  }
}



XLSite.KabinetEmailSaveSetVisible = function ()
{
  if(!XLCommon.IsEmpty(XLCommon.GetElement("kabinet-email-area")))
  {
    if(XLCommon.GetElement("kabinet-email-area").style.display == "none")
    {
      XLCommon.GetElement("kabinet-email-area").style.display = "block";
      XLCommon.GetElement("kabinet-email-new").focus();
    }
    else
    {
      XLCommon.GetElement("kabinet-email-area").style.display = "none";
    }
  }
}



XLSite.KabinetPasswordSaveSetVisible = function ()
{
  if(!XLCommon.IsEmpty(XLCommon.GetElement("kabinet-password-new1")))
  {
    if(XLCommon.GetElement("kabinet-password-area").style.display == "none")
    {
      XLCommon.GetElement("kabinet-password-area").style.display = "block";
      XLCommon.GetElement("kabinet-password-new1").focus();
    }
    else
    {
      XLCommon.GetElement("kabinet-password-area").style.display = "none";
    }
  }
}




XLSite.KabinetPhotoEdit = function (Gallery, Key)
{
  var w = 450, h = 480;
  var l = Math.round((XLConst.ScreenWidth - w) / 2), t = Math.round((XLConst.ScreenHeight - h) / 2);
  window.open(XLConst.Base + "?ac=kabinet-image&gallery=" + (!XLCommon.IsEmpty(Gallery) ? "1" : "") + "&key=" + (!XLCommon.IsEmpty(Key) ? Key : ""), "_blank", "width=" + w + ",height=" + h + ",left=" + l + ",top=" + t + "scrollbars=no");
}




XLSite.KabinetPhotoDelete = function (Gallery, Key)
{
  if(!XLXO.IsDataSending())
  {
    if(XLCommon.IsEmpty(Gallery)) 
    {
      if(!confirm("Вы уверены?")) return false;
      XLSite.CommonFormClear("kabinet-photo-delete");
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "kabinet-photo-delete"}, XLSite.CommonForm))
      {
        XLCommon.GetElement("kabinet-photo-loading").innerHTML = XLConst.StringLoading;
      }
    }
    else if(!XLCommon.IsEmpty(Key)) 
    {
      if(!confirm("Вы уверены?")) return false;
      XLSite.CommonFormClear("kabinet-photos-delete");
      XLCommon.FormSetNameValue(XLSite.CommonForm, "key", Key);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "kabinet-photos-delete"}, XLSite.CommonForm))
      {
        XLCommon.GetElement("kabinet-photos-loading").innerHTML = XLConst.StringLoading;
      }
    }
  }
}


XLSite.KabinetPhotosRefresh = function ()
{
  if(!XLXO.IsDataSending())
  {
    XLSite.CommonFormClear("kabinet-photos");
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "kabinet-photos"}, XLSite.CommonForm))
    {
      XLCommon.GetElement("kabinet-photos-loading").innerHTML = XLConst.StringLoading;
    }
  }
}


XLSite.KabinetPhotoRefresh = function (Hash)
{
  XLCommon.GetElement("kabinet-photo-avatar").setAttribute("src", "?ch=image&hash=" + Hash + "&bounds=150x150");
  XLCommon.GetElement("kabinet-photo").style.display = "block";
}


XLSite.OnOff = function (OnId, OffId, ObjectId)
{
  var on = XLCommon.GetElement(OnId);
  var off = XLCommon.GetElement(OffId);
  var obj = XLCommon.GetElement(ObjectId);
  
  if(!XLCommon.IsEmpty(on) && !XLCommon.IsEmpty(off) && !XLCommon.IsEmpty(obj))
  {
    if(obj.style.display != "none")
    {
      obj.style.display = "none";
      on.style.display = "inline";
      off.style.display = "none";
    }
    else
    {
      obj.style.display = "block";
      var elems = obj.getElementsByTagName("*");
      for(var i = 0; i < elems.length; i++)
      {
        if(elems.item(i).tagName.toUpperCase() == "IMG")
        {
          if(new String(elems.item(i).src).replace(/^(.+)\.png$/g, "") == "" && new String(elems.item(i).className).toUpperCase() == "")
          {
            if(elems.item(i).offsetWidth)
            {
              elems.item(i).className = "withpng";
            }
          }
        }
      }
      on.style.display = "none";
      off.style.display = "inline";
    }
  }
}


XLSite.LoadTreeComments = function (CommentKey, CommentId)
{
  var d = XLCommon.GetElement(CommentId);
  if(!XLXO.IsDataSending() && !XLCommon.IsEmpty(d))
  {
    XLSite.CommonFormClear("gettreecomments");
    XLCommon.FormSetNameValue(XLSite.CommonForm, "key", CommentKey);
    d.innerHTML = XLConst.StringLoading;
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "gettreecomments", CommentId: CommentId}, XLSite.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSite.InitBlockPanel = function ()
{
  if(XLCommon.IsEmpty(XLSite.BlockPanel))
  {
    XLSite.BlockPanel = XLCommon.GetElement("block-panel");
  }
  if(!XLCommon.IsEmpty(XLSite.BlockPanel) && !XLCommon.IsEmpty(XLCommon.GetElement("mainarea")))
  {
    XLSite.BlockPanel.style.height = XLCommon.GetElement("mainarea").offsetHeight + "px";
  }
  XLSite.BlockPanel.className = "block-panel-gray";
}


XLSite.Initialize = function ()
{
  XLSite.CorrectWidth();
  if(!XLCommon.IsEmpty(XLCommon.GetElement("block-panel")))
  {
    XLSite.InitBlockPanel();
  }
}


XLSite.BlockPanelShow = function ()
{
  XLSite.InitBlockPanel();
  XLSite.BlockPanel.style.display = "block";
}


XLSite.BlockPanelHide = function ()
{
  XLSite.InitBlockPanel();
  XLSite.BlockPanel.style.display = "none";
}


XLSite.PopupExitShow = function (Sender)
{
  if(Sender && XLPopup.Create("white", Sender)) 
  {
    XLCommon.GetElement("xlpopup").innerHTML = "";
    
    var d = document.createElement("div")
    d.style.padding = "0 0 0 0";
    d.style.fontSize = "8pt";
    d.innerHTML = "<nobr>&nbsp;или <a href = '#exitanywhere' onclick = 'XLSite.LogoffAnywhere(); return false;' class = 'small'>Выйти на всех компьютерах</a>&nbsp;</nobr>";
    
    XLCommon.GetElement("xlpopup").appendChild(d);
    var sx = XLCommon.GetElementPosition(Sender).x;
    var sy = XLCommon.GetElementPosition(Sender).y;
    var sh = Sender.offsetHeight;
    XLPopup.Area.style.left = (sx - 150) + "px";
    XLPopup.Area.style.top = (sy + sh) + "px";
    XLPopup.Show(); 
  }
}


XLSite.UpdateMainMenuItems = function (SearchString)
{
  if(!XLCommon.IsEmpty(SearchString))
  {
    if(SearchString.value.Trim() != "")
    {
      XLCommon.GetElement("mainmenu-item-firms").href = XLConst.SiteRoot + "?ch=search&chapter=firms&text=" + SearchString.value.Trim();
      XLCommon.GetElement("mainmenu-item-forums").href = XLConst.SiteRoot + "?ch=search&chapter=forums&text=" + SearchString.value.Trim();
      XLCommon.GetElement("mainmenu-item-discount").href = XLConst.SiteRoot + "?ch=search&chapter=discount&text=" + SearchString.value.Trim();
    }
    else
    {
      XLCommon.GetElement("mainmenu-item-firms").href = XLConst.SiteRoot + "firms";
      XLCommon.GetElement("mainmenu-item-forums").href = XLConst.SiteRoot + "forums";
      XLCommon.GetElement("mainmenu-item-discount").href = XLConst.SiteRoot + "discount";
    }
  }
}


XLSite.LoadCardRubricsAndOffers = function (CardKey, RubricKey, LoadingElementId)
{
  if(!XLXO.IsDataSending() && CardKey > 0 && RubricKey > 0)
  {
    XLSite.CommonFormClear("getdiscountcardrubrics");
    XLCommon.FormSetNameValue(XLSite.CommonForm, "gid", CardKey);
    XLCommon.FormSetNameValue(XLSite.CommonForm, "rubrickey", RubricKey);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "getdiscountcardrubrics"}, XLSite.CommonForm))
    {
      if(!XLCommon.IsEmpty(LoadingElementId))
      {
        var e = XLCommon.GetElement(LoadingElementId);
        if(!XLCommon.IsEmpty(e))
        {
          e.innerHTML = XLConst.StringLoading;
        }
      }
      return true;
    }
  }
  return false;
}


XLSite.PopupPhotosViewShow = function (Gid, PhotoNumber)
{
  if(!XLXO.IsDataSending())
  {
    if(XLPopup.Create("white")) 
    {
      XLCommon.GetElement("xlpopup").innerHTML = "";
      
      var d = document.createElement("div")
      d.style.padding = "10px 5px 10px 5px";
      d.style.fontSize = "8pt";
      d.innerHTML = "<table width = '" + XLSite.PopupPhotosWidth + "' height = '50' cellspacing = '0' cellpadding = '0' border = '0'><tr><td align = 'center' valign = 'middle' id = 'xlpopup-photos-view'>" + XLConst.StringLoading + "</td></tr></table>";
      
      XLCommon.GetElement("xlpopup").appendChild(d);
      
      
      
      XLPopup.Area.style.left = XLCommon.GetMiddleWindowLeft(XLSite.PopupPhotosWidth);
      XLPopup.Area.style.top = 50 + (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
      XLPopup.Show(); 
      XLPopup.CallBackBlockPanelClickCode = "XLPopup.Hide();";
      
      XLCommon.CommonFormClear("loaduserphotos");
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "number", PhotoNumber);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "loaduserphotos"}, XLCommon.CommonForm))
      {
        return true;
      }
    }
  }
}


XLSite.PopupPhotosCorrect = function ()
{
  var p = XLCommon.GetElement("xlpopup-photo");
  XLPopup.Area.style.left = XLCommon.GetMiddleWindowLeft((XLSite.PopupPhotosWidth > p.getAttribute("initw") / 1 ? XLSite.PopupPhotosWidth : p.getAttribute("initw") / 1) + 20) + "px";
  p.style.display = "inline";
}


XLSite.PopupPhotosViewGo = function (Gid, PhotoNumber)
{
  if(!XLXO.IsDataSending())
  {
    
    XLCommon.GetElement("xlpopup-photo-span").innerHTML = XLConst.StringLoading;
    XLCommon.CommonFormClear("loaduserphotos");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "number", PhotoNumber);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "loaduserphotos"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
}


XLSite.Subscribe = function (ObjectKey)
{
  if(!XLXO.IsDataSending())
  {
    XLCommon.CommonFormClear("subscriptuserobject");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "object", ObjectKey);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "subscriptuserobject", ObjectKey: ObjectKey}, XLCommon.CommonForm))
    {
      return true;
    }
  }
}


XLSite.UnSubscribe = function (ObjectKey)
{
  if(!XLXO.IsDataSending())
  {
    XLCommon.CommonFormClear("unsubscriptuserobject");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "object", ObjectKey);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "unsubscriptuserobject", ObjectKey: ObjectKey}, XLCommon.CommonForm))
    {
      return true;
    }
  }
}


XLSite.ClearKabinetComments = function (Filter)
{
  if(!XLXO.IsDataSending())
  {
    XLCommon.CommonFormClear("clearkabinetcomments");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "filter", Filter);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "clearkabinetcomments"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
}


XLSite.SetSubscriptionViewed = function (ObjectKey)
{
  if(!XLXO.IsDataSending())
  {
    XLCommon.CommonFormClear("subscriptionviewed");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "object", ObjectKey);
    XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "subscriptionviewed", ObjectKey: ObjectKey}, XLCommon.CommonForm);
  }
  return true;
}


XLSite.KabinetOptionsSave = function ()
{
  if(!XLXO.IsDataSending())
  {
    var komp = XLCommon.GetElement("kabinet-options-mailnote-permanently");
    var kom = XLCommon.GetElement("kabinet-options-mailnote");
    var komo = XLCommon.GetElement("kabinet-options-mailnote-off");
    var bs = XLCommon.GetElement("kabinet-options-button-save");
    if(!XLCommon.IsEmpty(komp) && !XLCommon.IsEmpty(kom) && !XLCommon.IsEmpty(komo))
    {
      XLSite.CommonFormClear("kabinet-options");
      if(komp.checked) XLCommon.FormSetNameValue(XLSite.CommonForm, "mailnote", "permanently");
      else if(kom.checked) XLCommon.FormSetNameValue(XLSite.CommonForm, "mailnote", "");
      else XLCommon.FormSetNameValue(XLSite.CommonForm, "mailnote", "off");
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "kabinet-options"}, XLSite.CommonForm))
      {
        bs.disabled = true; 
      }
    }
  }
}


XLSite.PopupFirmPhotosViewShow = function (Gid, PhotoNumber)
{
  if(!XLXO.IsDataSending())
  {
    if(XLPopup.Create("white")) 
    {
      XLCommon.GetElement("xlpopup").innerHTML = "";
      
      var d = document.createElement("div")
      d.style.padding = "10px 5px 10px 5px";
      d.style.fontSize = "8pt";
      d.innerHTML = "<table width = '" + XLSite.PopupPhotosWidth + "' height = '50' cellspacing = '0' cellpadding = '0' border = '0'><tr><td align = 'center' valign = 'middle' id = 'xlpopup-photos-view'>" + XLConst.StringLoading + "</td></tr></table>";
      
      XLCommon.GetElement("xlpopup").appendChild(d);
      
      
      
      XLPopup.Area.style.left = XLCommon.GetMiddleWindowLeft(XLSite.PopupPhotosWidth);
      XLPopup.Area.style.top = 50 + (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
      XLPopup.Show(); 
      XLPopup.CallBackBlockPanelClickCode = "XLPopup.Hide();";
      
      XLCommon.CommonFormClear("loadfirmphotos");
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "number", PhotoNumber);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "loadfirmphotos"}, XLCommon.CommonForm))
      {
        return true;
      }
    }
  }
}


XLSite.PopupObjectPhotosViewShow = function (Gid, PhotoNumber)
{
  if(!XLXO.IsDataSending())
  {
    if(XLPopup.Create("white")) 
    {
      XLCommon.GetElement("xlpopup").innerHTML = "";
      
      var d = document.createElement("div")
      d.style.padding = "10px 5px 10px 5px";
      d.style.fontSize = "8pt";
      d.innerHTML = "<table width = '" + XLSite.PopupPhotosWidth + "' height = '50' cellspacing = '0' cellpadding = '0' border = '0'><tr><td align = 'center' valign = 'middle' id = 'xlpopup-photos-view'>" + XLConst.StringLoading + "</td></tr></table>";
      
      XLCommon.GetElement("xlpopup").appendChild(d);
      
      
      
      XLPopup.Area.style.left = XLCommon.GetMiddleWindowLeft(XLSite.PopupPhotosWidth);
      XLPopup.Area.style.top = 50 + (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
      XLPopup.Show(); 
      XLPopup.CallBackBlockPanelClickCode = "XLPopup.Hide();";
      
      XLCommon.CommonFormClear("loadgalleryphoto");
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "number", PhotoNumber);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "loadgalleryphoto"}, XLCommon.CommonForm))
      {
        return true;
      }
    }
  }
}


XLSite.PopupObjectPhotosViewGo = function (Gid, PhotoNumber, PostAction)
{
  if(!XLXO.IsDataSending())
  {
    
    XLCommon.GetElement("xlpopup-photo-span").innerHTML = XLConst.StringLoading;
    XLCommon.CommonFormClear(PostAction);
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "number", PhotoNumber);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: PostAction}, XLCommon.CommonForm))
    {
      return true;
    }
  }
}


XLSite.ScrollToComments = function ()
{
  if(!XLCommon.IsEmpty(XLCommon.GetElement("object-comments")))
  {
    var y1 = (document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
    var y2 = XLCommon.GetElementPosition(XLCommon.GetElement("object-comments")).y;
    var d = (y2 - y1) / 20;
    if(y1 < y2)
    {
      for(var i = y1; i < y2; i += d)
      {
        window.scroll(0, i);
      }
      window.scroll(0, y2);
    }
  }
}


XLSite.PopupRateSelectShow = function (Sender, Rate, Period)
{
  if(Sender && XLPopup.Create("white", Sender) && !XLXO.IsDataSending()) 
  {
    XLCommon.GetElement("xlpopup").innerHTML = "";
    
    var d = document.createElement("div")
    d.style.padding = "0 5px 0 5px";
    d.innerHTML = "";
    for(var i = 1; true; i++)
    {
      var rid = XLCommon.GetElement("rate-currency-id-" + i);
      var rname = XLCommon.GetElement("rate-currency-name-" + i);
      if(!XLCommon.IsEmpty(rid) && !XLCommon.IsEmpty(rname))
      {
        if(Rate == rid.innerHTML.Trim()) continue;
        d.innerHTML += "<div style = 'padding: 2px 5px 2px 5px;'><a href = '#period" + Period + "' onclick = 'XLSite.LoadRateGraphics(" + '"' + rid.innerHTML.Trim() + '"' + ", " + Period + "); return false;' class = 'dotted'><span class = 'dotted2px'>" + rname.innerHTML.Trim() + "</span></a></div>";
      }
      else
      {
        break;
      }
    }
    for(var i = 1; true; i++)
    {
      var rid = XLCommon.GetElement("rate-metal-id-" + i);
      var rname = XLCommon.GetElement("rate-metal-name-" + i);
      if(!XLCommon.IsEmpty(rid) && !XLCommon.IsEmpty(rname))
      {
        if(Rate == rid.innerHTML.Trim()) continue;
        d.innerHTML += "<div style = 'padding: 2px 5px 2px 5px;'><a href = '#period" + Period + "' onclick = 'XLSite.LoadRateGraphics(" + '"' + rid.innerHTML.Trim() + '"' + ", " + Period + "); return false;' class = 'dotted'><span class = 'dotted2px'>" + rname.innerHTML.Trim() + "</span></a></div>";
      }
      else
      {
        break;
      }
    }
    
    XLCommon.GetElement("xlpopup").appendChild(d);
    var sx = XLCommon.GetElementPosition(Sender).x;
    var sy = XLCommon.GetElementPosition(Sender).y;
    XLPopup.Area.style.left = (sx - 5) + "px";
    XLPopup.Area.style.top = (sy + 18) + "px";
    XLPopup.Show(); 
  }
  return false;
}


XLSite.LoadRateGraphics = function (Rate, Period)
{
  if(!XLXO.IsDataSending())
  {
    
    if(XLPopup.Visible) XLPopup.Hide();
    XLCommon.GetElement("rategraphicsimage").style.opacity = 0.3;
    XLCommon.GetElement("rategraphicsimage").style.filter = "alpha(opacity=30)";
    XLCommon.GetElement("rategraphicsloading").style.display = 'block';
    XLCommon.CommonFormClear("loadrategraphics");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "rate", Rate);
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "period", Period);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "loadrategraphics"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSite.LoadBankRateValues = function (Rate, SortRate, SortField)
{
  if(!XLXO.IsDataSending())
  {
    var d = XLCommon.GetElement("loadingstr");
    if(!XLCommon.IsEmpty(d))
    {
      d.innerHTML = XLConst.StringLoading;
    }
    
    XLCommon.CommonFormClear("loadbankratebody");
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "rate", Rate);
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "sortrate", SortRate);
    XLCommon.FormSetNameValue(XLCommon.CommonForm, "sortfield", SortField);
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "loadbankratebody"}, XLCommon.CommonForm))
    {
      return true;
    }
  }
  return false;
}


XLSite.SendRates = function ()
{
  XLCommon.GetElement("uploadratesloading").innerHTML = XLConst.StringLoading;
  document.forms.uploadratesfile.submit();
}


XLSite.PhotoGalleryShowPage = function (PageNumber)
{
  for(var i = 0; true; i++)
  {
    var d = XLCommon.GetElement("photogallery-" + i);
    if(!XLCommon.IsEmpty(d))
    {
      d.style.display = "none";
      d.style.visibility = "hidden";
    }
    else
    {
      break;
    }
  }
  var d = XLCommon.GetElement("photogallery-" + PageNumber);
  var nd = XLCommon.GetElement("photogallery-" + ((PageNumber - 1) + 2));
  
  
  if(!XLCommon.IsEmpty(d))
  {
    var e = d.getElementsByTagName("*");
    for(var i = 0; i < e.length; i++)
    {
      if(e[i].getAttribute("name") == "leftbutton" && PageNumber > 1)
      {
        var oc = "onclick = 'XLSite.PhotoGalleryShowPage(" + (PageNumber - 1) + "); return false;'";
        e[i].innerHTML = "<img style = 'cursor: pointer;' " + oc + "src = 'images/back.gif'/>  <a href = '#left' " + oc + " class = 'dotted'><span class = 'dotted2px'>назад</span></a>";
      }
      if(e[i].getAttribute("name") == "rightbutton" && !XLCommon.IsEmpty(nd))
      {
        var oc = "onclick = 'XLSite.PhotoGalleryShowPage(" + ((PageNumber - 1) + 2) + "); return false;'";
        e[i].innerHTML = "<a href = '#right' " + oc + " class = 'dotted'><span class = 'dotted2px'>ещё фото</span></a>  <img style = 'cursor: pointer;' " + oc + " src = 'images/forward.gif'/>";
      }
      if(!XLCommon.IsEmpty(e[i].getAttribute("setsrc")))
      {
        e[i].setAttribute("src", e[i].getAttribute("setsrc"));
      }
    }
    d.style.display = "inline";
    d.style.visibility = "";
  }
}


XLSite.PopupFeedBack = function (Sender, Chapter, Prompt, TextDefault, Gid)
{
  if(Sender && XLPopup.Create("gray")) 
  {
    XLCommon.GetElement("xlpopup").innerHTML = "";
    
    var OKD = "if(event.keyCode == XLConst.KeyCodeEscape) { XLPopup.Hide(); return false; }";
    var mf = document.createElement("form")
    mf.onsubmit = function (event) { XLSite.PopupFeedBackSubmit(Chapter, Gid); return false; };
    mf.style.padding = "10px 10px 0 10px";
    mf.setAttribute("id", "xlpopup-form");
    
    mf.style.backgroundColor = XLPopup.PresetColorGray;
    
    var d = document.createElement("div")
    d.innerHTML = Prompt;
    d.style.padding = "0 0 7px 0";
    mf.appendChild(d);
    var d = document.createElement("div")
    d.style.padding = "0 0 10px 0";
    d.innerHTML = "<textarea name = 'text' style = 'width: 650px; height: 200px;' id = 'xlpopup-text' onkeyup = '" + OKD + "'>" + TextDefault + "</textarea>";
    mf.appendChild(d);
    if(XLCommon.IsEmpty(XLConst.EnteredGid))
    {
      var d = document.createElement("div")
      d.innerHTML = "Введите символы, указанные на картинке";
      d.style.padding = "0 0 3px 0";
      mf.appendChild(d);
      var d = document.createElement("div")
      d.style.padding = "0 0 10px 0";
      d.style.verticalAlign = "top";
      d.innerHTML = "<table cellpadding = '0' cellspacing = '0' border = '0' style = 'border-collapse: collapse;'><tr><td align = 'left' valign = 'top'><input id = 'xlpopup-captcha' style = 'width: 100px;'></td><td align = 'left' valign = 'top'>&nbsp;&nbsp;&nbsp;</td><td align = 'left' valign = 'top'><img class = 'captcha' id = 'xlpopup-captcha-image' src = '?ac=captcha&rnd=" + XLCommon.Random(1, 1000000) + "'></td><td align = 'left' valign = 'top'>&nbsp;&nbsp;&nbsp;</td><td align = 'left' valign = 'top' class = 'comment-small'>Если символы<br>видны неразборчиво,<br><a class = 'small' href = '#update' onclick = \"XLCommon.GetElement('xlpopup-captcha-image').setAttribute('src', '?ac=captcha&rnd=' + XLCommon.Random(1, 1000000)); return false;\">обновите картинку</a></td></tr></table>";
      mf.appendChild(d);
    }
    var d = document.createElement("div");
    d.style.paddingTop = "10px";
    var b1 = document.createElement("button");
    b1.setAttribute("type", "submit");
    b1.setAttribute("id", "xlpopup-send");
    b1.innerHTML = "Отправить";
    b1.onclick = function (event) { XLSite.PopupFeedBackSubmit(Chapter, Gid); return false; };
    var b2 = document.createElement("button");
    b2.setAttribute("type", "button");
    b2.innerHTML = "Отмена";
    b2.onclick = function (event) { XLPopup.Hide(); return false; };
    b2.style.marginLeft = "10px";
    d.appendChild(b1);
    d.appendChild(b2);
    mf.appendChild(d);
    
    XLCommon.GetElement("xlpopup").appendChild(mf);
    var sx = XLCommon.GetElementPosition(Sender).x;
    var sy = XLCommon.GetElementPosition(Sender).y;
    if(sx > 600) XLPopup.Area.style.left = (sx - 579) + "px";
    else XLPopup.Area.style.left = (sx - 5) + "px";
    XLPopup.Area.style.top = (sy + 5) + "px";
    XLPopup.Show(new Array("xlpopup-caption", "xlpopup-text")); 
    XLPopup.CallBackBlockPanelClickCode = "if(XLCommon.GetElement('xlpopup-text').value.Trim() == '') XLPopup.Hide();";
    XLPopup.CorrectDocumentHeight(true);
    XLSite.InitBlockPanel();
  }
}


XLSite.PopupFeedBackSubmit = function (Chapter, Gid)
{
  if(!XLCommon.GetElement("xlpopup-send").disabled)
  {
    if(XLCommon.GetElement("xlpopup-text").value.Trim() == "")
    {
      alert("Нужен текст");
      return false;
    }
    if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-captcha")))
    {
      if(XLCommon.GetElement("xlpopup-captcha").value.Trim() == "")
      {
        alert("Введите символы, указанные на картинке");
        return false;
      }
    }
    if(!XLXO.IsDataSending())
    {
      XLCommon.CommonFormClear("feedback");
      if(!XLCommon.IsEmpty(XLCommon.GetElement("xlpopup-captcha")))
      {
        XLCommon.FormSetNameValue(XLCommon.CommonForm, "captcha", XLCommon.GetElement("xlpopup-captcha").value.Trim());
      }
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "text", XLCommon.GetElement("xlpopup-text").value.Trim());
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "chapter", Chapter);
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "feedback"}, XLCommon.CommonForm))
      {
        XLCommon.GetElement("xlpopup-send").disabled = true;
        return true;
      }
    }
  }
  return false;
}


XLSite.LoadRandomPresent = function ()
{
  if(!XLXO.IsDataSending())
  {
    XLCommon.CommonFormClear("getrandompresent");
    if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "getrandompresent"}, XLCommon.CommonForm))
    {
      var d = XLCommon.GetElement("present-random");
      if(!XLCommon.IsEmpty(d))
      {
        d.innerHTML = XLConst.StringLoading;
      }
      return true;
    }
  }
  return false;
}



XLSite.PopupShortArticleViewShow = function (Gid, Sender)
{
  if(!XLXO.IsDataSending())
  {
    if(XLPopup.Create("white")) 
    {
      XLCommon.GetElement("xlpopup").innerHTML = "";
      
      var d = document.createElement("div")
      d.style.padding = "4px 9px 9px 9px";
      d.style.fontSize = "8pt";
      d.innerHTML = "<table width = '610' cellspacing = '0' cellpadding = '0' border = '0'><tr><td id = 'xlpopup-article-body'>" + XLConst.StringLoading + "</td></tr></table>";
      
      XLCommon.GetElement("xlpopup").appendChild(d);
      
      
      
      if(Sender.offsetWidth + XLCommon.GetElementPosition(Sender).x > 700)
      {
        XLPopup.Area.style.left = Sender.offsetWidth + XLCommon.GetElementPosition(Sender).x - 643;
      }
      else
      {
        XLPopup.Area.style.left = XLCommon.GetElementPosition(Sender).x - 6;
      }
      XLPopup.Area.style.top = XLCommon.GetElementPosition(Sender).y + 8;
      XLPopup.CallBackBlockPanelClickCode = "XLPopup.Hide();"
      XLPopup.Show(); 
      
      XLCommon.CommonFormClear("getarticlebody");
      XLCommon.FormSetNameValue(XLCommon.CommonForm, "gid", Gid);
      if(XLXO.RequestServer(XLConst.FormMethodPost, XLConst.Url, XLSite.GetResult, {Action: "getarticlebody"}, XLCommon.CommonForm))
      {
        return true;
      }
    }
  }
}
