function confirmRemove(link) {
    $("#dialog-confirm").html($('<p>').text($(link).data("confirm").msg));
    $("#dialog-confirm").dialog({
	resizable: false,
	title: $(link).data("confirm").title,
	modal: true,
	buttons: [
	{
	    text: $(link).data("confirm").yes,
	    click: function() {
		$(this).dialog("destroy");
		window.location.href = $(link).attr("href");
	    }
	},
	{
	    text: $(link).data("confirm").no,
	    click: function() {
		$(this).dialog("destroy");
	    }
	}
	]
    });
    return false;
}

function selectUser(checkbox, user_id) {
    $("#skoleni").find("input").each(function () {
	var input_name = $(this).attr("name");
	if (input_name) {
	    if (input_name.startsWith('user')) {
		if (user_id == input_name.split("_")[1]) {
		    if ($(checkbox).attr('checked') == 'checked') {
			$(this).attr('checked', true);
		    }
		    else {
			$(this).attr('checked', false);
		    }
		}
	    }
	}
    });
}

function selectCourse(checkbox, course_id) {
    $("#skoleni").find("input").each(function () {
	var input_name = $(this).attr("name");
	if (input_name) {
	    if (input_name.startsWith('user')) {
		if (course_id == input_name.split("_")[3]) {
		    if ($(checkbox).attr('checked') == 'checked') {
			$(this).attr('checked', true);
		    }
		    else {
			$(this).attr('checked', false);
		    }
		}
	    }
	}
    });
}

if (typeof String.prototype.startsWith != 'function') {
    String.prototype.startsWith = function (str){
	return this.indexOf(str) == 0;
    };
}
