function encodeU1251(str){
	abc="0123456789ABCDEF";
	utfarr=[1000,1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1038,1039,1105,
	1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1118,1119,1168,1169,8211,8212,8216,8217,
	8218,8220,8221,8222,8224,8225,8226,8230,8240,8249,8250,8364,8470,8482,65533];

	utfarr2=[32,168,128,129,170,189,178,175,163,138,140,142,141,161,143,184,144,131,186,190,179,
	191,188,154,156,158,157,162,159,165,180,150,151,145,146,130,147,148,132,134,135,149,133,137,
	139,155,136,185,153,152];
	out='';
	for(x=0;x<str.length;x++){		symb=str.charCodeAt(x);
		if(symb>187){			if((symb>=1040)&&(symb<=1103)){				symb-=848;
			}else{				beg=0;
				end=49;
				while((end-beg)>1){					cur=((beg+end)>>1);
					if(utfarr[cur]>=symb)end=cur;
						else beg=cur;
				}
				if(symb==utfarr[end]){					symb=utfarr2[end];
				}
			}
		}
		out+=abc.charAt((symb&0xF0)>>4)+abc.charAt(symb&0xF);
	}
	return out;
}
