/* Copyright 2010, Mark B. Rosenthal.  All rights reserved.  Mark
 * B. Rosenthal owns all right, title, and interest in this listing.
 * This listing is confidential and proprietary. Any unauthorized use,
 * reproduction, altering, distribution, or transmission of this
 * listing, or any part thereof, in any form or by any means,
 * electronic or mechanical, is strictly prohibited without a license
 * from Mark B. Rosenthal.
 */
/* Author: Mark B. Rosenthal <mbr@arlsoft.com>, Arlington Software Enterprises */

var CREATE_DOCUMENT=true;
var DEBUG_CREATE_DOCUMENT = false;

/*
 * Function: writeToDocument(s)
 * Description: At document creation time, insert this string into document
 * Argument:
 *	s	string to insert into document
 */
function writeToDocument(s)
{
    if (DEBUG_CREATE_DOCUMENT)
	debug(s, false);
    if (CREATE_DOCUMENT)
	document.writeln(s);
}

/*
 * Function: findElement(id)
 * Description: Return the element corresponding to the id argument,
 *		allowing for quirks of as many browsers as possible.
 * Argument:
 *	id	id of element to find
 * Return value:
 *	Element corresponding to id
 */
function findElement(id)
{
    var retval;
    if (document.getElementById)
	{
	    retval = document.getElementById(id);
	    // debug("document.getElementById(\"" + id + "\") = \"" + retval + "\"\n", false);
	    return retval;
	}
    else if (document.all && document.all(id))
	{
	    retval = document.all( id );
	    // debug("document.all(\"" + id + "\") = \"" + retval + "\"\n", false);
	    return retval;
	}
    else if (document.layers && document.layers[id])
	{
	    retval = document.layers[id];
	    // debug("document.layers(\"" + id + "\") = \"" + retval + "\"\n", false);
	    return retval;
	}
    else
	{
	    // debug("No way to look up \"" + id + "\n", false);
	    return false;
	}
}

/*
 * Function: findAllTagsOfType(tagname)
 * Description: Return array of elements corresponding of type tagname.
 * Argument:
 *	tagname	type of tag to find
 * Return value:
 *	Array of elements corresponding to tagname
 */
function findAllTagsOfType(tagname)
{
    var retval;
    if (tagname === undefined)
	tagname = "*";
    if (document.getElementsByTagName !== undefined)
	{
	    retval = document.getElementsByTagName(tagname);
	    //debug("document.getElementsByTagName(\"" + tagname + "\") = \"" + retval + "\"\n");
	    return retval;
	}
    else if (document.all !== undefined)
	{
	    retval = tagname == "*" ? document.all : document.all.tags(tagname);
	    //debug("document.all.tags(\"" + tagname + "\") = \"" + retval + "\"\n");
	    return retval;
	}
    else
	{
	    //debug("No way to look up \"" + tagname + " tags\n", false);
	    return new Array();
	}
}
