
			var eng=new Array(96,	49,	50,	51,	52,	53,	54,	55,	56,	57,	48,	45,	61,	92,	113,	119,	101,	114,	116,	121,	117,	105,	111,	112,	91,	93,	97,	115,	100,	102,	103,	104,	106,	107,	108,	59,	39,	122,	120,	99,	118,	98,	110,	109,	44,	46,	47,	126,	33,	64,	35,	36,	37,	94,	38,	42,	40,	41,	95,	43,	124,	81,	87,	69,	82,	84,	89,	85,	73,	79,	80,	123,	125,	65,	83,	68,	70,	71,	72,	74,	75,	76,	58,	34,	90,	88,	67,	86,	66,	78,	77,	60,	62,	63	);
  			var standart=new Array(	96,	49,	50,	51,	52,	53,	54,	55,	56,	57,	48,	45,	61,	92,	216,	223,	196,	210,	212,	218,	214,	201,	207,	208,	91,	93,	192,	211,	195,	215,	194,	228,	227,	202,	203,	59,	39,	198,	225,	221,	197,	193,	205,	204,	44,	46,	47,	126,	33,	64,	35,	36,	37,	94,	38,	42,	40,	41,	95,	43,	124,	81,	224,	69,	217,	200,	89,	85,	73,	79,	80,	123,	125,	65,	219,	68,	70,	71,	72,	209,	75,	76,	58,	34,	222,	88,	220,	86,	66,	78,	77,	60,	62,	63 	);
  			var utf8=new Array(96,	49,	50,	51,	52,	53,	54,	55,	56,	57,	48,	45,	61,	92,	4325,	4332,	4308,	4320,	4322,	4327,	4323,	4312,	4317,	4318,	91,	93,	4304,	4321,	4307,	4324,	4306,	4336,	4335,	4313,	4314,	59,	39,	4310,	4334,	4330,	4309,	4305,	4316,	4315,	44,	46,	47,	126,	33,	64,	35,	36,	37,	94,	38,	42,	40,	41,	95,	43,	124,	81,	4333,	69,	4326,	4311,	89,	85,	73,	79,	80,	123,	125,	65,	4328,	68,	70,	71,	72,	4319,	75,	76,	58,	34,	4331,	88,	4329,	86,	66,	78,	77,	60,	62,	63	);
  			var utf8_UpperCase=new Array(	96,	49,	50,	51,	52,	53,	54,	55,	56,	57,	48,	45,	61,	92,	4277,	4284,	4260,	4272,	4274,	4279,	4275,	4264,	4269,	4270,	91,	93,	4256,	4273,	4259,	4276,	4258,	4288,	4287,	4265,	4266,	59,	39,	4262,	4286,	4282,	4261,	4257,	4268,	4267,	44,	46,	47,	126,	33,	64,	35,	36,	37,	94,	38,	42,	40,	41,	95,	43,	124,	81,	4285,	69,	4278,	4263,	89,	85,	73,	79,	80,	123,	125,	65,	4280,	68,	70,	71,	72,	4271,	75,	76,	58,	34,	4283,	88,	4281,	86,	66,	78,	77,	60,	62,	63	);
  	

//------------------------------
   function aris(chcode,mas) {
      for (j=0; j<mas.length; j++) {if (mas[j]==chcode) {return (j);}}
      return (-1);
   }
//------------------------------
function che (st, from, to) {
	
  	saidan=eval(from);
  	sad=eval(to);		
  	st1='';
  	var extramas=new Array();
     for (i=0; i<st.length; i++) {
            ch=st.charAt(i);
            if (extramas[ch]) {st1+=extramas[ch];} else {
            	chc=ch.charCodeAt(0);
            	chi=aris(chc,saidan);
            	if (chi!=-1) {
                   newchar=String.fromCharCode(sad[chi]);;
                   st1+=newchar;
				extramas[ch]=newchar;
             	} else {st1+=ch;extramas[ch]=ch;}
          }
       }
 	return st1;
}
//------------------------------
function change_encoding (obj,from,to) {
  			html=obj.value;
  			textmas = new Array();
  			textmas=html.split("<");
  			out='';
  			out=che(textmas[0],from,to);
  			for (ii=1; ii<textmas.length; ii++) {
  				ps=textmas[ii].indexOf('>');
  				txt1=textmas[ii].substr(0,ps);
  				txt2=textmas[ii].substr(ps,textmas[ii].length-ps);
  				if (txt1.substr(0,6)!='script' || txt1.substr(0,5)!='style' ) { txt2=che(txt2,from,to);}
  				out+="<"+txt1+txt2;  			
  			}
  			obj.value=out;
}
//------------------------------
function utf2upper (obj,k) {
	if (k==0) {change_encoding(obj,"utf8","utf8_UpperCase");}
	else {change_encoding(obj,"utf8_UpperCase","utf8");}
}
//------------------------------
function doconvert (html, from, to) {
	var out='';
	if (html) {
		var textmas = [],
			textmas = html.split('<'),
			out     = che(textmas[0], from, to);
		for (ii = 1, ps = -1, txt1 = null, txt2 = null; ii < textmas.length; ii++) {
			ps   = textmas[ii].indexOf('>');
			txt1 = textmas[ii].substr(0, ps);
			txt2 = textmas[ii].substr(ps, textmas[ii].length - ps);
			if (!/^(script|style)/i.test(txt1)) { //-- tuki script an style tegebia,mashin am tegebs shoris razaa is ar gadaikvanos
				txt2 = che(txt2, from, to);
			}
			out += '<' + txt1 + txt2;
		}
	}
	return out;
}
//------------------------------
function convert(nnn,from, to) {
	  	var doc=document.getElementById("idContentoEdit_"+nnn).contentWindow;
    		//doc.document.execCommand("Superscript",false,'');
    		
    		doc.document.execCommand("Subscript",false,'');
		html=doc.document.body.innerHTML;
		html=htmlspecialchars_decode(html);
		//alert(html);
		/*
		html=html.replace("<SUP><SUB>","<sup><sub>");
		html=html.replace("</SUB></SUP>","</sub></sup>");
		
		html=html.replace("<SUB><SUP>","<sub><sup>");
		html=html.replace("</SUP></SUB>","</sup></sub>");
		alert(html);
				
		var mas=html.split("<sub><sup>");
		alert(mas.length);
		if (mas.length>1) {
			alert("a");
			var out=mas[0];
			for (var ii=1; ii<mas.length; ii++) {
				var mas2=mas[ii].split('</sup></sub>');
				if (mas2.length>1) {out+= doconvert(mas2[0],from,to)+mas2[1];} else {out+= doconvert(mas2[0],from,to);}
			}		
		} else {
			alert("b");
			var mas=html.split("<sup><sub>");
			var out=mas[0];
			for (var ii=1; ii<mas.length; ii++) {
				var mas2=mas[ii].split('</sub></sup>');
				if (mas2.length>1) {out+= doconvert(mas2[0],from,to)+mas2[1];} else {out+= doconvert(mas2[0],from,to);}
			}		
		}		
		*/
		
		html=html.replace("<SUB>","<sub>");
		html=html.replace("</SUB>","</sub>");
		var mas=html.split("<sub>");
			var out=mas[0];
			for (var ii=1; ii<mas.length; ii++) {
				var mas2=mas[ii].split('</sub>');
				if (mas2.length>1) {out+= doconvert(mas2[0],from,to)+mas2[1];} else {out+= doconvert(mas2[0],from,to);}
			}		
		
		
	doc.document.body.innerHTML=out;
}
//------------------------------
function htmlspecialchars_decode(html) {
	chars=new Array('"','&quot;','\'','&apos;','<','&lt;','>','&gt;','','&nbsp;','¡','&iexcl;','¢','&cent;','£','&pound;','¤','&curren;','¥','&yen;','¦','&brvbar;','§','&sect;','¨','&uml;','©','&copy;','ª','&ordf;','«','&laquo;','¬','&not;','­','&shy;','®','&reg;','¯','&macr;','°','&deg;','±','&plusmn;','²','&sup2;','³','&sup3;','´','&acute;','µ','&micro;','¶','&para;','·','&middot;','¸','&cedil;','¹','&sup1;','º','&ordm;','»','&raquo;','¼','&frac14;','½','&frac12;','¾','&frac34;','¿','&iquest;','×','&times;','÷','&divide;','À','&Agrave;','Á','&Aacute;','Â','&Acirc;','Ã','&Atilde;','Ä','&Auml;','Å','&Aring;','Æ','&AElig;','Ç','&Ccedil;','È','&Egrave;','É','&Eacute;','Ê','&Ecirc;','Ë','&Euml;','Ì','&Igrave;','Í','&Iacute;','Î','&Icirc;','Ï','&Iuml;','Ð','&ETH;','Ñ','&Ntilde;','Ò','&Ograve;','Ó','&Oacute;','Ô','&Ocirc;','Õ','&Otilde;','Ö','&Ouml;','Ø','&Oslash;','Ù','&Ugrave;','Ú','&Uacute;','Û','&Ucirc;','Ü','&Uuml;','Ý','&Yacute;','Þ','&THORN;','ß','&szlig;','`','&agrave;','á','&aacute;','â','&acirc;','ã','&atilde;','ä','&auml;','å','&aring;','æ','&aelig;','ç','&ccedil;','è','&egrave;','é','&eacute;','ê','&ecirc;','ë','&euml;','ì','&igrave;','í','&iacute;','î','&icirc;','ï','&iuml;','ð','&eth;','ñ','&ntilde;','ò','&ograve;','ó','&oacute;','ô','&ocirc;','õ','&otilde;','ö','&ouml;','ø','&oslash;','ù','&ugrave;','ú','&uacute;','û','&ucirc;','ü','&uuml;','ý','&yacute;','þ','&thorn;','ÿ','&yuml;','∀','&forall;','∂','&part;','∃','&exists;','∅','&empty;','∇','&nabla;','∈','&isin;','∉','&notin;','∋','&ni;','∏','&prod;','∑','&sum;','−','&minus;','∗','&lowast;','√','&radic;','∝','&prop;','∞','&infin;','↠','&ang;','∧','&and;','∨','&or;','∩','&cap;','∪','&cup;','∫','&int;','∴','&there4;','∼','&sim;','≅','&cong;','≈','&asymp;','⇠','&ne;','≡','&equiv;','≤','&le;','≥','&ge;','⊂','&sub;','⊃','&sup;','⊄','&nsub;','⊆','&sube;','⊇','&supe;','⊕','&oplus;','⊗','&otimes;','⊥','&perp;','⋅','&sdot;','Α','&Alpha;','Β','&Beta;','Γ','&Gamma;','Δ','&Delta;','Ε','&Epsilon;','Ζ','&Zeta;','Η','&Eta;','Θ','&Theta;','Ι','&Iota;','Κ','&Kappa;','Λ','&Lambda;','Μ','&Mu;','Ν','&Nu;','Ξ','&Xi;','Ο','&Omicron;','̠','&Pi;','Ρ','&Rho;','Σ','&Sigma;','Τ','&Tau;','Υ','&Upsilon;','Φ','&Phi;','Χ','&Chi;','Ψ','&Psi;','Ω','&Omega;','α','&alpha;','β','&beta;','γ','&gamma;','δ','&delta;','ε','&epsilon;','ζ','&zeta;','η','&eta;','θ','&theta;','ι','&iota;','κ','&kappa;','λ','&lambda;','μ','&mu;','ν','&nu;','ξ','&xi;','ο','&omicron;','π','&pi;','ρ','&rho;','ς','&sigmaf;','σ','&sigma;','τ','&tau;','υ','&upsilon;','φ','&phi;','χ','&chi;','ψ','&psi;','ω','&omega;','ϑ','&thetasym;','ϒ','&upsih;','ϖ','&piv;','Œ','&OElig;','œ','&oelig;','à','&Scaron;','š','&scaron;','Ÿ','&Yuml;','ƒ','&fnof;','ˆ','&circ;','˜','&tilde;',' ','&ensp;',' ','&emsp;',' ','&thinsp;','‌','&zwnj;','‍','&zwj;','‎','&lrm;','‏','&rlm;','–','&ndash;','—','&mdash;','‘','&lsquo;','’','&rsquo;','‚','&sbquo;','“','&ldquo;','”','&rdquo;','„','&bdquo;','ᾠ','&dagger;','‡','&Dagger;','•','&bull;','…','&hellip;','‰','&permil;','′','&prime;','″','&Prime;','‹','&lsaquo;','›','&rsaquo;','‾','&oline;','€','&euro;','™','&trade;','←','&larr;','↑','&uarr;','→','&rarr;','↓','&darr;','↔','&harr;','↵','&crarr;','⌈','&lceil;','⌉','&rceil;','⌊','&lfloor;','⌋','&rfloor;','◊','&loz;','◠','&spades;','♣','&clubs;','♥','&hearts;','♦','&diams;');
	for (var i=0; i<chars.length; i+=2) {
		html=html.replace(chars[i+1],chars[i]);
	}
	return html;
}



































function convert2(nnn,from, to) {
	
	function _convert(text) {
		return che(text, from, to);
	};
	
	function _replace(oldNode) {
		var newNode = oldNode.ownerDocument.createTextNode(_convert(oldNode.nodeValue));
		oldNode.parentNode.replaceChild(newNode, oldNode);
	};
	
	var html,
		text,
		doc = oUtil.oEditor;
	
	doc  = document.getElementById('idContentoEdit_'+nnn).contentWindow;
	html = doc.getSelection();
	
	if (html) {
		if (html.anchorNode == html.focusNode) {
			text = doc.document.getSelection();
			var node = html.anchorNode;
			text = doc.document.createTextNode(node.nodeValue.substring(0, html.focusOffset) + _convert(text) + node.nodeValue.substring(html.anchorOffset));
			html.anchorNode.parentNode.replaceChild(text, html.anchorNode);
			
		} else {
			
			var node; 
			
			for (var j = 0; j < html.focusNode.parentNode.childNodes.length; j++) {
				node = html.focusNode.parentNode.childNodes[j];
				if (node != html.focusNode && node != html.anchorNode) {
					if (node.nodeName != '#text') {
						(function(el) {
							for (var i = 0; i < el.childNodes.length; i++) {
								if (el.childNodes[i].nodeName != '#text') {
									arguments.callee(el.childNodes[i]);
								} else {
									_replace(el.childNodes[i]);
								}
							}
						})(node);
					} else {
						_replace(node);
					}
				}
			}
			
			text = html.focusNode.nodeValue;
			if (text) {
				node = doc.document.createTextNode(text.substring(0, html.focusOffset) + _convert(text.substring(html.focusOffset)));
				html.focusNode.parentNode.replaceChild(node, html.focusNode);
			}
			
			text = html.anchorNode.nodeValue;
			if (text) {
				node = doc.document.createTextNode(_convert(text.substring(0, html.anchorOffset)) + text.substring(html.anchorOffset));
				html.anchorNode.parentNode.replaceChild(node, html.anchorNode);
			}
			
			node = null;
			
		}
	}
	
	doc = html = null;
	
}
//--------------------------------
function convert1(from, to) {
	
	var html,
		range,
		doc = oUtil.oEditor;
	
	doc   = doc.contentWindow && doc.contentWindow.document ? doc.contentWindow.document : doc.document;
	range = doc.selection ? doc.selection.createRange() : null;
	html  = range ? range.text : doc.getSelection();
	
	if (html) {
		var textmas = [],
			textmas = html.split('<'),
			out     = che(textmas[0], from, to);
		for (ii = 1, ps = -1, txt1 = null, txt2 = null; ii < textmas.length; ii++) {
			ps   = textmas[ii].indexOf('>');
			txt1 = textmas[ii].substr(0, ps);
			txt2 = textmas[ii].substr(ps, textmas[ii].length - ps);
			if (!/^(script|style)/i.test(txt1)) { //-- tuki script an style tegebia,mashin am tegebs shoris razaa is ar gadaikvanos
				txt2 = che(txt2, from, to);
			}
			out += '<' + txt1 + txt2;
		}
		
		if (range) {
			range.pasteHTML(out);
			
		} else if (!range && doc.execCommand) {
			doc.execCommand('InsertHTML', false, out);
		}
	}
	
	doc = null;
	
}

