var isNav = (document.layers)
var isIE = (document.all)
var isN6=((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function"));

function AddText(NewCode) {
document.form1.Body.value+=NewCode
}

function bold() {
	var r;
	r=document.selection.createRange();
	if (document.selection.type=="None")	{
		AddTxt="[b][/b]";
		AddText(AddTxt);
	} else {
			r.text="[b]"+r.text+"[/b]";
			AddText(r.text);
	}
}

function italicize() {
	var r;
	r=document.selection.createRange();
	if (document.selection.type=="None")	{
		AddTxt="[i][/i]";
		AddText(AddTxt);
	} else {
			r.text="[i]"+r.text+"[/i]";
			AddText(r.text);
	}
}

function quote() {
	var r;
	r=document.selection.createRange();
	if (document.selection.type=="None")	{
		AddTxt=" [quote] [/quote]";
		AddText(AddTxt);
	} else {
			r.text=" [quote] "+r.text+" [/quote]";
			AddText(r.text);
	}
}

function hyperlink() {
		if (document.selection.type=="None")	{
		AddTxt="[url][/url]";
		AddText(AddTxt);
		} else {
		var r;
		r=document.selection.createRange();
		r.txt2=r.text;
		if (r.txt2=="") {
					r.text="[url]"+r.text+"[/url]";
					AddText(r.text);
				} else {
					r.text="[url=\""+r.text+"\"]"+r.txt2+"[/url]";
					AddText(r.text);
				}         
	}
}

function image() {
		var r;
		r=document.selection.createRange();
		if (document.selection.type=="None")	{
		AddTxt="[img][/img]";
		AddText(AddTxt);
	} else {
			r.text="[img]"+r.text+"[/img]";
			AddText(r.text);        
	}
}

function showcode() {
		var r;
		r=document.selection.createRange();
		if (document.selection.type=="None")	{
		AddTxt=" [code] [/code]";
		AddText(AddTxt);
	} else {
			r.text=" [code] "+r.text+" [/code]";
			AddText(r.text);        
	}
}

function underline() {
		var r;
		r=document.selection.createRange();
		if (document.selection.type=="None")	{
		AddTxt="[u][/u]";
		AddText(AddTxt);
	} else {
			r.text="[u]"+r.text+"[/u]";
			AddText(r.text);        
	}
}

function email() {
	if (document.selection.type=="None")	{
	AddTxt="[email][/email]";
	AddText(AddTxt);
	} else {
	var r;
	r=document.selection.createRange();
	r.txt2=r.text;
	r.text="[email]"+r.text+"[/email]";
	AddText(r.text);
	}
}

function InsText (field, str) {
	if (field.createTextRange && field.caretPos) {
		var caretPos = field.caretPos;
		caretPos.text =
			caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
			str + ' ' : str;
	} else {
		field.value  = field.value + str; // for non MSIE browsers just append it
	}
	return true;
}

function DoPrompt(action) {
	var currentMessage = document.form1.Body.value;
	if (action == "url") {
		var thisURL = prompt("Введите полный URL к ссылке, которую Вы хотите добавить.", "http://");
		if (thisURL == null){return;}
		var thisTitle = prompt("Введите краткое описание ссылки.", "web page");
		if (thisTitle == null){return;}
		InsText(document.form1.Body, "[URL=" + thisURL + "]" + thisTitle + "[/URL]" + ' ');
		document.form1.Body.focus();
		return;
	}
	if (action == "email") {
		var thisEmail = prompt("Введите полный e-mail адрес, который Вы хотите добавить.", "");
		if (thisEmail == null){return;}
		InsText(document.form1.Body, ' ' + "[EMAIL]" + thisEmail + "[/EMAIL]" + ' ' );
		document.form1.Body.focus();
		return;
	}
	if (action == "bold") {
		var thisBold = prompt("Введите текст, который Вы хотите выделить жирным.", "");
		if (thisBold == null){return;}
		InsText(document.form1.Body, ' ' + "[B]" + thisBold + "[/B]" + ' ' );
		document.form1.Body.focus();
		return;
	}
	if (action == "italics") {
		var thisItal = prompt("Введите текст, который Вы хотите выделить курсивом.", "");
		if (thisItal == null){return;}
		InsText(document.form1.Body, ' ' + "[I]" + thisItal + "[/I]" + ' ' );
		document.form1.Body.focus();
		return;
	}
	if (action == "quote") {
		InsText(document.form1.Body, ' ' + "[QUOTE]  [/QUOTE]" + ' ' );
		document.form1.Body.focus();
		return;
	}
	if (action == "code") {
		InsText(document.form1.Body, ' ' + "[CODE]  [/CODE]" + ' ' );
		document.form1.Body.focus();
		return;
	}
} 

