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