﻿var nowPopupDivID = "div_MakePopup";
var nowTempDivID = "div_MakeTemp";
var nowPopupTitleID = "span_title";
var nowPopupIframeID = "iframe_Popup";
var nowPopupNumber = 0;

var ManagerRefreshControlID = "";
var ContentRefreshControlID = "";

function MakePopup() {
    nowPopupNumber = nowPopupNumber + 1;

    if (document.getElementById(nowPopupDivID + nowPopupNumber.toString()) != "[object]") {
        var makePopup = "<div id='" + nowPopupDivID + nowPopupNumber.toString() + "' name='" + nowPopupDivID + "' style='z-index:100; position:absolute; width:0px; height:0px; display:none; border:solid 2px #333333;' ><table border='0' cellpadding='0' cellspacing='0' ><tr style='background-color:#45689e' height='30px' ><td><span id='" + nowPopupTitleID + nowPopupNumber.toString() + "' style='color:White; font-size:10pt; font-Family:gulim; padding:0 0 0 5;'></span></td><td align='right' style='padding: 0 5 0 0'><img src='http://image.jump2000.net/j2/button/popupbtn_close.gif' style='cursor:hand' align='absmiddle' onclick='return ClosePopup()' /></td></tr><tr><td colspan='2' style='padding:8px 8px 8px 8px; background-color:White;' align='center' valign='middle' ><iframe frameborder='0' id='" + nowPopupIframeID + nowPopupNumber.toString() + "' onload='top.AutoSizeDialog();'></iframe></td></tr></table></div><div id='" + nowTempDivID + nowPopupNumber.toString() + "'></div>";
        var makeBackGround = "<div id='div_background' style='z-index:0; position:absolute; width:100%; height:100%; display: none; overflow:hidden'><table border='0' cellpadding='0' cellspacing='0' style='background-color: Gray; filter:alpha(opacity=70); width:101%; height:101%'><tr><td><iframe frameborder='0' style='filter:alpha(opacity=70); width:101%; height:101%'></iframe></td></tr></table></div>";

        if (nowPopupNumber > 1) {
            document.getElementById(nowTempDivID + (nowPopupNumber - 1).toString()).innerHTML += makePopup;
        }
        else {
            document.getElementById("div_popup").innerHTML += makePopup;
        }

        //document.body.innerHTML += makePopup;

        if (document.getElementById("div_background") != "[object]") {
            document.getElementById("div_popup").innerHTML += makeBackGround;
            //            document.body.innerHTML += makeBackGround;
        }
    }
}

function OpenPopup(page, title) {
    MakePopup();
    var divPopup = nowPopupDivID + nowPopupNumber.toString();
    var spanTitle = nowPopupTitleID + nowPopupNumber.toString();
    var iframePopup = nowPopupIframeID + nowPopupNumber.toString();

    document.getElementById(spanTitle).innerHTML = "";

    document.getElementById(divPopup).style.display = "inline";

    if (CheckNull(title)) {
        document.getElementById(spanTitle).innerHTML = title;
    }

    document.getElementById(iframePopup).src = page;

    document.getElementById("div_background").style.display = "inline";
    document.getElementById("div_background").style.left = "0";
    document.getElementById("div_background").style.top = "0";

    return false;
}

function ClosePopup() {
    var divPopup = nowPopupDivID + nowPopupNumber.toString();
    var spanTitle = nowPopupTitleID + nowPopupNumber.toString();
    var iframePopup = nowPopupIframeID + nowPopupNumber.toString();

    if (document.getElementById(divPopup) == "[object]") {
        document.getElementById(divPopup).style.display = "none";
        document.getElementById(divPopup).style.left = document.body.clientWidth;
        document.getElementById(divPopup).style.top = document.body.clientHeight;

        nowPopupNumber = nowPopupNumber - 1;

        if (nowPopupNumber == 0) {
            document.getElementById("div_background").style.display = "none";
            document.getElementById("div_background").style.left = document.body.clientWidth;
            document.getElementById("div_background").style.top = document.body.clientHeight;
        }
    }

    EndProcess();

    return false;
}

function PopupOpener(control_id) {
    var popupOpener; //= top. iframe_Main.iframe_Content.document.getElementById(control_id);

    if (nowPopupNumber > 1 && CheckNull(top. eval(nowPopupIframeID + (nowPopupNumber - 1).toString()).document.getElementById(control_id))) {
        popupOpener = top.eval(nowPopupIframeID + (nowPopupNumber - 1).toString()).document.getElementById(control_id);
    }
    else if (CheckNull(top.iframe_Main.iframe_Content.document.getElementById(control_id))) {
        popupOpener = top.iframe_Main.iframe_Content.document.getElementById(control_id);
    }
    else if (CheckNull(top.iframe_Main.document.getElementById(control_id))) {
        popupOpener = top.iframe_Main.document.getElementById(control_id);
    }
    else if (CheckNull(top.document.getElementById(control_id))) {
        popupOpener = top.document.getElementById(control_id);
    }


    return popupOpener;
}

function RefreshManager() {
    if (CheckNull(PopupOpener(ManagerRefreshControlID))) {
        PopupOpener(ManagerRefreshControlID).click();
    }
    else {
        iframe_Main.location.href = iframe_Main.location;
    }
}

function RefreshContent() {
    if (CheckNull(PopupOpener(ContentRefreshControlID))) {
        PopupOpener(ContentRefreshControlID).click();
    }
    else {
        iframe_Main.iframe_Content.location.href = iframe_Main.iframe_Content.location;
    }
}

function CheckNull(arg) {
    var fin = true;

    switch (arg) {
        case undefined: fin = false; break;
        case "": fin = false; break;
        case null: fin = false; break;
    }

    return fin;
}

function AutoSizeDialog() {
    var divPopup = nowPopupDivID + nowPopupNumber.toString();
    var spanTitle = nowPopupTitleID + nowPopupNumber.toString();
    var iframePopup = nowPopupIframeID + nowPopupNumber.toString();

    if (nowPopupNumber > 0 && CheckNull(eval(iframePopup).dialogTb)) {
        var height = eval(iframePopup).dialogTb.clientHeight;
        var width = eval(iframePopup).dialogTb.clientWidth;

        if (width > top.document.body.clientWidth) {
            height = height + 20;
            width = top.document.body.clientWidth;
        }

        if (height > top.document.body.clientHeight) {
            height = top.document.body.clientHeight - 40;
            width = width + 20;
        }

        top.document.getElementById(iframePopup).height = height + 2;
        top.document.getElementById(iframePopup).width = width + 2;

        top.document.getElementById(divPopup).style.left = (top.document.body.clientWidth / 2) - (width / 2);
        top.document.getElementById(divPopup).style.top = (top.document.body.clientHeight / 2) - (height / 2) - 32;
        top.document.getElementById(divPopup).style.display = "inline";
    }

    return false;
}

function ReSizeFrame(arg) {
    //    if (arg == "[object]")
    //    {
    //        if (arg.clientHeight < arg.scrollHeight)
    //        {
    //            arg.height = arg.scrollHeight;
    //        }
    //        
    //        if (arg.clientWidth < arg.scrollWidth)
    //        {
    //            arg.width = arg.scrollWidth;
    //        }
    //    }
}

function LoadProcess() {
//    div_Loding.style.display = "inline";
//    div_Loding.style.left = 0;
//    div_Loding.style.top = 0;
}

function EndProcess() {
//    div_Loding.style.display = "none";
}