// check forms
function eCheckNum(sn){
    s= sn.value;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1)
        if (!(ch >= "0" && ch <= "9"))
             return false;
        }
   return true;
}

function CheckNum(theForm){
   for(var i=1; i<CheckNum.arguments.length; i++)
         if (!eCheckNum(theForm.elements[CheckNum.arguments[i]])){
            alert("Neplatné číslo");
            theForm.elements[CheckNum.arguments[i]].focus();
            return false;
        }
   return true;
}

function eCheckFloat(sn){
    s= sn.value;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1)
        if (!((ch >= "0" && ch <= "9") || ch=="." || ch=="," || (ch=="-" && i==0) ))
             return false;
        }
   return true;
}

function CheckFloat(theForm)
{
  for(var i=1; i<CheckFloat.arguments.length; i++)
    {
      if (!eCheckFloat(theForm.elements[CheckFloat.arguments[i]]))
        {
          alert("Neplatné číslo.");
          theForm.elements[CheckFloat.arguments[i]].focus();
          return false;
        }
    }
  return true;
}

function CheckRequiredFields(theForm) {
   for(i=1; i<CheckRequiredFields.arguments.length; i++)
        if(theForm.elements[CheckRequiredFields.arguments[i]].value==""){
            alert("Tato položka musí být vyplněna.");
            theForm.elements[CheckRequiredFields.arguments[i]].focus();
            return false;
        }
   return true;
}



// check date
//--------------------------------------------------------------
function checkDate(a)
{
  function msg(a,v) { 
      alert("Datum je zadáno chybně (správný formát je 'mm.dd.yyyy', např. 20.1.2008).");
      a.focus();
      return(true);
    }
  var dat = new String(a.value);
  if (dat.length==0)
    return;
  
  for (var i=0; i<dat.length; i++) 
    { c = dat.substring(i, i + 1)
      if (!( ((c>="0")&&(c<="9")) || (c==".") ))
        return(msg(a));
    }
  
  var firstTecka = dat.indexOf(".");
  if (firstTecka==-1)
    return(msg(a));

  var lastTecka = dat.lastIndexOf(".");
  if (lastTecka<=firstTecka)
    { var d = new Date();
      dat = dat + "." + d.getFullYear();
      a.value = dat;
    }
  lastTecka = dat.lastIndexOf(".");
  if (lastTecka<=firstTecka)
    return(msg(a,dat));

  var den=dat.substring(0,firstTecka);
  if (den.substring(0,1)=="0") 
    den=dat.substring(1,firstTecka)
  var mesic=dat.substring(firstTecka+1,lastTecka);
  if (mesic.substring(0,1)=="0") 
    mesic=dat.substring(firstTecka+2,lastTecka)
  var rok=dat.substring(lastTecka+1,dat.length);
  if (rok<99)
    rok = "20" + rok;
  if ( (rok<1980) || (rok>2050) )
    return(msg(a));
  var d = new Date();
  d.setYear(rok);
  d.setMonth(mesic-1);
  d.setDate(den);
  if ((d.getDate().toString(10)!==den) || 
      (d.getFullYear().toString(10)!==rok) ||
      ((1+parseInt(d.getMonth(),10)).toString(10)!==mesic)) 
    return(msg(a));
//  a.value = d.getDate() + "." + (1+d.getMonth()) + "." + d.getFullYear();
}



// search in select tag
//--------------------------------------------------------------
var srchLastVal = '', srchTmr=0;

function getKey(e) {
  var code;
  if (!e) var e = window.event;
  if (e.keyCode) 
    code = e.keyCode;
  else
    if (e.which) code = e.which;
  return code;
}

function srchReset() {
  srchLastVal = '';
  srchTmr=0;
  window.defaultStatus = '*';  
}

function srchList(e,s) 
{
  if ( (navigator.userAgent.indexOf('MSIE')<0) && (navigator.userAgent.indexOf('Opera')<0) )
    return true;

  var c=getKey(e);
  if ((c==8) && (srchLastVal.length>0))
    srchLastVal = srchLastVal.substring(0,srchLastVal.length-1);
  else if ( (c>=32) && (c<=127) )
    srchLastVal+= String.fromCharCode(c);
  window.defaultStatus = 'Hledání: ' + srchLastVal;
  if (srchTmr!=0) clearTimeout(srchTmr);
  srchTmr = setTimeout(srchReset, 1500);
  
  for (i=0; i<s.length; i++)
    if ((s.options[i].text.toLowerCase().indexOf(srchLastVal.toLowerCase())==0) && (srchLastVal.value!=''))
      {
        s.options[i].selected = true;
        return false;
      }
  return false;
}
//--------------------------------------------------------------



//--------------------------------------------------------------

