<div class="mf-codebtns">
<a href="javascript:void(0);" onclick="insertMyCode('b');" title="Bold"><i class="fas fa-bold"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('i');" title="Italic"><i class="fas fa-italic"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('u');" title="Underline"><i class="fas fa-underline"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('s');" title="Strikethrough"><i class="fas fa-strikethrough"></i></a>
<span class="mf-cb-sep"></span>
<a href="javascript:void(0);" onclick="insertMyCode('left');" title="Align Left"><i class="fas fa-align-left"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('center');" title="Center"><i class="fas fa-align-center"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('right');" title="Align Right"><i class="fas fa-align-right"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('justify');" title="Justify"><i class="fas fa-align-justify"></i></a>
<span class="mf-cb-sep"></span>
<a href="javascript:void(0);" onclick="insertMyCode('url');" title="Insert Link"><i class="fas fa-link"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('img');" title="Insert Image"><i class="fas fa-image"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('email');" title="Insert Email"><i class="fas fa-envelope"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('video');" title="Insert Video"><i class="fas fa-video"></i></a>
<span class="mf-cb-sep"></span>
<a href="javascript:void(0);" onclick="insertMyCode('list');" title="Bullet List"><i class="fas fa-list-ul"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('code');" title="Code"><i class="fas fa-code"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('php');" title="PHP Code"><i class="fab fa-php"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('quote');" title="Insert Quote"><i class="fas fa-quote-left"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('hr');" title="Horizontal Rule"><i class="fas fa-minus"></i></a>
<span class="mf-cb-sep"></span>
<a href="javascript:void(0);" onclick="insertMyCode('color');" title="Font Color"><i class="fas fa-palette"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('size');" title="Font Size"><i class="fas fa-text-height"></i></a>
<a href="javascript:void(0);" onclick="insertMyCode('font');" title="Font Name"><i class="fas fa-font"></i></a>
<a href="javascript:void(0);" onclick="removeFormatting();" title="Remove Formatting"><i class="fas fa-eraser"></i></a>
</div>
<script type="text/javascript">
function insertMyCode(tag) {
	var textarea = document.getElementById('message');
	if (!textarea) return;
	var start = textarea.selectionStart;
	var end = textarea.selectionEnd;
	var sel = textarea.value.substring(start, end);
	var before = textarea.value.substring(0, start);
	var after = textarea.value.substring(end);
	if (tag === 'hr') {
		textarea.value = before + '\n[hr]\n' + after;
	} else if (tag === 'list') {
		var items = sel ? sel.split('\n').map(function(l){ return '[*]' + l; }).join('\n') : '[*]';
		textarea.value = before + '[list]\n' + items + '\n[/list]' + after;
	} else if (tag === 'url') {
		var url = prompt('Enter URL:', 'https://');
		if (url) textarea.value = before + '[url=' + url + ']' + (sel || url) + '[/url]' + after;
	} else if (tag === 'img') {
		var imgUrl = prompt('Enter image URL:', 'https://');
		if (imgUrl) textarea.value = before + '[img]' + imgUrl + '[/img]' + after;
	} else if (tag === 'email') {
		var email = prompt('Enter email:', '');
		if (email) textarea.value = before + '[email]' + email + '[/email]' + after;
	} else if (tag === 'video') {
		var vidUrl = prompt('Enter video URL:', 'https://');
		if (vidUrl) textarea.value = before + '[video=' + (vidUrl.includes('youtube') ? 'youtube' : 'dailymotion') + ']' + vidUrl + '[/video]' + after;
	} else if (tag === 'color') {
		var color = prompt('Enter color (e.g. red, #ff0000):', '');
		if (color) textarea.value = before + '[color=' + color + ']' + (sel || 'text') + '[/color]' + after;
	} else if (tag === 'size') {
		var size = prompt('Enter size (e.g. small, large, x-large, xx-large):', 'large');
		if (size) textarea.value = before + '[size=' + size + ']' + (sel || 'text') + '[/size]' + after;
	} else if (tag === 'font') {
		var font = prompt('Enter font name:', 'Arial');
		if (font) textarea.value = before + '[font=' + font + ']' + (sel || 'text') + '[/font]' + after;
	} else {
		textarea.value = before + '[' + tag + ']' + (sel || '') + '[/' + tag + ']' + after;
	}
	textarea.focus();
}
function removeFormatting() {
	var textarea = document.getElementById('message');
	if (!textarea) return;
	var start = textarea.selectionStart;
	var end = textarea.selectionEnd;
	var sel = textarea.value.substring(start, end);
	if (sel) {
		var clean = sel.replace(/\[\/?\w+[^\]]*\]/g, '');
		textarea.value = textarea.value.substring(0, start) + clean + textarea.value.substring(end);
	}
	textarea.focus();
}
</script>