(function($){

	$.fn.alphanumeric = function(p) { 

		p = $.extend({
			ichars: "!@#$%^&*()+=[]\\\';,/{}|\":<>?~`.- ",
			nchars: "",
			allow: ""
		  }, p);	

		return this.each
			(
				function() 
				{

					if (p.nocaps) p.nchars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
					if (p.allcaps) p.nchars += "abcdefghijklmnopqrstuvwxyz";
					
					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).keypress
						(
							function (e)
								{
								
									if (!e.charCode) k = String.fromCharCode(e.which);
										else k = String.fromCharCode(e.charCode);
										
									if (ch.indexOf(k) != -1) e.preventDefault();
									if (e.ctrlKey&&k=='v') e.preventDefault();
									
								}
								
						);
						
					$(this).bind('contextmenu',function () {return false});
									
				}
			);

	};

	$.fn.numeric = function() {
		if($.browser.msie)
		{
			$(this).css({imeMode:"disabled",'-moz-user-select':"none"});
			$(this).bind("keydown",function(e){
				if(/\D/g.test($(this).val()))
					$(this).val($(this).val().replace(/\D/g,''));
			})
			.bind("dragenter",function(){return false})			
			.bind("contextmenu",function(){return false;})
			.bind("selectstart",function(){return false;})
			.bind("paste",function(){return false;});
		}
		else
		{
			$(this).css({imeMode:"disabled",'-moz-user-select':"none"});
			$(this).bind("keydown",function(e){
				if(e.ctrlKey == true || e.shiftKey == true || e.spaceKey== true)
				return false;
				if((((e.which >= 48 && e.which <= 57) || (e.which>=96 && e.which<=105)) && e.ctrlKey == false && e.shiftKey == false) || e.which == 0 || e.which == 8)
					return true;
				else if(e.ctrlKey == true && (e.which == 99 || e.which == 118))
					return false;
				else
					return false;
			})
			
			.bind("contextmenu",function(){return false;})
			.bind("selectstart",function(){return false;})
			.bind("dragenter",function(){return false})
			.bind("paste",function(){return false;});
			
			var src=document.getElementById($(this).attr("id"));
			src.addEventListener("dragover",function(){var src=document.getElementById($(this).attr("id")),svalue=src.value;(function(){document.onmousemove=function(){src.value=svalue;document.onmousemove=null;}})()},true);
		}
	};
	
	$.fn.alpha = function(p) {

		var nm = "1234567890";

		p = $.extend({
			nchars: nm
		  }, p);	

		return this.each (function()
			{
				$(this).alphanumeric(p);
			}
		);
			
	};	

})(jQuery);
