//<!--
function x () {
	return;
}

function DoPrompt(action) {
		if (action == "quote") {
			insertTags('[quote]','[/quote]',' ');
			return;
		}
		if (action == "img") {
			insertTags('[img]','[/img]',' ');
			return;
		}
		if (action == "imgext") {
			insertTags('[img href=http://ссылка_на_большое_фото.jpg ]','[/img]',' http://ссылка_на_превью_фото.jpg ');
			return;
		}
		if (action == "bold") {
			insertTags('[b]','[/b]',' ');
			return;
		}
		if (action == "header") {
			insertTags('[h]','[/h]',' ');
			return;
		}
		if (action == "italic") {
			insertTags('[i]','[/i]',' ');
			return;
		}
		if (action == "url") {
			insertTags('[url=http://ссылка_на_сайт ]','[/url]',' ');
			return;
		}
}

function insertTags( tagOpen, tagClose, sampleText ) {
	var txtarea = document.getElementById( 'edittags' );
	var selText, isSample = false;
	var selected;
	if (window.getSelection) selected = window.getSelection();
	else if (document.getSelection) selected = document.getSelection();
	else selected = document.selection.createRange().text;
	if(selected=='')sampleText = " ";
	else sampleText = "" + selected;
	
	if (document.selection  && document.selection.createRange ) { 
		if ( document.documentElement && document.documentElement.scrollTop ) {
			var winScroll = document.documentElement.scrollTop
		} else if ( document.body ) {
			var winScroll = document.body.scrollTop;
		}
		txtarea.focus();
		var range = document.selection.createRange();
		selText = range.text;
		checkSelectedText();
		range.text = tagOpen + selText + tagClose;
		if ( isSample && range.moveStart ) {
			if ( window.opera ) {
				tagClose = tagClose.replace(/\n/g,'');
			}
			range.moveStart('character', - tagClose.length - selText.length);
			range.moveEnd('character', - tagClose.length);
		}
		range.select();
		if ( document.documentElement && document.documentElement.scrollTop ) {
			document.documentElement.scrollTop = winScroll;
		} else if ( document.body ) {
			document.body.scrollTop = winScroll;
		}

	} else if ( txtarea.selectionStart || txtarea.selectionStart == '0' ) { 
		var textScroll = txtarea.scrollTop;
		txtarea.focus();
		var startPos = txtarea.selectionStart;
		var endPos = txtarea.selectionEnd;
		selText = txtarea.value.substring( startPos, endPos );
		checkSelectedText();
		txtarea.value = txtarea.value.substring(0, startPos)
			+ tagOpen + selText + tagClose
			+ txtarea.value.substring(endPos, txtarea.value.length);
		if ( isSample ) {
			txtarea.selectionStart = startPos + tagOpen.length;
			txtarea.selectionEnd = startPos + tagOpen.length + selText.length;
		} else {
			txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length;
			txtarea.selectionEnd = txtarea.selectionStart;
		}
		txtarea.scrollTop = textScroll;
	}

	function checkSelectedText() {
		if ( !selText ) {
			selText = sampleText;
			isSample = true;
		} else if ( selText.charAt(selText.length - 1) == ' ' ) { 
			selText = selText.substring(0, selText.length - 1);
			tagClose += ' ';
		}
	}

}
//-->

