﻿(function($){

	$.fn.allowChars = function(p) { 

		return this.each
			(
				function() 
				{

					if (p.type == 'number') if(p.ychars){p.ychars += "1234567890"}else{p.ychars="1234567890"};
					if (p.type == 'system') if(p.nchars){p.nchars += "!@#$%^&*()+=[]\\\';,/{}|\":<>?~`.- "}else{p.nchars="!@#$%^&*()+=[]\\\';,/{}|\":<>?~`.- "};
					if (p.type == 'search') if(p.nchars){p.nchars += "@#$^*()+=[]';,{}|\":<>~`"}else{p.nchars="@#$^*()+=[]';,{}|\":<>~`"};
					
					var ych = p.ychars;
					var nch = p.nchars;
					
					$(this).keypress
						(
							function (e){
									if($.browser.msie)
										e_charCode = e.keyCode;
									else
										e_charCode = e.charCode;

									k = String.fromCharCode(e_charCode);
									
									if(e_charCode > 0){
										
										if (nch){
											//alert(nch);
											if (nch.indexOf(k) != -1)
												e.preventDefault();
											}
										else if (ych){
												if (ych.indexOf(k) == -1)
													e.preventDefault();
											}
									

									if (e.ctrlKey&&k=='v') e.preventDefault();
									}
								}
								
						);
						
					$(this).bind('contextmenu',function () {return false});
									
				}
			);

	};

})(jQuery);
