var mouseX=0;
var mouseY=0;
var productLayerWidth=290;
var productLayerHeight=233;
var currentProductLayerElement=false;
//define reference to the body object in IE
var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;

function ShowLMETPresentationPopUp(yn)
{
  el=document.getElementById('lmetpresentation');
  ellink=document.getElementById('lmetpresentation_ic');
  if (yn)
    {
      CalculateWindowSize();
      left=(ecsWindowWidth-550)/2;
      el.style.left = parseInt(left) + 'px';
      el.style.visibility='visible';
      ellink.style.visibility='hidden';
    }
  else
    {
      el.style.visibility='hidden';
      ellink.style.visibility='visible';
    }
}

function productLayerShowHide(LayerId,ShowHide)
{
  productLayerElement=document.getElementById(LayerId);
  if (currentProductLayerElement
      && currentProductLayerElement!=productLayerElement)
    {
      currentProductLayerElement.style.display='none';
      currentProductLayerElement=false;
    };
  if (ShowHide)
    {
      //alert('A0');
      currentProductLayerElement=productLayerElement;

      currentProductLayerElement.style.display='block';
      if (currentProductLayerElement.clientWidth
          && currentProductLayerElement.clientWidth>0)
        {
          productLayerWidth=currentProductLayerElement.clientWidth;
          productLayerHeight=currentProductLayerElement.clientHeight;
        }
      else
        {
          productLayerWidth=290;
          productLayerHeight=233;
        };

      if (mouseX!=0 && mouseY!=0)
        {
          x=mouseX-(productLayerWidth+10)/2;
          y=mouseY-(productLayerHeight+10)/2;
          //alert('A');
          //alert('Aa'+document.all);
          //alert('iebody'+iebody);
          //alert('pageXOffset'+pageXOffset);
          //define universal dsoc left point                
          //alert('document.body'+document.body);
          //var dsocleft=parseInt(document.all  ? iebody.scrollLeft : pageXOffset);
          var dsocleft=parseInt(document.body  ? document.body.scrollLeft : pageXOffset);
          //alert('A1');
          //define universal dsoc top point
          //var dsoctop=parseInt(document.all  ? iebody.scrollTop : pageYOffset);
          var dsoctop=parseInt(document.body  ? document.body.scrollTop : pageYOffset);
          //alert('A2');
          var ww=0;
          var wh=0;
          if (document.body
              && document.body.clientWidth)
            ww=document.body.clientWidth;
          else
            ww=(document.all ? document.body.clientWidth : (window.innerWidth ? window.innerWidth : 800));
          if (document.body
              && document.body.clientHeight)
            wh=document.body.clientHeight;
          else
            wh=(document.all ? document.body.clientHeight : (window.innerHeight ? window.innerHeight : 600));
          //alert('A3');
          if (x+productLayerWidth-dsocleft>ww-10)
            x=dsocleft+(ww-10)-productLayerWidth;
          if (x<dsocleft)
            x=dsocleft;
          if (y+productLayerHeight-dsoctop>wh-10)
            y=dsoctop+(wh-10)-productLayerHeight;
          if (y<dsoctop)
            y=dsoctop;
          currentProductLayerElement.style.left = x+"px";
          currentProductLayerElement.style.top = y+"px";
        };
    }
  else
    {
      currentProductLayerElement.style.display='none';
      currentProductLayerElement=false;
    }
}

function checkwhere(e)
{
  if (window.event)
    {
      mouseX = window.event.clientX + document.documentElement.scrollLeft+ document.body.scrollLeft;
      mouseY = window.event.clientY + document.documentElement.scrollTop+document.body.scrollTop;
    }
  else
    {
      mouseX = e.clientX + window.scrollX;
      mouseY = e.clientY + window.scrollY;
    }
  //document.title=""+mouseX+" , "+mouseY+" / "+productLayerElement.style.left+" , "+productLayerElement.style.top;
  if (currentProductLayerElement
      && currentProductLayerElement.style.display!='none')
    {
      lx=parseInt(currentProductLayerElement.style.left);
      ly=parseInt(currentProductLayerElement.style.top);
      lx2=lx+productLayerWidth;
      ly2=ly+productLayerHeight;
      //document.title=""+mouseX+" , "+mouseY+" / "+lx+" , "+ly+" / "+lx2+" , "+ly2+" = "+productLayerElement.clientHeight;
      if (mouseX<lx-10 || mouseY<ly-10 || mouseX>lx2+10 || mouseY>ly2+10)
        {
          productLayerShowHide(currentProductLayerElement.id,0);
        }
    };
};


function InitCaptureMouse()
{
  document.onmousemove = checkwhere;
  if(document.captureEvents)
    {
      document.captureEvents(Event.MOUSEMOVE);
    }
}

function InitJavascriptLMET()
{  
  InitCaptureMouse();
}

