﻿//Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ExecuteRequest);
var ELPEndReq = null;

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent)
        while (1) {
        curleft += obj.offsetLeft;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

function findPosY(obj)  
{  
  var curtop = 0;  
  if(obj.offsetParent)  
      while(1)  
      {  
        curtop += obj.offsetTop;  
        if(!obj.offsetParent)  
          break;  
        obj = obj.offsetParent;  
      }  
  else if(obj.y)  
      curtop += obj.y;  
  return curtop;
}

function ActivateMenu(nav) {

/* currentStyle restricts the Javascript to IE only */
	if (document.all &&
 document.getElementById(nav).currentStyle) {  
        var navroot = document.getElementById(nav);
        
        /* Get all the list items within the menu */

        var lis=navroot.getElementsByTagName("LI");  
        for (i=0; i<lis.length; i++) {
        
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){
            
                /* assign the function to the LI */
             	lis[i].onmouseover=function() {	
                
                   /* display the inner menu */
                   this.lastChild.style.display="block";
                }
                lis[i].onmouseout=function() {   
                   this.lastChild.style.display="none";
                }
            }
        }
    }
}

function DisplayPanel(pid, obj)
{
    ShowGrayOut();
    var wh = -1;
    if (window.innerHeight)
        wh = window.innerHeight;
    else
        wh = document.documentElement.clientHeight;
    
    
    document.getElementById(pid).style.display = "block";
    document.getElementById(pid).style.left = findPosX(obj) + 10 + "px";
    
    //if(findPosY(obj) + document.getElementById(pid).offsetHeight < wh)
        document.getElementById(pid).style.top = findPosY(obj) + 10 + "px";
    //else
    //    document.getElementById(pid).style.top = wh - document.getElementById(pid).offsetHeight + "px";

    document.getElementById(pid).style.zIndex = "3";
}

function DisplayPanelOF(pid, obj, ofX, ofY)
{
    ShowGrayOut();
    var wh = -1;
    if (window.innerHeight)
        wh = window.innerHeight;
    else
        wh = document.documentElement.clientHeight;
    
    
    document.getElementById(pid).style.display = "block";
    document.getElementById(pid).style.left = findPosX(obj) + ofX + "px";
    
    //if(findPosY(obj) + document.getElementById(pid).offsetHeight < wh)
        document.getElementById(pid).style.top = findPosY(obj) + ofY + "px";
    //else
    //    document.getElementById(pid).style.top = wh - document.getElementById(pid).offsetHeight + "px";

    document.getElementById(pid).style.zIndex = "3";
}

function DisplayPanelR(pid, obj)
{
    ShowGrayOut();
    var wh = -1;
    if (window.innerHeight)
        wh = window.innerHeight;
    else
        wh = document.documentElement.clientHeight;


    document.getElementById(pid).style.display = "block";
    document.getElementById(pid).style.left = findPosX(obj) - 300 + "px";

    if (findPosY(obj) + document.getElementById(pid).offsetHeight < wh)
        document.getElementById(pid).style.top = findPosY(obj) + 10 + "px";
    else
        document.getElementById(pid).style.top = wh - document.getElementById(pid).offsetHeight + "px";

    document.getElementById(pid).style.zIndex = "3";
}

function DisplayPanelNGO(pid, obj)
{
    var wh = -1;
    if (window.innerHeight)
        wh = window.innerHeight;
    else
        wh = document.documentElement.clientHeight;


    document.getElementById(pid).style.display = "block";
    document.getElementById(pid).style.left = findPosX(obj) + 10 + "px";

    if (findPosY(obj) + document.getElementById(pid).offsetHeight < wh)
        document.getElementById(pid).style.top = findPosY(obj) + 10 + "px";
    else
        document.getElementById(pid).style.top = wh - document.getElementById(pid).offsetHeight + "px";

    document.getElementById(pid).style.zIndex = "3";
}

function DisplayPanelB(pid, obj)
{
    ShowGrayOut();
    document.getElementById(pid).style.display = "block";
    document.getElementById(pid).style.left = findPosX(obj) + 10 + "px";
    
    if(findPosY(obj) - document.getElementById(pid).offsetHeight > 50)
        document.getElementById(pid).style.top = findPosY(obj) + 10 - document.getElementById(pid).offsetHeight + "px";
    else
        document.getElementById(pid).style.top = 10 + "px";

    document.getElementById(pid).style.zIndex = "3";
}

function DisplayPanelF(pid)
{
    ShowGrayOut();
    document.getElementById(pid).style.display = "block";

    document.getElementById(pid).style.right = "0px";
    document.getElementById(pid).style.top = "10px";
    
    document.getElementById(pid).style.zIndex = "3";
}

function DisplayPanelC(pid, xloc, yloc)
{
    ShowGrayOut();
    document.getElementById(pid).style.display = "block";

    document.getElementById(pid).style.left = xloc + "px";
    document.getElementById(pid).style.top = yloc + "px";

    document.getElementById(pid).style.zIndex = "3";
}

function DisplayPanelMP(pid, e)
{
	document.getElementById(pid).style.display = "block";
	if(navigator.appName.indexOf("soft") != -1)
	{
		document.getElementById(pid).style.left = Number(e.clientX + document.documentElement.scrollLeft + 10) + "px";
		document.getElementById(pid).style.top = Number(e.clientY + document.documentElement.scrollTop + 10) + "px";
	}
	else
	{
		document.getElementById(pid).style.left = e.pageX + 10 + "px";
		document.getElementById(pid).style.top = e.pageY + 10 + "px";
	}
}

function ShowPanelBN(pid)
{
	var el = document.getElementsByName(pid);
	var i = 0;
	while(i < el.length)
	{
		el.item(i).style.display = "block";
		i++;
	}
}

function ClosePanelBN(pid)
{
    var el = document.getElementsByName(pid);
	var i = 0;
	while(i < el.length)
	{
		el.item(i).style.display = "none";
		i++;
	}
}

function ShowPanel(pid)
{
	document.getElementById(pid).style.display = "block";
}

function ClosePanel(pid)
{
    document.getElementById(pid).style.display = "none";
    if(document.getElementById("GrayOut"))
        document.getElementById("GrayOut").style.display = "none";
}

function ShowGrayOut()
{
    if (!document.getElementById("GrayOut"))
        return;
        
    document.getElementById("GrayOut").style.display = "block";
    if (window.innerWidth)
    {
        document.getElementById("GrayOut").style.width = window.innerWidth + "px";
        document.getElementById("GrayOut").style.height = window.innerHeight + "px";
    }
    else
    {
        document.getElementById("GrayOut").style.width = document.documentElement.clientWidth;
        document.getElementById("GrayOut").style.height = document.documentElement.clientHeight;
    }
    
}

function FillPanel(pid, html)
{
    document.getElementById(pid).innerHTML = html;
}

function OpenWindowAnchor(Address)
{
	window.open(Address);
}

function SetRequest(request)
{
    ELPEndReq = request;
}

function ExecuteRequest(sender, e)
{
    if (ELPEndReq != null)
        eval(ELPEndReq);
    ELPEndReq = null;
}

function LoopUpdate(eid, cv, ev, inc)
{
    var ival = cv + inc;
    document.getElementById(eid).innerHTML = Math.floor(ival);
    if ((ival < ev && inc > 0) || (ival > ev && inc < 0))
        setTimeout("LoopUpdate('" + eid + "', " + ival + ", " + ev + ", " + inc + ")", 1000);
}

function CrossDomainJS()
{
    var win = window.open("http://www.google.com");
    win.onbeforeunload = function()
    {
        alert("Test");
    };
    alert(win.document.body.innerHTML);
}
