// print page on load
var printEl = lm.e('previewContainer');
if (printEl) {
	window.print();
}
var limitflag, textarea;
textarea = lm.e('previewMsg');
if (textarea) {
	limitflag = false;        
	function getCharCount () {
		var keyID, charsLeft, chars;
		charsLeft = lm.e('charsLeft');
		chars = 150 - textarea.value.length;
		charsLeft.innerHTML = chars;
	}
	function getChar (e) {
		var keyId, selection;
		limitflag = (textarea.value.length > 149) ? true : false;
		e = (window.event) ? event : e;
		getCharCount();
		if ((textarea.selectionStart || textarea.selectionStart === 0) && textarea.selectionStart !== textarea.selectionEnd) {  
			limitflag = false;
		} else { 
			if (window.getSelection) { 
				selection = window.getSelection(); 
			} else if (document.getSelection ){ 
				selection = document.getSelection(); 
			} else if (document.selection) { 
				selection = document.selection.createRange().text; 
			} 
			if (selection && selection.length > 0) {
				limitflag = false;		
			}
		} 
		if (limitflag) {
			keyId = e.keyCode;
			if (keyId >= 48 || keyId === 32 || keyId === 13) {
				return false;
			} 
		} 
	}
	textarea.onkeydown = getChar;   
	textarea.onkeyup = getCharCount;  
	getCharCount();
}
