
function TestEmailu(adresa) {
  re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$/;
  return adresa.search(re) == 0;
}

function ZkontrolujEmail(adresa) {
  var pozice_zavinace = adresa.indexOf("@");
  if (pozice_zavinace < 0) return false;

  var cast_pred_zavinacem = adresa.substring(0,pozice_zavinace);
  var cast_po_zavinaci = adresa.substring(pozice_zavinace+1,adresa.length);

  if (cast_po_zavinaci.indexOf("@") >= 0) return false;
  if (cast_pred_zavinacem.length <= 0) return false;
  if (cast_po_zavinaci.length <= 0) return false;

  return true;
}


function KontrolaHledej() {
  if (document.fo_vyhledej.hledej_text.value != "" || document.fo_vyhledej.hledej_text.value != "hledaný výraz...") document.fo_vyhledej.submit();
  else alert("Nevyplnili jste pole s textem!");

}


function KontrolaNaemail() {
  if (document.fo_odeslat.uz_email.value != "") {
    document.fo_odeslat.uz_odeslatheslo.value = 1;
    document.fo_odeslat.submit();
  }
  else alert("Nevyplnili jste povinné údaje!");
}


function KontrolaPrihlaseni() {
  if (document.fo_prihlaseni1.uz_login.value != "" && document.fo_prihlaseni1.uz_heslo.value != "") document.fo_prihlaseni1.submit();
  else alert("Vyplňte prosím přihlašovací jméno a heslo!");
}


function KontrolaPrihlaseniPokladna() {
  if (document.fo_prihlaseni_pokladna.uz_login.value != "" && document.fo_prihlaseni_pokladna.uz_heslo.value != "") document.fo_prihlaseni_pokladna.submit();
  else alert("Vyplňte prosím přihlašovací jméno a heslo!");
}


function KontrolaPokladnaPrihlaseni() {
  if (document.fo_prihlaseni.uz_login.value != "" && document.fo_prihlaseni.uz_heslo.value != "") document.fo_prihlaseni.submit();
  else alert("Vyplňte prosím přihlašovací jméno a heslo!");
}


function KontrolaVelkoobchod() {
  if (document.fo_prihlaseni.uz_login.value != "" && document.fo_prihlaseni.uz_heslo.value != "") {
    document.fo_prihlaseni.submit();
  }
  else alert("Vyplňte prosím přihlašovací jméno a heslo!");
}


function OtevriObrazek(soubor) {
  okno = window.open("../obr_files/"+soubor, "Zobrazeni", "left=100, top=50, width=640, height=480, toolbar=no, statusbar=no, resizable=no, scrollbars=no");
  with (okno.document) {
    open();
    writeln("<html>\n<head><title>Detail obrázku: " +soubor+ "</title></head>");
    writeln("<body style='margin: 0; padding: 0' onLoad='pre()'>");
    writeln("<scri"+"pt language='javascript'>function pre() \n{\n imgwidth=obr.width;\n imgheight=obr.height;\n window.resizeTo(imgwidth+10, imgheight+30)\n }\n</sc"+"ript>")
    writeln("<img src='../obr_files/" +soubor+ ".jpg' border=0 onClick='window.close()' id=obr alt='kliknutím zavřete okno'>");
    writeln("");
    close();
  }
  return false;
}


function Zobraz(cislo) {
  if (cislo == 3) {
    document.getElementById('tab-osoba').className = 'videt';
    document.getElementById('tab-firma').className = 'nevidet';

    document.getElementById('zakaznik_osoba').checked = true;
    document.getElementById('zakaznik_firma').checked = false;
  }
  else {
    document.getElementById('tab-firma').className = 'videt';
    document.getElementById('tab-osoba').className = 'nevidet';

    document.getElementById('zakaznik_osoba').checked = false;
    document.getElementById('zakaznik_firma').checked = true;
  }
}


function RegKontrolaOsoba() {
  text="";
  var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

  if (document.fo_reg_osoba.os_heslo.value != document.fo_reg_osoba.os_heslo2.value) alert("Hesla neodpovídají!");
  else {
    if (!TestEmailu(document.fo_reg_osoba.os_email.value) || !ZkontrolujEmail(document.fo_reg_osoba.os_email.value) || (document.fo_reg_osoba.os_email.value.search(emailRegEx) == -1)) {
      alert("Zadaná emailová adresa není ve správném formátu!!");
      document.fo_reg_osoba.os_email.focus();
    }
    else {
      if (document.fo_reg_osoba.os_heslo.value == '') text += "heslo, ";
      if (document.fo_reg_osoba.os_heslo2.value == '') text += "heslo - potvrzení, ";
      if (document.fo_reg_osoba.os_jmeno.value == '') text += "jméno, ";
      if (document.fo_reg_osoba.os_prijmeni.value == '') text += "příjmení, ";
      if (document.fo_reg_osoba.os_ulice.value == '') text += "ulice, ";
      if (document.fo_reg_osoba.os_mesto.value == '') text += "město, ";
      if (document.fo_reg_osoba.os_psc.value  =='') text += "psč, ";
      if (document.fo_reg_osoba.os_telefon.value=='') text += "telefon.";

      if (text=="") document.fo_reg_osoba.submit();
      else {
        alert("Vložte prosím údaje:\n"+text);
      }
    }
  }

  return false;
}


function KontrolaPokladnaRegOsoba() {
  text="";
  var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

  if (document.fo_reg_osoba.os_heslo.value != document.fo_reg_osoba.os_heslo2.value) alert("Hesla neodpovídají!");
  else {
    if (!TestEmailu(document.fo_reg_osoba.os_email.value) || !ZkontrolujEmail(document.fo_reg_osoba.os_email.value) || (document.fo_reg_osoba.os_email.value.search(emailRegEx) == -1)) {
      alert("Zadaná emailová adresa není ve správném formátu!!");
      document.fo_reg_osoba.os_email.focus();
    }
    else {
      if (document.fo_reg_osoba.os_email.value == '') text += "email, ";
      if (document.fo_reg_osoba.os_heslo.value == '') text += "heslo, ";
      if (document.fo_reg_osoba.os_heslo2.value == '') text += "heslo - potvrzení, ";
      if (document.fo_reg_osoba.os_jmeno.value == '') text += "jméno, ";
      if (document.fo_reg_osoba.os_prijmeni.value == '') text += "příjmení, ";
      if (document.fo_reg_osoba.os_ulice.value == '') text += "ulice, ";
      if (document.fo_reg_osoba.os_mesto.value == '') text += "město, ";
      if (document.fo_reg_osoba.os_psc.value  =='') text += "psč, ";
      if (document.fo_reg_osoba.os_telefon.value=='') text += "telefon.";

      if (text=="") document.fo_reg_osoba.submit();
      else {
        alert("Vložte prosím údaje:\n"+text);
      }
    }
  }

  return false;
}



function RegKontrolaFirma() {
  text = "";
  var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

  if (document.fo_reg_firma.fi_heslo.value != document.fo_reg_firma.fi_heslo2.value) alert("Hesla neodpovídají!");
  else {
    if (!TestEmailu(document.fo_reg_firma.fi_email.value) || !ZkontrolujEmail(document.fo_reg_firma.fi_email.value) || (document.fo_reg_firma.fi_email.value.search(emailRegEx) == -1)) {
      alert("Zadaná emailová adresa není ve správném formátu!!");
      document.fo_reg_firma.fi_email.focus();
    }
    else {
      if (document.fo_reg_firma.fi_heslo.value == '') text += "heslo, ";
      if (document.fo_reg_firma.fi_heslo2.value == '') text += "heslo - potvrzení, ";
      if (document.fo_reg_firma.fi_jmeno.value == '') text += "jméno, ";
      if (document.fo_reg_firma.fi_prijmeni.value == '') text += "příjmení, ";
      if (document.fo_reg_firma.fi_ulice.value == '') text += "ulice, ";
      if (document.fo_reg_firma.fi_mesto.value == '') text += "město, ";
      if (document.fo_reg_firma.fi_psc.value  =='') text += "psč, ";
      if (document.fo_reg_firma.fi_telefon.value=='') text += "telefon, ";
      if (document.fo_reg_firma.fi_firma.value == '') text += "město, ";
      if (document.fo_reg_firma.fi_ico.value == '') text += "IČ, ";
      if (document.fo_reg_firma.fi_dic.value == '') text += "DIČ.";

      if (text=="") document.fo_reg_firma.submit();
      else {
        alert("Vložte prosím údaje:\n"+text);
      }
    }
  }

  return false;
}


function KontrolaPokladnaRegFirma() {
  text = "";
  var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

  if (document.fo_reg_firma.fi_heslo.value != document.fo_reg_firma.fi_heslo2.value) alert("Hesla neodpovídají!");
  else {
    if (!TestEmailu(document.fo_reg_firma.fi_email.value) || !ZkontrolujEmail(document.fo_reg_firma.fi_email.value) || (document.fo_reg_firma.fi_email.value.search(emailRegEx) == -1)) {
      alert("Zadaná emailová adresa není ve správném formátu!!");
      document.fo_reg_firma.fi_email.focus();
    }
    else {
      if (document.fo_reg_firma.fi_email.value == '') text += "email, ";
      if (document.fo_reg_firma.fi_heslo.value == '') text += "heslo, ";
      if (document.fo_reg_firma.fi_heslo2.value == '') text += "heslo - potvrzení, ";
      if (document.fo_reg_firma.fi_jmeno.value == '') text += "jméno, ";
      if (document.fo_reg_firma.fi_prijmeni.value == '') text += "příjmení, ";
      if (document.fo_reg_firma.fi_ulice.value == '') text += "ulice, ";
      if (document.fo_reg_firma.fi_mesto.value == '') text += "město, ";
      if (document.fo_reg_firma.fi_psc.value  =='') text += "psč, ";
      if (document.fo_reg_firma.fi_telefon.value=='') text += "telefon, ";
      if (document.fo_reg_firma.fi_firma.value == '') text += "město, ";
      if (document.fo_reg_firma.fi_ico.value == '') text += "IČ, ";
      if (document.fo_reg_firma.fi_dic.value == '') text += "DIČ.";

      if (text=="") document.fo_reg_firma.submit();
      else {
        alert("Vložte prosím údaje:\n"+text);
      }
    }
  }

  return false;
}


function OtevriTisk(obrazek) {
 window.open(obrazek, "zoom", "left=150, top=90, width=400, height=400, toolbar=no, statusbar=no, resizable=yes, scrollbars=yes");
}


function KontrolaMujucetOsoba() {
  chyba = "";
  var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

  if (document.fo_osoba.uz_heslo.value != document.fo_osoba.uz_heslo2.value) alert("Heslo se neshodují!");
  else {
    if (!TestEmailu(document.fo_osoba.uz_email.value) || !ZkontrolujEmail(document.fo_osoba.uz_email.value) || (document.fo_osoba.uz_email.value.search(emailRegEx) == -1)) {
      alert("Zadaná emailová adresa není ve správném formátu!!");
      document.fo_osoba.uz_email.focus();
    }
    else {
      if (document.fo_osoba.uz_jmeno.value == "") chyba += "jméno, ";
      if (document.fo_osoba.uz_prijmeni.value == "") chyba += "příjmení, ";
      if (document.fo_osoba.uz_ulice.value == "") chyba += "ulice, ";
      if (document.fo_osoba.uz_mesto.value == "") chyba += "město, ";
      if (document.fo_osoba.uz_psc.value == "") chyba += "PSČ, ";
      if (document.fo_osoba.uz_stat.value == "") chyba += "stát, ";
      if (document.fo_osoba.uz_email.value == "") chyba += "email, ";
      if (document.fo_osoba.uz_telefon.value == "") chyba += "telefon.";

      if (chyba != "") {
        alert("Vložte prosím následující údaje: "+chyba);
        return false;
      }
      else document.fo_osoba.submit();
    }
  }
}


function KontrolaMujucetFirma() {
  chyba = "";
  var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

  if (document.fo_firma.uz_heslo.value != document.fo_firma.uz_heslo2.value) alert("Heslo se neshodují!");
  else {
    if (!TestEmailu(document.fo_firma.uz_email.value) || !ZkontrolujEmail(document.fo_firma.uz_email.value) || (document.fo_firma.uz_email.value.search(emailRegEx) == -1)) {
      alert("Zadaná emailová adresa není ve správném formátu!!");
      document.fo_firma.uz_email.focus();
    }
    else {
      if (document.fo_firma.uz_jmeno.value == "") chyba += "jméno, ";
      if (document.fo_firma.uz_prijmeni.value == "") chyba += "příjmení, ";
      if (document.fo_firma.uz_ulice.value == "") chyba += "ulice, ";
      if (document.fo_firma.uz_mesto.value == "") chyba += "město, ";
      if (document.fo_firma.uz_psc.value == "") chyba += "PSČ, ";
      if (document.fo_firma.uz_stat.value == "") chyba += "stát, ";
      if (document.fo_firma.uz_email.value == "") chyba += "email, ";
      if (document.fo_firma.uz_firma.value == "") chyba += "firma, ";
      if (document.fo_firma.uz_ico.value == "") chyba += "IČ, ";
      if (document.fo_firma.uz_dic.value == "") chyba += "DIČ, ";
      if (document.fo_firma.uz_telefon.value == "") chyba += "telefon.";

      if (chyba != "") {
        alert("Vložte prosím následující údaje: "+chyba);
        return false;
      }
      else document.fo_firma.submit();
    }
  }
}


function KontrolaFaktury() {
  chyba = "";

  if (document.fakturace.uz_do_jmeno.value == "") chyba += "jméno, ";
  if (document.fakturace.uz_do_ulice.value == "") chyba += "ulice, ";
  if (document.fakturace.uz_do_mesto.value == "") chyba += "město, ";
  if (document.fakturace.uz_do_psc.value == "") chyba += "PSČ, ";
  if (document.fakturace.uz_do_telefon.value == "") chyba += "telefon.";

  if (chyba != "") {
    alert("Vložte prosím následující údaje: "+chyba);
    return false;
  }
  else document.fakturace.submit();
}



function ZobrazDodaci() {
  if (document.getElementById('dodaciadresa').className == "nevidet") document.getElementById('dodaciadresa').className = 'videt';
  else document.getElementById('dodaciadresa').className = 'nevidet';

  if (document.getElementById('dodaciadresa_checkbox').checked == true) document.getElementById('dodaciadresa_checkbox').checked = false;
  else document.getElementById('dodaciadresa_checkbox').checked = true;
}


function ZmenAdresu(cislo) {
  if (cislo == 1) {
    document.getElementById('oh_afakt').className = "videt";
    document.getElementById('oh-ajina').className = "nevidet";

    document.getElementById('oh_fakt').checked = true;
    document.getElementById('oh_jina').checked = false;
  }
  else {
    document.getElementById('oh_afakt').className = "nevidet";
    document.getElementById('oh-ajina').className = "videt";

    document.getElementById('oh_jina').checked = true;
    document.getElementById('oh_fakt').checked = false;
  }
}

function KontrolaDodaniCZK() {
  if (document.fo_dodani.oh_platba[3].checked == 1) {
    document.fo_dodani.uz_varianta.value = 0;
    document.fo_dodani.submit();
  }
  else {
    if ((document.getElementById('oh_fakt').checked != 1) && (document.getElementById('oh_jina').checked != 1)) alert("Zvolte prosím jednu z variant dodací adresy.");
    else {
      if (document.getElementById('oh_fakt').checked == 1) {
        document.fo_dodani.uz_varianta.value = 1;
        document.fo_dodani.submit();
      }
      else {
        if (document.getElementById('oh_jina').checked == 1) {
          chyba = "";

          if (document.fo_dodani.uz_do_jmeno.value == "") chyba += "jméno, ";
          if (document.fo_dodani.uz_do_ulice.value == "") chyba += "ulice, ";
          if (document.fo_dodani.uz_do_mesto.value == "") chyba += "mesto, ";
          if (document.fo_dodani.uz_do_psc.value == "") chyba += "psc, ";
          if (document.fo_dodani.uz_do_telefon.value == "") chyba += "telefon, ";

          if (chyba != "") {
            alert("Vložte prosím následující údaje: "+chyba);
            return false;
          }
          else {
            document.fo_dodani.uz_varianta.value = 2;
            document.fo_dodani.submit();
          }
        }
        else alert("Zvolte prosím jednu z variant dodací adresy.");
      }
    }
  }
}

function KontrolaDodaniEUR() {
  if ((document.getElementById('oh_fakt').checked != 1) && (document.getElementById('oh_jina').checked != 1)) alert("Zvolte prosím jednu z variant dodací adresy.");
  else {
    if (document.getElementById('oh_fakt').checked == 1) {
      document.fo_dodani.uz_varianta.value = 1;
      document.fo_dodani.submit();
    }
    else {
      if (document.getElementById('oh_jina').checked == 1) {
        chyba = "";

        if (document.fo_dodani.uz_do_jmeno.value == "") chyba += "jméno, ";
        if (document.fo_dodani.uz_do_ulice.value == "") chyba += "ulice, ";
        if (document.fo_dodani.uz_do_mesto.value == "") chyba += "mesto, ";
        if (document.fo_dodani.uz_do_psc.value == "") chyba += "psc, ";
        if (document.fo_dodani.uz_do_telefon.value == "") chyba += "telefon, ";

        if (chyba != "") {
          alert("Vložte prosím následující údaje: "+chyba);
          return false;
        }
        else {
          document.fo_dodani.uz_varianta.value = 2;
          document.fo_dodani.submit();
        }
      }
      else alert("Zvolte prosím jednu z variant dodací adresy.");
    }
  }
}


function KontrolaInzeratu() {
  chyba = "";
  document.fo_inzerat.ez_novy.value = 0;

  if (document.fo_inzerat.ez_nazev.value == "") chyba += "název, ";
  if (document.fo_inzerat.ez_text.value == "") chyba += "text, ";
  if (document.fo_inzerat.ez_typ.value == "") chyba += "typ, ";
  if (document.fo_inzerat.ez_skupina.value == "") chyba += "skupina, ";
  if (document.fo_inzerat.ez_cena.value == "") chyba += "cena, ";
  if (document.fo_inzerat.ez_jmeno.value == "") chyba += "jméno, ";
  if (document.fo_inzerat.ez_telefon.value == "") chyba += "telefon, ";
  if (document.fo_inzerat.ez_email.value == "") chyba += "email, ";
  if (document.fo_inzerat.ez_heslo.value == "") chyba += "heslo.";

  if (chyba != "") {
    alert("Vložte prosím následující údaje: "+chyba);
    return false;
  }
  else {
    document.fo_inzerat.ez_novy.value = 1;
    document.fo_inzerat.submit();
  }
}


function KontrolaOdstraneni() {
  if ((document.fo_inzerat.ez_kod.value != "") && (document.fo_inzerat.ez_heslo.value != "")) document.fo_inzerat.submit();
  else alert("Nejsou vloženy všechny povinné údaje!");
}


function KontrolaHledani() {
  if (document.fo_filtr.eb_slovo.value != "") document.fo_filtr.submit();
  else alert("Zadejte prosím hledané slovo!");
}


function KontrolaSmazUstajeni() {
}


function ZmenDodaniCZK(cislo) {
  if (cislo == 3) {
    document.getElementById('oh-jinaadresa').className = "nevidet";
  }
  else {
    document.getElementById('oh-jinaadresa').className = "videt";
  }
}


function ZmenDodaniEUR(cislo) {
  if (cislo == 3) {
    document.getElementById('oh-jinaadresa').className = "nevidet";
  }
  else {
    document.getElementById('oh-jinaadresa').className = "videt";
  }
}


function PocitadloTextu(textarea, countdown, maxlimit)
{
  textareaid = document.getElementById(textarea);
  if (textareaid.value.length > maxlimit) textareaid.value = textareaid.value.substring(0, maxlimit);
  else document.getElementById(countdown).value = maxlimit-textareaid.value.length;
}


function KontrolaUstajeni() {
  chyba = "";
  document.fo_ustajeni.us_odeslat.value = 0;

  if (document.fo_ustajeni.us_heslo.value == "") chyba += "heslo, ";
  if (document.fo_ustajeni.us_nazevstaje.value == "") chyba += "název stáje, ";
  if (document.fo_ustajeni.us_kontaktniosoba.value == "") chyba += "kontaktní osoba, ";
  if (document.fo_ustajeni.us_telefon.value == "") chyba += "telefon, ";
  if (document.fo_ustajeni.us_email.value == "") chyba += "email, ";
  if (document.fo_ustajeni.us_kraj.value == "") chyba += "kraj, ";
  if (document.fo_ustajeni.us_okres.value == "") chyba += "okres, ";
  if (document.fo_ustajeni.us_ulice.value == "") chyba += "ulice, ";
  if (document.fo_ustajeni.us_mesto.value == "") chyba += "mesto, ";
  if (document.fo_ustajeni.us_psc.value == "") chyba += "PSČ, ";
  if (document.fo_ustajeni.us_cena.value == "") chyba += "cena.";

  if (chyba != "") {
    alert("Vložte prosím následující údaje: "+chyba);
    return false;
  }
  else {
    document.fo_ustajeni.us_odeslat.value = 1;
    document.fo_ustajeni.submit();
  }
}


function KontrolaHledaniUstajeni() {
  if (document.fo_hledejustajeni.us_slovo.value != "") document.fo_hledejustajeni.submit();
  else alert("Zadejte prosím hledaný výraz!");
}

function KontrolaDotaz() {
  if (document.fo_dotaz.rd_email.value != "" && document.fo_dotaz.rd_telefon.value != "" && document.fo_dotaz.rd_dotaz.value != "") {
    if (document.fo_dotaz.rd_typ.value == 0) {
      alert("Vyberte prosím typ dotazu!");
    }
    else if (!TestEmailu(document.fo_dotaz.rd_email.value) || !ZkontrolujEmail(document.fo_dotaz.rd_email.value) || (document.fo_dotaz.rd_email.value.search(emailRegEx) == -1)) {
      alert("Zadaná emailová adresa není ve správném formátu!!");
      document.fo_dotaz.rd_email.focus();
    }
    else if (document.fo_dotaz.rd_nevyplneno.value == "") {
      document.fo_dotaz.submit();
    }
    else {
      alert("Nastala chyba v odesílání formuláře!");
    }
  }
  else alert("Zadejte prosím všechny informace!");
}

function KontrolaKontaktniFormular() {
  if (document.fo_kf.kf_email.value != "") document.fo_kf.submit();
  else alert("Zadejte prosím Váš email!");
}

function KontrolaSmazUstajeni() {
  if ((document.fo_smazustajeni.us_kod.value != "") && (document.fo_smazustajeni.us_heslo.value != "")) document.fo_smazustajeni.submit();
  else alert("Zadejte prosím kód a heslo inzerátu!");
}

function KontrolaNewsletter() {
  if (document.fo_news.on_email.value != "") document.fo_news.submit();
  else alert("Zadejte prosím email!");
}


