// Modul:        shortlib.js
//
// Purpose:      Standard functions.
// Dependencies: none
//
// Author:       Riad Shalaby (riad.shalaby@bytecom.net)
// copyright:    1999 ByteCom GmbH 
// Last Changed: 25.11.1999

function whatBrowser ()
{
   var agt=navigator.userAgent.toLowerCase(); 

   this.major = parseInt(navigator.appVersion); 
   this.minor = parseFloat(navigator.appVersion); 
   this.MajorVer = parseInt(navigator.appVersion.charAt(0));
   this.MinorVer1 = parseInt(navigator.appVersion.charAt(2));
   this.MinorVer2 = parseInt(navigator.appVersion.charAt(3));

   this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) 
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) 
                && (agt.indexOf('webtv')==-1)); 
   this.nav2 = (this.nav && (this.major == 2)); 
   this.nav3 = (this.nav && (this.major == 3)); 
   this.nav4 = (this.nav && (this.major == 4)); 
   this.nav4up = (this.nav && (this.major >= 4)); 
   this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) || 
                          (agt.indexOf("; nav") != -1)) ); 
   this.nav5 = (this.nav && (this.major == 5)); 
   this.nav5up = (this.nav && (this.major >= 5)); 

   this.ie   = (agt.indexOf("msie") != -1); 
   this.ie3  = (this.ie && (this.major < 4)); 
   this.ie4  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")==-1) ); 
   this.ie4up  = (this.ie  && (this.major >= 4)); 
   this.ie5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) ); 
   this.ie5up  = (this.ie  && !this.ie3 && !this.ie4); 

   this.win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) ); 
   this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1)); 
   this.win16 = ((agt.indexOf("win16")!=-1) || 
                 (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || 
                 (agt.indexOf("windows 16-bit")!=-1) ); 

   this.win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) || 
                  (agt.indexOf("windows 16-bit")!=-1)); 
   this.winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1)); 
   this.win32 = ( this.win95 || this.winnt || this.win98 || 
                 ((this.major >= 4) && (navigator.platform == "Win32")) || 
                 (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1) ); 

   this.os2   = ((agt.indexOf("os/2")!=-1) || 
                 (navigator.appVersion.indexOf("OS/2")!=-1) || 
                 (agt.indexOf("ibm-webexplorer")!=-1)); 

   this.mac    = (agt.indexOf("mac")!=-1); 
   this.mac68k = (this.mac && ((agt.indexOf("68k")!=-1) || 
                              (agt.indexOf("68000")!=-1))); 
   this.macppc = (this.mac && ((agt.indexOf("ppc")!=-1) || 
                              (agt.indexOf("powerpc")!=-1))); 

   this.sun   = (agt.indexOf("sunos")!=-1); 
   this.sun4  = (agt.indexOf("sunos 4")!=-1); 
   this.sun5  = (agt.indexOf("sunos 5")!=-1); 
   this.suni86= (this.sun && (agt.indexOf("i86")!=-1)); 
   this.irix  = (agt.indexOf("irix") !=-1);    // SGI 
   this.irix5 = (agt.indexOf("irix 5") !=-1); 
   this.irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1)); 
   this.hpux  = (agt.indexOf("hp-ux")!=-1); 
   this.hpux9 = (this.hpux && (agt.indexOf("09.")!=-1)); 
   this.hpux10= (this.hpux && (agt.indexOf("10.")!=-1)); 
   this.aix   = (agt.indexOf("aix") !=-1);      // IBM 
   this.aix1  = (agt.indexOf("aix 1") !=-1); 
   this.aix2  = (agt.indexOf("aix 2") !=-1); 
   this.aix3  = (agt.indexOf("aix 3") !=-1); 
   this.aix4  = (agt.indexOf("aix 4") !=-1); 
   this.linux = (agt.indexOf("inux")!=-1); 
   this.sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1); 
   this.unixware = (agt.indexOf("unix_system_v")!=-1); 
   this.mpras    = (agt.indexOf("ncr")!=-1); 
   this.reliant  = (agt.indexOf("reliantunix")!=-1); 
   this.dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || 
        (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || 
        (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)); 
   this.sinix = (agt.indexOf("sinix")!=-1); 
   this.freebsd = (agt.indexOf("freebsd")!=-1); 
   this.bsd = (agt.indexOf("bsd")!=-1); 
   this.unix  = ((agt.indexOf("x11")!=-1) || this.sun || this.irix || this.hpux || 
                this.sco ||this.unixware || this.mpras || this.reliant || 
                this.dec || this.sinix || this.aix || this.linux || this.bsd || 
                this.freebsd); 

   this.vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1)); 
}

var br = new whatBrowser();

var dl = document.layers;
var da = document.all;

function rl()
{
	var obj;
	if (dl)
	{
		obj = dl[arguments[0]];
		for (var i = 1 ; i < arguments.length ; i++)
		{
			obj = obj.document.layers[arguments[i]];
		}	
	} 
	else if (da) obj = da[arguments[arguments.length-1]];
	return obj;
}

function rls()
{
	var obj;
	if (dl)
	{
		obj = dl[arguments[0]];
		for (var i = 1 ; i < arguments.length ; i++)
		{
			obj = obj.document.layers[arguments[i]];
		}	
	} 
	else 	if (da) obj = da[arguments[arguments.length-1]].style;
	
	return obj;
}

function Memo() {this.container = new Array();this.number = 0;}
function Memo_add() {this.number += 1; this.container[this.number] = new Object();return this.number}
function Memo_getref(n) {return this.container[n];}
function Memo_release(n) {this.container[n] = null;}
Memo.prototype.add = Memo_add;
Memo.prototype.getref = Memo_getref;
Memo.prototype.release = Memo_release;
var mem = new Memo();

function writeLayer(obj,content)
{
	if (br.nav4up)
	{
		obj.document.open();
		obj.document.write(content);
		obj.document.close();
	}
	if (br.ie4up)
	{
		obj.innerHTML = content;
	}
}

function clipLayer(obj,x,y,width,height) 
{
	var bottom = y+height;
	var right = x+width;
	if (br.nav4up) 
	{
		obj.clip.top = y;
		obj.clip.left = x;
		obj.clip.bottom = bottom;
		obj.clip.right = right;
	} 
	if (br.ie4up) 
	{
		obj.style.clip = 'rect('+y+','+right+','+bottom+','+x+')';
	}
}

function setChildImage(obj,iname,src)
{
	if (br.nav4up){obj.document.images[iname].src = src;}
	if (br.ie4up){document.images(iname).src = src;}
}

function setChildImageHeight(obj,iname,height)
{
	if (br.nav4up){obj.document.images[iname].height = height;}
	if (br.ie4up){document.images(iname).height = height}
}

function LayerObject(obj)
{
	this.obj = obj;
	this.id = getObjID(obj);
	this.left = getObjLeft(obj);
	this.top = getObjTop(obj);
	this.width = getObjWidth(obj);
	this.height = getObjHeight(obj);
}

function setObjPos(obj, x, y,fn) {if (br.nav4up) {obj.left = x;obj.top = y;} else {obj.style.pixelLeft = x;obj.style.pixelTop = y;} if (fn){eval(fn+";");}}
function shiftObjPos(obj,dx,dy) {if (br.nav4up) {obj.left += dx;obj.top += dy;} else {obj.style.pixelLeft = obj.offsetLeft + dx;obj.style.pixelTop = obj.offsetTop + dy;}}
function getObjLeft(obj) {return (br.nav4up ? obj.left : (br.ie5up ? obj.offsetLeft : obj.style.pixelLeft))}
function getObjTop(obj) {return (br.nav4up ? obj.top : (br.ie5up ? obj.offsetTop : obj.style.pixelTop))}
function getObjWidth(obj) {return (br.nav4up ? obj.clip.width : (br.ie5up ? obj.offsetWidth : obj.style.pixelWidth))}
function getObjHeight(obj) {return (br.nav4up ? obj.clip.height : (br.ie5up ? obj.offsetHeight : obj.style.pixelHeight))}
function getObjcliWidth(obj) {return (br.nav4up ? obj.clip.width : obj.clientWidth)}
function getObjcliHeight(obj) {return (br.nav4up ? obj.clip.height : obj.clientHeight)}
function setObjWidth(obj,width) { if (br.nav4up) {obj.clip.width = width} else {obj.style.pixelWidth = width}}
function setObjHeight(obj,height) {if (br.nav4up) {obj.clip.height = height} else {obj.style.pixelHeight = height}}
function getObjMiddleX(obj) {return (br.nav4up ? obj.left+obj.clip.width / 2 : getObjLeft(obj)+getObjWidth(obj) / 2)}
function getObjMiddleY(obj) {return (br.nav4up ? obj.top+obj.clip.height / 2 : getObjTop(obj)+getObjHeight(obj) / 2)}
function getObjID(obj) {return(br.nav4up ? obj.name : obj.id)}
function showObj(obj,fn) {if (br.nav4up) {obj.visibility = "show";} else {obj.style.visibility = "visible";}if (fn) eval(fn+";");}
function hideObj(obj,fn) {if (br.nav4up) {obj.visibility = "hide";} else {obj.style.visibility = "hidden";}if (fn)	eval(fn+";");}
function show(l) {rls(l).visibility = dl ? "show" : "visible";}
function hide(l) {rls(l).visibility = dl ? "hide" : "hidden";}



function scrHeight(){return screen.height;}
function scrWidth(){return screen.width;}
function scrAvailHeight(){return screen.availHeight;}
function scrAvailWidth(){return screen.availWidth;}
function scrColorDepth() {return screen.colorDepth;}
function cliInnerHeight(obj) {return ( br.nav4up ? obj.innerHeight : (br.ie4up ? obj.document.body.clientHeight : 0))}
function cliInnerWidth(obj) {return ( br.nav4up ? obj.innerWidth : (br.ie4up ? obj.document.body.clientWidth : 0))}
function numFrames() {return top.window.length;}

function moveTo (obj,x,y,fn,steps,wait,interval,ninterval) 
{
	var s = ( steps == null ? 100 : steps);
	var w = ( wait == null ? 0 : wait);
	var i = ( interval == null ? 2 :  interval);
	var ni = (ninterval == null ? 0 : ninterval);
	i += (((ni > 0)  && br.nav4up) ? ni : 0);
	move(obj,getObjLeft(obj),getObjTop(obj),x,y,fn,s,w,i);
}

function moveBy (obj,dx,dy,fn,steps,wait,interval,ninterval)
{
	moveTo(obj,getObjLeft(obj)+dx,getObjTop(obj)+dy,fn,steps,wait,interval,ninterval);
}

function move(obj,x1,y1,x2,y2,fn,steps,wait,interval)
{
	var n = mem.add();	
	var o = mem.getref(n); 
	o.obj = obj;
	o.aktx = x1;
	o.akty = y1;
	o.x2 = x2;
	o.y2 = y2;
	o.steps = (steps == null ? 100 : steps);
	o.wait = ( wait == null ? 0 : wait);
	o.fn = fn;
	o.Hmove = setInterval("domoving('"+n+"')",( interval == null ? 1 : interval));
}

function domoving (n)
{
	var o = mem.getref(n);
	o.aktx += (o.x2 - o.aktx)/o.steps;
	o.akty += (o.y2 - o.akty)/o.steps;
	if (o.wait >  0) {o.wait -= 1;} else {o.steps -= 1;}
	setObjPos(o.obj,o.aktx,o.akty);
	if (o.steps == 0) 
	{
		clearInterval(o.Hmove);
		mem.release(n);
		if (o.fn)	eval(o.fn+";");	
	}
}	

function Animator()
{
	this.container = new Array();
	this.number = 0;
	this.actual = 0;
}

function Animator_add(fn,wait)
{
	var n = this.number
	this.container[n] = new Object();
	this.container[n].wait = wait;
	this.container[n].fn = fn;
	this.number += 1;
	this.stopNow = false;
	this.fnAfterStop = null;
	this.working = false;
}

function Animator_start(fn)	
{
	this.stopNow = false;
	this.fnAfterStop = null;
	this.actual = 0;
	this.working = true;
	this.next();
	if (fn) eval(fn+";");
}

function Animator_next()
{
	if (!this.stopNow) 
	{
		if (this.actual < this.number)
		{
			this.working = true;
			setTimeout(this.container[this.actual].fn,this.container[this.actual].wait);
			this.actual += 1;
		} else
		{
			this.working = false;
		}
	} else 
	{
		this.working = false;
		if (this.fnAfterStop) setTimeout(this.fnAfterStop,this.container[0].wait);
	}
}

function Animator_stop(fn)
{
	this.stopNow = true;	
	this.fnAfterStop = fn;		
}

function Animator_inProgress()
{
	return(this.working);
}

Animator.prototype.next = Animator_next;
Animator.prototype.add = Animator_add;
Animator.prototype.start = Animator_start;
Animator.prototype.stop = Animator_stop;
Animator.prototype.inProgress = Animator_inProgress;

function showWindow(url,titel)
{
	var t = (titel? titel : 'bytecom');
	return (window.open(url,t,"toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no"));
}

function showWindow2(url,titel,width,height,toolbars)
{
	var t = (titel? titel : 'bytecom');
	if (!toolbars) 
	{
		return (window.open(url,t,"toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height));
	} else
	{
		return (window.open(url,t,"toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width="+width+",height="+height));
	}
	
}

