/* menici */
function Menici(IdObalu,HtmlPrvku){
	var x = document.getElementById(IdObalu).getElementsByTagName(HtmlPrvku);
	var l = x.length;
	var ted = 0;
	function Zmenit(){ 
		for(var i = 0; i < l; i++) x[i].style.display = (ted == i) ? "block" : "none";
		ted = (ted + 1) % l;
	}
	setInterval(Zmenit, 2500);
	Zmenit();
}

/* kolotoc */
function Kolotoc(idobalu){
	var r = document.getElementById(idobalu);
	setInterval(function() {r.appendChild(r.firstChild)}, 2000);
}


/* iframe */
function OpenIframe (IdOdkazu,VyskaIframe){
	var a = document.getElementById(IdOdkazu);
	var f = document.createElement("iframe");
	f.src = "about:blank";
	f.name = a.target;
	f.id = a.target;
	f.style.display = "none";
	f.scrolling = "no";
	f.allowTransparency = "true";
	f.frameBorder = "0";
	a.parentNode.insertBefore(f, a.nextSibling);
	a.onclick = function(){
		if(f.style.display != "none"){
			f.style.display = "none";
		} else {
			f.contentWindow.location.href = this.href;
		} return false;
	}
	f.nacetloSe = function(){
		f.style.height = "0";
		f.style.display = "block";
		for(var i = 1; i <= 10; i++){
			(function(i){
				setTimeout(function(){
					f.style.height = VyskaIframe * i / 10 + "px";
				}, i * 50)
			})(i);
		}
	}
}


/* prolinajici */
var poziceo = 0;
function Prolinani(IdObalu,HtmlPrvku){
	m = document.getElementById(IdObalu).getElementsByTagName(HtmlPrvku);
	setInterval(function() {
		poziceo += 1;
		poziceo %= 400;
		var d = poziceo % 100;
		if(d > 79)
		{
			var info = document.getElementById("pro-" + (Math.floor(poziceo / 100) + 1));
			var infon = document.getElementById("pro-" + ((Math.floor(poziceo / 100) + 1) % 4 + 1));
			if(d == 80)
			{
				setOpacity(infon, 1);
				infon.style.zIndex = 1;
				infon.style.display = "block";
				info.style.zIndex = 2;
			}
			setOpacity(info, (99 - d) / 20);
			if(d == 99)
			{
				info.style.display = "none";
				info.style.zIndex = 1;
			}
		}
	}, 50)
}

setOpacity = function(objekt, o){
	var defined = (typeof(o) != "undefined");
	if(typeof(objekt.filters) == "object"){
		if(defined || objekt.style.filter != ""){
			objekt.style.filter = (defined) ? "alpha(opacity=" + Math.floor(o * 100) + ")" : "";
		}
	} else if(typeof(objekt.style.MozOpacity) != "undefined") {
		objekt.style.MozOpacity = (defined) ? o : "";
	} else if(typeof(objekt.style.opacity) != "undefined"){
		objekt.style.opacity = (defined) ? o : "";
	}
};


/* formular */
function KontrolaFormulare(eform){ 
	x0 = eform.prijemce; 
	if(x0){
		if (x0.value=="info"){ 
			x0.parentNode.className = "bg-input warning"; 
			var s = document.getElementById("warning");
			s.style.display = "block";
			s.innerHTML = "Komu napíšete?";
			x0.parentNode.appendChild(s);
			x0.focus();
			return false; 
		} else {
			x0.parentNode.className = "bg-input";
		}
	}

	x1 = eform.odesilatel; 
	if(x1){
		if (!zkontroluj_kontakt(x1.value)){ 
			x1.parentNode.className = "bg-input warning"; 
			var s = document.getElementById("warning");
			s.style.display = "block";
			s.innerHTML = "Nesprávný formát kontaktu!";
			x1.parentNode.appendChild(s);
			x1.focus();
			return false; 
		} else {
			x1.parentNode.className = "bg-input";
		}
	}

	x2 = eform.subjekt; 
	if(x2){
		if (!vyplneno(x2.value)) { 
			x2.parentNode.className = "bg-input  warning"; 
			var s = document.getElementById("warning");
			s.style.display = "block";
			s.innerHTML = "Napište prosím předmět!";
			x2.parentNode.appendChild(s);
			x2.focus(); 
			return false; 
		} else {
			x2.parentNode.className = "bg-input";
		}
	}

	x3 = eform.zprava; 
	if(x3){
		if (!vyplneno(x3.value)){ 
			x3.parentNode.className = "bg-textarea warning2"; 
			var s = document.getElementById("warning");
			s.style.display = "block";
			s.innerHTML = "Co napíšete?";
			x3.parentNode.appendChild(s);
			x3.focus(); 
			return false; 
		} else {
			x3.parentNode.className = "bg-textarea";
		}
	}
} 
function zkontroluj_kontakt(adresa) {
    retezec = /^[^\.]+(\.[^\.]+)*@([^\.]+\.)+[^\.]{2,8}|\+?(\d\s*){9,}$/;
	/^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,3}$/;
    return adresa.search(retezec) == 0;
}
function vyplneno(text) { 
	return (text.length > 0); 
} 
