﻿/**
 * jQuery numeric
 *
 * Copyright (c) 2009 FINTER
 *
 * Check [0-9] (ONLY POSITIV!) on the fly and allow "<-" "->" "backspace".
 * Supprot mousewheel
 * 
 * Depends: mousewheel plugin
 */
 
jQuery.fn.numeric = function() {
	return this.each(function(){
		$(this).keydown(function (e) {
			return (e.which >= 48 && e.which <= 57 && !e.shiftKey) 
				|| (e.which >= 96 && e.which <= 105 && !e.shiftKey) // numpad
				|| e.which == 8 	// "backspace"
				|| e.keyCode == 37  // "<--"
				|| e.keyCode == 39  // "-->"
				|| e.keyCode == 116;// "F5"
		});
		$(this).keyup(function () { $(this).change(); } );
		
		// this feature is buggy now .. :( 
		/*$(this).mousewheel(function(e, delta){
			var value = $(this).val();
			var maxlen = $(this).attr("maxlength");
			var valueup = (value - 1) + 2; // typecast
			
			if (delta < 0 && value == 0) return true; // ONLY POSITIV! :D
			if (delta > 0 && String(valueup).length > maxlen) return true; // maxlength check
			
			$(this).val(delta > 0 ? valueup : value - 1); 
			$(this).change();
			return true;
		});*/
	});
};

