/***********************************************************************************************************
 * com.tapogen.javascript.TypoGenerator
 * Location: http://www.tapogen.com/library/com/tapogen/javascript/typogenerator/2010042500/TypoGenerator.js
 * Created 2009040200
 * Version 2010042500
 * © tapogen.com (http://www.tapogen.com/)
***********************************************************************************************************/

if (typeof com == "undefined") {net = {};};
if (typeof com.tapogen == "undefined") {com.tapogen = {};};
if (typeof com.tapogen.javascript == "undefined") {com.tapogen.javascript = {};};

if (typeof com.tapogen.javascript.TypoGenerator == "undefined") {
 com.tapogen.javascript.TypoGenerator = function() {};
 com.tapogen.javascript.TypoGenerator.prototype = new com.oclib.javascript.lang.Root();  

 com.tapogen.javascript.TypoGenerator.prototype.classCreated = "2009040200"; 
 com.tapogen.javascript.TypoGenerator.prototype.classCreator = "http://www.tapogen.com/"; 
 com.tapogen.javascript.TypoGenerator.prototype.classIndexLocation = "http://www.tapogen.com/library/com/tapogen/"; 
 com.tapogen.javascript.TypoGenerator.prototype.classLocation = "http://www.tapogen.com/library/com/tapogen/javascript/TypoGenerator.js"; 
 com.tapogen.javascript.TypoGenerator.prototype.className = "TypoGenerator"; 
 com.tapogen.javascript.TypoGenerator.prototype.classNamespace = "com.tapogen.javascript.TypoGenerator"; 
 com.tapogen.javascript.TypoGenerator.prototype.classVersion = "2010042500"; 
 com.tapogen.javascript.TypoGenerator.prototype.classVersionIndexLocation = "http://www.tapogen.com/library/com/tapogen/javascript/typogenerator/2010042500/";
 com.tapogen.javascript.TypoGenerator.prototype.classVersionLocation = "http://www.tapogen.com/library/com/tapogen/javascript/typogenerator/2010042500/TypoGenerator.js";  

 com.tapogen.javascript.TypoGenerator.prototype.dom = null;  
  com.tapogen.javascript.TypoGenerator.prototype.getDom = function () {return this.dom;};
  com.tapogen.javascript.TypoGenerator.prototype.setDom = function (dom) {this.dom = dom;};
 com.tapogen.javascript.TypoGenerator.prototype.events = null;   
  com.tapogen.javascript.TypoGenerator.prototype.getEvents = function () {return this.events;};
  com.tapogen.javascript.TypoGenerator.prototype.setEvents = function (events) {this.events = events;};

 com.tapogen.javascript.TypoGenerator.prototype.ido = "";
  com.tapogen.javascript.TypoGenerator.prototype.whatDo = function () {return this.ido;}; 
 com.tapogen.javascript.TypoGenerator.prototype.doprogress = 0;
  com.tapogen.javascript.TypoGenerator.prototype.whatProgress = function () {return this.doprogress;};
 com.tapogen.javascript.TypoGenerator.prototype.lastGenerateTimeout = 0; 
 com.tapogen.javascript.TypoGenerator.prototype.ready = 1; 
  com.tapogen.javascript.TypoGenerator.prototype.getReady = function () {return this.ready;};
  com.tapogen.javascript.TypoGenerator.prototype.setReady = function (ready) {this.ready = ready;};
 com.tapogen.javascript.TypoGenerator.prototype.validDomainSymbols = "1234567890-qwertyuiopasdfghjklzxcvbnm."; 

 com.tapogen.javascript.TypoGenerator.prototype.resultArray = new Array();  
 com.tapogen.javascript.TypoGenerator.prototype.indexResultArray = new Array();
  com.tapogen.javascript.TypoGenerator.prototype.getResultArray = function () {return this.resultArray;};  
 com.tapogen.javascript.TypoGenerator.prototype.sourceArray = new Array();  
 com.tapogen.javascript.TypoGenerator.prototype.indexSourceArray = new Array();
  com.tapogen.javascript.TypoGenerator.prototype.addPhrase = function (p) {this.sourceArray[this.sourceArray.length] = p;this.indexSourceArray[p]=1;};
  com.tapogen.javascript.TypoGenerator.prototype.clearSource = function () {this.sourceArray = new Array();};
  com.tapogen.javascript.TypoGenerator.prototype.setSourceFromString = function (s) {this.sourceArray = s.split("\n");for(var i=0; i<this.sourceArray.length; i++) {this.indexSourceArray[this.sourceArray[i]]=1;};};

 com.tapogen.javascript.TypoGenerator.prototype.doubleLetters = 0;  
 com.tapogen.javascript.TypoGenerator.prototype.doubleLettersReady = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setDoubleLetters = function () {this.doubleLetters = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.insertedKey = 0;  
 com.tapogen.javascript.TypoGenerator.prototype.insertedKeyReady = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setInsertedKey = function () {this.insertedKey = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.lookAlikes = 0;  
 com.tapogen.javascript.TypoGenerator.prototype.lookAlikesReady = 0;   
  com.tapogen.javascript.TypoGenerator.prototype.setLookAlikes = function () {this.lookAlikes = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.missedKey = 0;  
 com.tapogen.javascript.TypoGenerator.prototype.missedKeyReady = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setMissedKey = function () {this.missedKey = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.phoneticKey = 0;  
 com.tapogen.javascript.TypoGenerator.prototype.phoneticKeyReady = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setPhoneticKey = function () {this.phoneticKey = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.reverseLetters = 0;  
 com.tapogen.javascript.TypoGenerator.prototype.reverseLettersReady = 0; 
  com.tapogen.javascript.TypoGenerator.prototype.setReverseLetters = function () {this.reverseLetters = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.skipLetter = 0;  
 com.tapogen.javascript.TypoGenerator.prototype.skipLetterReady = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setSkipLetter = function () {this.skipLetter = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.skipSpaces = 0;  
 com.tapogen.javascript.TypoGenerator.prototype.skipSpacesReady = 0; 
  com.tapogen.javascript.TypoGenerator.prototype.setSkipSpaces = function () {this.skipSpaces = 1;};
  
 com.tapogen.javascript.TypoGenerator.prototype.removeMethods = function () {this.skipLetter = 0;this.doubleLetters = 0;this.insertedKey = 0;this.lookAlikes = 0;this.missedKey = 0;this.phoneticKey = 0;this.reverseLetters = 0;this.skipSpaces = 0;};

 com.tapogen.javascript.TypoGenerator.prototype.groupIdentical = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setGroupIdentical = function () {this.groupIdentical = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.removeSource = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setRemoveSource = function () {this.removeSource = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.sortPopulary = 0;  
 com.tapogen.javascript.TypoGenerator.prototype.sortPopularyReady = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setSortPopulary = function () {this.sortPopulary = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.skipTLD = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setSkipTLD = function () {this.skipTLD = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.skipWWW = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setSkipWWW = function () {this.skipWWW = 1;};
 com.tapogen.javascript.TypoGenerator.prototype.validDomain = 0;  
  com.tapogen.javascript.TypoGenerator.prototype.setValidDomain = function () {this.validDomain = 1;};
  
 com.tapogen.javascript.TypoGenerator.prototype.removeOptions = function () {this.groupIdentical = 0;this.removeSource = 0;this.sortPopulary = 0;this.skipTLD = 0;this.skipWWW = 0;this.validDomain = 0;};
 
 com.tapogen.javascript.TypoGenerator.prototype.lookAlikesArray = new Array(); 
 com.tapogen.javascript.TypoGenerator.prototype.nearCharArray = new Array(); 
 com.tapogen.javascript.TypoGenerator.prototype.phoneticArray = new Array(); 
 
 com.tapogen.javascript.TypoGenerator.prototype.init = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.generate is init...");};
  this.ido="idoInit"; this.doprogress=0;
  
  var layouts = new Array(3);
  layouts[0] = "`1234567890-=qwertyuiop[]asdfghjkl;'\\|zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:\"|ZXCVBNM<>?"; // english
  layouts[1] = "ё1234567890-=йцукенгшщзхъфывапролджэ\\\\ячсмитьбю.Ё!\"№;%:?*()_+ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭ//ЯЧСМИТЬБЮ,"; // russian
  layouts[2] = "'1234567890-=йцукенгшщзхїфівапролджє\\ґячсмитьбю.₴!\"№;%:?*()_+ЙЦУКЕНГШЩЗХЇФІВАПРОЛДЖЄ/ҐЯЧСМИТЬБЮ,"; // ukrainian
  
  var symbols = "`1234567890-=[];'\\|,./~!@#$%^&*()_+{}:\"|<>?№₴";
  
  // create near chars array for little english
  this.nearCharArray["q"]=new Array("1","2","w","s","a");this.nearCharArray["w"]=new Array("2","3","e","s","a","q");this.nearCharArray["e"]=new Array("3","4","r","d","s","w");this.nearCharArray["r"]=new Array("4","5","t","f","d","e");this.nearCharArray["t"]=new Array("5","6","y","g","f","r");this.nearCharArray["y"]=new Array("6","7","u","h","g","t");this.nearCharArray["u"]=new Array("7","8","i","j","h","y");this.nearCharArray["i"]=new Array("8","9","o","k","j","u");this.nearCharArray["o"]=new Array("9","0","p","l","k","i");this.nearCharArray["p"]=new Array("0","-","[",";","l","o");
  this.nearCharArray["a"]=new Array("q","w","s","x","z","\\");this.nearCharArray["s"]=new Array("w","e","d","x","z","a");this.nearCharArray["d"]=new Array("e","r","f","c","x","s");this.nearCharArray["f"]=new Array("r","t","g","v","c","d");this.nearCharArray["g"]=new Array("t","y","h","b","v","f");this.nearCharArray["h"]=new Array("y","u","j","n","b","g");this.nearCharArray["j"]=new Array("u","i","k","m","n","h");this.nearCharArray["k"]=new Array("i","o","l",",","m","j");this.nearCharArray["l"]=new Array("o","p",";",".",",","k");
  this.nearCharArray["z"]=new Array("a","s","x","\\");this.nearCharArray["x"]=new Array("s","d","c","z");this.nearCharArray["c"]=new Array("d","f","v","x");this.nearCharArray["v"]=new Array("f","g","b","c");this.nearCharArray["b"]=new Array("g","h","n","v");this.nearCharArray["n"]=new Array("h","j","m","b");this.nearCharArray["m"]=new Array("j","k",",","n");
  // create near chars array for capital english  
  this.nearCharArray["Q"]=new Array("!","@","W","S","A");this.nearCharArray["W"]=new Array("@","#","E","S","A","Q");this.nearCharArray["E"]=new Array("#","$","R","D","S","W");this.nearCharArray["R"]=new Array("$","%","T","F","D","E");this.nearCharArray["T"]=new Array("%","^","Y","G","F","R");this.nearCharArray["Y"]=new Array("^","&","U","H","G","T");this.nearCharArray["U"]=new Array("&","*","I","J","H","Y");this.nearCharArray["I"]=new Array("*","(","O","K","J","U");this.nearCharArray["O"]=new Array("(",")","P","L","K","I");this.nearCharArray["P"]=new Array(")","_","{",":","L","O");
  this.nearCharArray["A"]=new Array("Q","W","S","X","Z","|");this.nearCharArray["S"]=new Array("W","E","D","X","Z","A");this.nearCharArray["D"]=new Array("E","R","F","C","X","S");this.nearCharArray["F"]=new Array("R","T","G","V","C","D");this.nearCharArray["G"]=new Array("T","Y","H","B","V","F");this.nearCharArray["H"]=new Array("Y","U","J","N","B","G");this.nearCharArray["J"]=new Array("U","I","K","M","N","H");this.nearCharArray["K"]=new Array("I","O","L","<","M","J");this.nearCharArray["L"]=new Array("O","P",":",">","<","K");this.nearCharArray[":"]=new Array("P","{","\"","?",">","L");
  this.nearCharArray["Z"]=new Array("A","S","X","|");this.nearCharArray["X"]=new Array("S","D","C","Z");this.nearCharArray["C"]=new Array("D","F","V","X");this.nearCharArray["V"]=new Array("F","G","B","C");this.nearCharArray["B"]=new Array("G","H","N","V");this.nearCharArray["N"]=new Array("H","J","M","B");this.nearCharArray["M"]=new Array("J","K","<","N");
  // create near chars array for space
                    //this.nearCharArray[" "]=new Array(" ");
  // create near chars array for nubmer and symbols
  this.nearCharArray["`"]=new Array("1");this.nearCharArray["1"]=new Array("`","2","q");this.nearCharArray["2"]=new Array("1","3","w","q");this.nearCharArray["3"]=new Array("2","4","e","w");this.nearCharArray["4"]=new Array("3","5","r","e");this.nearCharArray["5"]=new Array("4","6","t","r");this.nearCharArray["6"]=new Array("5","7","y","t");this.nearCharArray["7"]=new Array("6","8","u","y");this.nearCharArray["8"]=new Array("7","9","i","u");this.nearCharArray["9"]=new Array("8","0","o","i");this.nearCharArray["0"]=new Array("9","-","p","o");this.nearCharArray["-"]=new Array("0","=","[","p");this.nearCharArray["="]=new Array("-","]","[");
  this.nearCharArray["["]=new Array("-","=","]","'",";","p");this.nearCharArray["]"]=new Array("=","\\","'","[");
  this.nearCharArray[";"]=new Array("p","[","'","/",".","l");this.nearCharArray["'"]=new Array("[","]","\\","/",";");this.nearCharArray["\\"]=new Array("]","'","a","z");
  this.nearCharArray[","]=new Array("k","l",".","m");this.nearCharArray["."]=new Array("l",";","/",",");this.nearCharArray["/"]=new Array(";","'",".");
  this.nearCharArray["~"]=new Array("!");this.nearCharArray["!"]=new Array("~","@","Q");this.nearCharArray["@"]=new Array("!","#","W","Q");this.nearCharArray["#"]=new Array("@","$","E","W");this.nearCharArray["$"]=new Array("#","%","R","E");this.nearCharArray["%"]=new Array("$","^","T","R");this.nearCharArray["^"]=new Array("%","&","Y","T");this.nearCharArray["&"]=new Array("^","*","U","Y");this.nearCharArray["*"]=new Array("&","(","U","I");this.nearCharArray["("]=new Array("&","(","I","U");this.nearCharArray["("]=new Array("*",")","O","I");this.nearCharArray[")"]=new Array("(","_","P","O");this.nearCharArray["_"]=new Array(")","+","{","P");this.nearCharArray["+"]=new Array("_","}","{");
  this.nearCharArray["{"]=new Array("_","+","}","\"",":","P");this.nearCharArray["}"]=new Array("+","|","\"","{");
  this.nearCharArray["\""]=new Array("{","}","|","?",":");this.nearCharArray["|"]=new Array("}","\"","A","Z");
  this.nearCharArray["<"]=new Array("K","L",">","M");this.nearCharArray[">"]=new Array("L",":","?","<");this.nearCharArray["?"]=new Array(":","\"",">");
  
  // create near chars arrays for others layouts
  for(var l=1; l<layouts.length; l++) { // number of layout
   //if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.init l:"+l);};
   for(var forCharPos=0; forCharPos<layouts[l].length; forCharPos++) { 
    var forChar = layouts[l].charAt(forCharPos);
    if(this.nearCharArray[forChar]) {
     var beforeLength=this.nearCharArray[forChar].length;              
     for(var i=0; i<beforeLength; i++) {                              
      var existEnglishChar = this.nearCharArray[forChar][i];           
      var posExistEnglishChar = layouts[0].indexOf(existEnglishChar);  
      if(posExistEnglishChar>=0) {
       var newLayoutChar = layouts[l].charAt(posExistEnglishChar);
       var exist=false;
       for(var j=0; j<this.nearCharArray[forChar].length && !exist; j++) {if(this.nearCharArray[forChar][j]==newLayoutChar) {exist=true;};};
       if(!exist) {this.nearCharArray[forChar][this.nearCharArray[forChar].length]=newLayoutChar;};
      };
     };
    } else { // there no char from current layout in the nearCharArray
     var englishChar = layouts[0].charAt(forCharPos);
     var newArray = new Array();
     for(var i=0; i<this.nearCharArray[englishChar].length; i++) {
      var newEnglishChar = this.nearCharArray[englishChar][i];
      var newEnglishCharPos = layouts[0].indexOf(newEnglishChar);
      if(newEnglishCharPos>=0) {newArray[newArray.length]=layouts[l].charAt(newEnglishCharPos);};
     };
     this.nearCharArray[forChar]=newArray;
    };
   };
  }; 
  
  // create look alikes array
  this.lookAlikesArray[" "]=new Array(".", "-", "_");
  this.lookAlikesArray["_"]=new Array("-", " ");
  this.lookAlikesArray["."]=new Array(" ");
  this.lookAlikesArray["-"]=new Array(" ", "_");
  this.lookAlikesArray["$"]=new Array("S","s","₴");
  this.lookAlikesArray["₴"]=new Array("S","s","$");
  this.lookAlikesArray["0"]=new Array("o","O","о","О");//lat,lat,cyr,cyr
  this.lookAlikesArray["1"]=new Array("i","l","I","і", "І");//lat,lat,lat,cyr,cyr
  this.lookAlikesArray["3"]=new Array("з","З");
  this.lookAlikesArray["4"]=new Array("ч","Ч");
  this.lookAlikesArray["6"]=new Array("б","Б");
  this.lookAlikesArray["a"]=new Array("а");//cyr
  this.lookAlikesArray["A"]=new Array("А");//cyr
  this.lookAlikesArray["b"]=new Array("h");
  this.lookAlikesArray["c"]=new Array("с");//cyr
  this.lookAlikesArray["C"]=new Array("С");//cyr
  this.lookAlikesArray["e"]=new Array("е","ё");//cyr,cyr,
  this.lookAlikesArray["E"]=new Array("Е","Ё");//cyr,cyr,
  this.lookAlikesArray["g"]=new Array("q");
  this.lookAlikesArray["h"]=new Array("b");
  this.lookAlikesArray["i"]=new Array("1","l","і");//lat,lat,cyr,
  this.lookAlikesArray["I"]=new Array("1","l","І");//lat,lat,cyr,
  this.lookAlikesArray["l"]=new Array("1","i","і","І");//lat,lat,lat,cyr,cyr
  this.lookAlikesArray["o"]=new Array("0","о");//lat,cyr,
  this.lookAlikesArray["O"]=new Array("0","Q","О");//lat,lat,cyr
  this.lookAlikesArray["q"]=new Array("g");
  this.lookAlikesArray["Q"]=new Array("0","O","О");//lat,lat,cyr
  this.lookAlikesArray["s"]=new Array("$","₴");
  this.lookAlikesArray["S"]=new Array("$","₴");
  this.lookAlikesArray["u"]=new Array("v");
  this.lookAlikesArray["U"]=new Array("V");
  this.lookAlikesArray["v"]=new Array("u");
  this.lookAlikesArray["V"]=new Array("U");
  this.lookAlikesArray["а"]=new Array("a");//lat
  this.lookAlikesArray["А"]=new Array("A");//lat
  this.lookAlikesArray["б"]=new Array("6");
  this.lookAlikesArray["Б"]=new Array("6");
  this.lookAlikesArray["е"]=new Array("e","ё");//lat,cyr,
  this.lookAlikesArray["Е"]=new Array("E","Ё");//lat,cyr,
  this.lookAlikesArray["ё"]=new Array("е","йо");
  this.lookAlikesArray["Ё"]=new Array("Е","ЙО");
  this.lookAlikesArray["з"]=new Array("3");
  this.lookAlikesArray["З"]=new Array("3");
  this.lookAlikesArray["и"]=new Array("й","н");
  this.lookAlikesArray["И"]=new Array("Й","Н");
  this.lookAlikesArray["й"]=new Array("и");
  this.lookAlikesArray["Й"]=new Array("И");
  this.lookAlikesArray["л"]=new Array("п");
  this.lookAlikesArray["Л"]=new Array("П");
  this.lookAlikesArray["о"]=new Array("0","о");//lat,cyr,
  this.lookAlikesArray["О"]=new Array("0","О");//lat,cyr,
  this.lookAlikesArray["п"]=new Array("л");
  this.lookAlikesArray["П"]=new Array("Л");
  this.lookAlikesArray["с"]=new Array("c");
  this.lookAlikesArray["С"]=new Array("C");
  this.lookAlikesArray["ч"]=new Array("4");
  this.lookAlikesArray["Ч"]=new Array("4");
  this.lookAlikesArray["ш"]=new Array("щ");
  this.lookAlikesArray["Ш"]=new Array("Щ");
  this.lookAlikesArray["щ"]=new Array("ш");
  this.lookAlikesArray["Щ"]=new Array("Ш");
  this.lookAlikesArray["э"]=new Array("є","е");
  this.lookAlikesArray["Э"]=new Array("Є","Е");
  this.lookAlikesArray["ь"]=new Array("ъ");
  this.lookAlikesArray["ъ"]=new Array("ь");
  this.lookAlikesArray["Ь"]=new Array("Ъ");
  this.lookAlikesArray["Ъ"]=new Array("Ь");
  this.lookAlikesArray["і"]=new Array("1","ї","i");//cyr,cyr,lat
  this.lookAlikesArray["І"]=new Array("1","Ї","I");//cyr,cyr,lat
  this.lookAlikesArray["ї"]=new Array("1","і");
  this.lookAlikesArray["Ї"]=new Array("1","І");
  this.lookAlikesArray["г"]=new Array("ґ");
  this.lookAlikesArray["Г"]=new Array("Ґ");
  this.lookAlikesArray["ґ"]=new Array("г");
  this.lookAlikesArray["Ґ"]=new Array("Г");
  this.lookAlikesArray["є"]=new Array("э","е");
  this.lookAlikesArray["Є"]=new Array("Э","Е"); 
  
  // create phonetic array english
  this.phoneticArray["a"]=new Array("e","o","u");
  this.phoneticArray["A"]=new Array("E","O","U");
  this.phoneticArray["c"]=new Array("s","k");
  this.phoneticArray["C"]=new Array("S","K");
  this.phoneticArray["e"]=new Array("a", "i");
  this.phoneticArray["E"]=new Array("A", "I");
  this.phoneticArray["i"]=new Array("y","e");
  this.phoneticArray["I"]=new Array("Y","E");
  this.phoneticArray["k"]=new Array("c","ck");
  this.phoneticArray["K"]=new Array("C","CK");
  this.phoneticArray["o"]=new Array("u","a");
  this.phoneticArray["O"]=new Array("U","A");
  this.phoneticArray["s"]=new Array("c","th","z");
  this.phoneticArray["S"]=new Array("C","TH","Z");
  this.phoneticArray["u"]=new Array("a","o","w","oo");
  this.phoneticArray["U"]=new Array("A","O","W","OO");
  this.phoneticArray["v"]=new Array("w");
  this.phoneticArray["V"]=new Array("W");
  this.phoneticArray["w"]=new Array("u","v");
  this.phoneticArray["W"]=new Array("U", "V");
  this.phoneticArray["x"]=new Array("ks");
  this.phoneticArray["X"]=new Array("KS");
  this.phoneticArray["y"]=new Array("i","j");
  this.phoneticArray["Y"]=new Array("I","J");
  this.phoneticArray["z"]=new Array("th","s");
  this.phoneticArray["Z"]=new Array("TH","S");
   
  // create phonetic array russian
  this.phoneticArray["г"]=new Array("х");
  this.phoneticArray["Г"]=new Array("Х");
  this.phoneticArray["е"]=new Array("йэ","э");
  this.phoneticArray["Е"]=new Array("ЙЭ","Э");
  this.phoneticArray["з"]=new Array("с");
  this.phoneticArray["З"]=new Array("С");
  this.phoneticArray["и"]=new Array("ы");
  this.phoneticArray["И"]=new Array("Ы");
  this.phoneticArray["с"]=new Array("ц","з");
  this.phoneticArray["С"]=new Array("Ц","З");
  this.phoneticArray["х"]=new Array("г");
  this.phoneticArray["Х"]=new Array("Г");
  this.phoneticArray["ц"]=new Array("с");
  this.phoneticArray["Ц"]=new Array("С");
  this.phoneticArray["щ"]=new Array("шч","сч");
  this.phoneticArray["Щ"]=new Array("ШЧ","СЧ");
  this.phoneticArray["ы"]=new Array("и");
  this.phoneticArray["Ы"]=new Array("И");
  this.phoneticArray["ъ"]=new Array("","ь");
  this.phoneticArray["Ъ"]=new Array("","Ь");
  this.phoneticArray["ь"]=new Array("","ъ");
  this.phoneticArray["Ь"]=new Array("","Ъ");
  this.phoneticArray["э"]=new Array("е");
  this.phoneticArray["Э"]=new Array("Е");
  this.phoneticArray["ю"]=new Array("йу");
  this.phoneticArray["Ю"]=new Array("ЙУ");
  this.phoneticArray["я"]=new Array("йа");
  this.phoneticArray["Я"]=new Array("ЙА");  
  
  // create phonetic array  ukrainian
  this.phoneticArray["ї"]=new Array("йі");  
  this.phoneticArray["Ї"]=new Array("ЙІ");  
  this.phoneticArray["є"]=new Array("йе");  
  this.phoneticArray["Є"]=new Array("ЙЕ"); 
  
  this.ido="idoNothing"; this.doprogress=100;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.addResult = function(rm) {
  // if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.addResult is runing...");};
  // if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.addResult rm:"+rm);};
  if(this.removeSource==1 && this.indexSourceArray[rm]==1) {return;};
  if(this.validDomain) {
   for(var i=0; i<rm.length; i++) {
    if(this.validDomainSymbols.indexOf(rm.charAt(i))<0) {return;};
   };
  };
  if(this.groupIdentical==1) {
   if(this.indexResultArray[rm] && this.indexResultArray[rm]>0) {
    this.indexResultArray[rm]++;
   } else {
    this.indexResultArray[rm]=1;
    this.resultArray[this.resultArray.length]=rm;
   };
  } else {
   this.indexResultArray[rm]=1;
   this.resultArray[this.resultArray.length]=rm;
  };
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.getSkipTLD = function(s,f) {
  // if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.getSkipTLDis runing...");};
  var p;
  if(this.skipTLD) {
   for(p=f; p<s.length && s.charAt(p)!="."; p++) {}; 
  } else {
   p=s.length;
  };
  return p;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.getSkipWWW = function(s) {
  // if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.getSkipTLDis runing...");};
  return (this.skipWWW && s.charAt(0)=="w" && s.charAt(1)=="w" && s.charAt(2)=="w" && s.charAt(3)==".") ? 4 : 0;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.doDoubleLetters = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doDoubleLetters is runing...");};
  this.ido="idoDoubleLetters"; this.doprogress=0;
  for(var i=0; i<this.sourceArray.length; i++) {
   var s = this.sourceArray[i];
   var fp = this.getSkipWWW(s); var ep = this.getSkipTLD(s,fp);
   for(var j=fp; j<ep; j++) {
    var r = "";
    for(var k=0; k<s.length; k++) {
     if(k==j) {
      r+=s.charAt(k);
     };
     r+=s.charAt(k);
    };
    this.addResult(r);
   };
  };
  this.ido="idoNothing"; this.doprogress=100;
  this.doubleLettersReady=1;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.doInsertedKey = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doInsertedKey is runing...");};
  this.ido="idoInsertedKey"; this.doprogress=0;
  for(var i=0; i<this.sourceArray.length; i++) {
   var s = this.sourceArray[i];
   var fp = this.getSkipWWW(s); var ep = this.getSkipTLD(s,fp);
   for(var j=fp; j<ep; j++) {
    if(this.nearCharArray[s.charAt(j)] && this.nearCharArray[s.charAt(j)].length>0) {
     var mc = this.nearCharArray[s.charAt(j)].length;
     // if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doLookAlikes i:"+i+"; j:"+j+"; s.charAt(j):"+s.charAt(j)+"; mc:"+mc);};
     for(var k=0; k<mc; k++) {
      for(var f=0; f<2; f++) {
       var r = "";
       for(var l=0; l<s.length; l++) {
        if(l==j) {
         if(f==0) {
          r+=s.charAt(l)+this.nearCharArray[s.charAt(j)][k];
         } else {
          r+=this.nearCharArray[s.charAt(j)][k]+s.charAt(l);
         };
        } else {
         r+=s.charAt(l);
        };
       };
       this.addResult(r);
      };
     };
    };
   };
  };
  this.ido="idoNothing"; this.doprogress=100;
  this.insertedKeyReady=1;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.doLookAlikes = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doLookAlikes is runing...");};
  this.ido="idoLookAlikes"; this.doprogress=0;
  for(var i=0; i<this.sourceArray.length; i++) {
   var s = this.sourceArray[i];
   var fp = this.getSkipWWW(s); var ep = this.getSkipTLD(s,fp);
   for(var j=fp; j<ep; j++) {
    if(this.lookAlikesArray[s.charAt(j)] && this.lookAlikesArray[s.charAt(j)].length>0) {
     var mc = this.lookAlikesArray[s.charAt(j)].length;
     // if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doLookAlikes i:"+i+"; j:"+j+"; s.charAt(j):"+s.charAt(j)+"; mc:"+mc);};
     for(var k=0; k<mc; k++) {
      var r = "";
      for(var l=0; l<s.length; l++) {
       if(l==j) {
        r+=this.lookAlikesArray[s.charAt(j)][k];
       } else {
        r+=s.charAt(l);
       };
      };
      this.addResult(r);
     };
    };
   };
  };
  this.ido="idoNothing"; this.doprogress=100;
  this.lookAlikesReady=1;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.doMissedKey = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doMissedKey is runing...");};
  this.ido="idoMissedKey"; this.doprogress=0;
  for(var i=0; i<this.sourceArray.length; i++) {
   var s = this.sourceArray[i];
   var fp = this.getSkipWWW(s); var ep = this.getSkipTLD(s,fp);
   for(var j=fp; j<ep; j++) {
    if(this.nearCharArray[s.charAt(j)] && this.nearCharArray[s.charAt(j)].length>0) {
     var mc = this.nearCharArray[s.charAt(j)].length;
     // if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doMissedKey i:"+i+"; j:"+j+"; s.charAt(j):"+s.charAt(j)+"; mc:"+mc);};
     for(var k=0; k<mc; k++) {
      var r = "";
      for(var l=0; l<s.length; l++) {
       if(l==j) {
        r+=this.nearCharArray[s.charAt(j)][k];
       } else {
        r+=s.charAt(l);
       };
      };
      this.addResult(r);
     };
    };
   };
  };
  this.ido="idoNothing"; this.doprogress=100;
  this.missedKeyReady=1;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.doPhoneticKey = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doPhoneticKey is runing...");};
  this.ido="idoPhoneticKey"; this.doprogress=0;
  for(var i=0; i<this.sourceArray.length; i++) {
   var s = this.sourceArray[i];
   var fp = this.getSkipWWW(s); var ep = this.getSkipTLD(s,fp);
   for(var j=fp; j<ep; j++) {
    if(this.phoneticArray[s.charAt(j)] && this.phoneticArray[s.charAt(j)].length>0) {
     var mc = this.phoneticArray[s.charAt(j)].length;
     // if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doPhoneticKey i:"+i+"; j:"+j+"; s.charAt(j):"+s.charAt(j)+"; mc:"+mc);};
     for(var k=0; k<mc; k++) {
      var r = "";
      for(var l=0; l<s.length; l++) {
       if(l==j) {
        r+=this.phoneticArray[s.charAt(j)][k];
       } else {
        r+=s.charAt(l);
       };
      };
      this.addResult(r);
     };
    };
   };
  };
  this.ido="idoNothing"; this.doprogress=100;
  this.phoneticKeyReady=1;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.doReverseLetters = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doReverseLetters is runing...");};
  this.ido="idoReverseLetters"; this.doprogress=0;
  for(var i=0; i<this.sourceArray.length; i++) {
   var s = this.sourceArray[i];
   var fp = this.getSkipWWW(s); var ep = this.getSkipTLD(s,fp);
   for(var j=fp; j<ep-1; j++) {
    var r = "";
    for(var k=0; k<s.length; k++) {
     if(k==j && (k+1)<ep) {
      r+=s.charAt(k+1);
     } else if(k==j+1) {
      r+=s.charAt(k-1);
     } else {
      r+=s.charAt(k);
     };
    };
    this.addResult(r);
   };
  };
  this.ido="idoNothing"; this.doprogress=100;
  this.reverseLettersReady=1;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.doSkipLetter = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doSkipLetter is runing...");};
  this.ido="idoSkipLetter"; this.doprogress=0;
  for(var i=0; i<this.sourceArray.length; i++) {
   var s = this.sourceArray[i];
   var fp = this.getSkipWWW(s); var ep = this.getSkipTLD(s,fp);
   for(var j=fp; j<ep; j++) {
    var r = "";
    for(var k=0; k<s.length; k++) {
     if(k!=j) {
      r+=s.charAt(k);
     };
    };
    this.addResult(r);
   };
  };
  this.ido="idoNothing"; this.doprogress=100;
  this.skipLetterReady=1;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.doSkipSpaces = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doSkipSpaces is runing...");};
  this.ido="idoSkipSpaces"; this.doprogress=0;
  for(var i=0; i<this.sourceArray.length; i++) {
   var s = this.sourceArray[i];
   var fp = this.getSkipWWW(s); var ep = this.getSkipTLD(s,fp);
   var spaceArray = new Array();
   var rs = "";
   for(var j=0; j<s.length; j++) {
    if(s.charAt(j)==" ") {
     spaceArray[spaceArray.length]=j;
    } else {
     rs+=s.charAt(j);
    };
   };
   this.addResult(rs);
   // if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.doSkipSpaces spaceArray.length:"+spaceArray.length);};
   for(var j=0; j<spaceArray.length; j++) {
    var r = "";
    for(var k=fp; k<ep; k++) {
     if(k!=spaceArray[j]) {
      r+=s.charAt(k);
     };
    };
    this.addResult(r);
   };
  };
  this.ido="idoNothing"; this.doprogress=100;
  this.skipSpacesReady=1;
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.generate = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.generate is runing...");};
  this.ido="idoGenerate"; this.doprogress=0;
  if(this.ready==0) {return;};
  this.ready=0;
  this.resultArray = new Array(); 
  this.indexResultArray = new Array(); 
  var the=this; 
  if(this.doubleLetters) {this.doubleLettersReady=0; setTimeout(function() {the.doDoubleLetters();}, 50);};
  if(this.insertedKey) {this.insertedKeyReady=0; setTimeout(function() {the.doInsertedKey();}, 100);};
  if(this.lookAlikes) {this.lookAlikesReady=0; setTimeout(function() {the.doLookAlikes();}, 150);};
  if(this.missedKey) {this.missedKeyReady=0; setTimeout(function() {the.doMissedKey();}, 200);};
  if(this.phoneticKey) {this.phoneticKeyReady=0; setTimeout(function() {the.doPhoneticKey();}, 250);};
  if(this.reverseLetters) {this.reverseLettersReady=0; setTimeout(function() {the.doReverseLetters();}, 300);};
  if(this.skipLetter) {this.skipLetterReady=0; setTimeout(function() {the.doSkipLetter();}, 350);};
  if(this.skipSpaces) {this.skipSpacesReady=0; setTimeout(function() {the.doSkipSpaces();}, 400);};
  setTimeout(function() {the.testReadyGenerate()}, 450);
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.sort = function() {
  if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.sort is runing...");};
  this.sortPopularyReady=0;
  var the=this; setTimeout(function() {the.sortIJ(0,1);}, 5);
 };
 
   /**
 com.tapogen.javascript.TypoGenerator.prototype.sortI = function(i) {
  //if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.sortI is runing...");};
  if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.sortI i:"+i);};
  if(i<this.resultArray.length) {
   //var start = new Date().getTime();
   do {
    for(var j=i+1; j<this.resultArray.length; j++) {
     if( (this.groupIdentical==1 && this.indexResultArray[this.resultArray[i]]<this.indexResultArray[this.resultArray[j]])
          || (this.indexResultArray[this.resultArray[i]]==this.indexResultArray[this.resultArray[j]] && this.resultArray[i].length>this.resultArray[j].length)
          || (this.indexResultArray[this.resultArray[i]]==this.indexResultArray[this.resultArray[j]] && this.resultArray[i].length==this.resultArray[j].length && this.resultArray[i]>this.resultArray[j]) ) {
      var p = this.resultArray[i];
      this.resultArray[i] = this.resultArray[j];
      this.resultArray[j] = p;
     };
    };
    i++;
 //   * /
    var j=i+1;
    var the=this; setTimeout(function() {the.sortJ(i, j);}, 0);
   //} while(i<this.resultArray.length && ((start - new Date().getTime()) < 40));
   // var the=this; setTimeout(function() {the.sortI(i);}, 0);
  } else {
   /*for(var k=0; k<this.resultArray.length; k++) {
    this.resultArray[k] = this.indexResultArray[this.resultArray[k]]+"."+this.resultArray[k].length+"."+this.resultArray[k];
   };
   this.sortPopularyReady=1;
  };
 }; */
 
 com.tapogen.javascript.TypoGenerator.prototype.sortIJ = function(i, j) {
  //if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.sortIJ is runing...");};
  this.ido="idoSorting"; this.doprogress=0+((i/(this.resultArray.length-1))*100);
  //this.ido="idoSorting"; this.doprogress=0+(((i+1)*j/(this.resultArray.length*this.resultArray.length))*100);
  //if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.sortIJ new i:"+i+"; j:"+j+"; this.doprogress:"+this.doprogress);};
  if(i<this.resultArray.length) {
   var start = new Date().getTime();
   do {
    // if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.sortIJ old i:"+i+"; j:"+j);};
    do {
     if( (this.groupIdentical==1 && this.indexResultArray[this.resultArray[i]]<this.indexResultArray[this.resultArray[j]])
         || (this.indexResultArray[this.resultArray[i]]==this.indexResultArray[this.resultArray[j]] && this.resultArray[i].length>this.resultArray[j].length)
         || (this.indexResultArray[this.resultArray[i]]==this.indexResultArray[this.resultArray[j]] && this.resultArray[i].length==this.resultArray[j].length && this.resultArray[i]>this.resultArray[j]) ) {
      var p = this.resultArray[i];
      this.resultArray[i] = this.resultArray[j];
      this.resultArray[j] = p;
     };
     j++;
     // if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.sortIJ j:"+j+"; period:"+(new Date().getTime()-start));};
     if((new Date().getTime()-start) > 40) {
      var the=this; setTimeout(function() {the.sortIJ(i, j);}, 0);
      return;
     };
    } while(j<this.resultArray.length);
    i++;
    j=i+1;
   } while(i<this.resultArray.length && ((new Date().getTime()-start) < 40));
   var the=this; setTimeout(function() {the.sortIJ(i, j);}, 0);
  } else {
   this.ido="idoNothing"; this.doprogress=100;
   this.sortPopularyReady=1;
  };
 };
 
 /*
 com.tapogen.javascript.TypoGenerator.prototype.sortJ = function(i, j) {
  //if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.sortJ is runing...");};
  //if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.sortJ j:"+j);};
  if(j<this.resultArray.length) {
   var start = new Date().getTime();
   do {
    if( (this.groupIdentical==1 && this.indexResultArray[this.resultArray[i]]<this.indexResultArray[this.resultArray[j]])
        || (this.indexResultArray[this.resultArray[i]]==this.indexResultArray[this.resultArray[j]] && this.resultArray[i].length>this.resultArray[j].length)
        || (this.indexResultArray[this.resultArray[i]]==this.indexResultArray[this.resultArray[j]] && this.resultArray[i].length==this.resultArray[j].length && this.resultArray[i]>this.resultArray[j]) ) {
     var p = this.resultArray[i];
     this.resultArray[i] = this.resultArray[j];
     this.resultArray[j] = p;
    };
    j++;
   } while(j<this.resultArray.length && ((start - new Date().getTime()) < 40));
   var the=this; setTimeout(function() {the.sortJ(i, j);}, 0);
  } else {
   i++;
   var the=this; setTimeout(function() {the.sortI(i);}, 0);
  };
 };*/
 
 com.tapogen.javascript.TypoGenerator.prototype.testReady = function() {
  // if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.testReady is runing...");};
  if(this.sortPopularyReady){
   this.ready=1;
  } else {
   var the=this; this.lastGenerateTimeout = setTimeout(function() {the.testReady();}, 100);
  };
 };
 
 com.tapogen.javascript.TypoGenerator.prototype.testReadyGenerate = function() {
  //if(this.mustTrace()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.testReadyGenerate is runing...");};
  var ready=1;
  //if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.testReadyGenerate this.skipLetter:"+this.skipLetter+"; this.skipLetterReady:"+this.skipLetterReady);};
  if(this.skipLetter && !this.skipLetterReady){ready=0;};
  if(this.doubleLetters && !this.doubleLettersReady){ready=0;};
  if(this.reverseLetters && !this.reverseLettersReady){ready=0;};
  if(this.skipSpaces && !this.skipSpacesReady){ready=0;};
  if(this.missedKey && !this.missedKeyReady){ready=0;};
  if(this.insertedKey && !this.insertedKeyReady){ready=0;};
  if(this.lookAlikes && !this.lookAlikesReady){ready=0;};
  if(this.phoneticKey && !this.phoneticKeyReady){ready=0;}; 
  var the=this;
  //if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.testReadyGenerate ready:"+ready);};
  if(ready=1) {
   //if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.testReadyGenerate this.sortPopulary:"+this.sortPopulary);};
   if(this.sortPopulary) {
    setTimeout(function() {the.sort()}, 10);
    setTimeout(function() {the.testReady()}, 100);
   } else {
    this.ready=1;
    //if(this.mustDebug()) {this.getLog().println("com.tapogen.javascript.TypoGenerator.testReadyGenerate this.ready:"+this.ready);};
   };
  } else {
   setTimeout(function() {the.testReadyGenerate()}, 100);
  };  
 };
};

