/* *******	MULTIPLE SELECT FUNCTIONS ******* */


/* *******	NEW ARRAY FUNCTIONS ******* */
/* this is a simple shortcut function:
	all it does is add a value to the end of an array */
Array.prototype.append = function (val) {
	this[this.length] = val;
}
/*
Exemplo HTML:
<form action="#" onsubmit="return false;">
	<fieldset class="radio-holder">
	<legend>Get the selected values of a multiple select box</legend>
		<p><label for="mySelect" 
			title="if you hold CTRL, you can make multiple selections">Choose a value</label></p>
		<select name="mySelect" id="mySelect" multiple="multiple" size="2">
			<option value="1">Value: 1 (Index 0)</option>
			<option value="2">Value: 2 (Index 1)</option>
			<option value="3">Value: 3 (Index 2)</option>
			<option value="4">Value: 4 (Index 3)</option>
			<option value="5">Value: 5 (Index 4)</option>
			<option value="6">Value: 6 (Index 5)</option>
			<option value="7">Value: 7 (Index 6)</option>
		</select>
		
		<p><button type="button" 
			onclick="alert(getSelect('mySelect'));">Selected Options</button>
		<button type="button" 
			onclick="alert(getSelectValue('mySelect'));">Selected Values</button></p>
	</fieldset>
</form>
*/

function getSelect(id) {
	/* use getElementById() instead of the getFormGroup */
	element = document.getElementById(id);
	/* create a temp array */
	selected = new Array();
	if (element)
	{
		for (i = 0; i < element.options.length; i++)
		{
			if (element.options[i].selected)
			{
				selected.append(element.options[i])
			}
		}
	}
	/* this could be an empty array */
	return selected;
}

function getSelectValue(id) {
	/* get all the selected options */

	options = getSelect(id);
	/* create a temporary array for return */
	values = new Array();
	if (options.length < 1) /* nenhuma opção selecionada */
	{
		values.append("Nenhum");
	}
	else
	{
		for (i = 0; i < options.length; i++)
		{
			if (options[i].value != "")
				values.append(options[i].value);
		}
	}
	/* this could be an empty array */
	
	//for each 'values' array element, concatenate a string of response
	if (values[0] != "")
		response = "- "+values[0];
	for (i = 1; i < values.length; i++)
		response = response + "\n\r- " + values[i];
	
	return response;
}

