-- data exported from NUbase - 28th april 2011

--radioactiviy types
-- -2= N/A
-- -1= unknown
-- 0 = stable
-- 1 = beta+
-- 2 = beta-
-- 3 = alpha
-- 4 = internal transition
-- 5 = spontaneous fission
-- 6 = p
-- 7 = n
-- 8 = 2n
-- 9 = 2p
-- 10= 2beta-
-- 11= 2beta+
-- 12= EC

data =
{
 {
  "n",
  "",
  0,
  {
   {1,2},
   {2,-2},
   {3,6}
  }
 },
 {
  "H",
  "",
  1,
  {
   {0,0},
   {1,0},
   {2,2},
   {3,7},
   {4,8},
   {5,7},
   {6,8}
  }
 },
 {
  "He",
  "",
  2,
  {
   {1,0},
   {2,0},
   {3,7},
   {4,2},
   {5,7},
   {6,2},
   {7,7},
   {8,8}
  }
 },
 {
  "Li",
  "",
  3,
  {
   {1,6},
   {2,6},
   {3,0},
   {4,0},
   {5,2},
   {6,2},
   {7,7},
   {8,2},
   {9,7},
   {10,8}
  }
 },
 {
  "Be",
  "",
  4,
  {
   {1,6},
   {2,9},
   {3,12},
   {4,3},
   {5,0},
   {6,2},
   {7,2},
   {8,2},
   {9,7},
   {10,2},
   {11,7},
   {12,8}
  }
 },
 {
  "B",
  "",
  5,
  {
   {1,9},
   {2,6},
   {3,1},
   {4,6},
   {5,0},
   {6,0},
   {7,2},
   {8,2},
   {9,2},
   {10,2},
   {11,7},
   {12,2},
   {13,7},
   {14,2},
   {15,7},
   {16,7}
  }
 },
 {
  "C",
  "",
  6,
  {
   {2,9},
   {3,1},
   {4,1},
   {5,1},
   {6,0},
   {7,0},
   {8,2},
   {9,2},
   {10,2},
   {11,2},
   {12,2},
   {13,2},
   {14,2},
   {15,7},
   {16,2},
   {17,7}
  }
 },
 {
  "N",
  "",
  7,
  {
   {3,6},
   {4,6},
   {5,1},
   {6,1},
   {7,0},
   {8,0},
   {9,2},
   {10,2},
   {11,2},
   {12,2},
   {13,2},
   {14,2},
   {15,2},
   {16,2},
   {17,7},
   {18,7}
  }
 },
 {
  "O",
  "",
  8,
  {
   {4,9},
   {5,1},
   {6,1},
   {7,1},
   {8,0},
   {9,0},
   {10,0},
   {11,2},
   {12,2},
   {13,2},
   {14,2},
   {15,2},
   {16,2},
   {17,7},
   {18,8},
   {19,7},
   {20,7}
  }
 },
 {
  "F",
  "",
  9,
  {
   {5,6},
   {6,6},
   {7,6},
   {8,1},
   {9,1},
   {10,0},
   {11,2},
   {12,2},
   {13,2},
   {14,2},
   {15,2},
   {16,2},
   {17,2},
   {18,2},
   {19,7},
   {20,2},
   {21,7},
   {22,2}
  }
 },
 {
  "Ne",
  "",
  10,
  {
   {6,9},
   {7,1},
   {8,1},
   {9,1},
   {10,0},
   {11,0},
   {12,0},
   {13,2},
   {14,2},
   {15,2},
   {16,2},
   {17,2},
   {18,2},
   {19,2},
   {20,2},
   {21,2},
   {22,2},
   {23,7},
   {24,2}
  }
 },
 {
  "Na",
  "",
  11,
  {
   {7,6},
   {8,6},
   {9,1},
   {10,1},
   {11,1},
   {12,0},
   {13,2},
   {14,2},
   {15,2},
   {16,2},
   {17,2},
   {18,2},
   {19,2},
   {20,2},
   {21,2},
   {22,2},
   {23,2},
   {24,2},
   {25,7},
   {26,2}
  }
 },
 {
  "Mg",
  "",
  12,
  {
   {7,9},
   {8,1},
   {9,1},
   {10,1},
   {11,1},
   {12,0},
   {13,0},
   {14,0},
   {15,2},
   {16,2},
   {17,2},
   {18,2},
   {19,2},
   {20,2},
   {21,2},
   {22,2},
   {23,2},
   {24,2},
   {25,2},
   {26,2},
   {27,7},
   {28,2}
  }
 },
 {
  "Al",
  "",
  13,
  {
   {8,6},
   {9,1},
   {10,1},
   {11,1},
   {12,1},
   {13,1},
   {14,0},
   {15,2},
   {16,2},
   {17,2},
   {18,2},
   {19,2},
   {20,2},
   {21,2},
   {22,2},
   {23,2},
   {24,2},
   {25,2},
   {26,2},
   {27,2},
   {28,2},
   {29,2},
   {30,2}
  }
 },
 {
  "Si",
  "",
  14,
  {
   {8,1},
   {9,1},
   {10,1},
   {11,1},
   {12,1},
   {13,1},
   {14,0},
   {15,0},
   {16,0},
   {17,2},
   {18,2},
   {19,2},
   {20,2},
   {21,2},
   {22,2},
   {23,2},
   {24,2},
   {25,2},
   {26,2},
   {27,2},
   {28,2},
   {29,2},
   {30,2},
   {31,2}
  }
 },
 {
  "P",
  "",
  15,
  {
   {9,6},
   {10,6},
   {11,1},
   {12,1},
   {13,1},
   {14,1},
   {15,1},
   {16,0},
   {17,2},
   {18,2},
   {19,2},
   {20,2},
   {21,2},
   {22,2},
   {23,2},
   {24,2},
   {25,2},
   {26,2},
   {27,2},
   {28,2},
   {29,2},
   {30,2},
   {31,2},
   {32,2}
  }
 },
 {
  "S",
  "",
  16,
  {
   {10,9},
   {11,1},
   {12,1},
   {13,1},
   {14,1},
   {15,1},
   {16,0},
   {17,0},
   {18,0},
   {19,2},
   {20,0},
   {21,2},
   {22,2},
   {23,2},
   {24,2},
   {25,2},
   {26,2},
   {27,2},
   {28,2},
   {29,2},
   {30,2},
   {31,2},
   {32,2},
   {33,7}
  }
 },
 {
  "Cl",
  "",
  17,
  {
   {11,6},
   {12,6},
   {13,6},
   {14,1},
   {15,1},
   {16,1},
   {17,1},
   {18,0},
   {19,2},
   {20,0},
   {21,2},
   {22,2},
   {23,2},
   {24,2},
   {25,2},
   {26,2},
   {27,2},
   {28,2},
   {29,2},
   {30,2},
   {31,2},
   {32,2},
   {33,2},
   {34,2}
  }
 },
 {
  "Ar",
  "",
  18,
  {
   {12,6},
   {13,1},
   {14,1},
   {15,1},
   {16,1},
   {17,1},
   {18,11},
   {19,12},
   {20,0},
   {21,2},
   {22,0},
   {23,2},
   {24,2},
   {25,2},
   {26,2},
   {27,2},
   {28,2},
   {29,2},
   {30,2},
   {31,2},
   {32,2},
   {33,2},
   {34,2},
   {35,2}
  }
 },
 {
  "K",
  "",
  19,
  {
   {13,6},
   {14,6},
   {15,6},
   {16,1},
   {17,1},
   {18,1},
   {19,1},
   {20,0},
   {21,2},
   {22,0},
   {23,2},
   {24,2},
   {25,2},
   {26,2},
   {27,2},
   {28,2},
   {29,2},
   {30,2},
   {31,2},
   {32,2},
   {33,2},
   {34,2},
   {35,2},
   {36,2},
   {37,2}
  }
 },
 {
  "Ca",
  "",
  20,
  {
   {14,9},
   {15,1},
   {16,1},
   {17,1},
   {18,1},
   {19,1},
   {20,11},
   {21,12},
   {22,0},
   {23,0},
   {24,0},
   {25,2},
   {26,10},
   {27,2},
   {28,10},
   {29,2},
   {30,2},
   {31,2},
   {32,2},
   {33,2},
   {34,2},
   {35,2},
   {36,2},
   {37,2},
   {38,2}
  }
 },
 {
  "Sc",
  "",
  21,
  {
   {15,6},
   {16,6},
   {17,6},
   {18,6},
   {19,1},
   {20,1},
   {21,1},
   {22,1},
   {23,1},
   {24,0},
   {25,2},
   {26,2},
   {27,2},
   {28,2},
   {29,2},
   {30,2},
   {31,2},
   {32,2},
   {33,2},
   {34,2},
   {35,2},
   {36,2},
   {37,2},
   {38,2},
   {39,2},
   {40,2}
  }
 },
 {
  "Ti",
  "",
  22,
  {
   {16,9},
   {17,1},
   {18,1},
   {19,1},
   {20,1},
   {21,1},
   {22,12},
   {23,1},
   {24,0},
   {25,0},
   {26,0},
   {27,0},
   {28,0},
   {29,2},
   {30,2},
   {31,2},
   {32,2},
   {33,2},
   {34,2},
   {35,2},
   {36,2},
   {37,2},
   {38,2},
   {39,2},
   {40,2},
   {41,2}
  }
 },
 {
  "V",
  "",
  23,
  {
   {17,6},
   {18,6},
   {19,6},
   {20,1},
   {21,1},
   {22,1},
   {23,1},
   {24,1},
   {25,1},
   {26,12},
   {27,1},
   {28,0},
   {29,2},
   {30,2},
   {31,2},
   {32,2},
   {33,2},
   {34,2},
   {35,2},
   {36,2},
   {37,2},
   {38,2},
   {39,2},
   {40,2},
   {41,2},
   {42,2},
   {43,2}
  }
 },
 {
  "Cr",
  "",
  24,
  {
   {18,1},
   {19,1},
   {20,1},
   {21,1},
   {22,1},
   {23,1},
   {24,1},
   {25,1},
   {26,11},
   {27,12},
   {28,0},
   {29,0},
   {30,0},
   {31,2},
   {32,2},
   {33,2},
   {34,2},
   {35,2},
   {36,2},
   {37,2},
   {38,2},
   {39,2},
   {40,2},
   {41,2},
   {42,2},
   {43,2},
   {44,2}
  }
 },
 {
  "Mn",
  "",
  25,
  {
   {19,6},
   {20,6},
   {21,1},
   {22,1},
   {23,1},
   {24,1},
   {25,1},
   {26,1},
   {27,1},
   {28,12},
   {29,12},
   {30,0},
   {31,2},
   {32,2},
   {33,2},
   {34,2},
   {35,2},
   {36,2},
   {37,2},
   {38,2},
   {39,2},
   {40,2},
   {41,2},
   {42,2},
   {43,2},
   {44,2},
   {45,2}
  }
 },
 {
  "Fe",
  "",
  26,
  {
   {19,9},
   {20,1},
   {21,1},
   {22,1},
   {23,1},
   {24,1},
   {25,1},
   {26,1},
   {27,1},
   {28,11},
   {29,12},
   {30,0},
   {31,0},
   {32,0},
   {33,2},
   {34,2},
   {35,2},
   {36,2},
   {37,2},
   {38,2},
   {39,2},
   {40,2},
   {41,2},
   {42,2},
   {43,2},
   {44,2},
   {45,2},
   {46,2}
  }
 },
 {
  "Co",
  "",
  27,
  {
   {20,6},
   {21,6},
   {22,6},
   {23,1},
   {24,1},
   {25,1},
   {26,1},
   {27,1},
   {28,1},
   {29,1},
   {30,12},
   {31,1},
   {32,0},
   {33,2},
   {34,2},
   {35,2},
   {36,2},
   {37,2},
   {38,2},
   {39,2},
   {40,2},
   {41,2},
   {42,2},
   {43,2},
   {44,2},
   {45,2},
   {46,2},
   {47,2},
   {48,2}
  }
 },
 {
  "Ni",
  "",
  28,
  {
   {20,9},
   {21,1},
   {22,1},
   {23,1},
   {24,1},
   {25,1},
   {26,1},
   {27,1},
   {28,1},
   {29,1},
   {30,11},
   {31,1},
   {32,0},
   {33,0},
   {34,0},
   {35,2},
   {36,0},
   {37,2},
   {38,2},
   {39,2},
   {40,2},
   {41,2},
   {42,2},
   {43,2},
   {44,2},
   {45,2},
   {46,2},
   {47,2},
   {48,2},
   {49,2},
   {50,2}
  }
 },
 {
  "Cu",
  "",
  29,
  {
   {23,6},
   {24,6},
   {25,6},
   {26,1},
   {27,1},
   {28,1},
   {29,1},
   {30,1},
   {31,1},
   {32,1},
   {33,1},
   {34,0},
   {35,1},
   {36,0},
   {37,2},
   {38,2},
   {39,2},
   {40,2},
   {41,2},
   {42,2},
   {43,2},
   {44,2},
   {45,2},
   {46,2},
   {47,2},
   {48,2},
   {49,2},
   {50,2},
   {51,2}
  }
 },
 {
  "Zn",
  "",
  30,
  {
   {24,9},
   {25,1},
   {26,1},
   {27,1},
   {28,1},
   {29,1},
   {30,1},
   {31,1},
   {32,1},
   {33,1},
   {34,11},
   {35,1},
   {36,0},
   {37,0},
   {38,0},
   {39,2},
   {40,10},
   {41,2},
   {42,2},
   {43,2},
   {44,2},
   {45,2},
   {46,2},
   {47,2},
   {48,2},
   {49,2},
   {50,2},
   {51,2},
   {52,2},
   {53,2}
  }
 },
 {
  "Ga",
  "",
  31,
  {
   {25,6},
   {26,6},
   {27,6},
   {28,6},
   {29,1},
   {30,1},
   {31,1},
   {32,1},
   {33,1},
   {34,1},
   {35,1},
   {36,12},
   {37,1},
   {38,0},
   {39,2},
   {40,0},
   {41,2},
   {42,2},
   {43,2},
   {44,2},
   {45,2},
   {46,2},
   {47,2},
   {48,2},
   {49,2},
   {50,2},
   {51,2},
   {52,2},
   {53,2},
   {54,2},
   {55,2}
  }
 },
 {
  "Ge",
  "",
  32,
  {
   {26,9},
   {27,9},
   {28,1},
   {29,1},
   {30,1},
   {31,1},
   {32,1},
   {33,1},
   {34,1},
   {35,1},
   {36,12},
   {37,1},
   {38,0},
   {39,12},
   {40,0},
   {41,0},
   {42,0},
   {43,2},
   {44,10},
   {45,2},
   {46,2},
   {47,2},
   {48,2},
   {49,2},
   {50,2},
   {51,2},
   {52,2},
   {53,2},
   {54,2},
   {55,2},
   {56,2},
   {57,2}
  }
 },
 {
  "As",
  "",
  33,
  {
   {27,6},
   {28,6},
   {29,6},
   {30,6},
   {31,1},
   {32,1},
   {33,1},
   {34,1},
   {35,1},
   {36,1},
   {37,1},
   {38,1},
   {39,1},
   {40,12},
   {41,1},
   {42,0},
   {43,2},
   {44,2},
   {45,2},
   {46,2},
   {47,2},
   {48,2},
   {49,2},
   {50,2},
   {51,2},
   {52,2},
   {53,2},
   {54,2},
   {55,2},
   {56,2},
   {57,2},
   {58,2},
   {59,2}
  }
 },
 {
  "Se",
  "",
  34,
  {
   {30,1},
   {31,1},
   {32,1},
   {33,1},
   {34,1},
   {35,1},
   {36,1},
   {37,1},
   {38,12},
   {39,1},
   {40,11},
   {41,12},
   {42,0},
   {43,0},
   {44,0},
   {45,2},
   {46,10},
   {47,2},
   {48,10},
   {49,2},
   {50,2},
   {51,2},
   {52,2},
   {53,2},
   {54,2},
   {55,2},
   {56,2},
   {57,2},
   {58,2},
   {59,2},
   {60,2}
  }
 },
 {
  "Br",
  "",
  35,
  {
   {32,6},
   {33,6},
   {34,6},
   {35,1},
   {36,1},
   {37,1},
   {38,1},
   {39,1},
   {40,1},
   {41,1},
   {42,1},
   {43,1},
   {44,0},
   {45,2},
   {46,0},
   {47,2},
   {48,2},
   {49,2},
   {50,2},
   {51,2},
   {52,2},
   {53,2},
   {54,2},
   {55,2},
   {56,2},
   {57,2},
   {58,2},
   {59,2},
   {60,2},
   {61,2},
   {62,2}
  }
 },
 {
  "Kr",
  "",
  36,
  {
   {33,1},
   {34,1},
   {35,1},
   {36,1},
   {37,1},
   {38,1},
   {39,1},
   {40,1},
   {41,1},
   {42,11},
   {43,1},
   {44,0},
   {45,12},
   {46,0},
   {47,0},
   {48,0},
   {49,2},
   {50,10},
   {51,2},
   {52,2},
   {53,2},
   {54,2},
   {55,2},
   {56,2},
   {57,2},
   {58,2},
   {59,2},
   {60,2},
   {61,2},
   {62,2},
   {63,2},
   {64,2}
  }
 },
 {
  "Rb",
  "",
  37,
  {
   {34,6},
   {35,6},
   {36,6},
   {37,1},
   {38,1},
   {39,1},
   {40,1},
   {41,1},
   {42,1},
   {43,1},
   {44,1},
   {45,1},
   {46,12},
   {47,1},
   {48,0},
   {49,2},
   {50,2},
   {51,2},
   {52,2},
   {53,2},
   {54,2},
   {55,2},
   {56,2},
   {57,2},
   {58,2},
   {59,2},
   {60,2},
   {61,2},
   {62,2},
   {63,2},
   {64,2},
   {65,2}
  }
 },
 {
  "Sr",
  "",
  38,
  {
   {35,1},
   {36,1},
   {37,1},
   {38,1},
   {39,1},
   {40,1},
   {41,1},
   {42,1},
   {43,1},
   {44,12},
   {45,1},
   {46,11},
   {47,12},
   {48,0},
   {49,0},
   {50,0},
   {51,2},
   {52,2},
   {53,2},
   {54,2},
   {55,2},
   {56,2},
   {57,2},
   {58,2},
   {59,2},
   {60,2},
   {61,2},
   {62,2},
   {63,2},
   {64,2},
   {65,2},
   {66,2},
   {67,2}
  }
 },
 {
  "Y",
  "",
  39,
  {
   {37,1},
   {38,1},
   {39,1},
   {40,1},
   {41,1},
   {42,1},
   {43,1},
   {44,1},
   {45,1},
   {46,1},
   {47,1},
   {48,1},
   {49,1},
   {50,0},
   {51,2},
   {52,2},
   {53,2},
   {54,2},
   {55,2},
   {56,2},
   {57,2},
   {58,2},
   {59,2},
   {60,2},
   {61,2},
   {62,2},
   {63,2},
   {64,2},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2}
  }
 },
 {
  "Zr",
  "",
  40,
  {
   {38,1},
   {39,1},
   {40,1},
   {41,1},
   {42,1},
   {43,1},
   {44,1},
   {45,1},
   {46,1},
   {47,1},
   {48,12},
   {49,1},
   {50,0},
   {51,0},
   {52,0},
   {53,2},
   {54,10},
   {55,2},
   {56,10},
   {57,2},
   {58,2},
   {59,2},
   {60,2},
   {61,2},
   {62,2},
   {63,2},
   {64,2},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2},
   {70,2}
  }
 },
 {
  "Nb",
  "",
  41,
  {
   {40,6},
   {41,1},
   {42,1},
   {43,1},
   {44,1},
   {45,1},
   {46,1},
   {47,1},
   {48,1},
   {49,1},
   {50,12},
   {51,1},
   {52,0},
   {53,2},
   {54,2},
   {55,2},
   {56,2},
   {57,2},
   {58,2},
   {59,2},
   {60,2},
   {61,2},
   {62,2},
   {63,2},
   {64,2},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2},
   {70,2},
   {71,2},
   {72,2}
  }
 },
 {
  "Mo",
  "",
  42,
  {
   {41,1},
   {42,1},
   {43,1},
   {44,1},
   {45,1},
   {46,1},
   {47,1},
   {48,1},
   {49,1},
   {50,11},
   {51,12},
   {52,0},
   {53,0},
   {54,0},
   {55,0},
   {56,10},
   {57,2},
   {58,10},
   {59,2},
   {60,2},
   {61,2},
   {62,2},
   {63,2},
   {64,2},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2},
   {70,2},
   {71,2},
   {72,2},
   {73,2}
  }
 },
 {
  "Tc",
  "",
  43,
  {
   {42,6},
   {43,1},
   {44,1},
   {45,1},
   {46,1},
   {47,1},
   {48,1},
   {49,1},
   {50,1},
   {51,1},
   {52,1},
   {53,1},
   {54,12},
   {55,2},
   {56,2},
   {57,2},
   {58,2},
   {59,2},
   {60,2},
   {61,2},
   {62,2},
   {63,2},
   {64,2},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2},
   {70,2},
   {71,2},
   {72,2},
   {73,2},
   {74,2},
   {75,2}
  }
 },
 {
  "Ru",
  "",
  44,
  {
   {43,1},
   {44,1},
   {45,1},
   {46,1},
   {47,1},
   {48,1},
   {49,1},
   {50,1},
   {51,1},
   {52,11},
   {53,1},
   {54,0},
   {55,0},
   {56,0},
   {57,0},
   {58,0},
   {59,2},
   {60,10},
   {61,2},
   {62,2},
   {63,2},
   {64,2},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2},
   {70,2},
   {71,2},
   {72,2},
   {73,2},
   {74,2},
   {75,2},
   {76,2}
  }
 },
 {
  "Rh",
  "",
  45,
  {
   {44,1},
   {45,1},
   {46,1},
   {47,1},
   {48,1},
   {49,1},
   {50,1},
   {51,1},
   {52,1},
   {53,1},
   {54,1},
   {55,1},
   {56,12},
   {57,1},
   {58,0},
   {59,2},
   {60,2},
   {61,2},
   {62,2},
   {63,2},
   {64,2},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2},
   {70,2},
   {71,2},
   {72,2},
   {73,2},
   {74,2},
   {75,2},
   {76,2},
   {77,2}
  }
 },
 {
  "Pd",
  "",
  46,
  {
   {45,1},
   {46,1},
   {47,1},
   {48,1},
   {49,1},
   {50,1},
   {51,1},
   {52,1},
   {53,1},
   {54,12},
   {55,1},
   {56,11},
   {57,12},
   {58,0},
   {59,0},
   {60,0},
   {61,2},
   {62,0},
   {63,2},
   {64,10},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2},
   {70,2},
   {71,2},
   {72,2},
   {73,2},
   {74,2},
   {75,2},
   {76,2},
   {77,2},
   {78,2}
  }
 },
 {
  "Ag",
  "",
  47,
  {
   {46,6},
   {47,1},
   {48,1},
   {49,1},
   {50,1},
   {51,1},
   {52,1},
   {53,1},
   {54,1},
   {55,1},
   {56,1},
   {57,1},
   {58,1},
   {59,1},
   {60,0},
   {61,2},
   {62,0},
   {63,2},
   {64,2},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2},
   {70,2},
   {71,2},
   {72,2},
   {73,2},
   {74,2},
   {75,2},
   {76,2},
   {77,2},
   {78,2},
   {79,2},
   {80,2},
   {81,2},
   {82,2},
   {83,2}
  }
 },
 {
  "Cd",
  "",
  48,
  {
   {47,1},
   {48,1},
   {49,1},
   {50,1},
   {51,1},
   {52,1},
   {53,1},
   {54,1},
   {55,1},
   {56,1},
   {57,1},
   {58,11},
   {59,1},
   {60,11},
   {61,12},
   {62,0},
   {63,0},
   {64,0},
   {65,2},
   {66,10},
   {67,2},
   {68,10},
   {69,2},
   {70,2},
   {71,2},
   {72,2},
   {73,2},
   {74,2},
   {75,2},
   {76,2},
   {77,2},
   {78,2},
   {79,2},
   {80,2},
   {81,2},
   {82,2},
   {83,2},
   {84,2}
  }
 },
 {
  "In",
  "",
  49,
  {
   {48,6},
   {49,1},
   {50,1},
   {51,1},
   {52,1},
   {53,1},
   {54,1},
   {55,1},
   {56,1},
   {57,1},
   {58,1},
   {59,1},
   {60,1},
   {61,1},
   {62,12},
   {63,1},
   {64,0},
   {65,2},
   {66,2},
   {67,2},
   {68,2},
   {69,2},
   {70,2},
   {71,2},
   {72,2},
   {73,2},
   {74,2},
   {75,2},
   {76,2},
   {77,2},
   {78,2},
   {79,2},
   {80,2},
   {81,2},
   {82,2},
   {83,2},
   {84,2},
   {85,2},
   {86,2}
  }
 },
 {
  "Sn",
  "",
  50,
  {
   {49,1},
   {50,12},
   {51,1},
   {52,1},
   {53,1},
   {54,1},
   {55,1},
   {56,1},
   {57,1},
   {58,1},
   {59,1},
   {60,1},
   {61,1},
   {62,11},
   {63,1},
   {64,0},
   {65,0},
   {66,0},
   {67,0},
   {68,0},
   {69,0},
   {70,0},
   {71,2},
   {72,10},
   {73,2},
   {74,10},
   {75,2},
   {76,2},
   {77,2},
   {78,2},
   {79,2},
   {80,2},
   {81,2},
   {82,2},
   {83,2},
   {84,2},
   {85,2},
   {86,2},
   {87,2}
  }
 },
 {
  "Sb",
  "",
  51,
  {
   {52,1},
   {53,1},
   {54,1},
   {55,1},
   {56,1},
   {57,1},
   {58,1},
   {59,1},
   {60,1},
   {61,1},
   {62,1},
   {63,1},
   {64,1},
   {65,1},
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,0},
   {71,2},
   {72,0},
   {73,2},
   {74,2},
   {75,2},
   {76,2},
   {77,2},
   {78,2},
   {79,2},
   {80,2},
   {81,2},
   {82,2},
   {83,2},
   {84,2},
   {85,2},
   {86,2},
   {87,2},
   {88,2}
  }
 },
 {
  "Te",
  "",
  52,
  {
   {53,3},
   {54,3},
   {55,3},
   {56,1},
   {57,1},
   {58,1},
   {59,1},
   {60,1},
   {61,1},
   {62,1},
   {63,1},
   {64,1},
   {65,1},
   {66,12},
   {67,1},
   {68,11},
   {69,1},
   {70,0},
   {71,12},
   {72,0},
   {73,0},
   {74,0},
   {75,2},
   {76,10},
   {77,2},
   {78,10},
   {79,2},
   {80,2},
   {81,2},
   {82,2},
   {83,2},
   {84,2},
   {85,2},
   {86,2},
   {87,2},
   {88,2},
   {89,2},
   {90,2}
  }
 },
 {
  "I",
  "",
  53,
  {
   {54,3},
   {55,3},
   {56,6},
   {57,1},
   {58,1},
   {59,1},
   {60,1},
   {61,1},
   {62,1},
   {63,1},
   {64,1},
   {65,1},
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,1},
   {71,1},
   {72,12},
   {73,1},
   {74,0},
   {75,2},
   {76,2},
   {77,2},
   {78,2},
   {79,2},
   {80,2},
   {81,2},
   {82,2},
   {83,2},
   {84,2},
   {85,2},
   {86,2},
   {87,2},
   {88,2},
   {89,2},
   {90,2},
   {91,2}
  }
 },
 {
  "Xe",
  "",
  54,
  {
   {54,-1},
   {55,3},
   {56,3},
   {57,1},
   {58,1},
   {59,1},
   {60,1},
   {61,1},
   {62,1},
   {63,1},
   {64,1},
   {65,1},
   {66,1},
   {67,1},
   {68,12},
   {69,1},
   {70,11},
   {71,1},
   {72,11},
   {73,12},
   {74,0},
   {75,0},
   {76,0},
   {77,0},
   {78,0},
   {79,2},
   {80,10},
   {81,2},
   {82,10},
   {83,2},
   {84,2},
   {85,2},
   {86,2},
   {87,2},
   {88,2},
   {89,2},
   {90,2},
   {91,2},
   {92,2},
   {93,2}
  }
 },
 {
  "Cs",
  "",
  55,
  {
   {57,6},
   {58,6},
   {59,1},
   {60,1},
   {61,1},
   {62,1},
   {63,1},
   {64,1},
   {65,1},
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,1},
   {71,1},
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,12},
   {77,1},
   {78,0},
   {79,2},
   {80,2},
   {81,2},
   {82,2},
   {83,2},
   {84,2},
   {85,2},
   {86,2},
   {87,2},
   {88,2},
   {89,2},
   {90,2},
   {91,2},
   {92,2},
   {93,2},
   {94,2},
   {95,2},
   {96,2}
  }
 },
 {
  "Ba",
  "",
  56,
  {
   {56,-1},
   {57,-1},
   {58,1},
   {59,1},
   {60,1},
   {61,1},
   {62,1},
   {63,1},
   {64,1},
   {65,1},
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,1},
   {71,1},
   {72,12},
   {73,1},
   {74,11},
   {75,1},
   {76,11},
   {77,12},
   {78,0},
   {79,0},
   {80,0},
   {81,0},
   {82,0},
   {83,2},
   {84,2},
   {85,2},
   {86,2},
   {87,2},
   {88,2},
   {89,2},
   {90,2},
   {91,2},
   {92,2},
   {93,2},
   {94,2},
   {95,2},
   {96,2},
   {97,2}
  }
 },
 {
  "La",
  "",
  57,
  {
   {60,6},
   {61,1},
   {62,1},
   {63,1},
   {64,1},
   {65,1},
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,1},
   {71,1},
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,12},
   {81,1},
   {82,0},
   {83,2},
   {84,2},
   {85,2},
   {86,2},
   {87,2},
   {88,2},
   {89,2},
   {90,2},
   {91,2},
   {92,2},
   {93,2},
   {94,2},
   {95,2},
   {96,2},
   {97,2},
   {98,2}
  }
 },
 {
  "Ce",
  "",
  58,
  {
   {61,1},
   {62,1},
   {63,1},
   {64,1},
   {65,1},
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,1},
   {71,1},
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,12},
   {77,1},
   {78,11},
   {79,1},
   {80,11},
   {81,12},
   {82,0},
   {83,2},
   {84,3},
   {85,2},
   {86,2},
   {87,2},
   {88,2},
   {89,2},
   {90,2},
   {91,2},
   {92,2},
   {93,2},
   {94,2},
   {95,2},
   {96,2},
   {97,2},
   {98,2},
   {99,2}
  }
 },
 {
  "Pr",
  "",
  59,
  {
   {62,6},
   {63,1},
   {64,1},
   {65,1},
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,1},
   {71,1},
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,0},
   {83,2},
   {84,2},
   {85,2},
   {86,2},
   {87,2},
   {88,2},
   {89,2},
   {90,2},
   {91,2},
   {92,2},
   {93,2},
   {94,2},
   {95,2},
   {96,2},
   {97,2},
   {98,2},
   {99,2},
   {100,2}
  }
 },
 {
  "Nd",
  "",
  60,
  {
   {64,1},
   {65,1},
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,1},
   {71,1},
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,12},
   {81,1},
   {82,0},
   {83,0},
   {84,3},
   {85,0},
   {86,10},
   {87,2},
   {88,10},
   {89,2},
   {90,10},
   {91,2},
   {92,2},
   {93,2},
   {94,2},
   {95,2},
   {96,2},
   {97,2},
   {98,2},
   {99,2},
   {100,2},
   {101,2}
  }
 },
 {
  "Pm",
  "",
  61,
  {
   {65,1},
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,1},
   {71,1},
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,12},
   {83,12},
   {84,12},
   {85,12},
   {86,2},
   {87,2},
   {88,2},
   {89,2},
   {90,2},
   {91,2},
   {92,2},
   {93,2},
   {94,2},
   {95,2},
   {96,2},
   {97,2},
   {98,2},
   {99,2},
   {100,2},
   {101,2},
   {102,2}
  }
 },
 {
  "Sm",
  "",
  62,
  {
   {66,1},
   {67,1},
   {68,1},
   {69,1},
   {70,1},
   {71,1},
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,11},
   {83,12},
   {84,3},
   {85,3},
   {86,3},
   {87,3},
   {88,0},
   {89,2},
   {90,0},
   {91,2},
   {92,10},
   {93,2},
   {94,2},
   {95,2},
   {96,2},
   {97,2},
   {98,2},
   {99,2},
   {100,2},
   {101,2},
   {102,2},
   {103,2}
  }
 },
 {
  "Eu",
  "",
  63,
  {
   {67,6},
   {68,6},
   {69,1},
   {70,1},
   {71,1},
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,1},
   {83,1},
   {84,1},
   {85,1},
   {86,12},
   {87,1},
   {88,3},
   {89,1},
   {90,0},
   {91,2},
   {92,2},
   {93,2},
   {94,2},
   {95,2},
   {96,2},
   {97,2},
   {98,2},
   {99,2},
   {100,2},
   {101,2},
   {102,2},
   {103,2},
   {104,2}
  }
 },
 {
  "Gd",
  "",
  64,
  {
   {69,1},
   {70,1},
   {71,1},
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,12},
   {83,1},
   {84,3},
   {85,1},
   {86,3},
   {87,12},
   {88,3},
   {89,12},
   {90,0},
   {91,0},
   {92,0},
   {93,0},
   {94,0},
   {95,2},
   {96,10},
   {97,2},
   {98,2},
   {99,2},
   {100,2},
   {101,2},
   {102,2},
   {103,2},
   {104,2},
   {105,2}
  }
 },
 {
  "Tb",
  "",
  65,
  {
   {70,6},
   {71,1},
   {72,6},
   {73,1},
   {74,1},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,1},
   {83,1},
   {84,1},
   {85,1},
   {86,1},
   {87,1},
   {88,1},
   {89,1},
   {90,12},
   {91,1},
   {92,12},
   {93,1},
   {94,0},
   {95,2},
   {96,2},
   {97,2},
   {98,2},
   {99,2},
   {100,2},
   {101,2},
   {102,2},
   {103,2},
   {104,2},
   {105,2},
   {106,2}
  }
 },
 {
  "Dy",
  "",
  66,
  {
   {72,1},
   {73,1},
   {74,1},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,1},
   {83,1},
   {84,1},
   {85,1},
   {86,12},
   {87,1},
   {88,3},
   {89,1},
   {90,3},
   {91,1},
   {92,3},
   {93,12},
   {94,0},
   {95,0},
   {96,0},
   {97,0},
   {98,0},
   {99,2},
   {100,2},
   {101,2},
   {102,2},
   {103,2},
   {104,2},
   {105,2},
   {106,2},
   {107,2}
  }
 },
 {
  "Ho",
  "",
  67,
  {
   {73,6},
   {74,6},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,1},
   {83,1},
   {84,1},
   {85,1},
   {86,1},
   {87,1},
   {88,1},
   {89,1},
   {90,1},
   {91,1},
   {92,1},
   {93,1},
   {94,12},
   {95,1},
   {96,12},
   {97,12},
   {98,0},
   {99,2},
   {100,2},
   {101,2},
   {102,2},
   {103,2},
   {104,2},
   {105,2},
   {106,2},
   {107,2},
   {108,2}
  }
 },
 {
  "Er",
  "",
  68,
  {
   {74,6},
   {75,1},
   {76,1},
   {77,1},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,1},
   {83,1},
   {84,3},
   {85,3},
   {86,1},
   {87,1},
   {88,1},
   {89,1},
   {90,12},
   {91,1},
   {92,12},
   {93,1},
   {94,3},
   {95,1},
   {96,3},
   {97,12},
   {98,0},
   {99,0},
   {100,0},
   {101,2},
   {102,10},
   {103,2},
   {104,2},
   {105,2},
   {106,2},
   {107,2},
   {108,2},
   {109,2}
  }
 },
 {
  "Tm",
  "",
  69,
  {
   {75,6},
   {76,6},
   {77,6},
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,1},
   {83,1},
   {84,3},
   {85,3},
   {86,1},
   {87,1},
   {88,1},
   {89,1},
   {90,1},
   {91,1},
   {92,1},
   {93,1},
   {94,1},
   {95,12},
   {96,1},
   {97,1},
   {98,12},
   {99,1},
   {100,0},
   {101,2},
   {102,2},
   {103,2},
   {104,2},
   {105,2},
   {106,2},
   {107,2},
   {108,2},
   {109,2},
   {110,2}
  }
 },
 {
  "Yb",
  "",
  70,
  {
   {78,1},
   {79,1},
   {80,1},
   {81,1},
   {82,1},
   {83,1},
   {84,3},
   {85,3},
   {86,1},
   {87,1},
   {88,1},
   {89,1},
   {90,1},
   {91,1},
   {92,1},
   {93,1},
   {94,12},
   {95,1},
   {96,12},
   {97,1},
   {98,3},
   {99,12},
   {100,0},
   {101,0},
   {102,0},
   {103,0},
   {104,0},
   {105,2},
   {106,10},
   {107,2},
   {108,2},
   {109,2},
   {110,2},
   {111,2}
  }
 },
 {
  "Lu",
  "",
  71,
  {
   {79,6},
   {80,6},
   {81,1},
   {82,1},
   {83,1},
   {84,3},
   {85,3},
   {86,1},
   {87,1},
   {88,1},
   {89,1},
   {90,1},
   {91,1},
   {92,1},
   {93,1},
   {94,1},
   {95,1},
   {96,1},
   {97,1},
   {98,1},
   {99,1},
   {100,1},
   {101,1},
   {102,12},
   {103,1},
   {104,0},
   {105,2},
   {106,2},
   {107,2},
   {108,2},
   {109,2},
   {110,2},
   {111,2},
   {112,2},
   {113,2}
  }
 },
 {
  "Hf",
  "",
  72,
  {
   {81,1},
   {82,1},
   {83,1},
   {84,3},
   {85,3},
   {86,1},
   {87,1},
   {88,1},
   {89,1},
   {90,1},
   {91,1},
   {92,1},
   {93,1},
   {94,1},
   {95,1},
   {96,12},
   {97,1},
   {98,12},
   {99,1},
   {100,12},
   {101,1},
   {102,3},
   {103,12},
   {104,0},
   {105,0},
   {106,0},
   {107,0},
   {108,0},
   {109,2},
   {110,2},
   {111,2},
   {112,2},
   {113,2},
   {114,2},
   {115,2},
   {116,2}
  }
 },
 {
  "Ta",
  "",
  73,
  {
   {82,6},
   {83,6},
   {84,3},
   {85,3},
   {86,1},
   {87,1},
   {88,1},
   {89,1},
   {90,1},
   {91,1},
   {92,1},
   {93,1},
   {94,1},
   {95,1},
   {96,1},
   {97,1},
   {98,1},
   {99,1},
   {100,1},
   {101,1},
   {102,1},
   {103,1},
   {104,1},
   {105,1},
   {106,12},
   {107,12},
   {108,0},
   {109,2},
   {110,2},
   {111,2},
   {112,2},
   {113,2},
   {114,2},
   {115,2},
   {116,2},
   {117,2},
   {118,2},
   {119,2}
  }
 },
 {
  "W",
  "",
  74,
  {
   {83,1},
   {84,3},
   {85,3},
   {86,3},
   {87,3},
   {88,1},
   {89,1},
   {90,1},
   {91,1},
   {92,1},
   {93,1},
   {94,1},
   {95,1},
   {96,1},
   {97,1},
   {98,1},
   {99,1},
   {100,1},
   {101,1},
   {102,12},
   {103,1},
   {104,12},
   {105,1},
   {106,3},
   {107,12},
   {108,3},
   {109,3},
   {110,3},
   {111,2},
   {112,10},
   {113,2},
   {114,2},
   {115,2},
   {116,2},
   {117,2},
   {118,2},
   {119,2},
   {120,2}
  }
 },
 {
  "Re",
  "",
  75,
  {
   {84,6},
   {85,6},
   {86,6},
   {87,3},
   {88,1},
   {89,3},
   {90,1},
   {91,1},
   {92,3},
   {93,1},
   {94,1},
   {95,1},
   {96,1},
   {97,1},
   {98,1},
   {99,1},
   {100,1},
   {101,1},
   {102,1},
   {103,1},
   {104,1},
   {105,1},
   {106,1},
   {107,1},
   {108,12},
   {109,1},
   {110,0},
   {111,2},
   {112,2},
   {113,2},
   {114,2},
   {115,2},
   {116,2},
   {117,2},
   {118,2},
   {119,2},
   {120,2},
   {121,2}
  }
 },
 {
  "Os",
  "",
  76,
  {
   {85,3},
   {86,3},
   {87,3},
   {88,3},
   {89,3},
   {90,3},
   {91,3},
   {92,1},
   {93,1},
   {94,1},
   {95,1},
   {96,1},
   {97,1},
   {98,1},
   {99,1},
   {100,1},
   {101,1},
   {102,1},
   {103,1},
   {104,1},
   {105,1},
   {106,12},
   {107,1},
   {108,3},
   {109,12},
   {110,3},
   {111,0},
   {112,0},
   {113,0},
   {114,0},
   {115,2},
   {116,10},
   {117,2},
   {118,2},
   {119,2},
   {120,2},
   {121,2},
   {122,2},
   {123,2},
   {124,2}
  }
 },
 {
  "Ir",
  "",
  77,
  {
   {87,6},
   {88,6},
   {89,3},
   {90,3},
   {91,3},
   {92,3},
   {93,1},
   {94,3},
   {95,1},
   {96,1},
   {97,1},
   {98,1},
   {99,1},
   {100,1},
   {101,1},
   {102,1},
   {103,1},
   {104,1},
   {105,1},
   {106,1},
   {107,1},
   {108,1},
   {109,1},
   {110,1},
   {111,1},
   {112,12},
   {113,1},
   {114,0},
   {115,2},
   {116,0},
   {117,2},
   {118,2},
   {119,2},
   {120,2},
   {121,2},
   {122,2},
   {123,2},
   {124,2},
   {125,2}
  }
 },
 {
  "Pt",
  "",
  78,
  {
   {88,3},
   {89,3},
   {90,3},
   {91,3},
   {92,3},
   {93,3},
   {94,3},
   {95,3},
   {96,3},
   {97,3},
   {98,1},
   {99,1},
   {100,1},
   {101,1},
   {102,1},
   {103,1},
   {104,1},
   {105,1},
   {106,1},
   {107,1},
   {108,1},
   {109,1},
   {110,12},
   {111,1},
   {112,3},
   {113,12},
   {114,0},
   {115,12},
   {116,0},
   {117,0},
   {118,0},
   {119,2},
   {120,10},
   {121,2},
   {122,2},
   {123,2},
   {124,2},
   {125,2},
   {126,2},
   {127,2}
  }
 },
 {
  "Au",
  "",
  79,
  {
   {90,3},
   {91,6},
   {92,6},
   {93,3},
   {94,3},
   {95,3},
   {96,3},
   {97,3},
   {98,3},
   {99,1},
   {100,1},
   {101,1},
   {102,1},
   {103,1},
   {104,1},
   {105,1},
   {106,1},
   {107,1},
   {108,1},
   {109,1},
   {110,1},
   {111,1},
   {112,1},
   {113,1},
   {114,1},
   {115,1},
   {116,12},
   {117,1},
   {118,0},
   {119,2},
   {120,2},
   {121,2},
   {122,2},
   {123,2},
   {124,2},
   {125,2},
   {126,2},
   {127,2},
   {128,2},
   {129,2},
   {130,2},
   {131,2}
  }
 },
 {
  "Hg",
  "",
  80,
  {
   {91,3},
   {92,3},
   {93,3},
   {94,3},
   {95,3},
   {96,3},
   {97,3},
   {98,3},
   {99,3},
   {100,1},
   {101,1},
   {102,1},
   {103,1},
   {104,1},
   {105,1},
   {106,1},
   {107,1},
   {108,1},
   {109,1},
   {110,12},
   {111,1},
   {112,12},
   {113,1},
   {114,12},
   {115,1},
   {116,11},
   {117,12},
   {118,0},
   {119,0},
   {120,0},
   {121,0},
   {122,0},
   {123,2},
   {124,10},
   {125,2},
   {126,2},
   {127,2},
   {128,2},
   {129,2},
   {130,2},
   {131,2},
   {132,2},
   {133,2},
   {134,2},
   {135,2},
   {136,2}
  }
 },
 {
  "Tl",
  "",
  81,
  {
   {95,6},
   {96,3},
   {97,3},
   {98,3},
   {99,1},
   {100,1},
   {101,1},
   {102,1},
   {103,1},
   {104,1},
   {105,1},
   {106,1},
   {107,1},
   {108,1},
   {109,1},
   {110,1},
   {111,1},
   {112,1},
   {113,1},
   {114,1},
   {115,1},
   {116,1},
   {117,1},
   {118,1},
   {119,1},
   {120,12},
   {121,12},
   {122,0},
   {123,2},
   {124,0},
   {125,2},
   {126,2},
   {127,2},
   {128,2},
   {129,2},
   {130,2},
   {131,2},
   {132,2},
   {133,2},
   {134,2},
   {135,2},
   {136,2}
  }
 },
 {
  "Pb",
  "",
  82,
  {
   {96,3},
   {97,3},
   {98,3},
   {99,3},
   {100,3},
   {101,3},
   {102,3},
   {103,3},
   {104,1},
   {105,1},
   {106,1},
   {107,1},
   {108,1},
   {109,1},
   {110,1},
   {111,1},
   {112,1},
   {113,1},
   {114,1},
   {115,1},
   {116,1},
   {117,1},
   {118,12},
   {119,1},
   {120,12},
   {121,12},
   {122,3},
   {123,12},
   {124,0},
   {125,0},
   {126,0},
   {127,2},
   {128,2},
   {129,2},
   {130,2},
   {131,2},
   {132,2},
   {133,2},
   {134,2},
   {135,2},
   {136,2},
   {137,2},
   {138,2}
  }
 },
 {
  "Bi",
  "",
  83,
  {
   {101,3},
   {102,6},
   {103,3},
   {104,3},
   {105,3},
   {106,3},
   {107,3},
   {108,3},
   {109,1},
   {110,1},
   {111,1},
   {112,1},
   {113,1},
   {114,1},
   {115,1},
   {116,1},
   {117,1},
   {118,1},
   {119,1},
   {120,1},
   {121,1},
   {122,1},
   {123,1},
   {124,1},
   {125,1},
   {126,3},
   {127,2},
   {128,3},
   {129,2},
   {130,2},
   {131,2},
   {132,2},
   {133,2},
   {134,2},
   {135,2},
   {136,2},
   {137,2},
   {138,2},
   {139,2},
   {140,2},
   {141,2}
  }
 },
 {
  "Po",
  "",
  84,
  {
   {102,3},
   {103,3},
   {104,3},
   {105,3},
   {106,3},
   {107,3},
   {108,3},
   {109,3},
   {110,3},
   {111,3},
   {112,3},
   {113,1},
   {114,3},
   {115,1},
   {116,1},
   {117,1},
   {118,1},
   {119,1},
   {120,1},
   {121,1},
   {122,1},
   {123,1},
   {124,3},
   {125,3},
   {126,3},
   {127,3},
   {128,3},
   {129,3},
   {130,3},
   {131,3},
   {132,3},
   {133,3},
   {134,3},
   {135,2},
   {136,2},
   {137,2},
   {138,2},
   {139,2},
   {140,2},
   {141,2},
   {142,2},
   {143,2}
  }
 },
 {
  "At",
  "",
  85,
  {
   {106,3},
   {107,3},
   {108,3},
   {109,3},
   {110,3},
   {111,3},
   {112,3},
   {113,3},
   {114,3},
   {115,3},
   {116,3},
   {117,1},
   {118,1},
   {119,1},
   {120,1},
   {121,1},
   {122,1},
   {123,1},
   {124,1},
   {125,1},
   {126,12},
   {127,3},
   {128,3},
   {129,3},
   {130,3},
   {131,3},
   {132,3},
   {133,3},
   {134,3},
   {135,2},
   {136,2},
   {137,2},
   {138,2},
   {139,2},
   {140,2},
   {141,2},
   {142,2},
   {143,2},
   {144,2}
  }
 },
 {
  "Rn",
  "",
  86,
  {
   {107,3},
   {108,3},
   {109,3},
   {110,3},
   {111,3},
   {112,3},
   {113,3},
   {114,3},
   {115,3},
   {116,3},
   {117,3},
   {118,3},
   {119,1},
   {120,3},
   {121,1},
   {122,3},
   {123,1},
   {124,3},
   {125,1},
   {126,3},
   {127,3},
   {128,3},
   {129,3},
   {130,3},
   {131,3},
   {132,3},
   {133,3},
   {134,3},
   {135,2},
   {136,3},
   {137,2},
   {138,2},
   {139,2},
   {140,2},
   {141,2},
   {142,2},
   {143,2},
   {144,2},
   {145,2}
  }
 },
 {
  "Fr",
  "",
  87,
  {
   {112,3},
   {113,3},
   {114,3},
   {115,3},
   {116,3},
   {117,3},
   {118,3},
   {119,1},
   {120,3},
   {121,3},
   {122,3},
   {123,3},
   {124,3},
   {125,1},
   {126,3},
   {127,3},
   {128,3},
   {129,3},
   {130,3},
   {131,3},
   {132,3},
   {133,3},
   {134,3},
   {135,2},
   {136,2},
   {137,2},
   {138,2},
   {139,2},
   {140,2},
   {141,2},
   {142,2},
   {143,2},
   {144,2},
   {145,2},
   {146,2}
  }
 },
 {
  "Ra",
  "",
  88,
  {
   {113,3},
   {114,3},
   {115,3},
   {116,3},
   {117,3},
   {118,3},
   {119,3},
   {120,3},
   {121,3},
   {122,3},
   {123,3},
   {124,3},
   {125,3},
   {126,3},
   {127,3},
   {128,3},
   {129,3},
   {130,3},
   {131,3},
   {132,3},
   {133,3},
   {134,3},
   {135,3},
   {136,3},
   {137,2},
   {138,3},
   {139,2},
   {140,2},
   {141,2},
   {142,2},
   {143,2},
   {144,2},
   {145,2},
   {146,2},
   {147,2}
  }
 },
 {
  "Ac",
  "",
  89,
  {
   {117,3},
   {118,3},
   {119,3},
   {120,3},
   {121,3},
   {122,3},
   {123,3},
   {124,3},
   {125,3},
   {126,3},
   {127,3},
   {128,3},
   {129,3},
   {130,3},
   {131,3},
   {132,3},
   {133,3},
   {134,3},
   {135,1},
   {136,3},
   {137,2},
   {138,2},
   {139,2},
   {140,2},
   {141,2},
   {142,2},
   {143,2},
   {144,2},
   {145,2},
   {146,2},
   {147,2},
   {148,2}
  }
 },
 {
  "Th",
  "",
  90,
  {
   {118,3},
   {119,3},
   {120,3},
   {121,3},
   {122,3},
   {123,3},
   {124,3},
   {125,3},
   {126,3},
   {127,3},
   {128,3},
   {129,3},
   {130,3},
   {131,3},
   {132,3},
   {133,3},
   {134,3},
   {135,3},
   {136,3},
   {137,3},
   {138,3},
   {139,3},
   {140,3},
   {141,2},
   {142,3},
   {143,2},
   {144,2},
   {145,2},
   {146,2},
   {147,2},
   {148,2},
   {149,2}
  }
 },
 {
  "Pa",
  "",
  91,
  {
   {121,3},
   {122,3},
   {123,3},
   {124,3},
   {125,3},
   {126,3},
   {127,3},
   {128,3},
   {129,3},
   {130,3},
   {131,3},
   {132,3},
   {133,3},
   {134,3},
   {135,3},
   {136,3},
   {137,1},
   {138,12},
   {139,1},
   {140,3},
   {141,2},
   {142,2},
   {143,2},
   {144,2},
   {145,2},
   {146,2},
   {147,2},
   {148,2},
   {149,2},
   {150,2}
  }
 },
 {
  "U",
  "",
  92,
  {
   {125,3},
   {126,3},
   {127,3},
   {128,3},
   {129,3},
   {130,3},
   {131,3},
   {132,3},
   {133,3},
   {134,3},
   {135,3},
   {136,3},
   {137,1},
   {138,3},
   {139,12},
   {140,3},
   {141,3},
   {142,3},
   {143,3},
   {144,3},
   {145,2},
   {146,3},
   {147,2},
   {148,2},
   {149,2},
   {150,2},
   {151,2}
  }
 },
 {
  "Np",
  "",
  93,
  {
   {132,3},
   {133,3},
   {134,3},
   {135,12},
   {136,3},
   {137,1},
   {138,1},
   {139,1},
   {140,1},
   {141,1},
   {142,12},
   {143,12},
   {144,3},
   {145,2},
   {146,2},
   {147,2},
   {148,2},
   {149,2},
   {150,2},
   {151,2},
   {152,2}
  }
 },
 {
  "Pu",
  "",
  94,
  {
   {134,3},
   {135,3},
   {136,3},
   {137,1},
   {138,12},
   {139,1},
   {140,12},
   {141,1},
   {142,3},
   {143,12},
   {144,3},
   {145,3},
   {146,3},
   {147,2},
   {148,3},
   {149,2},
   {150,3},
   {151,2},
   {152,2},
   {153,2}
  }
 },
 {
  "Am",
  "",
  95,
  {
   {136,1},
   {137,1},
   {138,1},
   {139,1},
   {140,1},
   {141,1},
   {142,1},
   {143,1},
   {144,12},
   {145,1},
   {146,3},
   {147,2},
   {148,3},
   {149,2},
   {150,2},
   {151,2},
   {152,2},
   {153,2},
   {154,2}
  }
 },
 {
  "Cm",
  "",
  96,
  {
   {137,3},
   {138,1},
   {139,1},
   {140,1},
   {141,1},
   {142,12},
   {143,1},
   {144,3},
   {145,12},
   {146,3},
   {147,3},
   {148,3},
   {149,3},
   {150,3},
   {151,3},
   {152,3},
   {153,2},
   {154,5},
   {155,2},
   {156,2}
  }
 },
 {
  "Bk",
  "",
  97,
  {
   {138,1},
   {139,1},
   {140,1},
   {141,1},
   {142,1},
   {143,1},
   {144,3},
   {145,1},
   {146,1},
   {147,1},
   {148,12},
   {149,1},
   {150,3},
   {151,3},
   {152,2},
   {153,2},
   {154,2},
   {155,2},
   {156,2},
   {157,2}
  }
 },
 {
  "Cf",
  "",
  98,
  {
   {139,3},
   {140,5},
   {141,3},
   {142,3},
   {143,1},
   {144,3},
   {145,1},
   {146,3},
   {147,1},
   {148,3},
   {149,12},
   {150,3},
   {151,3},
   {152,3},
   {153,3},
   {154,3},
   {155,2},
   {156,5},
   {157,2},
   {158,5}
  }
 },
 {
  "Es",
  "",
  99,
  {
   {141,3},
   {142,3},
   {143,3},
   {144,3},
   {145,1},
   {146,1},
   {147,1},
   {148,1},
   {149,1},
   {150,1},
   {151,1},
   {152,12},
   {153,3},
   {154,3},
   {155,3},
   {156,2},
   {157,2},
   {158,2},
   {159,2}
  }
 },
 {
  "Fm",
  "",
  100,
  {
   {142,5},
   {143,3},
   {144,5},
   {145,3},
   {146,3},
   {147,3},
   {148,3},
   {149,1},
   {150,3},
   {151,1},
   {152,3},
   {153,12},
   {154,3},
   {155,3},
   {156,5},
   {157,3},
   {158,5},
   {159,5},
   {160,5}
  }
 },
 {
  "Md",
  "",
  101,
  {
   {144,3},
   {145,3},
   {146,3},
   {147,1},
   {148,3},
   {149,1},
   {150,1},
   {151,1},
   {152,1},
   {153,1},
   {154,1},
   {155,1},
   {156,12},
   {157,3},
   {158,5},
   {159,5},
   {160,3},
   {161,5}
  }
 },
 {
  "No",
  "",
  102,
  {
   {146,5},
   {147,1},
   {148,5},
   {149,3},
   {150,3},
   {151,3},
   {152,3},
   {153,3},
   {154,3},
   {155,3},
   {156,5},
   {157,3},
   {158,5},
   {159,3},
   {160,5},
   {161,3},
   {162,3}
  }
 },
 {
  "Lr",
  "",
  103,
  {
   {148,1},
   {149,1},
   {150,3},
   {151,3},
   {152,3},
   {153,3},
   {154,3},
   {155,3},
   {156,3},
   {157,3},
   {158,5},
   {159,1},
   {160,3},
   {161,3},
   {162,3},
   {163,3}
  }
 },
 {
  "Rf",
  "",
  104,
  {
   {149,5},
   {150,5},
   {151,3},
   {152,5},
   {153,3},
   {154,5},
   {155,3},
   {156,5},
   {157,3},
   {158,5},
   {159,5},
   {160,3},
   {161,5},
   {162,3},
   {163,5},
   {164,3}
  }
 },
 {
  "Db",
  "",
  105,
  {
   {150,3},
   {151,3},
   {152,3},
   {153,3},
   {154,3},
   {155,3},
   {156,5},
   {157,3},
   {158,5},
   {159,3},
   {160,3},
   {161,3},
   {162,5},
   {163,5},
   {164,3},
   {165,5}
  }
 },
 {
  "Sg",
  "",
  106,
  {
   {152,5},
   {153,3},
   {154,5},
   {155,3},
   {156,5},
   {157,3},
   {158,5},
   {159,3},
   {160,5},
   {161,5},
   {162,3},
   {163,3},
   {164,3},
   {165,3},
   {166,3},
   {167,5}
  }
 },
 {
  "Bh",
  "",
  107,
  {
   {153,3},
   {154,3},
   {155,3},
   {156,3},
   {157,3},
   {158,3},
   {159,3},
   {160,3},
   {161,3},
   {162,3},
   {163,3},
   {164,3},
   {165,3},
   {166,3},
   {167,3},
   {168,5}
  }
 },
 {
  "Hs",
  "",
  108,
  {
   {155,3},
   {156,3},
   {157,3},
   {158,3},
   {159,3},
   {160,3},
   {161,3},
   {162,3},
   {163,3},
   {164,3},
   {165,3},
   {166,3},
   {167,3},
   {168,3},
   {169,5}
  }
 },
 {
  "Mt",
  "",
  109,
  {
   {156,3},
   {157,3},
   {158,3},
   {159,3},
   {160,3},
   {161,3},
   {162,3},
   {163,3},
   {164,3},
   {165,3},
   {166,3},
   {167,3},
   {168,3},
   {169,3},
   {170,3}
  }
 },
 {
  "Ds",
  "",
  110,
  {
   {157,3},
   {158,3},
   {159,3},
   {160,3},
   {161,3},
   {162,5},
   {163,3},
   {164,3},
   {165,3},
   {166,3},
   {167,3},
   {168,3},
   {169,5},
   {170,5},
   {171,5}
  }
 },
 {
  "Rg",
  "",
  111,
  {
   {161,3},
   {162,3},
   {163,3},
   {164,3},
   {165,3},
   {166,3},
   {167,3},
   {168,3},
   {169,3},
   {170,5},
   {171,3},
   {172,3}
  }
 },
 {
  "Cn",
  "",
  112,
  {
   {164,3},
   {165,3},
   {166,3},
   {167,3},
   {168,3},
   {169,3},
   {170,5},
   {171,3},
   {172,5},
   {173,3}
  }
 },
 {
  "Uut",
  "",
  113,
  {
   {165,3},
   {166,3},
   {167,3},
   {168,3},
   {169,3},
   {170,3},
   {171,3},
   {172,3},
   {173,3},
   {174,3}
  }
 },
 {
  "Uuq",
  "",
  114,
  {
   {171,3},
   {172,5},
   {173,3},
   {174,3},
   {175,3}
  }
 },
 {
  "Uup",
  "",
  115,
  {
   {172,3},
   {173,3},
   {174,3},
   {175,3},
   {176,3}
  }
 },
 {
  "Uuh",
  "",
  116,
  {
   {173,3},
   {174,3},
   {175,3},
   {176,3},
   {177,3},
   {178,-2},
   {179,-2},
   {180,-2},
   {181,-2},
   {182,-2},
   {183,-2},
   {184,-2},
   {185,-2},
   {186,-2},
   {187,2},
   {188,2}
  }
 },
 {
  "Uus",
  "",
  117,
  {
   {174,3},
   {175,3},
   {176,3},
   {177,3}
  }
 },
 {
  "Uuo",
  "",
  118,
  {
   {175,3},
   {176,3},
   {177,3}
  }
 }
}

maxN=188

--------------------------------------------------------------------- View: Widgets & Events manager

View = class()

function View:init(window)
    self.window         = window
    self.widgetList     = {}
    self.focusList      = {}
    self.currentFocus   = 0
    self.currentCursor = "default"

    -- Previous location of mouse pointer
    self.prev_mousex    = 0
    self.prev_mousey    = 0
end


function View:invalidate()
    self.window:invalidate()
end

function View:setCursor(cursor)
    if cursor~=self.currentCursor then
	self.currentCursor = cursor
	self:invalidate()
    end
end


function View:add(o)
    table.insert(self.widgetList, o)
    self:repos(o)
    if o.acceptsFocus then
        table.insert(self.focusList, o)
    end
    return o
end

function View:repos(o)
	if o.hConstraint =="right" then
		o.x = scrWidth-o.w-o.xOrig
	elseif o.hConstraint =="center" then
		o.x = (scrWidth-o.w+o.xOrig)/2
	end
	if o.vConstraint =="bottom" then
		o.y = scrHeight-o.h-o.yOrig
	elseif o.vConstraint =="middle" then
		o.y = (scrHeight-o.h+o.yOrig)/2
	end
end

function View:resize()
    for _, o in ipairs(self.widgetList) do
	self:repos(o)
    end
end

function View:hide(o)
    if o.visible then
	o.visible = false
	self:releaseFocus(o)
	if o:contains(self.prev_mousex, self.prev_mousey) then
		o:onMouseLeave(o.x-1,o.y-1)
	end
	self:invalidate()
    end
end

function View:show(o)
    if not o.visible then
	o.visible = true
	if o:contains(self.prev_mousex, self.prev_mousey) then
		o:onMouseEnter(self.prev_mousex,self.prev_mousey)
	end
	self:invalidate()
    end
end

function View:getFocus()
    if self.currentFocus==0 then
	return nil
    end
    return self.focusList[self.currentFocus]
end

function View:setFocus(obj)
	if self.currentFocus~=0 then
		if self.focusList[self.currentFocus]==obj then
			return
		end
	end
	for i = 1,#self.focusList do
		if self.focusList[i]==obj then
			self.currentFocus = i
			self:invalidate()
			break
		end
	end
end

function View:releaseFocus(obj)
	if self.currentFocus~=0 then
		if self.focusList[self.currentFocus]==obj then
			self.currentFocus = 0
			self:invalidate()
		end
	end
end

function View:sendStringToFocus(str)
    local o = self:getFocus()
    if o then
	if o.visible then
		if o:addString(str) then
			self:invalidate()
		else
			o = nil
		end
	end
    end
    if not o then -- look for a default handler
        for _, o in ipairs(self.focusList) do
            if o.visible then
		if o:addString(str) then
			self:setFocus(o)
			self:invalidate()
			break
		end
            end
        end
    end
end


function View:backSpaceHandler()
    -- Does the focused widget accept BackSpace?
    local o = self:getFocus()
    if o then
	if o.visible and o.acceptsBackSpace then
		o:backSpaceHandler()
		self:setFocus(o)
		self:invalidate()
	else
		o = nil
	end
    end
    if not o then -- look for a default handler
        for _, o in ipairs(self.focusList) do
            if o.visible and o.acceptsBackSpace then
                o:backSpaceHandler()
		self:setFocus(o)
		self:invalidate()
		break;
            end
        end
    end
end


function View:tabForward()
    local nextFocus = self.currentFocus + 1
    if nextFocus > #self.focusList then
        nextFocus = 1
    end
    self.currentFocus = nextFocus
    if not self:getFocus().visible then
	self:tabForward()
    end
    self:invalidate()
end


function View:tabBackward()
    local nextFocus = self.currentFocus - 1
    if nextFocus < 1 then
        nextFocus = #self.focusList
    end
    self.currentFocus = nextFocus
    if not self:getFocus().visible then
	self:tabBackward()
    end
    self:invalidate()
end


function View:onMouseDown(x, y)
    -- Find a widget that has a mouse down handler and bounds the click point
    for _, o in ipairs(self.widgetList) do
        if o.visible and o.acceptsFocus and o:contains(x, y) then
            self.mouseCaptured = o
            o:onMouseDown(o, window, x - o.x, y - o.y)
	    self:setFocus(o)
	    self:invalidate()
            return
        end
    end
    if self.currentFocus ~= 0 then
	self.currentFocus = 0
	self:invalidate()
    end
end


function View:onMouseMove(x, y)
    local prev_mousex = self.prev_mousex
    local prev_mousey = self.prev_mousey
    for _, o in ipairs(self.widgetList) do
        local xyin = o:contains(x, y)
       	local prev_xyin = o:contains(prev_mousex, prev_mousey)
        if xyin and not prev_xyin and o.visible then
       	    -- Mouse entered widget
            o:onMouseEnter(x, y)
	    self:invalidate()
       	elseif prev_xyin and (not xyin or not o.visible) then
            -- Mouse left widget
       	    o:onMouseLeave(x, y)
	    self:invalidate()
        end
    end
    self.prev_mousex = x
    self.prev_mousey = y
end


function View:onMouseUp(x, y)
    local mc = self.mouseCaptured
    if mc then
        self.mouseCaptured = nil
        if mc:contains(x, y) then
            mc:onMouseUp(x - mc.x, y - mc.y)
        else
            mc:cancelClick()
        end
    end
end


function View:enterHandler()
    -- Does the focused widget accept Enter?
    local o = self:getFocus()
    if o then
	if o.visible and o.acceptsEnter then
		o:enterHandler()
		self:setFocus(o)
		self:invalidate()
	else
		o = nil
	end
    end
    if not o then -- look for a default handler
        for _, o in ipairs(self.focusList) do
            if o.visible and o.acceptsEnter then
                o:enterHandler()
		self:setFocus(o)
		self:invalidate()
		break;
            end
        end
    end
end

function View:arrowLeftHandler()
    -- Does the focused widget accept ArrowLeft?
    local o = self:getFocus()
    if o then
	if o.visible and o.acceptsArrowLeft then
		o:arrowLeftHandler()
		self:setFocus(o)
		self:invalidate()
	else
		o = nil
	end
    end
    if not o then -- look for a default handler
        for _, o in ipairs(self.focusList) do
            if o.visible and o.acceptsArrowLeft then
                o:arrowLeftHandler()
		self:setFocus(o)
		self:invalidate()
		break;
            end
        end
    end
end

function View:arrowRightHandler()
    -- Does the focused widget accept ArrowRight?
    local o = self:getFocus()
    if o then
	if o.visible and o.acceptsArrowRight then
		o:arrowRightHandler()
		self:setFocus(o)
		self:invalidate()
	else
		o = nil
	end
    end
    if not o then -- look for a default handler
        for _, o in ipairs(self.focusList) do
            if o.visible and o.acceptsArrowRight then
                o:arrowRightHandler()
		self:setFocus(o)
		self:invalidate()
		break;
            end
        end
    end
end

function View:arrowUpHandler()
    -- Does the focused widget accept ArrowUp?
    local o = self:getFocus()
    if o then
	if o.visible and o.acceptsArrowUp then
		o:arrowUpHandler()
		self:setFocus(o)
		self:invalidate()
	else
		o = nil
	end
    end
    if not o then -- look for a default handler
        for _, o in ipairs(self.focusList) do
            if o.visible and o.acceptsArrowUp then
                o:arrowUpHandler()
		self:setFocus(o)
		self:invalidate()
		break;
            end
        end
    end
end

function View:arrowDownHandler()
    -- Does the focused widget accept ArrowDown?
    local o = self:getFocus()
    if o then
	if o.visible and o.acceptsArrowDown then
		o:arrowDownHandler()
		self:setFocus(o)
		self:invalidate()
	else
		o = nil
	end
    end
    if not o then -- look for a default handler
        for _, o in ipairs(self.focusList) do
            if o.visible and o.acceptsArrowDown then
                o:arrowDownHandler()
		self:setFocus(o)
		self:invalidate()
		break;
            end
        end
    end
end

function View:paint(gc)
    local fo = self:getFocus()
    for _, o in ipairs(self.widgetList) do
        if o.visible then
            o:paint(gc, fo == o)
	    if fo==o then
		gc:setColorRGB(0,0,0)
	        gc:setPen("thin", "dotted")
        	gc:drawRect(o.x-2, o.y-2, o.w+3, o.h+3)
	        gc:setPen("thin", "smooth")
	    end
	end
    end
    cursor.set(self.currentCursor)
end

theView = nil

--------------------------------------------------------------------- Widget

Widget = class()

function Widget:init(view, x, y, w, h, hConstraint, vConstraint)
    self.xOrig		= x
    self.yOrig		= y
    self.view         = view
    self.x              = x
    self.y              = y
    self.w              = w
    self.h              = h
    self.acceptsFocus   = false
    self.visible        = true
    self.acceptsEnter	= false
    self.acceptsEscape	= false
    self.acceptsTab	= false
    self.acceptsDelete	= false
    self.acceptsBackSpace= false
    self.acceptsReturn	= false
    self.acceptsArrowUp	= false
    self.acceptsArrowDown= false
    self.acceptsArrowLeft= false
    self.acceptsArrowRight= false
    self.hConstraint = hConstraint
    self.vConstraint = vConstraint
end


function Widget:contains(x, y)
    return x >= self.x and x <= self.x + self.w
       and y >= self.y and y <= self.y + self.h
end


function Widget:onMouseEnter(x, y)
    -- Implemented in subclasses
end


function Widget:onMouseLeave(x, y)
    -- Implemented in subclasses
end

function Widget:paint(gc, focused)
    -- Implemented in subclasses
end

function Widget:enterHandler()
end

function Widget:escapeHandler()
end

function Widget:tabHandler()
end

function Widget:deleteHandler()
end

function Widget:backSpaceHandler()
end

function Widget:returnHandler()
end

function Widget:arrowUpHandler()
end

function Widget:arrowDownHandler()
end

function Widget:arrowLeftHandler()
end

function Widget:arrowRightHandler()
end

--------------------------------------------------------------------- Button widget

Button = class(Widget)

function Button:init(view, x, y, w, h, hConstraint, vConstraint, default, command, shortcut)
    Widget.init(self, view, x, y, w, h, hConstraint, vConstraint)
    -- Button configuration
    self.acceptsFocus   = true
    self.acceptsBackspace = false
    self.command        = command or function() end      -- what to do when pressed
    self.default        = default        -- is default button when ENTER is pressed
    self.shortcut        = shortcut
    -- Current button state
    self.clicked        = false
    self.highlighted    = false
    self.acceptsEnter	= true
end

-- Act on key press on button
function Button:enterHandler()
    if self.acceptsEnter then
	self:command()
    end
end

function Button:escapeHandler()
    if self.acceptsEscape then
	self:command()
    end
end

function Button:tabHandler()
    if self.acceptsTab then
	self:command()
    end
end

function Button:deleteHandler()
    if self.acceptsDelete then
	self:command()
    end
end

function Button:backSpaceHandler()
    if self.acceptsBackSpace then
	self:command()
    end
end

function Button:returnHandler()
    if self.acceptsReturn then
	self:command()
    end
end

function Button:arrowUpHandler()
    if self.acceptsArrowUp then
	self:command()
    end
end

function Button:arrowDownHandler()
    if self.acceptsArrowDown then
	self:command()
    end
end

function Button:arrowLeftHandler()
    if self.acceptsArrowLeft then
	self:command()
    end
end

function Button:arrowRightHandler()
    if self.acceptsArrowRight then
	self:command()
    end
end

function Button:arrowUpHandler()
    if self.acceptsArrowUp then
	self:command()
    end
end

function Button:arrowDownHandler()
    if self.acceptsArrowDown then
	self:command()
    end
end

function Button:onMouseDown(x, y)
    self.clicked     = true
    self.highlighted = true
end

function Button:onMouseEnter(x, y)
    theView:setCursor("hand pointer")
    if self.clicked and not self.highlighted then
        self.highlighted = true
    end
end

function Button:onMouseLeave(x, y)
    theView:setCursor("default")
    if self.clicked and self.highlighted then
        self.highlighted = false
    end
end

function Button:cancelClick()
    if self.clicked then
        self.highlighted = false
        self.clicked     = false
    end
end

function Button:onMouseUp(x, y)
	self:cancelClick()
        self:command()
end

function Button:addString(str)
    if str == " " or str == self.shortcut then
        self:command()
	return true
    end
    return false
end

--------------------------------------------------------------------- ImgButton widget

ImgButton = class(Button)

function ImgButton:init(view, x, y, hConstraint, vConstraint, img, command, shortcut)
    self.img = image.new(img)
    self.w = image.width(self.img)
    self.h = image.height(self.img)
    Button.init(self, view, x, y, self.w, self.h, hConstraint, vConstraint, false, command, shortcut)
end

function ImgButton:paint(gc, focused)
    gc:drawImage(self.img, self.x, self.y)
end 

--------------------------------------------------------------------- events handling

function on.arrowUp()
	if zCurr<#data-1 then
		zCurr=zCurr+1
		getInfos()
		setView()
		theView:invalidate()
	end
end

function on.arrowDown()
	if zCurr>0 then
		zCurr=zCurr-1
		getInfos()
		setView()
		theView:invalidate()
	end
end

function on.arrowLeft()
	if nCurr>0 then
		nCurr=nCurr-1
		getInfos()
		setView()
		theView:invalidate()
	end
end

function on.arrowRight()
	if nCurr<maxN then
		nCurr=nCurr+1
		getInfos()
		setView()
		theView:invalidate()
	end
end

function on.charIn(ch)
    theView:sendStringToFocus(ch)
end

function on.tabKey()
    theView:tabForward()
end

function on.backtabKey()
    theView:tabBackward()
end

function on.enterKey()
	theView:enterHandler()
end

function on.returnKey()
    on.enterKey()
end

function on.mouseMove(x, y)
    theView:onMouseMove(x, y)
end

function on.mouseDown(x, y)
    theView:onMouseDown(x, y)
    if theView.currentFocus==0 then
	if y<=maxY then
		nCurr = math.floor((x-xDelta)/zoom)
		zCurr = math.floor((maxY-y+yDelta)/zoom)
		getInfos()
		setView()
		theView:invalidate()
	end
    end
end

function on.mouseUp(x, y)
    theView:onMouseUp(x, y)
end

function on.resize()
	local gc = platform.gc()
	gc:begin()
	gc:setFont("serif","r",6)
	scrWidth  = platform.window:width()
	scrHeight = platform.window:height()
	maxX=scrWidth-1
	strFullHeight=gc:getStringHeight("H")
	strHeight=strFullHeight-3
	maxY=scrHeight-4*strHeight-1
	zoomMax = 3*strHeight+12
	if not inited and (scrWidth>0 or scrHeight>0) then
		theView = View(platform.window)
		zoom = 2*strHeight+12
		upLeftButton = ImgButton(theView, 2, 2, "left", "top", "\014\000\000\000\014\000\000\000\000\000\000\000\028\000\000\000\016\000\001\000\255\255\255\255\255\255\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\000\000\255\255\000\128Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\000\000\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\255\255\000\000\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\255\255\000\000\000\000\000\000\255\255\000\128\000\128Z\235Z\235Z\235\000\128\000\128\255\255\255\255\000\000\000\000\000\000\000\000\255\255\255\255\000\128Z\235Z\235\000\128\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128\000\128\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000", function() moveView(-zoom,-zoom) end)
		upButton = ImgButton(theView, 0, 2, "center", "top", "\013\000\000\000\013\000\000\000\000\000\000\000\026\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128Z\235\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128Z\235\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128Z\235Z\235Z\235\000\128\255\255\255\255\000\000\000\000\000\000\000\000\255\255\000\128\000\128Z\235Z\235Z\235\000\128\000\128\255\255\000\000\000\000\000\000\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\000\000\000\000\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\000\000\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\255\255\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255", function() moveView(0,-zoom) end)
		upRightButton = ImgButton(theView, 2, 2, "right", "top", "\014\000\000\000\014\000\000\000\000\000\000\000\028\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128\000\128\255\255\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235\000\128\255\255\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235\000\128\255\255\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\255\255\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\000\000\000\000\255\255\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\000\000\000\000\000\000\255\255\255\255\000\128\000\128Z\235Z\235Z\235\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\000\128Z\235Z\235\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\000\128\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\000\000\000\000\000\000\000", function() moveView(zoom,-zoom) end)
		leftButton = ImgButton(theView, 2, maxY-scrHeight, "left", "middle", "\013\000\000\000\013\000\000\000\000\000\000\000\026\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128\000\128\255\255\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235\000\128\255\255\000\000\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235\000\128\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235\000\128\255\255\000\000\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235\000\128\255\255\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235\000\128\255\255\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\255\255", function() moveView(-zoom,0) end)
		rightButton = ImgButton(theView, 2, maxY-scrHeight, "right", "middle", "\013\000\000\000\013\000\000\000\000\000\000\000\026\000\000\000\016\000\001\000\255\255\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\255\255\000\128Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\255\255\000\128Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\000\255\255\000\128Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\128Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\000\255\255\000\128Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\255\255\000\128\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", function() moveView(zoom,0) end)
		downLeftButton = ImgButton(theView, 2, 2+scrHeight-maxY, "left", "bottom", "\014\000\000\000\014\000\000\000\000\000\000\000\028\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128\000\128\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128Z\235Z\235\000\128\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128Z\235Z\235Z\235\000\128\000\128\255\255\255\255\000\000\000\000\000\000\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\255\255\000\000\000\000\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\255\255\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\255\255\000\128Z\235Z\235Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\255\255\000\128Z\235Z\235\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\000\000\255\255\000\128\000\128\000\128\000\128\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000", function() moveView(-zoom,zoom) end)
		downButton = ImgButton(theView, 0, 2+scrHeight-maxY, "center", "bottom", "\013\000\000\000\013\000\000\000\000\000\000\000\026\000\000\000\016\000\001\000\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\000\128\255\255\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\000\000\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\000\000\000\000\255\255\255\255\000\128Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\000\000\000\000\000\000\255\255\000\128\000\128Z\235Z\235Z\235\000\128\000\128\255\255\000\000\000\000\000\000\000\000\255\255\255\255\000\128Z\235Z\235Z\235\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128Z\235\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128Z\235\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\000\128\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000", function() moveView(0,zoom) end)
		downRightButton = ImgButton(theView, 2, 2+scrHeight-maxY, "right", "bottom", "\014\000\000\000\014\000\000\000\000\000\000\000\028\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\000\128\255\255\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\000\128\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\000\128\000\128Z\235Z\235\000\128\255\255\255\255\000\000\000\000\000\000\000\000\255\255\255\255\000\128\000\128Z\235Z\235Z\235\000\128\000\128\255\255\000\000\000\000\000\000\255\255\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\000\000\255\255\255\255\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\000\000\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235Z\235Z\235Z\235\000\128\255\255\255\255\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235Z\235\000\128\000\128\255\255\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235Z\235Z\235\000\128\255\255\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128Z\235Z\235\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\000\128\000\128\000\128\000\128\255\255\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\255\255\255\255\255\255\255\255\255\255\255\255", function() moveView(zoom,zoom) end)
		zoomOutButton = ImgButton(theView, 2, 2, "right", "bottom", "\016\000\000\000\016\000\000\000\000\000\000\000 \000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\255\255\255\255\255\255\255\255\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\128\255\255\255\255\000\128\000\128\000\128\000\128\000\128\000\128\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\128\255\255\255\255\000\128\000\128\000\128\000\128\000\128\000\128\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\255\255\255\255\255\255\255\255\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\000\000\000\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\000", function() zoomOut() end, "-")
		zoomInButton = ImgButton(theView, 2+zoomOutButton.w+3, 2,"right","bottom", "\016\000\000\000\016\000\000\000\000\000\000\000 \000\000\000\016\000\001\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\255\255\255\255\255\255\255\255\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\000\128\000\128\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\000\128\000\128\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\128\255\255\255\255\000\128\000\128\000\128\000\128\000\128\000\128\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\128\255\255\255\255\000\128\000\128\000\128\000\128\000\128\000\128\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\000\128\000\128\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\000\128\000\128\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\128\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\255\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\255\255\255\255\255\255\255\255\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\000\000\000\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\000", function() zoomIn() end, "+")
		radioButton = ImgButton(theView, 2+zoomInButton.w+3+zoomOutButton.w+3, 2, "right", "bottom", "\017\000\000\000\016\000\000\000\000\000\000\000\034\000\000\000\016\000\001\000\000\000\000\000\000\000\000\000{\239\206\185\165\148!\132!\132!\132\165\148\206\185{\239\000\000\000\000\000\000\000\000\000\000\000\000\000\000{\239!\132\000\128\000\128\000\128\000\128\000\128\000\128\000\128!\132{\239\000\000\000\000\000\000\000\000\000\000\000\000\000\000\239\189\000\128\000\128\000\128\000\128\000\128\000\128\000\128\239\189\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\132\144\000\128\000\128\000\128\000\128\000\128\132\144\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\181\214\000\128\000\128\000\128\000\128\000\128\181\214\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\008\161\000\128\000\128\000\128\008\161\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\008\161!\132\140\177\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\000\128\000\000B\136\000\128B\136\000\000\000\128\000\128\000\128\000\128\000\128\000\128B\136\000\128\000\128\000\128\000\128\000\128\000\000R\202!\132\016\194\000\000\000\128\000\128\000\128\000\128\000\128B\136\165\148\000\128\000\128\000\128\000\128\000\128\000\000\000\000\000\000\000\000\000\000\000\128\000\128\000\128\000\128\000\128\165\148\173\181\000\128\000\128\000\128\000\128\000\128\000\128)\165\000\000)\165\000\128\000\128\000\128\000\128\000\128\000\128\173\181\024\227\000\128\000\128\000\128\000\128\000\128B\136\156\243\000\000\156\243B\136\000\128\000\128\000\128\000\128\000\128\024\227\000\000\231\156\000\128\000\128\000\128\000\128\181\214\000\000\000\000\000\000\181\214\000\128\000\128\000\128\000\128\231\156\000\000\000\0009\231!\132\000\128\000\128k\173\000\000\000\000\000\000\000\000\000\000k\173\000\128\000\128!\1329\231\000\000\000\000\000\000\148\210\000\128c\140\222\251\000\000\000\000\000\000\000\000\000\000\222\251c\140\000\128\148\210\000\000\000\000", function() desintegrate() end)
		theView:add(radioButton)
		theView:add(zoomInButton)
		theView:add(zoomOutButton)
		theView:add(upLeftButton)
		theView:add(upButton)
		theView:add(upRightButton)
		theView:add(leftButton)
		theView:add(rightButton)
		theView:add(downLeftButton)
		theView:add(downButton)
		theView:add(downRightButton)
		setView()
		setLanguage(locale:name())
		timer.start(1)
		inited = true
	end
	if inited then
		local posrdelta = gc:getStringWidth("2"..beta..sup_plus)+strHeight-1
		local w = gc:getStringWidth(langtable[lang][2])+strHeight-1
		local w2 = gc:getStringWidth(langtable[lang][1])+strHeight-1
		local w3 = gc:getStringWidth(langtable[lang][3])+strHeight-1
		local w4 = gc:getStringWidth(langtable[lang][4])+strHeight-1
		gc:finish()
		theView:resize()
		posr1= scrWidth-posrdelta
		posr2= posr1-posrdelta
		posr3= posr2-posrdelta
		posr4= posr3-posrdelta
		posr5= posr4-posrdelta
		if posr5-w2<posr4-w then
			posr5=posr3
		end
		posr6 = math.min(posr5-w2,math.min(posr4-w4,radioButton.x-w3))
		if posr5==posr3 then
			posr6=math.min(posr6,posr5-w)
		else
			posr6=math.min(posr6,radioButton.x-w)
		end
		setView()
		theView:invalidate()
	end
end

function on.timer()
	if setLanguage(locale:name()) then
		on.resize()
	end
end

function on.paint(gc)
    if inited then
	gc:setFont("serif","r",6)
	gc:setColorRGB(0,0,0)
	local n=0
	local z=-1
	local t
	local symb
	for i=1,#data do
	    z=data[i][3]
	    if maxY+yDelta-z*zoom<minY then
		    break
	    end
	    for j=1,#data[i][4] do
		t = data[i][4][j][2]
		n = data[i][4][j][1]
		if t ~= -2 and xDelta+(n+1)*zoom-1>=0 and xDelta+n*zoom<=scrWidth-1 and maxY+yDelta-(z+1)*zoom+1<=maxY and maxY+yDelta-z*zoom>=0 then
			setTypeColor(gc,t)
			gc:fillRect(xDelta+n*zoom+getLeftTopBorder()+getLeftTopSpacer(),maxY+yDelta-(z+1)*zoom+getLeftTopBorder()+getLeftTopSpacer()+1,zoom-getLeftTopBorder()-getRightBottomBorder()-getLeftTopSpacer()-getRightBottomSpacer(),zoom-getLeftTopBorder()-getRightBottomBorder()-getLeftTopSpacer()-getRightBottomSpacer())
			if zoom>=3 then
				gc:setColorRGB(0,0,0)
				if zoom<=4 then
					gc:drawRect(xDelta+n*zoom+getLeftTopSpacer(),maxY+yDelta-(z+1)*zoom+getLeftTopSpacer()+1,zoom-getLeftTopSpacer()-getRightBottomSpacer(),zoom-getLeftTopSpacer()-getRightBottomSpacer())
				elseif zoom<=16 then
					gc:drawRect(xDelta+n*zoom+getLeftTopSpacer(),maxY+yDelta-(z+1)*zoom+getLeftTopSpacer()+1,zoom-getLeftTopSpacer()-getRightBottomSpacer()-1,zoom-getLeftTopSpacer()-getRightBottomSpacer()-1)
				else
					gc:drawRect(xDelta+n*zoom+getLeftTopSpacer()+1,maxY+yDelta-(z+1)*zoom+getLeftTopSpacer()+1,zoom-getLeftTopSpacer()-getRightBottomSpacer()-3,zoom-getLeftTopSpacer()-getRightBottomSpacer()-1)
					gc:drawRect(xDelta+n*zoom+getLeftTopSpacer(),maxY+yDelta-(z+1)*zoom+getLeftTopSpacer()+2,zoom-getLeftTopSpacer()-getRightBottomSpacer()-1,zoom-getLeftTopSpacer()-getRightBottomSpacer()-3)
				end
				if zoom-getLeftTopSpacer()-getLeftTopBorder()-getRightBottomBorder()-getRightBottomSpacer()-2>=strHeight-1 then
					if t==0 then
						gc:setColorRGB(255,255,255)
					end
					drawIsotope(gc, xDelta+n*zoom+getLeftTopSpacer()+getLeftTopBorder()+1, maxY+yDelta-(z+1)*zoom+getLeftTopSpacer()+getLeftTopBorder()+2, zoom-getLeftTopSpacer()-getLeftTopBorder()-getRightBottomBorder()-getRightBottomSpacer()-2, zoom-getLeftTopSpacer()-getLeftTopBorder()-getRightBottomBorder()-getRightBottomSpacer()-2, data[i][1], z, n)
					gc:setColorRGB(0,0,0)
				end
			end
		end
	    end
	end
	n = nCurr
	z = zCurr
	t = type
	x1 = xDelta+(n+0.5)*zoom
	y1 = maxY+yDelta-(z+0.5)*zoom+1
	gc:setColorRGB(255,0,0)
	local nextNZ
	local isotopeInfo
	while t>0 and t~=5 and t~=4 do
		nextNZ = getNextNZ(z,n,t)
		z = nextNZ[1]	
		n = nextNZ[2]
		enlightIsotope(gc,z,n,0)
		x2=xDelta+(n+0.5)*zoom
		y2 = maxY+yDelta-(z+0.5)*zoom+1
		gc:drawLine(x1,y1,x2,y2)
		x1=x2
		y1=y2
		isotopeInfos = getIsotopeInfos(z,n)
		t = isotopeInfos[5]
	end
	local sepw = math.max(gc:getStringWidth("+"),gc:getStringWidth(right_arrow))
	local pos1=gc:getStringWidth("N=144")+3
	local pos2=pos1+2+3*strHeight
	local pos3=pos2+sepw
	local pos4=pos3+3*strHeight
	local pos4b=pos4+sepw+1
	local pos5=pos4b+sepw+gc:getStringWidth("4")
	gc:setColorRGB(191,191,191)
	gc:fillRect(0,maxY+1,pos1,scrHeight-1-maxY-strHeight)
	gc:setColorRGB(255,255,255)
	gc:fillRect(posr6-1,maxY+1,scrWidth-posr6+1,scrHeight-1-maxY)
	gc:setColorRGB(0,0,0)
	gc:drawLine(0,maxY+1,scrWidth-1,maxY+1)
	if posr6-pos1-1>0 and scrHeight-1-maxY>0 then
		gc:fillRect(pos1,maxY+1,posr6-pos1-1,scrHeight-1-maxY-strHeight)
	end
	gc:drawLine(0,scrHeight-1-strHeight+1,posr6-2,scrHeight-1-strHeight+1)
	gc:drawLine(posr6-2,scrHeight-1,posr6-2,scrHeight-1-strHeight+2)
	gc:setColorRGB(255,255,0)
	gc:fillRect(0,scrHeight-1-strHeight+2,posr6-2,strHeight-1)
	gc:setColorRGB(0,0,0)
	local pos12=gc:getStringWidth("N")+2
	gc:drawString("A",1,maxY+2 - strFullHeight+strHeight,"top")
	gc:drawString("N",1,maxY+2+strHeight - strFullHeight+strHeight,"top")
	gc:drawString("Z",1,maxY+2+2*strHeight - strFullHeight+strHeight,"top")
	gc:drawString("="..(nCurr+zCurr),pos12,maxY+2 - strFullHeight+strHeight,"top")
	gc:drawString("="..nCurr,pos12,maxY+2+strHeight - strFullHeight+strHeight,"top")
	gc:drawString("="..zCurr,pos12,maxY+2+2*strHeight - strFullHeight+strHeight,"top")
	gc:drawString("X. Andr"..e_acute.."ani, NUBASE 28.4.2011",1,maxY+2+3*strHeight+strHeight-strFullHeight,"top")

	if type~=-2 then
		if type~=0 then
			setTypeColor(gc, type)
		else
			gc:setColorRGB(255,255,255)
		end
		drawIsotope(gc, pos1+1, maxY+2, 3*strHeight, 3*strHeight,symbol, zCurr, nCurr)
		if zNext~=zCurr or nNext~=nCurr then
			gc:setColorRGB(255,255,255)
			local pos = pos2
			if type==12 then
				pos = pos4
			end
			gc:drawString(right_arrow,pos,maxY+2+strHeight - strFullHeight+strHeight,"top")
			pos = pos4
			if type==12 then
				pos = pos2
			end				
			gc:drawString("+",pos,maxY+2+strHeight - strFullHeight+strHeight,"top")
			if typeNext~=0 then
				setTypeColor(gc, typeNext)
			else
				gc:setColorRGB(255,255,255)
			end
			pos = pos3
			if type==12 then
				pos = pos5
			end
			drawIsotope(gc, pos, maxY+2, 3*strHeight, 3*strHeight,symbNext, zNext, nNext)
			gc:setColorRGB(255,255,255)
			local nbr=1
			if nCurr+zCurr==nNext+zNext then
				symb="e"
				nbr = math.abs(zCurr-zNext)
			elseif nNext==nCurr then
				symb="p"
				nbr = zCurr-zNext
			elseif zNext==zCurr then
				symb="n"
				nbr = nCurr-nNext
			else
				symb="He"
				nbr=(zCurr-zNext)/2
			end
			if nbr~=1 then
				gc:drawString(nbr,pos4b,maxY+2*strHeight)
			end
			pos = pos5
			local zDelta = zCurr-zNext
			local nDelta = nCurr-nNext
			if type==12 then
				pos = pos3
				zDelta = -zDelta
				nDelta = -nDelta
			end
			drawIsotope(gc, pos, maxY+2, 3*strHeight, 3*strHeight,symb, zDelta/nbr, nDelta/nbr)
		end
	end
	gc:setColorRGB(255,0,0)
	enlightIsotope(gc,zCurr,nCurr,1)
	drawLegend(gc,posr1,maxY+2,6)
	drawLegend(gc,posr2,maxY+2,7)
	drawLegend(gc,posr3,maxY+2,1)
	drawLegend(gc,posr4,maxY+2,2)
	if posr5==posr3 then
		drawLegend(gc,posr5,maxY+2+2*strHeight,3)
	else
		drawLegend(gc,posr5,maxY+2,3)
	end
	drawLegend(gc,posr6,maxY+2,0)
	drawLegend(gc,posr1,maxY+2+strHeight,9)
	drawLegend(gc,posr2,maxY+2+strHeight,8)
	drawLegend(gc,posr3,maxY+2+strHeight,11)
	drawLegend(gc,posr4,maxY+2+strHeight,10)
	drawLegend(gc,posr6,maxY+2+strHeight,-1)
	drawLegend(gc,posr6,maxY+2+2*strHeight,5)
	drawLegend(gc,posr6,maxY+2+3*strHeight,12)
	theView:paint(gc)
    end
end

--------------------------------------------------------------------- global variables

-- special characters
a_acute = string.uchar(225)
a_circ  = string.uchar(226)
a_tilde = string.uchar(227)
a_diaer = string.uchar(228)
a_ring  = string.uchar(229)
e_acute = string.uchar(233)
o_acute = string.uchar(243)
o_circ  = string.uchar(244)
alpha = string.uchar(945)
beta= string.uchar(946)
sup_plus = string.uchar(8314)
sup_minus = string.uchar(8315)
right_arrow = string.uchar(8594)
chinese_21457 = string.uchar(21457)
chinese_21464 = string.uchar(21464)
chinese_23376 = string.uchar(23376)
chinese_23450 = string.uchar(23450)
chinese_25429 = string.uchar(25429)
chinese_26410 = string.uchar(26410)
chinese_29554 = string.uchar(29554)
chinese_30005 = string.uchar(30005)
chinese_30332 = string.uchar(30332)
chinese_30340 = string.uchar(30340)
chinese_30693 = string.uchar(30693)
chinese_31283 = string.uchar(31283)
chinese_31337 = string.uchar(31337)
chinese_33258 = string.uchar(33258)
chinese_33719 = string.uchar(33719)
chinese_35010 = string.uchar(35010)
chinese_35722 = string.uchar(35722)
chinese_38651 = string.uchar(38651)

lang = ""

--------------------------------------------------------------------- messages

-- locales
-- fr		Francais French
-- en / en_GB	Anglais English
-- de		Allemand German Deutsch
-- da		Danois Danish
-- es		Espagnol Spanish
-- it		Italien Italian
-- nl		Neerlandais Dutch
-- nl_BE	Flamand Flemish
-- no		Norvegien Norske Norwegian
-- pt		Portugais Portuguese
-- fi		Finnois Finnish Suomi
-- sv		Suedois Swedish Svenska
-- zh_CN	Simplified chinese
-- zh_TW	Chinese traditional

langtable =
{
  da = {"stabilt",		"spontan fission",				"elektron capture",			"ukendt"},
  de = {"stabil",		"spontane Spaltung",				"Elektroneneinfang",			"unbekannt"},
  fi = {"vakaa",		"spontaanin fission",				"elektronin sieppaus",			"tuntematon"},
  fr = {"stable",		"fission spontan"..e_acute.."e",		"capture "..e_acute.."lectronique",	"inconnu"},
  en = {"stable",		"spontaneous fission",				"electronic capture",			"unknown"},
  es = {"estable",		"fisi"..o_acute.."n espont"..a_acute.."nea",	"captura electr"..o_acute.."nica",	"desconocido"},
  it = {"stabile",		"fissione spontanea",				"cattura elettronica",			"ok"..a_diaer.."nda"},
  nl = {"stabiel",		"spontane splijting",				"elektronenvangst",			"onbekende"},
  no = {"stabil",		"spontan fisjon",				"elektron fange",			"ukjent"},
  pt = {"est"..a_acute.."vel",	"fiss"..a_tilde.."o espont"..a_circ.."nea",	"captura eletr"..o_circ.."nica",	"desconhecido"},
  sv = {"stabil",		"spontan fission",				"elektroninf"..a_ring.."ngning",	"ok"..a_diaer.."nda"},
  zh_CN = {chinese_31283..chinese_23450..chinese_30340,chinese_33258..chinese_21457..chinese_35010..chinese_21464,chinese_30005..chinese_23376..chinese_25429..chinese_33719,chinese_26410..chinese_30693..chinese_30340},
  zh_TW = {chinese_31337..chinese_23450..chinese_30340,chinese_33258..chinese_30332..chinese_35010..chinese_35722,chinese_38651..chinese_23376..chinese_25429..chinese_29554,chinese_26410..chinese_30693..chinese_30340}
}

symbol = ""
symbNext = ""
type = -2
nCurr=0
zCurr=1
nNext=1
zNext=0
typeNext = -2
xDelta=0
yDelta=0
zoomInButton = nil
zoomOutButton = nil
leftButton = nil
rightButton = nil
upButton = nil
downButton = nil
downLeftButton = nil
downRightButton = nil
radioButton = nil
scrWidth = 0
scrHeight = 0
inited = false

zoom = 1
zoomMax = 1
-- 1	-> fond(1)						1-0=1
-- 2	-> fond(2)						2-0=2
-- 3	-> fond(2) + demi-bordure(1)				3-1=2
-- 4	-> fond(3) + demi-bordure(1)				4-1=3
-- 5	-> fond(4) + full-bordure(2)				5-2=3
-- 6	-> fond(4) + full-bordure(2)				6-2=4
-- 8	-> fond(5) + full-bordure(2) + demi-espace(1)		8-3=5
-- 9	-> fond(5) + full-bordure(2) + full-espace(2)		9-4=5
-- 10	-> fond(6) + full-bordure(2) + full-espace(2)		10-4=6
-- 11	-> fond(7) + full-bordure(2) + full-espace(2)		11-4=7
-- 12	-> fond(8) + full-bordure(2) + full-espace(2)		12-4=8
-- 13	-> fond(7) + full-bordure(2) + bbig-espace(4)		13-6=7
-- 14	-> fond(8) + full-bordure(2) + bbig-espace(4)		14-6=8
-- 15	-> fond(9) + full-bordure(2) + bbig-espace(4)		15-6=9
-- 16	-> fond(10) + full-bordure(2) + bbig-espace(4)		16-6=10
-- 17	-> fond(9) + bbig-bordure(4) + bbig-espace(4)		17-8=9
-- 18	-> fond(10) + bbig-bordure(4) + bbig-espace(4)		18-8=10
-- 19	-> fond(11) + bbig-bordure(4) + bbig-espace(4)		19-8=11
-- 20	-> fond(12) + bbig-bordure(4) + bbig-espace(4)		20-8=12
-- 21-	-> fond(11) + vbbig-bordure(6) + bbig-espace(4)		21-10=11


minY=0
maxY=0
minX=0
maxX=0
strHeight=0
strFullHeight=0
posr1=0
posr2=0
posr3=0
posr4=0
posr5=0

--------------------------------------------------------------------- global functions

function setLanguage(code)
	if code~=lang then
		if not langtable[code] then
			code = string.sub(code,1,2)
		end
		if langtable[code] then
			lang = code
			typeStr[1]=langtable[lang][4]
			typeStr[2]=langtable[lang][1]
			typeStr[7]=langtable[lang][2]
			typeStr[14]=langtable[lang][3]
			return true
		else
			return setLanguage("en")
		end
	end
	return false
end

function desintegrate()
	if (zNext~=zCurr or nNext~=nCurr) then
	    zCurr = zNext
	    nCurr = nNext
	    getInfos()
	    setView()
	    theView:invalidate()
	end
end

function getIsotopeInfos(z,n)
	if n<0 or z<0 or z>#data+1 then
		return { "?", "", z, n, -2}
	end
	local elementData = data[z+1]
	local t = -2
	for i=1,#elementData[4] do
		if elementData[4][i][1]==n then
			t = elementData[4][i][2]
			break
		end
	end
	return { elementData[1], elementData[2], z, n, t }
end

function getNextNZ(z,n,t)
	if t==1 or t==12 then
		n = n+1
		z = z-1
	elseif t==2 then
		n = n-1
		z = z+1
	elseif t==3 then
		n = n-2
		z = z-2
	elseif t==6 then
		z = z-1
	elseif t==7 then
		n = n-1
	elseif t==8 then
		n = n-2
	elseif t==9 then
		z = z-2
	elseif t==10 then
		n = n-2
		z = z+2
	elseif t==11 then
		n = n+2
		z = z-2
	end
	return {z,n}
end

function getInfos()
	local isotopeData = getIsotopeInfos(zCurr,nCurr)
	symbol = isotopeData[1]
	type = isotopeData[5]

	local nextNZ = getNextNZ(zCurr,nCurr,type)
	zNext = nextNZ[1]
	nNext = nextNZ[2]
	isotopeData = getIsotopeInfos(zNext,nNext)
	symbNext = isotopeData[1]
	typeNext = isotopeData[5]
end

function setTypeColor(gc, t)
	if t==0 then
		gc:setColorRGB(0,0,0)
	elseif t==1 then
		gc:setColorRGB(255,207,0)
	elseif t==2 then
		gc:setColorRGB(0,255,0)
	elseif t==3 then
		gc:setColorRGB(255,255,0)
	elseif t==4 then
		gc:setColorRGB(0,0,191)
	elseif t==5 then
		gc:setColorRGB(191,191,191)
	elseif t==6 then
		gc:setColorRGB(0,255,255)
	elseif t==7 then
		gc:setColorRGB(255,0,255)
	elseif t==8 then
		gc:setColorRGB(191,0,191)
	elseif t==9 then
		gc:setColorRGB(0,191,191)
	elseif t==10 then
		gc:setColorRGB(0,191,0)
	elseif t==11 then
		gc:setColorRGB(207,143,0)
	elseif t==12 then
		gc:setColorRGB(175,95,0)
	elseif t==-1 then
		gc:setColorRGB(255,255,255)
	end
end

typeStr = {"", "", beta..sup_plus, beta..sup_minus, alpha, "", "", "p", "n","2n","2p","2"..beta..sup_minus,"2"..beta..sup_plus,""}

function drawLegend(gc,x,y,t)
	local str = typeStr[t+2]
	setTypeColor(gc,t)
	gc:fillRect(x,y+1,strHeight-4,strHeight-4)
	gc:setColorRGB(0,0,0)
	gc:drawRect(x,y+1,strHeight-4,strHeight-4)
	gc:drawString(str,x+strHeight-2,y+strHeight-strFullHeight,"top")
end

function getLeftTopBorder()
	if zoom<=2 then
		return 0
	elseif zoom<=16 then
		return 1
	else
		return 2
	end
end

function getRightBottomBorder()
	if zoom<=4 then
		return 0
	elseif zoom<=16 then
		return 1
	else
		return 2
	end
end

function getLeftTopSpacer()
	if zoom<=6 then
		return 0
	elseif zoom<=12 then
		return 1
	elseif zoom<=20 then
		return 2
	else
		return 3
	end
end

function getRightBottomSpacer()
	if zoom<=8 then
		return 0
	elseif zoom<=12 then
		return 1
	elseif zoom<=20 then
		return 2
	else
		return 3
	end
end

function getContentSize()
	local size = zoom-getLeftTopBorder()-getRightBottomBorder()
	if zoom>=7 and zoom<=8 then
		size=size-1
	elseif zoom>=9 and zoom<=12 then
		size=size-2
	elseif zoom>=13 then
		size=size-4
	end
	return size
end

function zoomIn()
	if zoom<zoomMax then
		zoom = zoom + 1
		setCenteredView()
		theView:invalidate()
	end
end

function zoomOut()
	if zoom>1 then
		zoom = zoom - 1
		setCenteredView()
		theView:invalidate()
	end
end

getInfos()

function setCenteredView()
	xDelta = -(nCurr+1)*zoom+math.ceil((scrWidth+zoom)/zoom/2)*zoom
	yDelta = (zCurr+1)*zoom-math.floor((maxY+1+zoom)/zoom/2)*zoom-1
	setView()
end

function moveView(dx,dy)
	if dx~=0 or dy~=0 then
		xDelta = xDelta-dx
		yDelta = yDelta-dy
	end
	validateView()
	theView:invalidate()
end

function setView()
	if (nCurr+1)*zoom+xDelta>scrWidth then
		xDelta=scrWidth-(nCurr+1)*zoom
	end
	if nCurr*zoom+xDelta<0 then
		xDelta = -nCurr*zoom
	end
	if maxY+yDelta-(zCurr+1)*zoom+1<0 then
		yDelta=(zCurr+1)*zoom-1-maxY
	end
--	while yDelta>zCurr*zoom do
--		yDelta = yDelta-zoom
--	end
	if yDelta>zCurr*zoom then
		yDelta = zCurr*zoom
	end
	validateView()
end

function validateView()
	if xDelta<-(maxN+1)*zoom+scrWidth then
		xDelta = -(maxN+1)*zoom+scrWidth
	end
	if xDelta>0 then
		xDelta = 0
	end
	if yDelta>#data*zoom-maxY-1 then
		yDelta = #data*zoom-maxY-1
	end
	if yDelta<0 then
		yDelta = 0
	end
	if yDelta<=0 then
		theView:hide(downButton)
		theView:hide(downLeftButton)
		theView:hide(downRightButton)
	else
		theView:show(downButton)
	end
	if yDelta>=#data*zoom-maxY-1 then
		theView:hide(upButton)
		theView:hide(upLeftButton)
		theView:hide(upRightButton)
	else
		theView:show(upButton)
	end
	if xDelta>=0 then
		theView:hide(leftButton)
		theView:hide(downLeftButton)
		theView:hide(upLeftButton)
	else
		theView:show(leftButton)
		if yDelta>0 then
			theView:show(downLeftButton)
		end
		if yDelta<#data*zoom-maxY-1 then
			theView:show(upLeftButton)
		end
	end
	if xDelta<=-(maxN+1)*zoom+scrWidth then
		theView:hide(rightButton)
		theView:hide(upRightButton)
		theView:hide(downRightButton)
	else
		theView:show(rightButton)
		if yDelta>0 then
			theView:show(downRightButton)
		end
		if yDelta<#data*zoom-maxY-1 then
			theView:show(upRightButton)
		end

	end
end

function drawIsotope(gc, x, y, w, h, symb, z, n)
	local symbolWidth = gc:getStringWidth(symb)
	local aWidth = gc:getStringWidth(z+n)
	local zWidth = gc:getStringWidth(z)
	y = y - strFullHeight+strHeight
	if symbolWidth+aWidth<=w and h>=3*strHeight then
		gc:drawString(z+n,x+math.floor((w-symbolWidth-aWidth)/2),y+(h-3*strHeight)/2,"top")
		gc:drawString(symb,x+aWidth+math.floor((w-symbolWidth-aWidth)/2),y+strHeight+(h-3*strHeight)/2,"top")
		gc:drawString(z,x+aWidth-zWidth+math.floor((w-symbolWidth-aWidth)/2),y+2*strHeight+(h-3*strHeight)/2,"top")
	elseif symbolWidth<=w and aWidth<=w and h>=3*strHeight then
		gc:drawString(z+n,x,y+(h-3*strHeight)/2,"top")
		gc:drawString(symb,x+w-symbolWidth-1,y+strHeight+(h-3*strHeight)/2,"top")
		gc:drawString(z,x+aWidth-zWidth,y+2*strHeight+(h-3*strHeight)/2,"top")
	elseif symbolWidth+aWidth<=w and h>=2*strHeight then
		gc:drawString(z+n,x+math.floor((w-symbolWidth-aWidth)/2),y+math.ceil((h-2*strHeight)/2),"top")
		gc:drawString(symb,x+aWidth+math.floor((w-symbolWidth-aWidth)/2),y+strHeight+math.ceil((h-2*strHeight)/2),"top")
	elseif symbolWidth<=w and aWidth<=w and h>=2*strHeight then
		gc:drawString(z+n,x,y+math.ceil((h-2*strHeight)/2),"top")
		gc:drawString(symb,x+w-symbolWidth-1,y+strHeight+math.ceil((h-2*strHeight)/2),"top")
	elseif symbolWidth<=w and h>=strHeight then
		gc:drawString(symb,x+math.floor((w-symbolWidth)/2),y+math.ceil((h-strHeight)/2),"top")
	end
end

function enlightIsotope(gc,z,n,s)
	if zoom>=3 and zoom<=4 or zoom>=7 and zoom<=8 then
		if s==0 then
		        gc:setPen("thin", "dotted")
		end
		gc:drawRect(xDelta+n*zoom,maxY+yDelta-(z+1)*zoom+1,zoom,zoom)
		if s==0 then
		        gc:setPen("thin", "smooth")
		end
	else
		if s~=0 then
			gc:drawRect(xDelta+n*zoom,maxY+yDelta-(z+1)*zoom+1,zoom-1,zoom-1)
			if zoom>=13 then
				gc:drawRect(xDelta+n*zoom+1,maxY+yDelta-(z+1)*zoom+1+1,zoom-3,zoom-3)
			end
		else
			if zoom>=13 then
				gc:drawRect(xDelta+n*zoom+1,maxY+yDelta-(z+1)*zoom+1+1,zoom-3,zoom-3)
			else
			        gc:setPen("thin", "dotted")
				gc:drawRect(xDelta+n*zoom,maxY+yDelta-(z+1)*zoom+1,zoom-1,zoom-1)
			        gc:setPen("thin", "smooth")
			end
		end
	end
end