//bbcode editor
var b = 2;
var i = 2;
var u = 2;
var s = 2;
var small = 2;
var q = 2;
var url = 2;
var quote = 2;

function tag(v, tagadd, newbut, tagclose, oldbut, name) {
	var txt = window.document.commentForm.comment;
	
	if (document.selection) {
		theSelection = document.selection.createRange().text;
		if (theSelection) {
		document.selection.createRange().text = tagadd + theSelection + tagclose;
		txt.focus();
		theSelection = '';
		}
		else{
		if (eval(v)%2 == 0) {
 		document.getElementById(name).value = newbut;
        txt.focus();
		sel = document.selection.createRange();
		sel.text = tagadd;
    } else {
		document.getElementById(name).value = oldbut;
        txt.focus();
		sel = document.selection.createRange();
		sel.text = tagclose;
    }
	}
    eval(v+"++;");
		}
else{
	if((txt.value).substring(txt.selectionStart, txt.selectionEnd) != ''){
	   	txt.value = (txt.value).substring(0, txt.selectionStart) + tagadd + (txt.value).substring(txt.selectionStart, txt.selectionEnd) + tagclose + (txt.value).substring(txt.selectionEnd, txt.textLength);
		return;
		}
		else{
    if (eval(v)%2 == 0) {
 		document.getElementById(name).value = newbut;
        txt.value = (txt.value).substring(0, txt.selectionStart) + tagadd + (txt.value).substring(txt.selectionEnd, txt.textLength);
        txt.focus();
    } else {
        document.getElementById(name).value = oldbut;
        txt.value = (txt.value).substring(0, txt.selectionStart) + tagclose + (txt.value).substring(txt.selectionEnd, txt.textLength);
        txt.focus();
    }
    eval(v+"++;");
	}
}
}

bold_help = "Bold text: [b]text[/b]";
italic_help = "Italic text: [i]text[/i]";
underline_help = "Underline text: [u]text[/u]";
strikethrough_help = "Strikethrough text: [s]text[/s]";
small_help = "Small text: [small]text[/small]";
url_help = "Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url]";
quote_help = "Quote text: [quote]text[/quote] or [quote=name]text[/quote]";
clear_help = "";
//Function for displaying help information

// Shows the help messages in the helpline window
function helpline(help) {
        var helpbox = document.getElementById('helpbox');
        helpbox.innerText = eval(help + "_help");	// for IE
		helpbox.textContent = eval(help + "_help");

		//document.getElementById("helpbox").innerText = document.getElementById("note_1").innerText; // for IE
		//document.getElementById("helpbox").textContent = document.getElementById("note_1").textContent;
}