﻿function changeSelectedOption(listboxid, value) {
	
	var listboxEl = document.getElementById(listboxid);
	
	if (listboxEl != null) {
		
		clearSelectedItems(listboxEl);
		
		for (var i=0; i < listboxEl.options.length; i++) {
		
			if (listboxEl.options[i].value == value) {
				listboxEl.options[i].selected = "selected";
				break;
			}
		}
	}
}

// creates an option in the passed listbox
function createOption(listbox, text, value, selected, cssClass, style)
{
	var option = document.createElement("option");
	
	// option.text = text;
	option.innerHTML = text;
	
	// option.value = value;
	option.setAttribute("value", value);
	
	// nothing before
	option.setAttribute("class", cssClass);
	
	// nothing before
	option.setAttribute("style", style);
	
	// nothing before
	if (selected) {
		option.setAttribute("selected", "selected");
	}
	
	// listbox.options.add(option);
	listbox.appendChild(option);
}

// Clears passed listbox
function clearlistbox(listboxEl) {
	for (var i=listboxEl.length-1; i>=0; i--){
		listboxEl.options[i] = null;
	}
	listboxEl.selectedIndex = -1;
}

function clearSelectedItems(listboxEl) {
	for (var i=0; i < listboxEl.options.length; i++){
		listboxEl.options[i].selected = "";
	}
}