// Avoid `console` errors in browsers that lack a console.

(function() {

    var method;

    var noop = function noop() {};

    var methods = [

        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',

        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',

        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',

        'timeStamp', 'trace', 'warn'

    ];

    var length = methods.length;

    var console = (window.console = window.console || {});



    while (length--) {

        method = methods[length];



        // Only stub undefined methods.

        if (!console[method]) {

            console[method] = noop;

        }

    }

}());



// Place any jQuery/helper plugins in here.



function getCaretPosition (ctrl) {

	var caretPos = 0;

	if (document.selection) {

		// IE Support

		ctrl.focus ();

		var sel = document.selection.createRange ();

		sel.moveStart ('character', -ctrl.value.length);

		caretPos = sel.text.length;

	} else if (ctrl.selectionStart || ctrl.selectionStart == '0') {

		// Firefox support

		caretPos = ctrl.selectionStart;

	}

	return caretPos;

}

function setCaretPosition(ctrl, pos) {

	if (ctrl.setSelectionRange) {

		ctrl.focus();

		ctrl.setSelectionRange(pos,pos);

	} else if (ctrl.createTextRange) {

		var range = ctrl.createTextRange();

		range.collapse(true);

		range.moveEnd('character', pos);

		range.moveStart('character', pos);

		range.select();

	}

}