// rozsireni jquery o funkce
jQuery.fn.swapWith = function(to) {
    return this.each(function() {
        var copy_to = $(to).clone(true);
        var copy_from = $(this).clone(true);
        $(to).replaceWith(copy_from);
        $(this).replaceWith(copy_to);
    });
};

jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

function refresh(Seconds, ID, intLeft)
{
	var span = $('#'+ID);
	if (intLeft == undefined) intLeft = Seconds + 1; 
	
	if (Seconds == -1){
		span.html('0:00');
	} else {
		intLeft -= 1;
		var min = Math.floor(intLeft / 60);
		var sec = intLeft % 60;

		if (sec <= 9) sec = '0' + sec;

		if (intLeft == 0) span.html('teď');
		else span.html(min + ':' + sec);

		setTimeout("refresh(0, '"+ ID +"', "+ intLeft +")", 1000);

		if (intLeft == 0) location.href = location.href;
	}
}

// vyuziva stranka objednavka.php a view.php pro odeslani poznamky pomoci enteru
function check_pozn_enter(e, obj) {
	var evt = window.event ? event : e;
	if (evt.keyCode == 13) {
		document.getElementById(obj.name).focus();		
		return false; 
	} else return true;
}

/**
 * Overeni zmacknuti klavesy onter
 * @param e - event, udalost
 * @returns {Boolean}
 */
function isEnterPressed(e) {
	var evt = window.event ? event : e;
	if (evt.keyCode == 13) return true;
	else return false;
}

/**
 * Uklada poznamku pomoci ajaxu
 * 
 * @param int orderId - id objednavky
 * @param string noteName - nazev inputu
 */
function save_note(orderId, noteName) 
{
	var note = $("[name='"+ noteName +"\["+ orderId +"\]']").val();

	$('#field_' + noteName + orderId).hide();
	$('#anchor_' + noteName + orderId).show();
	$('#anchor_' + noteName + orderId).load(self.location.pathname, { order_id: orderId, ajaxSaveNote: noteName, note: note });
}

function alert_info(text)
{
	if (!text) text = 'Data budou vymazána, pokračovat?';

	if (confirm(text)) return true;
	else return false;
}


