function openOverlay(width, height, left, top, bgColor, floaterContentsId, opacity)
{
    hideAlwaysOnTop();
    
    var fcEl = document.getElementById(floaterContentsId);
    var pageDims = getPageSize();
    var pageScrollDims = getPageScroll();

    var pageShadow = document.getElementById('TGPageShadow');
    var isNew = !pageShadow;
    if (isNew)
    {
        pageShadow = document.createElement("div");
        pageShadow.setAttribute('id','TGPageShadow');
    }
    pageShadow.style.display = 'none';
    pageShadow.style.position = 'absolute';
    pageShadow.style.top = '0px';
    pageShadow.style.left = '0px';
    pageShadow.style.textAlign = 'left';
    pageShadow.style.zIndex = 998;
    pageShadow.style.backgroundColor = '#000000';
    pageShadow.style.filter="alpha(opacity=" + opacity + ")";
    pageShadow.style.opacity= opacity/100;
    pageShadow.style.width =  pageDims[0] + "px";
    pageShadow.style.height = pageDims[1] + "px";


    if (isNew) document.getElementsByTagName("body").item(0).appendChild(pageShadow);
    document.getElementById('TGPageShadow').style.display = 'block';

    var floater = document.getElementById('TGFloater');
    if (!floater)
    {
        floater = document.createElement("div");
        floater.setAttribute('id','TGFloater');
    }
    floater.style.display = 'none';
    floater.style.position = 'absolute';
    floater.style.top = '0px';
    floater.style.left = '0px';
    floater.style.textAlign = 'center';
    floater.style.zIndex = 999;
    if (isNew) 
        document.getElementsByTagName("body").item(0).appendChild(floater);

    if (width != '-99999')
    {
        floater.style.width = width;
    }
    else 
    {
        floater.style.width = fcEl.offsetWidth;
    }
    if (height != '-99999')
    {
        floater.style.height = height;
    }
    else
    {
        floater.style.height = fcEl.offsetHeight;
    }
    floater.style.backgroundColor = bgColor;

    if (!getChildById(floater, floaterContentsId))
        floater.appendChild(fcEl);

    if (top != '-99999')
    {
        floater.style.top = top + "px";
    }
    else
    {
        var floaterTop = pageScrollDims[1] + parseInt((pageDims[3] / 10));
        floater.style.top = floaterTop + "px";
    }
    if (left != '-99999')
    {
        floater.style.left = left + "px";
    }
    else
    {
        var floaterLeft = pageScrollDims[0] + parseInt((pageDims[0] - fcEl.offsetWidth) / 2);
        floater.style.left = floaterLeft + "px";
    }
    document.getElementById("TGFloater").style.display = 'block';
    
 
}

function closeOverlay()
{
    document.getElementById('TGFloater').style.display = 'none';
    document.getElementById('TGPageShadow').style.display = 'none';
    showAlwaysOnTop();
}

function showAlwaysOnTop()
{
    toggleVisByTagType("select", "visible");
    toggleVisByTagType("object", "visible");
    toggleVisByTagType("embed", "visible");
}

function hideAlwaysOnTop()
{
    toggleVisByTagType("select", "hidden");
    toggleVisByTagType("object", "hidden");
    toggleVisByTagType("embed", "hidden");
}

function toggleVisByTagType(tagName, vis, parentEl)
{
    var pel = parentEl ? parentEl : document;
    var els = pel.getElementsByTagName(tagName);
    for (i = 0; i != els.length; i++) 
    {
       els[i].style.visibility = vis;
    }
}

function getChildById(domEl, id)
{
    var children = domEl.childNodes;
    var retVal = null;
    for (var child in children)
    {
        if (child.id == id)
        {
            retVal = child;
            break;
        }
    }
    return retVal;
}

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

    var xScroll, yScroll;

    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    } 
    else if (document.documentElement && document.documentElement.scrollTop){    // Explorer 6 Strict
        yScroll = document.documentElement.scrollTop;
        xScroll = document.documentElement.scrollLeft;
    } 
    else if (document.body) {// all other Explorers
        yScroll = document.body.scrollTop;
        xScroll = document.body.scrollLeft; 
    }

    arrayPageScroll = new Array(xScroll,yScroll) 
    return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
    
    var xScroll, yScroll;
    
    if (window.innerHeight && window.scrollMaxY) {  
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } 
    else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } 
    else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    
    var windowWidth, windowHeight;

    if (self.innerHeight) { // all except Explorer
        if(document.documentElement.clientWidth){
            windowWidth = document.documentElement.clientWidth; 
        } 
        else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } 
    else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } 
    else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }   
    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight) {
        pageHeight = windowHeight;
    } 
    else { 
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){  
        pageWidth = xScroll;        
    } 
    else {
        pageWidth = windowWidth;
    }

    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
    return arrayPageSize;
}

