// ###########################
// created by: Ben Weeks
// Created Date: 17th May 2006
// Company: webtechy.co.uk
//
// Modified By:
// Modified Date:
// Modified Comment:
//
// Version: 1.00
// ###########################

function sortSelect(selectBoxObj) {
	arr = new Array();

	// Store current options in an array.
	for(i = 0; i < selectBoxObj.length; i++) {
		arr[i] = new Array();
		arr[i][0] = selectBoxObj.options[i].text;
		arr[i][1] = selectBoxObj.options[i].value;
		arr[i][2] = selectBoxObj.options[i].selected;
	}

	// Sort the array
	arr.sort();
	selectBoxObj.length = 0;

	// Put the new order back in.
	for (j = 0; j < arr.length; j++) {
		// See http://www.devguru.com/Technologies/ecmascript/quickref/option.html
		selectBoxObj.options[j] = new Option(arr[j][0], arr[j][1], arr[j][2], arr[j][2]);
	}
}

function orderSelects() {
	try {
		// First, rename the "All" option to "- All -" so that it appears first in the list.
		renameAllOption(document.getElementById("CommitteeSelectSpan").firstChild);
		renameAllOption(document.getElementById("PartySelectSpan").firstChild);
		renameAllOption(document.getElementById("WardSelectSpan").firstChild);

		// Sort the options alphabetically.
		sortSelect(document.getElementById("CommitteeSelectSpan").firstChild);
		sortSelect(document.getElementById("PartySelectSpan").firstChild);
		sortSelect(document.getElementById("WardSelectSpan").firstChild);
	}
	catch(er) {
		// Unable to sort lists - don't raise an error as not critical.
	}
}

function renameAllOption(selectBoxObj) {
	if (selectBoxObj.options[0].text == "All") {
		selectBoxObj.options[0].text = "- All -";
	}
}

orderSelects();
