/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

//showhide koupit
function showhidekoupit(){
    var contact = document.getElementById("contact-area");
    var buttonk = document.getElementById("contact-button");

    if(contact){
        if(contact.style.display){
            contact.style.display = "";
            buttonk.style.display = "none";
        }else{
            contact.style.display = "none";
            buttonk.style.display = "";
        }
    }
}

function showhidekoupitstart(){
    var contact = document.getElementById("contact-area");
    var buttonk = document.getElementById("contact-button");

    if(contact){
        contact.style.display = "none";
        buttonk.style.display = "";
    }
}

//validace form
function formemail(theForm){
    if(theForm.mail){
                expirace=/^.+@.+\..{2,4}$/
                if(theForm.mail.value.length==0 || theForm.mail.value==" "){
                    alert('Musíte zadat kotaktní e-mail.');
                    focus();
                    return false;
                }
                if(expirace.test(theForm.mail.value)==false){
                    alert('Zadejte korektní e-mail.');
                    focus();
                    return false;
                }
       }

    if(theForm.subject){
            if(theForm.subject.value.length==0 || theForm.subject.value==" "){
                alert('Musíte vyplnit předmět požadavku.');
                focus();
                return false;
            }
     }

     if(theForm.message){
            if(theForm.message.value.length==0 || theForm.message.value==" "){
                alert('Musíte vyplnit požadavek.');
                focus();
                return false;
            }
     }

     return true;
}

function formobjednavka(theForm){
    if(theForm.jmeno){
            if(theForm.jmeno.value.length==0 || theForm.jmeno.value==" "){
                alert('Musíte vyplnit Jméno.');
                focus();
                return false;
            }
     }
    if(theForm.prijmeni){
            if(theForm.prijmeni.value.length==0 || theForm.prijmeni.value==" "){
                alert('Musíte vyplnit Příjmení.');
                focus();
                return false;
            }
     }
    if(theForm.mail){
                expirace=/^.+@.+\..{2,4}$/
                if(theForm.mail.value.length==0 || theForm.mail.value==" "){
                    alert('Musíte zadat kotaktní e-mail.');
                    focus();
                    return false;
                }
                if(expirace.test(theForm.mail.value)==false){
                    alert('Zadejte korektní e-mail.');
                    focus();
                    return false;
                }
       }

    if(theForm.ulice){
            if(theForm.ulice.value.length==0 || theForm.ulice.value==" "){
                alert('Musíte vyplnit Ulici a číslo popisné.');
                focus();
                return false;
            }
     }

     if(theForm.mesto){
            if(theForm.mesto.value.length==0 || theForm.mesto.value==" "){
                alert('Musíte vyplnit Město.');
                focus();
                return false;
            }
     }

     if(theForm.psc){
                expirace=/^[0-9]{5}$/
                if(theForm.psc.value.length==0 || theForm.psc.value==" "){
                    alert('Musíte zadat PSČ.');
                    focus();
                    return false;
                }
                if(expirace.test(theForm.psc.value)==false){
                    alert('PSČ musí obsahovat pouze 5 číslic.');
                    focus();
                    return false;
                }
       }

     return true;
}

//validace formulare pro zadani rezervace terminu
  function ValidateRezervacePublicForm(theForm){

      var termin = document.getElementById("termin");
      if(termin.innerHTML==""){
          alert("Nejdříve vyberte termín, který chcete rezervovat.")
          focus();
          return false;
      }

      if(theForm.jmeno){
            if(theForm.jmeno.value.length==0 || theForm.jmeno.value==" "){
                alert('Musíte vyplnit Jméno kontaktní osoby.');
                focus();
                return false;
            }
       }

       if(theForm.skola){
            if(theForm.skola.value.length==0 || theForm.skola.value==" "){
                alert('Musíte vyplnit název školy.');
                focus();
                return false;
            }
       }

       if(theForm.rocnik){
            if(theForm.rocnik.value.length==0 || theForm.rocnik.value==" "){
                alert('Musíte vyplnit ročník třídy, která se zúčastní.');
                focus();
                return false;
            }
       }

       if(theForm.pocet){
                expirace=/^[0-9]+$/
                if(theForm.pocet.value.length==0 || theForm.pocet.value==" "){
                    alert('Musíte zadat orientační počet účastníků.');
                    focus();
                    return false;
                }
                if(expirace.test(theForm.pocet.value)==false){
                    alert('Počet musí obsahovat pouze číslice.');
                    focus();
                    return false;
                }
       }

       if(theForm.telefon){
                expirace=/^[0-9]{9}$/
                if(theForm.telefon.value.length==0 || theForm.telefon.value==" "){
                    alert('Musíte zadat telefonní kontakt na pedagoga, který příjde s dětmi.');
                    focus();
                    return false;
                }
                if(expirace.test(theForm.telefon.value)==false){
                    alert('Telefon musí obsahovat 9 číslic.');
                    focus();
                    return false;
                }
       }

       if(theForm.email){
                expirace=/^.+@.+\..{2,4}$/
                if(theForm.email.value.length==0 || theForm.email.value==" "){
                    alert('Musíte zadat kotaktní e-mail, na který bude zaslán potvrzující e-mail.');
                    focus();
                    return false;
                }
                if(expirace.test(theForm.email.value)==false){
                    alert('Zadejte korektní e-mail.');
                    focus();
                    return false;
                }
       }

       if(theForm.kontrola){
                if(theForm.kontrola.value.length==0 || theForm.kontrola.value==" "){
                    alert('Opište kontrolní kód z obrázku.');
                    focus();
                    return false;
                }
       }

      return true;
  }

  //funkce pro vkladani rezervovaneho temrinu
  function setRezervedTerm(datum,dobaod,dobado,idterm){

      //vlozeni id do terminu
      var cislo=/^[1-9][0-9]*$/
      if(cislo.test(idterm)==true){
        document.getElementById("idtermin").value = idterm;
      }else{
          alert("Nesprávné vložení termínu!");
          focus();
          return;
      }

      //vlozeni terminu do vypisu
      var termin = document.getElementById("termin");
      termin.innerHTML = "<strong>"+datum+" "+dobaod+" - "+dobado+"</strong>";

      //schovani hlasky o nevlozeni terminu
      var termintext = document.getElementById("termintext");
      termintext.style.display='none';

      //nastaveni pozice
      var kotva = document.getElementById("formular");
      var xpos = kotva.offsetLeft;
      var ypos = kotva.offsetTop;
      var col = document.getElementById("col-l");
      window.scrollTo(xpos, ypos);
      col.scrollTop = ypos;
  }

 //funkce kontroly vyplneni formulare pro knihu
 function ValidateKnihaForm(theForm){
     if(theForm.koment){
            if(theForm.koment.value.length==0 || theForm.koment.value==" "){
                alert('Musíte vyplnit text příspěvku.');
                focus();
                return false;
            }
      }
     
     if(theForm.kontrola){
                if(theForm.kontrola.value.length==0 || theForm.kontrola.value==" "){
                    alert('Opište kontrolní kód z obrázku.');
                    focus();
                    return false;
                }
      }
 
     return true;
 }

 //funkce pro vkladani smailiku
 function putsmile(smile){
     var message = document.getElementById("koment");
     if(message){
         message.innerHTML = message.value + "*" + smile + "*";
     }
 }

 //funkce pro ovladani scriptu ajaxem
  function ajaxnahard(method,url,enddiv)
  {
     var httpRequest;

     if (url != 0)
     {
        if (window.XMLHttpRequest)
        { //používá Internet Explorer 7, Firefox, Opera, Safari
          httpRequest = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else
        {
          httpRequest = new XMLHttpRequest();
        }
        httpRequest.open(method, url, true);
        httpRequest.onreadystatechange= function () {processRequest(httpRequest,enddiv) } ;
        httpRequest.send(null);
      }
      else
      {

        document.getElementById(enddiv).innerHTML = "";

      }
  }

 function processRequest(httpRequest, kam)
 {
    if (httpRequest.readyState == 4)
    {
        if(httpRequest.status == 200)
        {
          document.getElementById(kam).innerHTML = httpRequest.responseText;
          //alert(httpRequest.responseText);
        }
        else
        {
            alert("Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText);
        }
    }
    else
    {
        if (typeof kam == 'string' && kam != '')
        {
            document.getElementById(kam).innerHTML = 'čekejte...';
        }
    }

  }


