﻿// File JScript
var dialog;

if (window.addEventListener)
{
    window.addEventListener ('scroll', scrollForDialog, false);
}
else
{
    window.attachEvent ("onscroll", scrollForDialog);
}

function scrollForDialog ()
{
    if (dialog == null)
        return;
        
    var scroll = getScrollXY ();
    dialog.style.left = scroll [0] + "px";
    dialog.style.top = scroll [1] + "px";
    
    centerInnerFrame ();
}

function ShowDialog (dialogName)
{
    dialog = document.createElement ("div");
    dialog.id = dialogName;
    var res = GLWebLibrary.DialogBox.GetDialogHtml (document.getElementById("sessionState").value, dialogName);
    dialog.innerHTML = res.value;
        
    var body = document.getElementsByTagName("body").item(0);
    body.insertBefore (dialog, body.firstChild);

    centerInnerFrame ();
}

function centerInnerFrame ()
{
    if (dialog == null)
        return;
        
    var scroll = getScrollXY ();

    
    var outerFrame = document.getElementById (dialog.id + "_outerFrame");
    var innerFrame = document.getElementById (dialog.id + "_innerFrame");
    
    outerFrame.style.left = scroll [0] + "px";
    outerFrame.style.top = scroll [1] + "px";
    innerFrame.style.left = ((getWindowWidth () - innerFrame.offsetWidth) / 2) + "px";
    innerFrame.style.top = ((getWindowHeight () - innerFrame.offsetHeight) / 2) + "px";
}

function dialogOnClickCancel (btn)
{
    CallCustomFunction (document.getElementById(dialog.id + "_outerFrame"), "CustomClickCancel");
    
    var body = document.getElementsByTagName("body").item(0);
    body.removeChild (dialog);
    
    dialog = null;
}

function dialogOnClickOK (btn)
{
    CallCustomFunction (document.getElementById(dialog.id + "_outerFrame"), "CustomClickOK");
    var body = document.getElementsByTagName("body").item(0);
    body.removeChild (dialog);
    
    dialog = null;
}
