var AvailButtons = {b:['Bold','bold','B'],u:['Underline','underline','U'],i:['Italic','italic','I'],str:['StrikeThrough','strikethrough','STRIKE']};

function HideIncompatible()
{
}

function HTMLtoCode(txt)
{
rExpB = /<\s*(\/?)(b|B|strong|STRONG)\s*>/gm;
rExpI = /<\s*(\/?)(i|I|en|EN)\s*>/gm;
rExpU = /<\s*(\/?)(u|U)\s*>/gm;
rExpQuote = /<\s*(\/?)(blockquote|BLOCKQUOTE|BlockQuote)\s*>/gm;
rExpStrike = /<\s*(\/?)(strike|STRIKE|Strike)\s*>/gm;
rExpInline = /<\s*(?:span|Span|SPAN)(?:\s+class\=[\"\']?inspan[\"\']?)?\s+id\s*=\s*[\"\']?(\w+?)_(\d+)[\"\']?(?:\s+class\=[\"\']?inspan[\"\']?)?\>([^\'\"\<\>\]\[]+)(?:\&nbsp\;|\s+)([^\'\"\<\>\]\[]*)\<\/\s*(SPAN|Span|span)\s*\>/gm;
rExpSmile = new RegExp("<\\s*(?:img|Img|IMG)\\s+src\\s*\\=\\s*[\\\"\\\']?" + BImgPath + "sm\\/([^\\\'\\\"\\<\\>\\]\\[]+)\\.gif[\\\"\\\']?\\s*>","gm");
rExpsP = /<\s*(p|P)\s*>/gm;
rExpnP = /(?:<\s*(?:[bB][rR])\s*>)?<\s*\/(p|P)\s*>/gm;
rExpCr = /[\n\r]+/gm;
rExpBr = /[\t\s]*<\s*(?:[bB][rR])\s*>[\t\s]*/gm;
rExpCrEnd = /[\n\r]+[\s\t]+/gm;

txt = txt.replace(rExpB,"[$1B]");
txt = txt.replace(rExpI,"[$1I]");
txt = txt.replace(rExpU,"[$1U]");
txt = txt.replace(rExpQuote,"[$1Q]");
txt = txt.replace(rExpStrike,"[$1STRIKE]");
txt = txt.replace(rExpInline,"[INLINE $1 $2]$3[/INLINE]");
txt = txt.replace(rExpSmile,"[\:$1\:]");
txt = txt.replace(rExpCr,' ');
txt = txt.replace(rExpsP,"[P]");
txt = txt.replace(rExpnP,"[/P]\n");
txt = txt.replace(rExpBr,"\n");
txt = txt.replace(rExpCrEnd,"\n");
return txt;
}

function CodetoHTML(txt)
{
rExpB = /\[\s*(\/?)(b|B)\s*\]/gm;
rExpI = /\[\s*(\/?)(i|I)\s*\]/gm;
rExpU = /\[\s*(\/?)(u|U)\s*\]/gm;
rExpQ = /\[\s*(\/?)(q|Q)\s*\]/gm;
rExpStrike = /\[s*(\/?)(strike|STRIKE|Strike)\s*\]/gm;
rExpInline = /\[\s*(?:inline|Inline|INLINE)\s+(\w+)\s+(\d+)(?:\s+(?:DESC|Desc|desc)\s*\=\s*[\"\']?([^\'\"\<\>\]\[]*)[\"\']?)?\s*\]([^\'\"\<\>\]\[]+)\[\/(?:inline|Inline|INLINE)\]/gm;
rExpSmile = /\[\:\s*([^\'\"\<\>\]\[]+)\s*\:\]/gm;
rExpsP = /\[\s*(p|P)\s*\]/gm;
rExpnP = /\[\s*\/(p|P)\s*\][\r\n]*/gm;

rExpBr = /[\n\r]+/gm;

txt = txt.replace(rExpB,"<$1b>");
txt = txt.replace(rExpI,"<$1i>");
txt = txt.replace(rExpU,"<$1u>");
txt = txt.replace(rExpStrike,"<$1strike>");
txt = txt.replace(rExpQ,"<$1blockquote>");
txt = txt.replace(rExpInline,"<span id=\"$1_$2\" class=\"inspan\">$4&nbsp;([$1])</span>");

for (i in ClsDescr)
	{
	var rcExp = new RegExp("\\["+ i +"\\]","gm");
	txt = txt.replace(rcExp,ClsDescr[i]);
	}

txt = txt.replace(rExpSmile,"<img src=\""+BImgPath+"sm\/$1\.gif\">");
txt = txt.replace(rExpsP,"<P>");
txt = txt.replace(rExpnP,"</P>");
txt = txt.replace(rExpBr,"<br>");
return txt;
}

function SmToggle()
{
var sm = byid('smiles').style;
if (sm.display)
	{ sm.display=''; }
else
	{ sm.display='none'; }
}

function MoveTopic(tid,ofid,pg,op)
{
var options = "toolbar=no,scrollbars=yes,resizable=no,width=420,height=300";
window.open("frselect.shtml?tid="+tid+"&ofid="+ofid+'&pg='+pg+'&op='+op,"frselectwindow",options);
}

function MoveAct(tid,fid,ofid,pg,op)
{
goRC('forum_fid_'+ofid+'_pg_'+pg+'.shtml?actUser-MoveTopic='+fid+'&mvtid='+tid+'&op='+op);
}

function RenameTopic(oname,tid,ofid,pg,op)
{
if(name=prompt('Введите название форума',oname))
	{ goRC('forum_fid_'+ofid+'_pg_'+pg+'.shtml?actUser-RenameTopic='+tid+'&op='+op+'&name='+escape(name)); }
}

function SetRight(tid,fid,pg,op)
{
var options = "toolbar=no,scrollbars=yes,resizable=no,width=420,height=300";
window.open("restricts.shtml?tid="+tid+"&fid="+fid+'&pg='+pg+'&op='+op,"restrictwindow",options);
}

function SetRestrict(tid,fid,pg,op,rs)
{
goRC('forum_fid_'+fid+'_pg_'+pg+'.shtml?actUser-SetRestrict='+tid+'&op='+op+'&acclim='+rs.acclim+'&lvllim='+rs.lvllim+'&racelim='+rs.racelim+'&clanlim='+rs.clanlim+'&reglim='+rs.reglim+'&timelim='+rs.timelim+'&rtp='+rs.tp);
}

function MakeQuote(Id)
{
var QObj = document.getElementById('frtd_'+Id);
rv = '';

if (ClientTp == 1)
	{
	Range = document.selection.createRange();
	TextRange = document.body.createTextRange();
	TextRange.moveToElementText(QObj);
	if (TextRange.inRange(Range) && (document.selection.type == 'Text' || document.selection.type == 'text'))
		{ rv = Range.text; }
	}
else
	{
   slct = window.getSelection();
  	range = slct.getRangeAt(0);
	if (range.compareNode(QObj) == 2)
	   { rv = range.toString(); }
	}
if (rv != '')
	{ 
	if (byid('switcher').value == 0)
		{
		var trgwin = document.getElementById('formedit').contentWindow;
		if (ClientTp == 1)
			{ 
			Range = trgwin.document.selection.createRange();
			FullRange = trgwin.document.body.createTextRange();
			if (FullRange.inRange(Range) && trgwin.document.selection.type == 'Text' || trgwin.document.selection.type == 'text')
				{ Range.pasteHTML('<blockquote>'+rv+'</blockquote>'); } 
			else
				{ trgwin.document.body.innerHTML = trgwin.document.body.innerHTML	+ '<blockquote>'+rv+'</blockquote>'; }
			}
		else
			{
		   slct = trgwin.getSelection();
   		range = slct.getRangeAt(0);
			var Div = trgwin.document.createElement('Blockquote');
			var Txt = trgwin.document.createTextNode(rv);
			Div.appendChild(Txt);
			ReplaceGeckoSelection(Div);
			}
		document.getElementById('formedit').contentWindow.focus();
		}
	else
		{ ReplaceTextSelection('[Q]'+rv+'[/Q]'); }
	}
else
	{ alert('Выделите фрагмент текста для цитаты') }
}
