onload = init;
function init() {
 focusRelevantInput();
 // mailtoRemDiak();
}
/* najde první textový nereadonly ani nedisabled input a focusne ho */
function focusRelevantInput() {
 if ( document.forms[0] ) {
  for ( var j = 0; j < document.forms[0].elements.length; j++) {
   if (document.forms[0].elements[j].name
   && !document.forms[0].elements[j].getAttribute('readonly')
   && document.forms[0].elements[j].type == 'text' ) {
    document.forms[0].elements[j].focus();
    break
   }
  }
 }
}
function reportVoidDbMail(inputElemID,outputElemID) {
if ( result == true && document.getElementById('userShouldEnterHisEmail') ) {
  info = document.getElementById(inputElemID).value;
  info = 'Uživatel uvedl "' + info + '" místo v administraci chybějící adresy.\n\n\n'
  outputHolder = document.getElementById(outputElemID);
  outputHolder.value = info + ' ' + outputHolder.value;
 }
}
// mailFromDbCheck('validate email','inNote');
var result;
/*
* myfalidate([formulář=objekt],[class povinných inputů=string])
* předpokládá, že všechny testované inputy mají vlastního parenta (např <p>)
* testované inputy musí mít jako první class [reqInputClassName]
* v druhém classu může být konkrétní typ (number|date|email|string)
* přidané je testování vypnlěnosti "jedné z" (pouze pro jedinou skupinu)
* warning se vypíše do (prvního) tagu ([warningTagName]) v daném kontejneru
*/
function myfalidate(thisForm,reqInputClassName) {
 if ( !reqInputClassName ) reqInputClassName = 'valid';
 var warningTagName = 'strong';
 // přidáme za všechny testované inputy prázdný warning
 for( var i = 0; i < thisForm.elements.length; i++) {
  if ( thisForm.elements[i].className.length >= reqInputClassName.length ) {
   if ( thisForm.elements[i].className.split(' ')[0] == reqInputClassName ) {
    setWarning(thisForm.elements[i],'');
   }
  }
 }
 // ale result vrátíme na "ano"
 result = true;
 // ale testování více ne
 var oneOf = 'chybi';
 var oneChecked = 'chybi';
 for( var i = 0; i < thisForm.elements.length; i++) {
  if ( thisForm.elements[i].className.length >= reqInputClassName.length ) {
   if ( thisForm.elements[i].className.split(' ')[0] == reqInputClassName ) {
    curr = thisForm.elements[i];
    currSecondClass = thisForm.elements[i].className.split(' ')[1];
    currValue = thisForm.elements[i].value;
    if ( currSecondClass == 'email' ) {
     if ( curr.value.search(/^[^@]+@.+\..+$/) == -1 ) {
      setWarning(curr,'<br /> Vložte platnou e-mailovou adresu.');
     }
    } else if ( currSecondClass == 'number' ) {
     if ( curr.value.search(/^\d+$/) == -1 ) {
      setWarning(curr,'Vložte prosím číslo.');
     }
    } else if ( currSecondClass == 'date' ) {
     if ( curr.value.search(/^\d\d\.\d\d\.\d\d\d\d$/) == -1 ) {
      setWarning(curr,'Vložte prosím datum ve formátu <code>dd.mm.rrrr<\/code>.');
     }
/* přidáno */
    } else if ( currSecondClass == 'oneOf' ) {
     if ( curr.value.length != 0 ) {
      oneOf = 'nechybi';
     }
    } else if ( currSecondClass == 'oneChecked' ) {
     if ( curr.checked != false ) {
      oneChecked = 'nechybi';
     }
/* /přidáno */
    } else {
     if ( curr.value.length == 0 ) {
      setWarning(curr,'Vyplňte prosím předešlou kolonku.');
     }
    }
   }
  }
 }
/* přidáno */
 if (oneOf == 'chybi') {
  for( var g = 0; g < thisForm.elements.length; g++) {
   if ( thisForm.elements[g].className.split(' ')[1] == 'oneOf' ) {
    setWarning(thisForm.elements[g],'Vyplňte prosím alespoň jeden z těchto.');
   }
  }
 }
 if (oneChecked == 'chybi') {
  for( var g = 0; g < thisForm.elements.length; g++) {
   if ( thisForm.elements[g].className.split(' ')[1] == 'oneChecked' ) {
    setWarning(thisForm.elements[g],'Vyplňte prosím alespoň jeden z těchto.');
   }
  }
 }
/* /přidáno */
 /* přidá text [str] za [obj]ekt do tagu [warningTagName] (viz začátek) */
 function setWarning(obj,str) {
  if ( obj.parentNode.getElementsByTagName(warningTagName).length == 0 ) {
   var novyObj = document.createElement(warningTagName);
   obj.parentNode.appendChild(novyObj);
  } else {
   obj.parentNode.getElementsByTagName(warningTagName)[0].innerHTML = str;
  }
  result = false;
 }
 return result
}
