// copyright by edv-organisation thomas päpenmöller gen. peppmöller, Bielefeld, www.edv-organisation.de

// declare
var tabStack=0;
var imgpath='/images/';
var soundpath='/sounds/';

var cHand='pointer';
var screenUnderSize=false;
var masterVolume=0.0; // db normal
var backgroundVolume=0.0; // db
var cSpeed='HI'; // LO/ME/HI/
var soundPlayer=null;
var centerApp=true;
var noAlphaImg=false;
var getRealSize=false;
window.status="visiLib 2.11 (c) Manaz GmbH";

//functions
var uAgent=navigator.userAgent,isIE=false,isIE5=false,ieVersion=0,isFirefox=false,i=uAgent.indexOf('MSIE'),isOpera=uAgent.indexOf('Opera')>-1;
if(i>0&&!isOpera){
  isIE=true;
  ieVersion=parseFloat(uAgent.substr(i+5));
  isIE5=(ieVersion<5.5);
}
else {
  isFirefox=(uAgent.indexOf('Firefox')>0?true:false);
};
modLeMedia=null;

if(isIE5)cHand='hand';

if(!window.innerWidth){
  window.iWidth=function(){return document.body.clientWidth};
  window.iHeight=function(){return document.body.clientHeight};
}
else {
  window.iWidth=function(){return window.innerWidth};
  window.iHeight=function(){return window.innerHeight};
};


function encodeData(data){
  if(isIE5)var s=escape(escape(data)); else var s=encodeURI(escape(data));
  return s.replace(/\+/g,'%2B');
};

function opt(){
  a=new Array();
  for (var c=0;c<arguments.length;c++)a[c]=arguments[c];
  return a;
};

function doMouseOver (){this.src=this.obj.imgOver.src};
function doMouseOut  (){this.src=this.obj.imgOut.src};
function doMouseDown (){this.src=this.obj.imgDown.src};
function doMouseUp   (){this.src=this.obj.imgOver.src};


//xmlHttp
var xmlHttp = new Array(), xmlOnReady=new Array(), xmlReqCount=0;
function createXmlHttp(ch){
  xmlHttp[ch] = false;
  if (window.XMLHttpRequest) {
    xmlHttp[ch] = new XMLHttpRequest();
  }
  else {
    if (window.ActiveXObject) {
      try {
        xmlHttp[ch]  = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        try {
          xmlHttp[ch]  = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
          xmlHttp[ch]  = false;
        }  
      }
    }
  }
}

function catchReady(ch){
  if (xmlHttp[ch]&&xmlHttp[ch].readyState == 4) {
    if(xmlOnReady[ch])xmlOnReady[ch](ch);
  };
};
function catchCh0(){catchReady(0)};
function catchCh1(){catchReady(1)};
function catchCh2(){catchReady(2)};
function catchCh3(){catchReady(3)};

function httpGet(url,fnc,async,ch){
  xmlReqCount++;
  //window.status='req '+xmlReqCount;
  if(!xmlHttp[ch])createXmlHttp(ch);
  if (!xmlHttp[ch]) alert('no XMLHttpRequest')
  else {
    xmlHttp[ch].abort();  // scheiße
    if(fnc)xmlOnReady[ch]=fnc; else xmlOnReady[ch]=false;
    xmlHttp[ch].onreadystatechange=eval('catchCh'+ch);
    xmlHttp[ch].open('GET', url, async);
    xmlHttp[ch].send(null);
  }
};
function httpClose(ch){
  if(!ch)ch=0;
  xmlOnReady[ch]=false;
  if(xmlHttp[ch]){
    var h=xmlHttp[ch];
    xmlHttp[ch]=false;
    h.abort();
  };
};

function containsNode(pNode,cNode){
  while (cNode!=document&&cNode!=null){
    if(cNode==pNode)return true;
    cNode=cNode.parentNode;
  };
  return false;
};

// Objects
function TVWinStyle(){
  this.winBorder='border-style: solid; border-width: 1px; border-color: #C0FFD0 #003300 #003300 #C0FFD0';
  this.winBG='';
  this.headBG='#c0c0c0';
  this.headStyle='';
};

function hImg(l,t,src,cmd){
  return '<img style="position:absolute; left:'+l+'; top:'+t+';'+(cmd?'cursor:pointer;':'')+'" border="0" src="'+imgpath+src+'" '+(cmd?'onClick="'+cmd+'"':'')+'>';
};

function posALay(){
  with (aLay.style) {
    window.ofsLeft=(iWidth()-appWidth)/2;left=(ofsLeft>0)?ofsLeft:0;
    window.ofsTop=(iHeight()-appHeight)/2;top=(ofsTop>0)?ofsTop:0;
 };
};

var moveObj=null,startMoveX=0;startMoveY=0;

function startMove(obj,event){
  blockSelect++;
  with (event){
    cancelBubble=true; 
    if(isFirefox)preventDefault();
    startMoveX=clientX;
    startMoveY=clientY;
  };
  moveObj=obj;
  window.status='move '+obj.idStr;
  with(document.body){onmousemove=bodyMoveObj;onmouseup=bodyMouseUp};
};

function stopMove(){moveObj=null;with(document.body){onmousemove=null;onmouseup=null};blockSelect=0};

function bodyMoveObj(ev){
  if (moveObj){
    if(!ev)ev=event;
    with (ev){
      cancelBubble=true; 
      if(isFirefox)preventDefault();
      moveObj.onWinMove(clientX-startMoveX,clientY-startMoveY);
      startMoveX=clientX;
      startMoveY=clientY;
    };
  } else document.body.onmousemove=null;
};
function bodyMouseUp(){stopMove()};

var loadClassParam='';
function loadClass(formClass){
  var src='php/resource/mLoad.php?getClass='+formClass+'&reqCount='+xmlReqCount+loadClassParam;
  httpGet(src,0,false,0);
  if (xmlHttp[0].readyState == 4) {
    window[formClass]=false;
    //alert(xmlHttp.responseText);
    var buffer=xmlHttp[0].responseText; // evtl recusiver Aufruf durch eval
    httpClose(0);
    window.eval(buffer);
    if(isIE&&!window[formClass]){
      var c=eval(formClass);
      if(c)window[formClass]=c;
    };
    if(!window[formClass])alert('Error:\n_________\n\n Can\'t load resource "'+formClass+'"');
  };
};

function classExist(className){
  if(!window[className]||window[className].reload)loadClass(className);
  return window[className]
};
function openForm(parent,formName,formClass,par1,par2,par3,par4,par5){
  var h=parent==window?window.all[formName]:parent[formName];
  if(h&&formClass==h.classType&&!window[formClass].reload){
    h.popupWin();
    h.run(par1,par2,par3,par4,par5);
  }
  else{
    if (classExist(formClass)){
      if (parent==window)h=new window[formClass]();
      else h=parent.add(window[formClass]);
      with (h){
        h.classType=formClass;
        setup(formName,par1,par2,par3,par4);
        run(par1,par2,par3,par4,par5);        
      };
    };
  };
  return h;
};

var preImages = new Array();
var aktPath ='';

function pimg(name,path){
  if(aktPath=='')aktPath=imgpath;
  if(path)aktPath=imgpath+path;
  preImages[preImages.length]=aktPath+name;
};


function limg(name){
  var h=imgpath+name;
  return ' src="'+h+'" ';
};

function alphaImg(bgAlpha){
  if(isIE5||noAlphaImg) var h='background-image:url('+imgpath+'alpha/'+bgAlpha+'.gif);';
  else {
    if(ieVersion>5.5){
      var h='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+imgpath+'alpha/'+bgAlpha+'.png\', sizingMethod=\'scale\');';
    }
    else var h='background-image:url('+imgpath+'alpha/'+bgAlpha+'.png);';
  };
  return h;
};

function runStep(nStep){
  setTimeout(nStep,10);
};

function doLoadImages(){
  var loadet=true;
  if(document.images){
    if(!document.preloadImg)document.preloadImg = new Array();
    with(document)
    for(var i=0;i<preImages.length;i++)
    if(!preImages[i]){
      if(preloadImg[i].readyState=='loading')loadet=false;
    }
    else {
      preloadImg[i]=new Image();
      preloadImg[i].src=preImages[i];
      preImages[i]=false;
      loadet=false;
    };
  };
  return loadet;
};

function initLib(appInit){
  if(!doLoadImages())setTimeout("initLib('"+appInit+"')",10);
  else {
    window.aLay=document.getElementById('appLayer');
    if (centerApp){
      posALay();
      window.onresize=posALay;
    };
    var hw=iWidth();
    var hh=iHeight();
    if(appWidth>hw||appHeight>hh){
      if(appWidth>hw)hw=appWidth;
      if(appHeight>hh)hh=appHeight;
      if (isIE){
        try {
          window.resizeTo(640,480);
        } catch(e) {
          window.cantResizeWin=true;
        }  
        if(!window.cantResizeWin){
          var hx=640-iWidth();
          var hy=480-iHeight();
          try {
            window.resizeTo(hw+hx+2,hh+hy);
          } catch(e) {
            window.cantResizeWin=true;
          }  
        }
      }
      else{
        window.innerWidth=hw+10;
        window.innerHeight=hh+10;
      };
      if(minWidth>iWidth()||minHeight>iHeight()){
        screenUnderSize=true;
        appWidth=iWidth()-4;appHeight=iHeight()-21;
      };
    };
    if(getRealSize){appWidth=iWidth()-2;appHeight=iHeight()-2};
    var hStr='';
    for(var i=0;i<10;i++)hStr+='<div style="position:absolute" id="'+i+'"></div> ';
    for(var i=0;i<3;i++) hStr+='<div style="position:absolute" id="SND'+i+'"></div> ';
    aLay.innerHTML=hStr;
    with (aLay.style) {
      width=appWidth;
      height=appHeight;
      window.blockSelect=0;
      document.body.onselectstart=function(){
        if(window.blockSelect){
          event.cancelBubble=true;
          event.returnValue=false;
        };
      };
    };
    window.eval(appInit);
  };
};

var cookieData=new Object();
cookieData['pngAlpha']='1';

function readCookie(){
  var h=document.cookie;
  var p=h.indexOf('zw=');
  if(p>=0){
    h=unescape(h.substr(p+3).split(';')[0]);
    if(h>''){
      h=h.split(';');
      for(var i=0;i<h.length;i++){
        var v=h[i].split('=');
        cookieData[v[0]]=unescape(v[1]);
      };
    };    
  };
};
readCookie();
if(cookieData['pngAlpha']!='1')noAlphaImg=true;

function saveCookie(){
  var d="";
  for (var e in cookieData){
    d+=e+'='+escape(cookieData[e])+';';
  };
  var h='zw='+escape(d)+'; expires='+new Date(new Date().getTime()+30*24*60*60*1000).toGMTString();
  document.cookie=h;
};

function cookieOpt(n,def){
  if(!window.cookieData[n])return def;
  else return window.cookieData[n];
};
