// Universal event handler
// Please don't use "onload = functionObject()" etc
// use instead this "addEvent(window, 'load', functionObject);"
function addEvent(obj, strEvent, objFunction)
{ 
	if (obj.addEventListener) { 
		obj.addEventListener(strEvent, objFunction, true); 
		return true; 
	}
	else if (obj.attachEvent) { 
		var returnValue = obj.attachEvent("on"+strEvent, objFunction); 
		return returnValue; 
	} 
	else return false; 
}

function removeEvent(obj, strEvent, objFunction)
{ 
	if (obj.addEventListener) {
		obj.removeEventListener(strEvent, objFunction, true)
	}
	else if (obj.attachEvent) {
		obj.detachEvent("on"+strEvent, objFunction);
	}
}

/////////////////////////////////////////////////////////////////////
//common geometric functions
// find object coordinates
function getXCoordinate(obj)
{	
	var objOffsetLeft = 0;
	var curElement = obj;
	while (curElement.offsetParent != null)
	{
	  //if (curElement.style.position == "absolute" || curElement.style.position == "relative" || curElement.style.overflow == 'auto') break;
	  objOffsetLeft += curElement.offsetLeft;
	  curElement = curElement.offsetParent;
	}
	return objOffsetLeft;
}
function getYCoordinate(obj)
{	
	var objOffsetTop = 0;
	var curElement = obj;

	while (curElement.offsetParent != null)
	{
	  //if (curElement.style.position == "absolute" || curElement.style.position == "relative" || curElement.style.overflow == 'auto') break;
	  objOffsetTop += curElement.offsetTop;
	  curElement = curElement.offsetParent;
	}
	return objOffsetTop;
}
// scroll positions
function getXScroll()
{
	var lScrX = 0;
	if( typeof( window.pageXOffset ) == 'number' ) lScrX = window.pageXOffset; //Netscape compliant
	else if( document.body && document.body.scrollLeft ) lScrX = document.body.scrollLeft; //DOM compliant
	else if( document.documentElement && document.documentElement.scrollLeft ) lScrX = document.documentElement.scrollLeft; //IE6 standards compliant mode	
	return lScrX;
}
function getYScroll()
{
	var lScrY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) lScrY = window.pageYOffset; //Netscape compliant
	else if( document.body && document.body.scrollTop ) lScrY = document.body.scrollTop; //DOM compliant
	else if( document.documentElement && document.documentElement.scrollTop ) lScrY = document.documentElement.scrollTop; //IE6 standards compliant mode	
	return lScrY;
}

function getDocHeight()
{
    var db = document.body;
    var dde = document.documentElement;
    return Math.max(db.scrollHeight, dde.scrollHeight, db.offsetHeight, dde.offsetHeight, db.clientHeight, dde.clientHeight);
}

function getClientHeight() {
  var retHeight = 0;
  if( typeof( window.innerHeight ) == 'number' ) 
  {
    retHeight = window.innerHeight;
  } 
  else if( document.documentElement && document.documentElement.clientHeight ) 
  {
    retHeight = document.documentElement.clientHeight;
  } 
  else if( document.body && document.body.clientHeight ) 
  {
    retHeight = document.body.clientHeight;
  }
  return retHeight;
}

////////////////////////////////////////////////////////////////////////////////////////
// standard trim function - clean spaces, tabs and new line symbols around the string //
function trim(str)
{
	var lead = 0, trail = str.length - 1;
	while(str.charCodeAt(lead)  < 33) lead++;
	while(str.charCodeAt(trail)  < 33) trail--;
	return lead > trail ? '' : str.substring(lead, trail + 1);
}

function checkTextLen(sString, iMin, iMax)
{
    if(typeof(sString) != 'string') return false;
    return sString.length >= iMin && sString.length <= iMax; 
}	

function clearNode(objNode)
{
	with(objNode) while(hasChildNodes()) removeChild(firstChild);
}


