// 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 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 isNum(passedVal) {
			if (passedVal == "") {
				return false
			}
			for (i=0; i < passedVal.length; i++) {
				if (passedVal.charAt(i) < "0") {
					return false
				}
				if (passedVal.charAt(i) > "9") {
					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



function manageNabVystBox() {

  if(document.souborForm.nabidka_vystoupeni.checked)  document.getElementById("nabVystBox").style.display = "block";
    else document.getElementById("nabVystBox").style.display = "none";
  

} // end formular



/*  funkce pro zobrazeni nabidky monitorovacich indikatoru fiche */

function manageFicheBoxes(ficheid) {

 for(i = 0; i < ficheBoxes.length; i++) {
 
   featured_box = document.getElementById("fb" + ficheBoxes[i]);
 
   if(ficheid == ficheBoxes[i]) featured_box.style.display = "block";
     else featured_box.style.display = "none";
 
 } // end for

} // end function


function checkZboziKat() {

  var chyba = "";
  var formular = document.souborForm;
  
    
    if(formular.nazev.value.trim() == "") chyba = chyba + "Vyplňte název projektu\n\n";
    if(formular.vyzva.value < 1) chyba = chyba + "Vyberte výzvu, ke které se projekt vztahuje\n\n";
    if(formular.obec.value < 1) chyba = chyba + "Vyberte místo realizace projektu\n\n";
    if(formular.osoba.value.trim() == "") chyba = chyba + "Vyplňte kontaktní osobu\n\n";
    if(formular.email.value.trim() == "") chyba = chyba + "Vyplňte e-mail\n\n";
      else  {    
        if(!validEmail(formular.email.value.trim())) chyba += "Uvedená e-mailová adresa není platná\n\n"; 
            else if(!bezdiakString(formular.email.value.trim()))  chyba += "Uvedená e-mailová adresa není platná (email nesmí obsahovat diakritiku)\n\n";    
    
      } // end email neni prazdny
  
    if(formular.popis.value.trim() == "") chyba = chyba + "Vyplňte stručný popis projektu\n\n";
 
    // kontrola logicke spravnosti dat
      // roky
     if(  (formular.ukonceni_rok.value > 0) && (formular.ukonceni_rok.value < formular.zacatek_rok.value) )  chyba = chyba + "Termín ukončení realizace nesmí být mení ne datum začátku realizace\n\n";
    
    // mesice
    else {
          mesic_od =   formular.zacatek_mesic.value - 0;
          mesic_do =   formular.ukonceni_mesic.value - 0;
    
          if( ( (formular.ukonceni_rok.value > 0) && (formular.ukonceni_rok.value == formular.zacatek_rok.value) )
          
                && 
          
              (mesic_do < mesic_od)
                 
            ) chyba = chyba + "Termín ukončení realizace nesmí být mení ne datum začátku realizace\n\n";
          
    }
     
    if( (formular.rozpocet.value.trim() !== "") && (!isNum(formular.rozpocet.value.trim())) ) chyba = chyba + "Částka rozpočtu musí být platné číslo\n\n";
    if( (formular.dotace.value.trim() !== "") && (!isNum(formular.dotace.value.trim())) ) chyba = chyba + "Částka dotace musí být platné číslo\n\n";
     
    
    if(formular.fiche.value < 1) chyba = chyba + "Vyberte fichi\n\n";
    
      else {
            idfiche = formular.fiche.value;
            indexboxu = idfiche - 1;
            
            if(ficheIndikatory[indexboxu].length > 0) {
            
                indValueError = 0;
                
               // projdu jednotlive indikatory a zkontroluji, za vyplnena hodnota je platne cislo
                 for(fi = 0; fi < ficheIndikatory[indexboxu].length; fi++) {
                 
                    featured_input = document.getElementById(ficheIndikatory[indexboxu][fi]);
 
                     if(featured_input.value.trim() !== "") {
                     
                     //   if(!isNum(featured_input.value.trim())) alert("Hodnota indikátoru musí být platné číslo");
                      
                      
                          // alert("Hodnota indikátoru: " + featured_input.value.trim());
                          
                          if(!isNum(featured_input.value.trim())) indValueError++;
                     
                     } // end input neni prazdny
                 
                 } // end for
            
                if(indValueError > 0) chyba = chyba + "Hodnota indkátoru musí být platné číslo\n\n";
            
            } // end jsou indikatory
            
            //  else alert("Fiche ID " + idfiche + ": nejsou indikatory");
      
      } // end else - fiche byla vybrana
    
    
    
    
  
  if(chyba !== "") {
                    alert(chyba);
                    return false;
  }
     else return true;
    

} // end function




function confirmSouborDel() {

  vymazat = window.confirm("Opravdu chcete odstranit tento projekt ?");

  if (vymazat) return true;
    else return false;
} // end function


function confirmAktualitaDel() {

  vymazat = window.confirm("Opravdu chcete odstranit tuto aktualitu ?");

  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




function checkAktualita() {

  var formular = document.aktForm;
  
  if(formular.aktualita.value.trim() == "") {
        
            alert("Vyplňte text aktuality");
            formular.aktualita.focus();
            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;
    } 

