//******************
// Global Variables
//******************

// These variables specify the normal and mouseover colors
// for the left-side and Policy navigation tables.
var WGH_leftNavNormal = "#00A552";
var WGH_leftNavHover  = "#0030E0";

var WGH_policyNormal  = "#0033CC";
var WGH_policyHover   = "#FFFF66";


// These variables indicate the type of DOM, if any, this browser uses.
var WGH_isDHTML  = 0;
var WGH_isLayers = 0;
var WGH_isAll    = 0;
var WGH_isID     = 0;
var WGH_browserVersion = parseInt(navigator.appVersion);

// Adjust global variable values based on browser type.
if (document.getElementById)
{
    WGH_isID    = 1;
    WGH_isDHTML = 1;
}
else if (document.all)
{
    WGH_isAll   = 1;
    WGH_isDHTML = 1;
}
else if ((navigator.appName.indexOf('Netscape') != -1) && (WGH_browserVersion == 4))
{
    WGH_isLayers = 1;
    WGH_isDHTML  = 1;
}


//********************************************************
//* This function takes an object's ID and creates a DOM
//* for the browser being used.
//********************************************************
function WGH_findDOM(objectId,withStyle)
{
    if (withStyle == 1)
    {
        if (WGH_isID)
        {
            return(document.getElementById(objectId).style);
        }
        else if (WGH_isAll)
        {
            return(document.all[objectId].style);
        }
        else if (WGH_isLayers)
        {
            return(document.layers[objectId]);
        }
    }
    else if (WGH_isID)
    {
        return(document.getElementById(objectId));
    }
    else if (WGH_isAll)
    {
        return(document.all[objectId]);
    }
    else if (WGH_isLayers)
    {
        return(document.layers[objectId]);
    }
    
} // WGH_findDOM()


//************************************
//* Returns specified object's width
//************************************
function WGH_findWidth(objectID)
{
    var dom = WGH_findDOM(objectID,0);

    if (dom.offsetWidth)
        return(dom.offsetWidth);

    if (dom.clip.width)
        return(dom.clip.width);

    return(null);

} // WGH_findWidth()


//*******************************************************
// This function is called from the Bible Gateway form
// to (1) request a Bible search and (2) put the results
// in a new window.
//*******************************************************
function WGH_BibleGateway()
{
    var serverURL = "http://bible.gospelcom.net/bible?";
    var sParams;
    var sFeatures;
    var newWindow;

    // The Bible Gateway server requires that the search parameters
    // be escaped.  So, escape them and build the URL string.
    sParams  = "passage="     + escape(document.BibleGW.passage.value);
    sParams += "&version="    + document.BibleGW.version.value;
    sParams += "&language="   + document.BibleGW.language.value;
    sParams += "&search="     + escape(document.BibleGW.search.value);
    sParams += "&SearchType=" + document.BibleGW.SearchType.value;

    serverURL += sParams;

    // Build window feature string
    sFeatures  = "height=400,width=500,innerHeight=400,innerWidth=500";
    sFeatures += ",screenX=50,screenY=50,left=50,top=50";
    sFeatures += ",resizable,scrollbars,status,dependent";

    // Open the Window and give it the focus.
    newWindow = window.open( serverURL, 'BGWSearchResults', sFeatures );
    newWindow.focus();

} // WGH_BibleGateway()


//*******************************************************
// This function can be called from any page on the
// site to allow the user to send an e-mail message
// to a specified person.
//*******************************************************
function WGH_WriteMessage(Code)
{
    var serverURL = "/misc/mail_compose.php";
    var sParams;
    var sFeatures;
    var newWindow;

    // Escape the parameter and build the URL string.
    sParams      = "?UserCode=" + escape(Code);
    serverURL += sParams;

    // Build window feature string
    sFeatures  = "height=450,width=510,innerHeight=450,innerWidth=510";
    sFeatures += ",screenX=100,screenY=50,left=100,top=50";
    sFeatures += ",resizable,scrollbars,status,dependent";

    // Open the Window and give it the focus.
    newWindow = window.open( serverURL, 'WGHMailCompose', sFeatures );
    newWindow.focus();

} // WGH_WriteMessage()

// Shortened function name for WGH_WriteMessage()
function mail(Code)
{
   WGH_WriteMessage(Code);
}


//****************************************************
//* Date Display Function for page heading
//*
//* Outputs a string of HTML of the form:
//*     day-of-week<br>
//*     full-month-name day, 4-digit-year
//*
//****************************************************
function WGH_displayToday()
{
  var Months = new Array("January","February","March","April","May","June",
                         "July","August","September","October","November","December");
  var Days   = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");

  var MyDate = new Date();
  var Year   = MyDate.getYear();

  if (Year < 1900)
  {
    Year += 1900;
  }
  document.write(Days[MyDate.getDay()]+"<br>\n"+Months[MyDate.getMonth()]+"&nbsp;"+MyDate.getDate()+",&nbsp;"+Year);
}

//************************************************************************
//* FUNCTION WGH_swapImages - for doing Image Rollovers
//*
//* PARAMETERS
//*   ImageName = Name of image as specified in IMG tag's name attribute.
//*   Source    = Integer indicating folder where NewImage is located:
//*                  1 = /images/
//*                  If any other value is specified, the path is assumed
//*                  to be in NewImage.
//*   NewImage  = Filename of the image to be swapped in.
//************************************************************************

function WGH_swapImages(ImageName, Source, NewImage)
{
  var ImageDir;

  if (document.images)
  {
    if (Source == 1)
    {
      ImageDir = "/images/";
    }
    else
    {
      ImageDir = "";
    }
    document[ImageName].src = ImageDir+NewImage;
  }
}

//************************************************************************
//* FUNCTION WGH_MakeLNavNormal - Sets the object's background color
//*                               to the left-side's normal color.
//*
//* PARAMETERS
//*   objID = Object's ID value.
//*
//* RETURN VALUE
//*   None
//************************************************************************

function WGH_MakeLNavNormal(objID)
{
    var thisobj = WGH_findDOM(objID,1);

    thisobj.backgroundColor = WGH_leftNavNormal;
}

function WGH_MakePolicyNormal(objID)
{
    var thisobj = WGH_findDOM(objID,1);
    var spanobj = WGH_findDOM("S"+objID,1);

    thisobj.backgroundColor = WGH_policyNormal;
    spanobj.color = "#FFFFFF";
}

//************************************************************************
//* FUNCTION WGH_MakeLNavHover - Sets the object's background color
//*                              to the left-side's mouseover color.
//*
//* PARAMETERS
//*   objID = Object's ID value.
//*
//* RETURN VALUE
//*   None
//************************************************************************

function WGH_MakeLNavHover(objID)
{
    var thisobj = WGH_findDOM(objID,1);

    thisobj.backgroundColor = WGH_leftNavHover;
}

function WGH_MakePolicyHover(objID)
{
    var thisobj = WGH_findDOM(objID,1);
    var spanobj = WGH_findDOM("S"+objID,1);

    thisobj.backgroundColor = WGH_policyHover;
    spanobj.color = "#000000";
}


//************************************************************************
//* FUNCTION WGH_NewHref - Changes the URL of the current window.
//*
//* PARAMETERS
//*   newUrl = absolute path to new page.
//*
//* RETURN VALUE
//*   None
//************************************************************************

function WGH_NewHref(newUrl)
{
    document.location.href= newUrl;
}


//********************************************************************************
//* FUNCTION WGH_getAbsTop()
//*     Runs recursively to get the absolute Y coordinate of the top
//*     of the specified DOM element.
//* AUTHOR
//*     Bill Hannold 27-Jul-2004
//*
//* NOTE - This has been tested on IE 6.0.  It has not been tested with Netscape.
//*********************************************************************************
function WGH_getAbsTop(ele)
{
    var eleName = ele.tagName;
    var offsetOfMyParent;
	
    if ((eleName.toUpperCase() == "BODY") || (ele.tagName == ""))
    {
    	offsetOfMyParent = 0;
    }
    else
    {
    	offsetOfMyParent = WGH_getAbsTop(ele.offsetParent);
    }

    return(ele.offsetTop + offsetOfMyParent);

} // end of WGH_getAbsTop()


//************************************************************************
//* FUNCTION JSFX_FloatTopDiv - Operates a floating DIV
//*
//* PARAMETERS
//*   None
//*
//* RETURN VALUE
//*   None
//*
//* GLOBAL VARIABLES
//*   Requires that an element with id="bottomLeftFixed" be located on 
//*     the page, just below that last fixed element that the floating
//*     DIV should not cover up.
//************************************************************************
function JSFX_FloatTopDiv()
{
    var ns     = (navigator.appName.indexOf("Netscape") != -1);
    var d      = document;
    var ble    = d.getElementById ? d.getElementById("bottomLeftFixed") :
                 d.all ? d.all["bottomLeftFixed"]:d.layers["bottomLeftFixed"];
    var msgdiv = d.getElementById ? d.getElementById("msgid") : d.all ? d.all["msgid"] : d.layers["msgid"];
	

	function ml(id)
	{
		var el = WGH_findDOM(id,0);

		if(d.layers)
		    el.style=el;
		el.sP=function(x,y){this.style.left=x;this.style.top=y;};
		el.x = JSFX_startX;
		if (JSFX_verticalPos=="fromtop")
		    el.y = JSFX_startY;
		else
		{
		    el.y  = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		    el.y -= JSFX_startY;
		}
		return el;
	}

	window.stayTopLeft=function()
	{
		if (JSFX_verticalPos=="fromtop")
		{
		    var pY = ns ? pageYOffset : document.body.scrollTop;
		    ftlObj.y += (pY + JSFX_startY - ftlObj.y)/8;
		}
		else
		{
		    var pY    = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		    var limit = WGH_getAbsTop(ble) + ble.offsetHeight + 10;

		    ftlObj.y += (pY - JSFX_startY - ftlObj.y)/8;

                    if (ftlObj.y < limit)
		    {
		    	ftlObj.y = limit;
		    }
		}
		ftlObj.sP( ftlObj.x, ftlObj.y );
		setTimeout( "stayTopLeft()", 10 );
	}
	ftlObj = ml("divStayTopLeft");
	stayTopLeft();
} //End of JSFX_FloatTopDiv()

