/* Перекодировка транслита */
sel=null;
function br_check()
{
if ((!(navigator.appVersion.indexOf ("MSIE")>0))||(navigator.userAgent.indexOf ("Opera")>0))
{return false}
return true;
}

function translit()
{
source="";

if (br_check())
  {
    if (sel!=null)
      source=sel.text;
  }
else
   {source=document.form.message.value;}

if (source.length>0)
{
dest='';
for(i=0; i<source.length; i++)
{
tmp=source.substring(i,i+2);
tmp=tmp.toLowerCase();
if ((tmp=="sh")||(tmp=="ch")||(tmp=="zh")||(tmp=="yu")||(tmp=="ju")||(tmp=="ya")||(tmp=="ja"))
{tmp=source.substring(i,i+2);i++;}
else 
{tmp=source.substring(i,i+1);}
dest=dest+encode(tmp);
}
if (br_check())
   {sel.text=dest;}
else
   {document.form.message.value=dest;}
}
}

function encode(str)
{
tmp=str.toLowerCase();
if (tmp=='a') tmp='а';
if (tmp=='b') tmp='б';
if (tmp=='v') tmp='в';
if (tmp=='w') tmp='в';
if (tmp=='g') tmp='г';
if (tmp=='d') tmp='д';
if (tmp=='e') tmp='е';
if (tmp=='z') tmp='з';
if (tmp=='i') tmp='и';
if (tmp=='k') tmp='к';
if (tmp=='l') tmp='л';
if (tmp=='m') tmp='м';
if (tmp=='n') tmp='н';
if (tmp=='o') tmp='о';
if (tmp=='p') tmp='п';
if (tmp=='r') tmp='р';
if (tmp=='s') tmp='с';
if (tmp=='t') tmp='т';
if (tmp=='u') tmp='у';
if (tmp=='f') tmp='ф';
if (tmp=='h') tmp='х';
if (tmp=='c') tmp='ц';
if (tmp=='y') tmp='ы';
if (tmp=="'") tmp='ь';
if (tmp=='sh') tmp='ш';
if (tmp=='zh') tmp='ж';
if (tmp=='ch') tmp='ч';
if (tmp=='yu') tmp='ю';
if (tmp=='ju') tmp='ю';
if (tmp=='ya') tmp='я';
if (tmp=='ja') tmp='я';
if (tmp=='q') tmp='ку';
if (tmp=='j') tmp='й';
if (tmp=='x') tmp='кс';

//Определяем регистр
if (str.substring(0,1)==str.substring(0,1).toLowerCase()) {tmp=tmp.toLowerCase()} else {tmp=tmp.toUpperCase();}
return tmp;
}

