﻿/**
 * All rights reserved.
 *
 * /!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!
 * /! ---------------- Kopiowanie zabronione zgodnie z Ustawą z dnia 4 lutego 1994 r. o prawie autorskim i prawach pokrewnych ---------------- /!
 * /! -- (Dz.U. z 1994r. nr 24, poz.83, nr 43, poz. 170; Dz.U. z 1997 r. nr 43, poz. 272, nr 88. poz. 554; Dz.U. z 2000 r. nr 53, poz. 637) -- /!
 * /!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!/!
 *
*/

﻿
(function($){var alphanumericChar={s:"!@#$%^&*()+=[]\\\';,/{}|\":<>?~`.- ",n:"1234567890",l:"ABCDEFGHIJKLMNOPQRSTUVWXYZ\u0104\u017b\u0179\u0106\u0143\u00d3\u0141\u0118",u:"abcdefghijklmnopqrstuvwxyz\u0105\u015b\u017c\u017a\u0107\u0144\u00f3\u0142\u0119",c:'#'};var checkUp=false;$.fn.alphanumeric=function(p){p=$.extend({ichars:alphanumericChar.s,nchars:'',allow:'',format:'',charFormat:alphanumericChar.c,maxChar:0,maxLines:0,ctrlKeyV:false},p);function strToNum(str){var v='';var n=alphanumericChar.n;for(var i=0;i<str.length;i++)
if(n.indexOf(str.charAt(i))!=-1)
v+=str.charAt(i);return v.length?Number(v):null;}
function microtime(){return new Date().getTime();}
function return2br(str){if(str)
return str.replace(/(\r\n|\r|\n)/g,'<br />');}
return this.each(function(){function keypress(e,paste){var _this=this;var count=0;var allChar='';var charCode=e.charCode?e.charCode:e.which;if(p.format!='')
p.maxChar=0;if(p.maxChar>0)
count=$(this).val().length;if(lineHeight==0)
p.maxLines=0;if(p.format!=''||p.maxChar>0||p.maxLines>0)
for(var i in alphanumericChar)
allChar+=alphanumericChar[i];var k=String.fromCharCode(charCode);if(textAreaTest!=null){textAreaTest.html(return2br($(this).val()+(charCode==13?'\n&nbsp;':k)));if(Math.floor(textAreaTest.height()/lineHeight)>p.maxLines&&(allChar.indexOf(k)>-1||charCode==13)){if(e.up){return'';}else{e.preventDefault();}}else{textAreaTest.html(return2br($(this).val()));}}
if(e.ctrlKey&&k=='v'){if(p.ctrlKeyV){checkUp=true;return;}else{e.preventDefault();}}else if(ch.indexOf(k)!=-1||(p.maxChar>0&&count>=p.maxChar&&allChar.indexOf(k)!=-1)){if(e.up){return'';}else{e.preventDefault();}}else if(e.up){_this=e._this;if(p.format=='')
return e.txt+k;}
if(p.format!=''){if(allChar.indexOf(k)!=-1){e.preventDefault();if(p.format!=''){var val=e.up?e.txt:$(_this).val();var txt='';if((p.format.length>val.length+1)&&p.format.charAt(val.length)!=p.charFormat&&val.charAt(val.length)!=p.format.charAt(val.length)){val+=p.format.charAt(val.length);if(k!=p.format.charAt(val.length-1)&&p.format.charAt(val.length)!=p.charFormat){val+=k;}}
var dig='';for(var i=0;i<val.length;i++){if(alphanumericChar.n.indexOf(val.charAt(i))>-1){dig+=val.charAt(i);}};var j=0;for(var i=0;i<val.length;i++){if(p.format.charAt(i)!=p.charFormat&&dig.charAt(j)!=p.format.charAt(i)){txt+=p.format.charAt(i);}else if(alphanumericChar.n.indexOf(dig.charAt(j))>-1){txt+=dig.charAt(j);j++;}}
val=txt;txt='';if(ch.indexOf(k)==-1&&!e.ctrlKey&&val.length<p.format.length)val+=k;var dig='';for(var i=0;i<val.length;i++){if(alphanumericChar.n.indexOf(val.charAt(i))>-1){dig+=val.charAt(i);}};var j=0;for(var i=0;i<p.format.length;i++){if(i>=val.length)break;if(p.format.charAt(i)!=p.charFormat&&dig.charAt(j)!=p.format.charAt(i)){txt+=p.format.charAt(i);}else{txt+=dig.charAt(j);j++;}}
if(p.format.length>txt.length&&p.format.charAt(txt.length)!=p.charFormat){txt+=p.format.charAt(txt.length);}}
if(e.up)
return txt;$(_this).val(txt);}}
if(textAreaTest!=null)
textAreaTest.html(return2br(txt));}
if(p.nocaps)p.nchars+=alphanumericChar.l;if(p.allcaps)p.nchars+=alphanumericChar.u;var lineHeight=0;var textAreaTest=null;if(p.maxLines>0&&this.tagName.toLowerCase()=='textarea'){textAreaTest=$('<div>').attr('id',($(this).attr('name')+$(this).attr('id')+microtime()+Math.random()).toLowerCase()).css({'position':'absolute','left':(-1000-$(this).width())+'px','width':$(this).width()+'px','font-family':$(this).css('font-family'),'font-size':$(this).css('font-size'),'white-space':'-moz-pre-wrap','white-space':'-hp-pre-wrap','white-space':'-o-pre-wrap','white-space':'-pre-wrap','white-space':'pre-wrap','white-space':'pre-line','word-wrap':'break-word'}).html($(this).val());$('body').append(textAreaTest);if($(this).css('line-height')){lineHeight+=strToNum($(this).css('line-height'));if(textAreaTest!=null)
textAreaTest.css('line-height',lineHeight+'px');}else if($(this).css('font-size')){lineHeight+=strToNum($(this).css('font-size'))+1;if(textAreaTest!=null)
textAreaTest.css('font-size',lineHeight+'px');}}
var s=p.allow.split('');for(i=0;i<s.length;i++){if(p.ichars.indexOf(s[i])!=-1){s[i]='\\'+s[i];}}
p.allow=s.join('|');var reg=new RegExp(p.allow,'gi');var ch=p.ichars+p.nchars;ch=ch.replace(reg,'');$(this).keyup(function(e){if(!checkUp){if(textAreaTest)
textAreaTest.html(return2br($(this).val()));return;}
checkUp=false;var v=$(this).val();var txt='';var txt2='';for(var i=0;i<v.length;i++){if(i<p.maxChar||p.maxChar==0){txt=keypress({charCode:v.charCodeAt(i),ctrlKey:false,up:true,_this:this,txt:txt2,preventDefault:e.preventDefault});if(textAreaTest!=null)
textAreaTest.html(return2br(txt));if(textAreaTest!=null&&Math.floor(textAreaTest.height()/lineHeight)>p.maxLines){textAreaTest.html(return2br(txt2));break;}
txt2=txt;}else{break;}}
$(this).val(txt2);if(textAreaTest!=null)
textAreaTest.html(return2br(txt2));});$(this).keypress(keypress);$(this).bind('contextmenu',function(){return false;});});};$.fn.numeric=function(p){p=$.extend({nchars:alphanumericChar.l+alphanumericChar.u},p);return this.each(function()
{$(this).alphanumeric(p);});};$.fn.alpha=function(p){p=$.extend({nchars:alphanumericChar.n},p);return this.each(function()
{$(this).alphanumeric(p);});};})(jQuery);