var zChar=new Array(' ','(',')','-','.');var maxphonelength=14;var phonevalue1;var phonevalue2;var cursorposition;function ParseForNumber1(a){phonevalue1=ParseChar(a.value,zChar)}function ParseForNumber2(a){phonevalue2=ParseChar(a.value,zChar)}function phoneUp(a,e){if(e){e=e}else{e=window.event}if(e.which){var b=e.which}else{var b=e.keyCode}ParseForNumber1(a);if(b>=48){ValidatePhone(a)}}function phoneDown(a,e){if(e){e=e}else{e=window.event}if(e.which){var b=e.which}else{var b=e.keyCode}ParseForNumber2(a)}function GetCursorPosition(){var a=phonevalue1;var b=phonevalue2;var c=false;for(i=0;i<a.length;i++){if(a.substring(i,1)!=b.substring(i,1)){if(!c){cursorposition=i;window.status=cursorposition;c=true}}}}function ValidatePhone(a){var p=phonevalue1;p=p.replace(/[^\d]*/gi,"");if(p.length<3){a.value=p}else if(p.length==3){pp=p;d4=p.indexOf('');d5=p.indexOf('-');if(d4==-1){pp=""+pp}if(d5==-1){pp=pp+"-"}a.value=pp}else if(p.length>3&&p.length<7){p=""+p;l30=p.length;p30=p.substring(0,3);p30=p30+"-";p31=p.substring(3,l30);pp=p30+p31;a.value=pp}else if(p.length>=7){p=""+p;l30=p.length;p30=p.substring(0,3);p30=p30+"-";p31=p.substring(3,l30);pp=p30+p31;l40=pp.length;p40=pp.substring(0,7);p40=p40+"-";p41=pp.substring(7,11);ppp=p40+p41;a.value=ppp.substring(0,maxphonelength)}GetCursorPosition();if(cursorposition>=0){if(cursorposition==0){cursorposition=2}else if(cursorposition<=2){cursorposition=cursorposition+1}else if(cursorposition<=4){cursorposition=cursorposition+3}else if(cursorposition==5){cursorposition=cursorposition+3}else if(cursorposition==6){cursorposition=cursorposition+3}else if(cursorposition==7){cursorposition=cursorposition+4}else if(cursorposition==8){cursorposition=cursorposition+4;e1=a.value.indexOf(')');e2=a.value.indexOf('-');if(e1>-1&&e2>-1){if(e2-e1==4){cursorposition=cursorposition-1}}}else if(cursorposition==9){cursorposition=cursorposition+4}else if(cursorposition<11){cursorposition=cursorposition+3}else if(cursorposition==11){cursorposition=cursorposition+1}else if(cursorposition==12){cursorposition=cursorposition+1}else if(cursorposition>=13){cursorposition=cursorposition}}}function ParseChar(a,b){if(b.length==null){zChar=new Array(b)}else zChar=b;for(i=0;i<zChar.length;i++){sNewStr="";var c=0;var d=a.indexOf(b[i]);while(d!=-1){sNewStr+=a.substring(c,d);c=d+1;d=a.indexOf(b[i],c)}sNewStr+=a.substring(a.lastIndexOf(b[i])+1,a.length);a=sNewStr}return sNewStr}
