/* AJAX ERROR */
$(document).ajaxError(function (request,settings,e) {
    alert('Error requesting URL: '+e.url);
});
/* URL ROUTER */
var Router = function (route,params) {
    //parametre
    if (typeof(params) == 'object') {
        var p = '';
        $.each(params,function (name,value) {
            if (p != '') {
                p += '&';
            }
            p += escape(name)+'='+escape(value);
        });
        return Router(route)+'?'+p;
    }
    else {
        return '/' + route;
    }
};
Router.route = function (route,params) {
    var url = Router(route,params);
    location.href = url;
}

function openWindow(href) {
    window.open(href, "", "scrollbars=1,status=1,toolbar=1,width=800,height=600,resizable=1");
    return false;    
}

/* Plugin na input hint */
jQuery.fn.inputHint = function () {
    this.each(function () {
        var self = $(this);
        if (self.is('input[type=text]')) {
            jQuery.inputHintShow(self);
            self.focus(function () {
                jQuery.inputHintHide(this);
            }).blur(function () {
                jQuery.inputHintShow(this);
            }).closest('form').submit(function () {
                jQuery.inputHintHide(self);
                return true;
            });
        }
    });
    return this;
};
jQuery.inputHintShow = function (inpt) {
    inpt = jQuery(inpt);
    if (inpt.val() == inpt.attr('title') || inpt.val() == '') {
        inpt.addClass('hint').val(inpt.attr('title'));
    }
}
jQuery.inputHintHide = function (inpt) {
    inpt = jQuery(inpt);
    inpt.removeClass('hint');
    if (inpt.val() == inpt.attr('title')) {
        inpt.val('');
    }
}

$(function(){
	//hinty vo formularoch
	$('input.hint').inputHint();

});	

function ajaxOverlay(kill) {
    if (typeof kill == 'undefined') {
        kill = false;    
    }
    if (kill) {
        $('div.preloader').hide();
        $('div.ui-widget-overlay').remove();
        return true;
    }
    $('html, body').animate({scrollTop:0}, 0);
    $('div.ui-widget-overlay').remove();
    var overlay = $('<div />').addClass('ui-widget-overlay').css('z-index', 1001).css('height', Math.max($(document).height(), $(window).height()));
    var left = ($('.body').width() / 2) - 130;
    $('div.preloader').css('left', left + 'px');
    $('div.preloader').show();
    $('body').append(overlay);
}

jQuery(function($){
    if (typeof($.datepicker) != 'undefined') {    
        $.datepicker.regional['sk'] = {
            clearText: 'Zmazať', clearStatus: '',
            closeText: 'Zavrieť', closeStatus: '',
            prevText: '',  prevStatus: '',
            prevBigText: '', prevBigStatus: '',
            nextText: '', nextStatus: '',
            nextBigText: '', nextBigStatus: '',
            currentText: 'Dnes', currentStatus: '',
            monthNames: ['Január','Február','Marec','Apríl','Máj','Jún',
            'Júl','August','September','Október','November','December'],
            monthNamesShort: ['Jan','Feb','Mar','Apr','Máj','Jún',
            'Júl','Aug','Sep','Okt','Nov','Dec'],
            monthStatus: '', yearStatus: '',
            weekHeader: 'Ty', weekStatus: '',
            dayNames: ['Nedel\'a','Pondelok','Utorok','Streda','Štvrtok','Piatok','Sobota'],
            dayNamesShort: ['Ned','Pon','Uto','Str','Štv','Pia','Sob'],
            dayNamesMin: ['Ne','Po','Ut','St','Št','Pia','So'],
            dayStatus: 'DD', dateStatus: 'D, M d',
            dateFormat: 'dd.mm.yy', firstDay: 0, 
            initStatus: '', isRTL: false
        };
        $.datepicker.setDefaults($.datepicker.regional['sk']);
    }
});

