function BotoTranslit(el) {
	var agt, isIe, isGecko, o, elCont, self;

	/* Detect browser */
	agt = navigator.userAgent.toLowerCase();
	isIE    = ((agt.indexOf("msie")  != -1) && (agt.indexOf("opera") == -1));
	isGecko = ((agt.indexOf('gecko') != -1) && (agt.indexOf("khtml") == -1));
	if ((!isIE) && (!isGecko)) {
		this.el        = el;
		this.supported = false;
		return;
	}
	
	/* set delay in ms before spellchecker kicks in */
	if(isGecko) {
		this.SPELL_CHECK_DELAY = 500;
	}
	else {
		this.SPELL_CHECK_DELAY = 1500;
	}
		 
	
	/* Set initial values */
	this.supported = true;
	this.elText    = el;
	this._start    = 0;
	this._len      = 0;
	this._lagTimer = null;

	/* Create markup container */
	elCont = document.createElement('div');
	elCont.className = 'webfx-spell-markupbox';
	el.parentNode.insertBefore(elCont, el);
	el.className = 'webfx-spell-textarea';
	elCont.style.width = el.clientWidth + 'px';
	elCont.style.height = el.clientHeight + 'px';
	this.elCont = elCont;

	/* Register instance and init static webFXSpellCheckHandler if needed */
	if (webFXSpellCheckHandler.instances.length == 0) { webFXSpellCheckHandler._init(); }
	o = new Object();
	o.elText = el;
	o.elCont = elCont;
	o.self   = this;
	this._instance = webFXSpellCheckHandler.instances.length;
	webFXSpellCheckHandler.instances.push(o);

	/*
	 * Assign event handlers
	 */	
	self = this;
	
	this._handleChange = function(e) {
		self._handleKey();
		self._syncScroll();
		self._lagTimer = null;
	}
	
	this.elText.onchange = this.elText.onkeyup = function(e) {
		if(self._lagTimer) clearTimeout(self._lagTimer);
		self._lagTimer = setTimeout(self._handleChange, self.SPELL_CHECK_DELAY);
	};

	if(isGecko) {
		this.elText.onkeypress = function(e) {
			try {
				transliteField(this,e);
			}
			catch(err) {
				alert(err);
			}
			switch(e.keyCode) {
				case 37: case 38: case 39: case 40:
					self._handleKey();
			}
		};
	}
	else {
				
	}
		
	this.elText.onselect = function(e) {
		self._determineActiveNode();
		self._syncScroll();
	};
	
	this.elText.onclick = function(e) {
		self._handleClick((e)?e:window.event);
		self._syncScroll();
	};

	/*
	 * As onscroll doesn't work on textareas in gecko (see bug #229089)
	 * the _syncScroll method is called by the onmousemove event handler
	 * instead... not pretty but it works pretty good.
	 */	
	if (isGecko) {
		this.elText.onmousemove = function(e) {
			self._syncScroll();
		};
	}
	else {
		this.elText.onscroll = function(e) {
			self._syncScroll();
		};
	}
	
	/* Populate with initial content */
	this.update();
}


BotoTranslit.prototype.getText = function() {
	return this.elText.value
};


BotoTranslit.prototype.setText = function(str) {
	this.elText.value = str;
	this.update();
};


BotoTranslit.prototype.replaceActive = function(word) {
	var str, len, n, offset, start, end, c;
	
	if (this._nodeEnd) {
		this._setWord(this._nodeEnd, word);
		
		str = this.elText.value;
		len = str.length;
		
		
		offset = this._end;
		
		for (n = offset-2; n >= 0; n--) {
			c = str.substr(n, 1);
			if (!c.match(/[а-яА-Я0-9_\']/)) { break; } //'
		}
		start = n+1;
		
		for (n = offset; n < len; n++) {
			c = str.substr(n, 1);
			if (!c.match(/[а-яА-Я0-9_\']/)) { break; } //'
		}
		end = n;

		this.elText.value = str.substr(0, start) + word + str.substr(end, len-end);
		this._determineActiveNode();	
}	};

BotoTranslit.prototype.rescan = function(word) {
	var node;
	
	if(word) {
		word = word.toLowerCase();
		els = this.elCont.getElementsByTagName('span');
		
		for(var i=0,l=els.length; i<l; i++) {
			if(els[i].getAttribute('lc') == word) els[i].style.background = 'none';
		}
	} else {
		for (node = this.elCont.firstChild; node; node = node.nextSibling) {
			if (node.firstChild) {
				switch (webFXSpellCheckHandler._spellCheck(node.firstChild)) {
					case RTSS_VALID_WORD:
					case RTSS_PENDING_WORD: node.style.background = 'none';                               break;
					case RTSS_INVALID_WORD: node.style.background = webFXSpellCheckHandler.invalidWordBg; break;
				}
			}
		}
	}
};


/*----------------------------------------------------------------------------\
|                               Private Methods                               |
\----------------------------------------------------------------------------*/

BotoTranslit.prototype._getSelection = function() {
	if (document.all) {
		var sr, r, offset;
		sr = document.selection.createRange();
		r = sr.duplicate();
		r.moveToElementText(this.elText);
		r.setEndPoint('EndToEnd', sr);
		this._start = r.text.length - sr.text.length;
		this._end   = this._start + sr.text.length;
	}
	else {
		this._start = this.elText.selectionStart;
		this._end   = this.elText.selectionEnd;
	}
};


BotoTranslit.prototype._handleKey = function(charCode) {
	var str, len, lastStart, lastEnd;
	
	str = this.elText.value;
	
	len = str.length;
	
	lastStart = this._start;
	lastEnd   = this._end;
	
	this._determineActiveNode();
	
	if ((this._last != str) || (len != this._len)) {
			
		/* Remove deleted/replaced text */
		if (lastEnd > lastStart) {
			this._remove(lastStart, lastEnd);
		}
		
		/* Remove text erased by backspace*/
		else if (lastEnd > this._start) {
			this._remove(this._start, lastEnd);
		}

		/* Append/insert new text */
		if (this._start > lastStart) {
			this._insert(lastStart, this._start);
	}	}

	this._len   = len;
	this._last  = str;
};

BotoTranslit.prototype.update = function() {
	while (this.elCont.firstChild) { this.elCont.removeChild(this.elCont.firstChild); }
	this._insertWord(null, this.elText.value);
};


BotoTranslit.prototype._createWordNode = function(word) {
	var node = document.createElement('span');
	node.className = 'webfx-spellchecker-word';
	node.setAttribute('lc', word.toLowerCase());
	node.appendChild(document.createTextNode(word));
	
	switch (webFXSpellCheckHandler._spellCheck(word)) {
		case RTSS_VALID_WORD:
		case RTSS_PENDING_WORD: node.style.background = 'none';                               break;
		case RTSS_INVALID_WORD: node.style.background = webFXSpellCheckHandler.invalidWordBg; break;
	};
	return node;
};


BotoTranslit.prototype._determineActiveNode = function() {
	var i, len, c, str, node, l;

	this._getSelection();
	this._nodeStart = null;
	this._nodeEnd   = null;
	
	node = this.elCont.firstChild;
	for (i = 0; node; node = node.nextSibling) {
		if (node.nodeType == 1) {
			str = (node.firstChild)?node.firstChild.nodeValue:'\n';
		}
		else { str = node.nodeValue; }
		
		n = str.length;
		
		if (i+n <= this._start) { this._nodeStart = node; }
		this._nodeEnd = node;
		if (i+n >= this._end) { break; }
		i += n;
	}
	
};


BotoTranslit.prototype._setWord = function(el, word) {
	var i, len, c, str, node, doc, n, last;
	
	len = word.length;

	str = '';
	n = 0;
	for (i = 0; i < len; i++) {
		c = word.substr(i, 1);
		
		if (!c.match(/[а-яА-Я0-9_\']/)) { // Match all but numbers, letters, - and '
			if (str) {
				el.parentNode.insertBefore(this._createWordNode(str), el);
			}
			
			last = (el.previousSibling)?el.previousSibling.nodeValue:'';
			switch (c) {
				case '\n': node = document.createElement('br');                   break;
				case ' ':  node = document.createTextNode((last == ' ')?' ':' '); break;
				default:   node = document.createTextNode(c);
			};
			el.parentNode.insertBefore(node, el);
			str = '';
			n++;
		}
		else { str += c; }
	}
	if (str) {
		if (el.firstChild) {
			el.firstChild.nodeValue = str;
			var res = webFXSpellCheckHandler._spellCheck(str);
			switch (res) {
				case RTSS_VALID_WORD: 
				case RTSS_PENDING_WORD: el.style.background = 'none';                               break;
				case RTSS_INVALID_WORD: el.style.background = webFXSpellCheckHandler.invalidWordBg; break;
			};
		}
		else { 
			node = this._createWordNode(str);
			el.parentNode.replaceChild(node, el);
			el = node;
	}	}
	else {
		node = el.previousSibling;
		el.parentNode.removeChild(el);
		el = node;
	}
	
	return el;
};


BotoTranslit.prototype._insertWord = function(el, word) {
	var i, len, c, str, node, n, last;
	
	len = word.length;
	str = '';
	n = 0;
	node = null;
	for (i = 0; i < len; i++) {
		c = word.substr(i, 1);
		
		if (!c.match(/[а-яА-Я0-9_\']/)) { // Match all but numbers, letters, - and '
			if (str) {
				if (el) { node = this.elCont.insertBefore(this._createWordNode(str), el); }
				else { node = this.elCont.appendChild(this._createWordNode(str)); }
			}

			last = ((el) && (el.previousSibling))?el.previousSibling.nodeValue:'';
			switch (c) {
				case '\n': node = document.createElement('br'); break;
				case ' ':  node = document.createTextNode((last == ' ')?' ':' '); break;
				default:   node = document.createTextNode(c);
			};
			if (el) { this.elCont.insertBefore(node, el); }
			else { this.elCont.appendChild(node); }
			str = '';
			n++;
		}
		else {str += c;}
	}
	
	if (str) {
		
		if (el) { node = this.elCont.insertBefore(this._createWordNode(str), el); }
		else { node = this.elCont.appendChild(this._createWordNode(str)); }
	}
	else if (el) {
		if (!node) { node = el.previousSibling; }
	}
	
	return node;
};

BotoTranslit.prototype._remove = function(startPos, endPos) {
	var node, i, n, startNode, endNode, word, next;

	/* Locate start and end node and determine what to keep of first and last node */	
	i = 0;
	startNode = endNode = null;
	for (node = this.elCont.firstChild; node; node = node.nextSibling) {
		if (node.nodeType == 1) {
			str = (node.firstChild)?node.firstChild.nodeValue:'\n';
		}
		else { str = node.nodeValue; }
		n = str.length;
			
		if ((startNode == null) && (i + n >= startPos)) {
			startNode = node;
			word = str.substr(0, startPos - i);
		}
		if (i + n >= endPos) {
			endNode = node.nextSibling;
			word += str.substr(endPos - i, n - (endPos - i));
			break;
		}
		
		i += n;
	}
	
	if (!startNode) { return; }
	
	/* Remove all but first node */
	for (node = startNode.nextSibling; node != endNode; node = next) {
		next = node.nextSibling;
		this.elCont.removeChild(node);
	}

	/* Set new word */	
	this._setWord(startNode, word);
};

BotoTranslit.prototype._insert = function(startPos, endPos) {
	var str, i, len, c, word, newNode, offset, startNode;

	/* Locate start node and determine offset */	
	i = 0;
	startNode = null;
	for (node = this.elCont.firstChild; node; node = node.nextSibling) {
		if (node.nodeType == 1) {
			str = (node.firstChild)?node.firstChild.nodeValue:'\n';
		}
		else { str = node.nodeValue; }
		n = str.length;
		if (i + n >= startPos) {
			startNode = node;
			offset = startPos - i
			break;
		}
		i += n;
	}
	
	str = this.elText.value.substring(startPos, endPos);
	if (startNode) {
		if (startNode.firstChild) {
			word = node.firstChild.nodeValue.substr(0, offset) + str + node.firstChild.nodeValue.substr(offset, node.firstChild.nodeValue.length);
			this._setWord(startNode, word);
		}
		else { this._insertWord(startNode.nextSibling, str); }
	}

	else {
		len = str.length;
		node = startNode;
		word = '';
		for (i = 0; ; i++) {
			c = str.substr(i, 1);
			if ((i >= len) || (!c.match(/[а-яА-Я0-9_\']/))) { // all but numbers, letters and '
				if (word) {
					newNode = this._createWordNode(word);
					if (node) { this.elCont.insertBefore(newNode, node); }
					else { this.elCont.appendChild(newNode); }
					word = '';
				}
				if (i >= len) { break; }
				
				last = (node && node.previousSibling)?node.previousSibling.nodeValue:'';
				switch (c) {
					case '\n': newNode = document.createElement('br');                   break;
					case ' ':  newNode = document.createTextNode((last == ' ')?' ':' '); break;
					default:   newNode = document.createTextNode(c);
				};
				if (node) { this.elCont.insertBefore(newNode, node); }
				else { this.elCont.appendChild(newNode); }
				
			}
			else { word += c; }
	}	}
};

BotoTranslit.prototype._syncScroll = function() {
	this.elCont.scrollTop = this.elText.scrollTop;
	this.	elCont.scrollLeft = this.elText.scrollLeft;
};

BotoTranslit.prototype._handleClick = function(e) {
	var word, o;
	
	this._determineActiveNode();
	if ((this._nodeEnd) && (this._nodeEnd.firstChild)) {
		word = this._nodeEnd.firstChild.nodeValue;
		o    = webFXSpellCheckHandler.words[word];
		if ((o) && (o[0] == RTSS_INVALID_WORD)) {
			webFXSpellCheckHandler._showSuggestionsMenu(e, this._nodeEnd, word, this._instance);
			return
	}	}
	
	webFXSpellCheckHandler._hideSuggestionsMenu();
};



/* Translit methods */
var DOM = document.getElementById ? 1 : 0, 
        opera = window.opera && DOM ? 1 : 0, 
        IE = !opera && document.all ? 1 : 0, 
        NN6 = DOM && !IE && !opera ? 1 : 0; 

var myDate = new Date();
var myExp = myDate.getTime() + (365 * 24 * 60 * 60 * 1000);
myDate.setTime(myExp);
var direction=1;
var isChat=false;
var DebugString="";


NoHtml=true;
NoScript=true;
NoStyle=true;
NoBBCode=true;
NoInstruction=false;

function setCondition(){
	transHtmlPause=false;
	transScriptPause=false;
	transStylePause=false;
	transInstructionPause=false;
	transBBPause=false;
	
}
setCondition();

//alert(document.cookie) ;

function SetPechenki(Name,Longness){
	document.cookie = Name+"="+Longness+"; expires=" + myDate.toGMTString();
}

/*function changeNoTranslit(Nr){
	if(document.trans.No_translit_HTML.checked)NoHtml=true;else{NoHtml=false}
	//if(document.trans.No_translit_Script.checked)NoScript=true;else{NoScript=false}
	//if(document.trans.No_translit_Style.checked)NoStyle=true;else{NoStyle=false}
	if(document.trans.No_translit_BBCode.checked)NoBBCode=true;else{NoBBCode=false}
	SetPechenki("NoHtml",NoHtml);SetPechenki("NoScript",NoScript);SetPechenki("NoStyle",NoStyle);SetPechenki("NoBBCode",NoBBCode);
}*/

function changedirection(r){
	direction=r;SetPechenki("Transdirection",direction);setFocus()
}

function changelanguage(){  
	if (language==1) {language=0;}
	else {language=1;}
	SetPechenki("autoTrans",language);
	setFocus();
	setCondition();
}

function setFocus(){elText.focus();}

function clearAll(){elText.value = '';}

function repl(t,a,b){	var w=t,i=0,n=0;	while((i=w.indexOf(a,n))>=0)		{
		t=t.substring(0,i)+b+t.substring(i+a.length,t.length);	
		w=w.substring(0,i)+b+w.substring(i+a.length,w.length);		n=i+b.length;		if(n>=w.length){break;}
		}	return t;	}
function smiles1(txt)	{
	var i,	buf=txt;
	for(i=0;i<sm1.length;i++){
			buf=repl(buf,sm1[i],sm2[i]);
	}
	txt=buf;
	
	return txt;
}
function smiles2(txt)	{
	var i,	buf=txt;
	for(i=0;i<sm1.length;i++){
			buf=repl(buf,sm2[i],sm1[i]);
	}
	txt=buf;
	
	return txt;
}
var sm1=new Array("oops:",":D",":-D",":grin:",":)",":-)",":smile:",":(",":-(",":sad:",":o",":-o",":eek:",":shock:",":?",":-?",":???:","8)","8-)",":cool:",":lol:",":x",":-x",":mad:",":P",":-P",":razz:",":oops:",":cry:",":evil:",":twisted:",":roll:",":wink:",";)",";-)",":!:",":?:",":idea:",":arrow:",":|",":-|",":neutral:",":mrgreen:")
var sm2=new Array("[oops:]","[:D]","[:-D]","[:grin:]","[:)]","[:-)]","[:smile:]","[:(]","[:-(]","[:sad:]","[:o]","[:-o]","[:eek:]","[:shock:]","[:?]","[:-?]","[:???:]","[8)]","[8-)]","[:cool:]","[:lol:]","[:x]","[:-x]","[:mad:]","[:P]","[:-P]","[:razz:]","[:oops:]","[:cry:]","[:evil:]","[:twisted:]","[:roll:]","[:wink:]","[;)]","[;-)]?","[:!:]","[:?:]","[:idea:]","[:arrow:]","[:|]","[:-|]","[:neutral:]","[:mrgreen:]")
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)+'-q').split('-');
var rus_rl = ('А-Б-В-Г-Д-Е-Ё-Ж-З-И-Й-К-Л-М-Н-О-П-Р-С-Т-У-Ф-Х-Ц-Ч-Ш-Щ-Ъ-Ы-Ь-Э-Ю-Я-а-б-в-г-д-е-ё-ж-з-и-й-к-л-м-н-о-п-р-с-т-у-ф-х-ц-ч-ш-щ-ъ-ы-ь-э-ю-я').split('-');
var lat_rl = ('A-B-V-G-D-E-JO-ZH-Z-I-J-K-L-M-N-O-P-R-S-T-U-F-H-C-CH-SH-SHH-'+String.fromCharCode(35)+String.fromCharCode(35)+'-Y-'+String.fromCharCode(39)+String.fromCharCode(39)+'-JE-JU-JA-a-b-v-g-d-e-jo-zh-z-i-j-k-l-m-n-o-p-r-s-t-u-f-h-c-ch-sh-shh-'+String.fromCharCode(35)+'-y-'+String.fromCharCode(39)+'-je-ju-ja').split('-');
var transAN=true;

function transliteText(txt)
{
	
	sourceTxt=txt.length>1?txt.substr(txt.length-2,1):"";
	letter=txt.substr(txt.length-1,1);
	txt=txt.substr(0,txt.length-2);
	//alert(sourceTxt+" "+letter);
	return txt+translitletterCyr(sourceTxt,letter);
}
function translitletterCyr(sourceTxt,txt)
{
	var twices = sourceTxt+txt;
	var code = txt.charCodeAt(0);
	
	if(txt=="<")transHtmlPause=true;else if(txt==">")transHtmlPause=false;
	if(txt=="<script")transScriptPause=true;else if(txt=="</script>")transScriptPause=false;
	if(txt=="<style")transStylePause=true;else if(txt=="</style>")transStylePause=false;
	if(txt=="[")transBBPause=true;else if(txt=="]")transBBPause=false;
	if(txt=="/")transInstructionPause=true;else if(txt==" ")transInstructionPause=false;
	
	
	
	if (
		(transHtmlPause==true 	&&   NoHtml==true)||
		(transScriptPause==true &&   NoScript==true)||
		(transStylePause==true 	&&   NoStyle==true)||
		(transBBPause==true 	&&   NoBBCode==true)||
		(transInstructionPause==true &&   NoInstruction==true)||
		
		!(((code>=65) && (code<=123))||(code==35)||(code==39))) return twices;
	
	for (x=0; x<lat_lr2.length; x++)
	{
		if (lat_lr2[x]==twices) return rus_lr2[x];
	}
	for (x=0; x<lat_lr1.length; x++)
	{
		if (lat_lr1[x]==txt) return sourceTxt+rus_lr1[x];
	}
	return twices;
}
function translitletterLat(letter)
{
	for (x=0; x<rus_rl.length; x++)
	{
		if (rus_rl[x]==letter)
		return lat_rl[x];
	}
	return letter;
}
function translateAlltoLatin()
{
	if (!IE) 
	{
		
		var txt=elText.value;
		var txtnew = "";
		var symb = "";
		for (y=0;y<txt.length;y++)
		{
			symb = translitletterLat(txt.substr(y,1));
			txtnew += symb;
			//alert(symb);
		}
		elText.value = txtnew;
		setFocus()
	} 
	else
	{
		var is_selection_flag = 1;
		var userselection = document.selection.createRange();
		var txt = userselection.text;

		if (userselection==null || userselection.text==null || userselection.parentElement==null || userselection.parentElement().type!="elText") 
		{
			is_selection_flag = 0;
			txt = elText.value;
		}
		txtnew="";
		var symb = "";
		for (y=0;y<txt.length;y++)
		{
			symb = translitletterLat(txt.substr(y,1));
			txtnew +=  symb;
			
		}
		if (is_selection_flag)
		{
			userselection.text = txtnew; userselection.collapse(); userselection.select();
		}
		else
		{
			elText.value = txtnew;
			setFocus()
		}
	}
	return;
}

function transliteField(object,evnt)
{
 if (language==1 || opera) return; //nothing to translit
 
	if (NN6){
			//alert(object);
		  	var code=void 0;
			var code =  evnt.charCode; 
			var elTextfontsize = 14; 
			var textreafontwidth = 7;
			//alert(evnt.charCode)
			if(code == 13){return;}
			if ( code && (!(evnt.ctrlKey || evnt.altKey)))
			{
				
        	
        	
				pXpix = object.scrollTop;
				pYpix = object.scrollLeft;
        	
        	
				evnt.preventDefault();
				txt=String.fromCharCode(code);
				pretxt = object.value.substring(0, object.selectionStart);
				result = transliteText(pretxt+txt);
				object.value = result+object.value.substring(object.selectionEnd);
				object.setSelectionRange(result.length,result.length);
				object.scrollTop=100000;
				object.scrollLeft=0;
				
				cXpix = (result.split("\n").length)*(elTextfontsize+3);
				cYpix = (result.length-result.lastIndexOf("\n")-1)*(textreafontwidth+1);
				taXpix = (object.rows+1)*(elTextfontsize+3);
				taYpix = object.clientWidth;
				
				if ((cXpix>pXpix)&&(cXpix<(pXpix+taXpix))) object.scrollTop=pXpix;
				if (cXpix<=pXpix) object.scrollTop=cXpix-(elTextfontsize+3);
				if (cXpix>=(pXpix+taXpix)) object.scrollTop=cXpix-taXpix;
				
				if ((cYpix>=pYpix)&&(cYpix<(pYpix+taYpix))) object.scrollLeft=pYpix;
				if (cYpix<pYpix) object.scrollLeft=cYpix-(textreafontwidth+1);
				if (cYpix>=(pYpix+taYpix)) object.scrollLeft=cYpix-taYpix+1;
			}
			return true;
		
	}
	else if(IE){
		if(isChat){
			var code = frames['input'].event.keyCode;
			if(code == 13){return;} //Enter pressed
			txt=String.fromCharCode(code);
			cursor_pos_selection = frames['input'].document.selection.createRange();
			cursor_pos_selection.text="";
			cursor_pos_selection.moveStart("character",-1);
			sourceTxt = cursor_pos_selection.text;
			if (sourceTxt.length>1) {sourceTxt="";}
			frames['input'].event.keyCode = 0;
			if (direction==2){result = sourceTxt+translitletterLat(txt)}
			else{result = translitletterCyr(sourceTxt,txt)}
			
			if (sourceTxt!="") { cursor_pos_selection.select(); cursor_pos_selection.collapse();}
			with(frames['input'].document.selection.createRange()) {text = result; collapse(); select()}	
			
		}else{
			var code = event.keyCode;
			if(code == 13){return;} //Enter pressed
			txt=String.fromCharCode(code);
			cursor_pos_selection = document.selection.createRange();
			cursor_pos_selection.text="";
			cursor_pos_selection.moveStart("character",-1);
			sourceTxt = cursor_pos_selection.text;
			if (sourceTxt.length>1) {sourceTxt="";}
			event.keyCode = 0;
			if (direction==2){result = sourceTxt+translitletterLat(txt)}
			else{result = translitletterCyr(sourceTxt,txt)}
			
			if (sourceTxt!="") { cursor_pos_selection.select(); cursor_pos_selection.collapse();}
			with(document.selection.createRange()) {text = result; collapse(); select()}	
		}
		return;
   }
}


function translateAlltoCyrillic() 
{
	if (!IE) 
	{
		txt = smiles1(elText.value);
		
		var txtnew = translitletterCyr("",txt.substr(0,1));
		var symb = "";
		for (kk=1;kk<txt.length;kk++)
		{
			symb = translitletterCyr(txtnew.substr(txtnew.length-1,1),txt.substr(kk,1));
			txtnew = txtnew.substr(0,txtnew.length-1) + symb;
		}
		elText.value = smiles2(txtnew);
		setFocus()
	} //end scenario
	else
	{ // IE scenario
		var is_selection_flag = 1;
		var userselection = document.selection.createRange();
		var txt = userselection.text;
		if (userselection==null || userselection.text==null || userselection.parentElement==null || userselection.parentElement().type!="elText") 
		{
			// no text selected, all the text in the elText is to be processed
			is_selection_flag = 0;
			txt = elText.value;
		}
		txt=smiles1(txt);
		var txtnew = translitletterCyr("",txt.substr(0,1));
		var symb = "";
		for (kk=1;kk<txt.length;kk++)
		{
			symb = translitletterCyr(txtnew.substr(txtnew.length-1,1),txt.substr(kk,1));
			txtnew = txtnew.substr(0,txtnew.length-1) + symb;
		}
		if (is_selection_flag)
		{
			userselection.text = txtnew; userselection.collapse(); userselection.select();
		}
		else
		{
			elText.value = smiles2(txtnew);
			setFocus()
		}
	} //end IE scenario
	return;
}
