
function write_select_options() {
///alert("write_select_options: " + opts + opts.length);
	str = "";
	for (i=0; i<opts.length; i++) {
		str += "<option";
		if (i == opt_index) { str += " selected"; }
		str += ">";

		str += get_option_name(opts[i]);

		str += "</option>";
	}

	document.write(str);
}



function page_loaded() {
	msg("selector page_loaded");
	top.any_page_loaded(page_id);
}


function select_changed() {
	form = document.forms["navigation"];
	si = form.selector.options.selectedIndex;

	if (si != opt_index) { set_option(si); }
}


function set_option(p) {

	sync_buttons("on");
	opt_index = p;
	sync_buttons("off");

	sync_option();
	update_display();
}

function get_option() {
	// alert("get_option: id, opt_i: " + page_id + " " + opt_index)
	return(opts[opt_index]);
}


function sync_option() {
	form = document.forms["navigation"];
	si = form.selector.options.selectedIndex;
	if (si != opt_index) { form.selector.options[opt_index].selected = true; }
}


function previous_option() {
	if (opt_index > 0) set_option(opt_index - 1)
}

function next_option() {
	if (opt_index < opts.length - 1) set_option(opt_index + 1)
}


function update_display() { display_option(opts[opt_index]); }



function sync_buttons(state) {
	switch (opt_index) {
	case (0): set_button("prev", state); break;
	case (opts.length - 1): set_button("next", state); break;
	}
}

function set_button(btn, state) {
	document.images[btn].src = "../img/btns/" + btn + "_" + state + ".gif";
}
