function sm(s) {
document.release_form.body.value=document.release_form.body.value+s+" ";
document.release_form.body.focus();
}

function sm2(s) {
document.release_form.head.value=document.release_form.head.value+s+" ";
document.release_form.head.focus();
}

function sm3(s) {
document.release_form.fullrelease.value=document.release_form.fullrelease.value+s+" ";
document.release_form.fullrelease.focus();
}

function bb(obj, stag, etag)
{
	r=document.selection.createRange();
	if( document.selection.type == 'Text' && (obj.value.indexOf(r.text) != -1) ) {
		a = r.text;
		r.text = stag+r.text+etag;
		if ( obj.value.indexOf(document.selection.createRange().text) == -1 ) {
			document.selection.createRange().text = a;
		}
	}
	else insertAtCaret(obj, stag+etag);	
}

function storeCaret(textEl)
{
	 if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret(textEl, text)
{

        if (textEl.createTextRange && textEl.caretPos)
	{
		var caretPos = textEl.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	}
	else 
		textEl.value  =  textEl.value + text;
}

function dialogTag(obj, qst, def, stag, etag)
{
var q;
	q = prompt(qst, def);
	if ( !q ) return;
	stag = stag.replace(/%s/i, q);
	sm1(obj, stag, etag);
}



function image_insert_head()
{
	dialogTag(document.release_form.head, 'Впишите ссылку на рисунок в строке ниже:', 'http://', '[img]%s[/img]', '');
}

function image_insert_body()
{
	dialogTag(document.release_form.body, 'Впишите ссылку на рисунок в строке ниже:', 'http://', '[img]%s[/img]', '');
}

function image_insert_fullrelease()
{
	dialogTag(document.release_form.fullrelease, 'Впишите ссылку на рисунок в строке ниже:', 'http://', '[img]%s[/img]', '');
}

function url_insert_head()
{
	dialogTag(document.release_form.head, 'Впишите ссылку в строке ниже:', 'http://', '[url]%s[/url]', '');
}

function url_insert_body()
{
	dialogTag(document.release_form.body, 'Впишите ссылку в строке ниже:', 'http://', '[url]%s[/url]', '');
}

function url_insert_fullrelease()
{
	dialogTag(document.release_form.fullrelease, 'Впишите ссылку в строке ниже:', 'http://', '[url]%s[/url]', '');
}
