var elmnt;
var axxx;
var waitX = 5;
var timerrr;
var wheree;
var currenter;

function countTimerLog(where,starter){
	currenter = Cookie.read("timerr");

	if (!currenter) currenter = 0;

	if (where) {
		if (!wheree) wheree = $(where);

		if (starter) {
			timerrr = setInterval(function(){
				countTimerLog(where,false);
			},1000);
		}
		else {
			if (currenter > 2) {
				currenter--;
				Cookie.write("timerr",currenter,3600);

				window.title=currenter+" secos";

				var secs = currenter;
				secs %= 60;
				hrs = Math.floor(currenter / 3600);
				var mins = Math.floor((currenter-secs-3600*hrs)/60);
				var hrs = Math.floor((currenter-secs-60*mins)/3600);
				mins = (mins > 9) ? ":"+mins : ":0"+mins;
				secs = (secs > 9) ? ":"+secs : ":0"+secs;
				wheree.set('text','přihlášení vyprší za '+hrs+""+mins+secs);
			}
			else {
				$clear(timerrr);
				wheree.set('class','red').set('text','Budete odhlášeni z přihláškového systému! Uložte si své texty.').getNext().setStyle('display','none').getNext().setStyle('display','none');
			}
		}
	}
	else {
		Cookie.write("timerr",3600,3600);
		currenter = 11;
		$clear(timerrr);
	}
}

function hide(obj){obj=$(obj);if(!obj){return;}if (obj.style.display=='none'){if (obj.hasClass("hide")){obj.removeClass("hide");obj.style.display='';}else{obj.style.display='';obj.style.visibility="visible";}}else if(obj.hasClass('hide')){obj.removeClass('hide');if(obj.id=="k"||obj.id=="zprava"){document.getElementById('km').focus();}}else{obj.addClass('hide');}}
function buttonenabler(t){t=$(t);t.setProperty('disabled',!t.getProperty('disabled'));}
function check_mail(mail){re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;return mail.search(re) == 0;}

hideBig = function(){
	if (axxx) axxx.start({'opacity':[1,0],'left':[500,10]}).chain(function(){this.set({'display':'none'})});
}

window.addEvent('domready',function(){
	elmnt = $('mess');
	if (elmnt) {
		elmnt.setStyle('visibility','hidden');
	  waitX = elmnt.getProperty("rel").toInt();
		axxx = new Fx.Morph(elmnt,{
			duration: 500,
			transition: Fx.Transitions.Expo.easeInOut
		});
		axxx.set({'opacity':0}).start({'opacity':[0,1],'left':[10,500]}).chain(function(){hideBig.delay(1000*waitX);});
	}
	$$('a[target=_blank]','a[href^=http]').addClass('out_url').setProperty("target","_blank");
	if (window.ie && document.forms.length > 0) $$('input','textarea','select').addEvents({'focus':function(){this.addClass('focus')},'blur':function(){this.removeClass('focus');}});

	tableRows = $$('table.vypis tbody tr');
	if (tableRows) tableRows.each(function(el,i){el.addClass((i % 2) ? 'even' : 'odd').addEvents({'mouseover':function(){el.addClass('highlight');},'mouseout':function(){el.removeClass('highlight');}});});

//	if (window.ie6 && document.forms.length > 0) $$('fieldset').setStyles({float:'left',marginTop:1,marginRight:1,clear:'both'});
});

var chybejici = false;
var ucast = true;
function SubmitIt(f){
	chybejici = false;
	ucast = $('ucast-ano').getProperty('checked');
	if (ucast) {
		chybejici = $$('.req').some(function(item){
			if (item.get('value') == "") {
				inpP = item;
				return true;
			}
			return false;
		});
	}
	if (chybejici) {
		alert('Musíte vyplnit všechny položky označené jako povinné!');
		inpP.focus();
	}
	else f.submit();
}

function checkTextarea(opt){
	opt = $(opt);
	val = opt.getProperty('value');
	if (val == 'jiny' || val == 'zadny' || val == '') {
		$('warlarp_stripky_snu_text').setProperty('disabled',true).addClass('disabled');
		$('warlarp_stripky_snu_label').empty();
		$('warlarp_stripky_snu_label_txt').addClass("invis");
	}
	else {
		$('warlarp_stripky_snu_text').setProperty('disabled',false).removeClass('disabled');
		$('warlarp_stripky_snu_label').setText(opt.get('text')+":");
		$('warlarp_stripky_snu_label_txt').removeClass("invis");
	}
}

var frmSearch = false;

function checkLoginer(frm){
	var el,str;
	if (!frm) return;
	if (!frmSearch)
		frmSearch = $(frm);
	el = frmSearch.getElement('input');
	str = el.getProperty('value').clean();
	el.setProperty('value',str);
	if (str.length >= 3) {
		return true;
	}
	else {
		return false;
	}
}

var inpSearch = false,spanSearch = false,timerSearch = 0;

function checkInput(inp){
	var str;
	if (!inp) return;
	if (!inpSearch)
		inpSearch = $(inp);
	if (!spanSearch)
		spanSearch = inpSearch.getParent().getElement('span').addEvent('click',function(event){
			var el = $(event.target);
			if (el.get('tag') == 'em') {
				inp.setProperty('value',el.getProperty('text'));
			}
		});
	str = inpSearch.getProperty('value').clean();
	inpSearch.setProperty('value',str);

	if (timerSearch)
		$clear(timerSearch);

	if (str.length >= 3) {
		timerSearch = setTimeout('doSearch()',1000);
	}
	else {
		spanSearch.setProperty('text','Část přezdívky musí mít nejméně 3 znaky.');
	}
}

var oldSearch = "";

function doSearch(){
	var str;
	str = inpSearch.getProperty('value').clean();
	if (oldSearch != str) {
		spanSearch.setProperty('text','Loading...').load('?user-search=1&user-name='+encodeURIComponent(str));
	}
}
