﻿//generic function to open a page in a new browser window...
function newWindow4(url, windowName, width, height) {
    var size = "width=" + width + ",height=" + height;
    var chrome = "top=20,left=20,scrollbars=1,title=0,address=0,status=0,toolbar=0,resizable=1," + size;
    var windo = window.open(url, windowName, chrome)
    windo.focus();
}

// "global" variables used by the showDiv() & hideDiv() functions
var g_divNameOpen = ""; // id (name) of the "open" hidden div
var g_showGrayOverlay = false; // only do this if specified
var g_scrollBackPosition = -1; // used to return scroll position back prior to when moved to show "special" divs

// function to display specified hidden div (without gray overlay)
function showDiv(divName) {
    g_showGrayOverlay = false;
    //alert("@showDiv(" + divName + ") : divOpen=" + g_divNameOpen);
    if (g_divNameOpen != "") {
        if (divName == g_divNameOpen)		// if div is already visible
            return; 					// don't do anything
        hideDiv(g_divNameOpen); 	// else hide the currently-open div
    }
    var divobj = getFieldByID(divName)
    if (divobj) {
        divobj.style.display = "block";
        g_divNameOpen = divName; 	// remember name of open div
    }
}

// function to display hidden div and also display the gray background overlay
function showDivWithOverlay(divName) {
    //alert("@showDivWithOverlay(" + divName + ") : divOpen=" + g_divNameOpen);
    showDiv(divName);
    showOverlay(true); // this will set the global variable: g_showGrayOverlay
}

// function to hide specified div and also hide the gray background overlay
function hideDiv(divName) {
    if (divName == '')
        divName = g_divNameOpen;
    var divobj = getFieldByID(divName)
    if (divobj) {
        divobj.style.display = "none";
        g_divNameOpen = ""; 	// reset the name of open div (since it is no longer open)
        if (g_showGrayOverlay)
            showOverlay(false); // will hide the overlay & reset the global variable: g_showGrayOverlay
    }
    //alert("g_scrollBackPosition=" + g_scrollBackPosition);
    if (g_scrollBackPosition >= 0) {
        window.scrollTo(0, g_scrollBackPosition);
    }
    // currently only 1 div is open at a time using these showDiv() & hideDiv() functions so following is OK
    g_scrollBackPosition = -1; 		// so this value will not cause unintended scroll-backs
}

function showOverlay(show)	// show or hide the gray overlay
{
    //alert("@showOverlay:show=[" + show + "]");
    var fld = getFieldByID('WindowOverlay');
    if (fld != null) {
        //show only if the browser supports opacity
        if ('opacity' in document.documentElement.style) {
            if (show) {
                var objDiv = getFieldByID('aspnetForm'); //'contentMain');
                if (objDiv != null) {
                    var fullHeight = objDiv.offsetHeight;
                    //alert("setOverlayFullHeight="+fullHeight);
                    fld.style.height = fullHeight + "px"; 	// set height of the overlay to entire page height
                }
            }
            g_showGrayOverlay = show; 	// keep track if this is currently open
            if (show)
                show = 'block';
            else
                show = 'none';
            //alert("ShowingOverlay:style.display=[" + show + "]");
            fld.style.display = show;
        }
    }
}



