function insertIntoInput(input, text, replaceAll) {
	if (replaceAll) {
		input.value = text;
	} else {
		input.focus();
		/* for Internet Explorer */
		if (typeof document.selection != 'undefined') {
			var range = document.selection.createRange();
			range.text = text;
			/* adjust cursor position */
			range = document.selection.createRange();
			range.moveStart('character', text);
			range.select();
		}
		/* for Gecko based browsers */
		else if (typeof input.selectionStart != 'undefined') {
			var start = input.selectionStart;
			var end = input.selectionEnd;
			input.value = input.value.substr(0, start) + text
					+ input.value.substr(end);
			/* adjust cursor position */
			var pos;
			if (text.length == 0) {
				pos = start;
			} else {
				pos = start + text.length;
			}
			input.selectionStart = pos;
			input.selectionEnd = pos;
		}
	}
}
