gendawano = (function(ekibanja, erinya, endagarinya)
{
	var form = $('<form action="'+ekibanja+'.php" method="post">' + '<input type="hidden" name="'+erinya+'" value="'+endagarinya+'"></input>'+'</form>');
	$('body').append(form);
	$(form).submit();
});

gendawano2 = (function(ekibanja, erinya1, endagarinya1, erinya2, endagarinya2)
{
	var form = $('<form action="'+ekibanja+'.php" method="post">' + '<input type="hidden" name="'+erinya1+'" value="'+endagarinya1+'"></input><input type="hidden" name="'+erinya2+'" value="'+endagarinya2+'"></input>'+'</form>');
	$('body').append(form);
	$(form).submit();
});

/**
 * Vertically center Bootstrap 3 modals so they aren't always stuck at the top
 */
$(function() 
{
    function reposition() 
	{
        var modal = $(this),
            dialog = modal.find('.modal-dialog');
        modal.css('display', 'block');
        
        // Dividing by two centers the modal exactly, but dividing by three 
        // or four works better for larger screens.
        dialog.css("margin-top", Math.max(0, ($(window).height() - dialog.height()) / 2));
    }
    // Reposition when a modal is shown
    $('.modal').on('show.bs.modal', reposition);
    // Reposition when the window is resized
    $(window).on('resize', function() 
	{
        $('.modal:visible').each(reposition);
    });
});

$(document).on("show.bs.modal", ".modal", function(event) 
{
	$(this).appendTo($("body"));
}).on("shown.bs.modal", ".modal.in", function(event) 
{
	setModalsAndBackdropsOrder();
}).on("hidden.bs.modal", ".modal", function(event) 
{
	setModalsAndBackdropsOrder();
});

function setModalsAndBackdropsOrder() 
{  
	var modalZIndex = 1040;
	$(".modal.in").each(function(index) 
	{
		var $modal = $(this);
		modalZIndex++;
		$modal.css("zIndex", modalZIndex);
		$modal.next(".modal-backdrop.in").addClass("hidden").css("zIndex", modalZIndex - 1);
	});
	$(".modal.in:visible:last").focus().next(".modal-backdrop.in").removeClass("hidden");
}

$(document).ajaxSend(function(event, request, settings) 
{
	$("#waitdialogmodal").modal("show");
});

$(document).ajaxComplete(function(event, request, settings) 
{
	$("#waitdialogmodal").modal("hide");
});
