var KT_focusedEl=null;KT_validateSingle=function(C,B){var A=C.charCodeAt(0);switch(B){case"9":if(A<58&&A>47){return true}break;case"A":if((A<91&&A>64)||(A<123&&A>96)){return true}break;case"X":if((A<91&&A>64)||(A<123&&A>96)||(A<58&&A>47)){return true}break;case"?":return true;break;default:return true;break}};KT_maskDefaultValue=function(A){switch(A){case"9":return"0";break;case"A":return"a";break;case"X":return"0";break;case"?":return"0";break;default:return"0";break}};KT_isSpecialChar=function(A){if(A=="9"||A=="A"||A=="X"||A=="?"){return true}else{return false}};mask_onValueChanged=function(){if((typeof window.getSelection=="undefined"&&typeof document.selection=="undefined")){return }if(KT_focusedEl==null||KT_focusedEl.mask==null||KT_focusedEl.mask==""){return }var A=KT_focusedEl.mask;var E=KT_focusedEl.value;var D=0;var C=false;if(E==KT_focusedEl.oldText){return }if(E.length>A.length){E=E.substr(0,A.length);C=true}for(;D<A.length;D++){if(E.charCodeAt(D).toString()!="NaN"){if(KT_isSpecialChar(A.charAt(D))){if(KT_validateSingle(E.charAt(D),A.charAt(D))){continue}else{E=KT_focusedEl.oldText;D=A.length;break}}else{if(E.charAt(D)!=A.charAt(D)){if(D==E.length-1){var B=E.substr(E.length-1,E.length);E=E.substr(0,E.length-1)+A.charAt(D)+B;C=true;continue}else{E=KT_focusedEl.oldText;D=A.length}break}}}else{if(E.length<KT_focusedEl.oldText.length){break}for(;D<A.length;D++){if(!KT_isSpecialChar(A.charAt(D))){E+=A.charAt(D);C=true}else{break}}break}}if(E.length>A.length){E=E.substr(0,A.length);C=true}if(KT_focusedEl.value!=E){KT_focusedEl.value=E}KT_focusedEl.oldText=E;if(C){}};mask_parseFirstTime=function(A,G){var F="";var D="";cond=1;imask=0;ival=0;cnt=0;while(cond==1){cond=1;if(!KT_isSpecialChar(G.charAt(imask))){if(A.charCodeAt(ival).toString()!="NaN"){if(G.charAt(imask)==A.charAt(ival)){imask++;ival++}else{A=A.substr(0,ival)+G.charAt(imask)+A.substr(ival,A.length);imask=0;ival=0;cond=1}}else{A+=KT_maskDefaultValue(G.charAt(imask))}}else{imask++;ival++}if(imask>=G.length||ival>=A.length){cond=0}}for(i=0;i<G.length;i++){if(KT_isSpecialChar(G.charAt(i))){F+=G.charAt(i);if(A.charCodeAt(i).toString()!="NaN"){D+=A.charAt(i)}else{D+=KT_maskDefaultValue(G.charAt(i))}}}oldvalue=A;A=D;var E="";for(i=0;i<F.length;i++){if(!KT_validateSingle(A.charAt(i),F.charAt(i))){E+=KT_maskDefaultValue(F.charAt(i))}else{E+=A.charAt(i)}}var C="";var B=0;for(i=0;i<G.length;i++){if(KT_isSpecialChar(G.charAt(i))){C+=E.charAt(B++)}else{C+=G.charAt(i)}}return C};mask_onSetFocus=function(B,A){if((typeof window.getSelection=="undefined"&&typeof document.selection=="undefined")){return }if(typeof B.mask=="undefined"){ret="";if(B.value!=""){ret=mask_parseFirstTime(B.value,A)}B.value=ret;B.mask=A}KT_focusedEl=B;if(typeof KT_focusedEl.oldText=="undefined"){KT_focusedEl.oldText=B.value;mask_onValueChanged()}};mask_onKillFocus=function(){if((typeof window.getSelection=="undefined"&&typeof document.selection=="undefined")){return }mask_onValueChanged();KT_focusedEl=null};