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 jeEmail(value){
		reg_vyraz=/.+@.+/
		return reg_vyraz.test(value)
}

function zkontrolujEmail(email){

	if (spatnyEmail = document.getElementById("spatnyEmail")) {
		document.getElementById("bunkaEmail").removeChild(spatnyEmail);
	 }

if(!jeEmail(email.value)){ 
    spatnyEmail = document.createElement('span');
	  spatnyEmail.setAttribute("class","chyba");
	  spatnyEmail.setAttribute("className","chyba");
	  spatnyEmail.setAttribute("id","spatnyEmail");
	  spatnyEmail.appendChild(document.createTextNode("Vyplňte prosím správně"));
    document.getElementById("bunkaEmail").appendChild(spatnyEmail);
    return false;
 }
 return true;
}

function zkontrolujJmeno(jmeno){
 if (chybiJmeno = document.getElementById("chybiJmeno")) {
		document.getElementById("bunkaJmeno").removeChild(chybiJmeno);
	}
	
	 if ((jmeno.value.length==0) || jePrazdny(jmeno.value)){
   
    chybiJmeno = document.createElement('span');
	  chybiJmeno.setAttribute("class","chyba");
	  chybiJmeno.setAttribute("className","chyba");
	  chybiJmeno.setAttribute("id","chybiJmeno");
    chybiJmeno.appendChild(document.createTextNode("Vyplňte prosím"));
    document.getElementById("bunkaJmeno").appendChild(chybiJmeno);
    return false;
 }
 return true;
}

function zkontrolujKdo(kdo){
 if (chybiKdo = document.getElementById("chybiKdo")) {
		document.getElementById("bunkaKdo").removeChild(chybiKdo);
	 }
 if (kdo.value=="vyberte"){
  chybiKdo = document.createElement('span');
  chybiKdo.setAttribute("class","chyba");
  chybiKdo.setAttribute("className","chyba");
  chybiKdo.setAttribute("id","chybiKdo");
  chybiKdo.appendChild(document.createTextNode("Vyberte prosím"));
  document.getElementById("bunkaKdo").appendChild(chybiKdo);

  return false;
 }
 return true;
}

function provedKontrolu(formular) {
 var vPoradku = true;

 if (!zkontrolujJmeno(formular.jmeno)) { vPoradku = false; }
 if (!zkontrolujEmail(formular.email)) { vPoradku = false; } 
 if (!zkontrolujKdo(formular.kdo))     { vPoradku = false; }

 return vPoradku;
}

 
 function uprav(kdo){
      
      var zobrazitOddil = true;
      
      zkontrolujKdo(kdo);
          
      switch(kdo.options[kdo.selectedIndex].value){
      
      case "clen":
        textPopisekJmeno = "Jméno či přezdívka";
        textPopisekOddil = "Oddíl";
        
	     
        break;
      
      case "rodic":
        textPopisekJmeno = "Jméno či přezdívka dítěte";
        textPopisekOddil = "Oddíl dítěte";
      
        break;
      
      case "jiny":
        textPopisekJmeno = "Jméno či přezdívka";
        zobrazitOddil = false;
      
        break;
      default: 
        textPopisekJmeno = "Jméno či přezdívka (dítěte, pokud jsem rodič)";
        textPopisekOddil = "Oddíl (dítěte, pokud jsem rodič)";
      }
            
      if (popisek = document.getElementById("popisekJmeno")) {
          document.getElementById("bunkaPopisekJmeno").removeChild(popisek);
	     }
	     
	     popisek = document.createElement('label');
	     popisek.setAttribute("id","popisekJmeno");
	     popisek.setAttribute("for","jmeno");
	     popisek.appendChild(document.createTextNode(textPopisekJmeno));
       document.getElementById("bunkaPopisekJmeno").appendChild(popisek);
       
       if (zobrazitOddil==true) {
       
       for (var i=1;i<6;i++){
       document.getElementById("radekOddil"+i).setAttribute("class","viditelny");
       document.getElementById("radekOddil"+i).setAttribute("className","viditelny");
       }
       if (popisek = document.getElementById("popisekOddil")) {
          document.getElementById("bunkaPopisekOddil").removeChild(popisek);
	     }
       popisek = document.createElement('span');
	     popisek.setAttribute("id","popisekOddil");
	     popisek.appendChild(document.createTextNode(textPopisekOddil));
       document.getElementById("bunkaPopisekOddil").appendChild(popisek);
       
       
       }
       else
       {
       for (var i=1;i<6;i++){
        document.getElementById("radekOddil"+i).setAttribute("class","neviditelny");
        document.getElementById("radekOddil"+i).setAttribute("className","neviditelny");
       }
       }
      
 }
