<script type="text/javascript">
	function ctrlEnter(event, formElem) {
		if((event.ctrlKey) && ((event.keyCode == 0xA)||(event.keyCode == 0xD)))
		{
            var hd = document.createElement('input');
            hd.type = 'hidden';
            hd.name = 'enter';
            hd.value = 1;
            formElem.appendChild(hd);
			formElem.submit();
		}
	}
</script>

<div id="toolbarpanel" style="margin: 3px;"></div>

<script xmlns="http://www.w3.org/1999/xhtml" language="javascript" type="text/javascript">
    /*<![CDATA[*/
    function tag(text1, text2, text3) {
        if ((document.selection)) {
            document.getElementById("message").focus();
        } else if(document.getElementById("message").selectionStart!=undefined) {
            var element = document.getElementById("message");
            var str = element.value;
            var start = element.selectionStart;
            var length = element.selectionEnd - element.selectionStart;
            element.value = str.substr(0, start) + text3 + text1 + str.substr(start, length) + text2 + text3 + str.substr(start + length);
        } else
            document.getElementById("message").value += text3+text1+text2+text3;
    }
    function text(text) {
        var element = document.getElementById("message");
        var str = element.value;
        var start = element.selectionStart;
        var length = element.selectionEnd - element.selectionStart;
        element.value = str.substr(0, start) + text + str.substr(start, length) + str.substr(start + length);
    }
	
    var toolbarpanel = document.getElementById('toolbarpanel');
    toolbarpanel.innerHTML += '<a style="border-radius: 10px;background: #fbfbfb;padding: 5px;border: 1px solid #f1f1f1;" href="?func=bb-code">бб-коды</a> <a style="border: 1px solid #f1f1f1;border-radius: 10px;background: #fbfbfb;padding: 5px;"  href="?func=smiles">смайлы</a> </br /><div style="margin-top: 5px;"></div>  '
        + '<a href="javascript:tag(\'[b]\', \'[/b]\', \'\')"><img src="/_images/value/bold.gif" alt="b" title="Жирный шрифт" /></a> '
        + '<a href="javascript:tag(\'[i]\', \'[/i]\', \'\')"><img src="/_images/value/italics.gif" alt="i" title="Наклонный шрифт" /></a> '
        + '<a href="javascript:tag(\'[u]\', \'[/u]\', \'\')"><img src="/_images/value/underline.gif" alt="u" title="Подчеркнутый шрифт" /></a> '
        + '<a href="javascript:tag(\'[s]\', \'[/s]\', \'\')"><img src="/_images/value/strike.gif" alt="s" title="Зачеркнутый шрифт" /></a> '
        + '<a href="javascript:text(\' =P \', \'\')"><img src="/_images/smiles/1.gif" alt="s" /></a> '
        + '<a href="javascript:text(\' :) \', \'\')"><img src="/_images/smiles/2.gif" alt="s" /></a> '
        + '<a href="javascript:text(\' .плак. \', \'\')"><img src="/_images/smiles/3.gif" alt="s" /></a> '
        + '<a href="javascript:text(\' :D \', \'\')"><img src="/_images/smiles/4.gif" alt="s" /></a> '
        + '<a href="javascript:text(\' .лол. \', \'\')"><img src="/_images/smiles/5.gif" alt="s" /></a> '
        ;
		
/*]]>*/
</script>

<textarea style="width: 99%;height: 120px;" id="message" name="msg" onkeypress="ctrlEnter(event, this.form);" placeholder="<?= (isset($placeholder) ? $placeholder : 'Написать сообщение..')?>">
<?= (isset($insert) ? $insert : '')?>
</textarea><br />
