var SviInputi=document.getElementsByTagName("INPUT"),DatumProblemi=new Array,key_code,oElement,dozvoljeni=new Array(8,9,16,17,18,27,37,38,39,40,46);function addLoadEvent(func){var oldonload=window.onload;if(typeof window.onload!='function')window.onload=func;else{window.onload=function(){oldonload();func();}}};function brCifara(string,broj){if(string.length!=broj)return false;else return true;};function sveCifre(string){return string.match(/^\d+$/);};function ToggleError(polje,greska){for(var i=1;i<SviInputi.length;i++){if((SviInputi[i].name!=null)||(SviInputi[i].id!=null)){if(SviInputi[i].name.indexOf(polje)!= -1){if(greska==1)SviInputi[i].className="CellFormError";else SviInputi[i].className="CellForm";}}}};function isDate(datum){pom=true;if(datum.match("^((0)?[1-9]|[12][0-9]|3[01])[. /.]((0)?[1-9]|1[012])[. /.](19|20)\\d\\d+$")){var str=datum.split("/");if(str[0].substring(0,1)=='0')dan=parseInt(str[0].substring(1,2));else dan=parseInt(str[0]);if(str[1].substring(0,1)=='0')mesec=parseInt(str[1].substring(1,2));else mesec=parseInt(str[1]);god=parseInt(str[2]);if(dan>brDanaUMesecu(mesec,god))pom=false;}else pom=false;return pom;};function brDanaUFebruaru(godina){return(((godina%4==0)&&((!(godina%100==0))||(godina%400==0)))?29:28);};function brDanaUMesecu(mesec,god){switch(mesec){case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 4:case 6:case 9:case 11:return 30;case 2:return brDanaUFebruaru(god);}};function DateValid(datum){var name=datum.name.toString(),value=datum.value,DatumOk,MestoProblem,Problem=false;for(i=0;i<DatumProblemi.length;i++){if(DatumProblemi[i]==name){var Problem=true;MestoProblem=i;break;}}if((value)&&(value!="")&&(value!=null)){if(!isDate(value)){alert(document.getElementById("DatumGreska").value);DatumOk=false;if(!Problem)DatumProblemi[DatumProblemi.length]=name;}else{DatumOk=true;if(Problem)DatumProblemi.splice(MestoProblem,1);}}else{DatumOk=true;if(Problem)DatumProblemi.splice(MestoProblem,1);}if(DatumProblemi.length==0){ToggleError(name,0);}else{ToggleError(name,1);if(DatumOk)datum.className="InputActive";}};function DateInputMask(param){key_code=window.event.keyCode;oElement=window.event.srcElement;if(oElement.value.length<10){if((key_code>47&&key_code<58)||(key_code>95&&key_code<106)){if(key_code>95)key_code-=(95-47);if(key_code>51&&key_code<58&&oElement.value.length==0){oElement.value+="0";}else if(key_code>49&&key_code<58&&oElement.value.length==3){oElement.value+="0";}oElement.value+=String.fromCharCode(key_code);if((oElement.value.length==2)||(oElement.value.length==5)){oElement.value+="/";}if(oElement.value.length==7){if(key_code==49){oElement.value+="9";}else if(key_code==50){oElement.value+="0";}}}}if(key_code==8){if((oElement.value.length==3)||(oElement.value.length==6)){oElement.value=oElement.value.substring(0,oElement.value.length-2);}else{oElement.value=oElement.value.substring(0,oElement.value.length-1);}window.event.returnValue=0;}if(key_code!=9){event.returnValue=false;}if((arguments.length==1)&&(param=="yyyy")){if(oElement.value&& !oElement.value.match(new RegExp('([1-2]{1}[0-9.]*?)?$')))oElement.value=oElement.value.substring(0,oElement.value.length-1);}else{if(oElement.value&& !oElement.value.match(new RegExp('^[0-3]{1}[0-9]?\/?([0-1]{1}([0-9]{1}\/?([1-2]{1}[0-9]*?)?)?)?$')))oElement.value=oElement.value.substring(0,oElement.value.length-1);}}