function ECMS_getElementPosition(elemId)
{
    var elem = document.getElementById(elemId);
	
    var w = elem.offsetWidth;
    var h = elem.offsetHeight;
	
    var l = 0;
    var t = 0;
	
    while (elem)
    {
        l += elem.offsetLeft;
        t += elem.offsetTop;
        elem = elem.offsetParent;
    }

    return {"left":l, "top":t, "width": w, "height":h};
}

function ECMS_ViewPosition()
    {
    var xScroll, yScroll;
    var windowWidth, windowHeight;
    if (self.pageYOffset) 
        {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
        } 
    else if (document.documentElement && document.documentElement.scrollTop) 
        {
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
        } 
    else if (document.body) 
        {
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft;    
        }
    if (self.innerHeight)     // all except Explorer
        {
        if(document.documentElement.clientWidth)
            {
            windowWidth = document.documentElement.clientWidth; 
            } 
        else 
            {
            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;
        }    
    return {"windowWidth":windowWidth, "windowHeight":windowHeight, "xScroll": xScroll, "yScroll":yScroll};
    }


function show_image_preview(id, url, pw_width, pw_height) {
	var el=	document.getElementById(id);
	var clView=ECMS_ViewPosition();

	if (typeof(left) == "undefined") left='100px';
	if (typeof(top) == "undefined") top='100px';
	el.innerHTML='<div  class="image_1" ><a href="#" title="Щелкните по изображению чтобы закрыть его" onclick="hide_image_preview(\''+id+'\'); return false;"><img style="display: block;" src="'+url+'" alt="" width="'+pw_width+'"  height="'+pw_height+'" />Закрыть окно</a></div>';
	el.style.top=(clView.yScroll+(clView.windowHeight-pw_height)/2)+'px';
	el.style.left=(clView.xScroll+(clView.windowWidth-pw_width)/2)+'px';
	el.style.display='block';
	}
	
function hide_image_preview(id){
	document.getElementById(id).style.display='none';
	}

function exc_mousePageXY(e)
{
  var x = 0, y = 0;

  if (!e) e = window.event;

  if (e.pageX || e.pageY)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else if (e.clientX || e.clientY)
  {
    x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
    y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
  }

  return {"x":x, "y":y};
}

 function exc_checkEmail(str){
  if(!str.match(/^[\w]{1}[\w\.\-_]*@[\w]{1}[\w\-_\.]*\.[\w]{2,4}$/i)){ 
       return false;
  } else {
   return true;
  } 
 }
