function writeBBCode(formname, textareaid, noIMG, noYT, noAL) {
var str='';
str+='<div class="editorOptions"><div class="bb bbB"><a href="javascript:void(0);" onclick="surroundText(\'[b]\', \'[\/b]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bb bbI"><a href="javascript:void(0);" onclick="surroundText(\'[i]\', \'[\/i]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bb bbU"><a href="javascript:void(0);" onclick="surroundText(\'[u]\', \'[\/u]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bb bbS"><a href="javascript:void(0);" onclick="surroundText(\'[s]\', \'[\/s]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div>';

// align text?
if(noAL!=1) {
	str+='<div class="bbSep"><\/div><div class="bb bbL"><a href="javascript:void(0);" onclick="surroundText(\'[left]\', \'[\/left]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bb bbC"><a href="javascript:void(0);" onclick="surroundText(\'[center]\', \'[\/center]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bb bbR"><a href="javascript:void(0);" onclick="surroundText(\'[right]\', \'[\/right]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bbSep"><\/div>';
}

// IMG tag?
if(noIMG!=1){
	str+='<div class="bb bbIm"><a href="javascript:void(0);" onclick="surroundText(\'[img]\', \'[\/img]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div>';
}
// YT tag?
if(noYT!=1){
	str+='<div class="bb bbYT"><a href="javascript:void(0);" onclick="surroundText(\'[youtube]\', \'[\/youtube]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div>';
}

str+='<div class="bb bbURL"><a href="javascript:void(0);" onclick="surroundText(\'[url]\', \'[\/url]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bbSep"><\/div><div class="bb bbCo"><a href="javascript:void(0);" onclick="surroundText(\'[code]\', \'[\/code]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bb bbQ"><a href="javascript:void(0);" onclick="surroundText(\'[quote]\', \'[\/quote]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bbSep"><\/div><div class="bb bbLi"><a href="javascript:void(0);" onclick="surroundText(\'[list][*]\', \'[*]second item[\/list]\', document.'+formname+'.'+textareaid+'); return false;"><\/a><\/div><div class="bb bbSmile"  onmouseover="document.getElementById(\'smilieBox\').style.display=\'block\'" onmouseout="document.getElementById(\'smilieBox\').style.display=\'none\'"><a href="javascript:void(0);" onmouseover="document.getElementById(\'smilieBox\').style.display=\'block\'" onmouseout="document.getElementById(\'smilieBox\').style.display=\'none\'"><\/a>';
str+='<br \/><div id="smilieBox" >';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :) \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/smiley.png" align="bottom" alt="Smiley" title="Smiley" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' ;) \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/wink.png" align="bottom" alt="Wink" title="Wink" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :D \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/grin.png" align="bottom" alt="Grin" title="Grin" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :angry: \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/angry.png" align="bottom" alt="Angry" title="Angry" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :( \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/sad.png" align="bottom" alt="Sad" title="Sad" border="0" \/><\/a>';
str+='';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :o \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/shocked.png" align="bottom" alt="Shocked" title="Shocked" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' 8) \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/cool.png" align="bottom" alt="Cool" title="Cool" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :P \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/tongue.png" align="bottom" alt="Tongue" title="Tongue" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :blush: \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/embarassed.png" align="bottom" alt="Embarrassed" title="Embarrassed" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :X \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/lipsrsealed.png" align="bottom" alt="Lips Sealed" title="Lips Sealed" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :/ \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/undecided.png" align="bottom" alt="Undecided" title="Undecided" border="0" \/><\/a>';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :* \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/kiss.png" align="bottom" alt="Kiss" title="Kiss" border="0" \/><\/a>';
str+='';
str+='					<a href="javascript:void(0);" onclick="replaceText(\' :cry: \', document.'+formname+'.'+textareaid+'); document.getElementById(\'smilieBox\').style.display=\'none\'; return false;"><img src="\/images\/icons\/smileys\/cry.png" align="bottom" alt="Cry" title="Cry" border="0" \/><\/a>';
str+='<\/div><\/div><\/div>';
document.write(str);
}

// add highlighting box around buttons
function bbcode_highlight(something, mode){
	something.style.backgroundImage = "url(" + (mode ? "/images/bbcode/bbcode_hoverbg.png)" : "/images/bbcode/bbcode_bg.png)");
}


// for inserting smilies
function replaceText(text, textarea)
{
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
	{
		var caretPos = textarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
		caretPos.select();
	}
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);
		var scrollPos = textarea.scrollTop;
		textarea.value = begin + text + end;
		if (textarea.setSelectionRange)
		{
			textarea.focus();
			textarea.setSelectionRange(begin.length + text.length, begin.length + text.length);
		}
		textarea.scrollTop = scrollPos;
	}
	else
	{
		textarea.value += text;
		textarea.focus(textarea.value.length - 1);
	}
}

// add bbcode around selected text
function surroundText(text1, text2, textarea)
{
	if (typeof(textarea.caretPos) != "undefined" && textarea.createTextRange)
	{
		var caretPos = textarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text1 + caretPos.text + text2 + ' ' : text1 + caretPos.text + text2;
		caretPos.select();
	}
	else if (typeof(textarea.selectionStart) != "undefined")
	{
		var begin = textarea.value.substr(0, textarea.selectionStart);
		var selection = textarea.value.substr(textarea.selectionStart, textarea.selectionEnd - textarea.selectionStart);
		var end = textarea.value.substr(textarea.selectionEnd);
		var newCursorPos = textarea.selectionStart;
		var scrollPos = textarea.scrollTop;
		textarea.value = begin + text1 + selection + text2 + end;
		if (textarea.setSelectionRange)
		{
			if (selection.length == 0)
				textarea.setSelectionRange(newCursorPos + text1.length, newCursorPos + text1.length);
			else
				textarea.setSelectionRange(newCursorPos, newCursorPos + text1.length + selection.length + text2.length);
			textarea.focus();
		}
		textarea.scrollTop = scrollPos;
	}
	else
	{
		textarea.value += text1 + text2;
		textarea.focus(textarea.value.length - 1);
	}
}