var PioenPartners_JS_Mask={checkMask:function(loEvent,loElement,lcMask){var loPasteExpr=/[\x00\x03\x08\x0D\x16\x18\x1A]/;var loKeysExpr=/^(8|9|13|16|17|20|35|36|37|38|39|40|46){1}$/;llEdited=false;if(typeof paChanged!='undefined'){paChanged[paChanged.length]=loElement.name;}
lcInputChar=String.fromCharCode(loEvent.keyCode);if(!loKeysExpr.test(loEvent.keyCode)&&!loPasteExpr.test(lcInputChar)){if(loEvent.keyCode==109){lcInputChar='-';}
if(loEvent.keyCode>=96&&loEvent.keyCode<=105){lcInputChar=String.fromCharCode(loEvent.keyCode-48);}
lnSelStart=PioenPartners_JS_Mask.getSelStart(loElement)-1;do{lnSelStart++;}while(lcMask.substr(lnSelStart,1)!='#'&&lcMask.substr(lnSelStart,1)!='!'&&lnSelStart<lcMask.length);lcMaskChar=lcMask.substr(lnSelStart,1);if(lcMaskChar=='#'||lcMaskChar=='!'){if(lcMaskChar=='#'){loRegExpr=/[0-9]{1}/;}else if(lcMaskChar=='!'){loRegExpr=/[a-zA-Z]{1}/;}
if(loRegExpr.test(lcInputChar)){lcEleChar=loElement.value.substr(lnSelStart,1);if(lcEleChar!=''||lcEleChar!=' '){lcReplace=loElement.value.substr(0,lnSelStart);lcReplace+=lcInputChar;lcReplace+=loElement.value.substr(lnSelStart+1);loElement.value=lcReplace;llEdited=true;}else{loElement.value+=lcInputChar;llEdited=true;}}}else{if(lcMaskChar==lcInputChar){loElement.value+=lcInputChar;llEdited=true;}}}else{return true;}
lcReplace='';for(var lnI=0;lnI<lcMask.length;lnI++){lcMaskChar=lcMask.substr(lnI,1);lcEleChar=loElement.value.substr(lnI,1);if(lcMaskChar=='#'||lcMaskChar=='!'){if(lcEleChar==''){lcReplace+=' ';}else{lcReplace+=lcEleChar;}}else{if(lcEleChar==''||lcEleChar==' '){lcReplace+=lcMaskChar;}else{lcReplace+=lcEleChar;}}}
loElement.value=lcReplace;if(llEdited==true){do{lnSelStart++;}while(lcMask.substr(lnSelStart,1)!='#'&&lcMask.substr(lnSelStart,1)!='!'&&lnSelStart<lcMask.length);}
if(loElement.createTextRange){loRange=loElement.createTextRange();loRange.moveStart("character",lnSelStart);loRange.select();}else{loElement.selectionStart=lnSelStart;}
return false;},getSelStart:function(loElement){if(loElement.createTextRange){loRange=document.selection.createRange().duplicate();loRange.moveEnd('character',loElement.value.length);if(loRange.text==''){return loElement.value.length;}else{return loElement.value.lastIndexOf(loRange.text);}}else{return loElement.selectionStart;}},isValid:function(loElement,lcMask){if(loElement.value.length!=lcMask.length){return false;}
for(var lnI=0;lnI<lcMask.length;lnI++){lcMaskChar=lcMask.substr(lnI,1);lcEleChar=loElement.value.substr(lnI,1);loRegExpr=null;if(lcMaskChar=='#'){loRegExpr=/[0-9]{1}/;}else if(lcMaskChar=='!'){loRegExpr=/[a-zA-Z]{1}/;}else{if(lcMaskChar!='#'&&lcMaskChar!='!'&&lcMaskChar!=lcEleChar){return false;}}
if(loRegExpr!=null){if(!loRegExpr.test(lcEleChar)){return false;}}}
return true;},checkNumeric:function(loEvent,loElement,llDecimal,llNegative){var loPasteExpr=/[\x00\x03\x08\x0D\x16\x18\x1A]/;var loKeysExpr=/^(8|9|13|16|17|20|35|36|37|38|39|40|46){1}$/;if(typeof paChanged!='undefined'){paChanged[paChanged.length]=loElement.name;}
lcInputChar=String.fromCharCode(loEvent.keyCode);if(!loKeysExpr.test(loEvent.keyCode)&&!loPasteExpr.test(lcInputChar)){if(loEvent.keyCode>=48&&loEvent.keyCode<=57||loEvent.keyCode>=96&&loEvent.keyCode<=105){return true;}
if(loEvent.keyCode==188&&llDecimal==true){if(loElement.value.indexOf(',')==-1){return true;}}
if((loEvent.keyCode==109||loEvent.keyCode==189)&&llNegative==true){if(loElement.value!='-'&&loElement.value.indexOf('-')==-1){return true;}}}else{return true;}
return false;},isNumeric:function(loElement,llDecimal,llNegative){llIsNumeric=true;llCommaExists=false;lcValidChars="0123456789";lcElementValue=loElement.value;for(var lnI=0;lnI<lcElementValue.length;lnI++){lcChar=lcElementValue.charAt(lnI);if(llDecimal==true&&lcChar==","&&llCommaExists==false){llCommaExists=true;}else if(llNegative==true&&lcChar=="-"){if(lnI!=0){llIsNumeric=false;}}else if(lcValidChars.indexOf(lcChar)==-1){llIsNumeric=false;}}
if(llIsNumeric==true){llIsNumeric=!isNaN(lcElementValue.replace(",","."));}
return llIsNumeric;}};
