/*
 * This is a set of functions to handle displaying or hiding a dhtml layer
 * that will be displayed at the center of the browser screen.
 *
 * A css style must be declared within the html page that includes this js
 * file. Ex:
 *
 * <style>
 * #myLayer
 * {
 *   display: none;
 *   position: absolute;
 *   left: 0px;
 *   top: 0px;
 *   z-index: 5;
 * }
 * </style>
 *
 * Copyright (C) 2003 by John Glorioso, Zitego Solutions, LLC
 * <jglorioso@zitego.com>. All rights reserved.
 *
 * Redistribution and use in source forms, with or without modification, are
 * permitted provided that the following condition is met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * @author John Glorioso
 * @version $Id: floating_layer.js,v 1.1 2008/02/20 15:19:35 jglorioso Exp $
 */

//DHTML include
document.write("<scr"+"ipt src=\"/js/dhtml.js\"></scr"+"ipt>");

/**
 * Displays or hides the dhtml layer named "floating_layer".
 *
 * @param flag Whether to hide or display the layer (true/false).
 */
function toggleLayer(flag, layer_id)
{
    var x, y;
    if (self.innerHeight)
    {
        x = self.innerWidth;
        y = self.innerHeight;
    }
    else
    {
        if (document.documentElement && document.documentElement.clientHeight)
        {
            x = document.documentElement.clientWidth;
            y = document.documentElement.clientHeight;
        }
        else
        {
            if (document.body)
            {
                x = document.body.clientWidth;
                y = document.body.clientHeight;
            }
        }
    }

    var elem = getObject( (layer_id ? layer_id : "floating_layer") );
    var shimElem = getObject("layerShim");
    if (elem != null && shimElem != null)
	{
	    elem.style.visibility = (flag ? "visible" : "hidden");
		elem.style.display = (flag ? "block" : "none");
		shimElem.style.visibility = (flag ? "visible" : "hidden");
		shimElem.style.display = (flag ? "block" : "none");
		shimElem.style.height = elem.offsetHeight;
	    shimElem.style.width = elem.offsetWidth;
		elem.style.zIndex = 999999;

		var top = (y / 2 - elem.offsetHeight / 2) + document.body.scrollTop;
		var left = x / 2 - elem.offsetWidth / 2;
		if (left <= 0) left = 10;

		elem.style.left = left + "px"
		elem.style.top = top + "px";
		shimElem.style.left = left + "px"
		shimElem.style.top = top + "px";
	}
}
