function x () {
return;
}


// bbCode control by
// subBlue design
// www.subBlue.com

// Startup variables
var imageTag = false;
var theSelection = false;

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
                && (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
                && (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);


// Replacement for arrayname.length property
function getarraysize(thearray) {
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
	thearray[ getarraysize(thearray) ] = value;
}

// Replacement for arrayname.pop() not implemented in IE until version 5.5
// Removes and returns the last element of an array
function arraypop(thearray) {
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}


function checkForm() {

	formErrors = false;

	if (document.board.body.value.length < 2) {
		formErrors = "Вы должны ввести текст сообщения";
	}

	if (formErrors) {
		alert(formErrors);
		return false;
	} 
}

function emoticon(text) {
	var txtarea = document.board.body;
	text = ' ' + text + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}

function sign(text) {
	var txtarea = document.board.body;

	if (text == "url") {
	var thisURL = prompt("Введите URL сайта или документа, который вы хотите вставить в ваше сообщение", "http://");
	var thisTitle = prompt("Теперь введите название вашего рессурса или оставьте URL", thisURL);
	var text = " <a href=\""+thisURL+"\">"+thisTitle+"</a> ";
	}

	else if (text == "email") {
	var thisEmail = prompt("Введите E-mail, который вы хотите вставить в ваше сообщение", "");
	var text = " <a href=\"mailto:"+thisEmail+"\">"+thisEmail+"</a> ";
	if(!thisEmail) {text = "";}
	}
	
	else if (text == "sqrt") {
	var thisSqrt = prompt("Введите текст, который будет стоять под квадратным корнем", "");
	var text = " &radic;<span style=\"text-decoration: overline\">"+thisSqrt+"</span> ";
	if(!thisSqrt) {text = "";}
	}

	else if (text == "sup") {
	var thisSup = prompt("Введите верхний индекс", "");
	var text = "<sup>"+thisSup+"</sup>";
	if(!thisSup) { text ="";}
	}

	else if (text == "sub") {
	var thisSub = prompt("Введите нижний индекс", "");
	text = "<sub>"+thisSub+"</sub>";
	if(!thisSub) { text = "";}
	}
	
	else if (text == "image") {
	var thisImage = prompt("Введите полный URL рисунка", "http://");
	text = "<img border=\"0\" src=\""+thisImage+"\">";
	}
	

	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value  += text;
		txtarea.focus();
	}
}


// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
	var selLength = txtarea.textLength;
	var selStart = txtarea.selectionStart;
	var selEnd = txtarea.selectionEnd;
	if (selEnd == 1 || selEnd == 2)
		selEnd = selLength;

	var s1 = (txtarea.value).substring(0,selStart);
	var s2 = (txtarea.value).substring(selStart, selEnd)
	var s3 = (txtarea.value).substring(selEnd, selLength);
	txtarea.value = s1 + open + s2 + close + s3;
	return;
}

// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl) {
	if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();
}
		

	


var form=document.forms["board"];
tags_stack=new Array();
var undoeng=new Array();

function insertCode(code){
if(form["body"].createTextRange && form["body"].caretPos)
{form["body"].caretPos.body=code}
else{form["body"].value+=code}
}



function storeCaret(el) {
if(el.createTextRange){el.caretPos=document.selection.createRange().duplicate();}
}

function getText() {
if(document.all && form["body"].createTextRange && form["body"].caretPos)return form["body"].caretPos.body;
return "";
}


var decoder_type='kw';
function DoTableWin(str, Type)
{

var aTable1 = "АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюяЁё"; // Windows-1251
var aTable2 = "юабцдефгхийклмнопярстужвьызшэщчъЮАБЦДЕФГХИЙКЛМНОПЯРСТУЖВЬЫЗШЭЩЧЪЁё"; // КОИ-8
var aTable6 = "ABVGDE¬ZIJKLMNOPRSTUFHC¬¬¬QY'W¬¬abvgde¬zijklmnoprstufhc¬¬¬qy'w¬¬¬¬"; // латиница
var strTable1, strTable2;
if ("kw" == Type)
{
strTable1 = aTable2;
strTable2 = aTable1;
}
else if ("wk" == Type)
{
strTable1 = aTable1;
strTable2 = aTable2;
}
else if ("dw" == Type)
{
strTable1 = aTable3;
strTable2 = aTable1;
}
else if ("wd" == Type)
{
strTable1 = aTable1;
strTable2 = aTable3;
}
else if ("mw" == Type)
{
strTable1 = aTable4;
strTable2 = aTable1;
}
else if ("wm" == Type)
{
strTable1 = aTable1;
strTable2 = aTable4;
}
else if ("iw" == Type)
{
strTable1 = aTable5;
strTable2 = aTable1;
}
else if ("wi" == Type)
{
strTable1 = aTable1;
strTable2 = aTable5;
}
else if ("lw" == Type)
{
strTable1 = aTable6;
strTable2 = aTable1;
}
else if ("wl" == Type)
{
strTable1 = aTable1;
strTable2 = aTable6;
}
else
{
alert("ASSERT!");
return str;
}
var strNew = "";
var i, len = str.length;
for (i = 0; i < len; i++)
{
if ("lw" == Type)
{
if ("'" == str.substr(i, 1))
{
strNew = strNew + "ь";
continue;
}
if (i < (len - 2))
{
var c = str.substr(i, 3);
if ("Sch" == c)
{
strNew = strNew + "Щ";
i = i + 2;
continue;
}
else if ("sch" == c)
{
strNew = strNew + "щ";
i = i + 2;
continue;
}
}
if (i < (len - 1))
{
var c = str.substr(i, 2);
if (("Zh" == c) || ("ZH" == c))
{
strNew = strNew + "Ж";
i++;
continue;
}
else if (("Ch" == c) || ("CH" == c))
{
strNew = strNew + "Ч";
i++;
continue;
}
else if (("Sh" == c) || ("SH" == c))
{
strNew = strNew + "Ш";
i++;
continue;
}
else if (("Ju" == c) || ("JU" == c))
{
strNew = strNew + "Ю";
i++;
continue;
}
else if (("Ja" == c) || ("JA" == c))
{
strNew = strNew + "Я";
i++;
continue;
}
if ("zh" == c)
{
strNew = strNew + "ж";
i++;
continue;
}
else if ("ch" == c)
{
strNew = strNew + "ч";
i++;
continue;
}
else if ("sh" == c)
{
strNew = strNew + "ш";
i++;
continue;
}
else if ("ju" == c)
{
strNew = strNew + "ю";
i++;
continue;
}
else if ("ja" == c)
{
strNew = strNew + "я";
i++;
continue;
}
else if (("Jo" == c) || ("JO" == c))
{
strNew = strNew + "Ё";
i++;
continue;
}
else if ("jo" == c)
{
strNew = strNew + "ё";
i++;
continue;
}
else if (("W" == c) || ("W" == c))
{
strNew = strNew + "н";
i++;
continue;
}
else if (("Q" == c) || ("Q" == c))
{
strNew = strNew + "к";
i++;
continue;
}
}
}
var c = str.substr(i, 1);
var pos = strTable1.indexOf(c);
if (pos < 0)
strNew = strNew + c;
else
{
var d = strTable2.substr(pos, 1);
if ("¬" == d)
{
if ("wl" == Type)
{
if ("Ж" == c)
d = "Zh";
else if ("Ч" == c)
d = "Ch";
else if ("Ш" == c)
d = "Sh";
else if ("Щ" == c)
d = "Sch";
else if ("Ю" == c)
d = "Ju";
else if ("Я" == c)
d = "Ja";
else if ("ж" == c)
d = "zh";
else if ("ч" == c)
d = "ch";
else if ("ш" == c)
d = "sh";
else if ("щ" == c)
d = "sch";
else if ("ю" == c)
d = "ju";
else if ("я" == c)
d = "ja";
else if ("Ё" == c)
d = "Jo";
else if ("ё" == c)
d = "jo";
}
}
strNew = strNew + d;
}
}
return strNew;
}

function DoQuotedWin(str, ToWin)
{
var aTable = "0123456789ABCDEF";
var strNew = ""
if (ToWin)
{
str.toUpperCase();
while (str.length > 0)
{
var c = str.charAt(0);
if (c != "=")
{
strNew += c;
str = str.substr(1);
}
else
{
var i1 = aTable.indexOf(str.charAt(1));
var i2 = aTable.indexOf(str.charAt(2));
if ((i1 >= 0) || (i2 >= 0))
{
var c = i1 * 16 + i2;
if (c >= 0x00C0)
c += 0x0350;
strNew += String.fromCharCode(c);
}
str = str.substr(3);
}
}
}
else
{
var i, len = str.length;
for (i = 0; i < len; i++)
{
var c = str.charCodeAt(i);
if ((c >= 0x0410) && (c <= 0x044F))
c -= 0x0350;
var i1 = Math.floor(c / 16);
var i2 = c % 16;
strNew += "=" + aTable.charAt(i1) + aTable.charAt(i2);
}
}
return strNew;
}

function Decode2(td)
{
decoder_type=td
var strText = document.forms.board.body.value;
if (0 == strText.length)
{
//alert("Введите текст для преобразования!");
document.forms.board.body.focus();
return strText;
}
if ("qw" == decoder_type)
strText = DoQuotedWin(strText, true);
else if ("wq" == decoder_type)
strText = DoQuotedWin(strText, false);
else
strText = DoTableWin(strText, decoder_type);
document.forms.board.body.value = strText;
return strText;
}


function Symbol(action) {
	var revisedMessage;
	var currentMessage = document.board.body.value;
	document.board.body.value=currentMessage+'<font face="Symbol">'+action+'</font>';
	document.board.body.focus();
}

function Greek(action) {
	var revisedMessage;
	var currentMessage = document.board.body.value;
	document.board.body.value=currentMessage+action;
	document.board.body.focus();
}






// Helpline messages
b_help = "Жирный текст: <b>текст</b>  (alt+b)";
i_help = "Наклонный текст: <i>текст</i>  (alt+i)";
u_help = "Подчёркнутый текст: <u>текст</u>  (alt+u)";
q_help = "Код программ и текстовая псевдографика: <pre>код</pre>";
c_help = "Формула LaTeX: <math>Формула</math>";
l_help = "Математический пакет \"Граф\": <gra>Формула</gra> (alt+l)";
o_help = "E-mail: <a href=\"mailto:info\@website.ru\">Мой e-mail</a>  (alt+o)";
p_help = "Вставить картинку: <img src=\"http://ссылка на рисунок\">  (alt+p)";
s_help = "Цвет шрифта: <font color=red>текст</font>  Подсказка: можно использовать color=#FF0000";
w_help = "Вставить ссылку: <a href=\"http://адрес ссылки\">URL</a>  (alt+w)";


// Define the htmlCode tags
htmlcode = new Array();
htmltags = new Array('<b>','</b>','<i>','</i>','<u>','</u>','<pre>','</pre>','<math>','</math>','<gra>','</gra>','<list=>','</list>','<img>','</img>','<url>','</url>');
imageTag = false;


// Shows the help messages in the helpline window
function htmlhelpline(help) {
	document.board.htmlhelpbox.value = eval(help + "_help");
}


function htmlfontstyle(htmlopen, htmlclose) {
	var txtarea = document.board.body;

	if ((clientVer >= 4) && is_ie && is_win) {
		theSelection = document.selection.createRange().text;
		if (!theSelection) {
			txtarea.value += htmlopen + htmlclose;
			txtarea.focus();
			return;
		}
		document.selection.createRange().text = htmlopen + theSelection + htmlclose;
		txtarea.focus();
		return;
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, htmlopen, htmlclose);
		return;
	}
	else
	{
		txtarea.value += htmlopen + htmlclose;
		txtarea.focus();
	}
	storeCaret(txtarea);
}


function htmlstyle(htmlnumber) {
	var txtarea = document.board.body;

	txtarea.focus();
	donotinsert = false;
	theSelection = false;
	htmllast = 0;

	if (htmlnumber == -1) { // Close all open tags & default button names
		while (htmlcode[0]) {
			butnumber = arraypop(htmlcode) - 1;
			txtarea.value += htmltags[butnumber + 1];
			buttext = eval('document.board.addhtmlcode' + butnumber + '.value');
			eval('document.board.addhtmlcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
		}
		imageTag = false; // All tags are closed including image tags :D
		txtarea.focus();
		return;
	}

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection) {
			// Add tags around selection
			document.selection.createRange().text = htmltags[htmlnumber] + theSelection + htmltags[htmlnumber+1];
			txtarea.focus();
			theSelection = '';
			return;
		}
	}
	else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, htmltags[htmlnumber], htmltags[htmlnumber+1]);
		return;
	}

	// Find last occurance of an open tag the same as the one just clicked
	for (i = 0; i < htmlcode.length; i++) {
		if (htmlcode[i] == htmlnumber+1) {
			htmllast = i;
			donotinsert = true;
		}
	}

	if (donotinsert) {		// Close all open tags up to the one just clicked & default button names
		while (htmlcode[htmllast]) {
				butnumber = arraypop(htmlcode) - 1;
				txtarea.value += htmltags[butnumber + 1];
				buttext = eval('document.board.addhtmlcode' + butnumber + '.value');
				eval('document.board.addhtmlcode' + butnumber + '.value ="' + buttext.substr(0,(buttext.length - 1)) + '"');
				imageTag = false;
			}
			txtarea.focus();
			return;
	} else { // Open tags

		if (imageTag && (htmlnumber != 14)) {		// Close image tag before adding another
			txtarea.value += htmltags[15];
			lastValue = arraypop(htmlcode) - 1;	// Remove the close image tag from the list
			document.board.addhtmlcode14.value = "Img";	// Return button back to normal state
			imageTag = false;
		}

		// Open tag
		txtarea.value += htmltags[htmlnumber];
		if ((htmlnumber == 14) && (imageTag == false)) imageTag = 1; // Check to stop additional tags after an unclosed image tag
		arraypush(htmlcode,htmlnumber+1);
		eval('document.board.addhtmlcode'+htmlnumber+'.value += "*"');
		txtarea.focus();
		return;
	}
	storeCaret(txtarea);
}

   




function PopUp(url, name, width,height,center,resize,scroll,posleft,postop) {
    if (posleft != 0) { x = posleft }
    if (postop  != 0) { y = postop  }
    if (!scroll) { scroll = 1 }
    if (!resize) { resize = 1 }
    if ((parseInt (navigator.appVersion) >= 4 ) && (center)) {
      X = (screen.width  - width ) / 2;
      Y = (screen.height - height) / 2;
    }
    if (scroll != 0) { scroll = 1 }
    var Win = window.open( url, name, 'width='+width+',height='+height+',top='+Y+',left='+X+',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
        }
        function ShowHide(id1, id2) {
          if (id1 != '') expMenu(id1);
          if (id2 != '') expMenu(id2);
        }
        function expMenu(id) {
          var itm = null;
          if (document.getElementById) {
                itm = document.getElementById(id);
          } else if (document.all){
                itm = document.all[id];
          } else if (document.layers){
                itm = document.layers[id];
          }
          if (!itm) {
           // do nothing
          }
          else if (itm.style) {
                if (itm.style.display == "none") { itm.style.display = ""; }
                else { itm.style.display = "none"; }
          }
          else { itm.visibility = "show"; }
        }