$.fn.extend({
	insertAtCaret: function(valueToInsert) {
		sStart = this[0].selectionStart;
		sEnd = this[0].selectionEnd;
		
		// IE
		if(document.selection) {
			this.focus();
			selection = document.selection.createRange();
			selection.text = valueToInsert;
		}
		// Everything else
		else if(sStart) {
			this.val(
				this.val().substring(0, sStart) +
				valueToInsert +
				this.val().substring(sEnd, this.val().length)
			);
		}
		// Fallback
		else {
			this.val(this.val() + valueToInsert);
		}
	}
});

