/*
 * deprecated; use DOM instead.
 */
var DOMExtractor =
{
	buildElementGroups: function(inDocument,inGroupDefinitions,inPrefix,inSeparator,inDepth)
	{
		var theGroup;
		var theElement;
		var theIndex;

		if (inSeparator === undefined)
			inSeparator = ".";
		if (inPrefix === undefined)
			inPrefix = "";
		if (inDepth === undefined)
			inDepth = 0;
		theGroup = new Array();
		if (inGroupDefinitions[inDepth] !== null)
			theIndex = inGroupDefinitions[inDepth].startIndex;
		if (theIndex === undefined)
			theIndex = 1;

		for (;;)
		{
			if (inDepth === inGroupDefinitions.length - 1)
				theElement = inDocument.getElementById(inPrefix + theIndex);
			else
			{
				theElement = DOMExtractor.buildElementGroups(
					inDocument,
					inGroupDefinitions,
					inPrefix + theIndex + inSeparator,
					inSeparator,
					inDepth + 1);
			}

			if (theElement == null)
				break;

			theGroup[theGroup.length] = theElement;
			theIndex++;
		}

		if (theGroup.length == 0)
			return (null);

		if (inGroupDefinitions[inDepth] !== null && inGroupDefinitions[inDepth].extractor !== undefined)
			theGroup = inGroupDefinitions[inDepth].extractor(theGroup);

		return (theGroup);
	},


	extractArrayElement: function(inIndex,inFunction)
	{
		if (inFunction === undefined)
			return (function(inItem) { return (inItem[inIndex]); });
		else
			return (function(inItem) { return (inFunction(inItem[inIndex])); });
	},


	extractPropertiesFromAttributes: function(inPropertyNames,inDataSourceElementFunction,inGroupPropertyName,inChainFunction)
	{
		return (function(inItem)
		{
			var i;
			var theDataSourceElement;
			var theObject;

			theDataSourceElement = inDataSourceElementFunction(inItem);
			if (inGroupPropertyName === undefined)
				theObject = inItem;
			else
			{
				theObject = new Object();
				theObject[inGroupPropertyName] = inItem;
			}
			for (i = 0; i < inPropertyNames.length; i++)
				theObject[inPropertyNames[i]] = theDataSourceElement.getAttribute(inPropertyNames[i]);
			if (inChainFunction === undefined)
				return (theObject);
			else
				return (inChainFunction(theObject));
		});
	},


	extractPropertiesFromFormElements: function(inDocument,inIDs)
	{
		var i;
		var theResult;
		var theElement;

		// todo: eventually this should populate the result in exactly the same way as a submit, i.e. it should
		// handle radio buttons and check boxes in the same way.  It should also handle selects.
		theResult = new Properties();
		for (i = 0; i < inIDs.length; i++)
		{
			theElement = inDocument.getElementById(inIDs[i]);
			if (theElement === null)
				theResult.setProperty(inIDs[i],null);
			else
				theResult.setProperty(inIDs[i],theElement.value);
		}

		return (theResult);
	}
};
