function hide_popup(id){
    var m=$(id);
    if (m!=null){
	m.style.visibility='hidden';
	m.style.display='none';
    };
};

function loading_filler(id){
    return document.createTextNode('...загрузка...');
};

function removeChildrenFromNode(node){
    var len = node.childNodes.length;	
    for(var i = len-1; i >=0; i--){
	node.removeChild(node.childNodes[i]);
    };
};

function getWindowSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  }else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }; 
  var sz=new Object();
  sz.width=myWidth;
  sz.height=myHeight;
  return sz;
};

function create_popup(ev,parent,filler,id){
    var m=$(id);
    mpos=get_mouse_pos(ev);
    if (m==null){
	m=document.createElement('div');
	m.id=id;
	m.style.zIndex='2';
	m.style.position='absolute';
	m.style.border='1px solid black';
	m.style.visibility='hidden';
	m.style.display='none';
	m.style.left=mpos.x+1;
	m.style.top=mpos.y+1;
	m.timeout=null;
	m.className='popup_win';
	m.onmouseout=function(){
	    this.onmouseover();
	    this.timeout=setTimeout('hide_popup(\''+this.id+'\')',500);
	};
	m.onmouseover=function(){
	    if (this.timeout!=null){
		clearTimeout(this.timeout);
		this.timeout=null;
	    };
	};
	document.body.appendChild(m);
    }else{
	m.onmouseover();
    };
    var t=filler(id);
    if (typeof(t)=='string'){
        if (m.innerHTML!=t) m.innerHTML=t;
    }else{
	removeChildrenFromNode(m);
        m.appendChild(t);
    };
    m.style.left=mpos.x+1;
    m.style.top=mpos.y+1;
    var sz=getWindowSize();
    if (mpos.x+170>sz.width){
	m.style.left=sz.width-170;
    };
    if (mpos.y+100>sz.height){
	m.style.top=sz.height-100;
    };
    if (m.style.display=='none'){
	m.timeout=setTimeout('create_popup_(\''+id+'\')',500);
    };
    parent.popup=m;
    parent.onmouseout=function(){
	this.popup.onmouseout();
    };
    if (!parent.onmousemove){
	parent.onmousemove=function(ev){
	    mpos=get_mouse_pos(ev);
	    this.popup.style.top=mpos.y+1;
	};
    };
};

function create_popup_(id){
    var m=$(id);
    if (m!=null && m.timeout!=null){
	m.timeout=null;
	m.style.visibility='visible';
	m.style.display='block';
    };
};

