function getElem(elementId)
{
	if(document.getElementById && document.getElementById(elementId))
		return document.getElementById(elementId);
  else if (document.all && document.all(elementId))
		return document.all(elementId);
  else if (document.layers && document.layers[elementId])
		return document.layers[elementId];
  else
		return false;
}
function Element(elemObjOrId)
{
	
	if (typeof(elemObjOrId) == 'string')
		this.elem = getElem(elemObjOrId);
	else if (typeof(elemObjOrId) == 'object')
		this.elem = elemObjOrId;

	
	if (typeof(_element_prototype_called) == 'undefined')
  {
     _element_prototype_called = true;
     Element.prototype.getElement = getElement;
     Element.prototype.getStyle = getStyle;
     Element.prototype.setStyleAttribute = setStyleAttribute;
     Element.prototype.setStyleAttributes = setStyleAttributes;
     Element.prototype.getStyleAttribute = getStyleAttribute;
     Element.prototype.hide = hide;
     Element.prototype.show = show;
     Element.prototype.disable = disable;
     Element.prototype.enable = enable;
     Element.prototype.toggleEnabled = toggleEnabled;
     Element.prototype.getPosition = getPosition;
     Element.prototype.setPosition = setPosition;
     Element.prototype.move = move;
     Element.prototype.getHeight = getHeight;
     Element.prototype.getWidth = getWidth;
     Element.prototype.setHeight = setHeight;
     Element.prototype.setWidth = setWidth;
     Element.prototype.setSize = setSize;
     Element.prototype.setValue = setValue;
     Element.prototype.getValue = getValue;
     Element.prototype.getId = getId;
     Element.prototype.setAttribute = setAttribute;
     Element.prototype.getAttribute = getAttribute;
     Element.prototype.setClassname = setClassname;
     Element.prototype.parentElement = parentElement;
     Element.prototype.nextSibling = nextSibling;
     Element.prototype.previousSibling = previousSibling;
     Element.prototype.swapWithElement = swapWithElement;
  }
	
	function getElement()
	{
		return this.elem;
	}
	
	function setClassname(name)
	{
		var elem = this.getElement();
		elem.className = name;
	} 
	
	function setAttribute(attribute, val)
	{
		var elem = this.getElement();
		elem.setAttribute(attribute, val);
	} 
	
	function getAttribute(attribute)
	{
		var elem = this.getElement();
		return elem.getAttribute(attribute);
	} 
	
	function getId()
	{
		return this.elementId;
	}

	function setValue(value)
	{
		var elem = this.getElement();
		
		if (elem.value != undefined)
			elem.value = value;
		else if (document.layers)
		{
			var lyr = document.layers[this.elementId].document;
			lyr.open();
			lyr.write(value);
			lyr.close();
		}
		else
			elem.innerHTML = value;
	} 

	function getValue()
	{
		var elem = this.getElement();
		
		if (elem.value != undefined)
			return elem.value;
		else if (document.layers)
			return false;
		else
			return elem.innerHTML;
	} 

	function getStyle()
	{
		elem = this.getElement();
		return elem.style;
		
	} 
	
	function setStyleAttribute(attribute, val)
	{
		var elemStyle = this.getStyle();
		elemStyle[attribute] = val;
	} 
	
	function setStyleAttributes(attributes)
	{
		var elemStyle = this.getStyle();
		for (attribute in attributes)
			elemStyle[attribute] = attributes[attribute];
	} 
	
	function getStyleAttribute(attribute)
	{
		var elemStyle = this.getStyle();
		return elemStyle[attribute];
	} 
	
	function hide()
	{
		this.setStyleAttribute('visibility', 'hidden');
	} 

	function show()
	{
		this.setStyleAttribute('visibility', 'visible');
	} 
	
	function disable()
	{
		elem = this.getElement();
		elem.disabled = true;
	} 
	
	function enable()
	{
		elem = this.getElement();
		elem.disabled = false;
	} 
	
	function toggleEnabled()
	{
		elem = this.getElement();
		elem.disabled = !elem.disabled;
	} 
	
	function getPosition()
	{
				
		var elem = this.getElement();
		
		var left = 0;
		var top  = 0;

		while (elem.offsetParent)
		{
			left += elem.offsetLeft;
			top += elem.offsetTop;
			elem = elem.offsetParent;
		}
	
		left += elem.offsetLeft;
		top += elem.offsetTop;
	
		return {x:left, y:top};
	} 
	
	function setPosition(x, y)
	{
		var elemStyle = this.getStyle();
		
	  if (document.layers)
	  {
	    elemStyle.left = x;
	    elemStyle.top = y;
	  }
	  else 
	  {
	    elemStyle.left = x + 'px';
	    elemStyle.top = y + 'px';  
	  }
	} 
	
	function move(dx, dy)
	{
		var pos = this.getPosition();
		this.setPosition(pos.x + dx, pos.y + dy);
	} 
	
	function getHeight()
	{
		return parseInt(this.getStyleAttribute('height'));
	} 
	
	function getWidth()
	{
		return parseInt(this.getStyleAttribute('width'));
	} 
	
	function setHeight(height)
	{
		this.setStyleAttribute('height', height);
	} 
	
	function setWidth(width)
	{
		this.setStyleAttribute('width', width);
	} 
	
	function setSize(width, height)
	{
		this.setHeight(height);
		this.setWidth(width);
	} 
	
	function parentElement()
	{
		elem = (this.getElement()).parentNode;
		if (elem != null)
			elem = new Element(elem);
		
		return elem;
	} 
	
     
  function nextSibling()
	{
		elem = (this.getElement()).nextSibling;
		if (elem != null)
			elem = new Element(elem);
		
		return elem;
	} 
	
	function previousSibling()
	{
		elem = (this.getElement()).previousSibling;
		if (elem != null)
			elem = new Element(elem);
		
		return elem;
	} 
	
	function swapWithElement(swapElem)
	{
		var swapElemParentElem = swapElem.parentElement();
		var replacedNode = this.parentElement().getElement().replaceChild(swapElem.getElement(), this.getElement());
		swapElemParentElem.getElement().appendChild(this.getElement());
		
 
	} 
	
} 