/**
 * Allows integer input only with a maximum limit
 * Usage: ("input.minutes").maxInt(60);
 * @author aerjotl
 */
(function($){
	jQuery.fn.maxInt = function(max) {
	
		this.each(function(){
			$(this).bind("blur", function() {
				if ($(this).val().length<1) 
					return;
				else if (isNaN($(this).val()))
					$(this).val('00');
				else if (max>10 && String($(this).val()).length < 2)
					$(this).val('0'+$(this).val());
				else if ($(this).val()>max)
					$(this).val(max);
			});
		});
		return this;
	};

	jQuery.fn.bindMinutes = function() {
	
		this.each(function(){
			$(this).bind("blur", function() {
				
				var id = $(this).attr("name").substring(7);
				var min = $("[name=time_m_"+id+"]");

				if (min && $(this).val().length<1) 
					min.val('');
				else if (min && min.val().length<1) 
					min.val('00');

				

			});
		});
		return this;
	};
})(jQuery);

