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

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

function paste(text, flag){
	if (document.REPLIER) {
		if ((document.selection)&&(flag)) {
			document.REPLIER.Post.focus();
			document.REPLIER.document.selection.createRange().text = text;
		} else if ((typeof(document.forms.REPLIER.Post.selectionStart) != "undefined")&&(flag)){
		var begin = document.forms.REPLIER.Post.value.substr(0, document.forms.REPLIER.Post.selectionStart);
		var end = document.forms.REPLIER.Post.value.substr(document.forms.REPLIER.Post.selectionEnd);
		var selection = document.forms.REPLIER.Post.value.substr(document.forms.REPLIER.Post.selectionStart, document.forms.REPLIER.Post.selectionEnd - document.forms.REPLIER.Post.selectionStart);
		var newCursorPos = document.forms.REPLIER.Post.selectionStart;
		var scrollPos = document.forms.REPLIER.Post.scrollTop;

		document.forms.REPLIER.Post.value = begin + text + end;

		if (document.forms.REPLIER.Post.setSelectionRange)
		{
			if (selection.length == 0)
				document.forms.REPLIER.Post.setSelectionRange(newCursorPos + text.length, newCursorPos + text.length);
			else
				document.forms.REPLIER.Post.setSelectionRange(newCursorPos, newCursorPos + text.length);
			document.forms.REPLIER.Post.focus();
		}
		document.forms.REPLIER.Post.scrollTop = scrollPos;			
		} 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(/ eusa_think.gif/gi, " :tormoju");
		selection = selection.replace(/ icon_wink.gif/gi, " ;)");
		selection = selection.replace(/ biggrin.gif/gi, " :D");
		selection = selection.replace(/ icon_rolleyes.gif/gi, " :rolleyes:");
		selection = selection.replace(/ up.gif/gi, " :vo!");
		selection = selection.replace(/ icon_frown.gif/gi, " :(");
		selection = selection.replace(/ eusa_angel.gif/gi, " :angel");
		selection = selection.replace(/ eusa_hand.gif/gi, " :nop");
		selection = selection.replace(/ eusa_snooty.gif/gi, " :nea");
		selection = selection.replace(/ icon_cool.gif/gi, " B)");
		selection = selection.replace(/ wub.gif/gi, " :wub:");
		selection = selection.replace(/ eusa_eh.gif/gi, " :unsure:");
		selection = selection.replace(/ eusa_doh.gif/gi, " :wacko:");
		selection = selection.replace(/ eusa_shhh.gif/gi, " :shhh");
		selection = selection.replace(/ smile3042.gif/gi, " :kon");
		selection = selection.replace(/ rocket.gif/gi, " :roket");
		selection = selection.replace(/ 2gunsfiring_v1.gif/gi, " :pestik");
		selection = selection.replace(/ 024.gif/gi, " :konXP");
		selection = selection.replace(/ 086.gif/gi, " :bolen");
		selection = selection.replace(/ eusa_shifty.gif/gi, " :glazeem");
		selection = selection.replace(/ icon_idea.gif/gi, " !i!");
		selection = selection.replace(/ eusa_dance.gif/gi, " :la-la");
		selection = selection.replace(/ 167.gif/gi, " :serenada");
		selection = selection.replace(/ 248.gif/gi, " :avsd");
		selection = selection.replace(/ 186.gif/gi, " :denga");
		selection = selection.replace(/ 358.gif/gi, " :pop");
		selection = selection.replace(/ eusa_naughty.gif/gi, " :nifiga");
		selection = selection.replace(/ angel.gif/gi, " :angelochek");
		selection = selection.replace(/ 0001.gif/gi, " :klbasit");
		selection = selection.replace(/ 028.gif/gi, " :pesochnica");
		selection = selection.replace(/ 241.gif/gi, " :galyun");
		selection = selection.replace(/ icon_evil.gif/gi, " :Zloy");
		selection = selection.replace(/ vampv.gif/gi, " :vampir");
		selection = selection.replace(/ confused.gif/gi, " :???");
		selection = selection.replace(/ eusa_boohoo.gif/gi, " :skripka");
		selection = selection.replace(/ eusa_liar.gif/gi, " :zavralsa");
		selection = selection.replace(/ smile3036.gif/gi, " :drachuny");
		selection = selection.replace(/ eusa_silenced.gif/gi, " :X");
		selection = selection.replace(/ elkgrin.gif/gi, " :rogonosec");
		selection = selection.replace(/ poster_offtopic.gif/gi, " :OFFTOP");
		selection = selection.replace(/ poster_dont.gif/gi, " :NOXYLIGAN");
		selection = selection.replace(/ poster_ban.gif/gi, " :BAN");
		selection = selection.replace(/ trud.gif/gi, " :trud");
		selection = selection.replace(/ devil.gif/gi, " :devil");
		selection = selection.replace(/ pom.gif/gi, " :strafe");
		selection = selection.replace(/ shv.gif/gi, " :soldat");
		selection = selection.replace(/ thk.gif/gi, " :dumayu");
		selection = selection.replace(/ mar.gif/gi, " :ukur");
		selection = selection.replace(/ pray.gif/gi, " :o-velikiy");
		selection = selection.replace(/ lam.gif/gi, " :lamer");
		selection = selection.replace(/ fart.gif/gi, " :fart");
		selection = selection.replace(/ inv.gif/gi, " :pobity");
		selection = selection.replace(/ waffen057.gif/gi, " :jedi");
		selection = selection.replace(/ jumprail.gif/gi, " :rail");
		selection = selection.replace(/ borgsmile.gif/gi, " :karatel");
		selection = selection.replace(/ 15_weeping.gif/gi, " :`(");
		selection = selection.replace(/ smile3005.gif/gi, " :sobutilniki");
		selection = selection.replace(/ str.gif/gi, " :strah");
		selection = selection.replace(/ rofl.gif/gi, " :rofl");
		selection = selection.replace(/ tsr.gif/gi, " :tsr");
		selection = selection.replace(/ umn.gif/gi, " :umn");
		selection = selection.replace(/ nunu.gif/gi, " :nunu");
		selection = selection.replace(/ pom.gif/gi, " :pom");
		selection = selection.replace(/ poz.gif/gi, " :poz");
		selection = selection.replace(/ pya.gif/gi, " :pya");
		selection = selection.replace(/ smile3002.gif/gi, " :3002");
		selection = selection.replace(/ waffen107.gif/gi, " :waff");
		selection = selection.replace(/ smile3033.gif/gi, " :glukk");
		selection = selection.replace(/ vamp.gif/gi, " :vamp");
		selection = selection.replace(/ poster_spam.gif/gi, " :spam");
		selection = selection.replace(/ poster_oops.gif/gi, " :oops");
		selection = selection.replace(/ poster_nospam.gif/gi, " :nosp");
		selection = selection.replace(/ respekt.gif/gi, " :respekt");
		selection = selection.replace(/ oyyy.gif/gi, " :oyy");
		selection = selection.replace(/ proffesor.gif/gi, " :proff");
		selection = selection.replace(/ user-334-1106438755.gif/gi, " :rock");
		selection = selection.replace(/ admin1.gif/gi, " :admin");
		selection = selection.replace(/ hul.gif/gi, " :huligan");
		selection = selection.replace(/ vibir 2004.gif/gi, " :vibir 2004");
		selection = selection.replace(/ tanksmile.gif/gi, " :pobeda");
		selection = selection.replace(/ playboy.gif/gi, " :playboy");
		selection = selection.replace(/ ofiget.gif/gi, " :ofiget");
		selection = selection.replace(/ user-900-1103187574.gif/gi, " :stena");
		selection = selection.replace(/ Vasya.gif/gi, " :not fear");
		selection = selection.replace(/ konoplya.gif/gi, " :ylet");
		selection = selection.replace(/ 150.gif/gi, " :bzzz");
		selection = selection.replace(/ BAN!.gif/gi, " :banned");
		selection = selection.replace(/ Poka.gif/gi, " :poka");
		selection = selection.replace(/ zlo.gif/gi, " :zlo:");
		selection = selection.replace(/ russian.gif/gi, " :taler");
		selection = selection.replace(/ facepalm_by_kYnQuinhe.gif/gi, " :facepalm1:");
		selection = selection.replace(/ icon_smile.gif/gi, " :)");
		
//		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";
} 

