function JCPoint()
{
  var _this = this;
  this.mess = {};
  this.floatDiv = null;
  this.content = null;
  this.menu = null;
  this.form = this.field = null;
  this.notClose = false;

  /* Applying styles */
  /*var head = document.getElementsByTagName("HEAD");
  if(head)
  {
    var link = document.createElement("LINK");
    link.rel = 'stylesheet';
    link.href = '/bitrix/components/travelshop/ibe.tools/templates/.default/point.css'+(jsIBEUtils.IsOpera()? '':'?'+phpVars.SM_VERSION);
    head[0].appendChild(link);
  }
  if(head)
  {
    var link = document.createElement("LINK");
    link.rel = 'stylesheet';
    link.href = phpVars.TOOLS_THEMES_PATH+'/point.css'+(jsIBEUtils.IsOpera()? '':'?'+phpVars.SM_VERSION);
    head[0].appendChild(link);
  }*/

  /* Main functions */
  this.Show = function(obj, field)
  {
    if(this.floatDiv)
      this.Close();

    this.form = jsIBEUtils.FindParentObject(obj, 'form');
    this.field = field;

    var div = document.body.appendChild(document.createElement("DIV"));
    div.id = "point_float_div";
    div.className = "point-float";
    div.style.position = 'absolute';
    div.style.left = '-1000px';
    div.style.top = '-1000px';

    div.innerHTML =
      '<div class="title">'+
      '<table>'+
      ' <tr>'+
      '   <td class="title-text" onmousedown="jsFloatDiv.StartDrag(arguments[0], jsIBEUtils.GetById(\'point_float_div\'));" id="point_float_title">'+this.mess["title"]+'</td><td width="0%"><a class="close" href="javascript:jsPoint.Close();" title="'+this.mess["close"]+'"></a></td></tr>'+
      '</table>'+
      '</div>'+
      '<div class="content"><div id="iplus_point"></div></div>';

    this.floatDiv = div;
    //this.content = jsIBEUtils.FindChildObject(this.floatDiv, 'div', 'content');
    //this.content.innerHTML = "";

    var pos = jsIBEUtils.GetRealPos(obj);
    pos["bottom"]+=2;
    pos = jsIBEUtils.AlignToPos(pos, div.offsetWidth, div.offsetHeight);

    //alert( this.mess["url"] );
    jsIBEUtils.LoadHTMLToDiv(
      this.mess["url"], 
      'iplus_point',
      null,
      new Function( "show_letter( \"letter_no_0\" );jsFloatDiv.Show(jsPoint.floatDiv, " + pos["left"] + "," + pos["top"] + ");" )
    );

    //jsFloatDiv.Show(div, pos["left"], pos["top"]);

    setTimeout(function(){jsIBEUtils.addEvent(document, "click", _this.CheckClick)}, 10);
    jsIBEUtils.addEvent(document, "keypress", _this.OnKeyPress);
  }

  /* Window operations: close, drag, move */
  this.Close =  function()
  {
    if ( _this.notClose )
    {
      this.notClose = false;
      return;
    }
    jsIBEUtils.removeEvent(document, "click", _this.CheckClick);
    jsIBEUtils.removeEvent(document, "keypress", _this.OnKeyPress);

    jsFloatDiv.Close(this.floatDiv);

    this.floatDiv.parentNode.removeChild(this.floatDiv);
    this.floatDiv = null;
  }

  this.OnKeyPress = function(e)
  {
    if(!e) e = window.event;
    if(!e) return;
    if(e.keyCode == 27)
      _this.Close();
    else if(e.keyCode == 13)
      _this.notClose = true;
  }

  this.CheckClick = function(e)
  {
    var div = _this.floatDiv;
    if(!div)
      return;

//    alert( e.clientX + ":" + e.clientY + ", " + document.documentElement.scrollLeft + ":" + document.documentElement.scrollTop + ", " + document.body.scrollLeft + ":" + document.body.scrollTop );

    var x = e.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
    var y = e.clientY + document.documentElement.scrollTop + document.body.scrollTop;

    /*region*/
    var posLeft = parseInt(div.style.left);
    var posTop = parseInt(div.style.top);
    var posRight = posLeft + div.offsetWidth;
    var posBottom = posTop + div.offsetHeight;
    //alert( posLeft + ":" + posTop + ", " + posRight + ":" + posBottom );

    if(x >= posLeft && x <= posRight && y >= posTop && y <= posBottom)
      return;

    _this.Close();
  }

  this.FakeSubmit =  function(obj)
  {
    if(!obj)
      return;
    obj.disabled = true;
    if (obj.form)
      this.Search(obj.form);
    else
      return false;
  }

  /* Submit search form */
  this.Search =  function(form)
  {
    var postData= "";
    var url;
    if ( form != null )
    {
      var n = form.childNodes.length;
      for(var j=0; j<n; j++)
      {
        var child = form.childNodes[j];
        if(child.tagName && child.tagName.toUpperCase() == 'INPUT')
        {
          if(child.getAttribute('type') && (child.getAttribute('type').toLowerCase() == 'hidden' || child.getAttribute('type').toLowerCase() == 'text') && child.value)
          {
            if (postData.length > 0)
            {
              postData += "&";
            }
            postData += child.getAttribute('name') + "=" + encodeURI(child.value);
          }
        }
      }
      //alert(postData);
      if(form.getAttribute('action') && form.getAttribute('action').length > 0)
      {
        url = form.action;
      }
      else
      {
        url = this.mess["url"];
      }
      jsIBEUtils.LoadHTMLToDiv(url, 'iplus_point', postData);
    }
    return false;
  }
  
  /* Insert value in field */
  this.SetValue =  function(value)
  {
    this.form.elements[this.field].value = value;
    this.notClose = false;
    _this.Close();
  }

  /* Highlight table row */
  this.HighlightRow = function(row, on)
  {
    if(on)

      row.className += '_over';
    else
      row.className = row.className.replace(/_over/i, '');
  }

  this.InitTable = function(tbl)
  {
    if(!tbl || tbl.rows.length < 1 || tbl.rows[0].cells.length < 1)
      return;
    var n = tbl.rows.length;
    for(i=0; i<n; i++)
    {
      var row = tbl.rows[i];
      if(i >= 1)
      {
        /*rows mousover action*/
        row.onmouseover = function(){_this.HighlightRow(this, true)};
        row.onmouseout = function(){_this.HighlightRow(this, false)};
      }
    }
  }

}
var jsPoint = new JCPoint();

var current_visible = null;
function show_letter( letter ) {
  if ( current_visible != null ) {
    current_visible.style.display = "none";
  }
  current_visible = document.getElementById( letter );
  if ( current_visible != null ) {
    current_visible.style.display = "block";
  }
  if ( jsIBEUtils.IsIE() ) {
    // скорректировать размер IFRAME
    jsFloatDiv.AdjustShadow( jsPoint.floatDiv );
  }
}
