// Created By Christopher Docherty.
// Created on Thursday 24th April 2008.
// Last updated on Thursday 24th April 2008 by Christopher Docherty.
function SelectMenu(opts, name){
	// "opts" is a sort of 2D array that holds the option value and text.
	// value = opts[i][0]
	// text = opts[i][1]
	// Where i is the refference to the option in the array.
	// Get the options array.
	this.opts = opts;
	// Get the name of the select menu.
	this.name = name;
	// Define a local method called "setDefaultSelectedValue()".
	function setDefaultSelectedValue(val){
		// "val" is the varaible to test to see what option in the select menu should be selected (i.e. "val" should be EQUAL to the option value).
		// Set the "mySelect" variable to the parent object (i.e the select menu element).
		var mySelect = this;
		// Check to see if the "mySelect" element has a "type" property.
		if(mySelect.type){
			// Check to see if the "type" property is EQUAL to "select-one"
			if(mySelect.type == "select-one"){
				// Loop through each of the options in the "mySelect" element.
				for(i=0; i<mySelect.options.length; i++){
					// Check to see if the current option is equal the the varaible "val" (This is one of the parameters that were passed to the function).
					if(mySelect.options[i].value == val){
						// Select the current option.
						mySelect.options[i].selected = true;
					}
					else{
						// Do NOT Select the current option.
						mySelect.options[i].selected = false;
					}
					// End of IF Else statement.
				}
				// End of FOR Loop.	
			}
			// End of IF statement.
		}
		// End of IF statement.
	}
	// End of METHOD "setDefaultSelectedValue".
	
	// Create a new select element.
	var selectMenu = document.createElement("select");
	// Set the id and name attributes of the select menu.
	selectMenu.setAttribute("id", name);
	selectMenu.setAttribute("name", name);
	// Loop through each of the options in the "opts" array.
	for(i=0; i<opts.length; i++){
		// Create a new option element.
		var opt = document.createElement("option");
		// Set the value and title properties of the option.
		opt.value = opts[i][0];
		opt.setAttribute("title", opts[i][1]);
		// Append the text to the option.
		opt.appendChild(document.createTextNode(opts[i][1]));
		// Append the option to the select menu.
		selectMenu.appendChild(opt);
	}
	// End of FOR Loop.
	
	// Assign the function "setDefaultSelectedValue()" to the "selectMenu" as the "setOption" method.
	selectMenu.setOption = setDefaultSelectedValue;
	
	// Return the select menu.
	return selectMenu;
}
// End of CLASS "SelectMenu".