
function getSel() {
    if (window.getSelection)
       return window.getSelection();
    else if (document.selection)
       return document.selection.createRange().text;
    else if (document.getSelection)
       return document.getSelection();
    else return '';
}


  function quotmsg(id) {
    var m=document.all['quot_'+id].innerHTML;
    var a=document.all['aut_'+id].innerHTML;
    var b="";
    var tag="";
    var c=true;

    for (var i=0; i < m.length; i++) {
      if (m.charAt(i)=='<') {
        c=false;
        tag="";
        continue;
      }

      if (c) b+=m.charAt(i); else if (m.charAt(i)!='"') tag+=m.charAt(i);

      if (m.charAt(i)=='>') {
        c=true;
        b+=checktag(tag); //Replace tag
      }
    }

    ins("\n[q][b]"+a+" писал(а):[/b]\n"+b+"[/q]\n");
  }

function ins2(txt1,txt2) {
    var txtarea;
    txtarea=document.newsarea.user_text;
    txtarea.focus();

    if (document.selection) {
      theSelection = document.selection.createRange().text; // Get text selection
      document.selection.createRange().text = txt1 + theSelection + txt2;
      theSelection = '';
      return;
    }
    else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
      mozWrap(txtarea, txt1, txt2);
    else txtarea.value=txtarea.value+txt1+txt2;
}

function copyQ(name) {
txt=''
if (document.getSelection) {txt=document.getSelection()}
else if (document.selection) {txt=document.selection.createRange().text;}
}

function ins(txt){
    ins2(txt,'');
}

function quote(id){
    var a=document.all['aut_'+id].innerHTML;
    if (txt!='')
      ins("\n[q][b]"+a+":[/b]\n"+txt+"[/q]\n");
    else quotmsg(id);
}

function insertext(text1,text2,area){
    var b=getSel();
    theSelection = document.selection.createRange().text;
    if(area=="short"){if (!theSelection) { document.newsarea.text_news_short.focus(); document.newsarea.text_news_short.value += text1 + text2; document.newsarea.text_news_short.focus(); return; } else {document.newsarea.text_news_short.focus(); document.selection.createRange().text = text1 + b + text2; document.newsarea.text_news_short.focus(); return; } }
    if(area=="full"){if (!theSelection) { document.newsarea.text_news.focus(); document.newsarea.text_news.value += text1 + text2; document.newsarea.text_news.focus(); return; } else {document.newsarea.text_news.focus(); document.selection.createRange().text = text1 + b + text2; document.newsarea.text_news.focus(); return; } }
    if(area=="shortc"){if (!theSelection) { document.newsarea.comm.focus(); document.newsarea.comm.value += text1 + text2; document.newsarea.comm.focus(); return; } else {document.newsarea.comm.focus(); document.selection.createRange().text = text1 + b + text2; document.newsarea.comm.focus(); return; } }
    if(area=="fullc"){if (!theSelection) { document.newsarea.con_full.focus(); document.newsarea.con_full.value += text1 + text2; document.newsarea.con_full.focus(); return; } else {document.newsarea.con_full.focus(); document.selection.createRange().text = text1 + b + text2; document.newsarea.con_full.focus(); return; } }

}

