// ÅÄÖ (to save it to utf8)

function update_select(select, innerHTML) {
	if(!Prototype.Browser.IE) {
		select.innerHTML = innerHTML;
		return;
	}
	
	$(select).update(innerHTML);
}

/*
 * Jimmy's note. Itterating Array with prototype is easy done with Prototype
 * Array.each, but in this application, each is really to slow to use, so here i
 * use regular for loop instaed.
 */

function fill_select(el, value, url, title) {

	update_select(el, "<option>Loading....</option>");

	el.disabled = true;

	// Run Ajax on timeout, to do this asyncronily.
	setTimeout(function() {
		new Ajax.Request(url + "?ver=3", {
			asynchronous : true,
			method : 'get',
			onComplete : function(reply) {
				var start = "<option value='0'>" + title + "</option>\n";

				// Enable list if we got any content.
				if (reply.responseText.length < 10) {
					update_select(el, start);
					return;
				}
			
				el.disabled = false;
				// Insert all options got
				update_select(el, start + reply.responseText);
	
				// Select first row default
				el.selectedIndex = 0;
	
				// Select right value
				for ( var i = 0; i < el.options.length; i++) {
					if (el.options[i].value == value) {					
						el.selectedIndex = i;
						break;
					}
				}
	
				// IF just one option, select it.
				if (el.options.length == 2)
					el.selectedIndex = 1;
	
				// Enable listbox.
				el.disabled = false;
			}
		});
	}, 10);
}