// act_select - select urceny k updatu
// id_val - index do pole
// insert_val - dvourozmerne pole polozek pro pridani do selectu (text, id)
// selected_val - index zvolene polozky
// valueCallback - nepovinne; volano pri vkladani do optionu
function change_select(act_select, id_val, insert_val, selected_val, valueCallback,
		extraOptIndex, extraOptText, extraOptValue) {
	while (act_select.options.length) {
		i = -1;
		while(act_select.options[++i]) {
			act_select.options[i] = null;
		}	
	}

	// prvni polozka selectu - popis vyberu
	act_select.options[0]= new Option(insert_val[0][0], insert_val[0][1]);
	
	// pokud neni vybrana zadna nadrazena polozka a maji se vypsat zakladni data
	if (selected_val == -1 && id_val == 0)
		id_val = 1;
 
	if (id_val > 0) {  	
		valuesCount = insert_val[id_val] ? insert_val[id_val].length : 0;
		targetIndex = 1;
		for (i=1; i<=valuesCount; i++){
			if (targetIndex == extraOptIndex) {
				if (valueCallback != null && valueCallback.length > 0) {
					extraOptText = eval(valueCallback + '(' + extraOptValue + ',\'' + extraOptText + '\')');
				}
				//alert (extraOptText + ', ' + extraOptValue);
				act_select.options[targetIndex]= new Option(extraOptText, extraOptValue);
				if (act_select.options[targetIndex].value == selected_val)
					act_select.options[targetIndex].selected = true;
				targetIndex++;
			}
			if (insert_val[id_val][i-1]) {
				jstxt = insert_val[id_val][i-1][0];
				id = insert_val[id_val][i-1][1];
				if (valueCallback != null && valueCallback.length > 0) {
					jstxt = eval(valueCallback + '(' + id + ',\'' + jstxt + '\')');
				}
				option = new Option(jstxt, id);
				act_select.options[targetIndex]= option;
				if (act_select.options[targetIndex].value == selected_val)
					act_select.options[targetIndex].selected = true;
				if (targetIndex % 2 != 0 && option.parentNode.className=="large space")
					option.style.backgroundColor = '#f4f4f4';
				targetIndex++;
			}
		}						
	}
	act_select.disabled = id_val <= 0;
	return true;
}

function change_select_add_first_option(insert_val, jstxt, id) {
	var arr=[];
	arr[0]=Array('',0); 
	arr[1] = new Array();
	arr[1][0] = Array(jstxt, id);
	insert_val[1] = arr[1].concat(insert_val[1]);
}
