// rozklik formularovych prvku...
function toggleKatForm(plusAnchor, minusAnchor, targetBlok) {

 if(document.getElementById) {
  
           targetPlusAnchor  = document.getElementById(plusAnchor);
           targetMinusAnchor = document.getElementById(minusAnchor);
           targetBlokOpen    = document.getElementById(targetBlok);
      
           if(targetBlokOpen.style.display == "none")  {
                                                        targetBlokOpen.style.display    = "";
                                                        targetMinusAnchor.style.display = "";
                                                        targetPlusAnchor.style.display  = "none";
           }
             else {
                   targetBlokOpen.style.display    = "none";
                   targetMinusAnchor.style.display = "none";
                   targetPlusAnchor.style.display  = "";
             }
                                     
 } // end HW		     	

} // end function

 String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
   }

function checkSearchForm() {

  var formular = document.formular;

  if((formular.searchstring.value == "") || (formular.searchstring.value == "Zadejte hledaný výraz") || (formular.searchstring.value.length < 3)) {
           
           alert("Zadejte hledaný výraz (min. 3 znaky)");
           formular.searchstring.focus();
           return false;           
  }
  
     else return true;

} // end function



 function validEmail(email) {
			invalidChars = " /:,;"
	
			if (email == "") {
				return false
			}
			for (i=0; i < invalidChars.length; i++) {
				badChar = invalidChars.charAt(i)
				if (email.indexOf(badChar,0) > -1) {
					return false
				}
			}
			atPos = email.indexOf("@",1)
			if (atPos == -1) {
				return false
			}
			if (email.indexOf("@",atPos+1) > -1) {
				return false
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {
				return false
			}
			if (periodPos+3 > email.length)	{
				return false
			}
			return true
		}
		
function bezdiakString(string) {
		
			var sdiak = "áäčďéěíĺžňóôőöŕúůűüýřÁÄČĎÉĚÍĹźŇÓÔŐÖŔÚŮŰÜÝŘ";
	
		  var spravne = 1;  // 1 = bez diakritiky, 2 = s diakritikou
                                                                                                                                                         
      for(p = 0; p < string.length; p++) { // proverim, jestli v nazvu neni znak s diakritikou...
                                                   
                if(sdiak.indexOf(string.charAt(p)) != -1) {
                                                          spravne = 2;
                                                          break;
                }
                  else continue;                                                   
                                                   
      } // end for
      
      
      if(spravne > 1) return false;
      
        else return true;
      
		} // end function		
		
		
function checkRegistrace() {

  var formular = document.regForm;
  var chyba = "";

  if(formular.jmeno.value.trim() == "") chyba += "Vyplňte jméno";

  if(formular.email.value.trim() == "") chyba += "\n\nVyplňte emailovou adresu";
    else {
          if(!validEmail(formular.email.value.trim())) chyba += "Uvedená emailová adresa není platná"; 
            else if(!bezdiakString(formular.email.value.trim()))  chyba += "Uvedená emailová adresa není platná (email nesmí obsahovat diakritiku)";                                       
    }
 
 
 var vzor = /\w{3,15}/;
  var vzor_spatne = /\W/;
  
     var heslo = formular.heslo.value.trim();
  
   if(heslo == "") chyba += "\n\nVyplňte heslo";
    else {
          if( (heslo.length < 3) || (heslo.length > 15)) chyba += "\n\nHeslo musí mít 3 - 15 znaků bez diakritiky";
          else {
                if(heslo.search(vzor_spatne) > -1)  chyba += "\n\nHeslo musí mít 3 - 15 znaků bez diakritiky";
                else if(heslo.search(vzor) < 0)  chyba += "\n\nHeslo musí mít 3 - 15 znaků bez diakritiky";
          }
       // alert("Vzor: " + formular.login.value.search(vzor) + "\nVzor spatne: " + formular.login.value.search(vzor_spatne));                                           
    }
  
  var heslo2 = formular.heslo2.value.trim();
  
  if(heslo2 == "") chyba += "\n\nVyplňte heslo znovu";
    else {
          if(heslo2 !== "") {
          
            if(heslo !== heslo2) chyba += "\n\nHeslo a kontrolní heslo nesouhlasí";
          }
    }

  if(chyba !== "")  {
                     alert(chyba);
                     return false;
  }
  
     else return true;


} // end function



function checkLogin() {

  var formular = document.loginForm;
  var chyba = "";

  

 if(formular.uid.value.trim() == "") chyba += "Vyplňte emailovou adresu";
    else {
          if(!validEmail(formular.uid.value.trim())) chyba += "Uvedená emailová adresa není platná"; 
            else if(!bezdiakString(formular.uid.value.trim()))  chyba += "Uvedená emailová adresa není platná (email nesmí obsahovat diakritiku)";                                       
    }
 
  if(formular.heslo.value.trim() == "") chyba += "\n\nVyplňte heslo";

  if(chyba !== "")  {
                     alert(chyba);
                     return false;
  }
  
     else return true;


} // end function


function checkLostPass() {

  var formular = document.lostPassForm;
  var chyba = "";
  

 if(formular.email.value.trim() == "") chyba += "Vyplňte emailovou adresu";
    else {
          if(!validEmail(formular.email.value.trim())) chyba += "Uvedená emailová adresa není platná"; 
            else if(!bezdiakString(formular.email.value.trim()))  chyba += "Uvedená emailová adresa není platná (email nesmí obsahovat diakritiku)";                                       
    }
 

  if(chyba !== "")  {
                     alert(chyba);
                     formular.email.focus();
                     return false;
  }
  
     else return true;


} // end function


// funkce pro rozklik podkategorii
function manageKat(chId,katId,boxId) {

  if(document.getElementById) {
  
    if(document.getElementById(chId).checked) {
                                               document.getElementById(katId).style.fontWeight = "bold";
                                               document.getElementById(boxId).style.display = "block";
    }   
    
      else {
            document.getElementById(katId).style.fontWeight = "normal";
            document.getElementById(boxId).style.display = "none";
            
            
            // ================ odznaceni vsech podkategorii ====================
              // zjistim index kategorie
              for(i = 0; i < kategorie.length; i++) {
              
                if(kategorie[i] == chId) {
                                          for(pk = 0; pk < podkategorie[i].length; pk++) {
                                          
                                            document.getElementById(podkategorie[i][pk]).checked = false;
                                            
                                          
                                          } // end for
                                          break;
                } // end match
              
              } // end for - kategorie
            // ================ KONEC: odznaceni vsech podkategorii ====================
      }
  
  }

} // end function


// funkce pro ztucneni podkategorii
function managePodKat(chId,katId) {

  if(document.getElementById) {
  
    if(document.getElementById(chId).checked)  document.getElementById(katId).style.fontWeight = "bold";
               
      else document.getElementById(katId).style.fontWeight = "normal";
       
  }

} // end function


function manageNabVystBox() {

  if(document.souborForm.nabidka_vystoupeni.checked)  document.getElementById("nabVystBox").style.display = "block";
    else document.getElementById("nabVystBox").style.display = "none";
  

} // end formular


function checkZboziKat() {

  var chyba = "";
  var formular = document.souborForm;
  
  
  if(kategorie.length > 0) {
                            var numVybKat = 0;
                            
                            for(i = 0; i < kategorie.length; i++) {
                            
                                var inputName = kategorie[i];
                                                        
                              //  alert(inputName);
                                                           
                                if(document.getElementById(inputName).checked) {
                                
                                   numVybKat++;
                                   
                                   // proverim, zda je vybrana aspon 1 podkategorie
                                   
                                   var numVybPodKat = 0;
                                    
                                          for(pkk = 0; pkk < podkategorie[i].length; pkk++) {
                                    
                                             var inputPodName = podkategorie[i][pkk];
                                             
                                             if(document.getElementById(inputPodName).checked) {
                                             
                                               numVybPodKat++;
                                               
                                             }
                                          
                                          } // end for
                                          
                                          
                                  if(numVybPodKat < 1) chyba = chyba + "Vyberte jednu nebo více podkategorií v kategorii \"" + nazvyKat[i] + "\"\n\n";
                                   
                        
                                      
                                } // end checked
                                
                                /*
                                   else {
                                   
                                   
                                   } // end else - 
                            */
                            
                            } // end for
                            
                            if(numVybKat < 1) chyba = chyba + "Zařaďte produkt do jedné nebo více kategorií\n\n";
                            
  } // end kategorie OK
  
    else chyba = chyba + "Chyba při výběru kategorie\n\n";
  
  
    if(formular.nazev.value.trim() == "") chyba = chyba + "Vyplňte název uměleckého souboru\n\n";
    if(formular.obec.value < 1) chyba = chyba + "Vyberte obec, ve které má umělecký soubor základnu\n\n";
    if(formular.osoba.value.trim() == "") chyba = chyba + "Vyplňte kontaktní osobu\n\n";
    if(formular.telefon.value.trim() == "") chyba = chyba + "Vyplňte telefon\n\n";
    
    if(formular.email.value.trim() !== "") {
    
        if(!validEmail(formular.email.value.trim())) chyba += "Uvedená emailová adresa není platná\n\n"; 
            else if(!bezdiakString(formular.email.value.trim()))  chyba += "Uvedená emailová adresa není platná (email nesmí obsahovat diakritiku)\n\n";    
    
    } // end email neni prazdny
  
    if(formular.popis.value.trim() == "") chyba = chyba + "Vyplňte popis činnosti\n\n";
 
     
    if((formular.nabidka_vystoupeni) && (formular.nabidka_vystoupeni.checked)) {
     
        if(formular.vystoupeni.value.trim() == "") chyba = chyba + "Vyplňte název vystoupení\n\n";
        if(formular.delka.value < 1) chyba = chyba + "Vyplňte délku vystoupení\n\n";
        
        // cilova skupina
        
        var vybranaSkupina = 0;
        
        for(i = 0; i < ciloveSkupiny.length; i++) {
        
          if(document.getElementById(ciloveSkupiny[i]).checked) {
                                                                 vybranaSkupina++;
                                                                 break;
          }
        
        } // end for
     
         if(vybranaSkupina < 1) chyba = chyba + "Vyberte cílovou skupinu\n\n";
     
     
    } // end nabidka vystoupeni checked
  
  
  
  if(chyba !== "") {
                    alert(chyba);
                    return false;
  }
     else return true;
    

} // end function




function confirmSouborDel() {

  vymazat = window.confirm("Opravdu chcete odstranit tento záznam ?");

  if (vymazat) return true;
    else return false;
} // end function



function confirmVystDel() {

  vymazat = window.confirm("Opravdu chcete odstranit toto vystoupení ?");

  if (vymazat) return true;
    else return false;
} // end function



function manageDelFoto(fotoid) {

   var butonek = document.getElementById("butDelFoto_" + fotoid);
   
   if(butonek.checked == true) {
                                  // alert("now checked");
                                  document.getElementById("fotorow_" + fotoid).style.backgroundColor = "silver";
   }
     else {
           // alert("now NOT checked");
           document.getElementById("fotorow_" + fotoid).style.backgroundColor = "transparent";
     }
} // end function



function validateVystoupeni() {

  var chyba = "";
  var formular = document.vystForm;
  
        if(formular.vystoupeni.value.trim() == "") chyba = chyba + "Vyplňte název vystoupení\n\n";
        if(formular.delka.value < 1) chyba = chyba + "Vyplňte délku vystoupení\n\n";
        
        // cilova skupina
        
        var vybranaSkupina = 0;
        
        for(i = 0; i < ciloveSkupiny.length; i++) {
        
          if(document.getElementById(ciloveSkupiny[i]).checked) {
                                                                 vybranaSkupina++;
                                                                 break;
          }
        
        } // end for
     
         if(vybranaSkupina < 1) chyba = chyba + "Vyberte cílovou skupinu\n\n";
     
    
  
  
  
  if(chyba !== "") {
                    alert(chyba);
                    return false;
  }
     else return true;
    

} // end function


var poc = 0;


function showInfo2(imWidth,imHeight,winFile)   { 

      if (poc !== 0) iwin.close(); ; 
     
      url = winFile; 
      resStr = "resizable=0,scrollbars=0";

                                             // define window oversize
      winPlusWidth = 0;
      winPlusHeight = 0;
                                             // calculate window size
      winHeight = imHeight + winPlusHeight;
      winWidth = imWidth + winPlusWidth;
                                             // test if the window is not too large
		heightOK = true;
		
      if (winHeight>screen.availHeight)
        {
         winHeight = screen.availHeight-80;
      	 resStr=",resizable=1,scrollbars=1";
    	 heightOK = false;
      	}
      	
      if (heightOK==false)
        { 
         winWidth = winWidth+22;
      	}	
      								 
      if (winWidth>screen.width)
        { 
          winWidth = screen.width-80;
      	  resStr=",resizable=1,scrollbars=1";
      	}								 

                                                        // calculate centered window position
      winLeft = Math.round((screen.width-winWidth)/2);
      winTop  = Math.round((screen.availHeight-winHeight)/2);

      iwin = window.open(url, "", "left="+winLeft+",top="+winTop+",height="+winHeight+",width="+winWidth+",directories=no,location=no,menubar=no,status=no,toolbar=no,resizable=0,scrollbars=1");
      
      poc++;
      return true;
    } 

