function zacatek() {
  if(document.all == undefined) {
    document.getElementById("dotaznik").disabled = false;
    document.getElementById("locale").value = locale;
  } else {
    dotaznik.disabled = false;
    dotaznik.locale.value = locale;
  }
}

function poslat() {

  var nazvy = "";
  var hodnoty = "";
  var n = "";
  var h = "";
  var vysledek = true;
  var prvek;
  var pocetprvku;

  pocetprvku = (document.all == undefined) ? document.getElementById("dotaznik").length : dotaznik.all.length;

  for(var i=0; i < pocetprvku; i++) {
    prvek = (document.all == undefined) ? document.getElementById("dotaznik")[i] : dotaznik.all(i);
    if(maxtabindex == undefined)
      var maxtabindex = 0;

    if ((prvek.tagName == "INPUT") || (prvek.tagName == "TEXTAREA") || (prvek.tagName == "SELECT")) {
      h = "";
      n = "";
      if(prvek.className == "spatne") {
        switch (locale) {
          case "cz": alert("Opravte, prosím, červeně označená pole."); break;
          case "en": alert("Please correct all red coloured fields."); break;
        }
        return false;
      }
      switch(prvek.type) {
        case "select-one":
          h = "'" + prvek.all(prvek.selectedIndex).value + "'";
          if(h == "''")
            h = "'" + prvek.all(prvek.selectedIndex).innerText + "'";
            n = prvek.name;
          break;
        case "image" : break;
        case "textarea" :
        case "hidden" :
          if ((prvek.name == "nazvy") || (prvek.name == "hodnoty") || (prvek.id == "nazvy") || (prvek.id == "hodnoty"))
            break;
        case "text" : h = "'" + prvek.value + "'";
          n = prvek.name;
          if ((prvek.tabIndex > 0) && (prvek.tabIndex <= maxtabindex) && (prvek.value == "")) {
            switch (locale) {
              case "cz" : alert("Vyplňte prosím všechna povinná pole."); break;
              case "en" : alert("Fill all obligatory data, please!"); break;
            }
            prvek.focus();
            vysledek = false;
            window.scroll(0, document.body.scrollTop - 50);
          }
          break;
        case "radio" :
          if(prvek.checked == true) {
            h = "'" + prvek.value + "'";
            n = prvek.name;
          }
        break;
        case "checkbox": n = prvek.name; h=prvek.checked; break;
      }

      if(!vysledek) {
        break;
      }

      if(n != "") {
        nazvy = nazvy + n + ",";
        hodnoty = hodnoty + h + ",";
      }
    }
  }

  if(document.all==undefined) {
    document.getElementById("nazvy").value = nazvy;
    document.getElementById("hodnoty").value = hodnoty;
  } else {
    document.all("nazvy").value = nazvy;
    document.all("hodnoty").value = hodnoty;
  }

  //dotaznik.submit
  //alert(document.getElementById("nazvy").value);
  //alert("ulozeno "+vysledek)
  //return false
  return vysledek;
}

function kontrola(prvek, typ, zprava) {
  var ok = true;
  var hodnota = prvek.value;
  switch(typ) {
    case "text255" :
      if(hodnota.length > 255) {
        switch(locale) {
          case "cz": alert("Zapsáno " + prvek.value.length + " znaků."); break;
          case "en": alert(prvek.value.length + " characters writed."); break;
        }
        ok = false;
      }
      break;
    case "int"        : ok = /^-{0,1}\d+$/.test(hodnota); break;
    case "tpICO"      : ok = /^\d{8}$|^$/.test(hodnota); break;
    case "tpPSC"      : ok = /(^[1-8]\d{4}$)|(^$)/.test(hodnota); break;
    case "telefon"    : ok = /([2-9]\d{8})/.test(hodnota); break;
    case "fax"        : ok = /([2-9]\d{8})|(^$)/.test(hodnota); break;
    case "mobil"      : ok = /^(60[1-8]{1}|72[0-9]{1}|73[0-9]{1}|77[3-7]{1})([0-9]{6})$/.test(hodnota); break;
    case "email"      : ok = /(\w+@.+\.\w\w+)|(^$)/.test(hodnota); break;
    case "jmeno"      : ok = /^.{1,50}$/.test(hodnota); break;
    case "prijmeni"   : ok = /^.{1,50}$/.test(hodnota); break;
    case "titul"      : ok = /^.{1,15}$|(^$)/.test(hodnota); break;
    case "prac_poz"   : ok = /^.{1,50}$/.test(hodnota); break;
    case "spolecnost" : ok = /^.{1,50}$/.test(hodnota); break;
    case "ulice"      : ok = /^.{1,50}$/.test(hodnota); break;
    case "mesto"      : ok = /^.{1,50}$/.test(hodnota); break;
    case "www"        : ok = /^.{1,50}$|(^$)/.test(hodnota); break;
    case "pocet_zam"  : ok = /^[0-9]{0,4}$/.test(hodnota); break;
  }

  if(!ok) {
    alert(zprava);
    prvek.className = "spatne"; /*window.scroll(0,document.body.scrollTop-30);*/
    //prvek.focus();
  } else {
    prvek.className = "dobre";
  }
  //alert(typ+': '+prvek.className);
}

function setNullEu() {
  document.dotaznik.pocet_eu.value = '';
}

function setNullTm() {
  document.dotaznik.pocet_pa.value='';
}

function setNullOs() {
  document.dotaznik.pocet_os.value='';
}

function trim(str) {
  if (typeof str != "string") { return str; }
  var rv = str;
  var ch = rv.substring(0, 1);
  while (ch == " ") { // Check for spaces at the beginning of the string
    rv = rv.substring(1, rv.length);
    ch = rv.substring(0, 1);
  }
  ch = rv.substring(rv.length-1, rv.length);
  while (ch == " ") { // Check for spaces at the end of the string
    rv = rv.substring(0, rv.length-1);
    ch = rv.substring(rv.length-1, rv.length);
  }
  while (rv.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
    rv = rv.substring(0, rv.indexOf("  ")) + rv.substring(rv.indexOf("  ")+1, rv.length); // Again, there are two spaces in each of the strings
  }
  return rv; // Return the trimmed string back to the user
}



