/** 
 * @fileoverview HTML Forms-related functionality for the JSPOOP library
 * @author James Palmer james@phoenixlondon.co.uk
 * @version 0.1 
 */

/**
 * Construct the Phoenix.DOM.Forms object.
 * @class Base class for HTML Forms-related functionality in the Phoenix library.
 * @constructor
 * @requires Phoenix.DOM
 */
Phoenix.DOM.Forms = function()
{
}


/**
 * Generate a select box from an array of values.  Optionally abbreviates the option text to save space (eg, "50000" => "50K").
 * 
 * @param {object} selectobj An HTML select box element to hold the new list of options
 * @param {Array} valuearray A javascript array of values (list of values or value-label pairs)
 * 
 * @return {Boolean} True
*/
Phoenix.DOM.Forms.buildSelectBoxFromArray = function (selectobj, valuearray)
{	// this == Phoenix.DNG.Controls.QuickSearch

	while(selectobj.options.length > 0)
			selectobj.remove(0);

	for(i=0; i<valuearray.length; i++)
	{
		newoption = document.createElement('option');
		
		if(valuearray[i][1] != undefined)	// If passed in value->label pairs, use them
		{
			newoption.value = valuearray[i][0];
			newoption.text = valuearray[i][1];
		}
		else																	// else, use the value for both
		{
			newoption.value = valuearray[i];
			newoption.text = valuearray[i];
		}
		
		try
		{
			selectobj.add(newoption, null); // standards compliant
		}
		catch(ex)
		{
			selectobj.add(newoption); // IE only
		}
	}
	
	return(true);
};