/* Populate a select box with the options listed in a struct */
function populateSelect(selectBoxId, options) {
	var selectBox = document.getElementById(selectBoxId);

	var previouslySelected = new Array();

	/* Disabled - select box will now contain different things, */
	/*  so we shouldn't be setting selected                     */
	for (var i = 0; i < selectBox.options.length; i++) {
		if (selectBox.options[i].selected) {
			previouslySelected[selectBox.options[i].value] = true;
		}
	}

	/* remove existing items */
	while (selectBox.hasChildNodes()) {
		selectBox.removeChild(selectBox.firstChild);
	}

			/* Fun fixes for IE */
	/* We can't just remove the options, then add new ones, IE can't cope */
	/* So, instead, record the properties of the select box, remove it, */
	/*  add a new one, reset properties, then add the options */
	selectName = selectBox.name;
	selectID = selectBox.id;
	selectParent = selectBox.parentNode;
	selectClass = selectBox.className;
	selectOnchange = selectBox.onchange;
	selectMultiple = selectBox.multiple;
	
	selectParent.removeChild(selectBox);

	selectBox = document.createElement('select');
	selectBox.name = selectName;
	selectBox.id = selectID;
	selectBox.className = selectClass;
	selectBox.onchange = selectOnchange;
	selectBox.multiple = selectMultiple;
	if ( selectMultiple ) { selectBox.size = 4; }
	
	selectParent.appendChild(selectBox);

	/* add new items to the new select box */
	for (var i in options) {
		var newOption = document.createElement('option');
		newOption.value = i;
		if (previouslySelected[i]) newOption.selected = true;
		var optionText = document.createTextNode(options[i]);
		newOption.appendChild(optionText);
		selectBox.appendChild(newOption);
	}
}
