';
		if (data.args.length != 0) {
			form += '
'
		bootbox.dialog({
			title: "Command execution: " + command + ".",
			message: form,
			buttons: {
				cancel: {
					label: "Cancel",
					className: "btn-cancel"
				},
				success: {
					label: "Execute",
					className: "btn-success",
					callback: function () {
						if (command == "register") {
							var postdata = {};
							if ($("#command_arg0").val()) {
								postdata["jid"] = $("#command_arg0").val();
							}
							if ($("#command_arg1").val()) {
								postdata["uin"] = $("#command_arg1").val();
							}
							if ($("#command_arg2").val()) {
								postdata["password"] = $("#command_arg2").val();
							}
							$.post($.cookie("base_location") + "api/v1/instances/register/" + instance, postdata, function(data) {
								if (data.oauth2_url) {
									window.location.replace(data.oauth2_url);
								}
								else {
									var dialog = bootbox.dialog({
										title: "Command result: " + command + ".",
										message: "
" + data.message + "
",
										buttons: {
											success: {
												label: "OK",
												className: "btn-success",
												callback: function () {
													 location.reload(); 
												}
											}
										}
									})
									dialog.find("div.modal-dialog").addClass("largeWidth");
									dialog.find("div.modal-body").addClass("maxHeight");
								}
							});
						}
						else {
							if (command == "unregister") {
								var posturl = $.cookie("base_location") + "api/v1/instances/unregister/" + instance;
							}
							else {
								var posturl = $.cookie("base_location") + "api/v1/instances/execute/" + instance + "?command=" + command;
							}
							var postdata = {}
							for (i = 0; i < 10; i++) {
								var val = $('#command_arg' + i).val();
								if (val) {
									postdata["command_arg" + i] = val;
								}
							}
							$.post(posturl, postdata, function(data) {
								if (data.table) {
									data.message = "
";
									data.message += "";
									for (var key in data.table[0]) {
										if (data.table[0].hasOwnProperty(key)) {
											data.message += "| " + key + "";
										}
									}
									data.message += " | 
";
									$.each(data.table, function(i, line) {
										data.message += "";
										for (var key in line) {
											if (line.hasOwnProperty(key)) {
												data.message += "| " + line[key] + "";
											}
										}
										data.message += " | 
";
									})
									data.message += "
";
								}
								var dialog = bootbox.dialog({
									title: "Command result: " + command + ".",
									message: "
" + data.message + "
",
									buttons: {
										success: {
											label: "OK",
											className: "btn-success",
											callback: function () {
												if (command == "unregister") {
													location.reload(); 
												}
											}
										}
									}
								})
								dialog.find("div.modal-dialog").addClass("largeWidth");
								dialog.find("div.modal-body").addClass("maxHeight");
							});
						}
					}
				}
			}
		})
	});
}
function show_instance() {
	var query = getQueryParams(document.location.search);
	$("#main_content").html("
Instance: " + query.id + "
Available commands:
Available variables:
");
	$.get($.cookie("base_location") + "api/v1/instances/commands/" + query.id, function(data) {
		$.each(data.commands, function(i, command) {
			var row = '
'
			row += '| ' + command.label + '';
			row += ' | ' + command.category + '';
			row += ' | ' + command.desc + '';
			row += ' | 
';
			$("#commands  > tbody:last-child").append(row);
		});
		$(".button_command").click(function(e) {
			e.preventDefault();
			var command = $(this).attr('command');
			var instance = $(this).attr('instance');
			execute_command(instance, command);
		})
	});
	$.get($.cookie("base_location") + "api/v1/instances/variables/" + query.id, function(data) {
		$.each(data.variables, function(i, variable) {
			var row = '
'
			row += '| ' + variable.name + '';
			row += ' | ' + variable.value + '';
			row += ' | ' + variable.read_only + '';
			row += ' | ' + variable.desc + '';
			row += ' | 
';
			$("#variables  > tbody:last-child").append(row);
		});
	});
}