﻿
// Skript pro zobrazení dialogového popup okna.

// Příklad použití:
//
// <%--tlačítko pro zobrazení popup okna--%>
// <asp:HyperLink ID="btnShow" runat="server">Smazat</asp:HyperLink>
// <%-popup okno--%>
//	<div id="divPopup" style="position:absolute; z-index:100; display:none; background-image:url(../_Img/Dialog/160x40.png); width:160px; height:40px" runat="server">
//		<div style="width:146px; margin:12px auto 6px auto">
//			opravdu smazat&nbsp;
//			<asp:LinkButton ID="lbSmazat" runat="server">Ano</asp:LinkButton>&nbsp;/&nbsp;
//			<asp:HyperLink ID="btnHide" runat="server">Ne</asp:HyperLink>								
//		</div>
//	</div>
// <%--doplnění parametrů dynamicky (pokud je popup použito např. v ListView)--%>
// btnShow.NavigateUrl = String.Format("javascript:ShowPopup('{0}', '{1}', 20, -110)", divPopup.ClientID, btnShow.ClientID)
// btnHide.NavigateUrl = String.Format("javascript:HidePopup('{0}')", divPopup.ClientID)


// Zobrazí popup okno idDivPopup po kliknutí na odkaz idBtnPopup. Pozice okna je relativní vůči idBtnPopup, offset určují offsetTop resp. offsetLeft.
function ShowPopup(idDivPopup, idBtnPopup, offsetTop, offsetLeft) {
    document.getElementById(idDivPopup).style.display = "block";
    document.getElementById(idDivPopup).style.top = getY(document.getElementById(idBtnPopup)) + offsetTop + 'px';
    document.getElementById(idDivPopup).style.left = getX(document.getElementById(idBtnPopup)) + offsetLeft + 'px';
    //alert(document.getElementById(idDivPopup).style.left + "\n" + document.getElementById(idDivPopup).style.top);
}

// Skryje popup okno
function HidePopup(idPopup) {
    document.getElementById(idPopup).style.display = "none";
}

// Vrací Y pozici elementu v dokumentu (element není absolutně pozicován).
function getY(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

// Vrací X pozici elementu v dokumentu (element není absolutně pozicován).
function getX(oElement) {
    var iReturnValue = 0;
    while (oElement != null) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
