/**
 * @project     Chameleon
 * @revision    
 * @purpose     DHTML utilities for building an interface
 * @author      DM Solutions Group (spencer@dmsolutions.ca)
 * @copyright
 * <b>Copyright (c) 2005, DM Solutions Group Inc.</b>
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

//browser detection
var CWCIsNav4 = (document.layers) ? 1:0;
var CWCIsIE = (document.all) ? 1:0;
var CWCIsNav6 = (document.getElementById && !document.all) ? 1:0;


/* ==================================================================== */
/*  CWCDHTML_GetBrowserWH( )                                            */
/*  returns width and height of current browser window                  */
/* ==================================================================== */
function CWCDHTML_GetBrowserWH( )
{
    var aWinWH = Array();

    if (self.innerHeight) // all except Explorer
    {
      aWinWH[0] = self.innerWidth;
      aWinWH[1] = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
      // Explorer 6 Strict Mode
    {
      aWinWH[0] = document.documentElement.clientWidth;
      aWinWH[1] = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
      aWinWH[0] = document.body.clientWidth;
      aWinWH[1] = document.body.clientHeight;
    }

    return aWinWH;
}

/* ==================================================================== */
/*  CWCDHTML_GetLayer( name )                                           */
/*  returns a handle on a Layer object                                  */
/*  if optional arg (true) is set - layer returned writes to contents   */
/* ==================================================================== */
function CWCDHTML_GetLayer( name )
{
    if (CWCIsNav4) // Netscape
    {                
        return document.layers[name];
    } 
    else if (CWCIsIE) // IE
    {            
        if (eval('document.all.' + name) != null) 
        {
            if( arguments.length > 1 && arguments[1] == true )
            {
                layer = eval('document.all.' + name);
            }
            else
            {
                layer = eval('document.all.' + name + '.style');
            }
            return layer;

        } 
        else 
        {
            return null;
        }
    } 
    else if (CWCIsNav6) 
    {
        if (eval('document.getElementById("' + name + '")') != null)
        {
            if( arguments.length > 1 && arguments[1] == true )
            {
                layer = eval('document.getElementById("' + name + '")');
            }
            else
            {
                layer = eval('document.getElementById("' + name + '").style');
            }
            return layer;
        } 
        else 
        {
            return null;
        }
    } 
    else // Don't know
    {                              
        return null;
    }
}


/* ==================================================================== */
/*  GetLayerWH(layerName)                                               */
/*  gets a layer's real width and height including padding and borders  */
/* ==================================================================== */
function getLayerWH(szLayer)
{
    /* Content Layer Height */
    var oLayer;
    var aLayerWH = Array();

    if( CWCIsNav4 )
    {
        oLayer = CWCDHTML_GetLayer( szLayer );
        aLayerWH[0] = oLayer.clip.width;
        aLayerWH[1] = oLayer.clip.height;
    }
    else
    {
        oLayer = CWCDHTML_GetLayer( szLayer, true );
        aLayerWH[0] = oLayer.offsetWidth;
        aLayerWH[1] = oLayer.offsetHeight;
    }
    return aLayerWH;
}


/* ==================================================================== */
/*  CWCDHTML_SetLayerPos(layerName, x, y)                               */
/*  sets layer position based on recieved x & y coords                  */
/* ==================================================================== */
function CWCDHTML_SetLayerPos(layerName, x, y)
{
    var oLayer = CWCDHTML_GetLayer(layerName);
    
    if (oLayer != null)
    {
        oLayer.left=x;
        oLayer.top=y;
    }
    else
        alert( "layer " + layerName + " doesn't exist" );
}


/* ==================================================================== */
/*  CWCDHTML_SetLayerVis(layerName, bVisible)                           */
/*  sets layer visibility based on true/false                           */
/* ==================================================================== */
function CWCDHTML_SetLayerVis(layerName, bVisible)
{
    var oLayer = CWCDHTML_GetLayer(layerName);
    if (CWCIsNav4)
    {
        if (bVisible)
            oLayer.visibility = "show";
        else
            oLayer.visibility = "hide";
    }
    else
    {
        if (bVisible)
            oLayer.visibility = "visible";
        else            
            oLayer.visibility = "hidden";
    }
}

/* ==================================================================== */
/*  CWCDHTML_SetLayerSize(layerName, bVisible)                          */
/*  sets layer size based on true/false                                 */
/* ==================================================================== */
function CWCDHTML_SetLayerSize(layerName, imgWidth, imgHeight)
{

    var oLayer = CWCDHTML_GetLayer( layerName );

    oLayer.width = imgWidth;
    oLayer.height = imgHeight;

}

/* ==================================================================== */
/*  CWCDHTML_GetImage( szImage )                                        */
/*  returns a handle on an Image object                                 */
/* ==================================================================== */
function CWCDHTML_GetImage( szImage )
{
    var obj = null;
    if (CWCIsNav4) //Netscape 4.x
    {
        obj = document.images[szImage];
    }
    else
    {
        obj = document.getElementById(szImage);
    }
    return obj;
}

