/*
// <module		name		="BMEOBJECTS"
//				src			="bmeobjects.js"
//				language	="JavaScript"
//				purpose		="Multi-purpose cross-browser JavaScript objects generation"
//				copyright	="Copyright (c) 2001-2002 by Manfred Baumeister, Dublin"
//				author		="Manfred Baumeister" authorid="mb" />
// <audit>
// <ecr			author		="mb" date="05/05/2002"	todo="NS4 compatibility check" />
// <ecn			author		="mb" date="04/05/2002"	note="DHTML methods added to bmeDomObject" />
// <ecn			author		="mb" date="18/10/2001"	note="Original coding" />
// </audit>
// <functions>
// <function	name	="bmeBrowser"
//				purpose	="Create web browser object with feature sensing methods" />
// <function	name	="bmeDomObject"
//				purpose	="Create DOM object with cross-browser DHTML and CSS/style access methods for given object id" />
// </functions>
// </module>
*/

//______________________________________________________________

function bmeBrowser()
// Create web browser object with OO methods for browser detection and feature sensing
{
	// Fill browser check object entities
	this.ver		= navigator.appVersion;
	this.versionnum	= parseInt(this.ver);
	this.agent		= navigator.userAgent;

	// Document object model
	this.isDom		= function() { return document.getElementById ? 1 : 0; }

	// Opera browser detection
//	this.isOpera	= function() { return this.agent.indexOf("Opera") > -1 ? 1 : 0; }
	this.isOpera	= function() { return window.opera ? 1 : 0; }
	this.isOpera5	= function() { return this.isOpera() && this.versionnum <= 5 ? 1 : 0; }
	this.isOpera6	= function() { return this.isOpera() && this.versionnum >= 6 ? 1 : 0; }
	// Netscape browser detection
	this.isNS4		= function() { return (document.layers && !this.isDom()) ? 1 : 0; }
	this.isNS6		= function() { return this.isDom() && this.versionnum >= 5 && !this.isOpera() ? 1 : 0; }
	this.isNS		= function() { return this.isNS4() || this.isNS6() ? 1 : 0; }
	// Internet Explorer browser detection
	this.isMSIE4	= function() { return document.all && !this.isDom() && !this.isOpera() ? 1 : 0; }
	this.isMSIE5	= function() { return this.ver.indexOf("MSIE 5") > -1 && this.isDom() && !this.isOpera() ? 1 : 0; }
	this.isMSIE6	= function() { return this.ver.indexOf("MSIE 6") > -1 && this.isDom() && !this.isOpera() ? 1 : 0; }
	this.isMSIE		= function() { return this.isMSIE6() || this.isMSIE5() || this.isMSIE4() ? 1 : 0; }

	// DHTML support detection
	this.isDHTML	= function() { return this.isMSIE() || this.isNS() || this.isOpera() ? 1 : 0; }

	// Operating system detection
	this.isMac		= function() { return this.agent.indexOf('Mac') > -1 ? 1 : 0; }

	// Browser positioning units
	this.PosUnits	= function() { return this.isNS4() || this.isOpera() ? '' : 'px'; }

	// Page property access
	this.getPageTitle	= function()	{ return document.title; }
	this.getPageUri		= function()	{ return self.location; }
	this.getPageWidth	= function()
		{
			if (window.innerWidth != null)
			{
				return parseInt(window.innerWidth);
			}
			if (document.body.clientWidth != null)
			{
				return parseInt(document.body.clientWidth);
			}
			return 0;
		}
	this.getPageHeight	= function()
		{
			if (window.innerHeight != null)
			{
				return parseInt(window.innerHeight);
			}
			if (document.body.clientHeight != null)
			{
				return parseInt(document.body.clientHeight);
			}
			return 0;
		}

	this.getProps	= function()
		{
			return 'BROWSER PROPERTIES:'
				+'\n'+navigator.userAgent
				+'\n'+navigator.appVersion
				+'\n'
				+'\nisDom    = '+this.isDom()
				+'\nisOpera5 = '+this.isOpera5()
				+'\nisOpera6 = '+this.isOpera6()
				+'\nisOpera  = '+this.isOpera()
				+'\nisMSIE6  = '+this.isMSIE6()
				+'\nisMSIE5  = '+this.isMSIE5()
				+'\nisMSIE4  = '+this.isMSIE4()
				+'\nisMSIE   = '+this.isMSIE()
				+'\nisNS6    = '+this.isNS6()
				+'\nisNS4    = '+this.isNS4()
				+'\nisNS     = '+this.isNS()
				+'\nPosUnits = '+this.PosUnits()
				+'\n'
				+'\nPageTitle  = '+this.getPageTitle()
				+'\nPageUri	   = '+this.getPageUri()
				+'\nPageWidth  = '+this.getPageWidth()
				+'\nPageHeight = '+this.getPageHeight()
				;
		}

	// Return browser object
	return this;
}

//______________________________________________________________
// Create DOM object with cross-browser DHTML and CSS/style access methods for given object id.

function bmeDomObject(objectid, nest)
{
	// Get browser
	if (!curBrowser)
	{
		curBrowser = bmeBrowser();
	}

	// Get DOM and style objects
	this.dom = this.style = null;
	if (curBrowser.isDom())
	{
		this.dom	= document.getElementById(objectid);
		this.style	= document.getElementById(objectid).style;
	}
	else if (curBrowser.isMSIE4())
	{
		this.dom	= document.all[objectid];
		this.style	= document.all[objectid].style;
	}
	else if (curBrowser.isNS4())
	{
		if (0)
		{
			// Nested objects support
			nest = nest ? ('document.'+nest+'.') : '';
			this.dom	= eval(nest+'document.'+objectid);
	  		this.style	= eval(nest+'document.'+objectid);
	  	}
  		this.dom	= document.layers[objectid];
  		this.style	= document.layers[objectid];
  	}

	// Visibility property settings
	this.isVisible	= function()	{ return (this.style.visibility == 'visible' || this.style.visibility == 'show') ? 1 : 0; }
	this.Show		= function()	{ this.style.visibility = /*curBrowser.isNS4() ? 'show' :*/ 'visible'; }
	this.Hide		= function()	{ this.style.visibility = /*curBrowser.isNS4() ? 'hide' :*/ 'hidden'; }
	
	this.DispToggle	= function()	{ if (this.style.display == 'none') this.style.display = 'block'; else this.style.display = 'none'; }

	// Width/height property settings
	this.getWidth	= function()
		{
			if (curBrowser.isNS4())
				return parseInt(this.style.document.width);
			if (curBrowser.isOpera())
				return parseInt(this.style.pixelWidth);
			if (this.dom.offsetWidth)
				return parseInt(this.dom.offsetWidth);
			if (this.dom.clip.width)
				return parseInt(this.dom.clip.width);
			return 0;
		}
	// Width/height property settings
	this.setWidth	= function(w)
		{
			if (curBrowser.isNS4())
			{
//				this.style.document.width = w + curBrowser.PosUnits();
			}
			else if (curBrowser.isOpera())
			{
				this.style.pixelWidth = w + curBrowser.PosUnits();
//				this.style.width = w + curBrowser.PosUnits();
			}
			else
			{
				this.style.width = w + curBrowser.PosUnits();
			}
		}

	this.getHeight	= function()
		{
			if (curBrowser.isNS4())
				return parseInt(this.style.document.height);
			if (curBrowser.isOpera())
				return parseInt(this.style.pixelHeight);
			if (this.dom.offsetHeight)
				return parseInt(this.dom.offsetHeight);
			if (this.dom.clip.height)
				return parseInt(this.dom.clip.height);
			return 0;
		}
	// Top/left/right/bottom property settings
	this.getTop		= function()
		{
			if (this.style.top)
				return parseInt(this.style.top);
			if (this.style.pixelTop)
				return parseInt(this.style.pixelTop);
			if (this.dom.offsetTop)
				return parseInt(this.dom.offsetTop);
			return 0;
		}
	this.setTop		= function(t)	{ this.style.top = t + curBrowser.PosUnits(); }
	this.getLeft	= function()
		{
			if (this.style.left)
				return parseInt(this.style.left);
			if (this.style.pixelLeft)
				return parseInt(this.style.pixelLeft);
			if (this.dom.offsetLeft)
				return parseInt(this.dom.offsetLeft);
			return 0;
		}
	this.setLeft	= function(l)	{ this.style.left = l + curBrowser.PosUnits(); }
	this.getRight	= function()	{ return this.getLeft() + this.getWidth(); }
	this.getBottom	= function()	{ return this.getTop() + this.getHeight(); }
	// Visible object area
	this.getClipArray	= function()
		{
			var clip = new Array();
			if (this.style.clip == null)
			{
				clip[0] = clip[1] = clip[2] = clip[3] = 0;
				return clip;
			}
			var s = this.style.clip;
			// Top
			var i = s.indexOf('(');
			clip[0] = parseInt(s.substring(i + 1, s.length), 10);
			// Right
			i = s.indexOf(' ', i + 1);
			clip[1] = parseInt(s.substring(i + 1, s.length), 10);
			// Bottom
			i = s.indexOf(' ', i + 1);
			clip[2] = parseInt(s.substring(i + 1, s.length), 10);
			// Left
			i = s.indexOf(' ', i + 1);
			clip[3] = parseInt(s.substring(i + 1, s.length), 10);
			// Return clip array
			return clip;
		}
	this.getClipTop		= function()
		{
			if (this.style.clip.top)
				return parseInt(this.style.clip.top);
			var clip = this.getClipArray();
			return clip[0];
		}
	this.getClipBottom	= function()
		{
			if (this.style.clip.bottom)
				return parseInt(this.style.clip.bottom);
			var clip = this.getClipArray();
			return clip[2];
		}
	this.getClipLeft	= function()
		{
			if (this.style.clip.left)
				return parseInt(this.style.clip.left);
			var clip = this.getClipArray();
			return clip[3];
		}
	this.getClipRight	= function()
		{
			if (this.style.clip.right)
				return parseInt(this.style.clip.right);
			var clip = this.getClipArray();
			return clip[1];
		}
	this.getClipWidth	= function()
		{
			if (this.style.clip.width)
				return parseInt(this.style.clip.width);
			var clip = this.getClipArray();
			return clip[1] - clip[3];
		}
	this.getClipHeight	= function()
		{
			if (this.style.clip.height)
				return parseInt(this.style.clip.height);
			var clip = this.getClipArray();
			return clip[2] - clip[0];
		}
	this.setClip		= function(t, r, b, l)
		{
			if (this.style.clip.left)
			{
				this.style.clip.top		= t;
				this.style.clip.right	= r;
				this.style.clip.bottom	= b;
				this.style.clip.left	= l;
			}
			this.style.clip = 'rect('+t+' '+r+' '+b+' '+l+')';
		}

	// 3-D positioning
	this.getLayer	= function()	{ return this.style.zIndex != null ? this.style.zIndex : null; }
	this.setLayer	= function(l)	{ this.style.zIndex = l; }

	// Object movement
	this.MoveTo		= function(x,y)	{ this.setLeft(x); this.setTop(y); }
	this.MoveBy		= function(x,y)	{ this.MoveTo(this.getLeft() + x, this.getTop() + y); }

	// Property query
	this.getProps	= function()
		{
			return 'OBJECT PROPERTIES:'
				+'\n'
				+'\nVisible = '+(this.isVisible() ? 'yes' : 'no')
				+'\nLayer   = '+this.getLayer()
				+'\nWidth   = '+this.getWidth()
				+'\nHeight  = '+this.getHeight()
				+'\nTop     = '+this.getTop()
				+'\nLeft    = '+this.getLeft()
				+'\nBottom  = '+this.getBottom()
				+'\nRight   = '+this.getRight()

				+'\nClip        = '+this.style.clip
				+'\nClipWidth   = '+this.getClipWidth()
				+'\nClipHeight  = '+this.getClipHeight()
				+'\nClipTop     = '+this.getClipTop()
				+'\nClipLeft    = '+this.getClipLeft()
				+'\nClipBottom  = '+this.getClipBottom()
				+'\nClipRight   = '+this.getClipRight()
				;
		}

	// Return DOM object
	return this;
}

//______________________________________________________________
// End of JavaScript source