// copyright by edv-organisation thomas päpenmöller gen. peppmöller, Bielefeld, www.edv-organisation.de

window.allClass = new Array();
window.all      = new Array();

var stdListBoxHeader='', stdListBoxClass='',
    stdInputClass='', stdInputStyle='',
    stdTextStyle='';


function regClass(tClass,pClass){
  allClass[allClass.length]=tClass;
  if(pClass)tClass.prototype=new pClass;
};

function TObj(){
  this.id ='';
  this.idStr;
  this.classType='TObj';
  this.isVisible = false;
  this.onClick=false;
  this.onMouseOver=false;
  this.onMouseOut=false;
  this.padding=0;
  this.margin =0;
  this.bgAlpha=false;
  this.isWindow=false;

  this.getSelf=function(){return this};
  this.pos= function(l,t,w,h){  // wegen prototyp vererbung
    var np=new Object();
    np.l=l;
    np.t=t;
    if(arguments.length>2){np.w=w; np.h=h;}
    else {
      np.w=(!this.position)?null:this.position.w;
      np.h=(!this.position)?null:this.position.h;
    };
    this.position=np;
    with (this){
      position.str='';
      var p=position;
      if(l!=null)p.str+='left:'+l+';';
      if(t!=null)p.str+='top:'+t+';';
      if(w!=null)p.str+='width:'+w+';';
      if(h!=null)p.str+='height:'+h+';';
    };
  };
  this.rel = function(l,t,w,h){
    if(this.owner) with (this){
      if(owner.relPosLeft)l+=owner.relPosLeft;
      owner.relPosLeft=l;
      if(owner.relPosTop)t+=owner.relPosTop;
      owner.relPosTop=t;
      pos(l,t,w,h);
    };
  };
  this.html=function(){return ''};
  this.childHtml=function(){
    return '<div id="parent@'+this.idStr+'">'+this.html()+'</div>';
  };  
  
  this.innerWidth=function (){return this.position.w-2*this.padding}
  this.innerHeight=function (){return this.position.h-2*this.padding}
  
  this.setup=function(id){
    this.id=id;
    this.self=this;
    if(id&&this.owner){
      if(this.owner[id])this.owner[id].destroy();
      this.owner[id]=this;
      this.idStr=this.owner.idStr+'.'+id;
      if(this.owner.win)this.win=this.owner.win;
    }
    else{
     if(all[id])all[id].destroy();
     all[id]=this;
     this.idStr='window.all.'+id;
    };
  };
  this.doClick=function (obj,ev){
    if(this.onClick){
      if(ev)ev.cancelBubble=true;
      eval(this.onClick);
    };
  };
  this.doBlur=function (obj,ev){
    if(this.onBlur){
      ev.cancelBubble=true;
      eval(this.onBlur);
    };
  };  
  this.doMouseOver=function(){
    if(this.onMouseOver)eval(this.onMouseOver);
  };
  this.doMouseOut=function(obj,ev){
    with(this)
    if(ev.toElement){
      if(onMouseOut&&!obj.contains(ev.toElement))eval(onMouseOut);
    }
    else {
      if(onMouseOut&&!containsNode(obj,ev.relatedTarget))eval(onMouseOut);
    }
  };  
  this.inherited = function(method){
    this.method=method;
    return this;
  };
  this.destroy = function(){
    if(this.id&&this.owner){
      this.owner[this.id]=null;
    }
    else{
     all[this.id]=null;
    };
  };
  this.setVisible=function(state){
    this.isVisible=state;
    var e=document.getElementById('parent@'+this.idStr);
    if(e&&e.firstChild){
      e.firstChild.style.visibility=state?'':'hidden';
    }
  };
  this.setValue=function(value){
    if(!this.objNr)var e=document.getElementById('parent@'+this.idStr);
              else var e=document.getElementById('obj'+this.objNr);
              
    if(e&&e.firstChild)e.firstChild.innerHTML=value;
  };  
  this.update=function(){
    var e=document.getElementById('parent@'+this.idStr);
    if(e)e.innerHTML=this.html();
  };
  // defaultpos
  this.pos(0,0,100,100);
};
regClass(TObj);

function TText(){
  this.classType='TText';
  this.value='';
  this.style='';
  this.cssClass='';
  this.textStyle=stdTextStyle;
  this.text='';
  this.textWidth=0;
  this.setValue=function(val){
    this.value=val;
    var o=document.getElementById(this.idStr);
    if(o)o.innerHTML=val;
  };

  this.html  = function (){
    with (this){                                                                                                                                                                                                                     
      return (text?'<span style="position:absolute;left:'+position.l+';top:'+position.t+';width:'+textWidth+';line-height:'+position.h+'px;'+textStyle+'">'+text+'</span>':'')+'<span id="'+idStr+'" class="'+cssClass+'" style="position:absolute;left:'+(position.l+textWidth)+';top:'+position.t+';width:'+(position.w-textWidth)+';height:'+position.h+';overflow:hidden;line-height:'+position.h+'px;'+style+'">'+value+'</span>';
    };
  };
};
regClass(TText,TObj);

function TImg(){
  this.classType='TImg';
  this.src='';
  this.title='';
  this.onClick=false;

  this.html  = function (){
    with (this){
      return '<img id="'+idStr+'" src="'+src+'" '+((title)?'title="'+title+'" alt="'+title+'"':'')+' style="'+(onClick?'cursor:'+cHand+';':'')+((this.position)?'position:absolute;'+position.str:'')+'" '+(onClick?'onClick="'+idStr+'.doClick(this,event)"':'')+'>';
    };
  };
  this.setValue=function(src){
    this.src=src;
    this.update();
  };
  var setup=this.setup;
  this.setup = function(id,src){this.inherited(setup).method(id);this.src=src};
};
regClass(TImg,TObj);

function TLnk(){
  this.classType='TLnk';
  this.txt='';
  this.href='';
  this.title='';
  this.onClick=false;

  this.html  = function (){
    with (this){
      if (href) return '<a href="'+href+'" '+((title)?'title="'+title+'"':'')+'>'+txt+'</a>';
      else return '<div id="'+idStr+'" '+((title)?'title="'+title+'"':'')+' style="cursor:'+cHand+';'+((this.position)?'position:absolute;'+position.str:'')+'" onClick="'+idStr+'.doClick(this,event)">'+txt+'</div>';
    };
  };
  var setup=this.setup;
  this.setup = function(id,txt,fnc){this.inherited(setup).method(id);this.txt=txt;this.onClick=fnc};
};
regClass(TLnk,TObj);

function TInput(){
  this.classType='TInput';
  this.value='';
  this.oldValue='';
  this.style=stdInputStyle;
  this.cssClass=stdInputClass;
  this.textStyle=stdTextStyle;
  this.text='';
  this.textWidth=0;
  this.lines=1;
  this.editable=true;
  this.onClick=false;
  this.onBlur=false;
  this.password=false;

  this.onEnter = function(){
  };
  this.onKeyDown = function(ev){
    if(ev.keyCode==13)this.onEnter();
    else{
    };
  };

  this.getValue=function(){
    with (this){
      var o=document.getElementById(idStr);
      if(o){
        value=o.value;
        return value; 
      }
      else return value;
    };
  };
  
  this.setValue=function(v){
    this.value=v;
    this.oldValue=v;
    var o=document.getElementById(this.idStr);
    if(o)o.value=v;
  };
  
  this.isChanged=function(){
    with (this){
      return oldValue!=getValue();
    };
  };
  
  this.effectHtml=function(){
    with (this)
    if(owner.fieldEffect)return ' onMouseOver="'+owner.fieldEffect+'(this,1);'+idStr+'.doMouseOver(this,event)" onMouseOut="'+owner.fieldEffect+'(this,0)" ';
                    else return ' onMouseOver="'+idStr+'.doMouseOver(this,event)" ';
  };
  
  this.textHtml=function(){
    with (this){
      return text?'<div style="position:absolute;left:'+position.l+';top:'+position.t+';width:'+textWidth+';'+textStyle+'">'+text+'</div>':'';
    };
  };
  this.html  = function (){
    with (this){
      var pText=textHtml();
      if(lines==1) return pText+'<input    id="'+idStr+'" class="'+cssClass+'" style="position:absolute;left:'+(position.l+textWidth)+';top:'+position.t+';width:'+(position.w-textWidth)+';height:'+position.h+';'+style+'" type="'+(password?'password':'text')+'" '+(onBlur?'onblur="'+idStr+'.doBlur(this,event)"':'')+'onKeyDown="'+idStr+'.onKeyDown(event)"'+effectHtml()+' value="'+value+'">';
      else         return pText+'<textarea id="'+idStr+'" class="'+cssClass+'" style="position:absolute;left:'+(position.l+textWidth)+';top:'+position.t+';width:'+(position.w-textWidth)+';height:'+position.h+';'+style+'" onKeyDown="'+idStr+'.onKeyDown(event)">'+value+'</textarea>';        
    };
  };

  var setup=this.setup;
  this.setup = function(id,size,val,f){
      this.inherited(setup).method(id);this.setValue(val);
      if(f){
        this.pos(f.l,f.t,size,20);
      }
      else this.pos(0,0,size,20);
  };
};
regClass(TInput,TObj);

function TSelect(){
  this.classType='TSelect';
  this.options=new Array();
  this.onClick=false;
  
  this.html  = function (){
    with (this){
      var ostr='';
      for(var o in options)ostr+='<option value="'+o+'">'+options[o]+'</option>';
      return textHtml()+'<select id="'+idStr+'" class="'+cssClass+'" style="position:absolute;left:'+(position.l+textWidth)+';top:'+position.t+';width:'+(position.w-textWidth)+';height:'+position.h+';'+style+'" type="text" onKeyDown="'+idStr+'.onKeyDown(event)" value="'+value+'">'+ostr+'</select>';
    };
  };
};
regClass(TSelect,TInput);

function TCheckBox(){
  this.classType='TCheckBox';
  this.onClick=false;
  this.value="OFF";
  this.oldValue="OFF";
  this.state=false;
  this.style=stdInputStyle;
  this.cssClass=stdInputClass;  
  this.text='';
  
  this.doClick=function (obj,ev){
    ev.cancelBubble=true;
    this.setState(!this.state);
    if(this.onClick){
      eval(this.onClick);
    };
  };
  this.setValue=function(val){
    with (this){
      setState(val=='ON');
      oldValue=getValue();
    };
  };  
  this.setState=function(s){
    with (this)
    if(state!=s){
      state=s;
      update();
    };
  };  
  this.getValue=function (){this.value=this.state?'ON':'OFF';return this.value};
  this.isChanged=function(){return (this.oldValue!=this.getValue())};
  this.html  = function (){
    with (this){
      return textHtml()+'<input id="'+idStr+'" class="'+cssClass+'" style="position:absolute;left:'+(position.l+textWidth)+';top:'+position.t+';width:'+(position.w-textWidth)+';height:'+position.h+';font-weight:bold;font-family:Verdana;padding:0;text-align:center;'+style+'" type="button" '+(onBlur?'onblur="'+idStr+'.doBlur(this,event)"':'')+effectHtml()+' value="'+(this.state?'&#8730;':'')+'" onClick="'+idStr+'.doClick(this,event)">';      
    };
  };
};
regClass(TCheckBox,TInput);

function TButton(){
  this.classType='TButton';
  this.editable=false;
  
  this.style=stdInputStyle;
  this.cssClass=stdInputClass;  
  this.onClick=false;
  this.html  = function (){
    with (this){
      return '<input id="'+idStr+'" value="'+value+'" '+effectHtml()+'class="'+cssClass+'" style="position:absolute;left:'+position.l+';top:'+position.t+';width:'+position.w+';height:'+position.h+';'+style+'" type="button" onClick="'+idStr+'.doClick(this,event)">';
    };
  };
};
regClass(TButton,TInput);

THidden=TInput;


function TABtn(){
  this.classType='TABtn';
  this.onClick=false;
  this.objectOver=false;
  var setup=this.setup;
  this.setup = function(id,txt,fnc){
    this.inherited(setup).method(id);
    this.title=txt;
    this.onClick=fnc
    this.imgOver=new Image(); this.imgOver.src=imgpath+'btn/'+id+'/over.gif';
    this.imgOut =new Image(); this.imgOut.src=imgpath+'btn/'+id+'/out.gif';
    this.imgDown=new Image(); this.imgDown.src=imgpath+'btn/'+id+'/down.gif';
  };
  this.html  = function (){
    with (this){
      return '<img id="'+idStr+'" '+((title)?'title="'+title+'"':'')+' src="'+imgOut.src+'" style="cursor:'+cHand+';'+((this.position)?'position:absolute;'+position.str:'')+'" onMouseOver="'+idStr+'.onMouseOver(this)" onClick="'+idStr+'.doClick(this,event)">';
    };
  };
  this.onMouseOver = function(obj){
    obj.obj=this;
    if(!obj.onmouseout){
      obj.fncmouseover=doMouseOver;
      obj.onmouseout =doMouseOut;
      obj.onmousedown=doMouseDown;
      obj.onmouseup  =doMouseUp;
    };
    obj.fncmouseover();
    if(this.objectOver){
      this.objectOver();
    };
  };
};
regClass(TABtn,TObj);


function TListBox(){
  this.classType='TListBox';
  this.header=false;
  this.cols=1;
  this.colSize='';
  this.cssClass=stdListBoxClass;
  this.headerStyle=stdListBoxHeader;
  this.border=0;
  this.spacing=0;
  this.rowEffect=false;
  this.value=new Array();
  this.rowStyle=false;

  this.html  = function (){
    with (this){      
      var h='<div style="position:absolute;'+position.str+'; overflow:auto"><table cellpadding="'+padding+'" cellspacing="'+spacing+'" class="'+this.cssClass+'" border="'+border+'">';
      if(header){
        var harr=header.split(',');
        var carr=colSize.split(',');
        var aarr=align.split(',');
        var trstr='';
        var fc=rowStyle=='firstCol';

        if(rowEffect) trstr=' onMouseOver="'+rowEffect+'(this,1)" onMouseOut="'+rowEffect+'(this,0)"';
        h+='<tr'+(headerStyle?' style="'+headerStyle+'"':'')+'>';
        for(var i=0;i<harr.length;i++){
          h+='<td'+(carr[i]?' width='+carr[i]:'')+'>'+harr[i]+'</td>';
          if(i>=cols)cols=i+1;
        };
        h+='</tr>';
        var row=1, col=0, hcols=cols; if(fc)hcols++;
        rstr=''; 
        var htrstr=trstr;
        for (var i=0;i<value.length;i++){          
          if(++col>hcols){
            col=1;row++;
            h+='<tr'+htrstr+'>'+rstr+'</tr>';rstr=''; htrstr=trstr;
          };
          if(fc){
            if(col==1)htrstr+=' '+value[i];
            else rstr+='<td'+(aarr[col-2]?' align="'+aarr[col-2]+'"':'')+'>'+value[i]+'</td>';
          }
          else rstr+='<td'+(aarr[col-1]?' align="'+aarr[col-1]+'"':'')+'>'+value[i]+'</td>';
        };
        if(rstr>'')h+='<tr'+htrstr+'>'+rstr+'</tr>';
      };
      h+='</table></div>';
      return h;
    };
  };
  this.setValue=function(v){
    this.value=v;
    this.update();
  };    
};
regClass(TListBox,TObj);
                                                                     

// autolayout in TCon containern
var winPopupCnt=1;
function TCon(){
  this.classType = 'TCon';
  this.childs    = false;
  this.add       = function(cl){var o=new cl();o.owner=this;if(!this.childs)this.childs=new Array(o);else this.childs[this.childs.length]=o;return o}
  this.cssClass  = '';
  this.fixHtml   = '';
  this.bgImg     = '';
  this.bgAlpha   =false;
  this.style     = '';
  this.borderSize = 0;
  this.sounds    = new Array();
  this.elements  = new Array();

  this.html = function(){
    with (this){
      var h=isIE||isOpera?0:borderSize*2;
      var xs=position.w-margin*2-h,ys=position.h-margin-h-1;yp=position.t,xp=position.l+margin,bofs=0;
      if(!isFirefox)bofs=2*borderSize;
      var hstr='<div id="'+idStr+'" '+((cssClass)?'class="'+cssClass+'"':'')+' style="position:absolute; top:'+yp+';left:'+xp+';height:'+ys+';width:'+xs+';z-index:0;'+'border-width:'+borderSize+';'+((bgImg>'')?'background-image:url('+imgpath+bgImg+');':'')+style+'"'+(onClick||this.isWindow?' onClick="'+idStr+'.doClick(this,event)"':'')+(onMouseOut?' onMouseOut="'+idStr+'.doMouseOut(this,event)" ':'')+'>'+
               (bgAlpha?'<div style="position:absolute;left:0;top:0;width:'+(xs-bofs)+';height:'+(ys-bofs)+';'+alphaImg(bgAlpha)+';"></div>':'');
      if(padding>0||bgAlpha)hstr+='<div style="position:absolute;left:'+padding+';top:'+padding+';width:'+(xs-padding*2)+';height:'+(ys-padding*2)+'">';
      hstr+=fixHtml;
      if (sounds&&soundPlayer) for(var c in sounds)
      with (sounds[c]){
        hstr+=soundPlayer('snd'+c+'@'+idStr,soundpath+file,vol)
      };
      for(var c in elements)hstr+=elements[c].html();
      if (childs) for(var c=0;c<childs.length;c++)hstr+=childs[c].childHtml();
      return hstr+(padding>0||bgAlpha?'</div>':'')+'</div>';
    };
  };
  this.show  = function(){
    with (this){
      if(!isVisible){
        for(var c=0;c<childs.length;c++){
          var ch=childs[c];
          if(!ch.isVisible)ch.setVisible(true);
        };
        if(this.owner&&!this.isWindow){
          if(this.owner.isVisible){
            var c=document.getElementById('parent@'+idStr);
            if(!c){
              this.owner.update();
              c=document.getElementById('parent@'+idStr);
            };
            if(c)c.innerHTML=html();
          };
        }
        else {          
          tabStack++;
          //window.status='tabStack '+tabStack;
          this.objNr=tabStack;
          var w='obj'+tabStack;
          if(!document.getElementById(w))aLay.innerHTML+='<div style="position:absolute" id="'+w+'"></div> ';
          with(document.getElementById(w)){
            style.zIndex=winPopupCnt++;
            innerHTML=html();
          };
        };
        this.isVisible=true;
      }
      else if(isWindow)popupWin();
    };
  };

  this.update = function(updateChilds){
    with (this)
    if(isVisible){
      if(!this.objNr){
        var c=document.getElementById('parent@'+idStr);
        if(c){
          c.innerHTML=html();
          //if(id)this.obj=document.getElementById('Self@'+idStr);
        };
      }
      else {
        var w='obj'+this.objNr;
        document.getElementById(w).innerHTML=html();
        //if(id)this.obj=document.getElementById('Self@'+idStr);
      };
      //if(updateChilds)
      /*
      for(var c=0;c<childs.length;c++){
        var ch=childs[c];
        if(ch.update)ch.update();
      };
      */
    };
  };

  this.hide  = function(){
    with(this){
      if (isVisible){
        if (!this.objNr){
          if(owner.isVisible){
            var c=document.getElementById('parent@'+idStr);
            if(c)c.innerHTML='';
          };
        }
        else {
          if(tabStack==objNr)tabStack--;
          document.getElementById('obj'+objNr).innerHTML='';
        };
        isVisible=false;
        for(var c=0;c<childs.length;c++){
          var ch=childs[c];
          if(ch.isVisible)ch.setVisible(false);
        };
      };
    };
  };
  var inherDestroy  = this.destroy;
  this.destroy = function(){
    this.hide();
    this.inherited(inherDestroy).method();
  };

  this.fieldBlock = function(l,t,d){
    var o=new Object();
    o.con=this;
    o.l=l;o.t=t;o.d=d;
    o.add=function (t,id,size,txt){
      var f=new t(this.con);f.owner=this.con;
      f.setup(id,size,txt,this);
      this.t+=this.d;
      var e=this.con.elements;e[e.length]=f;
      return f;
    };
    return o;
  };

  this.sound = function(f,v,l){
    n=new Object(); n.file=f;n.vol=v+masterVolume /*db*/;n.loop=l;
    this.sounds[this.sounds.length]=n;
  };
  
  this.getFields=function (){
    var retValues='';
    with (this){
      for (ch in childs){
        var c=childs[ch];
        if (c.editable&&c.isChanged())retValues+='&field['+this.idStr+']['+c.id+']='+encodeData(c.getValue());
      };
    };
    return retValues;
  }
  this.getAllFields=function (){
    var retValues='';
    with (this){
      for (ch in childs){
        var c=childs[ch];
        if (c.editable)retValues+='&field['+this.idStr+']['+c.id+']='+encodeData(c.getValue());
      };
    };
    return retValues;
  }
};
regClass(TCon,TObj);

function TTab(){
  this.classType = 'TTab';
  this.isActive=false;
  
  this.setActive=function(){
    with(this){
      owner.activeTab.isActive=false;
      owner.activeTab=this;
      isActive=true;
      owner.update();
    };
  };
  this.parentHtml=this.html;
  this.html = function(){
    with (this){
      if(isActive)return parentHtml();
      else return '';
    };
  };
  var setup  = this.setup;
  this.setup      = function(sid){
    this.inherited(setup).method(sid);
    if(this.owner&&!this.owner.activeTab){
      this.owner.activeTab=this;
      this.isActive=true;
    };
  };
};
regClass(TTab,TCon);

function THead(){
  this.classType='THead';
  this.msg      ='';
  this.bg       ='';
  this.bgImg    ='';
  this.bgAlpha  ='';
  this.cssClass ='wmsg';
  this.img      ='';
  this.optLeft  ='';
  this.optRight ='';
  this.topOfs   = 0;
  this.onMouseDown=function (event){
                     this.owner.popupWin();
                     startMove(this.owner,event);
                   };
  this.onMouseUp   = function (){};
  this.onMouseOut  = function (){};

  this.html = function(){
    with (this){
      (bgImg)?bg=imgpath+bgImg:'';
      var hstr=
      '<div class="'+cssClass+'" onmousedown="'+idStr+'.onMouseDown(event)"  onmouseup="'+idStr+'.onMouseUp(event)" style="cursor:move;position:absolute;left:'+position.l+';top:'+(position.t+topOfs)+';width:'+(position.w-(isIE||isOpera?2:4))+'px;height:'+(position.h-topOfs-(isIE||isOpera?0:2))+'px"><table UNSELECTABLE width="100%" border="0" cellspacing="0" cellpadding="0" '+(bg?'background="'+bg+'"':'')+'>'+
      '<tr><td UNSELECTABLE valfsenign="top" style="padding-left:1;padding-right:4;"></td><td width="90%" class="wmsgt">'+msg+'</td><td align="right" valign="top" style="padding-right:1;">'+optRight+'</td>'+((img)?'<td ><div style="width:45"></div></td>':'')+'</tr>'+
      '</table>'+
      (img?'<img style="position:absolute; top:2; left: '+(position.w-42)+'px;" src="'+imgpath+img+'">':'')+
      '</div>';
      return hstr;
    };
  };
};
regClass(THead,TObj);

function TTopControl(){
  this.classType='TTopControl';
  this.height=32;
  this.cssClass='wintc';
  var setup  = this.setup;
  this.setup      = function(){
    this.inherited(setup).method('topControl');
    if(this.owner)this.owner.topControl=this;
    this.style="";
  };
};
regClass(TTopControl,TCon);

function TWin(){
  this.classType = 'TWin';
  this.headerSize= 0;
  this.borderSize= 1;
  this.canMove  = true;
  this.topControl=null;
  this.onRun=false;
  this.isWindow=true;
  this.bgImg='';
  this.bgAlpha   =false;

  var inherPos    = this.pos;
  this.pos= function(l,t,w,h){
    with (this){
      inherited(inherPos).method(l,t,w,h);
      layout();
    };
  };

  this.oChildHtml=this.childHtml;
  function childHtml(){
    with(this){
      //if(isVisible)return oChildHtml();
      //else 
      //return h='<div id="parent@'+this.idStr+'"></div>';
      return '';
    };
  }

  this.setVisible = function (state){
    if(!state)this.hide();
  }
  
  this.layout=function(){
    with (this){
      if(this.head){
        if(!headerSize)headerSize=head.img?44:(head.msg?25:0);
        head.pos(0,0,position.w-2*padding-2,headerSize);
      };
      var xh=headerSize;
      if(topControl){
        topControl.pos(0,xh,position.w-2-(2*padding)-2*borderSize,topControl.height);
        xh+=topControl.height-topControl.margin;
      };
      if(this.body)body.pos(0,xh,position.w-2-(2*padding)-2*borderSize,position.h-xh-2-(2*padding));
    };
  };
  
  this.popupWin=function(){
    if(this.isVisible)document.getElementById('obj'+this.objNr).style.zIndex=winPopupCnt++;
  };
  
  var inherShow=this.show;
  this.show=function (){
    with (this){
      layout();
      inherited(inherShow).method();
    };
  }

  var setup  = this.setup;
  this.setup      = function(id,head){
    this.inherited(setup).method(id);
    this.win=this;
    this.childHtml=childHtml;
    with (this.add(TCon)) {setup('body');padding=3};
    with (this.add(THead)){
      setup('head');
      msg=head;
    };
  };
  this.doClick=function (obj,ev){
    this.popupWin(); if(this.onClick){
      if(ev)ev.cancelBubble=true;
      eval(this.onClick);
    };
  };
  this.onClose    = this.hide;
  this.onWinMove  = function (dx,dy){if(this.isVisible&&this.canMove){with (this.position){l+=dx;t+=dy;window.status='x'+l+';y'+t;var o=document.getElementById(this.idStr);o.style.left=l;o.style.top=t}}};
  this.run= function(){if(this.onRun)eval(this.onRun);else this.doRun()};
  this.doRun=function(){this.show()};
};
regClass(TWin,TCon);


function TMsgBox(){
  this.classType='TMsgBox';
  this.msgHeader='Information';
  this.defWidth=400;
  this.defHeight=150;
  this.bodyClass='wmsgb';
  this.headClass='wmsg';
  this.center=true;
  this.bodyStyle='overflow:hidden; color:#AAFF77;';
  var inherSetup  = this.setup;
  this.actionStr='';
  this.setup      = function(msg,fnc){
    with (this){
      inherited(inherSetup).method('msgBox',msgHeader);
      pos((appWidth-defWidth)/2,(appHeight-defHeight)/2,defWidth,defHeight);
      if(fnc)onClose=fnc;
      with (head){
        cssClass=headClass;
        optRight = fnClose(this.idStr);
      };
      with (body){
        padding=2;
        style=bodyStyle;
        cssClass=bodyClass;
        body.fixHtml=(center)?'<center>'+msg+'</center>':msg;
      };
      if(actionStr>'')
      with (body.add(TLnk)){pos(body.position.w/2-40,body.position.h-28); setup('btOk',actionStr,this.idStr+'.onClose()'); title='OK, weiter ...'};
    };
  };
};
regClass(TMsgBox,TWin);

function TMsgBoxInfo(){};
regClass(TMsgBoxInfo,TMsgBox);

function TMsgBoxWait(){};
regClass(TMsgBoxWait,TMsgBox);

function TMsgBoxWarning(){};
regClass(TMsgBoxWarning,TMsgBox);

function msg(msgType,msg,fnc){
  var h=new msgType();
  with(h){setup(msg,fnc);show()};
  return h;
};
