function ShowHideMoreBBC(ASelf, Aidx){
  var span_MoreBBC = document.getElementById("morebbc"+Aidx);
  var isVis        = (span_MoreBBC.style.display == "")
  var NewVisib     = isVis ? "none" : "";
  span_MoreBBC.style.display = NewVisib;
  if (isVis) {ASelf.innerHTML="&raquo;";}
  else       {ASelf.innerHTML="&laquo;";}
}

function TA_Check_Rows(AElem, AMinRows, AMaxRows) {
  var hard_lines = 0;
  var is_has_hardlines = false;
  var last       = 0;
  var strtocount = AElem.value;
  while ( true ) {
    last = strtocount.indexOf("\n", last+1);
    hard_lines++;
    is_has_hardlines = true;
    if ( last == -1 ) break;
  }
  if (is_has_hardlines) hard_lines++;
  var soft_lines = Math.round(strtocount.length / (AElem.cols-1));
  if ( hard_lines < soft_lines ) hard_lines = soft_lines;
  var try_lines = hard_lines;
  ///
  if (try_lines < AMinRows) try_lines = AMinRows;
  if (AMaxRows < try_lines) try_lines = AMaxRows;
  AElem.rows = try_lines;
}

// добавляет обработчик события
function addEvent ( obj, type, fn ){
 if (obj.addEventListener) obj.addEventListener( type, fn, false );
 else
   if (obj.attachEvent) {obj.attachEvent("on"+type, fn);}
}

function InsertEmail(AContents, Apart1, Apart2){
	document.write('<a href="anti-spam" ' +
	                  'onMouseOver="ReplaceEmail(this, \''+Apart1+'\', \''+Apart2+'\')">' +
	                AContents +
	               '</a>');
}

function loadjscssfile(filename, filetype, ACallBack){
  if (filetype=="js"){ //if filename is a external JavaScript file
    var fileref=document.createElement("script")
    //if (ACallBack) fileref.onload = ACallBack; // callback
    fileref.setAttribute("type","text/javascript")
    fileref.setAttribute("src", filename)
  } else if (filetype=="css"){ //if filename is an external CSS file
    var fileref=document.createElement("link")
    //if (ACallBack) fileref.onload = ACallBack; // callback
    fileref.setAttribute("rel", "stylesheet")
    fileref.setAttribute("type", "text/css")
    fileref.setAttribute("href", filename)
  }
  if (typeof fileref!="undefined") document.getElementsByTagName("head")[0].appendChild(fileref);
}

function PrepareBBC(AAddIdx) {
  editor_tools_smileys_popupwidth = '155px';
  editor_tools_smileys_popupoffset = 0;
  editor_tools_smileys['[;)]'   ] = '/img/emo/icon_wink.gif';
  editor_tools_smileys['[:(]'   ] = '/img/emo/icon_sad.gif';
  editor_tools_smileys['[O_O]'  ] = '/img/emo/icon_shok.gif';
  editor_tools_smileys['[:)]'   ] = '/img/emo/icon_smile.gif';
  editor_tools_smileys['[:P]'   ] = '/img/emo/icon_crazy.gif';
  editor_tools_smileys['[bad]'  ] = '/img/emo/icon_bad.gif';
  editor_tools_smileys['[conf]' ] = '/img/emo/icon_confused.gif';
  editor_tools_smileys['[haha]' ] = '/img/emo/icon_haha.gif';
  editor_tools_smileys['[gm]'   ] = '/img/emo/icon_julli-huh.gif';
  editor_tools_smileys['[good]' ] = '/img/emo/icon_good.gif';
  editor_tools_smileys['[sorry]'] = '/img/emo/icon_sorry.gif';
  editor_tools_smileys['[hehe]' ] = '/img/emo/icon_usikker.gif';
  editor_tools_smileys['[buba]' ] = '/img/emo/icon_buba.gif';
  editor_tools_smileys['[hi]'   ] = '/img/emo/icon_hi.gif';
  editor_tools_smileys['[angry]'] = '/img/emo/icon_angry.gif';
  editor_tools_smileys['[old]'  ] = '/img/emo/icon_old.gif';
  editor_tools_smileys['[lala]' ] = '/img/emo/icon_lala.gif';
  editor_tools_smileys['[ohgod]'] = '/img/emo/icon_ohgod.gif';
  editor_tools_smileys['[lam]'  ] = '/img/emo/icon_lam.gif';
  //
  var msg_obj = document.getElementById('message');
  addEvent(msg_obj, 'click', editor_tools_hide_all_popups);
  if (AAddIdx) {
    var msg_obj2 = document.getElementById('message'+AAddIdx);
    addEvent(msg_obj2, 'click', editor_tools_hide_all_popups);
  }
}
