function getElementInfo(elem)
 {
	var offsetTrail = elem;
	var offsetLeft = 0;
	var offsetTop = 0;
	var offsetWidth=offsetTrail.offsetWidth;
	var offsetHeight=offsetTrail.offsetHeight;
	while (offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}
	if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != "undefined") {
		offsetLeft += document.body.leftMargin;
		offsetTop += document.body.topMargin;
	}
	return {left:offsetLeft, top:offsetTop, width:offsetWidth, height:offsetHeight};
}



//функция позиционирует элемент по центру.
function positionCenter(elem)
{
	var bodyEl=document.getElementsByTagName('body')[0];
	var elemInfo=getElementInfo(elem);
	var wWin=getlnsideWindowWidth();
	var hWin=getlnsideWindowHeight();
	elem.style.top=(hWin/2-elemInfo.height/2)+bodyEl.scrollTop;
	elem.style.left=(wWin/2-elemInfo.width/2)+bodyEl.scrollLeft;
}



//функция возврощает высоту документа
function getlnsideWindowHeight()
{
	if (window.innerHeight)
	{
		return window.innerHeight;
	}
	else if (document.body.parentElement.clientHeight)
	{
    return document.body.parentElement.clientHeight;
	}
	else if (document.body && document.body.clientHeight)
	{
		return document.body.clientHeight;
	}
	return 0;
}

//функция возврощает ширену документа
function getlnsideWindowWidth()
{
	if (window.innerWidth)
	{
		return window.innerWidth;
	}
	else if (document.body.parentElement.clientWidth)
	{
		return document.body.parentElement.clientWidth;
	}
	else if (document.body && document.body.clientWidth)
	{
		return document.body.clientWidth;
	}
	return 0;
}


function pause(ms)
{
	var date = new Date();
	curDate = null;
	do
    {
		var curDate = new Date();
	}
	while(curDate - date < ms);
}


function getOpacity(element,alfa)
{
    try
	{
		element.style.filter="alpha(opacity="+alfa+")";
		alfa=alfa/100;
		element.style.opacity=alfa;
		element.style.mozOpacity=alfa;
	}
	catch(e)
	{
	}
}


 function finClassName(element,clasname)
 {
    e=element;
	try
	{
		while(e.className!=clasname)
		{
			e=e.parentNode;
		}
		return e;
	}
	catch(error)
	{
	  return false;
	}
 }
 
 
 function getObject(obj) {
   var theObj;
   if (document.layers) {
      if (typeof obj == "string") {
         return document.layers[obj];
      } else {
         return obj;
      }
   }
   if (document.all) {
      if (typeof obj == "string") {
         return document.all(obj);
      } else {
         return obj;
      }
   }
   if (document.getElementById) {
      if (typeof obj == "string") {
         return document.getElementById(obj);
      } else {
         return obj;
      }
   }
   return null
}


function GUI_addEvent(el, evname, func) {
	if (el.addEventListener) {
		el.addEventListener(evname, func, true);
	} else {
	    el.attachEvent("on" + evname, func);		
	}
}


function setIDU(thisel)
{
	if(thisel.id!=null)
	{
		var preg=/(\d)+$/gi	
		var idu=thisel.id.match(preg);
		return idu;
	}
	else
	{
		return null;
	}	
	
}


agt = navigator.userAgent.toLowerCase();
is_ie	   = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
is_opera  = (agt.indexOf("opera") != -1);
is_mac	   = (agt.indexOf("mac") != -1);
is_mac_ie = (is_ie && is_mac);
is_win_ie = (is_ie && !is_mac);
is_gecko  = (navigator.product == "Gecko");


function trim(str){
  var reg=/^\s+/g
  str=str.replace(reg,"");
  reg=/\s+$/g
  str=str.replace(reg,"");
  return str;
  
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
