// 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.prijmeni.value.trim() == "") chyba += "\n\nVyplňte příjmení";


  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 checkClanek() {

  tinyMCE.triggerSave();

  var chyba = "";
  var formular = document.clanekForm;
  
  
    if(formular.nazev.value.trim() == "") chyba = chyba + "Vyplňte nadpis článku.\n\n";
    if(formular.prispevek.value.trim() == "") chyba = chyba + "Vyplňte text článku.\n\n";
        
       
  if(chyba !== "") {
                    alert(chyba);
                    return false;
  }
     else return true;
    

} // end function




function confirmClanekDel() {

  vymazat = window.confirm("Opravdu chcete odstranit tento článek ?");

  if (vymazat) return true;
    else return false;
} // end function



function showDelInfo() {
    
         if(document.userForm.smazatFoto.checked) alert("Fotografie bude odstraněna po uloení nastavení");
        
} // end function



function checkFotoFormat(soubor)  {
    	
        	
    //	var soubor = document.formular.letak.value;
    	
    	var sekce = soubor.split(".");
    	
           delkapole = sekce.length;
           poslednisekce = delkapole - 1;
           pripona = sekce[poslednisekce];
     
           var pripony = new Array("jpg","JPG","jpeg","JPEG","gif","GIF","png","PNG");
           var povolena = 0;
           
           for(p = 0; p < pripony.length; p++) {
                         
                if(pripony[p] == pripona) {
                                            povolena = 1;
                                            break;
                }             
                             
           } // end for
           
           
           
          // otestuju, jestli pripona sedi (gif/jpg)
           if(povolena < 1) { // neni ok
                             
                              return false;
             }
             
               else return true;
             
    } // end function



function checkUserInfo() {

  var chyba = "";
  var formular = document.userForm;
  
  
    if(formular.jmeno.value.trim() == "") chyba = chyba + "Vyplňte jméno.\n\n";
    if(formular.prijmeni.value.trim() == "") chyba = chyba + "Vyplňte příjmení.\n\n";
   // if(formular.prispevek.value.trim() == "") chyba = chyba + "Vyplňte text článku.\n\n";
        
    
    if((formular.foto.value.trim() !== "") && !checkFotoFormat(formular.foto.value.trim())) chyba += "Vkládaný soubor nemá povolenou příponu: .jpg, .jpeg, .gif, .png";
     
       
  if(chyba !== "") {
                    alert(chyba);
                    return false;
  }
     else return true;
    

} // 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 checkKomentar() {

  var chyba = "";
  var formular = document.formular;
  
  
    if(formular.komjmeno.value.trim() == "") chyba = chyba + "Vyplňte své jméno.\n\n";
    if(formular.komkom.value.trim() == "") chyba = chyba + "Vyplňte text komentáře.\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;
    } 

