    x=0;
    y=0;
    m=0;
    tab=0;
    tabid="";
    tabMin=0;
    tabMax=0;
    tabX=0;

    bcls=new Image();
    bcls1=new Image();
    bmin=new Image();
    bmin1=new Image();
    bmax=new Image();
    bmax1=new Image();
    bres=new Image();
    bres1=new Image();
    butt11=new Image();
    butt12=new Image();
    butt21=new Image();
    butt22=new Image();
    butt31=new Image();
    butt32=new Image();
    butt11.src="menu/cm.bmp";
    butt12.src="menu/cm2.bmp";
    butt21.src="menu/cs.bmp";
    butt22.src="menu/cs2.bmp";
    butt31.src="menu/cd.bmp";
    butt32.src="menu/cd2.bmp";
    bcls.src="menu/zamknij.bmp";
    bcls1.src="menu/zamknij1.bmp";
    bmin.src="menu/min.bmp";
    bmin1.src="menu/min1.bmp";
    bmax.src="menu/max.bmp";
    bmax1.src="menu/max1.bmp";
    bres.src="menu/res.bmp";
    bres1.src="menu/res1.bmp";

    document.onmousedown=ReturnFalse;
    document.onmousemove=null;
    document.onmouseup=ReturnFalse;
    document.onselectstart=ReturnFalse;
    document.oncontextmenu=ReturnFalse;
 
    function CenterWindow(s,ox,oy)
    {
      tab=parent[s];
      tab.style.display='';
      if (tab)
      {
        wid=tab.offsetWidth;
        hei=tab.offsetHeight;
        if ((window.innerWidth)&&(window.innerWidth!="undefined"))
        {
          docwid=parent.innerWidth;
          dochei=parent.innerHeight;
        }else
        {
          docwid=parent.document.body.clientWidth;
          dochei=parent.document.body.clientHeight;
        }
        pozx=Math.floor((docwid-wid)/2);
        pozy=Math.floor((dochei-hei)/2);
        if (pozx<0)
        pozx=0;
        if (pozy<0)
        pozy=0;
        pozx+=ox;
        pozy+=oy;
        tab.style.left=pozx+'px';
        tab.style.top=pozy+'px';
        tab.style.visibility="visible";
      }
    }

    fram=0;

    function exitFrame(s)
    {
      xx=parent.XF1;
      yy=parent.XF2;
      if(xx&&yy)   
      if(fram)
      { 
        xx.style.display='';
        yy.style.display='';
        fram=0;
        document.body.onunload=null;
      }else
      { 
        xx.style.display='none';
        yy.style.display='none';
        fram=1;
        document.body.onunload=exitFrame;
      }
    }

    function MinMax(nazwa)
    {
      y=document.getElementById(nazwa+'BMin');
      nazwa=nazwa;
      if (document.getElementById)
      { 
        x=document.getElementById(nazwa+'C');
        if (x.ismin)
        { 
          parent[nazwa].style.height=x.xminsize+'px';
          parent[nazwa+"Row"].style.height=x.xminsize+'px';
          x.ismin=0;
          y.style.backgroundImage="url("+eval("bmin.src")+")"
        }else          
        {
          x.xminsize=parent[nazwa].offsetHeight;
          parent[nazwa].style.height='27px';
          parent[nazwa+"Row"].style.height='27px';
          x.ismin=1;
          y.style.backgroundImage="url("+eval("bres.src")+")"
        }
      }
    }

    function CloseWin(s)
    {
      elem=parent[s];
      if (elem)
      elem.style.display="none";
    }   


    if(document.captureEvents)
    document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);

    function ReturnFalse()
    {
      return false;
    }

    function activate(s)
    { 
      ot=tab;
      tabid=s;
      tab=parent[s];
      if (tab!=ot)
      {
        parent.zi++;
        tab.style.zIndex=parent.zi;
      }
      m=0;
      return true;
    }

    function down(s,e)
    { if (!(e))
      e=event;
      if (typeof e.which=='number')
      { 
        if (e.which!=1)
        return activate(s);
      }else
      { 
        if (!((e.button)&1))
        return activate(s);
      };
      document.onmousedown=ReturnFalse;
      document.onmousemove=move;
      document.onmouseup=up;
      ot=tab;
      tabid=s;
      tab=parent[s];
      tabMin=document.getElementById(s+'RMin');
      tabMax=document.getElementById(s+'RMax');
      tabX=document.getElementById(s+'Close');
      if (tab!=ot)
      {
        parent.zi++;
        tab.style.zIndex=parent.zi;
      }
      xscr=e.clientX;
      yscr=e.clientY;
      x=xscr;
      y=yscr;
      if(tab.style.position!="absolute")
      {
        x-=5;
        y-=5;
      }
      if ((window.innerWidth)&&(window.innerWidth!="undefined"))
      {
        docwid=window.innerWidth;
        dochei=window.innerHeight;
      }else
      {
        docwid=document.body.clientWidth;
        dochei=document.body.clientHeight;
      }
      m=0;
      if (tabMin)
      {
        fflef=tabMin.offsetLeft+1;
        ffrig=fflef+tabMin.offsetWidth-3;
        fftop=tabMin.offsetTop+4;
        ffbot=fftop+tabMin.offsetHeight-6;
        if ((x>=fflef)&&(x<ffrig)&&(y>=fftop)&&(y<ffbot))
        {
          x=document.getElementById(tabid+'BMin');
          if (document.getElementById(tabid+'C').ismin) 
          x.style.backgroundImage="url("+eval("bres1.src")+")";else
          x.style.backgroundImage="url("+eval("bmin1.src")+")";
          m|=2;
        }
      }
      if((m==0)&&(tabX))
      {
        fflef=tabX.offsetLeft+1;
        ffrig=fflef+tabX.offsetWidth-3;
        fftop=tabX.offsetTop+4;
        ffbot=fftop+tabX.offsetHeight-6;
        if ((x>=fflef)&&(x<ffrig)&&(y>=fftop)&&(y<ffbot))
        {
          x=document.getElementById(tabid+'BClose');
          x.style.backgroundImage="url("+eval("bcls1.src")+")"
          m|=4;
        }
      }
      if ((m==0)&&(tabMax))
      {
        fflef=tabMax.offsetLeft+1;
        ffrig=fflef+tabMax.offsetWidth-3;
        fftop=tabMax.offsetTop+4;
        ffbot=fftop+tabMax.offsetHeight-6;
        if ((x>=fflef)&&(x<ffrig)&&(y>=fftop)&&(y<ffbot))
        {
          x=document.getElementById(tabid+'BMax');
          if (window[tabid+'Max']) 
          x.style.backgroundImage="url("+eval("bres1.src")+")";else
          x.style.backgroundImage="url("+eval("bmax1.src")+")";
          m|=8;
        }
      }
      if (m==0)
      m|=1;
      if (document.body.setCapture)
      document.body.setCapture();else
      if (document.getElementById("wallGhost"))
      document.getElementById("wallGhost").style.display="";
      return false;
    }

    function up(e)
    {
      if (m&2)
      MinMax(tabid);else
      if (m&4)
      {
        x=document.getElementById(tabid+'BClose');
        x.style.backgroundImage="url("+eval("bcls.src")+")"
        CloseWin(tabid);
      }else
      if (m&8)
      {
        x=document.getElementById(tabid+'BMax');
        if(window[tabid+'Max'])
        {
          window[tabid+'Max']=0;
          x.style.backgroundImage="url("+eval("bmax.src")+")"; 
        }else
        {
          window[tabid+'Max']=1;
          x.style.backgroundImage="url("+eval("bres.src")+")";
        }
        exitFrame(tabid);
      }
      m=0;
      document.onmousedown=ReturnFalse;
      document.onmousemove=ReturnFalse;
      document.onmouseup=ReturnFalse;
      if (document.body.releaseCapture)
      document.body.releaseCapture();else
      if (document.getElementById("wallGhost"))
      document.getElementById("wallGhost").style.display="none";

      return false;
    }

    function move(e)
    { if (tab.style.position!="absolute")
      return false;
      if (!(e))
      e=event;
      if (m==1)
      {
        ecx=e.clientX;
        ecy=e.clientY;
        pozx=tab.offsetLeft+ecx-xscr;
        pozy=tab.offsetTop+ecy-yscr;
        wid=tab.offsetWidth;
        hei=tab.offsetHeight;
        if ((parent.innerWidth)&&(parent.innerWidth!="undefined"))
        {
          docwid=parent.innerWidth;
          dochei=parent.innerHeight;
        }else
        {
          docwid=parent.document.body.clientWidth;
          dochei=parent.document.body.clientHeight;
        }
        if(wid+pozx>docwid)
        pozx=docwid-wid;
        if(pozx<0)
        pozx=0;
        if(hei+pozy>dochei)
        pozy=dochei-hei;
        if(pozy<0)
        pozy=0;
        tab.style.left=pozx+'px';
        tab.style.top=pozy+'px';
      }
      return false;
    }
