﻿function ReplaceeLatinChar(ctrl,e)
{                                                    
    var strValue= ctrl.value;                                                 
    var tmp=/'/g;
    strValue=strValue.replace(tmp,"");     
    
     var tmp=/"/g;
    strValue=strValue.replace(tmp,"");  
                              
    if(!(e.keyCode == 37 || e.keyCode==38 || e.keyCode==13 || e.keyCode==39 || e.keyCode == 40))
    {                                                                                                                  
            var i=0,sChar,sTemp="";                                                                       
            for(i=0;i<strValue.length;i++)
            {
                sChar =strValue.substr(i,1);                                                                                                                                                                     
                if (sChar > "~" && sChar != 13){
                    switch(sChar){
                         case  "Ç" : sChar = "C";break; 
                         case  "ü" : sChar = "u";break;
                         case  "é" : sChar = "e";break;
                         case  "â" : sChar = "a";break;
                         case  "ä" : sChar = "a";break;
                         case  "à" : sChar = "a";break;
                         case  "å" : sChar = "a";break; 
                         case  "ç" : sChar = "c";break;
                         case  "ê" : sChar = "e";break;
                         case  "ë" : sChar = "e";break;
                         case  "è" : sChar = "e";break;
                         case  "ï" : sChar = "i";break;
                         case  "î" : sChar = "i";break;
                         case  "ì" : sChar = "i";break; 
                         case  "Ä" : sChar = "A";break;
                         case  "Å" : sChar = "A";break;
                         case  "É" : sChar = "E";break;
                         case  "æ" : sChar = "ae";break;
                         case  "Æ" : sChar = "AE";break;
                         case  "ô" : sChar = "o";break;
                         case  "ö" : sChar = "o";break;
                         case  "ò" : sChar = "o";break;
                         case  "û" : sChar = "u";break;
                         case  "ù" : sChar = "u";break;
                         case  "ÿ" : sChar = "y";break;
                         case  "Ö" : sChar = "O";break;
                         case  "Ü" : sChar = "U";break;
                         case  "¢" : sChar = "c";break;
                         case  "£" : sChar = "$";break;
                         case  "¥" : sChar = "N";break; 
                         case  "P" : sChar = "P";break; 
                         case  "ƒ" : sChar = "f";break;
                         case  "á" : sChar = "a";break;
                         case  "í" : sChar = "i";break;
                         case  "ó" : sChar = "o";break;
                         case  "ú" : sChar = "u";break;
                         case  "ñ" : sChar = "n";break;
                         case  "Ñ" : sChar = "N";break;
                         case  "¡" : sChar = "i";break;
                         case  "«" : sChar = "<";break;
                         case  "»" : sChar = ">";break;
                    }                      
                }                                        
                if (sChar == "&")
                {                        
                      if ((i + 5) <= strValue.length)
                      {
                        if (strValue.substr(i+1,1)=="#")
                        {
                            if(strValue.substr(i + 5,1) == ";")
                            {                                            
                                switch(strValue.substr(i + 2,3)){
                                      case   "256" : sChar = "A" ;break;
                                      case   "257" : sChar = "a" ;break;
                                      case   "258" : sChar = "A" ;break;
                                      case   "259" : sChar = "a" ;break;
                                      case   "260" : sChar = "A" ;break;
                                      case   "261" : sChar = "a" ;break;
                                      case   "262" : sChar = "C" ;break;
                                      case   "263" : sChar = "c" ;break;
                                      case   "264" : sChar = "C" ;break;
                                      case   "265" : sChar = "c" ;break;
                                      case   "266" : sChar = "C" ;break;
                                      case   "267" : sChar = "c" ;break;
                                      case   "268" : sChar = "C" ;break;
                                      case   "269" : sChar = "c" ;break;
                                      case   "270" : sChar = "D" ;break;
                                      case   "271" : sChar = "d" ;break;
                                      case   "272" : sChar = "D" ;break;
                                      case   "273" : sChar = "d" ;break;
                                      case   "274" : sChar = "E" ;break;
                                      case   "275" : sChar = "e" ;break;
                                      case   "276" : sChar = "E" ;break;
                                      case   "277" : sChar = "e" ;break;
                                      case   "278" : sChar = "E" ;break;
                                      case   "279" : sChar = "e" ;break;
                                      case   "280" : sChar = "E" ;break;
                                      case   "281" : sChar = "e" ;break;
                                      case   "282" : sChar = "E" ;break;
                                      case   "283" : sChar = "e" ;break;
                                      case   "284" : sChar = "G" ;break;
                                      case   "285" : sChar = "g" ;break;
                                      case   "286" : sChar = "G" ;break;
                                      case   "287" : sChar = "g" ;break;
                                      case   "288" : sChar = "G";break;
                                      case   "289" : sChar = "g" ;break;
                                      case   "290" : sChar = "G" ;break;
                                      case   "291" : sChar = "g" ;break;
                                      case   "292" : sChar = "H" ;break;
                                      case   "293" : sChar = "h" ;break;
                                      case   "294" : sChar = "H" ;break;
                                      case   "295" : sChar = "h" ;break;
                                      case   "296" : sChar = "I" ;break;
                                      case   "297" : sChar = "i" ;break;
                                      case   "298" : sChar = "I" ;break;
                                      case   "299" : sChar = "i" ;break;
                                      case   "300" : sChar = "I" ;break;
                                      case   "301" : sChar = "i" ;break;
                                      case   "302" : sChar = "I" ;break;
                                      case   "303" : sChar = "i" ;break;
                                      case   "304" : sChar = "I" ;break;
                                      case   "305" : sChar = "i";break;
                                      case   "306" : sChar = "?" ;break;
                                      case   "307" : sChar = "?" ;break;
                                      case   "308" : sChar = "J" ;break;
                                      case   "309" : sChar = "j" ;break;
                                      case   "310" : sChar = "K" ;break;
                                      case   "311" : sChar = "k" ;break;
                                      case   "312" : sChar = "?" ;break;
                                      case   "313" : sChar = "L" ;break;
                                      case   "314" : sChar = "l" ;break;
                                      case   "315" : sChar = "L" ;break;
                                      case   "316" : sChar = "l" ;break;
                                      case   "317" : sChar = "L" ;break;
                                      case   "318" : sChar = "l" ;break;
                                      case   "319" : sChar = "L" ;break;
                                      case   "320" : sChar = "l" ;break;
                                      case   "321" : sChar = "L" ;break;
                                      case   "322" : sChar = "l" ;break;
                                      case   "323" : sChar = "N" ;break;
                                      case   "324" : sChar = "n" ;break;
                                      case   "325" : sChar = "N" ;break;
                                      case   "326" : sChar = "n" ;break;
                                      case   "327" : sChar = "N" ;break;
                                      case   "328" : sChar = "n" ;break;
                                      case   "329" : sChar = "n" ;break;
                                      case   "332" : sChar = "O" ;break;
                                      case   "333" : sChar = "o" ;break;
                                      case   "334" : sChar = "O" ;break;
                                      case   "335" : sChar = "o" ;break;
                                      case   "336" : sChar = "O" ;break;
                                      case   "337" : sChar = "o" ;break;
                                      case   "340" : sChar = "R" ;break;
                                      case   "341" : sChar = "r" ;break;
                                      case   "342" : sChar = "R" ;break;
                                      case   "343" : sChar = "r";break;
                                      case   "344" : sChar = "R" ;break;
                                      case   "345" : sChar = "r" ;break;
                                      case   "346" : sChar = "S" ;break;
                                      case   "347" : sChar = "s" ;break;
                                      case   "348" : sChar = "S" ;break;
                                      case   "349" : sChar = "s" ;break;
                                      case   "350" : sChar = "S";break;
                                      case   "351" : sChar = "s" ;break;
                                      case   "352" : sChar = "S" ;break;
                                      case   "353" : sChar = "s" ;break;
                                      case   "354" : sChar = "T" ;break;
                                      case   "355" : sChar = "t" ;break;
                                      case   "356" : sChar = "T" ;break;
                                      case   "357" : sChar = "t" ;break;
                                      case   "358" : sChar = "T" ;break;
                                      case   "359" : sChar = "t" ;break;
                                      case   "360" : sChar = "U" ;break;
                                      case   "361" : sChar = "u" ;break;
                                      case   "362" : sChar = "U" ;break;
                                      case   "363" : sChar = "u" ;break;
                                      case   "364" : sChar = "U" ;break;
                                      case   "365" : sChar = "u" ;break;
                                      case   "366" : sChar = "U" ;break;
                                      case   "367" : sChar = "u" ;break;
                                      case   "368" : sChar = "U" ;break;
                                      case   "369" : sChar = "u" ;break;
                                      case   "370" : sChar = "U" ;break;
                                      case   "371" : sChar = "u" ;break;
                                      case   "372" : sChar = "W" ;break;
                                      case   "373" : sChar = "w" ;break;
                                      case   "374" : sChar = "Y" ;break;
                                      case   "375" : sChar = "y" ;break;
                                      case   "376" : sChar = "Y" ;break;
                                      case   "377" : sChar = "Z" ;break;
                                      case   "378" : sChar = "z" ;break;
                                      case   "379" : sChar = "Z" ;break;
                                      case   "380" : sChar = "z" ;break;
                                      case   "381" : sChar = "Z" ;break;
                                      case   "382" : sChar = "z" ;break;
                                      case   "383" : sChar = "s" ;break;
                                      case   "402" : sChar = "f" ;break;
                                      case   "478" : sChar = "A" ;break;
                                      case   "479" : sChar = "a" ;break;
                                      case   "484" : sChar = "G" ;break;
                                      case   "485" : sChar = "g" ;break;
                                      case   "486" : sChar = "G" ;break;
                                      case   "487" : sChar = "g" ;break;
                                      case   "488" : sChar = "K" ;break;
                                      case   "489" : sChar = "k" ;break;
                                      case   "500" : sChar = "G" ;break;
                                      case   "501" : sChar = "g" ;break;
                                      case   "506" : sChar = "A" ;break;
                                      case   "507" : sChar = "a";break;
                                      case   "510" : sChar = "O" ;break;
                                      case   "511" : sChar = "o" ;break;
                                      case   "636" : sChar = "r";break;
                                      default : sChar = strValue.substr(i + 2,3); break;
                                }
                                i=i+5;
                            }
                             else
                             {                                               
                                    if ((i + 6) <= strValue.length)
                                    {   
                                         if (strValue.substr(i + 6,1) == ";")
                                         {                                                                                                                                             
                                            sChar =  strValue.substr(i + 2,4) ;
                                            i = i + 6
                                         }
                                    }
                                    else
                                    {                                                      
                                          if ((i + 7) <= strValue.length)
                                          {                                                           
                                                 if (strValue.substr(i + 7,1) == ";")
                                                 {
                                                    sChar=  strValue.substr(i + 2,5) ;
                                                    i = i + 7;
                                                 }
                                          }                                                                                                     
                                    }
                            }
                        }
                      } 
                }  
                
                if (sChar > "~")                            
                   sChar = "#";                                                           
                if (sChar < " ")                                             
                   sChar = " ";
                
               
                                                      
                sTemp=sTemp + sChar;
            }
            ctrl.value=sTemp;
    }
}
