function ins(name){
	if (name != "") paste("[b]"+name+"[/b]"+"\n",1);
}

function Insert2(text){
  text = selection;
	if (text!="") paste("[quote]"+text+"[/quote]\n", 0);
	if (text=="") alert('сначала выделите текст, который хотите процитировать');
}

function Insert(qname,text){
  text = selection;
  if (text!="") paste("[quote="+qname+"]"+text+"[/quote]\n", 0);
	if (text=="") alert('сначала выделите текст, который хотите процитировать');
}





function paste(text, flag){
	if (document.REPLIER) {
		if ((document.selection)&&(flag)) {
			document.REPLIER.Post.focus();
			document.REPLIER.document.selection.createRange().text = text;
		} else document.REPLIER.Post.value += text;
	}
}

function getSel()
{
	var txt = 'Ошибка';
	if (window.getSelection)
	{
		txt = window.getSelection();
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
	}
	return txt;
}

function get_selection() {

  if (document.getSelection){
		selection = document.getSelection();
    if      (window.getSelection)   selection = window.getSelection().toString();      
   else if (document.getSelection) selection = document.getSelection();                
   else if (document.selection)   selection = document.selection.createRange().text;  
		selection = selection.replace(/\r\n\r\n/gi, "_doublecaret_");
    selection = selection.replace(/\r\n/gi, " ");
    while (selection.indexOf("  ") !=-1) selection = selection.replace(/  /gi, "");
		selection = selection.replace(/_doublecaret_/gi, "\r\n\r\n");
	  } else {
	     selection = getSel();
	  }
}

function InsertSelection() {
	get_selection();
    Insert(selection);
}

