//(document.all)?document.write('<link rel="Stylesheet" type="text/css" href="/common.css">'):document.write('<link rel="Stylesheet" type="text/css" href="/common_ne.css">');
if(document.all){IE=true;NN=false}else{NN=true;IE=false}
//document.write('<link rel="Stylesheet" type="text/css" href="/common.css">')

function valNrLicencji(NrLicencjiStr){
//  if(NrLicencjiStr == "") return false
  for (i = 0;i < NrLicencjiStr.length;i++){
    c=NrLicencjiStr.charCodeAt(i)
    if(!((c>=48 && c<=57) || c==45 || c==47 || c==40 || c==41 || c==91 || c==93 || c==95 || c==46 || c==58)) return false //0-9 - / ( ) [ ] _ . :
  }
  return true
}

function notValidNrLicencji(){
  notValidNrLicencjiArgs = notValidNrLicencji.arguments
  if(notValidNrLicencjiArgs[1]) errMsg = notValidNrLicencjiArgs[1]; else errMsg = "Podaj poprawny numer licencji"
  if(notValidNrLicencjiArgs[2]){
    if(notValidNrLicencjiArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(madatory && (notValidNrLicencjiArgs[0].value != "") && valNrLicencji(notValidNrLicencjiArgs[0].value)) return false
  if(!madatory && valNrLicencji(notValidNrLicencjiArgs[0].value)) return false
  if(!progCheck){
    alert(errMsg)
    notValidNrLicencjiArgs[0].focus()
  }  
  return true;
}

function notValidLogin(){
  notValidLoginArgs = notValidLogin.arguments
  if(notValidLoginArgs[1]) errMsg = notValidLoginArgs[1]; else errMsg = "Podaj poprawny login"
  if(notValidLoginArgs[2]) minLength = notValidLoginArgs[2]; else minLength = 1
  if(valLogin(notValidLoginArgs[0].value) && notValidLoginArgs[0].value.length>=minLength) return false
  if(errMsg){
    alert(errMsg)
    notValidLoginArgs[0].focus()
  }  
  return true;
}


function valLogin(LoginStr){
  if(LoginStr == "") return false
  for (i = 0;i < LoginStr.length;i++){
    c=LoginStr.charCodeAt(i)
    if(!((c>=65 && c<=90) || (c>=97 && c<=122) || (c>=48 && c<=57) || c==95 || c==45 || c==64)) return false
  }
  return true
}

function showText(id,visible){
  if(visible==1){
    if($('w'+id)) Element.show('w'+id)
    if($('wm'+id)) Element.show('wm'+id);
    if($('ww'+id)) Element.hide('ww'+id)
  }else{
    if($('w'+id)) Element.hide('w'+id)
    if($('wm'+id)) Element.hide('wm'+id);
    if($('ww'+id)) Element.show('ww'+id)
  }
}

function nd(dTmp,mTmp,yTmp){
  mTmp=Number(mTmp)-1
  return new Date(yTmp,mTmp,dTmp)
}  

function dStr(dateStr){
  dTmp=Number(dateStr.value.substring(0,dateStr.value.indexOf("/")))
  mTmp=Number(dateStr.value.substring(dateStr.value.indexOf("/")+1,dateStr.value.lastIndexOf("/")))-1
  yTmp=Number(dateStr.value.substring(dateStr.value.lastIndexOf("/")+1,dateStr.value.length))
  return new Date(yTmp,mTmp,dTmp)
}


function d(dateF){
  if(dateF){
    dTmp=Number(dateF.value.substring(0,dateF.value.indexOf("/")))
    mTmp=Number(dateF.value.substring(dateF.value.indexOf("/")+1,dateF.value.lastIndexOf("/")))-1
    yTmp=Number(dateF.value.substring(dateF.value.lastIndexOf("/")+1,dateF.value.length))
    return new Date(yTmp,mTmp,dTmp)
  }else{
    return new Date()
  }  
}


function submitTo(dest){
  document.mainForm.action=dest
  document.mainForm.submit()
}

function pl2enDate(dateStr){
  return dateStr.substring(3,5)+"/"+dateStr.substring(0,2)+"/"+dateStr.substring(6,10)
}

function rollOn(imgObj, imgSrc){
  document.images[imgObj].src = imgSrc
}


function noise(){
  noiseDate = new Date();
  return noiseDate.getTime();
}

function ntg(){}

function swc(com){
  openPopUpWin(com)
}

function ssc(com){
  with(document.forms[0]){
    action = com
    submit() 
  }
}  

function spc(com){
  with(document.forms[0]){
    action = com
    target = "ICPParentWindow"
    submit() 
    close()
  }
}  

function openCalendar(field,e,reload){
  if(reload!=1) reload=0
  openCalendarArgs = openCalendar.arguments
  field = openCalendarArgs[0]
  e = openCalendarArgs[1]
  if(openCalendarArgs[2]){up = openCalendarArgs[2]}else{up = 10}
  if(openCalendarArgs[3]){down = openCalendarArgs[3]}else{down = 100}
  var posx = 0; var posy = 0;
  if(e){
    posx = e.screenX
    posy = e.screenY
  }
  if((posx+260) >= screen.width) posx-=260
  if((posy+245) >= screen.height) posy-=245

  dateedit = eval("document.mainForm."+field+".value")
  if(!valDate(dateedit)) dateedit = ""
  CalendarWinProp="toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,left="+posx+",top="+posy+",screenX="+posx+",screenY="+posy+",width=248,height=165";
  CalendarWin=window.open("/calendar?dateField=opener.document.forms[0]."+field+".value&editDate="+dateedit+"&up="+up+"&down="+down+"&reload="+reload,"CalendarWin",CalendarWinProp);
}


function openPopUpWin(){
  PopUpWinArgs = openPopUpWin.arguments
  if(PopUpWinArgs[0]) docName = PopUpWinArgs[0]; else docName = "/static/blank.ws"
  if(PopUpWinArgs[1]) winScrollbars = PopUpWinArgs[1]; else winScrollbars = 1
  if(PopUpWinArgs[2]) winWidth = PopUpWinArgs[2]; else winWidth = 747
  if(PopUpWinArgs[3]) winHeight = PopUpWinArgs[3]; else winHeight = 500
  if(PopUpWinArgs[4]) winStatus = PopUpWinArgs[4]; else winStatus = 1
  if(PopUpWinArgs[5]) winResizable = PopUpWinArgs[5]; else winResizable = 0
  if(PopUpWinArgs[6]) winName = PopUpWinArgs[6]; else winName = "PopUpWin"

  PopUpWinProp="toolbar=0,location=0,directories=0,status="+winStatus+",menubar=0,scrollbars="+winScrollbars+",resizable="+winResizable+",width="+winWidth+",height="+winHeight+",left=0,top=0,screenX=0,screenY=0";
  PopUpWin=window.open(docName,winName,PopUpWinProp);
}

function openMenuWin(docName,w,h,scrollbars,e,MenuWinName){
  var posx = 0; var posy = 0;
  if(e){
    posx = e.screenX
    posy = e.screenY
  }
  if((posy+h+55) > screen.height) posy-=(h+25)
  if((posx+w) > screen.width) posx-=(w+5)

  MenuWinProp="toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+scrollbars+",resizable=0,left="+posx+",top="+posy+",screenX="+posx+",screenY="+posy+",width="+w+",height="+h
  MenuWin=window.open(docName,MenuWinName,MenuWinProp)
}  

function showSnap(imgname,w,h,title){
  maxHeight = 650
  defHeight = 650
  prefs="toolbar=0,location=0,directories=0,status=0,menubar=0,left=0,top=0,screenX=0,screenY=0,resizable=0,scrollbars="
  if(h > maxHeight){prefs += "1,width="+(w+16+20)+",height="+defHeight+25}else{prefs += "0,width="+(w+20)+",height="+(h+25)}
  snapWin=window.open("","snapWin",prefs);
  snapWin.document.write("<html><title>"+title+"</title><body bgcolor='#ffffff' onBlur='self.close()' onLoad='self.focus()' marginwidth=10 marginheight=12 topmargin=12 leftmargin=10><div><img src="+imgname+" border=0 height="+h+" width="+w+" alt='"+title+"'></div></body></html>");
  snapWin.document.close();
}

function openPrintWin(docName){
  printWindow=window.open(docName,"printWindow","toolbar=1,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=0,width=775,height=600");
}


function howManyChecked(checkboxgroup){
  checkedCount = 0
  if(checkboxgroup.length){
    for(i=0;i<checkboxgroup.length;i++)
      if(checkboxgroup[i].checked) checkedCount++;
  } else {
    if(checkboxgroup.checked) checkedCount++;
  }
  return checkedCount;
}

function isAnyChecked(checkboxgroup){
  if(checkboxgroup.length){
    for(i=0;i<checkboxgroup.length;i++)
      if(checkboxgroup[i].checked) return true;
  } else {
    if(checkboxgroup.checked) return true;
  }
  return false;
}

function isMoreChecked(checkboxgroup){
  if(checkboxgroup.length){
    more=false
    for(i=0;i<checkboxgroup.length;i++)
      if(checkboxgroup[i].checked)
        if(more) return true; else more=true
  }
  return false;
}

function revSelection(checkboxgroup){
  if(checkboxgroup.length){
    for(i=0;i<checkboxgroup.length;i++){
      if(checkboxgroup[i].checked) checkboxgroup[i].checked = false; else checkboxgroup[i].checked = true
    }
  } else {
    if(checkboxgroup.checked) checkboxgroup.checked = false; else checkboxgroup.checked = true
  }  
}
function remSelection(checkboxgroup){
  if(checkboxgroup.length){
    for(i=0;i<checkboxgroup.length;i++) checkboxgroup[i].checked = false;
  } else {
    checkboxgroup.checked = false;
  }  
}

function selectGroup(checkboxgroup,newval){
  if(checkboxgroup.length){
    for(i=0;i<checkboxgroup.length;i++){
      checkboxgroup[i].checked = newval
    }
  } else {
    checkboxgroup.checked = newval
  }  
}


function valHour(hour){
  if(hour == "") return false
  if(hour.indexOf(":")==-1)return false
  if(hour.indexOf(":")!=hour.lastIndexOf(":"))return false
  h = hour.substring(0,hour.indexOf(":"))
  m = hour.substring(hour.indexOf(":")+1,hour.length)
  if(h.length>2 || m.length>2) return false
  if(!(valNo(m) && valNo(h))) return false
  if(h<0 || h>23) return false
  if(m<0 || m>59) return false
  return true
}

function valCode(code){
  if(code == "") return false
  if(code.indexOf("-")==-1)return false
  if(code.indexOf("-")!=code.lastIndexOf("-"))return false
  code1 = code.substring(0,code.indexOf("-"))
  code2 = code.substring(code.indexOf("-")+1,code.length)
  if(code1.length!=2 || code2.length!=3) return false
  if(!(valNo(code1) && valNo(code2))) return false
  return true
}


function valNo(No){
  if(No == "") return true
  for (i = 0;i < No.length;i++)
    if ((No.charAt(i) < "0") || (No.charAt(i) > "9")) return false
  return true
}

function valYear(year){
  if(year == "") return true
  if(!valNo(year)) return false
  if (year < 1000) return false
  return true
}

function valAge(age){
  if(age == "") return true
  if(!valNo(age)) return false
  if (age < 0) return false
  return true
}

function valDate(date,format){
  if(date == "") return true
  if(date.indexOf("/") == date.lastIndexOf("/")) return false
  if(format=="pl"){
    day = date.substring(0,date.indexOf("/"))
    month = date.substring(date.indexOf("/")+1,date.lastIndexOf("/"))
  }else{
    month = date.substring(0,date.indexOf("/"))
    day = date.substring(date.indexOf("/")+1,date.lastIndexOf("/"))
  }
  year = date.substring(date.lastIndexOf("/")+1,date.length)
  if( !( (valNo(month)) && (valNo(day)) && (valNo(year)) ) ) return false

  if ((day < 1) || (day > 31)) return false
  if (year < 1900) return false
  if ((month < 1) || (month > 12)) return false

  if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
    leap = true
  else leap = false

  if (((day > 31) && (month == 1)) ||
      ((day > 28) && (month == 2) && (!leap)) ||
      ((day > 29) && (month == 2) && (leap)) ||
      ((day > 31) && (month == 3)) ||
      ((day > 30) && (month == 4)) ||
      ((day > 31) && (month == 5)) ||
      ((day > 30) && (month == 6)) ||
      ((day > 31) && (month == 7)) ||
      ((day > 31) && (month == 8)) ||
      ((day > 30) && (month == 9)) ||
      ((day > 31) && (month == 10)) ||
      ((day > 30) && (month == 11)) ||
      ((day > 31) && (month == 12)))
  return false

  return true
}

function formatPhone(field){
  if(field.value == "") return
  if(field.value == "          ") return
  while(field.value.length < 10)
    field.value = " " + field.value
  field.value = "(" +  field.value.substring(0,3) + ") " + field.value.substring(3,6) + "-" + field.value.substring(6,10)
}

function unformatPhone(field){
  if(field.value == "") return
  if(field.value == "          ") return
  field.value = field.value.substring(1,4) + field.value.substring(6,9) + field.value.substring(10,14)
  field.value = field.value.substring(field.value.lastIndexOf(" ")+1,field.value.length)
}

function onlyDigits(field){
  return
  fieldTMP = ""
  for(i=0;i<field.value.length;i++){
    charTMP = field.value.charAt(i)
    if((charTMP >= "0") && (charTMP <= "9"))
      fieldTMP = fieldTMP + charTMP
  }    
  field.value = fieldTMP
}


function checkMail(mail){
/* Available Mail Host Domains
domains = new Array ("ad","ae","af","ag","ai","al","am","an","ao","aq","ar","arpa","as","at","au","aw","az","ba","bb","bd","be","bf","bg","bh","bi","bj","bm","bn","bo","br","bs","bt",
  "bv","bw","by","bz","ca","cc","cf","cd","cg","ch","ci","ck","cl","cm","cn","co","com","cr","cs","cu","cv","cx","cy","cz","de","dj","dk","dm","do","dz","ec","edu",
  "ee","eg","eh","er","es","et","fi","fj","fk","fm","fo","fr","fx","ga","gb","gd","ge","gf","gh","gi","gl","gm","gn","gov","gp","gq","gr","gs","gt","gu","gw","gy",
  "hk","hm","hn","hr","ht","hu","id","ie","il","in","int","io","iq","ir","is","it","jm","jo","jp","ke","kg","kh","ki","km","kn","kp","kr","kw","ky","kz","la","lb",
  "lc","li","lk","lr","ls","lt","lu","lv","ly","ma","mc","md","mg","mh","mil","mk","ml","mm","mn","mo","mp","mq","mr","ms","mt","mu","mv","mw","mx","my","mz","na",
  "nato","nc","ne","net","nf","ng","ni","nl","no","np","nr","nt","nu","nz","om","org","pa","pe","pf","pg","ph","pk","pl","pm","pn","pr","pt","pw","py","qa","re",
  "ro","ru","rw","sa","sb","sc","sd","se","sg","sh","si","sj","sk","sl","sm","sn","so","sr","st","su","sv","sy","sz","tc","td","tf","tg","th","tj","tk","tm","tn",
  "to","tp","tr","tt","tv","tw","tz","ua","ug","uk","um","us","uy","uz","va","vc","ve","vg","vi","vn","vu","wf","ws","ye","yt","yu","za","zm","zr","zw");
*/

  if(mail == "") return true
  if(mail.charAt(mail.length-1) == ".") mail=mail.substr(0,mail.length-1)
  if(mail.length < 6) return false
  if(mail.indexOf("@") == -1) return false

  mailHost = mail.substring(mail.indexOf("@")+1,mail.length) 
  if(mailHost.indexOf(".") == -1) return false

/* Checking Mail Host Domains
  mailHostDomain = mailHost.substring(mailHost.lastIndexOf(".")+1,mailHost.length)
  mailHostDomain = mailHostDomain.toLowerCase()
  for(i=0;i<=domains.length;i++)
    if(mailHostDomain == domains[i]) return true;
  return false
*/  

  return true;
}

function isAmount(what,decmaxlength){
  for (i=0;i<what.length;i++)
    if (!( ((what.charAt(i) >= "0") && (what.charAt(i) <= "9")) || (what.charAt(i) == "$") || (what.charAt(i) == ",") || (what.charAt(i) == "."))) return false
  if(what.indexOf("$") != what.lastIndexOf("$")) return false
  if(what.indexOf("$") > 0) return false
  if(what.indexOf(".") != what.lastIndexOf(".")) return false
  if(what.indexOf(".") == -1){
    loopStart = what.length-1
    decValue = ""
  } else {
    loopStart = what.indexOf(".")-1
    decValue = what.substring(what.indexOf(".")+1,what.length)
  }  
  if(decValue.indexOf(",") != -1) return false
  if(decValue.length > decmaxlength) return false
  commaCount = 0
  for (i=loopStart;i>=0;i--){
    if(commaCount != 3)
      if(what.charAt(i) == ",") return false; else commaCount++ 
    else {
      commaCount = 0
      if(what.charAt(i) != ",") commaCount++
    }  
  }
  return true
}

function parseAmount(what){
  if(what.value.charAt(0) == "$") what.value = what.value.substring(1,what.value.length)
  while(what.value.indexOf(",") > -1){
    what.value =  what.value.substring(0,what.value.indexOf(",")) + what.value.substring(what.value.indexOf(",")+1,what.value.length)
  }
  if(what.value == ".") what.value = "" 
//  if(what.value != "")
//    what.value = Math.round(parseFloat(what.value))
}

function clearBad(f_name){
  if(progCheck)return

  re=new RegExp("_[0-9]+");
  dodatkowy=f_name.name.replace(re,"")
  if($("l_"+dodatkowy))$("l_"+dodatkowy).removeClassName("bad")

  if($("l_"+f_name.name))$("l_"+f_name.name).removeClassName("bad")
  bad_no=1
  while($("l_"+f_name.name+"_"+bad_no)){
    $("l_"+f_name.name+"_"+bad_no).removeClassName("bad")
    bad_no++
  }  
}
function setBad(f_name){
  if(progCheck)return
  
  re=new RegExp("_[0-9]+");
  dodatkowy=f_name.name.replace(re,"")
  if($("l_"+dodatkowy)){
    $("l_"+dodatkowy).addClassName("bad")
    $("l_"+dodatkowy).scrollTo()
  }  
  if($("l_"+f_name.name)){
    $("l_"+f_name.name).addClassName("bad")
    $("l_"+f_name.name).scrollTo()
  }

  bad_no=1
  while($("l_"+f_name.name+"_"+bad_no)){
    $("l_"+f_name.name+"_"+bad_no).addClassName("bad")
//    $("l_"+f_name.name+"_"+bad_no).scrollTo()
    bad_no++
  }  
}
function notValid(){
  notValidArgs = notValid.arguments
//nowa walidacja  
  if(notValidArgs[0][0] && (notValidArgs[0][0].type == "radio" || notValidArgs[0][0].type == "checkbox")){
    clearBad(notValidArgs[0][0])
  }else{
    clearBad(notValidArgs[0])
  }
  if(notValidArgs[1]) errMsg = notValidArgs[1]; else errMsg = "Wypełnij wszystkie pola obowiązkowe."
  if(notValidArgs[0][0] && (notValidArgs[0][0].type == "radio" || notValidArgs[0][0].type == "checkbox")){if(isAnyChecked(notValidArgs[0])) return false}
  if(notValidArgs[0].type == "radio" || notValidArgs[0].type == "checkbox"){if(notValidArgs[0].checked) return false}
  if(notValidArgs[0].type == "select-one"){if(notValidArgs[0].selectedIndex != 0) return false}
  if(notValidArgs[0].type == "select-multiple"){ if(notValidArgs[0].selectedIndex != -1) return false}
  if((notValidArgs[0].type == "text") || (notValidArgs[0].type == "hidden") || (notValidArgs[0].type == "password") || (notValidArgs[0].type == "file") || (notValidArgs[0].type == "textarea")){if(notValidArgs[0].value != "") return false}
//  if(notValidArgs[1]){
    if(!progCheck) alert(errMsg)
    if(notValidArgs[0][0] && (notValidArgs[0][0].type == "radio" || notValidArgs[0][0].type == "checkbox")){
      if(!progCheck) notValidArgs[0][0].focus()
      setBad(notValidArgs[0][0])
    }else{
//nowa walidacja  
      setBad(notValidArgs[0])
      if(!progCheck) notValidArgs[0].focus()
    }
//  }  
  return true;
}

function notValidRadio(){
  notValidRadioArgs = notValidRadio.arguments
  clearBad(notValidRadioArgs[0])
  if(notValidRadioArgs[1]) errMsg = notValidRadioArgs[1]; else errMsg = "Wybierz jedną z opcji"
  if(isAnyChecked(notValidRadioArgs[0])) return false
  if(errMsg){
    if(!progCheck) alert(errMsg)
    if(!progCheck) notValidRadioArgs[0][0].focus()
    setBad(notValidRadioArgs[0])
  }  
  return true;
}

function notValidDesc(){//object,err msg,max length,mandatory
  notValidDescArgs = notValidDesc.arguments
  clearBad(notValidDescArgs[0])
  if(notValidDescArgs[3] == 1){
    if((notValidDescArgs[0].value.length <= notValidDescArgs[2]) && (notValidDescArgs[0].value != "")) return false
  }else{
    if(notValidDescArgs[0].value.length <= notValidDescArgs[2]) return false
  }
  if(!progCheck) alert(notValidDescArgs[1])
  if(!progCheck) notValidDescArgs[0].focus()
  setBad(notValidDescArgs[0])
  return true;
}

function notValidMail(){
  notValidMailArgs = notValidMail.arguments
  clearBad(notValidMailArgs[0])
  if(notValidMailArgs[1] && notValidMailArgs[1]!="") errMsg = notValidMailArgs[1]; else errMsg = "Podaj poprawny adres email."
  if(notValidMailArgs[2]){
    if(notValidMailArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(madatory && (notValidMailArgs[0].value != "") && checkMail(notValidMailArgs[0].value)) return false
  if(!madatory && checkMail(notValidMailArgs[0].value)) return false
  if(!progCheck) alert(errMsg)
  if(!progCheck) notValidMailArgs[0].focus()
  setBad(notValidMailArgs[0])
  return true;
}

function notValidDate(){//object, err message, mandatory, format
  notValidDateArgs = notValidDate.arguments
  clearBad(notValidDateArgs[0])
  if(notValidDateArgs[3]) if(notValidDateArgs[3]==0) langFormat="pl";else langFormat="en";else langFormat="pl";
  if(notValidDateArgs[2]){
    if(notValidDateArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(notValidDateArgs[1]) errMsg = notValidDateArgs[1]; else errMsg = "Podaj poprawną datę w formacie dd/mm/rrrr."
  if(!madatory && notValidDateArgs[0].value == "") return false
  if(notValidDateArgs[0].value != ""){
    if(valDate(notValidDateArgs[0].value,langFormat)) return false
  }  
  if(!progCheck) alert(errMsg)
  if(!progCheck) notValidDateArgs[0].focus()
  setBad(notValidDateArgs[0])
  return true;
}

function notValidInc(){ //object, error message, is madatory, min value, max value, min length, max length
  notValidIncArgs = notValidInc.arguments
  clearBad(notValidIncArgs[0])
  if(notValidIncArgs[1] && notValidIncArgs[1]!="") errMsg = notValidIncArgs[1]; else errMsg = "Podaj poprawna liczbe.";
  if(notValidIncArgs[2]){
    if(notValidIncArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(!madatory && (notValidIncArgs[0].value == "")) return false
//  if(notValidIncArgs[0].value=="")notValidIncArgs[0].value=0
  
  if(notValidIncArgs[3]) minValue = notValidIncArgs[3]; else minValue = 0
  if(notValidIncArgs[4]) maxValue = notValidIncArgs[4]; else maxValue = 99999999999999999999
  
  if(notValidIncArgs[5]) minLength = notValidIncArgs[5]; else minLength = 0
  if(notValidIncArgs[6]) maxLength = notValidIncArgs[6]; else maxLength = 20

  if(valNo(notValidIncArgs[0].value)){
    if(!madatory){
      if((notValidIncArgs[0].value <= maxValue) && (notValidIncArgs[0].value >= minValue) && (notValidIncArgs[0].value.length >= minLength) && (notValidIncArgs[0].value.length <= maxLength)) return false
    }else{
      if(notValidIncArgs[0].value!="" && (notValidIncArgs[0].value <= maxValue) && (notValidIncArgs[0].value >= minValue) && (notValidIncArgs[0].value.length >= minLength) && (notValidIncArgs[0].value.length <= maxLength)) return false
    }  
  }  

  if(!progCheck) alert(errMsg)
  if(!progCheck) notValidIncArgs[0].focus()
  setBad(notValidIncArgs[0])

  return true;
}

function notValidDec(){ //object, error message, is madatory, max decimal length, max value
//jezeli nie ma maxa, to max = 10 000 000
  notValidDecArgs = notValidDec.arguments
  clearBad(notValidDecArgs[0])
  if(notValidDecArgs[3]) maxDecLength = notValidDecArgs[3]; else maxDecLength = 2
  if(notValidDecArgs[1]) errMsg = notValidDecArgs[1]; else errMsg = "Podaj poprawna kwote.";
  if(notValidDecArgs[2]){
    if(notValidDecArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false
  if(!madatory && (notValidDecArgs[0].value == "")) return false
//  if(notValidDecArgs[0].value=="")notValidDecArgs[0].value=0
  if(notValidDecArgs[4]) maxValue = notValidDecArgs[4]; else maxValue = 10000000
  
  if(isAmount(notValidDecArgs[0].value,maxDecLength)){
    parseAmount(notValidDecArgs[0])
    if(!madatory){
      if(notValidDecArgs[0].value < maxValue) return false
    }else{
      if(notValidDecArgs[0].value!="" && (notValidDecArgs[0].value < maxValue) && (notValidDecArgs[0].value >= 0)) return false
    }  
  }  
  if(!progCheck) alert(errMsg)
  if(!progCheck) notValidDecArgs[0].focus()
  setBad(notValidDecArgs[0])

  return true;
}

function notValidYear(){ //object, error message, is madatory, max value
  notValidYearArgs = notValidYear.arguments
  clearBad(notValidYearArgs[0])
  if(notValidYearArgs[1] && notValidYearArgs[1]!="") errMsg = notValidYearArgs[1]; else errMsg = "Podaj poprawny rok."
  if(notValidYearArgs[3]) maxVal = notValidYearArgs[3]; else maxVal=9999
  if(notValidYearArgs[2]){
    if(notValidYearArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false

  if(!madatory && notValidYearArgs[0].value == ""){
    return false
  }else{
    if(valNo(notValidYearArgs[0].value)){
      if((notValidYearArgs[0].value >= 1753) && (notValidYearArgs[0].value <= maxVal)) return false
    }
  }

  if(!progCheck) alert(errMsg)
  if(!progCheck) notValidYearArgs[0].focus()
  setBad(notValidYearArgs[0])
  return true;
}
  

function notValidHour(){ //object, error message, is madatory
  notValidHourArgs = notValidHour.arguments
  clearBad(notValidHourArgs[0])
  if(notValidHourArgs[1]) errMsg = notValidHourArgs[1]; else errMsg = "Podaj poprzwną godzinę w formacie gg:mm."
  if(notValidHourArgs[2]){
    if(notValidHourArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false

  if(!madatory && notValidHourArgs[0].value == ""){
    return false
  }else{
    if(valHour(notValidHourArgs[0].value)) return false
  }

  if(!progCheck) alert(errMsg)
  if(!progCheck) notValidHourArgs[0].focus()
  setBad(notValidHourArgs[0])
  return true;
}

function notValidKod(){ //object, error message, is madatory
  notValidKodArgs = notValidKod.arguments
  clearBad(notValidKodArgs[0])
  if(notValidKodArgs[1] && notValidKodArgs[1]!="") errMsg = notValidKodArgs[1]; else errMsg = "Podaj poprawny kod pocztowy w formacie 00-000."
  if(notValidKodArgs[2]){
    if(notValidKodArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false

  if(!madatory && notValidKodArgs[0].value == ""){
    return false
  }else{
    if(valCode(notValidKodArgs[0].value)) return false
  }

  if(!progCheck) alert(errMsg)
  if(!progCheck) notValidKodArgs[0].focus()
  setBad(notValidKodArgs[0])
  return true;
}

function notValidPhone(){ //object, error message, is madatory
  notValidPhoneArgs = notValidPhone.arguments
  clearBad(notValidPhoneArgs[0])
  if(notValidPhoneArgs[1]) errMsg = notValidPhoneArgs[1]; else errMsg = "Niepoprawny format numeru telefonu/faksu"
  if(notValidPhoneArgs[2]){
    if(notValidPhoneArgs[2] == 1) madatory = true; else madatory = false
  }else madatory = false

  if(!madatory && notValidPhoneArgs[0].value == ""){
    return false
  }else{
    if(valPhone(notValidPhoneArgs[0].value)) return false
  }

  if(!progCheck) alert(errMsg)
  if(!progCheck) notValidPhoneArgs[0].focus()
  setBad(notValidPhoneArgs[0])
  return true;
}

function valPhone(phone){
  if(phone == "") return false
  for (i = 0;i < phone.length;i++)
    if (!( ((phone.charAt(i) >= "0") && (phone.charAt(i) <= "9")) || (phone.charAt(i) == " ") || (phone.charAt(i) == "-") || (phone.charAt(i) == "(") || (phone.charAt(i) == ")") || (phone.charAt(i) == "[") || (phone.charAt(i) == "]") || (phone.charAt(i) == ".") || (phone.charAt(i) == "+") || (phone.charAt(i) == "/") || (phone.charAt(i) == "\\") || (phone.charAt(i) == ""))) return false
  return true
}

function selectDateFrame(selectName,fieldName){
  fromField = eval("document."+fieldName+"From")
  toField = eval("document."+fieldName+"To")
  if(selectName.selectedIndex == 0){fromField.value = ""; toField.value = ""; return}
  if(selectName.selectedIndex != 8){
    fromField.value= selectName.options[selectName.selectedIndex].value.substring(0,10)
    toField.value= selectName.options[selectName.selectedIndex].value.substring(11,22)
  }else{
    fromField.value=""
    toField.value=""
    fromField.focus()
  }
}
  
function setCustomFrame(fieldName){
  eval("document."+fieldName+"Frame.selectedIndex = 8")
}  

function deselectLast(where){ if(where.options[where.options.length-1].selected) where.options[where.options.length-1].selected = false }
function deselectLastSingle(where){ if(where.selectedIndex==where.options.length-1)where.selectedIndex--;}
