/*
* Victor A.Spirin, victor_as@mail.ru
* 2003.03.01 - 2004.01.31
*/



checkUA();

function checkUA()
	{
	var UAs = {MSIE: 'MSIE ', Gecko: 'rv:'};
	var ua = navigator.userAgent;
		for( var n in UAs )
		{
		var is = ua.indexOf(n) != -1;
			if( is ) document['version' + n] = parseFloat(ua.substring(ua.indexOf(UAs[n]) + UAs[n].length));
		document['is' + n] = is;
		}
	}



/*========= DOM Event Methods: =========*/

	if( document.isMSIE )
	{
	patchDOM = function ( e )
		{
		e.addEventListener = function ( evt, listener, useCapture )
			{
			e.attachEvent('on' + evt, listener);
			}
		
		e.removeEventListener = function ( evt, listener, useCapture )
			{
			e.detachEvent('on' + evt, listener);
			}
		
		return e;
		}
	}
	else
	{
	patchDOM = function ( e )
		{
		return e;
		}
	}



/*========= DOM CSS Methods: =========*/

	if( typeof(getComputedStyle) != 'function' )
	{
	getComputedStyle = document.isMSIE ?
	function ( e, pseudo )
		{
		return e.currentStyle;
		}
	:
	function ( e, pseudo )
		{
		return e.style;
		}
	}



	if( document.getOverrideStyle == null )
	{
	document.getOverrideStyle = document.isMSIE ?
	function ( e, pseudo )
		{
		return e.runtimeStyle;
		}
	:
	function ( e, pseudo )
		{
		return e.style;
		}
	}



/*======== Geometric Methods: ========*/

document.getElementPosition = document.isMSIE && document.versionMSIE == 5.5 ?
	function ( e )
		{
		var x = 0;
		var y = 0;
		var n = e;
			while( n != null )
			{
			x += n.offsetLeft;
			y += n.offsetTop;
			var p = n.parentElement;
				while( p != n.offsetParent )
				{
					if( p.tagName == 'TR' ) y -= p.offsetTop;
				p = p.parentElement;
				}
			n = n.offsetParent;
			}
		return {x: x, y: y};
		}
	:
	function ( e )
		{
		var x = 0;
		var y = 0;
		var n = e;
			while( n != null )
			{
			x += n.offsetLeft;
			y += n.offsetTop;
			n = n.offsetParent;
			}
		return {x: x, y: y};
		}

document.setElementPosition = function ( e, pointX, pointY )
	{
	var x = 0;
	var y = 0;
	var n = e.offsetParent;
		while( n != null )
		{
		x += n.offsetLeft;
		y += n.offsetTop;
		n = n.offsetParent;
		}
	var s = document.getOverrideStyle(e); 
        if ( s == null ) s = e.style;
	s.left = (pointX - x)+'px';
	s.top = (pointY - y)+'px'; 
	}

document.getElementSize = function ( e )
	{
//	return {width: e.scrollWidth, height: e.scrollHeight};
	return {width: e.offsetWidth, height: e.offsetHeight};
	}

document.setElementSize = function ( e, width, height )
	{
	var w = width < 1 ? 1 : width;
	var h = height < 1 ? 1 : height;
	var s = document.getOverrideStyle(e);
	s.width = w;
	s.height = h;
	s.clip = 'rect(0px ' + w + 'px ' + h + 'px 0px)';
	}

