var activeDialog=null;


function showVisiblePos(div) {

    div.style.left = 0;
    div.style.top = 0;
    div.style.visibility = "hidden";
    div.style.display = "";

    var w = div.offsetWidth;
    var h = div.offsetHeight;

    var x = document.body.clientWidth/2-w/2;
    var y = document.body.clientHeight/2-h/2;
    if (x<0) x = 0;
    if (y<0) y = 0;
    var scrlX = document.all?document.body.scrollLeft:window.pageXOffset;
    var scrlY = document.all?document.body.scrollTop:window.pageYOffset;

    div.style.left = (scrlX+x)+"px";
    div.style.top = (scrlY+y)+"px";
    div.style.visibility = "visible";
}

function dialogShow(id) {
    activeDialog = document.getElementById(id);
    showVisiblePos(activeDialog);
    showDarko();
}
function dialogShowXY(id, x, y) {
    activeDialog = document.getElementById(id);
    activeDialog.style.left = x+"px";
    activeDialog.style.top = y+"px";
    activeDialog.style.display = "";
    showDarko();
}
function dialogClose() {
    if (activeDialog!=null) {
        activeDialog.style.display = 'none';
        activeDialog = null;
        hideDarko();
    }
}
function __dlg(a) {return true;}

var darko_div = null;
function darko() {
    if (darko_div==null) {
        darko_div =  document.createElement("div");
        darko_div["className"] = "darko";
        document.body.appendChild(darko_div);
    }
    return darko_div;
}
function showDarko() {
    darko().style.display = 'block';
    darkoResize();
}
function hideDarko() {
    darko().style.width = "0px";
    darko().style.height = "0px";
    darko().style.display = 'none';
}
function darkoResize() {
    darko().style.width = document.body.scrollWidth +"px";
    darko().style.height = document.body.scrollHeight +"px";
}
frameAttach("resize", function() {
   if (activeDialog) {
       darkoResize();
   }
});
