/*
* 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,warningType) {
 var warningTagName = 'strong';
 var fullWarningClass = 'error';
 // 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 ) {
    if ( warningType == 'border') {
     thisForm.elements[i].className = thisForm.elements[i].className.replace(/ warning/g,'');
    } else {
     setWarning(thisForm.elements[i],'');
    }
   }
  }
 }
 // ale result vrátíme na "ano"
 result = true;
 // ale testování více ne
 var oneOf = '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,'Vložte prosím platnou e-mailovou adresu.');
     }
    } else if ( currSecondClass == 'number' ) {
     if ( curr.value.search(/^\d+$/) == -1 ) {
      setWarning(curr,'Vložte prosím číslo.');
     }
    } else if ( currSecondClass == 'looseNumber' ) {
     if ( curr.value.search(/[a-zA-Z]/) > -1 || 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';
     }
/* /přidáno */
    } else {
     if ( curr.value.length == 0 ) {
      setWarning(curr,'Please enter data in this field.');
     }
    }
   }
  }
 }
/* 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.');
   }
  }
 }
/* /přidáno */
 /* přidá text [str] za [obj]ekt do tagu [warningTagName] (viz začátek) */
 function setWarning(obj,str) {
  result = false;
  if ( warningType == 'border') {
   obj.className += ' warning';
  } else {
   if ( obj.parentNode.getElementsByTagName(warningTagName).length == 0 ) {
    var novyObj = document.createElement(warningTagName);
    novyObj.className = fullWarningClass;
    obj.parentNode.appendChild(novyObj);
   } else {
    obj.parentNode.getElementsByTagName(warningTagName)[0].innerHTML = str;
    obj.parentNode.getElementsByTagName(warningTagName)[0].className = fullWarningClass;
    if (str == '') {
     obj.parentNode.getElementsByTagName(warningTagName)[0].className = '';
    }
   }
  }
 }
 return result
}
