function DOM()
{
/*----------------------------------------------------------------------
//	Purpose:
//----------------------------------------------------------------------
//	Cross browser API to allow programmatic access to HTML elements and
//	CSS attributes via Javascript.
//
//----------------------------------------------------------------------
//	Use:
//----------------------------------------------------------------------
//	Instantiate one instance of the DOM class per page. Items may then
//	be added, and methods called to alter or manipulate the items in
//	any browser. Every effort has been made for graceful degradation in
//	unsupported browsers.
//
//----------------------------------------------------------------------
//	Public Methods:
//----------------------------------------------------------------------
//	addItemById(strID):	adds an object reference to the internal items
//		collection. Takes the id of the object as an argument. This id
//		must reference an actual object.
//	setColor(strID, strColor): sets the foreground colour of an object.
//		Takes the id of the object or object reference v and either a
//		string value representing the CSS colour name or a six digit
//		hex value representing the colour value as arguments.
//	setBGColor(strID, strColor): sets the background colour of an object.
//		Takes the id of the object or object reference v and either a
//		string value representing the CSS colour name or a six digit
//		hex value representing the colour value as arguments.
//	getX(v): gets the horizontal distance of the top left point of
//		an object from the left side of the screen. Takes the id of
//		the object or an object reference as an argument.
//	getY(v): gets the vertical distance of the top left point of
//		an object from the top of the screen. Takes the id of the
//		object or an object reference as an argument.
//	getWidth: gets the width of an object. Takes the id of the object
//		or object reference v as an argument.
//	getHeight: gets the height of an object. Takes the id of the object
//		or object reference v as an argument.
//	setWidth: sets the width of an object. Takes the id of the object
//		or object reference v and width i as arguments.
//	setHeight: sets the height of an object. Takes the id of the object
//		or object reference v and height i as arguments.
//	moveX(v, i): moves an object a given distance in pixels along the
//		horizontal. Takes the id of an object or an object reference as
//		an argument v, and the distance in pixels as an argument i.
//	moveY(v, i): moves an object a given distance in pixels along the
//		vertical. Takes the id of an object or an object reference as
//		an argument v, and the distance in pixels as an argument i.
//	putX(v, i): puts an object at a horizontal co-ordinate in pixels
//		from the top left corner of the screen. Takes the id of an
//		object or an object reference as an argument v, and the
//		distance in pixels as an argument i.
//	putY(v, i): puts an object at a vertical co-ordinate in pixels
//		from the top left corner of the screen. Takes the id of an
//		object or an object reference as an argument v, and the
//		distance in pixels as an argument i.
//	setPadding(v, i): sets the padding of an object. v is the id string
//		or an object reference, and i is an integer value for the
//		padding in pixels. There are an optional extra three arguments
//		if padding is required on specific sides. If these are used,
//		they must all be specified in the order (from the second
//		argument) Top, Right, Bottom - clockwise in other words. Any
//		that are not required to be set in this case must be specified
//		as null. Can also take an optional third argument to specify
//		the side to apply the margin to. This must be either Top,
//		Right, Bottom or Left - note capitalisation.
//	setMargins(v, i): sets the margins of an object. v is the id string
//		or an object reference, and i is an integer value for the
//		margin in pixels. There are an optional extra three arguments
//		if margins are required on specific sides. If these are used,
//		they must all be specified in the order (from the second
//		argument) Top, Right, Bottom - clockwise in other words. Any
//		that are not required to be set in this case must be specified
//		as null. Can also take an optional third argument to specify
//		the side to apply the margin to. This must be either Top,
//		Right, Bottom or Left - note capitalisation.
//	setBorders(v, iSize, strType, strColor): sets the borders of an
//		object. Also reduces the padding (if there is any) by the same
//		amount to maintain the same total area being used by the
//		object. Takes object, size, type and colour as arguments -
//		these being id string or object reference, integer, string and
//		string typed respectively.
//	remBorders(v): removes the borders of an object, and increases the
//		padding accordingly to maintain a constant area. Takes id
//		string or object reference as an argument.
//	show(v): sets CSS visibility attribute to make object visible.
//		Takes id string or object reference as an argument.
//	hide(v): sets CSS visibility attribute to make object hidden.
//		Takes id string or object reference as an argument.
//	toggleVisibility(v): sets CSS visibility attribute to opposite of
//		what it is at the moment. Takes id string or object reference
//		as an argument.
//----------------------------------------------------------------------
//	Member function and variable declarations
----------------------------------------------------------------------*/
	this.Items = new Array();
	this.rgstrSides = new Array('Top', 'Right', 'Bottom', 'Left');
	this.addItemById = addItemById;
	this.setColor = setColor;
	this.setBGColor = setBGColor;
	this.styleObj = styleObj;
	this.getX = getX;
	this.getY = getY;
	this.getWidth = getWidth;
	this.getHeight = getHeight;
	this.setWidth = setWidth;
	this.setHeight = setHeight;
	this.moveX = moveX;
	this.moveY = moveY;
	this.putX = putX;
	this.putY = putY;
	this.setPadding = setPadding;
	this.setMargins = setMargins;
	this.setBorders = setBorders;
	this.remBorders = remBorders;
	this.show = show;
	this.hide = hide;
	this.toggleVisibility = toggleVisibility;
/*----------------------------------------------------------------------
//	Publicly accessible member functions
----------------------------------------------------------------------*/
	function addItemById(strID)
	{
		if(typeof(strID) != 'string') return false;
		var m_siItemsLength = this.Items.length;
		if(document.layers)
		{
			var m_oItem = document.layers[strID];
			if(m_oItem == undefined) return false;
			this.Items[m_siItemsLength] = m_oItem;
			this.Items[strID] = m_oItem;
		}
		else if(document.all)
		{
			var m_oItem = document.all[strID];
			if(m_oItem == undefined) return false;
			this.Items[m_siItemsLength] = m_oItem;
			this.Items[strID] = m_oItem;
		}
		else if(document.getElementById)
		{
			var m_oItem = document.getElementById(strID);
			if(m_oItem == undefined) return false;
			this.Items[m_siItemsLength] = m_oItem;
			this.Items[strID] = m_oItem;
		}
		else
		{
			return false;
		}
		return true;
	}
/*--------------------------------------------------------------------*/
	function setColor(v, strColor)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		v = styleObj(v);
		v.color = makeColor(strColor);
		return true;
	}
/*--------------------------------------------------------------------*/
	function setBGColor(v, strColor)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		v = styleObj(v);
		v.backgroundColor = makeColor(strColor);
		return true;
	}
/*--------------------------------------------------------------------*/
	function getX(v)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) == 'object') return setPositionAtt(v).offsetLeft;
		return undefined;
	}
/*--------------------------------------------------------------------*/
	function getY(v)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) == 'object') return setPositionAtt(v).offsetTop;
		return undefined;
	}
/*--------------------------------------------------------------------*/
	function getWidth(v)
	{
		if(typeof(v) == 'string') return setPositionAtt(this.Items[v]).offsetWidth;
		if(typeof(v) == 'object') return setPositionAtt(v).offsetWidth;
	}
/*--------------------------------------------------------------------*/
	function getHeight(v)
	{
		if(typeof(v) == 'string') return setPositionAtt(this.Items[v]).offsetHeight;
		if(typeof(v) == 'object') return setPositionAtt(v).offsetHeight;
	}
/*--------------------------------------------------------------------*/
	function setWidth(v, i)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		styleObj(v).width = i;
		return true;
	}
/*--------------------------------------------------------------------*/
	function setHeight(v, i)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		styleObj(v).height = i;
		return true;
	}
/*--------------------------------------------------------------------*/
	function moveX(v, i)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		if(styleObj(v).position = 'absolute')
		{
			var iCoord = parseInt(getX(v)) + i;
		}
		else
		{
			var iCoord = styleObj(v).left;
			if(iCoord == '')
			{
				iCoord = 0;
			}
			else
			{
				iCoord = parseInt(iCoord);
			}
			iCoord = parseInt(iCoord) + i;
		}
		moveTo(v, iCoord, 'x');
		return true;
	}
/*--------------------------------------------------------------------*/
	function moveY(v, i)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		if(styleObj(v).position = 'absolute')
		{
			var iCoord = parseInt(getY(v)) + i;
		}
		else
		{
			var iCoord = styleObj(v).top;
			if(iCoord == '')
			{
				iCoord = 0;
			}
			else
			{
				iCoord = parseInt(iCoord);
			}
			iCoord = parseInt(iCoord) + i;
		}
		moveTo(v, iCoord, 'y');
		return true;
	}
/*--------------------------------------------------------------------*/
	function putX(v, i)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		moveTo(v, i, 'x');
		return true;
	}
/*--------------------------------------------------------------------*/
	function putY(v, i)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		moveTo(v, i, 'y');
		return true;
	}
/*--------------------------------------------------------------------*/
	function setPadding(v, i)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		if(typeof(parseInt(i)) != 'number') return false;
		var iArgs = arguments.length;
		if(iArgs != 2 && iArgs != 5 && iArgs != 3) return false;
		if(iArgs == 2) styleObj(v).padding = i;
		if(iArgs == 3)
		{
			var bIsOK = false;
			for(var iCount = 0; iCount < this.rgstrSides.length; iCount++) if(this.rgstrSides[iCount] == arguments[2]) bIsOK = true;
			if(bIsOK == false) return false;
			eval('styleObj(v).padding' + arguments[2] + ' = ' + parseInt(i));
			return true;
		}
		if(iArgs == 5) for(var iCount = 1; iCount < iArgs; iCount++) if(typeof(arguments[iCount]) == 'number') eval('styleObj(v).padding' + this.rgstrSides[iCount - 1] + ' = ' + parseInt(arguments[iCount]));
		return true;
	}
/*--------------------------------------------------------------------*/
	function setMargins(v, i)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		if(typeof(parseInt(i)) != 'number') return false;
		var iArgs = arguments.length;
		if(iArgs != 2 && iArgs != 5 && iArgs != 3) return false;
		if(iArgs == 2) styleObj(v).margin = i;
		if(iArgs == 3)
		{
			var bIsOK = false;
			for(var iCount = 0; iCount < this.rgstrSides.length; iCount++) if(this.rgstrSides[iCount] == arguments[2]) bIsOK = true;
			if(bIsOK == false) return false;
			eval('styleObj(v).margin' + arguments[2] + ' = ' + parseInt(i));
			return true;
		}
		if(iArgs == 5) for(var iCount = 1; iCount < iArgs; iCount++) if(typeof(arguments[iCount]) == 'number') eval('styleObj(v).margin' + this.rgstrSides[iCount - 1] + ' = ' + parseInt(arguments[iCount]));
		return true;
	}
/*--------------------------------------------------------------------*/
	function setBorders(v, iSize, strType, strColor)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		var iArgs = arguments.length;
		if(iArgs == 4)
		{
			if(typeof(iSize) != 'number' || typeof(strType) != 'string' || typeof(strColor) != 'string') return false;
			var o = styleObj(v)
			var iPad = parseInt(o.padding);
			if(iPad - iSize >= 0) o.padding = iPad - iSize;
			o.border = '' + iSize + 'px ' + strType + ' ' + strColor;
			return true;
		}
		return false;
	}
/*--------------------------------------------------------------------*/
	function remBorders(v)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		var o = styleObj(v)
		var iBW = (o.borderWidth == '') ? 0 : parseInt(o.borderWidth);
		var iPad = (o.padding == '') ? 0 : parseInt(o.padding);
		iPad = iPad + iBW;
		o.padding = iPad;
		o.border = '0px';
		return true;
	}
/*--------------------------------------------------------------------*/
	function show(v)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		styleObj(v).visibility = 'visible';
		return true;
	}
/*--------------------------------------------------------------------*/
	function hide(v)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		styleObj(v).visibility = 'hidden';
		return true;
	}
/*--------------------------------------------------------------------*/
	function toggleVisibility(v)
	{
		if(typeof(v) == 'string') v = this.Items[v];
		if(typeof(v) != 'object') return false;
		styleObj(v).visibility = (styleObj(v).visibility == 'hidden') ? 'visible' : 'hidden';
		return true;
	}
/*----------------------------------------------------------------------
//	Privately accessible member functions
----------------------------------------------------------------------*/
	function setPositionAtt(o)
	{
		if(styleObj(o).position != 'absolute') styleObj(o).position = 'relative';
		return o;
	}
/*--------------------------------------------------------------------*/
	function styleObj(o)
	{
		if(document.layers) return o;
		if(document.all || document.getElementById) return o.style;
		return undefined;
	}
/*--------------------------------------------------------------------*/
	function isIn(strStr, strPattern)
	{
		var oRE = new RegExp(strPattern, 'gim');
		return oRE.test(strStr);
	}
/*--------------------------------------------------------------------*/
	function moveTo(o, i, xy)
	{
		o = setPositionAtt(o);
		o = styleObj(o);
		if(xy == 'x' || xy == 'X')
		{
			o.left = i;
		}
		else
		{
			o.top = i;
		}
	}
/*--------------------------------------------------------------------*/
	function makeColor(strColor)
	{
		if(isIn(strColor, '^[a-zA-Z]+$') || isIn(strColor, '^#[0-9A-Fa-f]{6}$')) return strColor;
		if(isIn(strColor, '^[0-9A-Fa-f]{6}$')) return '#' + strColor;
		return '#000000';
	}

}
/*----------------------------------------------------------------------
//	End of Class
----------------------------------------------------------------------*/
