﻿var bgDiv = null;
var wndDiv = null;
function ShowPopup(url, width, height)
{
    var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body

    bgDiv = document.createElement("div");
    bgDiv.style.cssText = "width: " + iebody.scrollWidth + "px; height: " + Math.max(iebody.scrollHeight, iebody.clientHeight) + "px; position: absolute; top: 0; left: 0; z-index: 9990; background: url(images/bgdivbg.png);";
    document.body.appendChild(bgDiv);
    
//    var selects = document.getElementsByTagName("select");
//    if (selects.length > 0)
//    {
//        for (i in selects)
//        {
//            selects[i].style.visibility = "hidden";
//        }
//    }
    var page = document.getElementById("PageArea");
    var pos = getPosition(page);
    
    if (width == undefined || width == null)
        {
            width = 500;
            height = 400;
        }

    wndDiv = document.createElement("div");
    wndDiv.style.cssText = "position: absolute; left:" + (iebody.scrollLeft + iebody.offsetWidth/2 - width/2) +"px; height: "+height+"px; top: " + (iebody.scrollTop + iebody.offsetHeight/2 - height/2) + "px;  z-index: 9991;";
    var szHTML = "";
    szHTML += "<table dir='rtl' style='width: "+width+"px; height: "+height+"px;' cellpadding='0' cellspacing='0'>";
    szHTML += "<tr style='height: 31px;'><td style='width: 10px; background: url(images/wndBoxUR.gif)'>&nbsp;</td>";
    szHTML += "<td style='background: url(images/wndBoxUM.gif); text-align: left; vertical-align: middle;'>";
    szHTML += "<span style='color: white; font-family:verdana; font-size: 10pt; font-weight: bold; position: relative; top: 3px;' id='DlgSpanTitle'></span>";
    szHTML += "<img src='images/buttons/closeButton.gif' alt='close' style='cursor: hand; position: absolute; right: 10px; top: 10px;' onclick='ClosePopup();' />";
    szHTML += "</td><td style='width: 10px; background: url(images/wndBoxUL.gif)'>&nbsp;</td></tr>";
    szHTML += "<tr style='height: 100%;'><td style='width: 10px; background: url(images/wndBoxMR.gif)'>&nbsp;</td><td align='left' valign='top' style='background: white; '>";
    szHTML += "<iframe name='dlgframe' style='width:100%; height: "+(height - 75)+"px;' src='" + url + "' frameborder='0'></iframe>";
    szHTML += "</td><td style='width: 10px; background: url(images/wndBoxML.gif)'>&nbsp;</td></tr>";
    szHTML += "<tr style='height: 8px; font-size:1px;'><td style='width: 10px; background: url(images/wndBoxBR.gif)'>&nbsp;</td><td style='background: url(images/wndBoxBM.gif)'>&nbsp;<img src='images/buttons/close.png' alt='close' style='cursor: hand; position: absolute; left: "+(width/2 - 23)+"px; bottom: 10px;' onclick='ClosePopup();' /></td><td style='width: 10px; background: url(images/wndBoxBL.gif)'>&nbsp;</td></tr>";
    szHTML += "</table>";
    wndDiv.innerHTML = szHTML;
    document.body.appendChild(wndDiv);
    frames['dlgframe'].document.onreadystatechange = dialog_loaded;
}
function dialog_loaded()
{
    if (frames['dlgframe'].document.readyState=="complete")
    {
        var title = document.getElementById("DlgSpanTitle");
        title.innerHTML = frames['dlgframe'].document.title;
    }
}

function ClosePopup(refresh)
{
   // __doPostBack('Page_Load', '');
   if (dlgframe.location.pathname.indexOf("Project.aspx") > -1)
        afterClose();
    if (wndDiv != null) wndDiv.parentNode.removeChild(wndDiv);
    wndDiv = null;
    
//    var selects = document.getElementsByTagName("select");
//    if (selects.length > 0)
//    {
//        for (i in selects)
//        {
//            selects[i].style.visibility = "";
//        }
//    }
    
    if (bgDiv != null) bgDiv.parentNode.removeChild(bgDiv);
    bgDiv = null;
    
    if (refresh != null && refresh==true) location = location;
}

function getPosition(obj){
    var topValue= 0,leftValue= 0;
    while(obj){
	leftValue+= obj.offsetLeft;
	topValue+= obj.offsetTop;
	obj= obj.offsetParent;
    }
    var result = new Object();
    result.top = topValue;
    result.left = leftValue;
    return result;
}
