function ins(name){
	if (name != "") paste("[b]"+name+"[/b]"+"\n",1);
}

function Insert(text){
	if (text!="") paste("[quote]"+text+"[/quote]\n", 0);
}

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 get_selection() {
	if (document.getSelection){
		selection = document.getSelection();
		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 = document.selection.createRange().text;
}

function InsertSelection() {
	get_selection();
    Insert(selection);
}
function OpenSpoiler(id)
{
		var obj = "";	

		// Check browser compatibility
		if(document.getElementById)
			obj = document.getElementById(id).style;
		else if(document.all)
			obj = document.all[id];
		else if(document.layers)
			obj = document.layers[id];
		else
			return 1;
			
		// Do the magic :)
		if(obj.display == "")
			obj.display = "none";
		else if(obj.display != "none")
			obj.display = "none";
		else
			obj.display = "block";
} 
