//
// Adds a "selectRange" function to jQuery objects that allows us to select a
// specific range of text in a control (pass null for start and length to select all)
//
jQuery.fn.selectRange = function(start, length)
{
	if (start == null)
	{
		start = 0;
	}

	return this.each(function()
	{
		var end = length;
		if (end == null)
		{
			end = this.value.length - start;
		}
		else
		{
			end += start;
		}

		if (this.setSelectionRange)
		{
			this.focus();
			this.setSelectionRange(start, end);
		}
		else if (this.createTextRange)
		{
			var range = this.createTextRange();
			range.collapse(true);
			range.moveEnd('character', end);
			range.moveStart('character', start);
			range.select();
		}
	});
};

//
// Adds an event handler to the given jQuery to only allow numbers to be typed in to a field
//
jQuery.fn.numbersOnly = function()
{
	return this.keydown(function(e)
	{
		if
		(
			(e.which >= 48 && e.which <= 57)		//numbers
			|| (e.which >= 96 && e.which <= 105)	//numpad numbers
			|| e.which == 8							//backspace
			|| e.which == 46						//delete
			|| e.which == 9							//tab
			|| e.which == 37						//left arrow
			|| e.which == 39						//right arrow
		)
		{
		}
		else
		{
			e.preventDefault();
		}
	});
}
