function rikiTreeInit(id) {
	$( function() {
		menu = $('#' + id);
		/* nejdrive vse zavreme */
		menu.find('.top_parent, .parent').each( function() {
			$(this).next().addClass('close');
		});
		/* ted podle url otevreme, co sedi */
		p = window.location.pathname;
		if (p.length > 0) {
			menu.find('a').each( function() {
				url = $(this).attr('href').toLowerCase();
				//alert("url: "+url+", url strlen: "+url.length+", pathname: "+p+", pathname strlen: "+p.length);
				if (url == p) {
					$(this).parents().each( function() {$(this).removeClass('close');});
					$(this).next().removeClass('close');
			}
			});
		}
	});
}

function getPicker(id, lang) {
	$('document').ready( function() {
		$.datepicker.setDefaults($.extend( {
			showMonthAfterYear :false
		}, $.datepicker.regional['']));

		if (null == lang || undefined == lang)
			lang = 'en';

		$("#" + id).datepicker( {
			altField :'#' + id,
			altFormat :'yy-mm-dd'
		});
		$('#' + id).datepicker('option', $.extend( {
			showMonthAfterYear :false
		}, $.datepicker.regional[lang]));

	});
}

function createDiv(id, content, title) {
	if (undefined == content || null == content)
		content = '';
	if (undefined == title || null == title)
		title = '';

	div = $('<div id="' + id + '" title="' + title + '">' + content + '</div>')
	// add to document
			.appendTo('body');
}

function modalDialog(id, createDivId, content, contentIsFunct,
		replaceMainRowId, title) {
	// block ui
	setBlockOverlayId(id);

	if (createDivId == true && $("#" + id).length <= 0) {
		createDiv(id, '', title);
		$( function() {
			$("#" + id).dialog( {
				bgiframe :true,
				modal :true,
				autoOpen :false,
				minHeight :300,
				width :800,
				minWidth :800,
				close : function() {
					$(this).dialog('destroy');
					$("#" + id).remove();
				}
			});
		});
	}

	$("#" + id).dialog('open');

	if (contentIsFunct == true) {
		if (undefined != replaceMainRowId) {
			cont = Base64.decode(content);
			cont = cont.replace(/MAIN_ROW_ID/g, replaceMainRowId);
			eval(cont);
		} else {
			eval(Base64.decode(content));
		}
	} else {
		$("#" + id).text(content);
	}
}
function modalError(content, url) {
	if ($("#ErrorEvent").length <= 0) {
		createDiv('ErrorEvent');
	}
	$("#ErrorEvent").html(content);

	$( function() {
		$("#ErrorEvent").dialog( {
			bgiframe :true,
			modal :true,
			autoOpen :false,
			close : function() {
				if (undefined != url) {
					window.location = url;
				} else {
					url = new String(window.location);
					redirUrl = url.split('#');
					window.location = redirUrl[0];
				}
				$(this).dialog('destroy');
				$("#ErrorEvent").remove();
			},
			buttons : {
				Ok : function() {
					$(this).dialog('close');
				}
			}
		});
	});
	$('#ErrorEvent').dialog('open');

}

function modalMessage(id, createDivId, content, contentIsFunct, title) {
	if (createDivId == true && $("#" + id).length <= 0) {
		createDiv(id, '', title);
	}

	$( function() {
		$("#" + id).dialog( {
			bgiframe :true,
			modal :true,
			autoOpen :false,
			minHeight :300,
			width :600,
			close : function() {
				$(this).dialog('destroy');
				$("#" + id).remove();
			},
			buttons : {
				Ok : function() {
					$(this).dialog('close');
				}
			}
		});
		// $('.ui-dialog').block({ message: '<img
		// src="/imgs/icon/ajax-loader.gif" />' });
	});

	$("#" + id).dialog('open');
	setBlockOverlayId(id);

	if (contentIsFunct == true) {
		eval(Base64.decode(content));
	} else {
		$("#" + id).html(content);
	}
}

function modalDialogConfirm(id, createDivId, content, delFunct, title) {
	// block ui
	setBlockOverlayId(id);

	if (createDivId == true && $("#" + id).length <= 0) {
		createDiv(id, '', title);
		$( function() {
			$("#" + id).dialog( {
				bgiframe :true,
				resizable :false,
				height :140,
				modal :true,
				autoOpen :false,
				close : function() {
					$(this).dialog('destroy');
					$("#" + id).remove();
				},
				buttons : {
					'Delete' : function() {
						eval(Base64.decode(delFunct));
					},
					Cancel : function() {
						$(this).dialog('close');
					}
				}
			});
		});
	}

	$("#" + id).html(Base64.decode(content));
	$("#" + id).dialog('open');
}

function rightKontextMenu(id) {
	$( function() {
		// Show menu when #id is clicked
		$("#" + id).contextMenu( {
			menu :'myMenu' + id
		}, function(action, el, pos) {
			/*
			 * alert('Action: ' + action + '\n\n' + 'Element ID: ' +
			 * $(el).attr('id') + '\n\n' + 'X: ' + pos.x + ' Y: ' + pos.y + '
			 * (relative to element)\n\n' + 'X: ' + pos.docX + ' Y: ' + pos.docY + '
			 * (relative to document)');
			 */
		});
	});
}

function disableKontextMenuItem(id, disableIds) {
	$( function() {
		$('#myMenu' + id).disableContextMenuItems(disableIds);
	});

}