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();
	}
}

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);
}

function smilesOpen(catSmiles, close) {
  if (document.getElementById('smile-panel').style.display == 'block' && close != '2')
  document.getElementById('smile-panel').style.display = 'none';
  else 
  document.getElementById('smile-panel').style.display = 'block';  

  if (catSmiles == '100500') {
    resultHTML = '<div class="category_wrap_smiles">';
    for(i = 0; smilesArr.length > i; i++) {
  	
  	this_smile_arr = smilesArr[i][0][0].split("|");
  	if (smilesArr[i][1][0]) {
  	  this_smile = smilesArr[i][1][0].split("|");
  	} else {
  	  this_smile = false;
  	}
  	
  	resultHTML += '<a class="sm-cat" style="color: #3163b7;" onclick="smilesOpen(\'' + i + '\', \'2\')">' + this_smile_arr[1];
  	if (this_smile) {
  	  resultHTML += ' <img src="/style/smiles/' + this_smile[0] + '.gif" />';
  	}
  	resultHTML += '</a>';
    }   
    var listSmiles = document.getElementById('smiles-content');
    listSmiles.innerHTML = resultHTML + '</div>';
  } else {
    resultHTML = '';
    for(s = 0; smilesArr[catSmiles][2].length > s; s++) {
  	var this_smile_arr = smilesArr[catSmiles][2][s].split("|");
  	resultHTML += ' <a onclick="smilesOpen(\'0\', \'1\')" href="javascript:tag(\'\', \' ' + this_smile_arr[1] + ' \', \'\')" ><img src="/style/smiles/' + this_smile_arr[0] + '.gif" title="' + this_smile_arr[1] + '" /></a> ';
    }
    resultHTML += '<div class="sm-foot"><a style="color: #3163b7;"  onclick="smilesOpen(\'100500\', \'2\')">&larr; РќР°Р·Р°Рґ Рє РІС‹Р±РѕСЂСѓ РєР°С‚РµРіРѕСЂРёР№</a></div>';
    
    var listSmiles = document.getElementById('smiles-content');
    listSmiles.innerHTML = resultHTML;    
  }
}

var toolbar = document.getElementById('toolbar');
toolbar.innerHTML += '<a href="javascript:tag(\'[b]\', \'[/b]\', \'\')"><img src="/style/value/bold.gif" alt="b" title="" /></a> '
  + '<a href="javascript:tag(\'[i]\', \'[/i]\', \'\')"><img src="/style/value/italics.gif" alt="i" title="" /></a> '
  + '<a href="javascript:tag(\'[u]\', \'[/u]\', \'\')"><img src="/style/value/underline.gif" alt="u" title="" /></a> '
  + '<a onclick="smilesOpen(\'100500\', \'0\')" class="s-links"><img src="/style/value/smiles.png" alt="smiles" title="Cмайлы" /></a> '
  + '<a href="javascript:tag(\'[cit]\', \'[/cit]\', \'\')"><img src="/style/value/q.png" alt="q" title="Цитата" /></a> '
+' <span class="bb_opt" style="display: inline-block; cursor:pointer; 0px;"><img src="/style/value/color.gif" alt="url" title="Цвет шрифта" />'
+ "<div class=\"bb_hide bb_color\"><table><tr><td><a href=\"#link120\" onclick=\"return tag('[color=#ffffff]', '[/color]', '');\" style=\"background-color:#ffffff;\"></a></td><td><a href=\"#link121\" onclick=\"return tag('[color=#bcbcbc]', '[/color]', '');\" style=\"background-color:#bcbcbc;\"></a></td><td><a href=\"#link122\" onclick=\"return tag('[color=#708090]', '[/color]', '');\" style=\"background-color:#708090;\"></a></td><td><a href=\"#link123\" onclick=\"return tag('[color=#6c6c6c]', '[/color]', '');\" style=\"background-color:#6c6c6c;\"></a></td><td><a href=\"#link124\" onclick=\"return tag('[color=#454545]', '[/color]', '');\" style=\"background-color:#454545;\"></a></td></tr><tr><td><a href=\"#link125\" onclick=\"return tag('[color=#fcc9c9]', '[/color]', '');\" style=\"background-color:#fcc9c9;\"></a></td><td><a href=\"#link126\" onclick=\"return tag('[color=#fe8c8c]', '[/color]', '');\" style=\"background-color:#fe8c8c;\"></a></td><td><a href=\"#link127\" onclick=\"return tag('[color=#fe5e5e]', '[/color]', '');\" style=\"background-color:#fe5e5e;\"></a></td><td><a href=\"#link128\" onclick=\"return tag('[color=#fd5b36]', '[/color]', '');\" style=\"background-color:#fd5b36;\"></a></td><td><a href=\"#link129\" onclick=\"return tag('[color=#f82e00]', '[/color]', '');\" style=\"background-color:#f82e00;\"></a></td></tr><tr><td><a href=\"#link130\" onclick=\"return tag('[color=#ffe1c6]', '[/color]', '');\" style=\"background-color:#ffe1c6;\"></a></td><td><a href=\"#link131\" onclick=\"return tag('[color=#ffc998]', '[/color]', '');\" style=\"background-color:#ffc998;\"></a></td><td><a href=\"#link132\" onclick=\"return tag('[color=#fcad66]', '[/color]', '');\" style=\"background-color:#fcad66;\"></a></td><td><a href=\"#link133\" onclick=\"return tag('[color=#ff9331]', '[/color]', '');\" style=\"background-color:#ff9331;\"></a></td><td><a href=\"#link134\" onclick=\"return tag('[color=#ff810f]', '[/color]', '');\" style=\"background-color:#ff810f;\"></a></td></tr><tr><td><a href=\"#link135\" onclick=\"return tag('[color=#d8ffe0]', '[/color]', '');\" style=\"background-color:#d8ffe0;\"></a></td><td><a href=\"#link136\" onclick=\"return tag('[color=#92f9a7]', '[/color]', '');\" style=\"background-color:#92f9a7;\"></a></td><td><a href=\"#link137\" onclick=\"return tag('[color=#34ff5d]', '[/color]', '');\" style=\"background-color:#34ff5d;\"></a></td><td><a href=\"#link138\" onclick=\"return tag('[color=#b2fb82]', '[/color]', '');\" style=\"background-color:#b2fb82;\"></a></td><td><a href=\"#link139\" onclick=\"return tag('[color=#89f641]', '[/color]', '');\" style=\"background-color:#89f641;\"></a></td></tr><tr><td><a href=\"#link140\" onclick=\"return tag('[color=#b7e9ec]', '[/color]', '');\" style=\"background-color:#b7e9ec;\"></a></td><td><a href=\"#link141\" onclick=\"return tag('[color=#56e5ed]', '[/color]', '');\" style=\"background-color:#56e5ed;\"></a></td><td><a href=\"#link142\" onclick=\"return tag('[color=#21cad3]', '[/color]', '');\" style=\"background-color:#21cad3;\"></a></td><td><a href=\"#link143\" onclick=\"return tag('[color=#03939b]', '[/color]', '');\" style=\"background-color:#03939b;\"></a></td><td><a href=\"#link144\" onclick=\"return tag('[color=#039b80]', '[/color]', '');\" style=\"background-color:#039b80;\"></a></td></tr><tr><td><a href=\"#link145\" onclick=\"return tag('[color=#cac8e9]', '[/color]', '');\" style=\"background-color:#cac8e9;\"></a></td><td><a href=\"#link146\" onclick=\"return tag('[color=#9690ea]', '[/color]', '');\" style=\"background-color:#9690ea;\"></a></td><td><a href=\"#link147\" onclick=\"return tag('[color=#6a60ec]', '[/color]', '');\" style=\"background-color:#6a60ec;\"></a></td><td><a href=\"#link148\" onclick=\"return tag('[color=#4866e7]', '[/color]', '');\" style=\"background-color:#4866e7;\"></a></td><td><a href=\"#link149\" onclick=\"return tag('[color=#173bd3]', '[/color]', '');\" style=\"background-color:#173bd3;\"></a></td></tr><tr></td><td><a href=\"#link150\" onclick=\"return tag('[color=#f3cafb]', '[/color]', '');\" style=\"background-color:#f3cafb;\"></a></td><td><a href=\"#link151\" onclick=\"return tag('[color=#e287f4]', '[/color]', '');\" style=\"background-color:#e287f4;\"></a></td><td><a href=\"#link152\" onclick=\"return tag('[color=#c238dd]', '[/color]', '');\" style=\"background-color:#c238dd;\"></a></td><td><a href=\"#link153\" onclick=\"return tag('[color=#a476af]', '[/color]', '');\" style=\"background-color:#a476af;\"></a></td><td><a href=\"#link154\" onclick=\"return tag('[color=#b53dd2]', '[/color]', '');\" style=\"background-color:#b53dd2;\"></a></td></tr></table></div>"
+'</span>'

+ ' <span class="bb_opt" style="display: inline-block; cursor:pointer; padding:0px;"><img src="/style/value/color_bg.gif" alt="url" title="Цвет фона" />'
+ "<div class=\"bb_hide bb_color\"><table><tr><td><a href=\"#link20\" onclick=\"return tag('[background=#ffffff]', '[/background]', '');\" style=\"background-color:#ffffff;\"></a></td><td><a href=\"#link21\" onclick=\"return tag('[background=#bcbcbc]', '[/background]', '');\" style=\"background-color:#bcbcbc;\"></a></td><td><a href=\"#link22\" onclick=\"return tag('[background=#708090]', '[/background]', '');\" style=\"background-color:#708090;\"></a></td><td><a href=\"#link23\" onclick=\"return tag('[background=#6c6c6c]', '[/background]', '');\" style=\"background-color:#6c6c6c;\"></a></td><td><a href=\"#link24\" onclick=\"return tag('[background=#454545]', '[/background]', '');\" style=\"background-color:#454545;\"></td></a></tr><tr><td><a href=\"#link25\" onclick=\"return tag('[background=#fcc9c9]', '[/background]', '');\" style=\"background-color:#fcc9c9;\"></a></td><td><a href=\"#link26\" onclick=\"return tag('[background=#fe8c8c]', '[/background]', '');\" style=\"background-color:#fe8c8c;\"></a></td><td><a href=\"#link27\" onclick=\"return tag('[background=#fe5e5e]', '[/background]', '');\" style=\"background-color:#fe5e5e;\"></a></td><td><a href=\"#link28\" onclick=\"return tag('[background=#fd5b36]', '[/background]', '');\" style=\"background-color:#fd5b36;\"></a></td><td><a href=\"#link29\" onclick=\"return tag('[background=#f82e00]', '[/background]', '');\" style=\"background-color:#f82e00;\"></a></td></tr><tr><td><a href=\"#link30\" onclick=\"return tag('[background=#ffe1c6]', '[/background]', '');\" style=\"background-color:#ffe1c6;\"></a></td><td><a href=\"#link31\" onclick=\"return tag('[background=#ffc998]', '[/background]', '');\" style=\"background-color:#ffc998;\"></a></td><td><a href=\"#link32\" onclick=\"return tag('[background=#fcad66]', '[/background]', '');\" style=\"background-color:#fcad66;\"></a></td><td><a href=\"#link33\" onclick=\"return tag('[background=#ff9331]', '[/background]', '');\" style=\"background-color:#ff9331;\"></a></td><td><a href=\"#link34\" onclick=\"return tag('[background=#ff810f]', '[/background]', '');\" style=\"background-color:#ff810f;\"></a></td></tr><tr><td><a href=\"#link35\" onclick=\"return tag('[background=#d8ffe0]', '[/background]', '');\" style=\"background-color:#d8ffe0;\"></a></td><td><a href=\"#link36\" onclick=\"return tag('[background=#92f9a7]', '[/background]', '');\" style=\"background-color:#92f9a7;\"></a></td><td><a href=\"#link37\" onclick=\"return tag('[background=#34ff5d]', '[/background]', '');\" style=\"background-color:#34ff5d;\"></a></td><td><a href=\"#link38\" onclick=\"return tag('[background=#b2fb82]', '[/background]', '');\" style=\"background-color:#b2fb82;\"></a></td><td><a href=\"#link39\" onclick=\"return tag('[background=#89f641]', '[/background]', '');\" style=\"background-color:#89f641;\"></a></td></tr><tr><td><a href=\"#link40\" onclick=\"return tag('[background=#b7e9ec]', '[/background]', '');\" style=\"background-color:#b7e9ec;\"></a></td><td><a href=\"#link41\" onclick=\"return tag('[background=#56e5ed]', '[/background]', '');\" style=\"background-color:#56e5ed;\"></a></td><td><a href=\"#link42\" onclick=\"return tag('[background=#21cad3]', '[/background]', '');\" style=\"background-color:#21cad3;\"></a></td><td><a href=\"#link43\" onclick=\"return tag('[background=#03939b]', '[/background]', '');\" style=\"background-color:#03939b;\"></a></td><td><a href=\"#link44\" onclick=\"return tag('[background=#039b80]', '[/background]', '');\" style=\"background-color:#039b80;\"></a></td></tr><tr><td><a href=\"#link45\" onclick=\"return tag('[background=#cac8e9]', '[/background]', '');\" style=\"background-color:#cac8e9;\"></a></td><td><a href=\"#link46\" onclick=\"return tag('[background=#9690ea]', '[/background]', '');\" style=\"background-color:#9690ea;\"></a></td><td><a href=\"#link47\" onclick=\"return tag('[background=#6a60ec]', '[/background]', '');\" style=\"background-color:#6a60ec;\"></a></td><td><a href=\"#link48\" onclick=\"return tag('[background=#4866e7]', '[/background]', '');\" style=\"background-color:#4866e7;\"></a></td><td><a href=\"#link49\" onclick=\"return tag('[background=#173bd3]', '[/background]', '');\" style=\"background-color:#173bd3;\"></a></td></tr><tr><td><a href=\"#link50\" onclick=\"return tag('[background=#f3cafb]', '[/background]', '');\" style=\"background-color:#f3cafb;\"></a></td><td><a href=\"#link51\" onclick=\"return tag('[background=#e287f4]', '[/background]', '');\" style=\"background-color:#e287f4;\"></a></td><td><a href=\"#link52\" onclick=\"return tag('[background=#c238dd]', '[/background]', '');\" style=\"background-color:#c238dd;\"></a></td><td><a href=\"#link53\" onclick=\"return tag('[background=#a476af]', '[/background]', '');\" style=\"background-color:#a476af;\"></a></td><td><a href=\"#link54\" onclick=\"return tag('[background=#b53dd2]', '[/background]', '');\" style=\"background-color:#b53dd2;\"></a></td></tr></table></div>"
+ '</span>'
  ;