<!--
var rus_lr2=('Е-е-О-о-Ё-Ё-Ё-Ё-Ж-Ж-Ч-Ч-Ш-Ш-Щ-Щ-Ъ-Ь-Э-Э-Ю-Ю-Я-Я-Я-Я-ё-ё-ж-ч-ш-щ-э-ю-я-я').split('-');
var lat_lr2=('/E-/e-/O-/o-ЫO-Ыo-ЙO-Йo-ЗH-Зh-ЦH-Цh-СH-Сh-ШH-Шh-ъ'+String.fromCharCode(35)+'-ь'+String.fromCharCode(39)+'-ЙE-Йe-ЙU-Йu-ЙA-Йa-ЫA-Ыa-ыo-йo-зh-цh-сh-шh-йe-йu-йa-ыa').split('-');
var rus_lr1=('А-Б-В-Г-Д-Е-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Х-Ц-Щ-Ы-Я-а-б-в-г-д-е-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-х-ц-щ-ъ-ы-ь-ь-я').split('-');
var lat_lr1=('A-B-V-G-D-E-Z-I-J-K-L-M-N-O-P-R-S-T-U-F-H-X-C-W-Y-Q-a-b-v-g-d-e-z-i-j-k-l-m-n-o-p-r-s-t-u-f-h-x-c-w-'+String.fromCharCode(35)+'-y-'+String.fromCharCode(39)+'-'+String.fromCharCode(96)+'-q').split('-');

function dotranslate(text) {
	var txtnew = "";
	var symb = 0;
	var subsymb = "";
	var trans = 1;
	for (kk = 0; kk < text.length; kk++) {
		subsymb = text.substr(kk, 1);
		if (subsymb == "[" || subsymb == "<") {
			trans = 0;
		}
		if (subsymb == "]" || subsymb == ">") {
			trans = 1;
		}
		if (trans) {
			symb = transsymbtocyr(txtnew.substr(txtnew.length - 1, 1), subsymb);
		} else {
			symb = txtnew.substr(txtnew.length - 1, 1) + subsymb;
		}
		txtnew = txtnew.substr(0, txtnew.length - 1) + symb;
	}

	return txtnew;
}


function transsymbtocyr(pretxt, txt) {
	var doubletxt = pretxt + txt;
	var code = txt.charCodeAt(0);
	if (!(code >= 65 && code <= 123 || code == 35 || code == 39)) {
		return doubletxt;
	}
	var ii;
	for (ii = 0; ii < lat_lr2.length; ii++) {
		if (lat_lr2[ii] == doubletxt) {
			return rus_lr2[ii];
		}
	}
	for (ii = 0; ii < lat_lr1.length; ii++) {
		if (lat_lr1[ii] == txt) {
			return pretxt + rus_lr1[ii];
		}
	}
	return doubletxt;
}

function translate_update() {
if(IsSel(document.Chat.entry))
{
	txt = getSel(document.Chat.entry);	
	if(txt == '')
	{
		var dob = document.Chat.entry;
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}
	AddTxt=dotranslate(txt);
	SetSel(document.Chat.entry,AddTxt);  
}else{
     	txt=prompt("Введите текст, который вы хотите транслитерировать","","Text");
		if(txt!=null) {
			AddTxt=dotranslate(txt);
			AddText(AddTxt);        
		}
}
}

function translate_comment() {
if(IsSel(document.updateForm.centry))
{
	txt = getSel(document.updateForm.centry);	
	if(txt == '')
	{
		var dob = document.updateForm.centry;
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}
	AddTxt=dotranslate(txt);
	SetSel(document.updateForm.centry,AddTxt);  
}else{
     	txt=prompt("Введите текст, который вы хотите транслитерировать","","Text");
		if(txt!=null) {
			AddTxt=dotranslate(txt);
			AddText(AddTxt);        
		}
}
}



function setfocus(dob) {
	//document.Chat.entry.focus();
	dob.focus();
}

function setfocusCmnt(dob) {
	//document.updateForm.centry.focus();
	dob.focus();
}

function AddText(NewCode) {
	var dob = document.Chat.entry
	setfocus(dob);
	if (dob.createTextRange && dob.caretPos) {
		var caretPos = dob.caretPos;
		var ce = caretPos.text.length;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
		dob.caretPos = caretPos + NewCode.length;
	}
	else if (dob.setSelectionRange) {
		var st=dob.scrollTop;
		var es=dob.selectionEnd;
		dob.value = dob.value.substring(0,dob.selectionStart) + NewCode + dob.value.substring(dob.selectionEnd,dob.value.length);
		dob.selectionStart = es + NewCode.length;
		dob.selectionEnd = es + NewCode.length;
		dob.scrollTop=st;
	}
	else {
		dob.value += NewCode;
	}
	
	bodytext = "";
}

function AddTextCmnt(NewCode) {
	var dob = document.updateForm.centry
	setfocusCmnt(dob);
	if (dob.createTextRange && dob.caretPos) {
		var caretPos = dob.caretPos;
		var ce = caretPos.text.length;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? NewCode + ' ' : NewCode;
		dob.caretPos = caretPos + NewCode.length;
	}
	else if (dob.setSelectionRange) {
		var st=dob.scrollTop;
		var es=dob.selectionEnd;
		dob.value = dob.value.substring(0,dob.selectionStart) + NewCode + dob.value.substring(dob.selectionEnd,dob.value.length);
		dob.selectionStart = es + NewCode.length;
		dob.selectionEnd = es + NewCode.length;
		dob.scrollTop=st;
	}
	else {
		dob.value += NewCode;
	}

	bodytext = "";
}

function storeCaret (textEl){
	if(textEl.createTextRange){
		textEl.caretPos = document.selection.createRange().duplicate();
	}
}

function insertAtCaret (textEl, text){
	if (textEl.createTextRange && textEl.caretPos){
		var caretPos = textEl.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text : text;
	}else{
		textEl.value  = text;
	}
}

function chcolor(color) {
if(IsSel(document.Chat.entry))
{
	txt = getSel(document.Chat.entry);	
	if(txt == '')
	{
		var dob = document.Chat.entry
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}
	AddTxt="[color="+color+"]"+txt+"[/color]";
	SetSel(document.Chat.entry,AddTxt);  
}else{
     	txt=prompt("Введите текст, который вы хотите выделить цветом","текст","Text");
		if(txt!=null) {
			AddTxt="[color="+color+"]"+txt+"[/color] ";
			AddText(AddTxt);        
		} 
}
}

function blockcolor(color) {
if(IsSel(document.Chat.entry))
{
	txt = getSel(document.Chat.entry);	
	if(txt == '')
	{
		var dob = document.Chat.entry
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}
	AddTxt="[block="+color+"]"+txt+"[/block]";
	SetSel(document.Chat.entry,AddTxt);  
}else{
     	txt=prompt("Введите текст, который вы хотите выделить цветовым блоком","текст","Text");
		if(txt!=null) {
			AddTxt="[block="+color+"]"+txt+"[/block] ";
			AddText(AddTxt);        
		}
}
}

function insertteg(message,teg) {
		if(IsSel(document.Chat.entry))
		{
			txt = getSel(document.Chat.entry);	
			if(txt == '')
			{
				var dob = document.Chat.entry
				if (dob.setSelectionRange) {
					txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
				}
			}
			AddTxt="["+teg+"]"+txt+"[/"+teg+"]";
			SetSel(document.Chat.entry,AddTxt);  
		}else{

	 		txt=prompt(message+" ","текст");     
			if (txt!=null) {          
				AddTxt="["+teg+"]"+txt+"[/"+teg+"] ";
				AddText(AddTxt);  
			}
		}
}

function inserttegCmnt(message,teg) {
		if(IsSel(document.updateForm.centry))
		{
			txt = getSel(document.updateForm.centry);	
			if(txt == '')
			{
				var dob = document.updateForm.centry
				if (dob.setSelectionRange) {
					txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
				}
			}
			AddTxt="["+teg+"]"+txt+"[/"+teg+"]";
			SetSel(document.updateForm.centry,AddTxt);  
		}else{

	 		txt=prompt(message+" ","текст");     
			if (txt!=null) {          
				AddTxt="["+teg+"]"+txt+"[/"+teg+"] ";
				AddTextCmnt(AddTxt);  
			}
		}
}

function insertteg_test(message,teg) {
	var dob = document.Chat.entry
	if (dob.createTextRange && dob.caretPos) {
			AddTxt="["+teg+"]"+txt+"[/"+teg+"] ";
			AddText(AddTxt); 
	}
	else if (dob.setSelectionRange) {
			AddTxt="["+teg+"]"+txt+"[/"+teg+"] ";
			AddText(AddTxt); 
	}
	else {
 		txt=prompt(message+" ","текст");     
		if (txt!=null) {          
			AddTxt="["+teg+"]"+txt+"[/"+teg+"] ";
			AddText(AddTxt);  
		}
	}
}

function hyperlink() {
if(IsSel(document.Chat.entry))
{
	txt = getSel(document.Chat.entry);	
	if(txt == '')
	{
		var dob = document.Chat.entry
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}

	txt2=prompt("Введите адрес ссылки ","http://");      
	if (txt2!=null) {
		if (txt2=="") {
			AddTxt="[url]"+txt+"[/url]";
		} else {
			AddTxt="[url="+txt2+"]"+txt+"[/url]";
		}         
	} 

	SetSel(document.Chat.entry,AddTxt);  
}else{
			txt2=prompt("Как назвается этот сайт?\nЕсли Вы оставите это поле пустым, ссылка будет видна",""); 
		if (txt2!=null) {
			txt=prompt("Введите адрес ссылки ","http://");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url] ";
					AddText(AddTxt);
				} else {
					AddTxt="[url="+txt+"]"+txt2+"[/url] ";
					AddText(AddTxt);
				}         
			} 
		}
}
}

function quote() {
if(IsSel(document.Chat.entry))
{
	txt = getSel(document.Chat.entry);	
	if(txt == '')
	{
		var dob = document.Chat.entry
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}

	txt2=prompt("Чья эта цитата?\nЕсли Вы оставите это поле пустым, цитата будет безымянной","");
	if (txt2!=null) {
		if (txt2=="") {
			AddTxt="[quote]"+txt+"[/quote]";
		} else {
			AddTxt="[quote="+txt2+"]"+txt+"[/quote]";
		}         
	} 

	SetSel(document.Chat.entry,AddTxt);  
}else{
	txt2=prompt("Введите цитату ",""); 
	if (txt2!=null) {
		txt=prompt("Чья эта цитата?\nЕсли Вы оставите это поле пустым, цитата будет безымянной","");
		if (txt!=null) {
			if(txt!=""){
			   AddTxt="[quote="+txt+"]"+txt2+"[/quote] ";
			}else{
			   AddTxt="[quote]"+txt2+"[/quote] ";
			}
			AddText(AddTxt);
		}
	}
}
}

function quote_comment(from,comment) {
	AddTxt="[quote="+from+"]"+comment+"[/quote] ";
	AddTextCmnt(AddTxt);
}

function insertfriend() {
		txt2=prompt("Как зовут вашего друга?\nЕсли Вы оставите это поле пустым, ссылка будет видна",""); 

		if (txt2!=null) {
			txt=prompt("Его никнейм ","Text");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[friend]"+txt+"[/friend] ";
					AddText(AddTxt);
				} else {
					if(txt != ""){
						AddTxt="[friend="+txt+"]"+txt2+"[/friend] ";
					}else{
						AddTxt="[friend]"+txt2+"[/friend] ";
					}
					AddText(AddTxt);
				}         
			} 
		}
}

//Comment tags
function chcolorCmnt(color) {
if(IsSel(document.updateForm.centry))
{
	txt = getSel(document.updateForm.centry);	
	if(txt == '')
	{
		var dob = document.updateForm.centry
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}
	AddTxt="[color="+color+"]"+txt+"[/color]";
	SetSel(document.updateForm.centry,AddTxt);  
}else{
     	txt=prompt("Введите текст, который вы хотите выделить цветом","текст","Text");
		if(txt!=null) {
			AddTxt="[color="+color+"]"+txt+"[/color] ";
			AddTextCmnt(AddTxt);        
		} 
}
}

function blockcolorCmnt(color) {
if(IsSel(document.updateForm.centry))
{
	txt = getSel(document.updateForm.centry);	
	if(txt == '')
	{
		var dob = document.updateForm.centry
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}
	AddTxt="[block="+color+"]"+txt+"[/block]";
	SetSel(document.updateForm.centry,AddTxt);  
}else{
     	txt=prompt("Введите текст, который вы хотите выделить цветовым блоком","текст","Text");
		if(txt!=null) {
			AddTxt="[block="+color+"]"+txt+"[/block] ";
			AddTextCmnt(AddTxt);        
		} 
}
}
     	

function inserttegCmnt_test(message,teg) {
 		txt=prompt(message+" ","текст");     
		if (txt!=null) {          
			AddTxt="["+teg+"]"+txt+"[/"+teg+"] ";
			AddTextCmnt(AddTxt);  
	}
}

function hyperlinkCmnt() {
if(IsSel(document.updateForm.centry))
{
	txt = getSel(document.updateForm.centry);	
	if(txt == '')
	{
		var dob = document.updateForm.centry
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}

	txt2=prompt("Введите адрес ссылки ","http://");      
	if (txt2!=null) {
		if (txt2=="") {
			AddTxt="[url]"+txt+"[/url]";
		} else {
			AddTxt="[url="+txt2+"]"+txt+"[/url]";
		} 
	} 

	SetSel(document.updateForm.centry,AddTxt);  
}else{
			txt2=prompt("Как назвается этот сайт?\nЕсли Вы оставите это поле пустым, ссылка будет видна",""); 
		if (txt2!=null) {
			txt=prompt("Введите адрес ссылки ","http://");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[url]"+txt+"[/url] ";
					AddTextCmnt(AddTxt);
				} else {
					AddTxt="[url="+txt+"]"+txt2+"[/url] ";
					AddTextCmnt(AddTxt);
				}         
			} 
		}
}
}

function quoteCmt() {
	txt2=prompt("Введите цитату ",""); 
	if (txt2!=null) {
		txt=prompt("Чья эта цитата?\nЕсли Вы оставите это поле пустым, цитата будет безымянной","");
		if (txt!=null) {
			if(txt!=""){
			   AddTxt="[quote="+txt+"]"+txt2+"[/quote] ";
			}else{
			   AddTxt="[quote]"+txt2+"[/quote] ";
			}
			AddTextCmnt(AddTxt);
		}
	}
}

function insertfriendCmnt() {
			txt2=prompt("Как зовут вашего друга?\nЕсли Вы оставите это поле пустым, ссылка будет видна",""); 
		if (txt2!=null) {
			txt=prompt("Его никнейм ","Text");      
			if (txt!=null) {
				if (txt2=="") {
					AddTxt="[friend]"+txt+"[/friend] ";
					AddTextCmnt(AddTxt);
				} else {
					AddTxt="[friend="+txt+"]"+txt2+"[/friend] ";
					AddTextCmnt(AddTxt);
				}         
			} 
		}
}

function quoteCmnt() {
if(IsSel(document.updateForm.centry))
{
	txt = getSel(document.updateForm.centry);	
	if(txt == '')
	{
		var dob = document.updateForm.centry
		if (dob.setSelectionRange) {
			txt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		}
	}

	txt2=prompt("Чья эта цитата?\nЕсли Вы оставите это поле пустым, цитата будет безымянной","");
	if (txt2!=null) {
		if (txt2=="") {
			AddTxt="[quote]"+txt+"[/quote]";
		} else {
			AddTxt="[quote="+txt2+"]"+txt+"[/quote]";
		} 
	} 

	SetSel(document.updateForm.centry,AddTxt);  
}else{
	txt2=prompt("Введите цитату ",""); 
	if (txt2!=null) {
		txt=prompt("Чья эта цитата?\nЕсли Вы оставите это поле пустым, цитата будет безымянной","");      
		if (txt!=null) {
			if(txt!=""){
			   AddTxt="[quote="+txt+"]"+txt2+"[/quote] ";
			}else{
			   AddTxt="[quote]"+txt2+"[/quote] ";
			}
			AddTextCmnt(AddTxt);
		}
	}
}
}
//

function copytoCB(theField) {
var tempval=eval(theField);
tempval.focus();
tempval.select();
if (document.all){
therange=tempval.createTextRange();
therange.execCommand("Copy");
}
}

function del(href)
{
if (confirm('Вы действительно хотите удалить?')) window.location = href;
}

function IsSel(dob) {
	if (dob.createTextRange && dob.caretPos) {
		if (dob.caretPos.text.length > 0)
		{
			return(true);
		}else{
			return (false);
		}
	}
	else if (dob.setSelectionRange) {
	
		var selt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		if (selt.length > 0)
		{
			return(true);
		}else{
			return (false);
		}
	}else{
		var tmp = getSel();
		if(tmp.length > 0){
			return(true);
		}
	}
	setfocus(dob);
}

function SetSel(dob,newtext) {
	if (dob.createTextRange && dob.caretPos) {
		if (dob.caretPos.text.length > 0)
		{
			dob.caretPos.text = newtext;
			dob.caretPos.select();
		}
	}
	else if (dob.setSelectionRange) {	
		var selt = (dob.value).substring(dob.selectionStart,dob.selectionEnd)
		if (selt.length > 0)
		{
			var st=dob.scrollTop;
			var ss=dob.selectionStart;
			var stlt = ''
			dob.value = stlt.concat((dob.value).substring(0,dob.selectionStart),newtext,(dob.value).substring(dob.selectionEnd))
			dob.selectionStart = ss+newtext.length;
			dob.selectionEnd = dob.selectionStart;
			dob.scrollTop=st;
		}
	}

	setfocus(dob);
}

function TestSel() {
	alert(getSel());
}

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;
	}	else	{
		txt = '';
	}
	return(txt);
}

//-->