focus_after_create=null;

function close_window(name){
    var m = $(name);
    if (m){
	m.win_close();
        m.parentNode.removeChild(m);
    };
};

function create_window(ev,winname,head_text,body_create_func,param,onclose){
    var m = $(winname);
    mpos=get_mouse_pos(ev); 
    if (!m){
	var div=document.createElement('DIV');
	div.id=winname;
	div.style.position='absolute';
	div.style.background='white';
	div.style.color='black';
	div.style.left=mpos.x;
	div.style.top=mpos.y;
	div.style.zIndex='5';
	div.className='tmp_window';
	var tbl=document.createElement('TABLE');
	tbl.style.borderCollapse='separate';
	tbl.style.borderSpacing='0';
	var row=tbl.insertRow(-1);
	//create close button
	row.className='tmp_header';
	var btn=document.createElement('A');
	btn.appendChild(document.createTextNode('x'));
	btn.href='none';
	btn.window_name=winname;
	btn.onclick=function(){ close_window(this.window_name); return false;};
	div.close_btn=btn;
	
	var cell=row.insertCell(-1);
	cell.appendChild(document.createTextNode(head_text));
	cell=row.insertCell(-1);
	cell.style.textAlign='right';
	cell.appendChild(btn);
	
	// adding some valuable info
	
	row=tbl.insertRow(-1);
	cell=row.insertCell(-1);
	cell.style.padding='5';
	cell.colSpan=2;
//	cell.appendChild(document.createTextNode('other information here'));
	cell.appendChild(body_create_func(param));
	
	div.appendChild(tbl);
	
	
	//insert new window into document
	document.body.appendChild(div);
	
	div.focus_after_create=focus_after_create;
	m=div;
	div.win_close=function(){if (this.win_onclose!=null) this.win_onclose(this.win_param);};
    }else{
	m.win_close();
    };
    m.win_onclose=onclose;
    m.win_param=param;
    m.style.visibility='visible';
    m.style.display='block';
    m.style.left=mpos.x;
    m.style.top=mpos.y;
    if (m.focus_after_create){
	m.focus_after_create.focus();
    };
};

