function AddText(NewCode) {
	insertText(document.forms.input.message, NewCode);
}

function email() {
	if (getSelectedText()) {
		wrapText("[email]", "[/email]");
	} else {
		txt2=prompt(email_normal,"");
		if (txt2!=null) {
			txt=prompt(email_normal_input,"name@domain.com");
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[email]"+txt+"[/email]";
				} else {
					AddTxt="[email="+txt+"]"+txt2+"[/email]";
				}
				AddText(AddTxt);
			}
		}
	}
}

function chsize(size) {
	wrapText("[size=" + size + "]", "[/size]");
}

function chfont(font) {
	if (getSelectedText()) {
		wrapText("[font=" + font + "]", "[/font]");
	} else {
		txt=prompt(font_normal,text_input);
		if (txt!=null) {
			AddTxt="[font="+font+"]"+txt;
			AddText(AddTxt);
			AddText("[/font]");
		}
	}
}


function bold() {
	if (getSelectedText()) {
		wrapText("[b]", "[/b]");
	} else {
		txt=prompt(bold_normal,text_input);
		if (txt!=null) {
			AddText("[b]" + txt + "[/b]");
		}
	}
}

function italic() {
	if (getSelectedText()) {
		wrapText("[i]", "[/i]");
	} else {
		txt=prompt(italicize_normal,text_input);
		if (txt!=null) {
			AddText("[i]" + txt + "[/i]");
		}
	}
}

function quote() {
	if (getSelectedText()) {
		wrapText("[quote]", "[/quote]");
	} else {
		txt=prompt(quote_normal,text_input);
		if(txt!=null) {
			AddText("[quote]" + txt + "[/quote]");
		}
	}
}

function chcolor(color) {
	if (getSelectedText()) {
		wrapText("[color=" + color + "]", "[/color]");
	} else {
		txt=prompt(color_normal,text_input);
		if(txt!=null) {
			AddText("[color=" + color + "]" + txt + "[/color]");
		}
	}
}

function center() {
	if (getSelectedText()) {
		var range = document.selection.createRange();
		range.text = "[align=center]" + range.text + "[/align]";
	} else {
		txt=prompt(center_normal,text_input);
		if (txt!=null) {
			AddText("\r[align=center]" + txt + "[/align]");
		}
	}
}

function hyperlink() {
	txt2=prompt(link_normal,"");
	if (txt2!=null) {
		txt=prompt(link_normal_input,"http://");
		if (txt!=null) {
			if (txt2=="") {
				AddTxt="[url]"+txt;
				AddText(AddTxt);
				AddText("[/url]");
			} else {
				AddTxt="[url="+txt+"]"+txt2;
				AddText(AddTxt);
				AddText("[/url]");
			}
		}
	}
}

function image() {
	txt=prompt(image_normal,"http://");
	if(txt!=null) {
		AddText("\r[img]" + txt + "[/img]");
	}
}

function flash() {
	txt=prompt(flash_normal,"http://");
	if(txt!=null) {
		AddText("\r[swf]" + txt + "[/swf]");
	}
}

function code() {
	if (getSelectedText()) {
		wrapText("[code]", "[/code]");
	} else {
		txt=prompt(code_normal,"");
		if (txt!=null) {
			AddText("\r[code]" + txt + "[/code]");
		}
	}
}

function list() {
	txt=prompt(list_normal,"");
	while ((txt!="") && (txt!="A") && (txt!="a") && (txt!="1") && (txt!=null)) {
		txt=prompt(list_normal_error,"");
	}
	if (txt!=null) {
		if (txt=="") {
			AddTxt="\r[list]\r\n";
		} else {
			AddTxt="\r[list="+txt+"]\r";
		}
		txt="1";
		while ((txt!="") && (txt!=null)) {
			txt=prompt(list_normal_input,"");
			if (txt!="") {
				AddTxt+="[*]"+txt+"\r";
			}
		}
		AddTxt+="[/list]\r\n";
		AddText(AddTxt);
	}
}

function underline() {
	if (getSelectedText()) {
		wrapText("[u]", "[/u]");
	} else {
		txt=prompt(underline_normal,text_input);
		if (txt!=null) {
			AddText("[u]" + txt + "[/u]");
		}
	}
}

function insertText(o, val)
{
	//IE support
	if (document.selection)
	{
		o.focus();
		var sel = document.selection.createRange();
		sel.text = val;
		o.focus();
	}
	//MOZILLA/NETSCAPE support
	else if (o.selectionStart || o.selectionStart == 0)
	{
		var startPos = o.selectionStart;
		var endPos = o.selectionEnd;
		o.value = o.value.substring(0, startPos) + val + o.value.substring(endPos, o.value.length);
		o.focus();
		o.selectionStart = startPos + val.length;
		o.selectionEnd = startPos + val.length;
	}
	else
	{
		o.value += val;
		o.focus();
	}
}

function getSelectedText(o)
{
	//IE support
	if (document.selection)
	{
		o.focus();
		var sel = document.selection.createRange();
		return sel.text;
	}
	//MOZILLA/NETSCAPE support
	else if (o.selectionStart || o.selectionStart == 0)
	{
		var startPos = o.selectionStart;
		var endPos = o.selectionEnd;
		return o.value.substring(startPos, endPos);
	}
	else
		return o.value;
}

function wrapText(otag, etag)
{
}