////////////////////////////////////////////////////////////////////////////////
function set_gallery_user_delete_image (image) {
  var el = document.getElementById("to_delete");
  if (!el) {return false;}
  el.value = image;
}
////////////////////////////////////////////////////////////////////////////////
function gallery (element) {
  var mi = document.getElementById("main_image");
  if (!mi) {return false;}
  if (element.alt) {
    mi.src = element.alt;
  }
}
////////////////////////////////////////////////////////////////////////////////
function load_articles (source) {
	var x;
	var selected;
	var elements = Array("articles_label", "articles_data");
	//if (source.value != show_article_handler_id) {
	//alert("options_count:"+source.options.length);
	for (var x=0;x<source.options.length;x++) {
		if (source.options[x].selected) {
			//alert(source.options[x].value);
			//alert(source.options[x].text);
			selected = source.options[x].text;
		}
	}
	if (selected != "Obsah-Zobraz") {
		for (x=0;x<elements.length;x++) {
			hide_(elements[x]);
		}
	}else{
		for (x=0;x<elements.length;x++) {
			show_(elements[x]);
}	}	}
////////////////////////////////////////////////////////////////////////////////
function workload (state, x, y) {
	x = x + 1;
	y = y + 3;
	var num = document.getElementById('workload_state');
	var num_str = Math.ceil(x)+' %';
	num.innerHTML = num_str;
	var el = document.getElementById('workload_state');
	el.style.backgroundPosition = y + 'px';
	if (x<state) {
		setTimeout('workload('+state+', '+x+', '+y+')', 0);
		//loading(x, y);
	}else{
		//el.innerHTML = "blahh";
	}
}
////////////////////////////////////////////////////////////////////////////////
function loading (x, y) {
	x=x+3;
	y=y+0.33;
	var num=document.getElementById('loading');
	var num_str='LOADING | '+Math.ceil(y)+'%';
	num.innerHTML=num_str;
	var el=document.getElementById('loading');
	el.style.backgroundPosition=x+'px';
	if (x<-50) {
		setTimeout('loading('+x+','+y+')', 0);
		//loading(x, y);
	}else{
		el.innerHTML = "Vítejte";
	}
}
////////////////////////////////////////////////////////////////////////////////
function structure_nodes (pid, source) {
	var subs = document.getElementById(source.id+"_nodes").getElementsByTagName("li");
	if (subs.length == 0) {
		post_to_element(
			"ajax/nodes", 
			"pid="+pid, 
			source.id+"_nodes"
		);
	}else{
		
		$(source.id+"_nodes").innerHTML = "";
	}
}
////////////////////////////////////////////////////////////////////////////////
function wts_calendar (source) {
	var source = $(source);
	if (!source) {return false;}
	var calendar = $(source.id+"_calendar");
	if (!calendar) {return false;}
	calendar.style.position = "absolute";
	switch (calendar.style.display) {
		case "none":
			calendar.style.display = "block";
		break;
		case "block":
			calendar.style.display = "none";
		break;
		default:
			alert("select default case err");
			calendar.style.display = "block";
		break;
	}
	calendar.style.zIndex = calendar.style.zIndex + 1;
	post_to_element(
		"ajax/calendar", 
		"type="+source.id, 
		source.id+"_calendar"
	);
	
}
////////////////////////////////////////////////////////////////////////////////
function wtselect (source) {
	var source = $(source);
	if (!source) {return false;}
	var options = $(source.id+"_options");
	if (!options) {return false;}
	options.style.position = "absolute";
	switch (options.style.display) {
		case "none":
			options.style.display = "block";
		break;
		case "block":
			options.style.display = "none";
		break;
		default:
			alert("select default case err");
			options.style.display = "block";
		break;
	}
	options.style.zIndex = options.style.zIndex + 1;
	post_to_element(
		"ajax/select", 
		"type="+source.id, 
		source.id+"_options"
	);
}
////////////////////////////////////////////////////////////////////////////////
function reload_wts_select (target, table, where, value, col_value, col_name, level) {
	//if (!where) {where = "empty";}
	//if (!value) {value = "empty";}
	if (!target || !table || !where || !value || !col_value || !col_name || !level) {
		alert("err782");
		return false;
	}
	//alert("reload :: "+);
	post_to_element(
		'ajax/load_wts_select_options', 
		'table='+table+'&where='+where+'&value='+value+"&col_value="+col_value+"&col_name="+col_name+"&level="+level, 
		target
	);
}
function load_wts_select_options (target) {
	post_to_element(
		'ajax/load_wts_select_options', 
		'table='+table+'&where='+where+'&value='+value, 
		target
	);
}
function load_param_id (source, subject) {
	var label = $("param_id_label");
	if (!label) {alert(1);return false;}
	if (!source.value || !subject.value) {alert("err");}
	//alert(source.value+"|"+subject.value)
	load_options("param_id", subject.value, "empty", "empty", subject.value+"_id", subject.value+"_name");
	var label = $("param_id_label");
	var data = $("param_id_value");
	if (!data || !label) {
		alert(1);
		return false;
	}
	//show table rows
	data.style.display = "block";
	label.style.display = "block";
}
function wts_select (source) {
	//@todo test in browsers
	var options = $(source.id+"_options");
	if (!options) {alert("err");return false;}
	options.style.position = "absolute";
	switch (options.style.display) {
		case "none":
			options.style.display = "block";
		break;
		case "block":
			options.style.display = "none";
		break;
	}
	options.style.zIndex = options.style.zIndex + 1;
}
function load_options (target_id, table, where, value) {
//function load_options (target_id, source, col_value, col_name) {
	//if (!target_id || !table || !source || !col_value || !col_name) {
	if (!target_id || !table || !where || !value) {
		alert("load_options err");
		return false;
	}
	//alert('table='+table+'&where='+source.id+'&value='+source.value+'&col_name='+col_name+'&col_value='+col_value);
	post_to_element(
		'ajax/load_options', 
		'table='+table+'&where='+where+'&value='+value, 
		target_id
	);
}
function add_to_input_value (id_input, value) {
	var el;
	if (!(el = document.getElementById(id_input))) {
		return false;
	}
	el.value = el.value + value;
}
function set_input_value (id_input, value) {
	var el;
	if (!(el = document.getElementById(id_input))) {
		return false;
	}
	el.value = value;
}
function move (url) {
	if (url == "top") {
		var location = document.location.toString();
		if (location.match(/top/)) {
			return false;
		}else{
			document.location = document.location + '#top';
		}
	}else{
		document.location = url;
	}
}