//+-----------------------------------------------------------------------------+
//| alva & phoenix GmbH                                                         |
//| Gjuchstrasse 19                                                             |
//| 8953 Dietikon                                                               |
//+-----------------------------------------------------------------------------+
//| Projektbezeichnung: yourinternet                                            |
//+-----------------------------------------------------------------------------+
//| Datei:              dynlib.js                                               |
//+-----------------------------------------------------------------------------+
//| Das Urheberrecht an diesem Dokument (Code) verbleibt auf unbeschränkte Zeit |
//| bei der alva & phoenix GmbH, Dietikon. Ohne deren schriftliche Einwilligung |
//| darf es weder vervielfaeltigt, veraendert noch an Dritte, auch nicht in ab- |
//| geaenderter Form, ganz oder teilweise mitgeteilt, zugaenglich oder nutzbar  |
//| gemacht werden. Dieses Dokument ist nach Art. 2 Abs. 3 URG urheberrechtlich |
//| geschützt. Des weiteren gelten die Allgemeinen Geschäftsbedingungen der     |
//| alva & phoenix GmbH, Dietikon                                               |
//+-----------------------------------------------------------------------------+
// 
// Development History:
// 2002-01-01	author	Description

var bDHTML = (document.getElementById || document.all ? true : false);
var bNS6 = (document.getElementById && !document.all ? true : false);
var bNS = (bDHTML || bNS6 ? false : true);
var dynLayers = new Array();

function dynLayer(id, parent)
{
	this.name = id;
	if (bDHTML && document.getElementById) {
		this.obj = document.getElementById(id);
		//this.name = this.obj.id;
	}
	else if (bDHTML && document.all) {
		this.obj = document.all[id];
		//this.name = this.obj.id;
	}
	
	if (bNS)
	{
		if (parent)
			this.obj = parent.obj.document.layers[id];
		else
			this.obj = document.layers[id];
		//this.name = this.obj.name;
	}
	this.event = this.obj;
	
	this.left = dynLeft;
	this.top = dynTop;
	this.pos = dynPos;
	this.moveby = dynMoveBy
	this.width = dynWidth;
	this.height = dynHeight;
	this.setHTML = dynSetHTML;
	this.vis = dynVis;
	this.toggleVis = dynToggleVis;
	this.zIndex = dynZIndex;
	this.clip = dynClip;
	this.bg = dynBG;

	dynLayers[this.name] = this;
}

function dynLeft(newLeft)
{
	if (newLeft != null)
	{
		if (bDHTML)
			this.obj.style.left = newLeft;
		if (bNS)
			this.obj.left = newLeft;
	}
	else
	{
		if (bDHTML)
			return this.obj.offsetLeft;
		if (bNS)
			return this.obj.left;
	}
}

function dynTop(newTop)
{
	if (newTop != null)
	{
		if (bDHTML)
			this.obj.style.top = newTop;
		if (bNS)
			this.obj.top = newTop;
	}
	else
	{
		if (bDHTML)
			return this.obj.offsetTop;
		if (bNS)
			return this.obj.top;
	}
}

function dynPos(newX, newY)
{
	this.left(newX);
	this.top(newY);
}

function dynMoveBy(dx, dy)
{
  this.pos(this.left() + dx, this.top() + dy);
}

function dynWidth(newWidth)
{
	if (newWidth != null)
	{
		if (bDHTML)
			this.obj.style.pixelWidth = newWidth;
		if (bNS)
			this.obj.document.width = newWidth;
	}
	else
	{
		if (bDHTML)
			return this.obj.offsetWidth;
		if (bNS)
			return this.obj.document.width;
	}
}

function dynHeight(newHeight)
{
	if (newHeight != null)
	{
		if (bDHTML)
			this.obj.style.pixelHeight = newHeight;
		if (bNS)
			this.obj.document.height = newHeight;
	}
	else
	{
		if (bDHTML)
			return this.obj.offsetHeight;
		if (bNS)
			return this.obj.document.height;
	}
}

function dynSetHTML(newHTML)
{
	if (bDHTML)
		this.obj.innerHTML = newHTML;
	if (bNS)
	{
		this.obj.document.open();
		this.obj.document.write(newHTML);
		this.obj.document.close();
		if (this.init)
		  this.init();
	}
}

function dynVis(bShow)
{
	if (bShow != null)
	{
		if (bDHTML)
			this.obj.style.visibility = (bShow ? "visible" : "hidden");
		if (bNS)
			this.obj.visibility = (bShow ? "show" : "hide");
	}
	else
	{
		if (bDHTML)
			return (this.obj.style.visibility != "hidden");
		if (bNS)
			return (this.obj.visibility != "hide");
	}
}

function dynToggleVis()
{
	this.vis(!this.vis());
}

function dynZIndex(newZIndex)
{
	if (newZIndex != null)
	{
		if (bDHTML)
			this.obj.style.zIndex = newZIndex;
		if (bNS)
			this.obj.zIndex = newZIndex;
	}
	else
	{
		if (bDHTML)
			return this.obj.style.zIndex;
		if (bNS)
			return this.obj.zIndex;
	}
}

function dynClip(x, y, width, height)
{
	if (x != null && y != null && width != null && height != null)
	{
		if (bDHTML)
			this.obj.style.clip = "rect(" + y + " " + (x + width) + " " + (y + height) + " " + x + ")";
		if (bNS)
		{
			this.obj.clip.left = x;
			this.obj.clip.top = y;
			this.obj.clip.width = width;
			this.obj.clip.height = height;
		}
	}
	else
	{
		if (bDHTML)
			this.obj.style.clip = "rect(auto auto auto auto)";
		if (bNS)
		{
			this.obj.clip.left = 0;
			this.obj.clip.top = 0;
			this.obj.clip.width = this.obj.document.width;
			this.obj.clip.height = this.obj.document.height;
		}
	}
}

function dynBG(src)
{
	if (src != null)
	{
		if (bDHTML)
			this.obj.style.background = src;
		if (bNS)
			this.obj.background.src = src;
	}
	else
	{
		if (bDHTML)
			return this.obj.style.background;
		if (bNS)
			return this.obj.background.src;
	}
}

function GetDynLayer(obj)
{
 return dynLayers[obj.id];
}

// doc Object

function doc()
{
	this.width = docWidth;
	this.height = docHeight;
	this.clientWidth = docClientWidth;
	this.clientHeight = docClientHeight;
}

function docWidth()
{
	if (bNS6)
		return document.body.offsetWidth;
	if (bDHTML)
		return document.body.offsetWidth;
	if (bNS)
		return document.width;
}

function docHeight()
{
	if (bNS6)
		return document.body.offsetHeight;
	if (bDHTML)
		return document.body.offsetHeight;
	if (bNS)
		return document.height;
}

function docClientWidth()
{
	if (bNS6)
		return document.body.offsetWidth;
	if (bDHTML)
		return document.body.scrollWidth;
	if (bNS)
		return document.width; //window.innerWidth;
}

function docClientHeight()
{
	if (bNS6)
		return document.body.offsetHeight;
	if (bDHTML)
		return document.body.scrollHeight;
	if (bNS)
		return document.height; //window.innerHeight;
}


// drag Object

function drag(id, parent)
{
 this.BaseClass = dynLayer;
 this.BaseClass(id, parent);
 
 this.init = dragInit;
 this.init();
 
 this.dx = 0;
 this.dy = 0;
}

function dragInit()
{
 if (this.event.captureEvents)
  this.event.captureEvents(Event.MOUSEDOWN);
 this.event.onmousedown = dragOnMouseDown;
}

function dragOnMouseDown(e)
{
 var ret = true;
 var dd = new dragdata(GetDynLayer(this), bNS || bNS6 ? e : window.event);
 SetCapture(this);

 if (typeof(OnBeginDrag) == "function")
  ret = OnBeginDrag(dd) ? true : false;
 if (ret)
 {
  GetDynLayer(this).dx = dd.x;
  GetDynLayer(this).dy = dd.y;
 }
 else
  ReleaseCapture();
 return !ret;
}

function dragOnMouseMove(e)
{
 var ret = true;
 var dd = new dragdata(GetDynLayer(CapturingObject), bNS || bNS6 ? e : window.event);
 
 if (typeof(OnDrag) == "function")
  ret = OnDrag(dd) ? true : false;
 if (ret)
 {
  dd.src.moveby(dd.x - dd.src.dx, dd.y - dd.src.dy);
  dd.src.dx = dd.x;
  dd.src.dy = dd.y;
 }
 else
  ReleaseCapture();
 return !ret;
}

function dragOnMouseUp(e)
{
 var ret = true;
 var dd = new dragdata(GetDynLayer(CapturingObject), bNS || bNS6 ? e : window.event);

 if (typeof(OnDrop) == "function")
 {
  ret = OnDrop(dd) ? true: false;
 }
 ReleaseCapture();
 return !ret;
}

// dragdata Object

function dragdata(source, e)
{
 this.src = source;
 this.x = 0;
 this.y = 0;
 this.offsetX = 0;
 this.offsetY = 0;
 this.altKey = false;
 this.ctrlKey = false;
 this.shiftKey = false;
 this.button = 0;

 if (bNS)
 {
  this.x = e.pageX;
  this.y = e.pageY;
  this.offsetX = e.layerX;
  this.offsetY = e.layerY;
  this.altKey = e.modifiers & Event.ALT_MASK ? true : false;
  this.ctrlKey = e.modifiers & Event.CONTROL_MASK ? true : false;
  this.shiftKey = e.modifiers & Event.SHIFT_MASK ? true : false;
  this.button = e.which;
 }
 if (bDHTML)
 {
  this.x = e.clientX;
  this.y = e.clientY;
  this.offsetX = e.offsetX;
  this.offsetY = e.offsetY;
  this.altKey = e.altKey;
  this.ctrlKey = e.ctrlKey;
  this.shiftKey = e.shiftKey;
  this.button = e.keyCode;
 }
}

var prevOnMouseMove = null;
var prevOnMouseUp = null;
var CapturingObject = null;

function SetCapture(obj)
{
 if (document.captureEvents)
  document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
 prevOnMouseMove = document.onmousemove;
 prevOnMouseUp = document.onmouseup;
 document.onmousemove = dragOnMouseMove;
 document.onmouseup = dragOnMouseUp;
 CapturingObject = obj;
}

function ReleaseCapture()
{
 document.onmousemove = prevOnMouseMove;
 document.onmouseup = prevOnMouseUp;
 CapturingObject = null;
}