/* findDOM.js  version 1.0 */

/* JavaScript functions that determine a browser's Document Object Model (DOM) Type    */
/* to allow for cross browser JavaScript/DHTML Functions                               */


var isDHTML = 0;    // Indicates browser has a DOM type and therefore is DHTML compatible
var isID = 0;       // Indicates browser uses W3C's ID DOM
var isAll = 0;      // Indicates browser uses Internet Explorer's All DOM
var isLayers = 0;   // Indicates browser uses Netscape Layer DOM (Netscape 4)


/* Determine browser's DOM (Document Object Model) Type */
if (document.getElementById)
{
    isID = 1; isDHTML = 1;
}
else
{
    if (document.all)
    {
        isAll = 1; isDHTML = 1;
    }
    else
    {
        browserVersion = parseInt(navigator.appVersion);
        if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4))
        {
            isLayers = 1; isDHTML = 1;
        }
    }
}


/* This function takes the ID for the desired object and creates a DOM for       */
/* the particular browser being used. Then you can use the function to change    */
/* the object's style (if withStyle=1 or true) or to change other properties     */
/* associated with the object (if withStyle=0 or false).                         */
/* Example Usage:                                                                */
/*     Ex 1 - gives an anchor focus                                              */
/*         In the html file:                                                     */
/*             <a href="..." id="myAnchor">                                      */
/*         In the javascript function:                                           */
/*             var dom = findDOM("myAnchor", false);                             */
/*             dom.focus();                                                      */
/*     Ex 2 - change a CSS attribute (zIndex in this case)                       */
/*         In the html file:                                                     */
/*             <img id="image1">                                                 */
/*            var domStyle = findDOM("image1", true);                            */
/*            domStyle.zIndex = 100;                                             */
/*     Ex 3 - change a an object's CSS class                                     */
/*         In the html file:                                                     */
/*             <istrong id="errorMessage">                                       */
/*            var newClass = "important"                                         */
/*            var dom = findDOM("important", false);                             */
/*            dom.className = newClass;                                          */
function findDOM(objectID, withStyle)
{
    if (withStyle == 2 || withStyle == true)
    {
		if (isID)
        {
            return (document.getElementById(objectID).style);
        }
		else
        {
			if (isAll)
            {
                return (document.all[objectID].style);
            }
		    else
            {
			    if (isLayers)
                {
                    return (document.layers[objectID]);
                }
		    }
        }
	}
	else
    {
		if (isID)
        {
            return (document.getElementById(objectID));
        }
		else
        {
			if (isAll)
            {
                return (document.all[objectID]);
            }
    		else
            {
    			if (isLayers)
                {
                    return (document.layers[objectID]);
                }
    		}
        }
	}
}

/* This function is similar to the findDOM function, but will determine the DOM  */
/* of an object located in a different browser window (i.e. document). The       */
/* document object containing the desired object is passed in as an additional   */
/* parameter.  As a reminder, window objects have a document property that will  */
/* return a document object.                                                     */
/*                                                                               */
/* See the findDOM function for more information.                                */
/*                                                                               */
/* Example Usage:                                                                */
/*     Ex 1 - calling from a popup window to reference an object in the window   */
/*            that opened the popup                                              */
/*         In javascript called from the  popup window:                          */
/*             var dom = findDOM(opener.document, "myAnchor", false);            */
/*             dom.focus();                                                      */
/* See the findDOM function for more examples   .                                */
function findDOMinDocument(theDocument, objectID, withStyle)
{
    if (withStyle == 1 || withStyle == true)
    {
		if (isID)
        {
            return (theDocument.getElementById(objectID).style);
        }
		else
        {
			if (isAll)
            {
                return (theDocument.all[objectID].style);
            }
		    else
            {
			    if (isLayers)
                {
                    return (theDocument.layers[objectID]);
                }
		    }
        }
	}
	else
    {
		if (isID)
        {
            return (theDocument.getElementById(objectID));
        }
		else
        {
			if (isAll)
            {
                return (theDocument.all[objectID]);
            }
    		else
            {
    			if (isLayers)
                {
                    return (theDocument.layers[objectID]);
                }
    		}
        }
	}
}
