var info={
  Div : null,
  ShowId : 0,
  oXmlHttp : null,
  event : null,
  Content : Array(),
  url : "/user/info.php?id=",
  textLoad : 'Ждите загрузка...',
  ie : document.all,
  ns6 : document.getElementById&&!document.all,
  Show : function(trg, textid, event){
    this.event = event;
    this.ShowId = textid;
    if(this.Div == null) this.CreateDiv();
    var pos = this.getPositionXY(this.event);
    this.Div.style.left = pos.x + "px";
    this.Div.style.top  = pos.y + "px";
    if( typeof(this.Content[textid])=='undefined' ){
      this.Div.innerHTML = this.textLoad;
      this.loadData(textid);
    }else{
      this.Div.innerHTML = this.Content[textid];
    }
    this.Div.style.display = "block";
    this.updatePosition();
    //trg.onmouseout = function(){ info.Hide() };
    //this.Div.onmouseout = function(){ info.Hide() };
  },
  updatePosition:function(){
    var pos = this.getPositionXY(this.event);
    this.Div.style.left = pos.x + "px";
    this.Div.style.top  = pos.y + "px";
  },
  Hide : function(){
    this.ShowId = 0;
    if(this.Div !== null) this.Div.style.display='none';
  },
/*  include_dom : function (script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
  },
*/
  loadData : function (id){
    if(!this.oXmlHttp){
      info.oXmlHttp = zXmlHttp.createRequest();
    } else if ( info.oXmlHttp.readyState != 0){
      info.oXmlHttp.abort();
    }
    info.oXmlHttp.open("get", this.url+id, true);
    this.oXmlHttp.onreadystatechange = function() {
      if (info.oXmlHttp.readyState == 4) {
        if (info.oXmlHttp.status == 200) {
          var aData = info.oXmlHttp.responseText.split("||",3);
          info.updateHelpText(aData[0],aData[1],aData[2]);
        }
      }
    }
    info.oXmlHttp.send(null);
  },

  updateHelpText : function (id, width, text){
    this.Content[id] = text;
    if(this.ShowId==id){
      this.Div.innerHTML=this.Content[id];
      this.updatePosition();
    }
  },



  Init : function(){
  },
  sd : function(){
  },
  ietruebody : function(){
    return (document.compatMode!="BackCompat")? document.documentElement : document.body
  },
  CreateDiv : function(){
    this.Div = document.createElement('div');
    this.Div.style.position = "absolute";
    this.Div.style.border = "solid 1px #C0C0C0";
    this.Div.style.background = "#FEF7DC";
    this.Div.style.width = "400px";
    this.Div.style.visibility="visible";
    this.ietruebody().appendChild(this.Div);
  },



  getPositionXY : function(e){
    var pos_X = 0; var pos_Y = 0;
    if ( !e ) e = window.event;
    if ( e ) {
      if ( typeof(e.pageX) == 'number' ) {
        pos_X = e.pageX;
        pos_Y = e.pageY;
      }
      else if ( typeof(e.clientX) == 'number' ) {
        pos_X = e.clientX;
        pos_Y = e.clientY;
        if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( window.opera || navigator.vendor == 'KDE' ) ) {
          pos_X += document.body.scrollLeft;
          pos_Y += document.body.scrollTop;
        }
        else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( window.opera || navigator.vendor == 'KDE' ) ) {
          pos_X += document.documentElement.scrollLeft;
          pos_Y += document.documentElement.scrollTop;
        }
      }
    }
    var horzpos=this.ns6? pageXOffset+e.clientX : this.ietruebody().scrollLeft+event.clientX
    var vertpos=this.ns6? pageYOffset+e.clientY : this.ietruebody().scrollTop+event.clientY
    var scroll_X = 0;
    var scroll_Y = 0;
    if ( document.body && ( document.body.scrollTop || document.body.scrollLeft ) && !( navigator.vendor == 'KDE' ) ) {
      scroll_X = document.body.scrollLeft;
      scroll_Y = document.body.scrollTop;
    }
    else if ( document.documentElement && ( document.documentElement.scrollTop || document.documentElement.scrollLeft ) && !( navigator.vendor == 'KDE' ) ) {
      scroll_X = document.documentElement.scrollLeft;
      scroll_Y = document.documentElement.scrollTop;
    }

    var win_size_X = 0;
    var win_size_Y = 0;

    if (window.innerWidth && window.innerHeight) {
      win_size_X = window.innerWidth;
      win_size_Y = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth && document.documentElement.clientHeight) {
      win_size_X = document.documentElement.clientWidth;
      win_size_Y = document.documentElement.clientHeight;
    }
    else if (document.body && document.body.clientWidth && document.body.clientHeight) {
      win_size_X = document.body.clientWidth;
      win_size_Y = document.body.clientHeight;
    }
    pos_X += -15;
    pos_Y += -15;
    if (this.Div.offsetWidth && this.Div.offsetHeight) {
    if (pos_X - scroll_X + this.Div.offsetWidth + 5 > win_size_X) pos_X -= (this.Div.offsetWidth + -15*2);
    if (pos_Y - scroll_Y + this.Div.offsetHeight + 5 > win_size_Y) pos_Y -= (this.Div.offsetHeight + -15*2);
    }
    return {x:pos_X, y:pos_Y};
  }
}

