function de(id) { return document.getElementById(id);}
function schovukaz(id) {if (de(id).style.display == '' || de(id).style.display == 'block') {de(id).style.display = 'none'}else{de(id).style.display = 'block'}}
function ukaz(id) {de(id).style.display = 'block'}
function ukazinline(id) {de(id).style.display = 'inline'}
function schov(id) {de(id).style.display = 'none'}

// HOVER PODBARVENÍ ŘÁDKŮ TABULKY
var stripe = function(){$("table tr").hover(function(){$(this).addClass("thover");},function(){$(this).removeClass("thover");})}

// NL2BR
function nl2br(str){ return str.replace(/\r?\n/g,'<br>')};

// ZÁLOŽKY
function tabClickHandler(tab){i = -1;while (true){i++;objTab = eval(de("Tab_" + i));
if (objTab) {objTab.className = (i == tab) ? "activetab" : ((i > tab) ? "tab" : "tab"); de("Panel_" + i).style.display = (i == tab ? "block" : "none"); }else break;}}

// VYJÍŽDĚCÍ UPOZORNĚNÍ
function showInfoBar(caption){
$("#infoBar").remove();
$(document.body).append("<div id=\"infoBar\" style=\"cursor:hand;cursor:pointer;\"><center>" + caption + "</center></div>");
$("#infoBar").click(hideInfoBar);
$(".iBar").click(hideInfoBar);
$("#infoBar").hide();
$("#infoBar").css({"padding": "0px", "margin": "0px", "position": "absolute"});
$(window).resize(info_position);
$(window).scroll(info_position);
info_position();
$("#infoBar").slideDown(1000);

infoTime = setTimeout( function(){$("#infoBar").fadeOut('normal');}, 7000);
}

function hideInfoBar(){$("#infoBar").fadeOut('slow');setTimeout( function(){$("#infoBar").remove(); clearTimeout(infoTime);}, 2000);}

function info_position() {
var scrollPosition = $(window).scrollTop();
$("#infoBar").css("top",scrollPosition +"px");
$("#infoContent").css("height","45px");
$("#infoBar").css("left","0px");
$("#infoBar").css("width",$(window).width());
}


function cctitle(e,typ,hlaska,cudlik){
ukaz('mess');

if (typ=='0') {var submittyp='submit4';}
else if (typ=='1') {var submittyp='submit2';}
else if (typ=='2') {var submittyp='submit4';}
else if (typ=='3') {var submittyp='submit3';}


	if (cudlik=='alert') {
		var divAkce = '<div style="padding:20">';
		var akce = '</div>' + $('#messAlert').html();
		var leftVal = ($('body').outerWidth()/2) - 150 + 'px';
		var topVal = ($('body').outerHeight()/2) - 20 + 'px';
		var fontSize = '16px';
	}

	else if (cudlik=='confirm') {
		var divAkce = '<div style="padding:20">';
		var akce = '</div>' + $('#messConfirm').html();
		var leftVal = ($('body').outerWidth()/2) - 150 + 'px';
		var topVal = ($('body').outerHeight()/2) - 20 + 'px';
		var fontSize = '16px';
	}
	else{
		var divAkce = '';
		var akce = '';
		var leftVal = e.pageX + 'px';
		var topVal = e.pageY + 22 + 'px';
		var fontSize = '12px';
}

var typ = 'hlaska' + typ;


$('#mess').css({'left' : leftVal, 'top' : topVal, fontSize : fontSize});
$('#mess').html(divAkce + hlaska + akce);
$('#mess').removeClass();
$('#mess').addClass(typ);

if (akce !='') {



document.body.style.overflow = 'hidden';
ukaz('overlay');
$('#overlay').css({'display' : 'block', 'width' : $('body').outerWidth(), 'height' : $('body').outerHeight(), 'top': $('body').scrollTop(), 'left': $('body').scrollLeft()});

	if (cudlik=='alert') {
		$('#mAlertOK').removeClass();
		$('#mAlertOK').addClass(submittyp);
	}
	else if (cudlik=='confirm') {
		$('#mOK').removeClass();
		$('#mOK').addClass(submittyp);
	}
}

}


// SMART FOCUS
jQuery.fn.smartFocus = function(text) {$(this).val(text).focus(function(){if($(this).val() == text){$(this).val('');}}).blur(function(){if( $(this).val() == '' ){$(this).val(text);}});};

// vložení na pozici kurzoru
(function(){var c={getSelection:function(){var e=this.jquery?this[0]:this;return(('selectionStart'in e&&function(){var l=e.selectionEnd-e.selectionStart;return{start:e.selectionStart,end:e.selectionEnd,length:l,text:e.value.substr(e.selectionStart,l)}})||(document.selection&&function(){e.focus();var r=document.selection.createRange();if(r==null){return{start:0,end:e.value.length,length:0}}var a=e.createTextRange();var b=a.duplicate();a.moveToBookmark(r.getBookmark());b.setEndPoint('EndToStart',a);return{start:b.text.length,end:b.text.length+r.text.length,length:r.text.length,text:r.text}})||function(){return{start:0,end:e.value.length,length:0}})()},replaceSelection:function(){var e=this.jquery?this[0]:this;var a=arguments[0]||'';return(('selectionStart'in e&&function(){e.value=e.value.substr(0,e.selectionStart)+a+e.value.substr(e.selectionEnd,e.value.length);return this})||(document.selection&&function(){e.focus();document.selection.createRange().text=a;return this})||function(){e.value+=a;return this})()}};jQuery.each(c,function(i){jQuery.fn[i]=this})})();

// výběr označeného textu mimo textarea
function getSelText(){var txt = '';if (window.getSelection){txt = window.getSelection();}else if (document.getSelection){txt = document.getSelection();}else if (document.selection){txt = document.selection.createRange().text;} else return;return txt;}

// ODPOČÍTÁVÁNÍ ZNAKŮ VE FORMU / Text limiter for form fields
jQuery.fn.textlimit=function(counter_el,thelimit,speed){var charDelSpeed=speed||15;var toggleCharDel=speed!=-1;var toggleTrim=true;var that=this[0];updateCounter();function updateCounter(){jQuery(counter_el).text(thelimit-that.value.length)};this.keypress(function(e){if(this.value.length>=thelimit&&e.charCode!='0')e.preventDefault()}).keyup(function(e){updateCounter();if(this.value.length>=thelimit&&toggleTrim){if(toggleCharDel){that.value=that.value.substr(0,thelimit+100);var init=setInterval(function(){if(that.value.length<=thelimit){init=clearInterval(init);updateCounter()}else{that.value=that.value.substring(0,that.value.length-1);jQuery(counter_el).text('trimming...  '+(thelimit-that.value.length))}},charDelSpeed)}else this.value=that.value.substr(0,thelimit)}})};

jQuery.fn.countDown=function(settings,to){settings=jQuery.extend({startFontSize:'36px',endFontSize:'12px',duration:1000,startNumber:10,endNumber:0,callBack:function(){}},settings);return this.each(function(){if(!to&&to!=settings.endNumber){to=settings.startNumber}$(this).text(to).css('fontSize',settings.startFontSize);$(this).animate({'fontSize':settings.endFontSize},settings.duration,'',function(){if(to>settings.endNumber+1){$(this).css('fontSize',settings.startFontSize).text(to-1).countDown(settings,to-1)}else{settings.callBack(this)}})})};

// HVĚZDIČKOVÉ HODNOCENÍ OBSAHU
$.fn.rater=function(options){var opts=$.extend({},$.fn.rater.defaults,options);return this.each(function(){var $this=$(this);var $on=$this.find('.ui-rater-starsOn');var $off=$this.find('.ui-rater-starsOff');opts.size=$on.height();if(opts.rating==undefined)opts.rating=$on.width()/opts.size;if(opts.id==undefined)opts.id=$this.attr('id');$off.mousemove(function(e){var left=e.clientX-$off.offset().left;var width=$off.width()-($off.width()-left);width=Math.ceil(width/(opts.size/opts.step))*opts.size/opts.step;$on.width(width)}).hover(function(e){$on.addClass('ui-rater-starsHover')},function(e){$on.removeClass('ui-rater-starsHover');$on.width(opts.rating*opts.size)}).click(function(e){var r=Math.round($on.width()/$off.width()*(opts.units*opts.step))/opts.step;$off.unbind('click').unbind('mousemove').unbind('mouseenter').unbind('mouseleave');$off.css('cursor','default');$on.css('cursor','default');$.fn.rater.rate($this,opts,r)}).css('cursor','pointer');$on.css('cursor','pointer')})};$.fn.rater.defaults={postHref:location.href,units:5,step:1};$.fn.rater.rate=function($this,opts,rating){var $on=$this.find('.ui-rater-starsOn');var $off=$this.find('.ui-rater-starsOff');$.ajax({url:opts.postHref,type:"POST",data:'id='+opts.id+'&rating='+rating,complete:function(req){if(req.status==200){opts.rating=parseFloat(req.responseText);$on.removeClass('ui-rater-starsHover').width(opts.rating*opts.size);var $count=$this.find('.ui-rater-rateCount');$count.text(parseInt($count.text())+1);$this.find('.ui-rater-rating').text(opts.rating.toFixed(1));$this.attr('title',rating.toFixed(1))}else{alert(req.responseText);$on.removeClass('ui-rater-starsHover').width(opts.rating*opts.size);$this.rater(opts)}}})};

// HLASOVÁNÍ U PŘÍSPĚVKŮ
function vote(url,vcat,vid,hlas) {$.post(url,{cat: vcat, id: vid, v: hlas},function(data){schov('vt' + vid );$('#voted' + vid).text(data);});}