﻿
(function($) {

	$.fn.forceUpperCase = function() {

		$(this).change(function(e) {
			$(this).val(String($(this).val()).toUpperCase());
			return false;
		});

		$(this).keypress(function(event) {
			if (event.which >= 32 && !(event.altKey || event.ctrlKey || event.metaKey)) {
				var myValue = String.fromCharCode(event.which).toUpperCase();

				if (document.selection) {
					this.focus();
					sel = document.selection.createRange();
					sel.text = myValue;
					sel.select();
				}
				//MOZILLA/NETSCAPE support
				else if (this.selectionStart || this.selectionStart == '0') {
					var startPos = this.selectionStart;
					var endPos = this.selectionEnd;
					var scrollTop = this.scrollTop;
					this.value = this.value.substring(0, startPos) + myValue + this.value.substring(endPos, this.value.length);
					this.focus();
					this.selectionStart = startPos + myValue.length;
					this.selectionEnd = startPos + myValue.length;
					this.scrollTop = scrollTop;
				}
				else {
					this.value += myValue;
					this.focus();
				}
				return false;
			}
			return true;

		});


		return this;
	};





})(jQuery);
