// this works like getElementById(), except that it can handle multiple same ID values in the document,
// and it uses the property 'jsname'.

function getElementByJSName(jsname, parentObj)
{
	// if parentObj wasn't passed or is undefined, default it to the document
	parentObj = parentObj || document;

	// copy the children list into an array, for readability
	var children = parentObj.childNodes;

	// iterate over each child
	if (children && children.length)
	{
		for (var i=0, len=children.length; i<len; i++)
		{
			// short cut to our current child
			var child = children[i];

			// if we have a match, return it immediately
			if (child.getAttribute && child.getAttribute('jsname') == jsname) return child;

			// if there's no match, but this element has children, recurse into the element.
			// if that returns a match, return it immediately.  else, keep looping through our children.
			else if (child.childNodes && child.childNodes.length)
			{
				if (returnVal = getElementByJSName(jsname, child)) return returnVal;
			}

			// if there's no match and no children, keep looping through our siblings
		}
	}

	// if we get here, we're out of stuff to search through, and we haven't found anything.  return false.
	return false;
};

// this function works exactly like getElementsByJSName, except that it returns an array of results.
// the nestedCall parameter is for internal use only and should not be set.

function getElementsByJSName(jsname, parentObj, nestedCall)
{
	// if this is the original function call, clear the result stack
	if (nestedCall == undefined) _resultStack = Array();

	// if parentObj wasn't passed or is undefined, default it to the document
	parentObj = parentObj || document;

	// copy the children list into an array, for readability
	var children = parentObj.childNodes;

	// iterate over each child
	if (children && children.length)
	{
		for (var i=0, len=children.length; i<len; i++)
		{
			// short cut to our current child
			var child = children[i];

			// if we have a match, add it to our results array
			if (child.getAttribute && child.getAttribute('jsname') == jsname) _resultStack.push(child);

			// if there's no match, but this element has children, recurse into the element.
			// the nested calls to getElementsByJSName add results directly to the results array.
			else if (child.childNodes && child.childNodes.length) getElementsByJSName(jsname, child, true);

			// if there's no match and no children, keep looping through our siblings
		}
	}

	// if this is the original function call, return the result stack.  otherwise, return nothing
	if (nestedCall == undefined) return _resultStack;
};

// this global variables is needed to make getElementsByJSName work.
var _resultStack;
