function rozbalit(id,element)
{
	var x = document.getElementById(id).style.display;
	if (x == 'block') {
		document.getElementById(id).style.display = 'none';
		element.setAttribute('class','sbaleno');
		element.setAttribute('title', 'rozbalit');
	}
	else {
		document.getElementById(id).style.display = 'block';
		element.setAttribute('class','rozbaleno');
		element.setAttribute('title', 'sbalit');
	}
	
	
}




function jeEmail(value){
		reg_vyraz=/^.+@.+\..{2,4}$/
		return reg_vyraz.test(value)
	}
	
function jeCena(value){
	reg_vyraz=/^\d{1,12}\.?\d{0,2}$/
	return reg_vyraz.test(value)
}
	
function jeHeslo(value){
	reg_vyraz=/^.{5,}$/
	return reg_vyraz.test(value)
}

function jePSC(value){
	reg_vyraz=/^[0-9 ]{3,9}$/
	return reg_vyraz.test(value)
}

function jeJmeno(value){
	reg_vyraz=/^[A-ZÁČĎÉĚÍŇÓŘÚŮÝÜÄËÖ][A-ZÁČĎÉĚÍŇÓŘÚŮÝÜÄËÖa-záčďéěíňóřúůýüäëö]*$/
	return reg_vyraz.test(value)
}
	

function jePrazdny(retezec)
{
	for(var i = 0; i < retezec.length; i++) {
		var znak = retezec.charAt(i);
		if ((znak != ' ') && (znak != '\n') && (znak != '\t')) return false;
	}
	return true;
}


function vytvorHlasku(text, id, postfix) {
	var hlaska = document.createElement('span');
	hlaska.setAttribute("class","error");
	hlaska.setAttribute("id", "hlaska_"+id+postfix);
	hlaska.setAttribute("title",text);
	var vykricnik = document.createTextNode("(!)");
	hlaska.appendChild(vykricnik);
	
	var info = document.createElement('span');
	var info_text = document.createTextNode(" - "+text);
	info.appendChild(info_text);
	
	hlaska.appendChild(info);
	
	return hlaska
}

function existujeHlaska(id,postfix) {
	return document.getElementById("hlaska_"+id+postfix);
}

function zrusHlasku(id,postfix) {
	if (existujeHlaska(id,postfix)!=null) {
	  document.getElementById("div_"+id).removeChild(document.getElementById("hlaska_"+id+postfix));
	}
}


	
function provedKontrolu(formular) {
	var kontrola = true;
	var chyby = "";
	
	for (var i = 0; i < formular.length; i++) {
		var elem = formular.elements[i];
		
		if (((elem.type == "text") || (elem.type == "textarea")) && elem.povinne) {
			if ((elem.value == null) || (elem.value == "") || jePrazdny(elem.value)) {
				kontrola = false;
				if (existujeHlaska(elem.id)==null)
				  document.getElementById("div_"+elem.id).appendChild(vytvorHlasku("pole musí být vyplněno ", elem.id));
			}
			else
				zrusHlasku(elem.id);
			
		}
		if (elem.email) {
			if (!jeEmail(elem.value)) {
				kontrola = false;
				if (existujeHlaska(elem.id,"e")==null)
					document.getElementById("div_"+elem.id).appendChild(vytvorHlasku("platný formát: (jmeno@domena.neco) ", elem.id, "e"));	
			}
			else
				zrusHlasku(elem.id,"e");
		}
		if (elem.cena) {
			if (!jeCena(elem.value)) {
				kontrola = false;
				chyby+="- pole \"cena\" musí mít správný formát (max pocet cislic: 123456789012.12)\n";
			}
		}
		if (elem.jmeno) {
			if (!jeJmeno(elem.value)) {
				kontrola = false;
				if (existujeHlaska(elem.id,"jm")==null)
				  document.getElementById("div_"+elem.id).appendChild(vytvorHlasku("jméno musí začínat velkým písmenem ", elem.id, "jm"));
			}
			else
				zrusHlasku(elem.id,"jm");
		}
		if (elem.psc) {
			if (!jePSC(elem.value)) {
				kontrola = false;
				if (existujeHlaska(elem.id,"psc")==null)
				  document.getElementById("div_"+elem.id).appendChild(vytvorHlasku("potovní směrovací číslo musí být pouze čísla ", elem.id, "psc"));
			}
			else
				zrusHlasku(elem.id,"psc");
		}
		 
	}
	if (!kontrola) alert('Ve formuláři jsou chyby...\nPro informaci o chybě najeďte myí nad vykřičník (!) !!!');
	return kontrola
}
