function cutContent(text) {
	var oldInd = 0;
	var ind = 40;
	var newInd = ind;
	var cutText = [];
	var c = 0;
	for (newInd; oldInd < text.length; newInd += ind) {
		if (newInd > text.length) {
			newInd = text.length;
			cutText[c] = text.substring(oldInd, newInd) + '\n';
			oldInd = text.length;
		}
		else {
			for (newInd; text.charAt(newInd) != " "; newInd--) {};
			cutText[c] = text.substring(oldInd, newInd) + '\n';
			oldInd = newInd;
		}
		c++;
	}
	return cutText;
}
	
	
function getSelectedText() {
		if (window.getSelection) {
			return window.getSelection().toString();
		}
	else if (document.getSelection) {
			return document.getSelection( );
		}
	else if (document.selection) {
			return document.selection.createRange().text;
		}
}
	
	
function insertQuote(){
		var text = ''			
		text = getSelectedText();			
		text = text.replace('\n', '');
		text = text.replace('\r', '');
		
		if(text.length == 0){
			alert('Для цитирования следует выделить мышкой цитируемый текст');			
		}
		else{
			text_str = cutContent(text).join('>');
			document.forms.formtext.comment.value+='\n> ' +  text_str + '\n';	
		}
		text = ''		
	}
