Greasy Fork is available in English.

RatingR6 Full ver1.2 season 80

RatingRX, R6REC, RX VALUE, REREC(+b), Season TI, RVA's Captaincy, Trade Calculator , Hidden Skills Scout

// ==UserScript==
// @name           	RatingR6 Full ver1.2 season 80
// @version        	1.2
// @description    	RatingRX, R6REC, RX VALUE, REREC(+b), Season TI, RVA's Captaincy, Trade Calculator , Hidden Skills Scout
// @author			Metalist Dominia FC (Domenico Federico)
// @namespace		https://trophymanager.com/club/4052254/
// @include			https://trophymanager.com/players/*
// @include			https://fb.trophymanager.com/players/*
// @exclude			https://trophymanager.com/players/
// @exclude			https://fb.trophymanager.com/players/
// @exclude			https://trophymanager.com/players/compare/*
// @exclude			https://fb.trophymanager.com/players/compare/*
// ==/UserScript==

var version = "ver1.2 for Season80";

var youthID = 130173661;
var botID = 129826272;
var SS = new Date("04 13 2020 08:00:00 GMT"); // s63 start
var training1 = new Date("04 13 2020 23:00:00 GMT");  // first training
var wage_rate = 15.8079;

var removeID = 109000000;

//	R5 Captaincy(RVA) Custom Weights
//	Weights sum must be 1.0
var leadWeight2 = 0.5;	// Leadership
var profWeight2 = 0.25;	// Professhionalism
var rouWeight2 = 0.15;	// Routine
var aggrWeight2 = 0.1;	// Aggression

var testmode = 0;

// R5 weights   [Str, Sta, Pac, Mar, Tac, Wor, Pos, Pas, Cro, Tec, Hea, Fin, Lon, Set]
var weightR5 = [
    [0.5375, 0.00, 0.5925, 0.9500, 0.9206, 0.5274, 0.5825, 0.1313, 0.0656, 0.0937, 0.5282, 0.0491, 0.0216, 0.00], // DC
    [0.5140, 0.00, 0.6825, 0.8280, 0.8063, 0.5026, 0.5825, 0.1313, 0.2337, 0.1752, 0.4762, 0.0491, 0.0216, 0.00], // DL/R
    [0.4520, 0.00, 0.5683, 0.6864, 0.6727, 0.5780, 0.5720, 0.5105, 0.1095, 0.3504, 0.2850, 0.1050, 0.1102, 0.00], // DMC
    [0.4523, 0.00, 0.6666, 0.5765, 0.5499, 0.5327, 0.5120, 0.3255, 0.2949, 0.3226, 0.4547, 0.2230, 0.0893, 0.00], // DML/R
    [0.3291, 0.00, 0.4548, 0.3515, 0.3236, 0.5648, 0.5907, 0.6467, 0.0952, 0.6042, 0.2850, 0.5001, 0.2543, 0.00], // MC
    [0.2958, 0.00, 0.6709, 0.2840, 0.3039, 0.5042, 0.5420, 0.4126, 0.4244, 0.6020, 0.2580, 0.4501, 0.2521, 0.00], // ML/R
    [0.3363, 0.00, 0.4932, 0.2035, 0.1910, 0.5619, 0.5719, 0.6670, 0.0675, 0.6016, 0.4225, 0.6053, 0.2783, 0.00], // OMC
    [0.3585, 0.00, 0.6621, 0.1105, 0.1025, 0.5359, 0.5192, 0.3313, 0.4250, 0.6258, 0.4212, 0.6000, 0.3080, 0.00], // OML/R
    [0.4225, 0.00, 0.4500, 0.0003, 0.0002, 0.3845, 0.5015, 0.4050, 0.0010, 0.5825, 0.7000, 0.9500, 0.6025, 0.00], // F
    [0.35, 0.00, 0.35, 1.0, 0.6, 1.0, 0.5, 0.6, 0.3, 0.0, 0.3]]; // GK

var weightAssist = [
    [0.00189394, 0.09807900, 0.13636364, 0, 0, 0.09375000, 0.08996212, 0.30113636, 0.03449675, 0.24431818, 0, 0, 0, 0], // Shortpassing
    [0.00219024, 0.10090738, 0.22027534, 0, 0, 0.09590113, 0.09152065, 0.25438048, 0.08995620, 0.14486859, 0, 0, 0, 0], // Through balls
    [0.01562500, 0.09754464, 0.21071429, 0, 0, 0.09040179, 0.05915179, 0.18437500, 0.15691964, 0.18526786, 0, 0, 0, 0], // Wings
    [0.00223499, 0.11318646, 0.24010217, 0, 0, 0.08764368, 0.08317369, 0.25446999, 0.04070881, 0.17848020, 0, 0, 0, 0], // Direct
    [0.00333333, 0.09738095, 0.14476190, 0, 0, 0.08976190, 0.08309524, 0.27666667, 0.12071429, 0.18428571, 0, 0, 0, 0], // Long balls
    [0.00438596, 0.10181704, 0.19047619, 0, 0, 0.09179198, 0.08302005, 0.25877193, 0.07988722, 0.18984962, 0, 0, 0, 0]]; // Balanced

var weightDefence = [
    [0.01699757, 0.05099272, 0.08941580, 0.25724896, 0.34152264, 0.09884302, 0.12998143, 0, 0, 0, 0.01499786, 0, 0, 0],
	[0.02270559, 0.06048464, 0.23392482, 0.24441900, 0.24251097, 0.08624308, 0.08967754, 0, 0, 0, 0.02003435, 0, 0, 0],
	[0.04134184, 0.05031892, 0.16678479, 0.25537444, 0.29270021, 0.08221120, 0.08646350, 0, 0, 0, 0.02480510, 0, 0, 0],
	[0.02190318, 0.05245721, 0.12552917, 0.33591018, 0.21627094, 0.12442481, 0.10417817, 0, 0, 0, 0.01932634, 0, 0, 0],
	[0.10566556, 0.04724564, 0.11644776, 0.23936483, 0.20446971, 0.09017840, 0.09370712, 0, 0, 0, 0.10292100, 0, 0, 0],
    [0.03965345, 0.05231589, 0.14195268, 0.26691103, 0.26357881, 0.09730090, 0.10329890, 0, 0, 0, 0.03498834, 0, 0, 0]];

var weightABal = [
    [0.00276422, 0.10067205, 0.16547592, 0, 0, 0.09057143, 0.08504298, 0.27613666, 0.08638046, 0.19295627, 0, 0, 0, 0], //DC
    [0.00442064, 0.10241347, 0.18932208, 0, 0, 0.08991175, 0.08107047, 0.25614835, 0.09842144, 0.17829181, 0, 0, 0, 0], //DLR
    [0.00258676, 0.10122555, 0.17075867, 0, 0, 0.09110939, 0.08593586, 0.27616843, 0.07739470, 0.19482064, 0, 0, 0, 0], //DMC
    [0.00326678, 0.10214868, 0.18073211, 0, 0, 0.09060837, 0.08407481, 0.26783111, 0.08275247, 0.18858565, 0, 0, 0, 0], //DMLR
    [0.00217077, 0.10412690, 0.18835057, 0, 0, 0.09147931, 0.08713777, 0.27491544, 0.05128438, 0.20053487, 0, 0, 0, 0], //MC
    [0.00401069, 0.09973343, 0.17156444, 0, 0, 0.09205432, 0.08403294, 0.26818903, 0.08251735, 0.19789780, 0, 0, 0, 0], //MLR
    [0.00204832, 0.10083736, 0.18085991, 0, 0, 0.09394054, 0.08984389, 0.27755008, 0.05714698, 0.19777292, 0, 0, 0, 0], //OMC
    [0.00501401, 0.10330073, 0.19217931, 0, 0, 0.09101568, 0.08098767, 0.25747692, 0.06584592, 0.20417978, 0, 0, 0, 0], //OMLR
    [0.00200925, 0.10061759, 0.16988620, 0, 0, 0.09354589, 0.08952740, 0.28380866, 0.04908803, 0.21151698, 0, 0, 0, 0]]; //F

var weightDBal = [
    [0.03336560, 0.05319037, 0.14377141, 0.26763355, 0.26771576, 0.09844299, 0.10600777, 0, 0, 0, 0.02987255, 0, 0, 0],
    [0.03432328, 0.05314668, 0.14707558, 0.26690202, 0.26677011, 0.09743710, 0.10421476, 0, 0, 0, 0.03013048, 0, 0, 0],
    [0.03342026, 0.05327265, 0.14451824, 0.26631785, 0.26837303, 0.09800297, 0.10608690, 0, 0, 0, 0.03000810, 0, 0, 0],
    [0.04017728, 0.05218948, 0.14432124, 0.26532036, 0.26553143, 0.09590531, 0.10190701, 0, 0, 0, 0.03464790, 0, 0, 0],
    [0.03321351, 0.05318841, 0.14255567, 0.26792155, 0.26777895, 0.09880470, 0.10657690, 0, 0, 0, 0.02996031, 0, 0, 0],
    [0.03685060, 0.05291193, 0.14849502, 0.26553463, 0.26516723, 0.09638160, 0.10259796, 0, 0, 0, 0.03206104, 0, 0, 0],
    [0.03329700, 0.05319468, 0.14464604, 0.27009280, 0.26471479, 0.09915742, 0.10523286, 0, 0, 0, 0.02966442, 0, 0, 0],
    [0.03530321, 0.05379872, 0.15753782, 0.26267798, 0.26280546, 0.09529275, 0.10159547, 0, 0, 0, 0.03098860, 0, 0, 0],
    [0.02661505, 0.05528894, 0.17957068, 0.27999454, 0.24432637, 0.09915076, 0.09420038, 0, 0, 0, 0.02085327, 0, 0, 0]];

var weightASho = [
    [0, 0.02859171, 0.02859171, 0, 0, 0.02859171, 0.02859171, 0.10007097, 0, 0.08577512],
    [0, 0         , 0	      , 0, 0, 0	        , 0	        , 0         , 0, 0	       ],
    [0, 0.02303312, 0.02303312, 0, 0, 0.02303312, 0.02303312, 0.08061591, 0, 0.06909935],
    [0, 0.01005579, 0.01005579, 0, 0, 0.01005579, 0.01005579, 0.03519527, 0, 0.03016737],
    [0, 0.09523810, 0.09523810, 0, 0, 0.09523810, 0.09523810, 0.33333333, 0, 0.28571429],
    [0, 0.04051014, 0.04051014, 0, 0, 0.04051014, 0.04051014, 0.14178549, 0, 0.12153042],
    [0, 0.08318078, 0.08318078, 0, 0, 0.08318078, 0.08318078, 0.29113271, 0, 0.24954233],
    [0, 0.02792502, 0.02792502, 0, 0, 0.02792502, 0.02792502, 0.09773757, 0, 0.08377506],
    [0, 0.09292480, 0.09292480, 0, 0, 0.09292480, 0.09292480, 0.32523680, 0, 0.27877440]];

var weightAThr = [
    [0, 0.04755028, 0.11887571, 0, 0, 0.04755028, 0.04755028, 0.11887571, 0.04755028, 0.04755028],
    [0, 0.05368688, 0.13421720, 0, 0, 0.05368688, 0.05368688, 0.13421720, 0.05368688, 0.05368688],
    [0, 0.04848123, 0.12120307, 0, 0, 0.04848123, 0.04848123, 0.12120307, 0.04848123, 0.04848123],
    [0, 0.05651589, 0.14128973, 0, 0, 0.05651589, 0.05651589, 0.14128973, 0.05651589, 0.05651589],
    [0, 0.08702999, 0.21757497, 0, 0, 0.08702999, 0.08702999, 0.21757497, 0.08702999, 0.08702999],
    [0, 0.05817945, 0.14544862, 0, 0, 0.05817945, 0.05817945, 0.14544862, 0.05817945, 0.05817945],
    [0, 0.10000000, 0.25000000, 0, 0, 0.10000000, 0.10000000, 0.25000000, 0.10000000, 0.10000000],
    [0, 0.05165832, 0.12914580, 0, 0, 0.05165832, 0.05165832, 0.12914580, 0.05165832, 0.05165832],
    [0, 0.09793659, 0.24484147, 0, 0, 0.09793659, 0.09793659, 0.24484147, 0.09793659, 0.09793659]];

var weightAWin = [
    [0	       , 0	       , 0	       , 0, 0, 0	     , 0, 0, 0	       , 0	       ],
    [0.03061975, 0.06123949, 0.18371848, 0, 0, 0.06123949, 0, 0, 0.24495797, 0.12247899],
    [0	       , 0	       , 0	       , 0, 0, 0	     , 0, 0, 0	       , 0	       ],
    [0.01382584, 0.02765167, 0.08295502, 0, 0, 0.02765167, 0, 0, 0.11060669, 0.05530335],
    [0	       , 0	       , 0	       , 0, 0, 0	     , 0, 0, 0	       , 0	       ],
    [0.02218614, 0.04437227, 0.13311682, 0, 0, 0.04437227, 0, 0, 0.17748909, 0.08874454],
    [0	       , 0	       , 0	       , 0, 0, 0	     , 0, 0, 0	       , 0	       ],
    [0.04347826, 0.08695652, 0.26086957, 0, 0, 0.08695652, 0, 0, 0.34782609, 0.17391304],
    [0	       , 0	       , 0	       , 0, 0, 0	     , 0, 0, 0	       , 0	       ]];

var weightADir = [
    [0, 0.07520964, 0.17548915, 0, 0, 0.05013976, 0.05013976, 0.15041928, 0, 0.10027952],
    [0, 0.09537563, 0.22254314, 0, 0, 0.06358376, 0.06358376, 0.19075127, 0, 0.12716751],
    [0, 0.12500000, 0.29166667, 0, 0, 0.08333333, 0.08333333, 0.25000000, 0, 0.16666667],
    [0, 0.11101400, 0.25903266, 0, 0, 0.07400933, 0.07400933, 0.22202799, 0, 0.14801866],
    [0, 0.11062291, 0.25812013, 0, 0, 0.07374861, 0.07374861, 0.22124582, 0, 0.14749721],
    [0, 0.10893804, 0.25418876, 0, 0, 0.07262536, 0.07262536, 0.21787608, 0, 0.14525072],
    [0, 0.07190075, 0.16776842, 0, 0, 0.04793384, 0.04793384, 0.14380151, 0, 0.09586767],
    [0, 0.03200717, 0.07468340, 0, 0, 0.02133812, 0.02133812, 0.06401435, 0, 0.04267623],
    [0, 0.09856088, 0.22997539, 0, 0, 0.06570725, 0.06570725, 0.19712176, 0, 0.13141451]];

var weightALon = [
    [0, 0.08333333, 0, 0, 0, 0.08333333, 0.08333333, 0.33333333, 0.25000000, 0.16666667],
    [0, 0.05124751, 0, 0, 0, 0.05124751, 0.05124751, 0.20499004, 0.15374253, 0.10249502],
    [0, 0.05708605, 0, 0, 0, 0.05708605, 0.05708605, 0.22834419, 0.17125814, 0.11417210],
    [0, 0.04958375, 0, 0, 0, 0.04958375, 0.04958375, 0.19833502, 0.14875126, 0.09916751],
    [0, 0.00998916, 0, 0, 0, 0.00998916, 0.00998916, 0.03995664, 0.02996748, 0.01997832],
    [0, 0.02233372, 0, 0, 0, 0.02233372, 0.02233372, 0.08933487, 0.06700115, 0.04466744],
    [0, 0	      , 0, 0, 0, 0	       , 0	       , 0	       , 0	       , 0	       ],
    [0, 0	      , 0, 0, 0, 0	       , 0	       , 0	       , 0	       , 0	       ],
    [0, 0	      , 0, 0, 0, 0	       , 0	       , 0	       , 0	       , 0	       ]];

var weightASho2 = [
    [0	       , 0.06730870, 0.09124884, 0, 0, 0.06362077, 0.06362077, 0.20914435, 0.08785123, 0.11922802],
    [0.00450435, 0.06043899, 0.11899608, 0, 0, 0.05576222, 0.04675351, 0.14212098, 0.10084866, 0.08783143],
    [0	       , 0.06550198, 0.10684459, 0, 0, 0.05937256, 0.05937256, 0.18791317, 0.06720133, 0.10779898],
    [0.00203387, 0.06316406, 0.11722427, 0, 0, 0.05772045, 0.05365272, 0.16403037, 0.08099827, 0.09506144],
    [0	       , 0.10055996, 0.17719784, 0, 0, 0.09513553, 0.09513553, 0.29047785, 0.04642320, 0.19507009],
    [0.00326372, 0.07258041, 0.13954252, 0, 0, 0.06723859, 0.06071116, 0.18445832, 0.06970589, 0.12717988],
    [0	       , 0.09244576, 0.17274623, 0, 0, 0.08892008, 0.08892008, 0.26356276, 0.04413183, 0.17144521],
    [0.00639592, 0.05296688, 0.11902513, 0, 0, 0.05139740, 0.03860556, 0.11075222, 0.07396511, 0.09266587],
    [0	       , 0.09987761, 0.18404130, 0, 0, 0.09504464, 0.09504464, 0.28460205, 0.04322121, 0.18902555]];

var weightAThr2 = [
    [0	       , 0.06086869, 0.12249491, 0, 0, 0.05910502, 0.05910502, 0.16694636, 0.07546436, 0.07615446],
    [0.00215410, 0.06667221, 0.15132879, 0, 0, 0.06443565, 0.06012745, 0.16238773, 0.08599717, 0.07977198],
    [0	       , 0.06158727, 0.13251818, 0, 0, 0.05865602, 0.05865602, 0.16167723, 0.06624396, 0.07412675],
    [0.00097265, 0.06828739, 0.15377877, 0, 0, 0.06568412, 0.06373882, 0.17196712, 0.07849440, 0.08018511],
    [0	       , 0.09342159, 0.22191019, 0, 0, 0.09082748, 0.09082748, 0.23634768, 0.08342636, 0.10683003],
    [0.00156079, 0.06887829, 0.16229516, 0, 0, 0.06632369, 0.06320211, 0.16687312, 0.07426440, 0.08146763],
    [0	       , 0.10067782, 0.24460456, 0, 0, 0.09899175, 0.09899175, 0.25333009, 0.09145497, 0.11069317],
    [0.00305869, 0.05701132, 0.14311452, 0, 0, 0.05626076, 0.05014337, 0.12750712, 0.07171366, 0.06667554],
    [0	       , 0.10115413, 0.24475095, 0, 0, 0.09884287, 0.09884287, 0.25407093, 0.08956788, 0.11277037]];

var weightAWin2 = [
    [0	       , 0.04225231, 0.06418877, 0, 0, 0.03990278, 0.03990278, 0.12658467, 0.06042507, 0.06515848],
    [0.02295724, 0.08371143, 0.20891484, 0, 0, 0.08073193, 0.03481745, 0.10312186, 0.22998134, 0.14133791],
    [0	       , 0.04217719, 0.07533138, 0, 0, 0.03827223, 0.03827223, 0.11673707, 0.04735657, 0.06093047],
    [0.01036596, 0.06188936, 0.14055609, 0, 0, 0.05842132, 0.03768940, 0.11148288, 0.12946112, 0.09677401],
    [0	       , 0.05528222, 0.11634162, 0, 0, 0.05182640, 0.05182640, 0.14616214, 0.03773190, 0.08161443],
    [0.01663412, 0.07359684, 0.18265559, 0, 0, 0.07019365, 0.03692541, 0.10592847, 0.16629992, 0.12308049],
    [0	       , 0.05347288, 0.11868897, 0, 0, 0.05122672, 0.05122672, 0.13955974, 0.03748764, 0.07421258],
    [0.03259795, 0.09066534, 0.25410493, 0, 0, 0.08966544, 0.02446955, 0.06527805, 0.28014906, 0.16306968],
    [0	       , 0.05628111, 0.12366833, 0, 0, 0.05320210, 0.05320210, 0.14641423, 0.03671411, 0.08002005]];

var weightADir2 = [
    [0	       , 0.08075120, 0.06418877, 0, 0, 0.05949152, 0.05949152, 0.18569886, 0.03585454, 0.11366435],
    [0.00199739, 0.09795727, 0.20891484, 0, 0, 0.07099723, 0.06700245, 0.20358339, 0.04121776, 0.13499025],
    [0	       , 0.11981065, 0.07533138, 0, 0, 0.08447662, 0.08447662, 0.25739438, 0.02663692, 0.16334105],
    [0.00090189, 0.10951085, 0.14055609, 0, 0, 0.07813027, 0.07632650, 0.23132927, 0.03223086, 0.14919847],
    [0	       , 0.10929674, 0.11634162, 0, 0, 0.07802672, 0.07802672, 0.23106156, 0.01490855, 0.14764675],
    [0.00144725, 0.10676876, 0.18265559, 0, 0, 0.07597500, 0.07308050, 0.21872210, 0.02711490, 0.14561345],
    [0	       , 0.07659390, 0.11868897, 0, 0, 0.05626955, 0.05626955, 0.16357267, 0.01304641, 0.10206713],
    [0.00283618, 0.04041881, 0.25410493, 0, 0, 0.03137127, 0.02569892, 0.07415911, 0.02942897, 0.05686726],
    [0	       , 0.09923451, 0.12366833, 0, 0, 0.07137408, 0.07137408, 0.20917165, 0.01277721, 0.13284697]];

var weightALon2 = [
    [0	       , 0.09135249, 0.08015464, 0, 0, 0.08668146, 0.08668146, 0.30922528, 0.18710149, 0.15880317],
    [0.00285254, 0.07820315, 0.10859446, 0, 0, 0.07227967, 0.06657458, 0.22444246, 0.14699134, 0.12455340],
    [0	       , 0.08257883, 0.10205393, 0, 0, 0.07481548, 0.07481548, 0.25536345, 0.13409849, 0.13411006],
    [0.00128802, 0.07902599, 0.10975275, 0, 0, 0.07213126, 0.06955523, 0.23228564, 0.13214762, 0.12431357],
    [0	       , 0.07033421, 0.13969444, 0, 0, 0.06346377, 0.06346377, 0.18620577, 0.05273479, 0.10502058],
    [0.00206687, 0.06571937, 0.11843836, 0, 0, 0.05895357, 0.05481984, 0.17098947, 0.08361022, 0.10070354],
    [0	       , 0.05985233, 0.13361060, 0, 0, 0.05538680, 0.05538680, 0.15212416, 0.03726411, 0.08270112],
    [0.00405045, 0.03640027, 0.08942853, 0, 0, 0.03441240, 0.02631151, 0.07085240, 0.05165358, 0.05266056],
    [0	       , 0.06512748, 0.14435549, 0, 0, 0.05900617, 0.05900617, 0.16390511, 0.03649520, 0.09178552]];

var weightABal2 = [
    [0	       , 0.07964933, 0.13049122, 0, 0, 0.07202489, 0.07202489, 0.22705993, 0.09804267, 0.11994034],
    [0.00310411, 0.08203883, 0.16794454, 0, 0, 0.07237004, 0.06616183, 0.19632672, 0.09999489, 0.11208474],
    [0	       , 0.08716561, 0.16630390, 0, 0, 0.07449362, 0.07449362, 0.22645828, 0.07683839, 0.12337579],
    [0.00140161, 0.08634351, 0.17482178, 0, 0, 0.07508937, 0.07228615, 0.21422573, 0.08671568, 0.11749548],
    [0	       , 0.10537469, 0.22687560, 0, 0, 0.09416019, 0.09416019, 0.26679060, 0.06122188, 0.15141683],
    [0.00224914, 0.08601186, 0.18609034, 0, 0, 0.07496817, 0.07046989, 0.20330035, 0.07190556, 0.12136807],
    [0	       , 0.09669569, 0.21709005, 0, 0, 0.08940669, 0.08940669, 0.24480884, 0.06082555, 0.13199094],
    [0.00440765, 0.05467208, 0.13241390, 0, 0, 0.05142733, 0.04261203, 0.11447588, 0.06668265, 0.07613425],
    [0	       , 0.10518906, 0.23451157, 0, 0, 0.09519736, 0.09519736, 0.26362858, 0.05957047, 0.14646773]];

var weightDSho = [
    [0, 0.05000000, 0.05000000, 0.25000000, 0.40000000, 0.10000000, 0.15000000, 0, 0, 0, 0],
    [0, 0.04285714, 0.04285714, 0.21428571, 0.34285714, 0.08571429, 0.12857143, 0, 0, 0, 0],
    [0, 0.04000000, 0.04000000, 0.20000000, 0.32000000, 0.08000000, 0.12000000, 0, 0, 0, 0],
    [0, 0.03428571, 0.03428571, 0.17142857, 0.27428571, 0.06857143, 0.10285714, 0, 0, 0, 0],
    [0, 0.04714286, 0.04714286, 0.23571429, 0.37714286, 0.09428571, 0.14142857, 0, 0, 0, 0],
    [0, 0.04000000, 0.04000000, 0.20000000, 0.32000000, 0.08000000, 0.12000000, 0, 0, 0, 0],
    [0, 0.02285714, 0.02285714, 0.11428571, 0.18285714, 0.04571429, 0.06857143, 0, 0, 0, 0],
    [0, 0.01714286, 0.01714286, 0.08571429, 0.13714286, 0.03428571, 0.05142857, 0, 0, 0, 0],
    [0, 0	      , 0	      , 0	      , 0	      , 0	      , 0	      , 0, 0, 0, 0]];

var weightDThr = [
    [0, 0.07142857, 0.35714286, 0.21428571, 0.21428571, 0.07142857, 0.07142857, 0, 0, 0, 0],
    [0, 0.05714286, 0.28571429, 0.17142857, 0.17142857, 0.05714286, 0.05714286, 0, 0, 0, 0],
    [0, 0.06785714, 0.33928571, 0.20357143, 0.20357143, 0.06785714, 0.06785714, 0, 0, 0, 0],
    [0, 0.04642857, 0.23214286, 0.13928571, 0.13928571, 0.04642857, 0.04642857, 0, 0, 0, 0],
    [0, 0.05357143, 0.26785714, 0.16071429, 0.16071429, 0.05357143, 0.05357143, 0, 0, 0, 0],
    [0, 0.04464286, 0.22321429, 0.13392857, 0.13392857, 0.04464286, 0.04464286, 0, 0, 0, 0],
    [0, 0.03035714, 0.15178571, 0.09107143, 0.09107143, 0.03035714, 0.03035714, 0, 0, 0, 0],
    [0, 0.01964286, 0.09821429, 0.05892857, 0.05892857, 0.01964286, 0.01964286, 0, 0, 0, 0],
    [0, 0.02500000, 0.12500000, 0.07500000, 0.07500000, 0.02500000, 0.02500000, 0, 0, 0, 0]];

var weightDWin = [
    [0.03787879, 0.03787879, 0.18939394, 0.18939394, 0.30303030, 0.03787879, 0.03787879, 0, 0, 0, 0],
    [0.04545455, 0.04545455, 0.22727273, 0.22727273, 0.36363636, 0.04545455, 0.04545455, 0, 0, 0, 0],
    [0.01212121, 0.01212121, 0.06060606, 0.06060606, 0.09696970, 0.01212121, 0.01212121, 0, 0, 0, 0],
    [0.04090909, 0.04090909, 0.20454545, 0.20454545, 0.32727273, 0.04090909, 0.04090909, 0, 0, 0, 0],
    [0.00909091, 0.00909091, 0.04545455, 0.04545455, 0.07272727, 0.00909091, 0.00909091, 0, 0, 0, 0],
    [0.03333333, 0.03333333, 0.16666667, 0.16666667, 0.26666667, 0.03333333, 0.03333333, 0, 0, 0, 0],
    [0.00606061, 0.00606061, 0.03030303, 0.03030303, 0.04848485, 0.00606061, 0.00606061, 0, 0, 0, 0],
    [0.03030303, 0.03030303, 0.15151515, 0.15151515, 0.24242424, 0.03030303, 0.03030303, 0, 0, 0, 0],
    [0	       , 0	       , 0	       , 0	       , 0	       , 0	       , 0	       , 0, 0, 0, 0]];

var weightDDir = [
    [0, 0.05263158, 0.10526316, 0.42105263, 0.15789474, 0.15789474, 0.10526316, 0, 0, 0, 0],
    [0, 0.04251012, 0.08502024, 0.34008097, 0.12753036, 0.12753036, 0.08502024, 0, 0, 0, 0],
    [0, 0.05060729, 0.10121457, 0.40485830, 0.15182186, 0.15182186, 0.10121457, 0, 0, 0, 0],
    [0, 0.02631579, 0.05263158, 0.21052632, 0.07894737, 0.07894737, 0.05263158, 0, 0, 0, 0],
    [0, 0.04655870, 0.09311741, 0.37246964, 0.13967611, 0.13967611, 0.09311741, 0, 0, 0, 0],
    [0, 0.03846154, 0.07692308, 0.30769231, 0.11538462, 0.11538462, 0.07692308, 0, 0, 0, 0],
    [0, 0.02226721, 0.04453441, 0.17813765, 0.06680162, 0.06680162, 0.04453441, 0, 0, 0, 0],
    [0, 0.01214575, 0.02429150, 0.09716599, 0.03643725, 0.03643725, 0.02429150, 0, 0, 0, 0],
    [0, 0.01619433, 0.03238866, 0.12955466, 0.04858300, 0.04858300, 0.03238866, 0, 0, 0, 0]];

var weightDLon = [
    [0.21428571, 0.03571429, 0.07142857, 0.14285714, 0.10714286, 0.07142857, 0.07142857, 0, 0, 0, 0.28571429],
    [0.18367347, 0.03061224, 0.06122449, 0.12244898, 0.09183673, 0.06122449, 0.06122449, 0, 0, 0, 0.24489796],
    [0.16836735, 0.02806122, 0.05612245, 0.11224490, 0.08418367, 0.05612245, 0.05612245, 0, 0, 0, 0.22448980],
    [0.15306122, 0.02551020, 0.05102041, 0.10204082, 0.07653061, 0.05102041, 0.05102041, 0, 0, 0, 0.20408163],
    [0.12244898, 0.02040816, 0.04081633, 0.08163265, 0.06122449, 0.04081633, 0.04081633, 0, 0, 0, 0.16326531],
    [0.09183673, 0.01530612, 0.03061224, 0.06122449, 0.04591837, 0.03061224, 0.03061224, 0, 0, 0, 0.12244898],
    [0.03061224, 0.00510204, 0.01020408, 0.02040816, 0.01530612, 0.01020408, 0.01020408, 0, 0, 0, 0.04081633],
    [0.01530612, 0.00255102, 0.00510204, 0.01020408, 0.00765306, 0.00510204, 0.00510204, 0, 0, 0, 0.02040816],
    [0	       , 0	       , 0	       , 0	       , 0	       , 0	       , 0	       , 0, 0, 0, 0	        ]];

var weightDSho2 = [
    [0.02351850, 0.05174242, 0.10885426, 0.24146309, 0.32864208, 0.09342436, 0.12354377, 0, 0, 0, 0.02881152],
    [0.02081352, 0.04425684, 0.09322829, 0.20734042, 0.28468582, 0.07972176, 0.10566963, 0, 0, 0, 0.02469559],
    [0.01758937, 0.04247508, 0.09135745, 0.19667236, 0.26157344, 0.07662652, 0.10029338, 0, 0, 0, 0.02263763],
    [0.01749739, 0.03545775, 0.07569886, 0.16465119, 0.22905140, 0.06315689, 0.08430303, 0, 0, 0, 0.02057966],
    [0.01280616, 0.04386743, 0.08251932, 0.20811520, 0.28839592, 0.08152075, 0.11007361, 0, 0, 0, 0.01646373],
    [0.01094152, 0.03813457, 0.07535078, 0.18144170, 0.25389952, 0.06977501, 0.09405426, 0, 0, 0, 0.01234780],
    [0.00339253, 0.02151661, 0.04274348, 0.10125305, 0.14098769, 0.03925853, 0.05311781, 0, 0, 0, 0.00411593],
    [0.00307136, 0.01660520, 0.03547113, 0.07866357, 0.11363750, 0.02932373, 0.03994783, 0, 0, 0, 0.00205797],
    [0	       , 0.00459803, 0.02054060, 0.01787671, 0.01379410, 0.00623108, 0.00541455, 0, 0, 0, 0         ]];

var weightDThr2 = [
    [0.02351850, 0.06254674, 0.26371620, 0.22345589, 0.23500462, 0.07901859, 0.08392793, 0, 0, 0, 0.02881152],
    [0.02081352, 0.05145972, 0.21567727, 0.18573178, 0.19825125, 0.06531599, 0.06965522, 0, 0, 0, 0.02469559],
    [0.01758937, 0.05652070, 0.24225781, 0.19847308, 0.20286996, 0.07050408, 0.07400287, 0, 0, 0, 0.02263763],
    [0.01749739, 0.04158019, 0.17545876, 0.14844471, 0.16098417, 0.05199242, 0.05585165, 0, 0, 0, 0.02057966],
    [0.01280616, 0.04710873, 0.19380383, 0.17030007, 0.17927227, 0.06099254, 0.06577590, 0, 0, 0, 0.01646373],
    [0.01094152, 0.04047551, 0.16772773, 0.14812837, 0.16008199, 0.05194788, 0.05605906, 0, 0, 0, 0.01234780],
    [0.00339253, 0.02529813, 0.10774948, 0.08954837, 0.09470918, 0.03151543, 0.03385010, 0, 0, 0, 0.00411593],
    [0.00307136, 0.01786571, 0.07634748, 0.06515816, 0.07420173, 0.02194077, 0.02392142, 0, 0, 0, 0.00205797],
    [0	       , 0.01720308, 0.08356581, 0.05569183, 0.05160923, 0.01883612, 0.01801960, 0, 0, 0, 0         ]];

var weightDWin2 = [
    [0.03919295, 0.05157883, 0.18438446, 0.23191400, 0.30286959, 0.07443731, 0.08501062, 0, 0, 0, 0.03061224],
    [0.03915982, 0.04876222, 0.18122110, 0.22287341, 0.30108722, 0.06807635, 0.07727862, 0, 0, 0, 0.02623907],
    [0.02323416, 0.03616757, 0.12082772, 0.15688298, 0.18804817, 0.05531063, 0.06331381, 0, 0, 0, 0.02405248],
    [0.03393188, 0.04080813, 0.15487693, 0.18563878, 0.25600510, 0.05554459, 0.06331849, 0, 0, 0, 0.02186589],
    [0.01701564, 0.03268405, 0.09886764, 0.14575714, 0.18067043, 0.05248662, 0.06261996, 0, 0, 0, 0.01749271],
    [0.02412536, 0.03826671, 0.13737525, 0.17674226, 0.23980012, 0.05474181, 0.06339566, 0, 0, 0, 0.01311953],
    [0.00587729, 0.01696449, 0.05511404, 0.07484424, 0.09449272, 0.02601936, 0.03094892, 0, 0, 0, 0.00437318],
    [0.01462695, 0.02271202, 0.09242080, 0.10682042, 0.15603032, 0.02887851, 0.03281968, 0, 0, 0, 0.00218659],
    [0	       , 0.00622470, 0.02852082, 0.02301186, 0.01867409, 0.00795980, 0.00709225, 0, 0, 0, 0         ]];

var weightDDir2 = [
    [0.02351850, 0.05225420, 0.12680460, 0.34675784, 0.19152197, 0.12989368, 0.10043769, 0, 0, 0, 0.02881152],
    [0.02081352, 0.04332659, 0.10649383, 0.28561270, 0.16304753, 0.10646282, 0.08292077, 0, 0, 0, 0.02469559],
    [0.01758937, 0.04748837, 0.11330480, 0.32044017, 0.16568895, 0.12069401, 0.09155646, 0, 0, 0, 0.02263763],
    [0.01749739, 0.03002336, 0.07682289, 0.18992762, 0.11767022, 0.07055121, 0.05675959, 0, 0, 0, 0.02057966],
    [0.01280616, 0.04318986, 0.09920740, 0.29463944, 0.15563092, 0.11103667, 0.08527310, 0, 0, 0, 0.01646373],
    [0.01094152, 0.03696965, 0.08845310, 0.24993140, 0.13948036, 0.09296690, 0.07179043, 0, 0, 0, 0.01234780],
    [0.00339253, 0.02078153, 0.04935853, 0.14105663, 0.07539707, 0.05279156, 0.04050117, 0, 0, 0, 0.00411593],
    [0.00307136, 0.01345569, 0.03570872, 0.08694287, 0.05664995, 0.03136379, 0.02513140, 0, 0, 0, 0.00205797],
    [0	       , 0.01313578, 0.03383459, 0.09248120, 0.03940734, 0.03436533, 0.02375055, 0, 0, 0, 0         ]];

var weightDLon2 = [
    [0.08834443, 0.04863381, 0.13360942, 0.21587391, 0.21847591, 0.08625938, 0.09355704, 0, 0, 0, 0.11524610],
    [0.07637860, 0.04125529, 0.11315556, 0.18373963, 0.18924660, 0.07298088, 0.07949846, 0, 0, 0, 0.09878237],
    [0.06852403, 0.04080273, 0.11441131, 0.18063366, 0.17588413, 0.07241209, 0.07739287, 0, 0, 0, 0.09055051],
    [0.06380162, 0.03301337, 0.09166245, 0.14401060, 0.15257061, 0.05725404, 0.06324381, 0, 0, 0, 0.08231864],
    [0.04984955, 0.03607430, 0.09405191, 0.16461598, 0.16993850, 0.06558091, 0.07277067, 0, 0, 0, 0.06585491],
    [0.03872406, 0.03082068, 0.08361015, 0.14155772, 0.15128557, 0.05483556, 0.06104112, 0, 0, 0, 0.04939119],
    [0.01265337, 0.01649373, 0.04650923, 0.07490208, 0.07982060, 0.02880487, 0.03232174, 0, 0, 0, 0.01646373],
    [0.00770178, 0.01206496, 0.03627660, 0.05504700, 0.06544295, 0.01986524, 0.02296218, 0, 0, 0, 0.00823186],
    [0         , 0.00667506, 0.02847617, 0.02819039, 0.02002518, 0.00994114, 0.00830810, 0, 0, 0, 0         ]];

var weightDBal2 = [
    [	0.03432282	,	0.05452880	,	0.16196603	,	0.24790778	,	0.26137096	,	0.09350018	,	0.10318615	,	0	,	0	,	0	,	0.04321729	],	//DC
    [	0.03007437	,	0.04576532	,	0.13514081	,	0.20891264	,	0.22438533	,	0.07838200	,	0.08707794	,	0	,	0	,	0	,	0.03704339	],	//DLR
    [	0.02607848	,	0.04715645	,	0.14361335	,	0.21344593	,	0.21511336	,	0.08082842	,	0.08729118	,	0	,	0	,	0	,	0.03395644	],	//DMC
    [	0.02521476	,	0.03604833	,	0.10832060	,	0.16023333	,	0.17896240	,	0.05996893	,	0.06808923	,	0	,	0	,	0	,	0.03086949	],	//DMLR
    [	0.01898006	,	0.04343295	,	0.12022178	,	0.20279229	,	0.21578394	,	0.07724354	,	0.08683970	,	0	,	0	,	0	,	0.02469559	],	//MC
    [	0.01557194	,	0.03743664	,	0.10631387	,	0.17531034	,	0.19130153	,	0.06550493	,	0.07380486	,	0	,	0	,	0	,	0.01852169	],	//MLR
    [	0.00493600	,	0.02169636	,	0.06379325	,	0.09944718	,	0.10695311	,	0.03727163	,	0.04197070	,	0	,	0	,	0	,	0.00617390	],	//OMC
    [	0.00384310	,	0.01574372	,	0.04784781	,	0.07195950	,	0.08512269	,	0.02585435	,	0.03006760	,	0	,	0	,	0	,	0.00308695	],	//OMLR
    [	0	        ,	0.01001259	,	0.04271425	,	0.04228558	,	0.03003776	,	0.01491171	,	0.01246215	,	0	,	0	,	0	,	0	        ]	//F
];

// RECb weights
var weightRb = [
    [	0.10493615	,	0.05208547	,	0.07934211	,	0.14448971	,	0.13159554	,	0.06553072	,	0.07778375	,	0.06669303	,	0.05158306	,	0.02753168	,	0.12055170	,	0.01350989	,	0.02549169	,	0.03887550	],	// DC
    [	0.07715535	,	0.04943315	,	0.11627229	,	0.11638685	,	0.12893778	,	0.07747251	,	0.06370799	,	0.03830611	,	0.10361093	,	0.06253997	,	0.09128094	,	0.01314110	,	0.02449199	,	0.03726305	],	// DL/R
    [	0.08219824	,	0.08668831	,	0.07434242	,	0.09661001	,	0.08894242	,	0.08998026	,	0.09281287	,	0.08868309	,	0.04753574	,	0.06042619	,	0.05396986	,	0.05059984	,	0.05660203	,	0.03060871	],	// DMC
    [	0.06744248	,	0.06641401	,	0.09977251	,	0.08253749	,	0.09709316	,	0.09241026	,	0.08513703	,	0.06127851	,	0.10275520	,	0.07985941	,	0.04618960	,	0.03927270	,	0.05285911	,	0.02697852	],	// DML/R
    [	0.07304213	,	0.08174111	,	0.07248656	,	0.08482334	,	0.07078726	,	0.09568392	,	0.09464529	,	0.09580381	,	0.04746231	,	0.07093008	,	0.04595281	,	0.05955544	,	0.07161249	,	0.03547345	],	// MC
    [	0.06527363	,	0.06410270	,	0.09701305	,	0.07406706	,	0.08563595	,	0.09648566	,	0.08651209	,	0.06357183	,	0.10819222	,	0.07386495	,	0.03245554	,	0.05430668	,	0.06572005	,	0.03279859	],	// ML/R
    [	0.07842736	,	0.07744888	,	0.07201150	,	0.06734457	,	0.05002348	,	0.08350204	,	0.08207655	,	0.11181914	,	0.03756112	,	0.07486004	,	0.06533972	,	0.07457344	,	0.09781475	,	0.02719742	],	// OMC
    [	0.06545375	,	0.06145378	,	0.10503536	,	0.06421508	,	0.07627526	,	0.09232981	,	0.07763931	,	0.07001035	,	0.11307331	,	0.07298351	,	0.04248486	,	0.06462713	,	0.07038293	,	0.02403557	],	// OML/R
    [	0.07738289	,	0.05022488	,	0.07790481	,	0.01356516	,	0.01038191	,	0.06495444	,	0.07721954	,	0.07701905	,	0.02680715	,	0.07759692	,	0.12701687	,	0.15378395	,	0.12808992	,	0.03805251	],	// F
    [	0.07466384	,	0.07466384	,	0.07466384	,	0.14932769	,	0.10452938	,	0.14932769	,	0.10452938	,	0.10344411	,	0.07512610	,	0.04492581	,	0.04479831	]	// GK
];
// REC weights
var weightR = [
    [0.653962303361921,  0.330014238020285, 0.562994547223387, 0.891800163983125,  0.871069095865164,  0.454514672470839, 0.555697278549252, 0.42777598627972,  0.338218821750765, 0.134348455965202, 0.796916786677566, 0.048831870932616, 0.116363443378865, 0.282347752982916],	//DC
	[0.565605120229193,  0.430973382039533, 0.917125432457378, 0.815702528287723,  0.99022325015212,   0.547995876625372, 0.522203232914265, 0.309928898819518, 0.837365352274204, 0.483822472259513, 0.656901420858592, 0.137582588344562, 0.163658117596413, 0.303915447383549],	//DL/R
	[0.55838825558912,   0.603683502357502, 0.563792314670998, 0.770425088563048,  0.641965853834719,  0.675495235675077, 0.683863478201805, 0.757342915150728, 0.473070797767482, 0.494107823556837, 0.397547163237438, 0.429660916538242, 0.56364174077388,  0.224791093448809],	//DMC
	[0.582074038075056,  0.420032202680124, 0.7887541874616,   0.726221389774063,  0.722972329840151,  0.737617252827595, 0.62234458453736,  0.466946909655194, 0.814382915598981, 0.561877829393632, 0.367446981999576, 0.360623408340649, 0.390057769678583, 0.249517737311268],	//DML/R
	[0.578431939417021,  0.778134685048085, 0.574726322388294, 0.71400292078636,   0.635403391007978,  0.822308254446722, 0.877857040588335, 0.864265671245476, 0.433450219618618, 0.697164252367046, 0.412568516841575, 0.586627586272733, 0.617905053049757, 0.308426814834866],	//MC
	[0.497429376361348,  0.545347364699553, 0.788280917110089, 0.578724574327427,  0.663235306043286,  0.772537143243647, 0.638706135095199, 0.538453108494387, 0.887935381275257, 0.572515970409641, 0.290549550901104, 0.476180499897665, 0.526149424898544, 0.287001645266184],	//ML/R
	[0.656437768926678,  0.617260722143117, 0.656569986958435, 0.63741054520629,   0.55148452726771,   0.922379789905246, 0.790553566121791, 0.999688557334153, 0.426203575603164, 0.778770912265944, 0.652374065121788, 0.662264393455567, 0.73120100926333,  0.274563618133769],	//OMC
	[0.483341947292063,  0.494773052635464, 0.799434804259974, 0.628789194186491,  0.633847969631333,  0.681354437033551, 0.671233869875345, 0.536121458625519, 0.849389745477645, 0.684067723274814, 0.389732973354501, 0.499972692291964, 0.577231818355874, 0.272773352088982],	//OML/R
	[0.493917051093473,  0.370423904816088, 0.532148929996192, 0.0629206658586336, 0.0904950078155216, 0.415494774080483, 0.54106107545574,  0.468181146095801, 0.158106484131194, 0.461125738338018, 0.83399612271067,  0.999828328674183, 0.827171977606305, 0.253225855459207],	//F
    [0.5, 0.333, 0.5, 1,   0.5, 1,  0.5, 0.5, 0.333, 0.333, 0.333] //GK
];

//	[DC, DL/R, DMC, DML/R, MC, ML/R, OMC, OML/R, F, GK]
var recLast = [
    [14.866375  ,   15.980742   ,   15.8932675  ,   15.5835325  ,   17.6955092  ,   16.6189141  ,   18.1255351  ,   15.6304867  ,   13.2762119  , 15    ],
    [18.95664   ,   22.895539   ,   23.1801296  ,   23.2813871  ,   26.8420884  ,   23.9940623  ,   27.8974544  ,   24.54323    ,   19.5088591  , 22.3  ]
];

//  [DL, DC, DR, DML, DMC, DMR, ML, MC, MR, OML, OMC, OMR, F]
var	positionsAll = [
    [2, 0,  2,  3,  1,  3,  4,  2,  4,  4,  3,  4,  4],	// D C
	[0,	2,	1,	1,	3,	2,	2,	4,	3,	3,	4,	4,	4],	// D L
	[1,	2,	0,	2,	3,	1,	3,	4,	2,	4,	4,	3,	4],	// D R
	[3,	1,	3,	2,	0,	2,	3,	1,	3,	4,	2,	4,	3],	// DM C
	[1,	3,	2,	0,	2,	1,	1,	3,	2,	2,	4,	3,	4],	// DM L
	[2,	3,	1,	1,	2,	0,	2,	3,	1,	3,	4,	2,	4],	// DM R
	[4,	2,	4,	3,	1,	3,	2,	0,	2,	3,	1,	3,	2],	// M C
	[2,	4,	3,	1,	3,	2,	0,	2,	1,	1,	3,	2,	4],	// M L
	[3,	4,	2,	2,	3,	1,	1,	2,	0,	2,	3,	1,	4],	// M R
	[4,	3,	4,	4,	2,	4,	3,	1,	3,	2,	0,	2,	1],	// OM C
	[3,	4,	4,	2,	4,	3,	1,	3,	2,	0,	2,	1,	3],	// OM L
	[4,	4,	3,	3,	4,	2,	2,	3,	1,	1,	2,	0,	3],	// OM R
    [4,	4,	4,	4,	3,	4,	4,	2,	4,	3,	1,	3,	0]	// F
];

var positionNames = ["D C", "D L", "D R", "DM C", "DM L", "DM R", "M C", "M L", "M R", "OM C", "OM L", "OM R", "F", "GK"];
var positionNames2 = ["DC", "DL/R", "DMC", "DML/R", "MC", "ML/R", "OMC", "OML/R", "F"];
var positionNames3 = ["DL", "DC", "DR", "DML", "DMC", "DMR", "ML", "MC", "MR", "OML", "OMC", "OMR", "F", "GK"];
var positionFullNames = [
/* EN */	["Defender Center", "Defender Left", "Defender Right", "Defensive Midfielder Center", "Defensive Midfielder Left", "Defensive Midfielder Right", "Midfielder Center", "Midfielder Left", "Midfielder Right", "Offensive Midfielder Center", "Offensive Midfielder Left", "Offensive Midfielder Right", "Forward", "Goalkeeper"],
/* JP */	["ディフェンダー 中央", "ディフェンダー 左", "ディフェンダー 右", "守備的ミッドフィルダー 中央", "守備的ミッドフィルダー 左", "守備的ミッドフィルダー 右", "ミッドフィルダー 中央", "ミッドフィルダー 左", "ミッドフィルダー 右", "攻撃的ミッドフィルダー 中央", "攻撃的ミッドフィルダー 左", "攻撃的ミッドフィルダー 右", "フォワード", "ゴールキーパー"],
/* P  */	["Obrońca środkowy", "Obrońca lewy", "Obrońca prawy", "Defensywny pomocnik środkowy", "Defensywny pomocnik lewy", "Defensywny pomocnik prawy", "Pomocnik środkowy", "Pomocnik lewy", "Pomocnik prawy", "Ofensywny pomocnik środkowy", "Ofensywny pomocnik lewy", "Ofensywny pomocnik prawy", "Napastnik", "Bramkarz"],
/* D  */	["Forsvar Centralt", "Forsvar Venstre", "Forsvar Højre", "Defensiv Midtbane Centralt", "Defensiv Midtbane Venstre", "Defensiv Midtbane Højre", "Midtbane Centralt", "Midtbane Venstre", "Midtbane Højre", "Offensiv Midtbane Centralt", "Offensiv Midtbane Venstre", "Offensiv Midtbane Højre", "Angriber", "Målmand"],
/* I  */	["Difensore Centrale", "Difensore Sinistro", "Difensore Destro", "Centrocampista Difensivo Centrale", "Centrocampista Difensivo Sinistro", "Centrocampista Difensivo Destro", "Centrocampista Centrale", "Centrocampista Sinistro", "Centrocampista Destro", "Centrocampista Offensivo Centrale", "Centrocampista Offensivo Sinistro", "Centrocampista Offensivo Destro", "Attaccante", "Portiere"],
/* H  */	["Defensa Central", "Defensa Izquierdo", "Defensa Derecho", "Mediocampista Defensivo Central", "Mediocampista Defensivo Izquierdo", "Mediocampista Defensivo Derecho", "Mediocampista Central", "Mediocampista Izquierdo", "Mediocampista Derecho", "Mediocampista Ofensivo Central", "Mediocampista Ofensivo Izquierdo", "Mediocampista Ofensivo Derecho", "Delantero", "Portero"],
/* F  */	["Défenseur Central", "Défenseur Gauche", "Défenseur Droit", "Milieu défensif Central", "Milieu défensif Gauche", "Milieu défensif Droit", "Milieu Central", "Milieu Gauche", "Milieu Droit", "Milieu offensif Central", "Milieu offensif Gauche", "Milieu offensif Droit", "Attaquant", "Gardien de but"],
/* A  */	["Defender Center", "Defender Left", "Defender Right", "Defensive Midfielder Center", "Defensive Midfielder Left", "Defensive Midfielder Right", "Midfielder Center", "Midfielder Left", "Midfielder Right", "Offensive Midfielder Center", "Offensive Midfielder Left", "Offensive Midfielder Right", "Forward", "Goalkeeper"],
/* C  */	["Obrambeni Sredina", "Obrambeni Lijevo", "Obrambeni Desno", "Defenzivni vezni Sredina", "Defenzivni vezni Lijevo", "Defenzivni vezni Desno", "Vezni Sredina", "Vezni Lijevo", "Vezni Desno", "Ofenzivni vezni Sredina", "Ofenzivni vezni Lijevo", "Ofenzivni vezni Desno", "Napadač", "Golman"],
/* G  */	["Verteidiger Zentral", "Verteidiger Links", "Verteidiger Rechts", "Defensiver Mittelfeldspieler Zentral", "Defensiver Mittelfeldspieler Links", "Defensiver Mittelfeldspieler Rechts", "Mittelfeldspieler Zentral", "Mittelfeldspieler Links", "Mittelfeldspieler Rechts", "Offensiver Mittelfeldspieler Zentral", "Offensiver Mittelfeldspieler Links", "Offensiver Mittelfeldspieler Rechts", "Stürmer", "Torhüter"],
/* PO */	["Defesa Centro", "Defesa Esquerdo", "Defesa Direito", "Médio Defensivo Centro", "Médio Defensivo Esquerdo", "Médio Defensivo Direito", "Medio Centro", "Medio Esquerdo", "Medio Direito", "Medio Ofensivo Centro", "Medio Ofensivo Esquerdo", "Medio Ofensivo Direito", "Avançado", "Guarda-Redes"],
/* R  */	["Fundas Central", "Fundas Stânga", "Fundas Dreapta", "Mijlocas Defensiv Central", "Mijlocas Defensiv Stânga", "Mijlocas Defensiv Dreapta", "Mijlocas Central", "Mijlocas Stânga", "Mijlocas Dreapta", "Mijlocas Ofensiv Central", "Mijlocas Ofensiv Stânga", "Mijlocas Ofensiv Dreapta", "Atacant", "Portar"],
/* T  */	["Defans Orta", "Defans Sol", "Defans Sağ", "Defansif Ortasaha Orta", "Defansif Ortasaha Sol", "Defansif Ortasaha Sağ", "Ortasaha Orta", "Ortasaha Sol", "Ortasaha Sağ", "Ofansif Ortasaha Orta", "Ofansif Ortasaha Sol", "Ofansif Ortasaha Sağ", "Forvet", "Kaleci"],
/* RU */	["Defender Center", "Defender Left", "Defender Right", "Defensive Midfielder Center", "Defensive Midfielder Left", "Defensive Midfielder Right", "Midfielder Center", "Midfielder Left", "Midfielder Right", "Offensive Midfielder Center", "Offensive Midfielder Left", "Offensive Midfielder Right", "Forward", "Goalkeeper"],
/* CE */	["Obránce Střední", "Obránce Levý", "Obránce Pravý", "Defenzivní Záložník Střední", "Defenzivní Záložník Levý", "Defenzivní Záložník Pravý", "Záložník Střední", "Záložník Levý", "Záložník Pravý", "Ofenzivní záložník Střední", "Ofenzivní záložník Levý", "Ofenzivní záložník Pravý", "Útočník", "Gólman"],
/* HU */	["Védő , középső", "Védő , bal oldali", "Védő , jobb oldali", "Védekező Középpályás , középső", "Védekező Középpályás , bal oldali", "Védekező Középpályás , jobb oldali", "Középpályás , középső", "Középpályás , bal oldali", "Középpályás , jobb oldali", "Támadó középpályás , középső", "Támadó középpályás , bal oldali", "Támadó középpályás , jobb oldali", "Csatár", "Kapus"],
/* GE */	["მცველი ცენტრალური", "მცველი მარცხენა", "მცველი მარჯვენა", "საყრდენი ნახევარმცველი ცენტრალური", "საყრდენი ნახევარმცველი მარცხენა", "საყრდენი ნახევარმცველი მარჯვენა", "ნახევარმცველი ცენტრალური", "ნახევარმცველი მარცხენა", "ნახევარმცველი მარჯვენა", "შემტევი ნახევარმცველი ცენტრალური", "შემტევი ნახევარმცველი მარცხენა", "შემტევი ნახევარმცველი მარჯვენა", "თავდამსხმელი", "მეკარე"],
/* FI */	["Puolustaja Keski", "Puolustaja Vasen", "Puolustaja Oikea", "Puolustava Keskikenttä Keski", "Puolustava Keskikenttä Vasen", "Puolustava Keskikenttä Oikea", "Keskikenttä Keski", "Keskikenttä Vasen", "Keskikenttä Oikea", "Hyökkäävä Keskikenttä Keski", "Hyökkäävä Keskikenttä Vasen", "Hyökkäävä Keskikenttä Oikea", "Hyökkääjä", "Maalivahti"],
/* SV */	["Försvarare Central", "Försvarare Vänster", "Försvarare Höger", "Defensiv Mittfältare Central", "Defensiv Mittfältare Vänster", "Defensiv Mittfältare Höger", "Mittfältare Central", "Mittfältare Vänster", "Mittfältare Höger", "Offensiv Mittfältare Central", "Offensiv Mittfältare Vänster", "Offensiv Mittfältare Höger", "Anfallare", "Målvakt"],
/* NO */	["Forsvar Sentralt", "Forsvar Venstre", "Forsvar Høyre", "Defensiv Midtbane Sentralt", "Defensiv Midtbane Venstre", "Defensiv Midtbane Høyre", "Midtbane Sentralt", "Midtbane Venstre", "Midtbane Høyre", "Offensiv Midtbane Sentralt", "Offensiv Midtbane Venstre", "Offensiv Midtbane Høyre", "Angrep", "Keeper"],
/* SC */	["Defender Centre", "Defender Left", "Defender Richt", "Defensive Midfielder Centre", "Defensive Midfielder Left", "Defensive Midfielder Richt", "Midfielder Centre", "Midfielder Left", "Midfielder Richt", "Offensive Midfielder Centre", "Offensive Midfielder Left", "Offensive Midfielder Richt", "Forward", "Goalkeeper"],
/* VL */	["Verdediger Centraal", "Verdediger Links", "Verdediger Rechts", "Verdedigende Middenvelder Centraal", "Verdedigende Middenvelder Links", "Verdedigende Middenvelder Rechts", "Middenvelder Centraal", "Middenvelder Links", "Middenvelder Rechts", "Aanvallende Middenvelder Centraal", "Aanvallende Middenvelder Links", "Aanvallende Middenvelder Rechts", "Aanvaller", "Doelman"],
/* BR */	["Zagueiro Central", "Zagueiro Esquerdo", "Zagueiro Direito", "Volante Central", "Volante Esquerdo", "Volante Direito", "Meio-Campista Central", "Meio-Campista Esquerdo", "Meio-Campista Direito", "Meia Ofensivo Central", "Meia Ofensivo Esquerdo", "Meia Ofensivo Direito", "Atacante", "Goleiro"],
/* GR */	["Αμυντικός Κεντρικός", "Αμυντικός Αριστερός", "Αμυντικός Δεξιός", "Αμυντικός Μέσος Κεντρικός", "Αμυντικός Μέσος Αριστερός", "Αμυντικός Μέσος Δεξιός", "Μέσος Κεντρικός", "Μέσος Αριστερός", "Μέσος Δεξιός", "Επιθετικός μέσος Κεντρικός", "Επιθετικός μέσος Αριστερός", "Επιθετικός μέσος Δεξιός", "Επιθετικός", "Τερματοφύλακας"],
/* BG */	["Защитник Централен", "Защитник Ляв", "Защитник Десен", "Дефанзивен Халф Централен", "Дефанзивен Халф Ляв", "Дефанзивен Халф Десен", "Халф Централен", "Халф Ляв", "Халф Десен", "Атакуващ Халф Централен", "Атакуващ Халф Ляв", "Атакуващ Халф Десен", "Нападател"],
/* ID */	["Bek Tengah", "Bek Kiri", "Bek Kanan", "Gelandang Bertahan Tengah", "Gelandang Bertahan Kiri", "Gelandang Bertahan Kanan", "Gelandang Tengah", "Gelandang Kiri", "Gelandang Kanan", "Gelandang Serang Tengah", "Gelandang Serang Kiri", "Gelandang Serang Kanan", "Penyerang", "Penjaga Gawang"],
/* CL */	["Defensa Centre", "Defensa Esquerra", "Defensa Dreta", "Migcampista Defensiu Centre", "Migcampista Defensiu Esquerra", "Migcampista Defensiu Dreta", "Migcampista Centre", "Migcampista Esquerra", "Migcampista Dreta", "Migcampista Ofensiu Centre", "Migcampista Ofensiu Esquerra", "Migcampista Ofensiu Dreta", "Davanter", "Porter"],
/* CQ */	["後衛 中", "後衛 左", "後衛 右", "防守中場 中", "防守中場 左", "防守中場 右", "中場 中", "中場 左", "中場 右", "進攻中場 中", "進攻中場 左", "進攻中場 右", "前鋒", "龍門"],
/* EE */	["Kaitsja Kesk", "Kaitsja Vasak", "Kaitsja Parem", "Kaitsev Kesmängija Kesk", "Kaitsev Kesmängija Vasak", "Kaitsev Kesmängija Parem", "Keskmängija Kesk", "Keskmängija Vasak", "Keskmängija Parem", "Ründav Keskmängija Kesk", "Ründav Keskmängija Vasak", "Ründav Keskmängija Parem", "Ründaja", "Väravavaht"],
/* UA */	["Захисник Центральний","Захисник Лівий","Захисник Правий","Опорний півзахисник Центральний","Опорний півзахисник Лівий","Опорний півзахисник Правий","Півзахисник Центральний","Півзахисник Лівий","Півзахисник Правий","Атакувальний півзахисник Центральний","Атакувальний півзахисник Лівий","Атакувальний півзахисник Правий","Нападник","Воротар"],
];

var skilltable = $("div.main_center div.column2_a table.skill_table");
var infotable = $("div.main_center div.column2_a table.info_table");
var MR = Math.round;
var MP = Math.pow;
var ML = Math.log;

if (location.href.indexOf("/players/") != -1) {
    document.findPositionIndex = function (position) {
        var index = -1;
        for (var i = 0; i < positionFullNames.length; i++) {
            for (var j = 0; j < positionFullNames[i].length; j++) {
                if (position.indexOf(positionFullNames[i][j]) == 0) return j;
            }
        }
        return index;
    };

    document.getSkills = function (table) {
        var skillArray = [];
        var tableData = table.getElementsByTagName("td");
        if (tableData.length > 1) {
            for (var i = 0; i < 2; i++) {
                for (var j = i; j < tableData.length; j += 2) {
                    if (tableData[j].innerHTML.indexOf("star.png") > 0) {
                        skillArray.push(20);
                    }
                    else if (tableData[j].innerHTML.indexOf("star_silver.png") > 0) {
                        skillArray.push(19);
                    }
                    else if (tableData[j].textContent.length != 0) {
                        skillArray.push(tableData[j].textContent);
                    }
                }
            }
        }
        return skillArray;
    };

    const funFix1 = (i) => {
        i = (MR(i * 10) / 10).toFixed(1);
        return i;
    }

    const funFix2 = (i) => {
        i = (MR(i * 100) / 100).toFixed(2);
        return i;
    }

    const funFix3 = (i) => {
        i = (MR(i * 1000) / 1000).toFixed(3);
        return i;
    }

    var en = new Intl.NumberFormat("en-US");

    $("body").append("<div id=\"rank\" style=\"display:none\"></div>");
    $(function(){
        $("#rank").load("https://trophymanager.com/national-teams/rankings/ #tab0 table", function(){
            rankArray();
        });
    });
    var nation_rank = [];
    function rankArray(){
        var tr = $("table.zebra.hover tr:gt(0)");
        for(i = 0; i < 20; i++ ){
            var cells = tr.eq(i).children("td").eq(2);
            nation_rank[i] = cells.find("ib").attr("alt").slice(-2);
        }
        return nation_rank;
    }

    function computeRating(table, skills) {
        var REREC = [[], [], []];
        var REREC2 = [];
        var FP = [];
        var positionCell = document.getElementsByClassName("favposition long")[0].childNodes;
        var positionArray = [];
        if (positionCell.length == 1) {
            positionArray[0] = positionCell[0].textContent;
        }
        else if (positionCell.length == 2) {
            positionArray[0] = positionCell[0].textContent + positionCell[1].textContent;
        }
        else if (positionCell[1].className == "split") {
            positionArray[0] = positionCell[0].textContent + positionCell[3].textContent;
            positionArray[1] = positionCell[2].textContent + positionCell[3].textContent;
        }
        else if (positionCell[3].className == "f") {
            positionArray[0] = positionCell[0].textContent + positionCell[1].textContent;
            positionArray[1] = positionCell[3].textContent;
        }
        else {
            positionArray[0] = positionCell[0].textContent + positionCell[1].textContent;
            positionArray[1] = positionCell[0].textContent + positionCell[3].textContent;
        }

        var positionFullnames2 = Array.prototype.concat.apply([], positionFullNames);
        var positionIndex2 = [];
        for (i = 0; i < positionArray.length; i++) {
            positionIndex2[i] = positionFullnames2.indexOf(positionArray[i]);
            while (positionIndex2[i] > 13) positionIndex2[i] -= 14;
        }

        var gettr = document.getElementsByTagName("tr");
        var SI = new String(gettr[6].getElementsByTagName("td")[0].innerHTML).replace(/,/g, "");
        var rou = gettr[8].getElementsByTagName("td")[0].innerHTML;
        var rou2 = (3 / 100) * (100 - (100) * MP(Math.E, -rou * 0.035));
        var rou3 = rou;
        rou = MP(5 / 3, Math.LOG2E * ML(rou * 10));
        for (var i = 0; i < positionArray.length; i++) {
            var positionIndex = document.findPositionIndex(positionArray[i]);
            FP[i] = positionIndex;
            FP[i + 1] = FP[i];
            if (positionIndex > -1) {
                REREC2[i] = document.calculateREREC2(positionIndex, skills, SI);
            }
            if (i == 0) {
                REREC = document.calculateREREC(positionIndex, skills, SI, rou2);
            }
        }

        const retire = gettr[7].getElementsByTagName("td")[0].innerHTML.indexOf("retire.gif") > 0 ? true : false;
        const notGK = positionIndex != 13 ? true : false;

        if (notGK) {
            var phySum = skills[0] * 1 + skills[1] * 1 + skills[2] * 1 + skills[10] * 1;
            var tacSum = skills[3] * 1 + skills[4] * 1 + skills[5] * 1 + skills[6] * 1;
            var tecSum = skills[7] * 1 + skills[8] * 1 + skills[9] * 1 + skills[11] * 1 + skills[12] * 1 + skills[13] * 1;
            var weight = 263533760000;
        }
        else {
            var phySum = skills[0] * 1 + skills[1] * 1 + skills[2] * 1 + skills[7] * 1;
            var tacSum = skills[4] * 1 + skills[6] * 1 + skills[8] * 1;
            var tecSum = skills[3] * 1 + skills[5] * 1 + skills[9] * 1 + skills[10] * 1;
            var weight = 48717927500;
        }
        var allSum = phySum + tacSum + tecSum;
        var remainder = funFix1(MP(2, ML(weight * SI) / ML(MP(2, 7))) - allSum);

        var FP2 = [FP[0], FP[1]];
        for (i = 0; i < FP.length; i++) {
            for (j = 0; 2 + j <= FP[i]; j += 2) FP[i]--;
        }

        var goldstar = 0;
        var skillsB = [];
        for (j = 0; j < 2; j++) {
            for (i = 0; i < skills.length; i++) {
                if (j == 0 && skills[i] == 20) goldstar++;
                if (j == 1) {
                    if (skills[i] != 20) skillsB[i] = skills[i] * 1 + remainder / (skills.length - goldstar);
                    else skillsB[i] = skills[i];
                }
            }
        }
        var skillsB_rou = [];
        for (i = 0; i < skills.length; i++) {
            if (i == 1) skillsB_rou[1] = skillsB[1];
            else skillsB_rou[i] = skillsB[i] * 1 + rou2;
        }

        var { ageMonths, month, year } = calc_age();
        var { staPrice, maxPrice } = calc_SellToAgent();
        var { weight, session, newPlayer, TI, session2, wage } = calc_TI();
        var { R5FP0, R5FP1, posGain, posKeep, headerBonus, ckBonus, fkBonus, pkBonus, allBonus } = calc_R5bonus();
        var { bep, futureSTA } = bep();
        var { shotregular, shotlong, shothead } = finish_type();
        var { R5FP, minR } = calc_stamina_effect();
        var { peak, R5RECstar } = calc_R5REC();
        var { i, hidden, R5all, adap, aggr, prof, minR5Value, maxR5Value, minR5Value2, maxR5Value2, R5Value, R5Value2, nation } = calc_VALUE();
        var { cap, cap2, cap3, weightDefault } = calc_captaincy();

        var skilltable = document.getElementsByClassName("skill_table zebra")[0];
        var skillth = skilltable.getElementsByTagName("th");
        var skilltd = skilltable.getElementsByTagName("td");
        var skill2 = [];
        if (notGK) {
            var skill2array = [skillsB_rou[0], skillsB_rou[7], skillsB_rou[1], skillsB_rou[8], skillsB_rou[2], skillsB_rou[9], skillsB_rou[3], skillsB_rou[10], skillsB_rou[4], skillsB_rou[11], skillsB_rou[5], skillsB_rou[12], skillsB_rou[6], skillsB_rou[13]];
            for (i = 0; i < 14; i++) {
                skillth[i].style.width = "100px";
                skilltd[i].style.width = "40px";
                skill2[i] = document.createElement("small");
                skill2[i].setAttribute("style", "color: moccasin;");
                skill2[i].innerHTML = " (" + funFix2(skill2array[i]) + ")";
                skilltd[i].appendChild(skill2[i]);
            }
        }
        else {
            var skill2array = [skillsB_rou[0], skillsB_rou[3], skillsB_rou[1], skillsB_rou[4], skillsB_rou[2], skillsB_rou[5], "", skillsB_rou[6], "", skillsB_rou[7], "", skillsB_rou[8], "", skillsB_rou[9], "", skillsB_rou[10]];
            for (i = 0; i < 16; i++) {
                skillth[i].style.width = "100px";
                skilltd[i].style.width = "40px";
                skill2[i] = document.createElement("small");
                skill2[i].setAttribute("style", "color: moccasin;");
                if (skill2array[i] != "") skill2[i].innerHTML = " (" + funFix2(skill2array[i]) + ")";
                skilltd[i].appendChild(skill2[i]);
            }
        }

//	### infotable #################################################################################

        if (FP[0] != FP[1]) {
            var RERECb = "<tr id=\"tr_RERECb\" style=\"color:gold;\"><th><b>REC</b></th><td>" + REREC[0][FP[0]] + "/" + REREC[0][FP[1]] + "</td></tr>";
            var R5 = "<tr id=\"tr_R5\" style=\"color:gold;\"><th><b>RatingR6</b></th><td>" + R5FP0 + "/" + R5FP1 + "</td></tr>";
        }
        else {
            var RERECb = "<tr id=\"tr_RERECb0\" style=\"color:gold;\"><th><b>REC</b></th><td>" + REREC[0][FP[0]] + "</td></tr>";
            var R5 = "<tr id=\"tr_R5\" style=\"color:gold;\"><th><b>RatingR6</b></th><td>" + R5FP0 + "</td></tr>";
        }
        if (newPlayer == 0) {
        	var seasonTI = "<tr id=\"tr_seasonTI\"><th><b>Season TI</b></th><td id=\"td_seasonTI\">" + TI + " (" + funFix1(TI / session) + " x " + session2 + ")</td></tr>";
        }
        else {
            var seasonTI = "<tr id=\"tr_seasonTI\"><th><b>Season TI</b></th><td>---</td></tr>";
            if (wage == 30000) var newPlayerTI = "<tr id=\"tr_newPlayerSI\"><th><b>New Player TI</b></th><td>---</td></tr>";
            else {
                wage_rate = 23.75;
                var TI2 = MP(2, ML(weight * SI) / ML(MP(2, 7))) - MP(2, ML(weight * wage / (wage_rate)) / ML(MP(2, 7)));
                var newPlayerTI = "<tr id=\"tr_newPlayerSI\"><th><b>New Player TI</b></th><td>" + MR(TI2 * 10) + "</td></tr>";
            }
        }

//	### R5table ###################################################################################

        const trbg333333 = "<tr style=\"background-color: #333333\">";
        const td = "<td></td>";
        const tdright = "<td align=\"right\">";
        const tdright42 = "<td align=\"right\" width=\"42px\">";
        const tdright48 = "<td align=\"right\" width=\"48px\">";

        // R5table0 ###############################################################################
        var table_border = "border-left:solid 1px; border-right:solid 1px; border-top:solid 1px; border-bottom:solid 1px";
        var R5table =   "<div class=\"std\" id=\"R5table_div\">"+
                            "<div id=\"R5table0_div\">"+
                                "<table id=\"R5table0\" style=\"margin-top:10px; margin-bottom:10px; border-left:solid 1px; border-right:solid 1px; border-bottom:solid 1px\" cellspascing=\"0\" cellpadding=\"0\">"+
                                    "<tbody></tbody>"+
                                "</table>"+
                            "</div>"+
                        "</div>";
        if (hidden[0].innerHTML != "") $("#hidden_skill_table").after(R5table);
        else $("div.hidden_skills_text.align_center").after(R5table);
        var R5tbody0 = $("#R5table0 > tbody");
        var R5_header = [];
        var R5_row = [];
        var R5pure_row = [];
        var RouEffect_row = [];
        var gain_row = [];
        var keep_row = [];
        var headerbonus_row = [];
        var ckbonus_row = [];
        var fkbonus_row = [];
        var pkbonus_row = [];
        var R5stamina_row = [];
        var R5ave_row = [];
        var flg_btn = [];

        for (i = 0; i < positionArray.length; i++) {
            R5_header[i] =
                trbg333333+
                    "<td colspan=\"9\" style=\"border-bottom:solid 1px; border-top:solid 1px; padding-left:5px\" id=\"tdPosName\"><b>Position : " + positionArray[i] + "</b></td>"+
                "</tr>";
            R5_row[i] =
                "<tr>"+
                    "<td style=\"padding-left:5px\">RatingR6 : </td>"+
                    td+
                    tdright + R5FP[i] + "</td>"+
                    td+
                    td+
                    td+
                    td+
                    "<td align=\"right\" colspan=\"2\">"+
                        "<span class=\"button\" style=\"width:80px\" id=\"detail_btn" + i + "\">"+
                            "<span id=\"btn_text" + i + "\" class=\"button_border\" style=\"width:78px; padding: 0;\">Detail</span>"+
                        "</span>"+
                    "</td>"+
                "</tr>";
            R5stamina_row[i] =
                "<tr class=\"odd\">"+
                    tdright + "Stamina Effect</td>"+
                    tdright42 + "65\'</td>"+
                    tdright48 + minR[i][1] + "</td>"+
                    tdright42 + "75\'</td>"+
                    tdright48 + minR[i][2] + "</td>"+
                    tdright42 + "85\'</td>"+
                    tdright48 + minR[i][3] + "</td>"+
                    tdright42 + "95'</td>"+
                    tdright48 + minR[i][4] + "</td>"+
                "</tr>";
            R5ave_row[i] =
                "<tr>"+
                    tdright+"Average</td>"+
                    tdright + "1\'-74\'</td>"+
                    tdright + funFix2((R5FP[i] * 64 + minR[i][1] * 10) / 74) + "</td>"+
                    tdright + "1\'-84\'</td>"+
                    tdright + funFix2((R5FP[i] * 64 + minR[i][1] * 10 + minR[i][2] * 10) / 84) + "</td>"+
                    tdright + "1\'-94\'</td>"+
                    tdright + funFix2((R5FP[i] * 64 + minR[i][1] * 10 + minR[i][2] * 10 + minR[i][3] * 10) / 94) + "</td>"+
                    td+
                    td+
                "</tr>";
            R5pure_row[i] =
                "<tr class=\"detail" + i + "\" style=\"background-color:#649024;\">"+
                    "<td align=\"right\" colspan=\"2\">R5pure</td>"+
                    tdright + REREC[1][FP[i]] + "</td>"+
                    td+
                    td+
                    td+
                    td+
                    td+
                    td+
                "</tr>";
            RouEffect_row[i] =
                "<tr class=\"detail" + i + "\">"+
                    "<td align=\"right\" colspan=\"2\">Routine Effect</td>"+
                    tdright + funFix2(REREC[2][FP[i]] * 1 - REREC[1][FP[i]] * 1) + "</td>"+
                    td+
                    td+
                    td+
                    td+
                    td+
                    td+
                "</tr>";
            gain_row[i] =
                "<tr class=\"detail" + i + "\" style=\"background-color:#649024;\">"+
                    "<td align=\"right\" colspan=\"2\">Gain Bonus</td>"+
                    tdright + funFix2(posGain[FP[i]]) + "</td>"+
                    td+
                    td+
                    td+
                    td+
                    td+
                    td+
                "</tr>";
            keep_row[i] =
                "<tr class=\"detail" + i + "\">"+
                    "<td align=\"right\" colspan=\"2\">Keep Bonus</td>"+
                    tdright + funFix2(posKeep[FP[i]]) + "</td>"+
                    td+
                    td+
                    td+
                    td+
                    td+
                    td+
                "</tr>";
            headerbonus_row[i] =
                "<tr class=\"detail" + i + "\" style=\"background-color:#649024;\">"+
                    "<td align=\"right\" colspan=\"2\">Header Bonus</td>"+
                    tdright + headerBonus + "</td>"+
                    td+
                    td+
                    td+
                    td+
                    td+
                    td+
                "</tr>";
            ckbonus_row[i] =
                "<tr class=\"detail" + i + "\">"+
                    "<td align=\"right\" colspan=\"2\">CK Bonus</td>"+
                    tdright + ckBonus + "</td>"+
                    td+
                    td+
                    td+
                    td+
                    td+
                    td+
                "</tr>";
            fkbonus_row[i] =
                "<tr class=\"detail" + i + "\" style=\"background-color:#649024;\">"+
                    "<td align=\"right\" colspan=\"2\">FK Bonus</td>"+
                    tdright + fkBonus + "</td>"+
                    td+
                    td+
                    td+
                    td+
                    td+
                    td+
                "</tr>";
            pkbonus_row[i] =
                "<tr class=\"detail" + i + "\">"+
                    "<td align=\"right\" colspan=\"2\">PK Bonus</td>"+
                    tdright + pkBonus + "</td>"+
                    td+
                    td+
                    td+
                    td+
                    td+
                    td+
                "</tr>";
            if (notGK) R5tbody0.append(R5_header[i], R5_row[i], R5pure_row[i], RouEffect_row[i], gain_row[i], keep_row[i], headerbonus_row[i], ckbonus_row[i], fkbonus_row[i], pkbonus_row[i], R5stamina_row[i], R5ave_row[i]);
            else R5tbody0.append(R5_header[i], R5_row[i], R5pure_row[i], RouEffect_row[i], R5stamina_row[i], R5ave_row[i]);
            $(".detail" + i).hide();
            flg_btn[i] = "hide";
        }
        var btn_functions = [];
        for (let i = 0; i < positionArray.length; i++) {
            (function () {
                $("#detail_btn" + i).click(function () {
                    if (flg_btn[i] == "hide") {
                        flg_btn[i] = "show";
                        $("#btn_text" + i).text("Hide Detail");
                    }
                    else {
                        flg_btn[i] = "hide";
                        $("#btn_text" + i).text("Show Detail");
                    }
                    $(".detail" + i).slideToggle();
                });
                btn_functions.push(function () { });
            })();
            btn_functions[i]();
        }

        if (positionArray.length == 2 && FP[0] == FP[1]) {
            var newPosName = "<b>Position : " + positionCell[0].textContent + " " + positionCell[1].textContent + "/" + positionCell[3].textContent + "</b>";
            $("#tdPosName").html(newPosName);
            $("#R5table0 > tbody > tr:gt(11)").remove();
        }

        if (notGK) {
            for (i = 0; i < 9; i++) {
                REREC[0][i] = funFix3(REREC[0][i] * 1);
                REREC[2][i] = funFix2(REREC[2][i] * 1 + allBonus * 1 + posGain[i] * 1 + posKeep[i] * 1);
                if (REREC[2][i] >= 100) REREC[2][i] = funFix1(REREC[2][i]);
            }

            var ADir = funFix2((skillsB_rou[1] * 0.125 + skillsB_rou[2] * 0.29166666 + (skillsB_rou[5] + skillsB_rou[6]) * 0.08333333 + skillsB_rou[7] * 0.25 + skillsB_rou[9] * 0.16666666) * 5);
            var AWin = funFix2((skillsB_rou[0] * 0.04347826 + (skillsB_rou[1] + skillsB_rou[5]) * 0.08695652 + skillsB_rou[2] * 0.26086956 + skillsB_rou[8] * 0.34782608 + skillsB_rou[9] * 0.17391304) * 5);
            var ASho = funFix2(((skillsB_rou[1] + skillsB_rou[2] + skillsB_rou[5] + skillsB_rou[6]) * 0.09523809 + skillsB_rou[7] * 0.33333333 + skillsB_rou[9] * 0.28571428) * 5);
            var ALon = funFix2(((skillsB_rou[1] + skillsB_rou[5] + skillsB_rou[6]) * 0.08333333 + skillsB_rou[7] * 0.33333333 + skillsB_rou[8] * 0.25 + skillsB_rou[9] * 0.16666666) * 5);
            var AThr = funFix2(((skillsB_rou[1] + skillsB_rou[5] + skillsB_rou[6] + skillsB_rou[8] + skillsB_rou[9]) * 0.1 + (skillsB_rou[2] + skillsB_rou[7]) * 0.25) * 5);
            var DDir = funFix2((skillsB_rou[1] * 0.052631579 + (skillsB_rou[2] + skillsB_rou[6]) * 0.105263158 + skillsB_rou[3] * 0.421052632 + (skillsB_rou[4] + skillsB_rou[5]) * 0.157894737) * 5);
            var DWin = funFix2(((skillsB_rou[0] + skillsB_rou[1] + skillsB_rou[5] + skillsB_rou[6]) * 0.045454545 + (skillsB_rou[2] + skillsB_rou[3]) * 0.227272727 + skillsB_rou[4] * 0.363636364) * 5);
            var DSho = funFix2(((skillsB_rou[1] + skillsB_rou[2]) * 0.05 + skillsB_rou[3] * 0.25 + skillsB_rou[4] * 0.4 + skillsB_rou[5] * 0.1 + skillsB_rou[6] * 0.15) * 5);
            var DLon = funFix2(((skillsB_rou[0] + skillsB_rou[3] + skillsB_rou[10]) * 0.2 + skillsB_rou[1] * 0.04 + (skillsB_rou[2] + skillsB_rou[5] + skillsB_rou[6]) * 0.08 + skillsB_rou[4] * 0.12) * 5);
            var DThr = funFix2(((skillsB_rou[1] + skillsB_rou[5] + skillsB_rou[6]) * 0.071428571 + skillsB_rou[2] * 0.357142857 + (skillsB_rou[3] + skillsB_rou[4]) * 0.214285714) * 5);

            var SSho = funFix2((shotregular * 0.534 + shotlong * 0.339 + shothead * 0.127) * 5);
            var SThr = funFix2((shotregular * 0.703 + shotlong * 0.151 + shothead * 0.146) * 5);
            var SWin = funFix2((shotregular * 0.252 + shotlong * 0.035 + shothead * 0.713) * 5);
            var SDir = funFix2((shotregular * 0.339 + shotlong * 0.342 + shothead * 0.319) * 5);
            var SLon = funFix2((shotregular * 0.271 + shotlong * 0.037 + shothead * 0.692) * 5);

            // R5table1 ###########################################################################
            var R5table1 =
                "<div id=\"R5table1_div\">"+
                    "<table id=\"R5table1\" style=\"margin-bottom:10px; " + table_border + "\" cellspascing=\"0\" cellpadding=\"0\">"+
                        "<tbody></tbody>"+
                    "</table>"+
                "</div>";
            $("#R5table_div").append(R5table1);
            var R5table1_header = "<thead><tr style=\"background-color: #333333\"><th colspan=\"10\">All Positions Rating : NOT applied Adaptability</th></tr><tr style=\"background-color: #333333\"><th></th><th>DC</th><th>DLR</th><th>DMC</th><th>DMLR</th><th>MC</th><th>MLR</th><th>OMC</th><th>OMLR</th><th>F</th></tr></thead>";
            var RERECb_row = "<tr id=\"RERECb_row\"><td style=\"padding-left:5px\">REC</td></tr>";
            var R5all_row = "<tr id=\"R5all_row\" class=\"odd\"><td style=\"padding-left:5px\">R6</td></tr>";
            $("#R5table1 > tbody").before(R5table1_header);
            $("#R5table1").find("th").attr("align", "center");
            $("#R5table1").find("th").attr("style", "border-bottom:solid 1px");
            $("#R5table1 > tbody").append(RERECb_row, R5all_row);
            for (i = 0; i < 9; i++) {
                $("#R5table1 > tbody > tr:eq(0)").append("<td align=\"center\">" + REREC[0][i] + "</td>");
                $("#R5table1 > tbody > tr:eq(1)").append("<td align=\"center\">" + REREC[2][i] + "</td>");
            }

            // R5table2 ###########################################################################
            var R5table2 = "<div id=\"R5table2_div\">"+
                                "<table id=\"R5table2\" style=\"margin-bottom:10px; " + table_border + "\" cellspascing=\"0\" cellpadding=\"0\">"+
                                    "<tbody></tbody>"+
                                "</table>"+
                            "</div>";
            var R5table2_header = "<thead><tr style=\"background-color: #333333\"><th colspan=\"10\">RatingR6 by Attacking Style (1-115)</th></tr><tr style=\"background-color: #333333\"><th></th><th>Short</th><th>Through</th><th>Wings</th><th>Direct</th><th>Long</th></tr></thead>";
            var assist_row = "<tr><td style=\"padding-left:5px\">Assist</td><td>" + ASho + "</td><td>" + AThr + "</td><td>" + AWin + "</td><td>" + ADir + "</td><td>" + ALon + "</td></tr>";
            var defence_row = "<tr class=\"odd\"><td style=\"padding-left:5px\">Defence</td><td>" + DSho + "</td><td>" + DThr + "</td><td>" + DWin + "</td><td>" + DDir + "</td><td>" + DLon + "</td></tr>";
            var shooting_row = "<tr><td style=\"padding-left:5px\">Shooting</td><td>" + SSho + "</td><td>" + SThr + "</td><td>" + SWin + "</td><td>" + SDir + "</td><td>" + SLon + "</td></tr>";
            $("#R5table_div").append(R5table2);
            $("#R5table2 > tbody").before(R5table2_header);
            $("#R5table2").find("th").attr("align", "center");
            $("#R5table2").find("th").attr("style", "border-bottom:solid 1px");
            $("#R5table2 > tbody").append(assist_row, defence_row, shooting_row);
            $("#R5table2 > tbody > tr").eq(0).children("td:gt(0)").attr("style", "padding-right:20px;");
            $("#R5table2 > tbody > tr").eq(0).children("td:gt(0)").attr("align", "right");
            $("#R5table2 > tbody > tr").eq(1).children("td:gt(0)").attr("style", "padding-right:20px;");
            $("#R5table2 > tbody > tr").eq(1).children("td:gt(0)").attr("align", "right");
            $("#R5table2 > tbody > tr").eq(2).children("td:gt(0)").attr("style", "padding-right:20px;");
            $("#R5table2 > tbody > tr").eq(2).children("td:gt(0)").attr("align", "right");

            // R5table10 ##########################################################################
            var R5AS = [];
            var R5AT = [];
            var R5AW = [];
            var R5AD = [];
            var R5AL = [];
            var R5AB = [];
            var R5AS2 = [];
            var R5AT2 = [];
            var R5AW2 = [];
            var R5AD2 = [];
            var R5AL2 = [];
            var R5AB2 = [];
            var R5DS = [];
            var R5DT = [];
            var R5DW = [];
            var R5DD = [];
            var R5DL = [];
            var R5DB = [];
            var R5DS2 = [];
            var R5DT2 = [];
            var R5DW2 = [];
            var R5DD2 = [];
            var R5DL2 = [];
            var R5DB2 = [];
            const sB = skillsB_rou;
            const wAS = weightASho;
            const wAS2 = weightASho2;
            const wAT = weightAThr;
            const wAT2 = weightAThr2;
            const wAW = weightAWin;
            const wAW2 = weightAWin2;
            const wAD = weightADir;
            const wAD2 = weightADir2;
            const wAL = weightALon;
            const wAL2 = weightALon2;
            const wAB = weightABal;
            const wAB2 = weightABal2;
            const wDS = weightDSho;
            const wDS2 = weightDSho2;
            const wDT = weightDThr;
            const wDT2 = weightDThr2;
            const wDW = weightDWin;
            const wDW2 = weightDWin2;
            const wDD = weightDDir;
            const wDD2 = weightDDir2;
            const wDL = weightDLon;
            const wDL2 = weightDLon2;
            const wDB = weightDBal;
            const wDB2 = weightDBal2;
            var tr_ASho = [];
            var tr_AThr = [];
            var tr_AWin = [];
            var tr_ADir = [];
            var tr_ALon = [];
            var tr_ABal = [];
            var tr_DSho = [];
            var tr_DThr = [];
            var tr_DWin = [];
            var tr_DDir = [];
            var tr_DLon = [];
            var tr_DBal = [];
            for (i = 0; i < 9; i++) {
                R5AS[i] = funFix2((sB[0] * wAS[[i]][0] + sB[1] * wAS[[i]][1] + sB[2] * wAS[[i]][2] + sB[5] * wAS[[i]][5] + sB[6] * wAS[[i]][6] + sB[7] * wAS[[i]][7] + sB[8] * wAS[[i]][8] + sB[9] * wAS[[i]][9]) * 5);
                R5AT[i] = funFix2((sB[0] * wAT[[i]][0] + sB[1] * wAT[[i]][1] + sB[2] * wAT[[i]][2] + sB[5] * wAT[[i]][5] + sB[6] * wAT[[i]][6] + sB[7] * wAT[[i]][7] + sB[8] * wAT[[i]][8] + sB[9] * wAT[[i]][9]) * 5);
                R5AW[i] = funFix2((sB[0] * wAW[[i]][0] + sB[1] * wAW[[i]][1] + sB[2] * wAW[[i]][2] + sB[5] * wAW[[i]][5] + sB[6] * wAW[[i]][6] + sB[7] * wAW[[i]][7] + sB[8] * wAW[[i]][8] + sB[9] * wAW[[i]][9]) * 5);
                R5AD[i] = funFix2((sB[0] * wAD[[i]][0] + sB[1] * wAD[[i]][1] + sB[2] * wAD[[i]][2] + sB[5] * wAD[[i]][5] + sB[6] * wAD[[i]][6] + sB[7] * wAD[[i]][7] + sB[8] * wAD[[i]][8] + sB[9] * wAD[[i]][9]) * 5);
                R5AL[i] = funFix2((sB[0] * wAL[[i]][0] + sB[1] * wAL[[i]][1] + sB[2] * wAL[[i]][2] + sB[5] * wAL[[i]][5] + sB[6] * wAL[[i]][6] + sB[7] * wAL[[i]][7] + sB[8] * wAL[[i]][8] + sB[9] * wAL[[i]][9]) * 5);
                R5AB[i] = funFix2((sB[0] * wAB[[i]][0] + sB[1] * wAB[[i]][1] + sB[2] * wAB[[i]][2] + sB[5] * wAB[[i]][5] + sB[6] * wAB[[i]][6] + sB[7] * wAB[[i]][7] + sB[8] * wAB[[i]][8] + sB[9] * wAB[[i]][9] ) * 5);
                R5DS[i] = funFix2((sB[0] * wDS[[i]][0] + sB[1] * wDS[[i]][1] + sB[2] * wDS[[i]][2] + sB[3] * wDS[[i]][3] + sB[4] * wDS[[i]][4] + sB[5] * wDS[[i]][5] + sB[6] * wDS[[i]][6] + sB[10] * wDS[[i]][10]) * 5);
                R5DT[i] = funFix2((sB[0] * wDT[[i]][0] + sB[1] * wDT[[i]][1] + sB[2] * wDT[[i]][2] + sB[3] * wDT[[i]][3] + sB[4] * wDT[[i]][4] + sB[5] * wDT[[i]][5] + sB[6] * wDT[[i]][6] + sB[10] * wDT[[i]][10]) * 5);
                R5DW[i] = funFix2((sB[0] * wDW[[i]][0] + sB[1] * wDW[[i]][1] + sB[2] * wDW[[i]][2] + sB[3] * wDW[[i]][3] + sB[4] * wDW[[i]][4] + sB[5] * wDW[[i]][5] + sB[6] * wDW[[i]][6] + sB[10] * wDW[[i]][10]) * 5);
                R5DD[i] = funFix2((sB[0] * wDD[[i]][0] + sB[1] * wDD[[i]][1] + sB[2] * wDD[[i]][2] + sB[3] * wDD[[i]][3] + sB[4] * wDD[[i]][4] + sB[5] * wDD[[i]][5] + sB[6] * wDD[[i]][6] + sB[10] * wDD[[i]][10]) * 5);
                R5DL[i] = funFix2((sB[0] * wDL[[i]][0] + sB[1] * wDL[[i]][1] + sB[2] * wDL[[i]][2] + sB[3] * wDL[[i]][3] + sB[4] * wDL[[i]][4] + sB[5] * wDL[[i]][5] + sB[6] * wDL[[i]][6] + sB[10] * wDL[[i]][10]) * 5);
                R5DB[i] = funFix2((sB[0] * wDB[[i]][0] + sB[1] * wDB[[i]][1] + sB[2] * wDB[[i]][2] + sB[3] * wDB[[i]][3] + sB[4] * wDB[[i]][4] + sB[5] * wDB[[i]][5] + sB[6] * wDB[[i]][6] + sB[10] * wDB[[i]][10]) * 5);
                R5AS2[i] = funFix2((sB[0] * wAS2[[i]][0] + sB[1] * wAS2[[i]][1] + sB[2] * wAS2[[i]][2] + sB[5] * wAS2[[i]][5] + sB[6] * wAS2[[i]][6] + sB[7] * wAS2[[i]][7] + sB[8] * wAS2[[i]][8] + sB[9] * wAS2[[i]][9]) * 5);
                R5AT2[i] = funFix2((sB[0] * wAT2[[i]][0] + sB[1] * wAT2[[i]][1] + sB[2] * wAT2[[i]][2] + sB[5] * wAT2[[i]][5] + sB[6] * wAT2[[i]][6] + sB[7] * wAT2[[i]][7] + sB[8] * wAT2[[i]][8] + sB[9] * wAT2[[i]][9]) * 5);
                R5AW2[i] = funFix2((sB[0] * wAW2[[i]][0] + sB[1] * wAW2[[i]][1] + sB[2] * wAW2[[i]][2] + sB[5] * wAW2[[i]][5] + sB[6] * wAW2[[i]][6] + sB[7] * wAW2[[i]][7] + sB[8] * wAW2[[i]][8] + sB[9] * wAW2[[i]][9]) * 5);
                R5AD2[i] = funFix2((sB[0] * wAD2[[i]][0] + sB[1] * wAD2[[i]][1] + sB[2] * wAD2[[i]][2] + sB[5] * wAD2[[i]][5] + sB[6] * wAD2[[i]][6] + sB[7] * wAD2[[i]][7] + sB[8] * wAD2[[i]][8] + sB[9] * wAD2[[i]][9]) * 5);
                R5AL2[i] = funFix2((sB[0] * wAL2[[i]][0] + sB[1] * wAL2[[i]][1] + sB[2] * wAL2[[i]][2] + sB[5] * wAL2[[i]][5] + sB[6] * wAL2[[i]][6] + sB[7] * wAL2[[i]][7] + sB[8] * wAL2[[i]][8] + sB[9] * wAL2[[i]][9]) * 5);
                R5AB2[i] = funFix2((sB[0] * wAB2[[i]][0] + sB[1] * wAB2[[i]][1] + sB[2] * wAB2[[i]][2] + sB[5] * wAB2[[i]][5] + sB[6] * wAB2[[i]][6] + sB[7] * wAB2[[i]][7] + sB[8] * wAB2[[i]][8] + sB[9] * wAB2[[i]][9]) * 5);
                R5DS2[i] = funFix2((sB[0] * wDS2[[i]][0] + sB[1] * wDS2[[i]][1] + sB[2] * wDS2[[i]][2] + sB[3] * wDS2[[i]][3] + sB[4] * wDS2[[i]][4] + sB[5] * wDS2[[i]][5] + sB[6] * wDS2[[i]][6] + sB[10] * wDS2[[i]][10]) * 5);
                R5DT2[i] = funFix2((sB[0] * wDT2[[i]][0] + sB[1] * wDT2[[i]][1] + sB[2] * wDT2[[i]][2] + sB[3] * wDT2[[i]][3] + sB[4] * wDT2[[i]][4] + sB[5] * wDT2[[i]][5] + sB[6] * wDT2[[i]][6] + sB[10] * wDT2[[i]][10]) * 5);
                R5DW2[i] = funFix2((sB[0] * wDW2[[i]][0] + sB[1] * wDW2[[i]][1] + sB[2] * wDW2[[i]][2] + sB[3] * wDW2[[i]][3] + sB[4] * wDW2[[i]][4] + sB[5] * wDW2[[i]][5] + sB[6] * wDW2[[i]][6] + sB[10] * wDW2[[i]][10]) * 5);
                R5DD2[i] = funFix2((sB[0] * wDD2[[i]][0] + sB[1] * wDD2[[i]][1] + sB[2] * wDD2[[i]][2] + sB[3] * wDD2[[i]][3] + sB[4] * wDD2[[i]][4] + sB[5] * wDD2[[i]][5] + sB[6] * wDD2[[i]][6] + sB[10] * wDD2[[i]][10]) * 5);
                R5DL2[i] = funFix2((sB[0] * wDL2[[i]][0] + sB[1] * wDL2[[i]][1] + sB[2] * wDL2[[i]][2] + sB[3] * wDL2[[i]][3] + sB[4] * wDL2[[i]][4] + sB[5] * wDL2[[i]][5] + sB[6] * wDL2[[i]][6] + sB[10] * wDL2[[i]][10]) * 5);
                R5DB2[i] = funFix2((sB[0] * wDB2[[i]][0] + sB[1] * wDB2[[i]][1] + sB[2] * wDB2[[i]][2] + sB[3] * wDB2[[i]][3] + sB[4] * wDB2[[i]][4] + sB[5] * wDB2[[i]][5] + sB[6] * wDB2[[i]][6] + sB[10] * wDB2[[i]][10]) * 5);
            }
            var R5Assist_ShoAll = [R5AS[1], R5AS[0], R5AS[1], R5AS[3], R5AS[2], R5AS[3], R5AS[5], R5AS[4], R5AS[5], R5AS[7], R5AS[6], R5AS[7], R5AS[8]];
            var R5Assist_ThrAll = [R5AT[1], R5AT[0], R5AT[1], R5AT[3], R5AT[2], R5AT[3], R5AT[5], R5AT[4], R5AT[5], R5AT[7], R5AT[6], R5AT[7], R5AT[8]];
            var R5Assist_WinAll = [R5AW[1], R5AW[0], R5AW[1], R5AW[3], R5AW[2], R5AW[3], R5AW[5], R5AW[4], R5AW[5], R5AW[7], R5AW[6], R5AW[7], R5AW[8]];
            var R5Assist_DirAll = [R5AD[1], R5AD[0], R5AD[1], R5AD[3], R5AD[2], R5AD[3], R5AD[5], R5AD[4], R5AD[5], R5AD[7], R5AD[6], R5AD[7], R5AD[8]];
            var R5Assist_LonAll = [R5AL[1], R5AL[0], R5AL[1], R5AL[3], R5AL[2], R5AL[3], R5AL[5], R5AL[4], R5AL[5], R5AL[7], R5AL[6], R5AL[7], R5AL[8]];
            var R5Assist_BalAll = [R5AB[1], R5AB[0], R5AB[1], R5AB[3], R5AB[2], R5AB[3], R5AB[5], R5AB[4], R5AB[5], R5AB[7], R5AB[6], R5AB[7], R5AB[8]];
            var R5Defence_ShoAll = [R5DS[1], R5DS[0], R5DS[1], R5DS[3], R5DS[2], R5DS[3], R5DS[5], R5DS[4], R5DS[5], R5DS[7], R5DS[6], R5DS[7], R5DS[8]];
            var R5Defence_ThrAll = [R5DT[1], R5DT[0], R5DT[1], R5DT[3], R5DT[2], R5DT[3], R5DT[5], R5DT[4], R5DT[5], R5DT[7], R5DT[6], R5DT[7], R5DT[8]];
            var R5Defence_WinAll = [R5DW[1], R5DW[0], R5DW[1], R5DW[3], R5DW[2], R5DW[3], R5DW[5], R5DW[4], R5DW[5], R5DW[7], R5DW[6], R5DW[7], R5DW[8]];
            var R5Defence_DirAll = [R5DD[1], R5DD[0], R5DD[1], R5DD[3], R5DD[2], R5DD[3], R5DD[5], R5DD[4], R5DD[5], R5DD[7], R5DD[6], R5DD[7], R5DD[8]];
            var R5Defence_LonAll = [R5DL[1], R5DL[0], R5DL[1], R5DL[3], R5DL[2], R5DL[3], R5DL[5], R5DL[4], R5DL[5], R5DL[7], R5DL[6], R5DL[7], R5DL[8]];
            var R5Defence_BalAll = [R5DB[1], R5DB[0], R5DB[1], R5DB[3], R5DB[2], R5DB[3], R5DB[5], R5DB[4], R5DB[5], R5DB[7], R5DB[6], R5DB[7], R5DB[8]];
            var R5Assist_Sho2All = [R5AS2[1], R5AS2[0], R5AS2[1], R5AS2[3], R5AS2[2], R5AS2[3], R5AS2[5], R5AS2[4], R5AS2[5], R5AS2[7], R5AS2[6], R5AS2[7], R5AS2[8]];
            var R5Assist_Thr2All = [R5AT2[1], R5AT2[0], R5AT2[1], R5AT2[3], R5AT2[2], R5AT2[3], R5AT2[5], R5AT2[4], R5AT2[5], R5AT2[7], R5AT2[6], R5AT2[7], R5AT2[8]];
            var R5Assist_Win2All = [R5AW2[1], R5AW2[0], R5AW2[1], R5AW2[3], R5AW2[2], R5AW2[3], R5AW2[5], R5AW2[4], R5AW2[5], R5AW2[7], R5AW2[6], R5AW2[7], R5AW2[8]];
            var R5Assist_Dir2All = [R5AD2[1], R5AD2[0], R5AD2[1], R5AD2[3], R5AD2[2], R5AD2[3], R5AD2[5], R5AD2[4], R5AD2[5], R5AD2[7], R5AD2[6], R5AD2[7], R5AD2[8]];
            var R5Assist_Lon2All = [R5AL2[1], R5AL2[0], R5AL2[1], R5AL2[3], R5AL2[2], R5AL2[3], R5AL2[5], R5AL2[4], R5AL2[5], R5AL2[7], R5AL2[6], R5AL2[7], R5AL2[8]];
            var R5Assist_Bal2All = [R5AB2[1], R5AB2[0], R5AB2[1], R5AB2[3], R5AB2[2], R5AB2[3], R5AB2[5], R5AB2[4], R5AB2[5], R5AB2[7], R5AB2[6], R5AB2[7], R5AB2[8]];
            var R5Defence_Sho2All = [R5DS2[1], R5DS2[0], R5DS2[1], R5DS2[3], R5DS2[2], R5DS2[3], R5DS2[5], R5DS2[4], R5DS2[5], R5DS2[7], R5DS2[6], R5DS2[7], R5DS2[8]];
            var R5Defence_Thr2All = [R5DT2[1], R5DT2[0], R5DT2[1], R5DT2[3], R5DT2[2], R5DT2[3], R5DT2[5], R5DT2[4], R5DT2[5], R5DT2[7], R5DT2[6], R5DT2[7], R5DT2[8]];
            var R5Defence_Win2All = [R5DW2[1], R5DW2[0], R5DW2[1], R5DW2[3], R5DW2[2], R5DW2[3], R5DW2[5], R5DW2[4], R5DW2[5], R5DW2[7], R5DW2[6], R5DW2[7], R5DW2[8]];
            var R5Defence_Dir2All = [R5DD2[1], R5DD2[0], R5DD2[1], R5DD2[3], R5DD2[2], R5DD2[3], R5DD2[5], R5DD2[4], R5DD2[5], R5DD2[7], R5DD2[6], R5DD2[7], R5DD2[8]];
            var R5Defence_Lon2All = [R5DL2[1], R5DL2[0], R5DL2[1], R5DL2[3], R5DL2[2], R5DL2[3], R5DL2[5], R5DL2[4], R5DL2[5], R5DL2[7], R5DL2[6], R5DL2[7], R5DL2[8]];
            var R5Defence_Bal2All = [R5DB2[1], R5DB2[0], R5DB2[1], R5DB2[3], R5DB2[2], R5DB2[3], R5DB2[5], R5DB2[4], R5DB2[5], R5DB2[7], R5DB2[6], R5DB2[7], R5DB2[8]];
            var posGainAll = [posGain[1], posGain[0], posGain[1], posGain[3], posGain[2], posGain[3], posGain[5], posGain[4], posGain[5], posGain[7], posGain[6], posGain[7], posGain[8]];
            var posKeepAll = [posKeep[1], posKeep[0], posKeep[1], posKeep[3], posKeep[2], posKeep[3], posKeep[5], posKeep[4], posKeep[5], posKeep[7], posKeep[6], posKeep[7], posKeep[8]];
            var R5adapt = [];
            var RERECall = [REREC[0][1], REREC[0][0], REREC[0][1], REREC[0][3], REREC[0][2], REREC[0][3], REREC[0][5], REREC[0][4], REREC[0][5], REREC[0][7], REREC[0][6], REREC[0][7], REREC[0][8]];
            var RERECadapt = [];

            if (hidden[0].innerHTML != "") {
                for (i = 0; i < 13; i++) {
                    if (positionsAll[FP2[0]][i] > positionsAll[FP2[1]][i]) positionsAll[FP2[0]][i] = positionsAll[FP2[1]][i];
                    R5adapt[i] = funFix2((R5all[i] * 1 + allBonus * 1 + posGainAll[i] * 1 + posKeepAll[i] * 1) * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    RERECadapt[i] = funFix2(RERECall[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_ShoAll[i] = funFix2(R5Assist_ShoAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_ThrAll[i] = funFix2(R5Assist_ThrAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_WinAll[i] = funFix2(R5Assist_WinAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_DirAll[i] = funFix2(R5Assist_DirAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_LonAll[i] = funFix2(R5Assist_LonAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_BalAll[i] = funFix2(R5Assist_BalAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_ShoAll[i] = funFix2(R5Defence_ShoAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_ThrAll[i] = funFix2(R5Defence_ThrAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_WinAll[i] = funFix2(R5Defence_WinAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_DirAll[i] = funFix2(R5Defence_DirAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_LonAll[i] = funFix2(R5Defence_LonAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_BalAll[i] = funFix2(R5Defence_BalAll[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_Sho2All[i] = funFix2(R5Assist_Sho2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_Thr2All[i] = funFix2(R5Assist_Thr2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_Win2All[i] = funFix2(R5Assist_Win2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_Dir2All[i] = funFix2(R5Assist_Dir2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_Lon2All[i] = funFix2(R5Assist_Lon2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Assist_Bal2All[i] = funFix2(R5Assist_Bal2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_Sho2All[i] = funFix2(R5Defence_Sho2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_Thr2All[i] = funFix2(R5Defence_Thr2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_Win2All[i] = funFix2(R5Defence_Win2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_Dir2All[i] = funFix2(R5Defence_Dir2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_Lon2All[i] = funFix2(R5Defence_Lon2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                    R5Defence_Bal2All[i] = funFix2(R5Defence_Bal2All[i] * (1 - (20 - adap) * positionsAll[FP2[0]][i] / 200));
                }

                var R5table10 =  "<div id=\"R5table10_div\">"+
                                    "<table id=\"R5table10\" style=\"" + table_border + "\" align=\"center\">"+
                                        "<tbody>"+
                                            "<tr>"+
                                                "<td colspan=\"3\" align=\"center\" style=\"border-bottom:solid 1px; background-color: #333333;\"><b>RatingR6 All Positions</b></td>"+
                                            "</tr>"+
                                        "</tbody>"+
                                    "</table>"+
                                "</div>";
                var tr_F = "<tr><td></td><td align=\"center\" id=\"cell_12\" class=\"R5cell\">" + R5adapt[12] + "</td><td></td></tr>";
                var tr_OM = "<tr><td id=\"cell_9\">" + R5adapt[9] + "</td><td id=\"cell_10\">" + R5adapt[10] + "</td><td id=\"cell_11\">" + R5adapt[11] + "</td></tr>";
                var tr_M = "<tr><td id=\"cell_6\">" + R5adapt[6] + "</td><td id=\"cell_7\">" + R5adapt[7] + "</td><td id=\"cell_8\">" + R5adapt[8] + "</td></tr>";
                var tr_DM = "<tr><td id=\"cell_3\">" + R5adapt[3] + "</td><td id=\"cell_4\">" + R5adapt[4] + "</td><td id=\"cell_5\">" + R5adapt[5] + "</td></tr>";
                var tr_D = "<tr><td id=\"cell_0\">" + R5adapt[0] + "</td><td id=\"cell_1\">" + R5adapt[1] + "</td><td id=\"cell_2\">" + R5adapt[2] + "</td></tr>";
                $("#R5table_div").append(R5table10);
                $("#R5table10 > tbody").append(tr_F, tr_OM, tr_M, tr_DM, tr_D);
                $("#R5table10 > tbody > tr:eq(0)").nextAll("tr").attr("align", "center");
                $("#R5table10 > tbody > tr:odd").addClass("odd");
                $("#R5table10").find("td:gt(4)").addClass("R5cell");
                var table10_note = "click each number to show detail";
                $("#R5table_div").append(table10_note);

                // R5table3b ######################################################################
                var R5table3b = [];
                var flg_table3b = [];
                for (i = 0; i < 13; i++) {
                    R5table3b[i] =  "<div id=\"R5table3b_div\">"+
                                        "<table id=\"R5table3b_" + i + "\" style=\"display:none; " + table_border + "\">"+
                                            "<tbody>"+
                                                "<tr style=\"background-color:darkslategray\">"+
                                                    "<td><b>" + positionNames3[i] + "</b></td>"+
                                                    td+
                                                    td+
                                                    td+
                                                    td+
                                                    td+
                                                "</tr>"+
                                            "</tbody>"+
                                        "</table>"+
                                    "</div>";
                    tr_ASho[i] = "<tr><td width=\"30px\"></td><td width=\"120px\"><b>R5 Assist</b></td><td width=\"70px\">pure</td><td width=\"70px\">by position</td><td width=\"70px\">composite</td><td></td></tr><tr><td></td><td>Shortpassing : </td><td>" + ASho + "</td><td>" + R5Assist_ShoAll[i] + "</td><td>" + R5Assist_Sho2All[i] + "</td><td></td></tr>";
                    tr_AThr[i] = "<tr class=\"odd\"><td></td><td>Through Balls : </td><td>" + AThr + "</td><td>" + R5Assist_ThrAll[i] + "</td><td>" + R5Assist_Thr2All[i] + "</td><td></td></tr>";
                    tr_AWin[i] = "<tr><td></td><td>Wings Attack : </td><td>" + AWin + "</td><td>" + R5Assist_WinAll[i] + "</td><td>" + R5Assist_Win2All[i] + "</td><td></td></tr>";
                    tr_ADir[i] = "<tr class=\"odd\"><td></td><td>Direct/Counter : </td><td>" + ADir + "</td><td>" + R5Assist_DirAll[i] + "</td><td>" + R5Assist_Dir2All[i] + "</td><td></td></tr>";
                    tr_ALon[i] = "<tr><td></td><td>Long Balls : </td><td>" + ALon + "</td><td>" + R5Assist_LonAll[i] + "</td><td>" + R5Assist_Lon2All[i] + "</td><td></td></tr>";
                    tr_ABal[i] = "<tr class=\"odd\"><td></td><td>Balanced : </td><td>-----</td><td>-----</td><td>" + R5Assist_Bal2All[i] + "</td><td></td></tr>";
                    tr_DSho[i] = "<tr><td>&nbsp;</td></tr><tr><td></td><td><b>R5 Defence</b></td><td>pure</td><td>by position</td><td>composite</td></tr><tr><td></td><td>Shortpassing : </td><td>" + DSho + "</td><td>" + R5Defence_ShoAll[i] + "</td><td>" + R5Defence_Sho2All[i] + "</td><td></td></tr>";
                    tr_DThr[i] = "<tr class=\"odd\"><td></td><td>Through Balls : </td><td>" + DThr + "</td><td>" + R5Defence_ThrAll[i] + "</td><td>" + R5Defence_Thr2All[i] + "</td><td></td></tr>";
                    tr_DWin[i] = "<tr><td></td><td>Wings Attack : </td><td>" + DWin + "</td><td>" + R5Defence_WinAll[i] + "</td><td>" + R5Defence_Win2All[i] + "</td><td></td></tr>";
                    tr_DDir[i] = "<tr class=\"odd\"><td></td><td>Direct/Counter : </td><td>" + DDir + "</td><td>" + R5Defence_DirAll[i] + "</td><td>" + R5Defence_Dir2All[i] + "</td><td></td></tr>";
                    tr_DLon[i] = "<tr><td></td><td>Long Balls : </td><td>" + DLon + "</td><td>" + R5Defence_LonAll[i] + "</td><td>" + R5Defence_Lon2All[i] + "</td><td></td></tr>";
                    tr_DBal[i] = "<tr class=\"odd\"><td></td><td>Balanced : </td><td>-----</td><td>-----</td><td>" + R5Defence_Bal2All[i] + "</td><td></td></tr>";
                    $("#R5table_div").append(R5table3b[i]);
                    $("#R5table3b_" + i).find("tbody").append(tr_ASho[i], tr_AThr[i], tr_AWin[i], tr_ADir[i], tr_ALon[i], tr_ABal[i], tr_DSho[i], tr_DThr[i], tr_DWin[i], tr_DDir[i], tr_DLon[i], tr_DBal[i]);
                    $("#R5table3b_" + i).find("td").attr("style", "padding-left:5px");
                    flg_table3b[i] = "hide";
                }
                var table3b_functions = [];
                for (let i = 0; i < 13; i++) {
                    (function () {
                        $("#cell_" + i).click(function () {
                            if (flg_table3b[i] == "hide") {
                                flg_table3b[i] = "show";
                                $(this).attr("style", "color: yellow; text-shadow: 0px 0px 2px black");
                            }
                            else {
                                flg_table3b[i] = "hide";
                                $(this).removeAttr("style");
                            }
                            $("#R5table3b_" + i).slideToggle();
                        });
                        table3b_functions.push(function () { });
                    })();
                    table3b_functions[i]();
                }
            }
            else {
                // R5table5 #######################################################################
                var R5table5 = [];
                var R5table5_array = [1, 0, 2, 4, 3, 5, 7, 6, 8, 10, 9, 11, 12];
                var R5table5_index = [];
                var flg_R5AS = [];
                for (i = 0; i < positionArray.length; i++) {
                    R5table5_index[i] = R5table5_array.indexOf(positionIndex2[i]);
                    R5table5[i] = "<div id=\"R5table5_div\"><table id=\"R5table5_" + i + "\" style=\"margin-top:1px;"+ table_border + "\"><tbody><tr id=\"R5AS" + i + "\" style=\"background-color:darkslategray\"><td colspan=\"2\"><b>" + positionNames[positionIndex2[i]] + "</b></td><td></td><td></td><td align=\"right\" colspan=\"2\"><span class=\"button\" style=\"width:80px; line-height:19px;\" id=\"R5ASdetail_btn" + i + "\"><span id=\"R5ASbtn_text" + i + "\" class=\"button_border\" style=\"width:78px; line-height:19px; padding: 0;\">Show Detail</span></span></td></tr></tbody></table></div>";
                    tr_ASho[i] = "<tr class=\"R5AS" + i + "\"><td width=\"30px\"></td><td width=\"120px\"><b>R5 Assist</b></td><td width=\"70px\">pure</td><td width=\"70px\">by position</td><td width=\"70px\">composite</td><td></td></tr><tr class=\"R5AS" + i + "\"><td></td><td>Shortpassing : </td><td>" + ASho + "</td><td>" + R5Assist_ShoAll[R5table5_index[i]] + "</td><td>" + R5Assist_Sho2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_AThr[i] = "<tr class=\"odd R5AS" + i + "\"><td></td><td>Through Balls : </td><td>" + AThr + "</td><td>" + R5Assist_ThrAll[R5table5_index[i]] + "</td><td>" + R5Assist_Thr2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_AWin[i] = "<tr class=\"R5AS" + i + "\"><td></td><td>Wings Attack : </td><td>" + AWin + "</td><td>" + R5Assist_WinAll[R5table5_index[i]] + "</td><td>" + R5Assist_Win2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_ADir[i] = "<tr class=\"odd R5AS" + i + "\"><td></td><td>Direct/Counter : </td><td>" + ADir + "</td><td>" + R5Assist_DirAll[R5table5_index[i]] + "</td><td>" + R5Assist_Dir2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_ALon[i] = "<tr class=\"R5AS" + i + "\"><td></td><td>Long Balls : </td><td>" + ALon + "</td><td>" + R5Assist_LonAll[R5table5_index[i]] + "</td><td>" + R5Assist_Lon2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_ABal[i] = "<tr class=\"odd R5AS" + i + "\"><td></td><td>Balanced : </td><td>-----</td><td>" + R5Assist_BalAll[R5table5_index[i]] + "</td><td>" + R5Assist_Bal2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_DSho[i] = "<tr class=\"R5AS" + i + "\"><td>&nbsp;</td></tr><tr class=\"R5AS" + i + "\"><td></td><td><b>R5 Defence</b></td><td>pure</td><td>by position</td><td>composite</td></tr><tr class=\"R5AS" + i + "\"><td></td><td>Shortpassing : </td><td>" + DSho + "</td><td>" + R5Defence_ShoAll[R5table5_index[i]] + "</td><td>" + R5Defence_Sho2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_DThr[i] = "<tr class=\"odd R5AS" + i + "\"><td></td><td>Through Balls : </td><td>" + DThr + "</td><td>" + R5Defence_ThrAll[R5table5_index[i]] + "</td><td>" + R5Defence_Thr2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_DWin[i] = "<tr class=\"R5AS" + i + "\"><td></td><td>Wings Attack : </td><td>" + DWin + "</td><td>" + R5Defence_WinAll[R5table5_index[i]] + "</td><td>" + R5Defence_Win2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_DDir[i] = "<tr class=\"odd R5AS" + i + "\"><td></td><td>Direct/Counter : </td><td>" + DDir + "</td><td>" + R5Defence_DirAll[R5table5_index[i]] + "</td><td>" + R5Defence_Dir2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_DLon[i] = "<tr class=\"R5AS" + i + "\"><td></td><td>Long Balls : </td><td>" + DLon + "</td><td>" + R5Defence_LonAll[R5table5_index[i]] + "</td><td>" + R5Defence_Lon2All[R5table5_index[i]] + "</td><td></td></tr>";
                    tr_DBal[i] = "<tr class=\"odd R5AS" + i + "\"><td></td><td>Balanced : </td><td>-----</td><td>" + R5Defence_BalAll[R5table5_index[i]] + "</td><td>" + R5Defence_Bal2All[R5table5_index[i]] + "</td><td></td></tr>";
					$("#R5table_div").append(R5table5[i]);
                    $("#R5table5_" + i).find("tbody").append(tr_ASho[i], tr_AThr[i], tr_AWin[i], tr_ADir[i], tr_ALon[i], tr_ABal[i], tr_DSho[i], tr_DThr[i], tr_DWin[i], tr_DDir[i], tr_DLon[i], tr_DBal[i]);
                    $("#R5table5_" + i).find("td").attr("style", "padding-left:5px");
                    $(".R5AS" + i).hide();
                    flg_R5AS[i] = "hide";
				}
                var R5ASbtn_functions = [];
                for (let i = 0; i < positionArray.length; i++) {
                    (function () {
                        $("#R5ASdetail_btn" + i).click(function () {
                            if (flg_R5AS[i] == "hide") {
                                flg_R5AS[i] = "show";
                                $("#R5ASbtn_text" + i).text("Hide Detail");
                            }
                            else {
                                flg_R5AS[i] = "hide";
                                $("#R5ASbtn_text" + i).text("Show Detail");
                            }
                            $(".R5AS" + i).slideToggle();
                        });
                        R5ASbtn_functions.push(function () { });
                    })();
                    R5ASbtn_functions[i]();
                }
            }
        }

        // R5table3 ###############################################################################
        if (hidden[0].innerHTML != "") {
            var R5table3 = "<div id=\"R5table3_div\"><table id=\"R5table3\" style=\"margin-top:10px; margin-bottom:10px; border-left:solid 1px; border-right:solid 1px; border-top:solid 1px; border-bottom:solid 1px\" cellspascing=\"0\" cellpadding=\"0\"><tbody></tbody></table></div>";
            var capheader1 = "<tr style=\"background-color: #333333\"><td style=\"border-bottom:solid 1px\" align=\"center\" colspan=\"6\"><b>Captaincy</b></td></tr>";
            var capheader2 = "<tr style=\"background-color: #333333;\"><td style=\"padding-left:5px\">Leadership</td><td>Level 1</td><td>Level 2</td><td>Level 3</td><td>Level 4</td><td>Level 5</td></tr>";
            var cap_row = "<tr id=\"rva\"><td style=\"padding-left:5px\">Captaincy(RVA)</td></tr>";
            var cap_row2 = "<tr id=\"rva2\"><td style=\"padding-left:5px\">RVA:custom</td></tr>";
            var cap_row3 = "<tr id=\"tss\"><td style=\"padding-left:5px\">Captaincy(TSS)</td></tr>";
            $("#R5table_div").append(R5table3);
            $("#R5table3 > tbody").append(capheader1, capheader2, cap_row, cap_row3);
            for (i = 1; i < 6; i++) {
                $("#rva").append("<td align=\"right\" style=\"padding-right:15px\">" + cap[i] + "</td>");
                $("#tss").append("<td align=\"right\" style=\"padding-right:15px\">" + cap3[i] + "</td>");
            }
            if (weightDefault == "custom") {
                $("#R5table3 tr:eq(2)").after(cap_row2);
                for (i = 0; i < 6; i++) {
                    $("#rva2").append("<td align=\"right\" style=\"padding-right:15px\">" + cap2[i] + "</td>");
                }
            }
            $("#R5table3 > tbody > tr:eq(1) > td:eq(0)").nextAll().attr("align", "center");
            $("#R5table3 > tbody > tr:odd").addClass("odd");
        }

        // R5table4 ###############################################################################
        if (notGK) {
            var tr_skills =
                "<tr>"+
                    "<td></td>"+
                    "<td colspan=\"4\">Str:-- Sta:-- Pac:-- Mar:-- Tac:-- Wor:-- Pos:--<br>Pas:-- Cro:-- Tec:-- Hea:-- Fin:-- Lon:-- Set:--</td>"+
                "</tr>";
        }
        else {
            var tr_skills =
                "<tr>"+
                    "<td></td>"+
                    "<td colspan=\"4\">Str:-- Sta:-- Pac:--<br>Han:-- One:-- Ref:-- Aer:-- Jum:-- Com:-- Kic:-- Thr:--</td>"+
                "</tr>";
        }

        var R5table4 =
            "<div id=\"R5table4_div\">"+
                "<table id=\"R5table4\" style=\"margin-top:3px; margin-bottom:3px; border-left:solid 1px; border-right:solid 1px; border-top:solid 1px; border-bottom:solid 1px\" cellspascing=\"0\" cellpadding=\"0\">"+
                    "<tbody>"+
                        "<tr>"+
                            "<td style=\"padding-left:5px\">Age</td>"+
                            "<td width=\"100\">Skill Index</td>"+
                            "<td width=\"100\">REC</td>"+
                            "<td width=\"100\">RatingR6</td>"+
                            "<td align=\"right\">"+
                                "<span class=\"button\" style=\"width:50px; line-height:19px;\"><span class=\"button_border add\" style=\"width:48px; line-height:19px; padding: 0;\">Add</span></span>"+
                            "</td>"+
                        "</tr>"+
                        "<tr>"+
                            "<td><select name=\"selects\" id=\"select0\"><option selected=\"selected\">select</option></select></td>"+
                            "<td>---</td>"+
                            "<td>---</td>"+
                            "<td>---</td>"+
                            "<td></td>"+
                        "</tr>"+
                        tr_skills +
                    "</tbody>"+
                "</table>"+
            "</div>";

        $(function(){
            var clearKey = localStorage.getItem(version);

            if (clearKey == "done") console.log("old storae has been removed.");
            else {
                var keys = [];
                for (i = 0; i < localStorage.length; i++){
                    if (localStorage.key(i).substr(0,9) < removeID) keys.push(localStorage.key(i).substr(0,9));
                }
                for (i = 0; i < keys.length; i++){
                    localStorage.removeItem(keys[i]+"_SI");
                    localStorage.removeItem(keys[i]+"_REREC");
                    localStorage.removeItem(keys[i]+"_R5");
                    localStorage.removeItem(keys[i]+"_skills");
                }
                localStorage.setItem(version,"done");
            }
        });

        $(function() {
            infotable.parent().append(R5table4);
            var yearTIaverage = 0;

            let SIdata = {};
            let RERECdata = {};
            let R5data = {};
            let skillsdata = {};

            function setJSON() {
                var time0 = new Date();
                console.log("JSON処理開始");
                if (FP[0] != FP[1]) {
                    var R5now = R5FP0 + "/" + R5FP1;
                    var RERECnow = REREC[0][FP[0]] + "/" + REREC[0][FP[1]];
                }
                else {
                    var R5now = R5FP0;
                    var RERECnow = REREC[0][FP[0]];
                }

                function loadJSON() {
                    SIdata = JSON.parse(localStorage.getItem(player_id+"_SI"));
                    RERECdata = JSON.parse(localStorage.getItem(player_id+"_REREC"));
                    R5data = JSON.parse(localStorage.getItem(player_id+"_R5"));
                    skillsdata = JSON.parse(localStorage.getItem(player_id+"_skills"));

                    if(SIdata == null) {
                        SIdata= {};
                        RERECdata = {};
                        R5data = {};
                        skillsdata = {};
                    }
                    return { SIdata, RERECdata, R5data, skillsdata };

                }

                function addJSON(){
                    SIdata[year+"."+month] = SI;
                    RERECdata[year+"."+month] = RERECnow;
                    R5data[year+"."+month] = R5now;
                    skillsdata[year+"."+month] = skills;
                    return { SIdata, RERECdata, R5data, skillsdata };
                }

                $.when(
                    loadJSON()
                ).done(function(){
                    var time1 = new Date();
                    console.log("JSON読み込み完了");
                    $.when(
                        addJSON()
                    ).done(function(){
                        localStorage.setItem(player_id+"_SI",JSON.stringify(SIdata));
                        localStorage.setItem(player_id+"_REREC",JSON.stringify(RERECdata));
                        localStorage.setItem(player_id+"_R5",JSON.stringify(R5data));
                        localStorage.setItem(player_id+"_skills",JSON.stringify(skillsdata));
                        var time2 = new Date();
                        console.log("JSON書き込み完了");

                        for (i = 15; i < 39; i++) {
                            for (j = 0; j < 12; j++) {
                                if (isNaN(parseInt(SIdata[i+"."+j]))) continue;
                                else $("#select0").append($("<option>").val(i+"."+j).html(i+"."+j));
                            }
                        }
                        var time3 = new Date();
                        console.log("JSON処理完了 "+(time3.getTime()-time0.getTime())+"msec.");

                        var id_num = 1;
                        function addSelect() {
                            var newSelect =
                                "<table style=\"margin-top:5px; margin-bottom:3px; border-left:solid 1px; border-right:solid 1px; border-top:solid 1px; border-bottom:solid 1px\" cellspascing=\"0\" cellpadding=\"0\">"+
                                    "<tbody>"+
                                        "<tr>"+
                                            "<td style=\"padding-left:5px\">Age</td>"+
                                            "<td width=\"100\">Skill Index</td>"+
                                            "<td width=\"100\">REC</td>"+
                                            "<td width=\"100\">RatingR6</td>"+
                                            "<td align=\"right\">"+
                                                "<span class=\"button\" style=\"width:50px; line-height:19px;\"><span class=\"button_border add\" style=\"width:48px; line-height:19px; padding: 0;\">Add</span></span>"+
                                            "</td>"+
                                        "</tr>"+
                                        "<tr>"+
                                            "<td><select name=\"selects\"><option selected=\"selected\">select</option></select></td>"+
                                            "<td>---</td>"+
                                            "<td>---</td>"+
                                            "<td>---</td>"+
                                            "<td></td>"+
                                        "</tr>"+
                                        tr_skills +
                                    "</tbody>"+
                                "</table>";
                            $("#R5table4_div").append(newSelect);

                            var selects = $("#R5table4_div").find("select");
                            var len =  selects.length-1;
                            selects.eq(len).attr("id", "select"+id_num);

                            for (i = 15; i < 39; i++) {
                                for (j = 0; j < 12; j++) {
                                    if (isNaN(parseInt(SIdata[i+"."+j]))) continue;
                                    else $("#select"+id_num).append($("<option>").val(i+"."+j).html(i+"."+j));
                                }
                            }

                            $("#R5table4_div").on("click","#select"+id_num, function(){
                                addOption();
                            })
                            id_num ++;
                        }

                        function addOption() {
                            $("select").each(function() {
                                $(this).change(function() {
                                    if ($(this).val() == "select") {
                                        $(this).parent().nextAll().text("---");
                                        $(this).closest("tbody").find("tr").eq(2).text("");
                                    }
                                    else {
                                        var val = $(this).val();
                                        var selectedYear = val.slice(0,2);
                                        var selectedMonth = val.substr(3);
                                        $(this).parent().next().text(en.format(SIdata[selectedYear+"."+selectedMonth]));
                                        $(this).parent().next().next().text(RERECdata[selectedYear+"."+selectedMonth]);
                                        $(this).parent().next().next().next().text(R5data[selectedYear+"."+selectedMonth]);
                                        var seleSkills = skillsdata[selectedYear+"."+selectedMonth];

                                        if (notGK) var skillsHTML = "<td></td><td colspan=\"4\">Str:"+parseInt(seleSkills[0])+" Sta:"+parseInt(seleSkills[1])+" Pac:"+parseInt(seleSkills[2])+" Mar:"+parseInt(seleSkills[3])+" Tac:"+parseInt(seleSkills[4])+" Wor:"+parseInt(seleSkills[5])+" Pos:"+parseInt(seleSkills[6])+"<br>Pas:"+parseInt(seleSkills[7])+" Cro:"+parseInt(seleSkills[8])+" Tec:"+parseInt(seleSkills[9])+" Hea:"+parseInt(seleSkills[10])+" Fin:"+parseInt(seleSkills[11])+" Lon:"+parseInt(seleSkills[12])+" Set:"+parseInt(seleSkills[13])+"</td>";
                                        else var skillsHTML = "<td></td><td colspan=\"4\">Str:"+parseInt(seleSkills[0])+" Sta:"+parseInt(seleSkills[1])+" Pac:"+parseInt(seleSkills[2])+"<br>Han:"+parseInt(seleSkills[3])+" One:"+parseInt(seleSkills[4])+" Ref:"+parseInt(seleSkills[5])+" Aer:"+parseInt(seleSkills[6])+" Jum:"+parseInt(seleSkills[7])+" Com:"+parseInt(seleSkills[8])+" Kic:"+parseInt(seleSkills[9])+" Thr:"+parseInt(seleSkills[10])+"</td>";
                                        $(this).closest("tbody").find("tr").eq(2).html(skillsHTML);
                                    }
                                })
                            })
                        };
                        addOption();

                        $("#R5table4_div").on("click",".button_border.add", function() {
                            addSelect();
                            $(this).removeClass("add").addClass("remove").text("Remove");
                        });
                        $("#R5table4_div").on("click",".button_border.remove", function() {
                            $(this).closest("table").remove();
                        });

                        function calc_yearTI() {
                            var yearTIaverage = 0;
                            var yearSI = [];
                            var yearSIlen = 0;
                            for (i = 0; i < month+1; i++) {
                                yearSI[i] = SIdata[year+"."+i] * 1;
                                if (yearSI[i] > 0) yearSIlen++;
                            }

                            if (SIdata[year - 1 + ".11"] > 0) {
                                var yearSIlast = SIdata[year - 1 + ".11"];
                                var yearTI = MP(2, ML(weight * SI) / ML(MP(2, 7))) - MP(2, ML(weight * yearSIlast) / ML(MP(2, 7)));
                                yearTI = MR(yearTI * 10);
                                yearTIaverage = yearTI / (month + 1);
                            }
                            else {
                                var yearSIfirst = yearSI.find(element => element > 0);
                                var yearTI = MP(2, ML(weight * SI) / ML(MP(2, 7))) - MP(2, ML(weight * yearSIfirst) / ML(MP(2, 7)));
                                yearTI = MR(yearTI * 10);
                                if (yearTI == 0) yearTIaverage = 0;
                                else yearTIaverage = yearTI / (month - yearSI.indexOf(yearSIfirst));
                            }
                            return { yearSIlen, yearTIaverage };
                        }
                        var { yearSIlen, yearTIaverage} = calc_yearTI();

                        const TI_flag = (yearSIlen > 1 || SIdata[year-1+".11"] > 0) ? true : false;
                        var yearTIave = "<tr id=\"tr_seasonTI\"><th><b>Year TI average</b></th><td id=\"td_yearTI\">" + funFix1(yearTIaverage) + "</td></tr>";

                        infotable.find("tr").eq(0).append("<th>PlayerID</th><td>" + player_id + "</td>");
                        infotable.find("tr").eq(5).after(RERECb);
                        infotable.find("tr").eq(6).after(R5);
                        infotable.find("tr").eq(8).after(seasonTI);
                        if (newPlayer == 2) {
                            infotable.find("tr").eq(9).after(newPlayerTI);
                            if(TI_flag) infotable.find("tr").eq(10).after(yearTIave);
                        }
                        else if (TI_flag) infotable.find("tr").eq(9).after(yearTIave);
                        infotable.find("td").eq(0).attr("rowspan", infotable.find("tr").length);
                        infotable.find("th").css("font-weight", "bold");
                        infotable.find("tr").removeClass();
                        infotable.find("tr:odd").addClass("odd");

                        return yearTIaverage;
                    });
                });
            }
            setJSON();
        });

//	### transfer info #############################################################################
        var R5Value_num = 0;
        var R5Value2_num = 0;
        var maxPrice_num = 0;
        var staPrice_num = 0;
        if (((newPlayer == 0 && year <= 24) && session <= month) || session > month) {
            if (minR5Value != maxR5Value) {
                R5Value_num = en.format(minR5Value) + " - " + "<span class=\"coin\">" + en.format(maxR5Value) + "</span>";
                R5Value2_num = en.format(minR5Value2) + " - " + "<span class=\"coin\">" + en.format(maxR5Value2) + "</span>";
            }
            else {
                R5Value_num = "<span class=\"coin\">" + en.format(maxR5Value) + "</span>";
                R5Value2_num = "<span class=\"coin\">" + en.format(maxR5Value2) + "</span>";
            }
        }
        else {
            R5Value_num = "<span class=\"coin\">" + en.format(R5Value) + "</span>";
            R5Value2_num = "<span class=\"coin\">" + en.format(R5Value2) + "</span>";
        }
        if (retire) {
            maxPrice_num = "Transfer not possible";
            staPrice_num = "Transfer not possible";
        }
        else if (year < 18) {
        	maxPrice_num = "<span class=\"coin\" style=\"color:silver;\">" + en.format(maxPrice) + "</span>";
        	staPrice_num = "<span class=\"coin\" style=\"color:silver;\">" + en.format(staPrice) + "</span>";
        }
        else {
            maxPrice_num = "<span class=\"coin\">" + en.format(maxPrice) + "</span>";
            staPrice_num = "<span class=\"coin\">" + en.format(staPrice) + "</span>";
        }
        var pricetable = "<div><table id=\"pricetable\" style=\"margin-right:25px; margin-top:5px; margin-bottom:5px\"><tbody></tbody></table></div>";
        var R5Value_row = "<tr><td align=\"left\">VALUE</td><td align=\"right\">" + R5Value_num + "</td></tr>";
        var R5Value2_row = "<tr><td align=\"left\">VALUE MAX</td><td align=\"right\">" + R5Value2_num + "</td></tr>";
        var maxPrice_row = "<tr><td align=\"left\">Max Sell Price</td><td align=\"right\">" + maxPrice_num + "</td></tr>";
        var staPrice_row = "<tr><td align=\"left\">Sell To Agent</td><td align=\"right\">" + staPrice_num + "</td></tr>";
        var countryforum = "<br><a href = \"https://trophymanager.com/forum/" + nation + "/general/\" target = \"_blank\"><span class=\"button\" style=\"width:170px; text-align:left;\"><span class=\"button_border\" style=\"width:168px; padding: 0;\">&nbsp;<ib class=\"flag-img-" + nation + " \"></ib>&nbsp;Home Country Forum</span></span></a>";
        var transferforum = "<br><a href = \"https://trophymanager.com/forum/int/transfer/\" target = \"_blank\"><span class=\"button\" style=\"width:170px; text-align:left;\"><span class=\"button_border\" style=\"width:168px; padding: 0;\">&nbsp;<img src=\"/pics/flags/gradient/int.png\">&nbsp;Transfer Forum</span></span></a>";
        if (notGK) {
            var transferPosArray = ["de/", "de/", "dm/", "dm/", "mf/", "mf/", "om/", "om/", "fw/"];
            var transferSideArray = ["ce/", "le/ri/", "ce/", "le/ri/", "ce/", "le/ri/", "ce/", "le/ri/", "ce/"];
            var pos1 = transferPosArray[FP[0]];
            var pos2 = "";
            var side1 = transferSideArray[FP[0]];
            var side2 = "";
            if (FP[0] != FP[1]) {
                pos2 = transferPosArray[FP[1]];
                side2 = transferSideArray[FP[1]];
                if (pos1 == pos2) pos2 = "";
                if (side1 == side2) side2 = "";
            }
            var transferPos = pos1 + pos2;
            var transferSide = side1 + side2;
        }
        var amin = Math.max(year * 1 - 2, 18);
        var amax = Math.min(year * 1 + 1, 37);
        var skillsC = [];
        for (i = 0; i < skills.length; i++) {
            skillsC[i] = Math.floor(skills[i] * 1 - 2);
            if (skillsC[i] < 1) skillsC[i] = 1;
        }
        if (notGK) {
            if (R5FP0 < R5FP1) var skillselect = FP[1];
            else var skillselect = FP[0];
            var t_skills = ["/str/" + skillsC[0] + "/pac/" + skillsC[2] + "/mar/" + skillsC[3] + "/tac/" + skillsC[4] + "/wor/" + skillsC[5] + "/pos/" + skillsC[6] + "/pas/" + skillsC[7] + "/hea/" + skillsC[10],
            "/str/" + skillsC[0] + "/pac/" + skillsC[2] + "/mar/" + skillsC[3] + "/tac/" + skillsC[4] + "/wor/" + skillsC[5] + "/pos/" + skillsC[6] + "/cro/" + skillsC[8] + "/hea/" + skillsC[10],
            "/str/" + skillsC[0] + "/pac/" + skillsC[2] + "/mar/" + skillsC[3] + "/tac/" + skillsC[4] + "/wor/" + skillsC[5] + "/pos/" + skillsC[6] + "/pas/" + skillsC[7] + "/tec/" + skillsC[9] + "/hea/" + skillsC[10],
            "/pac/" + skillsC[2] + "/mar/" + skillsC[3] + "/tac/" + skillsC[4] + "/wor/" + skillsC[5] + "/pos/" + skillsC[6] + "/pas/" + skillsC[7] + "/cro/" + skillsC[8] + "/tec/" + skillsC[9] + "/hea/" + skillsC[10],
            "/pac/" + skillsC[2] + "/wor/" + skillsC[5] + "/pos/" + skillsC[6] + "/pas/" + skillsC[7] + "/tec/" + skillsC[9] + "/hea/" + skillsC[10] + "/fin/" + skillsC[11] + "/lon/" + skillsC[12],
            "/pac/" + skillsC[2] + "/wor/" + skillsC[5] + "/pos/" + skillsC[6] + "/pas/" + skillsC[7] + "/cro/" + skillsC[8] + "/tec/" + skillsC[9] + "/hea/" + skillsC[10] + "/fin/" + skillsC[11] + "/lon/" + skillsC[12],
            "/pac/" + skillsC[2] + "/wor/" + skillsC[5] + "/pos/" + skillsC[6] + "/pas/" + skillsC[7] + "/tec/" + skillsC[9] + "/hea/" + skillsC[10] + "/fin/" + skillsC[11] + "/lon/" + skillsC[12],
            "/pac/" + skillsC[2] + "/wor/" + skillsC[5] + "/pos/" + skillsC[6] + "/pas/" + skillsC[7] + "/cro/" + skillsC[8] + "/tec/" + skillsC[9] + "/hea/" + skillsC[10] + "/fin/" + skillsC[11],
            "/str/" + skillsC[0] + "/pac/" + skillsC[2] + "/wor/" + skillsC[5] + "/pos/" + skillsC[6] + "/pas/" + skillsC[7] + "/tec/" + skillsC[9] + "/hea/" + skillsC[10] + "/fin/" + skillsC[11] + "/lon/" + skillsC[12]];
            var similarplayer = "<br><a href=\"https://trophymanager.com/transfer/#/" + transferPos + transferSide + "for/amin/" + amin + "/amax/" + amax + t_skills[skillselect] + "/\" target = \"_blank\"><span class=\"button\" style=\"width:170px; text-align:left;\"><span class=\"button_border\" style=\"width:168px; padding: 0;\">&nbsp;<img src=\"/pics/binoc.png\">&nbsp;&nbsp;Similar Player</span></span></a>";
        }
        else {
            var similarplayer = "<br><a href=\"https://trophymanager.com/transfer/#/gk/for/amin/" + amin + "/amax/" + amax + "/str/" + skillsC[0] + "/pac/" + skillsC[2] + "/han/" + skillsC[3] + "/one/" + skillsC[4] + "/ref/" + skillsC[5] + "/ari/" + skillsC[6] + "/jum/" + skillsC[7] + "/\" target = \"_blank\"><span class=\"button\" style=\"width:170px; text-align:left;\"><span class=\"button_border\" style=\"width:168px; padding: 0;\">&nbsp;<img src=\"/pics/binoc.png\">&nbsp;&nbsp;Similar Player</span></span></a>";
        }

        $("div.std.align_center.transfer_box").attr("id", "transferbox");
        $("#transferbox").append("<div id=\"t_link\"></div>");
        $("#t_link").append(countryforum, transferforum, similarplayer, pricetable);
        $("#pricetable").append(R5Value_row);
        if (hidden[0].innerHTML != "") $("#pricetable").append(R5Value2_row);
        $("#pricetable").append(maxPrice_row, staPrice_row);
        if (testmode == 99) {
            var bep_row = "<tr><td align=\"left\">BEP</td><td align=\"right\">" + bep + "</td></tr>";
            var fstaPrice_row = "<tr><td align=\"left\">FutureSTA</td><td align=\"right\">" + en.format(futureSTA) + "</td></tr>";
            $("#pricetable").append(bep_row, fstaPrice_row);
        }
        $("#pricetable").find("tr:odd").addClass("odd");

//	### R5 column #################################################################################
        var R5column =
            "<div class=\"box\">"+
                "<div class=\"box_head\">"+
                    "<h2 class=\"std\">Rating R6</h2>"+
                "</div>"+
                "<div class=\"box_body\">"+
                    "<div class=\"box_shadow\"></div>"+
                    "<div id=\"R5column_content\" class=\"content_menu\"></div>"+
                "</div>"+
                "<div class=\"box_footer\">"+
                    "<div></div>"+
                "</div>"+
            "</div>";
        $(".column1").append(R5column);

        if (notGK) {
            var goldstar = 0;
			for (j = 0; j < 2; j++) {
				for (i = 0; i < 14; i++) {
					if (j == 0 && skills[i] == 20) goldstar++;
					if (j == 1 && skills[i] != 20) skills[i] = skills[i] * 1 + remainder / (14 - goldstar);
				}
			}
			var CK = funFix2(skills[8] + skills[13] + skills[9] / 2 + rou2 * 2.5)*2;
			var FK = funFix2(skills[12] + skills[13] + skills[9] / 2 + rou2 * 2.5)*2;
			var PK = funFix2(skills[11] + skills[13] + skills[9] / 2 + rou2 * 2.5)*2;

           function colorNumber(value) {
    // Converti il valore in numero
    var num = parseFloat(value);
    // Restituisci il numero con il colore e il formato appropriati
    if (num > 100) {
        return "<span style=\"color: red; font-weight: bold;\">" + num + "</span>";
    } else if (num >= 70) {
        return "<span style=\"color: yellow;\">" + num + "</span>";
    } else {
        return "<span style=\"color: blue;\">" + num + "</span>";
    }
}

var content1 =
    "<table>" +
        "<tr><td>Physum: </td><td>" + phySum + " (" + MR(phySum / peak[0] * 5) + "%)</td></tr>" +
        "<tr><td>TacSum: </td><td>" + tacSum + " (" + MR(tacSum / peak[1] * 5) + "%)</td></tr>" +
        "<tr><td>TecSum: </td><td>" + tecSum + " (" + MR(tecSum / peak[2] * 5) + "%)</td></tr>" +
        "<tr><td>AllSum: </td><td>" + allSum + " + " + remainder + " </td></tr>" +
        "<tr><td></td><td>&nbsp;</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Finish Type</span></td><td></td></tr>" +
        "<tr><td>Regular: </td><td>" + shotregular + "</td></tr>" +
        "<tr><td>Long: </td><td>" + shotlong + "</td></tr>" +
        "<tr><td>Header: </td><td>" + shothead + "</td></tr>" +
        "<tr><td>&nbsp;</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Set Pieces</span></td><td></td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Corner(1-115): </span></td><td>" + colorNumber(CK) + "</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Freekick(1-115): </span></td><td>" + colorNumber(FK) + "</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Penalty(1-115): </span></td><td>" + colorNumber(PK) + "</td></tr>" +
    "</table>";
function colorNumber(value) {
    // Converti il valore in numero
    var num = parseFloat(value);
    // Restituisci il numero con il colore e il formato appropriati
    if (num > 100) {
        return "<span style=\"color: red; font-weight: bold;\">" + num + "</span>";
    } else if (num >= 70) {
        return "<span style=\"color: yellow;\">" + num + "</span>";
    } else {
        return "<span style=\"color: blue;\">" + num + "</span>";
    }
}

var content1 =
    "<table>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Physum:</span></td><td>" + phySum + " (" + MR(phySum / peak[0] * 5) + "%)</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">TacSum:</span></td><td>" + tacSum + " (" + MR(tacSum / peak[1] * 5) + "%)</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">TecSum:</span></td><td>" + tecSum + " (" + MR(tecSum / peak[2] * 5) + "%)</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">AllSum:</span></td><td>" + allSum + " + " + remainder + " </td></tr>" +
        "<tr><td></td><td>&nbsp;</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Finish Type</span></td><td></td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Regular:</span></td><td>" + shotregular + "</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Long:</span></td><td>" + shotlong + "</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Header:</span></td><td>" + shothead + "</td></tr>" +
        "<tr><td>&nbsp;</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Set Pieces</span></td><td></td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Corner(1-115): </span></td><td>" + colorNumber(CK) + "</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Freekick(1-115): </span></td><td>" + colorNumber(FK) + "</td></tr>" +
        "<tr><td><span style=\"color: black; font-weight: bold;\">Penalty(1-115): </span></td><td>" + colorNumber(PK) + "</td></tr>" +
    "</table>";var content2 = "<br><table><tr><td>Physique</td><td>" + R5RECstar[0] + "</td></tr><tr><td>Tactical</td><td>" + R5RECstar[1] + "</td></tr><tr><td>Technical</td><td>" + R5RECstar[2] + "</td></tr><tr><td>Assist</td><td>" + R5RECstar[3] + "</td></tr><tr><td>Defence</td><td>" + R5RECstar[4] + "</td></tr><tr><td>Shooting</td><td>" + R5RECstar[5] + "</td></tr>";
        }
        else {
            var content1 = "<table><tr><td>PhySum: </td><td>" + phySum + " (" + MR(phySum / peak[0] * 5) + "%)</td></tr><tr><td>TacSum: </td><td>" + tacSum + " (" + MR(tacSum / peak[1] * 5) + "%)</td></tr><tr><td>TecSum: </td><td>" + tecSum + " (" + MR(tecSum / peak[2] * 5) + "%)</td></tr><tr><td>AllSum: </td><td>" + allSum + " + " + remainder + " </td></tr></table>";
            var content2 = "<br><table><tr><td>Physique</td><td>" + R5RECstar[0] + "</td></tr><tr><td>Tactical</td><td>" + R5RECstar[1] + "</td></tr><tr><td>Technical</td><td>" + R5RECstar[2] + "</td></tr><tr><td>Saving</td><td>" + R5RECstar[6] + "</td></tr><tr><td>Counter</td><td>" + R5RECstar[7] + "</td></tr></table>";
        }
        $("#R5column_content").append(content1, content2);

//	### about R5 #################################################################################


        var R5config =
            "<div id=\"R5confg\" class=\"link_area\">"+
                "<ul>"+
                    "<li class=\"header\">R6 configuration</li>"+
                    "<li><input type=\"checkbox\" name=\"checkbox\" id=\"config0\" value=\"FP Detail\"> FP detail</li>"+
                    "<li><input type=\"checkbox\" name=\"checkbox\" id=\"config1\" value=\"All Position Rating\"> All Position Rating</li>"+
                    "<li><input type=\"checkbox\" name=\"checkbox\" id=\"config2\" value=\"R5 by Attacking Style\"> R6 by Attacking Style</li>"+
                    "<li><input type=\"checkbox\" name=\"checkbox\" id=\"config3\" value=\"Captaincy\"> Captaincy</li>"+
                    "<li><input type=\"checkbox\" name=\"checkbox\" id=\"config4\" value=\"Growth Record\"> Growth Record</li><br>"+
                    "<li id=\"reload\"><span class=\"button config\" style=\"width:80px; line-height:19px;\" onclick=\"window.location.reload()\"><span class=\"button_border\" style=\"width:78px; line-height:19px; padding: 0;\">Reload</span></span></li>"+
                "</ul>"+
            "</div>";
        $(".column1").append(aboutR5, R5config);
        $("input[name='checkbox']").attr("style","opacity:0.7");
        $("#reload").hide();

        $(function(){
            for(i = 0; i < 5; i++){
                if ($.cookie("config"+i) == undefined) $.cookie("config"+i,true,{expires:3650,path:"/players/"});
            }
            $("input[name='checkbox']").each(function(){
                var name = $(this).attr("id");
                $(this).change(function(){
                    $.cookie(name,$(this).prop("checked"),{expires:3650,path:"/players/"});
                    $("#reload").show();
                })
            })
        });

        for(i = 0; i < 5; i++){
        	if($.cookie("config"+i) == "true") {
                $("#config"+i).prop("checked", true);
                $("#R5table"+i+"_div").show();
            }
        	else {
                $("#config"+i).prop("checked", false);
                $("#R5table"+i+"_div").hide();
            }
        }



// ### Award ######################################################################################
        var award = $("html body div.main_center div.column3_a div.box div.box_body div.std ul.clean.underlined");
        var medal_a = award.find("img[src$='/pics/player_award_year.png']").length;
        var medal_b = award.find("img[src$='/pics/player_award_goal.png']").length;
        var medal_u21a = award.find("img[src$='/pics/player_award_year_u21.png']").length;
        var medal_u21b = award.find("img[src$='/pics/player_award_goal_u21.png']").length;
        var medals = medal_a + medal_b + medal_u21a + medal_u21b;
        var medals_icon = "";
        var award_table = "";
        var medals_a_row = "";
        var medals_b_row= "";
        var medals_u21a_row = "";
        var medals_u21b_row = "";
        if (medal_a) medals_a_row = "<tr><td style=\"font-size:small; color:gold; padding-left:30px\" align=\"left\">Calciatore Dell'Anno * " + medal_a + "</td></tr>";
        if (medal_b) medals_b_row = "<tr><td style=\"font-size:small; color:gold; padding-left:30px\" align=\"left\">Capocannoniere * " + medal_b + "</td></tr>";
        if (medal_u21a) medals_u21a_row = "<tr><td style=\"font-size:small; font-weight:normal; padding-left:30px\" align=\"left\"> Calciatore Dell'Anno Under21 * " + medal_u21a + "</td></tr>";
        if (medal_u21b) medals_u21b_row = "<tr><td style=\"font-size:small; font-weight:normal; padding-left:30px\" align=\"left\">U-21 Capocannoniere * " + medal_u21b + "</td></tr>";
        if (medals) {
            for (i = 0; i < medals; i++) {
                medals_icon += "<img src=\"/pics/icons/mini_medal.png\">&nbsp;";
            };
            award_table = "<div class=\"std\"><table id=\"award\" style=\"border-top:solid 1px;\"><tbody><tr><td align=\"center\">" + medals_icon + "</td></tr>" + medals_a_row + medals_b_row + medals_u21a_row + medals_u21b_row +"</tbody></table></div<div>";
        };

        var column3_a_box = $("html body div.main_center div.column3_a div.box div.box_head").length;
        $("html body div.main_center div.column3_a div.box div.box_head").eq(column3_a_box-1).append(award_table);

// ### functions ##################################################################################

        function calc_captaincy() {
            // WEIGHT(RVA's)
            var leadWeight = 0.5; // ## default Leadership weight 			DO NOT CHANGE
            var profWeight = 0.25; // ## default Professhionalism weight 		DO NOT CHANGE
            var rouWeight = 0.15; // ## default Routine weight 				DO NOT CHANGE
            var aggrWeight = 0.1; // ## default Aggression weight				DO NOT CHANGE
            if (leadWeight2 === 0.5 && profWeight2 === 0.25 && rouWeight2 === 0.15 && aggrWeight2 === 0.1)
                var weightDefault = "default";
            else
                var weightDefault = "custom";
            var cap = [];
            var cap2 = [];
            var cap3 = [];
            for (i = 1; i < 6; i++) {
                var leadWeight3 = [0, 0.131578947, 0.421052632, 0.657894737, 0.815789474, 1];
                if (leadWeight + profWeight + rouWeight + aggrWeight == 1)
                    cap[i] = funFix2(i * leadWeight3[i] * 20 * leadWeight + prof * 5 * profWeight + rou3 * rouWeight + (100 - aggr * 5) * aggrWeight);
                else
                    cap[i] = "---";
                if (leadWeight2 + profWeight2 + rouWeight2 + aggrWeight2 == 1)
                    cap2[i] = funFix2(i * leadWeight3[i] * 20 * leadWeight2 + prof * 5 * profWeight2 + rou3 * rouWeight2 + (100 - aggr * 5) * aggrWeight2);
                else
                    cap2[i] = "---";
                if (i * 4 + prof * 1 - aggr * 1 < 0)
                    cap3[i] = "neg.";
                else
                    cap3[i] = funFix2((i * 4 + prof * 1 - aggr * 1) / 39 * rou3);
            }
            return { cap, cap3, weightDefault, cap2 };
        }

        function calc_R5REC() {
            if (notGK)
                var peak = [4, 4, 6];
            else
                var peak = [4, 3, 4];
            var phyREC = funFix2((phySum / peak[0] + rou2) * 5 / 20);
            var tacREC = funFix2((tacSum / peak[1] + rou2) * 5 / 20);
            var tecREC = funFix2((tecSum / peak[2] + rou2) * 5 / 20);
            var assistREC = funFix2((skills[0] * 0.01 + skills[1] * 0.1 + skills[2] * 0.2 + skills[5] * 0.09 + skills[6] * 0.07 + skills[7] * 0.22 + skills[8] * 0.13 + skills[9] * 0.18 + rou2) / 4);
			var defenceREC = funFix2((skills[0] * 0.121481481 + skills[1] * 0.040740741 + skills[2] * 0.111111111 + skills[3] * 0.202962963 + skills[4] * 0.2 + skills[5] * 0.071111111 + skills[6] * 0.071111111 + skills[10] * 0.181481481 + rou2) / 4);
			var shootingREC = funFix2((skills[0] * 0.082813522 + skills[2] * 0.038541421 + skills[5] * 0.087757535 + skills[6] * 0.126339391 + skills[9] * 0.104203341 + skills[10] * 0.104949572 + skills[11] * 0.301067794 + skills[12] * 0.154327424 + rou2) / 4);
			var savingREC = funFix2((skills[0] * 0.092691271 + skills[1] * 0.007577625 + skills[2] * 0.104277679 + skills[3] * 0.278073812 + skills[4] * 0.069518453 + skills[5] * 0.278073812 + skills[6] * 0.069518453 + skills[7] * 0.092691271 + skills[8] * 0.007577625 + rou2) / 4);
			var counterREC = funFix2((skills[0] * 0.046345635 + skills[1] * 0.003788813 + skills[2] * 0.052138840 + skills[3] * 0.139036906 + skills[4] * 0.034759226 + skills[5] * 0.139036906 + skills[6] * 0.034759226 + skills[7] * 0.046345635 + skills[8] * 0.003788813 + skills[9] * 0.25 + skills[10] * 0.25 + rou2) / 4);
            var R5REC = [phyREC, tacREC, tecREC, assistREC, defenceREC, shootingREC, savingREC, counterREC];
            var star1 = ["", "", "", "", "", "", "", ""];
            var star2 = [];
            var star3 = ["", "", "", "", "", "", "", ""];
            var R5RECstar = [];
            var star = "<img src = \"/pics/star.png\">";
            var halfstar = "<img src = \"/pics/half_star.png\">";
            var darkstar = "<img src = \"/pics/dark_star.png\">";
            var eightstar = "<img src=\"/pics/half_star.png\">";
            var over5star = "<img src=\"/pics/star.png\">";
            for (i = 0; i < 8; i++) {
                for (j = 0; j < Math.floor(R5REC[i]); j++) {
                    star1[i] += star;
                }
                star2[i] = R5REC[i] - Math.floor(R5REC[i]);
                if (R5REC[i] < 5 && star2[i] >= 0.5)
                    star2[i] = halfstar;
                else
                    star2[i] = "";
                if (5 - MR(R5REC[i]) >= 1) {
                    for (k = 0; k < 5 - MR(R5REC[i]); k++) {
                        star3[i] += darkstar;
                    }
                }
                else if (R5REC[i] >= 5.5)
                    star3[i] = over5star;
                else if (R5REC[i] >= 5.25 && R5REC[i] < 5.5)
                	star3[i] = eightstar;
                else
                    star3[i] = "";
                R5RECstar[i] = star1[i] + star2[i] + star3[i];
            }
            return { peak, R5RECstar };
        }

        function calc_stamina_effect() {
            var minR = [];
            var minR0 = [];
            var minR1 = [];
            if (FP[0] != FP[1]) {
                for (i = 1; i < 7; i++) {
                    minR0[i] = funFix2(R5FP0 * (1 - (20 - skills[1]) * i / 200));
                    minR1[i] = funFix2(R5FP1 * (1 - (20 - skills[1]) * i / 200));
                }
                minR0[0] = funFix2(R5FP0 * (1 - (20 - skills[1]) * 62 / 93 / 200));
                minR1[0] = funFix2(R5FP1 * (1 - (20 - skills[1]) * 62 / 93 / 200));
            }
            else {
                if (skills.length == 11)
                    var staGK = 4; //	GK
                else
                    var staGK = 1;
                for (i = 1; i < 7; i++) {
                    minR0[i] = funFix2(R5FP0 * (1 - (20 - skills[1]) * i / staGK / 200));
                }
                minR0[0] = funFix2(R5FP0 * (1 - (20 - skills[1]) * 62 / 93 / staGK / 200));
            }
            var R5FP = [R5FP0, R5FP1];
            for (i = 0; i < positionArray.length; i++) {
                if (i == 0)
                    minR[i] = [minR0[0], minR0[1], minR0[2], minR0[4], minR0[6]];
                else
                    minR[i] = [minR1[0], minR1[1], minR1[2], minR1[4], minR1[6]];
            }
            return { R5FP, minR };
        }

        function finish_type() {
            var shotregular = funFix2(skillsB[11] * 0.5 + (skillsB[9] + skillsB[6] + skillsB[2]) / 3 * 0.4 + (skillsB[0] + skillsB[5]) / 2 * 0.1 + rou2);
            var shotlong = funFix2(skillsB[12] * 0.5 + (skillsB[9] + skillsB[11] + skillsB[6]) / 3 * 0.4 + (skillsB[0] + skillsB[5]) / 2 * 0.1 + rou2);
            var shothead = funFix2(skillsB[10] * 0.5 + (skillsB[0] * 2 + skillsB[6]) / 3 * 0.4 + (skillsB[2] + skillsB[5]) / 2 * 0.1 + rou2);
            return { shotregular, shotlong, shothead };
        }

        function bep() {
            var futureSTA = 0;
            var bep = 0;
            if (newPlayer == 0) {
                var futureSI = [];
                var wage2 = [];
                for (i = 1; i < 12; i++){
                    if (notGK) futureSI[i] = parseInt(MP((funFix1(TI / session / 10 * i + allSum + remainder * 1)), 7) / (MP(2, 9) * MP(5, 4) * MP(7, 7)));
                    else futureSI[i] = parseInt(MP(funFix1(TI / session / 10 * i + allSum + remainder * 1) / 11 * 14, 7) / (MP(2, 9) * MP(5, 4) * MP(7, 7)));
                    wage2[i] = futureSI[i]*wage_rate;
                }

                if (notGK) futureSTA = parseInt(futureSI[6] * 500 * MP(300 / (ageMonths + 6), 2.5));
                else futureSTA = parseInt(futureSI[6] * 500 * MP(300 / (ageMonths + 6), 2.5) * 0.75);

                if (session < 5) bep = parseInt(futureSTA * 0.94 - wage * 7); // 移籍税6% 移籍不可期間6週+1週分の給料
                else bep = parseInt(futureSTA * 0.94 - wage * (11 - session) - wage2[session-4] * (session-4));

                if (session <= month) bep = en.format(bep);
                else bep = "(" + en.format(bep) + ")";
            }
            return { bep, futureSTA };
        }

        function calc_VALUE() {
            function calcR5V(i) {
                i = MR(R5Value_base * i);
                return i;
            }
            function calcR5V2(i) {
                i = MR(R5Value2_base * i);
                return i;
            }
            var ageValue = (1 / 50) * (100 - (100) * MP(Math.E, -1 * (443 - ageMonths) * 0.008)) * 240 / ageMonths;
            if (rou3 == 0)
                rou3 = 0.1;
            var rouValue = (1 / 80) * (100 - (100) * MP(Math.E, -rou3 / ((ageMonths - 179) * 0.283) * 1.529445597));
            var ratValue = R5FP0 > R5FP1 ? R5FP0 : R5FP1;
            var nation = document.getElementsByClassName("country_link ")[0].getAttribute("href").substring(16).replace(/\/$/, '');
            var nation_rank_number = nation_rank.indexOf(nation) + 1;
            var rankadapt = [1, 1.3, 1.2, 1.2, 1.15, 1.15, 1.15, 1.15, 1.15, 1.15, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.1, 1.05, 1.05, 1.05, 1.05, 1.05];
            var rankValue = rankadapt[nation_rank_number];
            if (document.getElementsByClassName("nt_icon").length) {
                var NTageValue = (400 - ageMonths) / 100;
                if (NTageValue < 1.1)
                    NTageValue = 1.1;
                var NTValue = NTageValue * rankValue;
            }
            else
                var NTValue = 1;
            //				DC    DL/R  DMC   DML/R MC   ML/R  OMC   OML/R F	GK
            var posValue = [1.2, 1.0, 1.1, 0.7, 1.2, 1.0, 0.9, 0.8, 1.2, 0.8];
            if (R5FP0 > R5FP1) {
                if (R5FP0 / R5FP1 > 1.05)
                    posValue = posValue[FP[0]] * 1;
                else
                    posValue = Math.max(posValue[FP[0]] * 1, posValue[FP[1]] * 1);
            }
            else if (R5FP0 < R5FP1) {
                if (R5FP1 / R5FP0 > 1.05)
                    posValue = posValue[FP[1]] * 1;
                else
                    posValue = Math.max(posValue[FP[0]] * 1, posValue[FP[1]] * 1);
            }
            else
                posValue = posValue[FP[0]] * 1;
            if (FP[0] != FP[1])
                var FPValue = 1.1;
            else
                var FPValue = 1;
            if (funFix2(REREC[1][FP[0]] * 1) < funFix2(REREC[1][FP[1]] * 1))
                var FPR5pure = funFix2(REREC[1][FP[1]] * 1);
            else
                var FPR5pure = funFix2(REREC[1][FP[0]] * 1);
            if (notGK)
                var skillMax = 280;
            else
                var skillMax = 220;
            var SIValue = SI * skillMax / allSum * FPR5pure / 100;
            if (session <= month) {
                if (newPlayer > 0) {
                    var aveTI = (27 - year) * 2;
                    var TIValue = ML(aveTI);
                }
                else {
                    var aveTI = TI / session2;
                    if (year <= 24) {
                        var TIValue = [];
                        if (year < 18)
                            TIValue = [ML(aveTI) * (18 - year), ML(aveTI) * (19 - year)];
                        else if (year == 18)
                            TIValue = [ML(aveTI) / 3, ML(aveTI)];
                        else if (year == 19)
                            TIValue = [ML(aveTI) / 2, ML(aveTI)];
                        else if (year == 20)
                            TIValue = [ML(aveTI), ML(aveTI) * 2];
                        else if (year == 21 || year == 22)
                            TIValue = [ML(aveTI), ML(aveTI) * ((25 - year) * 0.5)];
                        else
                            TIValue = [ML(aveTI), ML(aveTI) * 1.5];
                    }
                    else
                        var TIValue = ML(aveTI);
                    if (aveTI < 0) {
                        if (year <= 24)
                            TIValue = [1 + aveTI / 10, 1];
                        else
                            TIValue = 1 + aveTI / 10;
                    }
                    if (aveTI >= 0 && aveTI < 2.8) {
                        if (year <= 24)
                            TIValue = [1, 1.1];
                        else
                            TIValue = 1;
                    }
                }
            }
            else {
                var aveTI = [];
                var TIValue = [];
                if (newPlayer > 0) {
                    aveTI = [(27 - year) * 2 - 2, (27 - year) * 2];
                    TIValue = [ML(aveTI[0]), ML(aveTI[1])];
                }
                else if (year <= 24) {
                    if (year < 18) {
                        aveTI = [TI / session2 - 2, TI / ((session2 - month) / 2 + month)];
                        TIValue = [ML(aveTI[0]) * (18 - year), ML(aveTI[0]) * (19 - year), ML(aveTI[1]) * (18 - year), ML(aveTI[1]) * (19 - year)];
                    }
                    else if (year == 18) {
                        aveTI = [TI / ((session2 - month) * 1.5 + month), TI / ((session2 - month) / 1.5 + month)];
                        TIValue = [ML(aveTI[0]) / 3, ML(aveTI[0]), ML(aveTI[1]) / 3, ML(aveTI[1])];
                    }
                    else if (year == 19) {
                        aveTI = [TI / ((session2 - month) * 4 + month), TI / session2];
                        TIValue = [ML(aveTI[0]) / 2, ML(aveTI[0]), ML(aveTI[1]) / 2, ML(aveTI[1])];
                    }
                    else if (year == 20 || year == 21) {
                        aveTI = [TI / ((session2 - month) * 3 + month), TI / ((session2 - month) / 2 + month)];
                        if (year == 20)
                            TIValue = [ML(aveTI[0]), ML(aveTI[0]) * 2, ML(aveTI[1]), ML(aveTI[1]) * 2];
                        else
                            TIValue = [ML(aveTI[0]), ML(aveTI[0]) * ((25 - year) * 0.5), ML(aveTI[1]), ML(aveTI[1]) * ((25 - year) * 0.5)];
                    }
                    else {
                        aveTI = [TI / ((session2 - month) * 3 + month), TI / session2 - 1];
                        if (year == 22)
                            TIValue = [ML(aveTI[0]), ML(aveTI[0]) * ((25 - year) * 0.5), ML(aveTI[1]), ML(aveTI[1]) * ((25 - year) * 0.5)];
                        else
                            TIValue = [ML(aveTI[0]), ML(aveTI[0]) * 1.5, ML(aveTI[1]), ML(aveTI[1]) * 1.5];
                    }
                }
                else {
                    aveTI = [TI / session2 - 0.5, TI / session2];
                    TIValue = [ML(aveTI[0]), ML(aveTI[1])];
                }
                if (year <= 24) {
                    if (aveTI[0] < 0) {
                        TIValue[0] = 1 + aveTI[0] / 10;
                        TIValue[1] = 1 + aveTI[0] / 10;
                    }
                    if (aveTI[1] < 0) {
                        TIValue[2] = 1 + aveTI[1] / 10;
                        TIValue[3] = 1 + aveTI[1] / 10;
                    }
                    if (aveTI[0] >= 0 && aveTI[0] < 2.8) {
                        TIValue[0] = 1;
                        TIValue[1] = 1;
                    }
                    if (aveTI[1] >= 0 && aveTI[1] < 2.8) {
                        TIValue[2] = 1;
                        TIValue[3] = 1;
                    }
                }
                else {
                    if (aveTI[0] < 0)
                        TIValue[0] = 1 + aveTI[0] / 10;
                    if (aveTI[1] < 0)
                        TIValue[1] = 1 + aveTI[1] / 10;
                    if (aveTI[0] >= 0 && aveTI[0] < 2.8)
                        TIValue[0] = 1;
                    if (aveTI[1] >= 0 && aveTI[1] < 2.8)
                        TIValue[1] = 1;
                }
            }
            var bloom = 1;
            if (notGK) {
                SI = SI * 1;
                if (year == 18) {
                    if (SI >= 50000)
                        bloom = 0.3;
                    if (SI > 25000 && SI < 50000)
                        bloom = 0.4;
                }
                if (year == 19) {
                    if (SI >= 100000)
                        bloom = 0.4;
                    if (SI >= 75000 && SI < 100000)
                        bloom = 0.5;
                    if (SI > 50000 && SI < 75000)
                        bloom = 0.6;
                }
                if (year == 20) {
                    if (SI >= 150000)
                        bloom = 0.5;
                    if (SI >= 100000 && SI < 150000)
                        bloom = 0.6;
                    if (SI > 75000 && SI < 100000)
                        bloom = 0.7;
                }
                if (year == 21) {
                    if (SI >= 200000)
                        bloom = 0.6;
                    if (SI >= 150000 && SI < 200000)
                        bloom = 0.7;
                    if (SI > 100000 && SI < 150000)
                        bloom = 0.8;
                }
                if (year == 22) {
                    if (SI >= 250000)
                        bloom = 0.7;
                    if (SI >= 200000 && SI < 250000)
                        bloom = 0.8;
                    if (SI > 150000 && SI < 200000)
                        bloom = 0.9;
                }
                if (year == 23) {
                    if (SI >= 300000)
                        bloom = 0.8;
                    if (SI >= 250000 && SI < 300000)
                        bloom = 0.9;
                }
                if (year == 24 && SI >= 350000)
                    bloom = 0.9;
            }
            var R5Value_base = SIValue * wage_rate * ageValue * rouValue * ratValue * NTValue * FPValue * posValue * (1 + ((ratValue - 100) / 100)) * bloom;
            if (session <= month) {
                if (newPlayer == 0 && year <= 24) {
                    var R5Value = [calcR5V(TIValue[0]), calcR5V(TIValue[1])];
                    var maxR5Value = Math.max.apply(null, R5Value);
                    var minR5Value = Math.min.apply(null, R5Value);
                    maxR5Value = Math.max(maxR5Value, staPrice);
                    minR5Value = Math.max(minR5Value, staPrice);
                }
                else {
                    var R5Value = calcR5V(TIValue);
                    R5Value = Math.max(R5Value, staPrice);
                }
            }
            else {
                if (newPlayer == 0 && year <= 24)
                    var R5Value = [calcR5V(TIValue[0]), calcR5V(TIValue[1]), calcR5V(TIValue[2]), calcR5V(TIValue[3])];
                else
                    var R5Value = [calcR5V(TIValue[0]), calcR5V(TIValue[1])];
                var maxR5Value = Math.max.apply(null, R5Value);
                var minR5Value = Math.min.apply(null, R5Value);
                maxR5Value = Math.max(maxR5Value, staPrice);
                minR5Value = Math.max(minR5Value, staPrice);
            }
            var hidden = hidden_skill_table.getElementsByTagName("td");
            if (hidden[0].innerHTML != "") {
                var x;
                for (var i = 0; i < 4; i++) {
                    x = hidden[i].getAttribute("tooltip").match(/\d+/);
                    if (x < 10)
                        x = " " + x;
                    hidden[i].setAttribute("style", "white-space: nowrap;");
                    hidden[i].innerHTML += " (" + x + "/20)";
                }
                if (R5FP0 > R5FP1)
                    var valueFP = FP[0];
                else
                    var valueFP = FP[1];
                var inju = hidden[0].getAttribute("tooltip").match(/\d+/);
                var aggr = hidden[1].getAttribute("tooltip").match(/\d+/);
                var prof = hidden[2].getAttribute("tooltip").match(/\d+/);
                var adap = hidden[3].getAttribute("tooltip").match(/\d+/);
                var injuValue = [0, 0.050, 0.040, 0.030, 0.020, 0.010, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.010, -0.020, -0.030, -0.040, -0.050];
                var aggrValue = [[0, 0.100, 0.080, 0.060, 0.040, 0.020, 0, 0, 0, 0, 0, 0, 0, -0.020, -0.040, -0.060, -0.080, -0.100, -0.120, -0.140, -0.160],
                [0, 0.100, 0.080, 0.060, 0.040, 0.020, 0, 0, 0, 0, 0, 0, 0, -0.020, -0.040, -0.060, -0.080, -0.100, -0.120, -0.140, -0.160],
                [0, 0.100, 0.080, 0.060, 0.040, 0.020, 0, 0, 0, 0, 0, 0, 0, -0.020, -0.040, -0.060, -0.080, -0.100, -0.120, -0.140, -0.160],
                [0, 0.080, 0.060, 0.050, 0.030, 0.010, 0, 0, 0, 0, 0, 0, 0, -0.010, -0.020, -0.030, -0.040, -0.050, -0.060, -0.080, -0.100],
                [0, 0.080, 0.060, 0.050, 0.030, 0.010, 0, 0, 0, 0, 0, 0, 0, -0.010, -0.020, -0.030, -0.040, -0.050, -0.060, -0.080, -0.100],
                [0, 0.080, 0.060, 0.050, 0.030, 0.010, 0, 0, 0, 0, 0, 0, 0, -0.010, -0.020, -0.030, -0.040, -0.050, -0.060, -0.080, -0.100],
                [0, 0.040, 0.030, 0.020, 0.010, 0.005, 0, 0, 0, 0, 0, 0, 0, -0.005, -0.010, -0.010, -0.020, -0.020, -0.030, -0.030, -0.040],
                [0, 0.040, 0.030, 0.020, 0.010, 0.005, 0, 0, 0, 0, 0, 0, 0, -0.005, -0.010, -0.010, -0.020, -0.020, -0.030, -0.030, -0.040],
                [0, 0.040, 0.030, 0.020, 0.010, 0.005, 0, 0, 0, 0, 0, 0, 0, -0.005, -0.010, -0.010, -0.020, -0.020, -0.030, -0.030, -0.040],
                [0, 0.020, 0.015, 0.010, 0.005, 0.003, 0, 0, 0, 0, 0, 0, 0, -0.003, -0.005, -0.005, -0.010, -0.010, -0.015, -0.015, -0.020],
                [0, 0.020, 0.015, 0.010, 0.005, 0.003, 0, 0, 0, 0, 0, 0, 0, -0.003, -0.005, -0.005, -0.010, -0.010, -0.015, -0.015, -0.020],
                [0, 0.020, 0.015, 0.010, 0.005, 0.003, 0, 0, 0, 0, 0, 0, 0, -0.003, -0.005, -0.005, -0.010, -0.010, -0.015, -0.015, -0.020],
                [0, 0.010, 0.008, 0.006, 0.004, 0.002, 0, 0, 0, 0, 0, 0, 0, -0.002, -0.004, -0.004, -0.006, -0.006, -0.008, -0.008, -0.010]];
                var profValue = [0, -0.020, -0.015, -0.010, -0.005, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.005, 0.010, 0.015, 0.020, 0.025, 0.030];
                var R5all = [REREC[2][1], REREC[2][0], REREC[2][1], REREC[2][3], REREC[2][2], REREC[2][3], REREC[2][5], REREC[2][4], REREC[2][5], REREC[2][7], REREC[2][6], REREC[2][7], REREC[2][8]];
                var maxR5 = Math.max.apply(null, R5all);
                var minR5 = Math.min.apply(null, R5all);
                var adapValue = [0, -0.020, -0.015, -0.010, -0.005, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0.005, 0.010, 0.015, 0.020, 0.025, 0.030];
                if (notGK) {
                    if (minR5 / maxR5 >= 0.9)
                        var hiddenValue = 1 + injuValue[inju] + aggrValue[valueFP][aggr] + profValue[prof] + adapValue[adap]; // R5の最大値と最小値の差が10%以上だった場合にはadapValueを加算しない。
                    else
                        var hiddenValue = 1 + injuValue[inju] + aggrValue[valueFP][aggr] + profValue[prof];
                }
                else
                    var hiddenValue = 1 + injuValue[inju] * 2 + profValue[prof];
                var R5Value2_base = R5Value_base * hiddenValue;
                if (session <= month) {
                    if (newPlayer == 0 && year <= 24) {
                        var R5Value2 = [calcR5V2(TIValue[0]), calcR5V2(TIValue[1])];
                        var maxR5Value2 = Math.max.apply(null, R5Value2);
                        var minR5Value2 = Math.min.apply(null, R5Value2);
                        maxR5Value2 = Math.max(maxR5Value2, staPrice);
                        minR5Value2 = Math.max(minR5Value2, staPrice);
                    }
                    else {
                        var R5Value2 = calcR5V2(TIValue);
                        R5Value2 = Math.max(R5Value2, staPrice);
                    }
                }
                else {
                    if (newPlayer == 0 && year <= 24)
                        var R5Value2 = [calcR5V2(TIValue[0]), calcR5V2(TIValue[1]), calcR5V2(TIValue[2]), calcR5V2(TIValue[3])];
                    else
                        var R5Value2 = [calcR5V2(TIValue[0]), calcR5V2(TIValue[1])];
                    var maxR5Value2 = Math.max.apply(null, R5Value2);
                    var minR5Value2 = Math.min.apply(null, R5Value2);
                    maxR5Value2 = Math.max(maxR5Value2, staPrice);
                    minR5Value2 = Math.max(minR5Value2, staPrice);
                }
            }
            return { i, hidden, R5all, adap, aggr, prof, minR5Value, maxR5Value, minR5Value2, maxR5Value2, R5Value, R5Value2, nation };
        }

        function calc_R5bonus() {
            var headerBonus = skillsB_rou[10] > 12 ? funFix2((MP(Math.E, (skillsB_rou[10] - 10) ** 3 / 1584.77) - 1) * 0.8 + MP(Math.E, (skillsB_rou[0] * skillsB_rou[0] * 0.007) / 8.73021) * 0.15 + MP(Math.E, (skillsB_rou[6] * skillsB_rou[6] * 0.007) / 8.73021) * 0.05) : 0;
            var fkBonus = funFix2(MP(Math.E, MP(skillsB_rou[13] + skillsB_rou[12] + skillsB_rou[9] * 0.5, 2) * 0.002) / 327.92526);
            var ckBonus = funFix2(MP(Math.E, MP(skillsB_rou[13] + skillsB_rou[8] + skillsB_rou[9] * 0.5, 2) * 0.002) / 983.65770);
            var pkBonus = funFix2(MP(Math.E, MP(skillsB_rou[13] + skillsB_rou[11] + skillsB_rou[9] * 0.5, 2) * 0.002) / 1967.31409);
            var gainBase = funFix2((skillsB_rou[0] ** 2 + skillsB_rou[1] ** 2 * 0.5 + skillsB_rou[2] ** 2 * 0.5 + skillsB_rou[3] ** 2 + skillsB_rou[4] ** 2 + skillsB_rou[5] ** 2 + skillsB_rou[6] ** 2) / 6 / 22.9 ** 2);
            var keepBase = funFix2((skillsB_rou[0] ** 2 * 0.5 + skillsB_rou[1] ** 2 * 0.5 + skillsB_rou[2] ** 2 + skillsB_rou[3] ** 2 + skillsB_rou[4] ** 2 + skillsB_rou[5] ** 2 + skillsB_rou[6] ** 2) / 6 / 22.9 ** 2);
            //	0:DC			1:DL/R			2:DMC			3:DML/R			4:MC			5:ML/R			6:OMC			7:OML/R			8:F
            var posGain = [gainBase * 0.3, gainBase * 0.3, gainBase * 0.9, gainBase * 0.6, gainBase * 1.5, gainBase * 0.9, gainBase * 0.9, gainBase * 0.6, gainBase * 0.3];
            var posKeep = [keepBase * 0.3, keepBase * 0.3, keepBase * 0.9, keepBase * 0.6, keepBase * 1.5, keepBase * 0.9, keepBase * 0.9, keepBase * 0.6, keepBase * 0.3];
            var allBonus = skills.length == 11 ? 0 : headerBonus * 1 + fkBonus * 1 + ckBonus * 1 + pkBonus * 1;
            if (skills.length == 11) {
                var R5FP0 = funFix2(REREC[2][FP[0]] * 1 + allBonus * 1);
                var R5FP1 = funFix2(REREC[2][FP[1]] * 1 + allBonus * 1);
            }
            else {
                var R5FP0 = funFix2(REREC[2][FP[0]] * 1 + allBonus * 1 + posGain[FP[0]] * 1 + posKeep[FP[0]] * 1);
                var R5FP1 = funFix2(REREC[2][FP[1]] * 1 + allBonus * 1 + posGain[FP[1]] * 1 + posKeep[FP[1]] * 1);
            }
            return { R5FP0, R5FP1, posGain, posKeep, headerBonus, ckBonus, fkBonus, pkBonus, allBonus };
        }

        function calc_TI() {
            var wage = new String(gettr[4].getElementsByTagName("span")[0].innerHTML).replace(/,/g, "");
            var today = new Date();
            var day = (today.getTime() - training1.getTime()) / 1000 / 3600 / 24;
            while (day > 84 - 16 / 24)
                day -= 84;
            var session = Math.floor(day / 7) + 1;
            var check = today.getTime() - SS.getTime();
            var season = 84 * 24 * 3600 * 1000;
            var count = 0;
            var ageMax = 20.1 + session / 12;

            while (check > season) {
                check -= season;
                count++;
            }

            if (wage == 30000 || (player_id > youthID && count == 0)) {
                var newPlayer = 1;
                wage_rate = 23.75;
            }
            else if (wage > 30000 && (player_id > youthID && count == 0)) {
                var newPlayer = 2;
                wage_rate = 23.75;
            }
            else var newPlayer = 0;

            if (document.getElementsByClassName("gk")[0] == null) var weight = 263533760000;
            else var weight = 48717927500;

            var TI = MP(2, ML(weight * SI) / ML(MP(2, 7))) - MP(2, ML(weight * wage / (wage_rate)) / ML(MP(2, 7)));
            TI = MR(TI * 10);
            const session2 = session == 0 ? 12 : session;
            return { weight, session, newPlayer, TI, session2, wage };
        }

        function calc_SellToAgent() {
            if (notGK)
                var staPrice = parseInt(SI * 500 * MP(300 / ageMonths, 2.5));
            else
                var staPrice = parseInt(SI * 500 * MP(300 / ageMonths, 2.5) * 0.75);
            var maxPrice = parseInt(SI * (192400 / (ageMonths / 12) - 5200));
            if (maxPrice < staPrice)
                maxPrice = staPrice;
            return { staPrice, maxPrice };
        }

        function calc_age() {
            var age = gettr[2].getElementsByTagName("td")[0].innerHTML;
            var yearidx = age.search(/\d\d/);
            var year = age.substr(yearidx, 2);
            age = age.slice(yearidx + 2);
            var month = Number(age.replace(/\D+/g, ""));
            var ageMonths = year * 12 + month * 1;
            return { ageMonths, month, year };
        }
    }

    document.calculateREREC = function (positionIndex, skills, SI, rou) {
        if (positionIndex == 13) var weight = 48717927500;
        else var weight = 263533760000;
        var rec = [];			// RERECb
        var ratingR = [];		// RatingR6
        var ratingR5 = [];		// RatingR6 + routine
        var skillSum = 0;

        for (var i = 0; i < skills.length; i++) {
            skillSum += parseInt(skills[i]);
        }
        for (i = 0; 2 + i <= positionIndex; i += 2) {		// TrExMaとRECのweight表のずれ修正
            positionIndex--;
        }
        var remainder = MR((MP(2, ML(weight * SI) / ML(MP(2, 7))) - skillSum) * 10) / 10;		// RatingR5 remainder
        for (var i = 0; i < 10; i++) {
            rec[i] = 0;
            ratingR[i] = 0;
        }
        for (var j = 0; j < 9; j++) {		// All position
            var remainderWeight = 0;		// REREC remainder weight sum
            var remainderWeight2 = 0;		// RatingR5 remainder weight sum
            var not20 = 0;					// 20以外のスキル数
            if (positionIndex == 9) j = 9;	// GK

            for (var i = 0; i < weightR[positionIndex].length; i++) {
                rec[j] += skills[i] * weightRb[j][i];
                ratingR[j] += skills[i] * weightR5[j][i];
                if (skills[i] != 20) {
                    remainderWeight += weightRb[j][i];
                    remainderWeight2 += weightR5[j][i];
                    not20++;
                }
            }
            if (remainder / not20 > 0.9 || not20 == 0) {
                if (positionIndex == 9) not20 = 11;
                else not20 = 14;
                remainderWeight = 1;
                remainderWeight2 = 5;
            }
            rec[j] = funFix3((rec[j] + remainder * remainderWeight / not20 - 2) / 3);
            ratingR[j] += remainder * remainderWeight2 / not20;
            ratingR5[j] = funFix2(ratingR[j] + rou * 5);
            ratingR[j] = funFix2(ratingR[j]);
            if (positionIndex == 9) j = 9;		// Loop end
        }
        var recAndRating = [rec, ratingR, ratingR5];
        return recAndRating;
    };

    document.calculateREREC2 = function (positionIndex, skills, SI) {
        if (positionIndex == 13) {
            var skillWeightSum = MP(SI, 0.143) / 0.02979;			// GK Skillsum
            var weight = 48717927500;
        }
        else {
            var skillWeightSum = MP(SI, 1 / 6.99194) / 0.02336483;	// Other Skillsum
            var weight = 263533760000;
        }
        var skillSum = 0;
        for (var j = 0; j < skills.length; j++) {
            skillSum += parseInt(skills[j]);
        }
        var remainder = MR((MP(2, ML(weight * SI) / ML(MP(2, 7))) - skillSum) * 10) / 10;		// 正確な余り
        var rec = 0;
        var weightSum = 0;
        var not20 = 0;

        for (i = 0; 2 + i <= positionIndex; i += 2) {		// TrExMaとRECのweight表のずれ修正
            positionIndex--;
        }
        skillWeightSum -= skillSum;			// REREC remainder
        for (var i = 0; i < weightR[positionIndex].length; i++) {
            rec += skills[i] * weightR[positionIndex][i];
            if (skills[i] != 20) {
                weightSum += weightR[positionIndex][i];
                not20++;
            }
        }
        if (remainder / not20 > 0.9 || not20 == 0) {
            weightSum = 0;
            for (var i = 0; i < weightR[positionIndex].length; i++) weightSum += weightR[positionIndex][i];
            if (positionIndex == 9) not20 = 11;
            else not20 = 14;
        }
        rec += skillWeightSum * weightSum / not20;	// REREC Score
        if (positionIndex == 9) rec *= 1.27;					// GK
        rec = funFix2((rec - recLast[0][positionIndex]) / recLast[1][positionIndex]);

        return rec;
    };

    if (testmode == 99) {
        var prevID = player_id * 1 - 1;
        var prev10ID = player_id * 1 - 10;
        var prev100ID = player_id * 1 - 100;
        var prev1000ID = player_id * 1 - 1000;
        var prev10000ID = player_id * 1 - 10000;
        var nextID = player_id * 1 + 1;
        var next10ID = player_id * 1 + 10;
        var next100ID = player_id * 1 + 100;
        var next1000ID = player_id * 1 + 1000;

        var id_select = "<div><a href=\"https://trophymanager.com/players/" + prev10000ID + "/\"><<10000</a>&nbsp;&nbsp;<a href=\"https://trophymanager.com/players/" + prev1000ID + "/\"><<1000</a>&nbsp;&nbsp;<a href=\"https://trophymanager.com/players/" + prev100ID + "/\"><<100</a>&nbsp;&nbsp;<a href=\"https://trophymanager.com/players/" + prev10ID + "/\"><<10</a>&nbsp;&nbsp;<a href=\"https://trophymanager.com/players/" + prevID + "/\"><<1</a>&nbsp;&nbsp;<a href=\"https://trophymanager.com/players/" + nextID + "/\">1>></a>&nbsp;&nbsp;<a href=\"https://trophymanager.com/players/" + next10ID + "/\">10>></a>&nbsp;&nbsp;<a href=\"https://trophymanager.com/players/" + next100ID + "/\">100>></a>&nbsp;&nbsp;<a href=\"https://trophymanager.com/players/" + next1000ID + "/\">1000>></a></div>";
        $("#top_menu_sub").append(id_select);
    }

   var version = "1.0"; // Assicurati che questa variabile sia definita

var aboutR5 =
    "<div class=\"aboutR5\">" +
    "RatingR6 " + version + "&nbsp;&nbsp;&nbsp;&nbsp;RatingR6 is developed by <a href=\"/club/4052254/\">Metalist Dominia FC</a>" +
    "</div>";
    $(".body_end").append(aboutR5);
    if ($(".aboutR5").length > 1) alert("CAUTION\nAnother version of RatingR5 is loaded at the same time.\nCheck the Tampermonkey dashboard and make sure you have one valid RationgR5.");


    (function () {
        var playerTable = document.getElementsByClassName("skill_table zebra")[0];
        var skillArray = document.getSkills(playerTable);
        computeRating(playerTable, skillArray);
    })();
}
// Funzioni esistenti nel tuo script
function existingFunction1() {
    // Codice esistente...
}

function existingFunction2() {
    // Codice esistente...
}

// ... Altre funzioni esistenti

// Funzione per aggiungere stili CSS dinamicamente
function addDynamicStyles() {
    const style = document.createElement('style');
    style.textContent = `
        .player-info {
            display: flex;
            flex-direction: column; /* Posiziona gli elementi verticalmente */
            align-items: center;    /* Allinea al centro orizzontalmente */
        }

        .icon-container {
            width: 24px;
            height: 24px;
            margin-top: 8px; /* Spazio sopra l'icona */
            vertical-align: middle;
        }

        .icon-green {
            color: green;
            transform: rotate(0deg); /* Orizzontale */
        }

        .icon-yellow {
            color: yellow;
            transform: rotate(45deg); /* Diagonale verso l'alto */
        }

        .icon-red {
            color: red;
            transform: rotate(-45deg); /* Diagonale verso il basso */
        }
    `;
    document.head.appendChild(style);
}

// Funzione per aggiornare lo stato del giocatore basato sulla media dei voti
function updatePlayerStatus(mediaVoto) {
    // Seleziona l'elemento dove aggiungere l'icona
    let playerNameElement = document.querySelector('.player-info');

    if (!playerNameElement) {
        console.error('Elemento per il nome del giocatore non trovato.');
        return;
    }

    // Crea un nuovo elemento per l'icona
    let iconElement = document.createElement('span');
    iconElement.classList.add('icon-container');

    // Rimuovere eventuali icone esistenti
    let existingIcon = playerNameElement.querySelector('.icon-container');
    if (existingIcon) {
        playerNameElement.removeChild(existingIcon);
    }

    // Determinare e applicare la classe di icona appropriata
    if (mediaVoto >= 5 && mediaVoto <= 5.5) {
        iconElement.classList.add('icon-green');
        iconElement.innerHTML = '<i class="fas fa-arrow-right"></i>'; // Orizzontale
    } else if (mediaVoto > 5.5) {
        iconElement.classList.add('icon-yellow');
        iconElement.innerHTML = '<i class="fas fa-arrow-up"></i>'; // Diagonale verso l’alto
    } else {
        iconElement.classList.add('icon-red');
        iconElement.innerHTML = '<i class="fas fa-arrow-down"></i>'; // Diagonale verso il basso
    }

    // Aggiungi l'icona sotto il nome del giocatore
    playerNameElement.appendChild(iconElement);
}

// Funzione per simulare il recupero dei dati del giocatore
function fetchPlayerData() {
    // Esempio di recupero dati, sostituisci con la tua logica
    let playerData = {
        mediaVoto: 5.4 // Sostituisci con il valore reale ottenuto
    };

    // Aggiorna lo stato del giocatore basato sulla media dei voti
    updatePlayerStatus(playerData.mediaVoto);
}

// Assicurati che il DOM sia completamente carico prima di eseguire il codice
document.addEventListener('DOMContentLoaded', function() {
    // Aggiungi stili CSS dinamicamente
    addDynamicStyles();

    // Chiamate alle funzioni esistenti
    existingFunction1();
    existingFunction2();

    // ... Altre chiamate a funzioni esistenti

    // Chiamata alla funzione per aggiornare lo stato del giocatore
    fetchPlayerData();
});
// Funzioni esistenti nel tuo script
function existingFunction1() {
    // Codice esistente...
}

function existingFunction2() {
    // Codice esistente...
}

// Aggiungi stili CSS dinamicamente
function addDynamicStyles() {
    const style = document.createElement('style');
    style.textContent = `
        .player-info {
            display: flex;
            flex-direction: column; /* Posiziona gli elementi verticalmente */
            align-items: center;    /* Allinea al centro orizzontalmente */
        }

        .icon-container {
            width: 24px;
            height: 24px;
            margin-top: 8px; /* Spazio sopra l'icona */
            vertical-align: middle;
        }

        .icon-green {
            color: green;
            transform: rotate(0deg); /* Orizzontale */
        }

        .icon-yellow {
            color: yellow;
            transform: rotate(45deg); /* Diagonale verso l'alto */
        }

        .icon-red {
            color: red;
            transform: rotate(-45deg); /* Diagonale verso il basso */
        }
    `;
    document.head.appendChild(style);
}
// Funzioni esistenti nel tuo script
function existingFunction1() {
    // Codice esistente...
}

function existingFunction2() {
    // Codice esistente...
}

// Aggiungi Font Awesome e stili CSS dinamicamente
function setupPage() {
    // Aggiungi Font Awesome dinamicamente
    const fontAwesomeLink = document.createElement('link');
    fontAwesomeLink.rel = 'stylesheet';
    fontAwesomeLink.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css';
    document.head.appendChild(fontAwesomeLink);

    // Aggiungi stili CSS dinamicamente
    const style = document.createElement('style');
    style.textContent = `
        .player-info {
            display: flex;
            flex-direction: column; /* Posiziona gli elementi verticalmente */
            align-items: center;    /* Allinea al centro orizzontalmente */
        }

        .icon-container {
            width: 24px;
            height: 24px;
            margin-top: 8px; /* Spazio sopra l'icona */
            vertical-align: middle;
        }

        .icon-green {
            color: green;
            transform: rotate(0deg); /* Orizzontale */
        }

        .icon-yellow {
            color: yellow;
            transform: rotate(45deg); /* Diagonale verso l'alto */
        }

        .icon-red {
            color: red;
            transform: rotate(-45deg); /* Diagonale verso il basso */
        }
    `;
    document.head.appendChild(style);
}
// Funzioni esistenti nel tuo script
function existingFunction1() {
    // Codice esistente...
}

function existingFunction2() {
    // Codice esistente...
}

// Aggiungi Font Awesome e stili CSS dinamicamente
function setupPage() {
    // Aggiungi Font Awesome dinamicamente
    const fontAwesomeLink = document.createElement('link');
    fontAwesomeLink.rel = 'stylesheet';
    fontAwesomeLink.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css';
    document.head.appendChild(fontAwesomeLink);

    // Aggiungi stili CSS dinamicamente
    const style = document.createElement('style');
    style.textContent = `
        .icon-container {
            display: inline-block;
            margin-left: 8px; /* Spazio a sinistra dell'icona */
            vertical-align: middle;
        }

        .icon-green {
            color: green;
            transform: rotate(0deg); /* Orizzontale */
        }

        .icon-yellow {
            color: yellow;
            transform: rotate(45deg); /* Diagonale verso l'alto */
        }

        .icon-red {
            color: red;
            transform: rotate(-45deg); /* Diagonale verso il basso */
        }
    `;
    document.head.appendChild(style);
}

// Funzione per aggiornare lo stato del giocatore basato sulla media dei voti
function updatePlayerStatus(mediaVoto) {
    // Seleziona l'elemento della media voto
    let mediaVotoElement = document.querySelector('.media-voto-selector'); // Modifica con il selettore corretto

    if (!mediaVotoElement) {
        console.error('Elemento della media voto non trovato.');
        return;
    }

    // Crea un nuovo elemento per l'icona
    let iconElement = document.createElement('span');
    iconElement.classList.add('icon-container');

    // Rimuovere eventuali icone esistenti
    let existingIcon = mediaVotoElement.querySelector('.icon-container');
    if (existingIcon) {
        mediaVotoElement.removeChild(existingIcon);
    }

    // Determinare e applicare la classe di icona appropriata
    if (mediaVoto >= 5 && mediaVoto <= 5.5) {
        iconElement.classList.add('icon-green');
        iconElement.innerHTML = '<i class="fas fa-arrow-right"></i>'; // Orizzontale
    } else if (mediaVoto > 5.5) {
        iconElement.classList.add('icon-yellow');
        iconElement.innerHTML = '<i class="fas fa-arrow-up"></i>'; // Diagonale verso l’alto
    } else {
        iconElement.classList.add('icon-red');
        iconElement.innerHTML = '<i class="fas fa-arrow-down"></i>'; // Diagonale verso il basso
    }

    // Aggiungi l'icona accanto alla media voto
    mediaVotoElement.appendChild(iconElement);
}
// Funzioni esistenti nel tuo script
function existingFunction1() {
    // Codice esistente...
}

function existingFunction2() {
    // Codice esistente...
}

// Aggiungi Font Awesome e stili CSS dinamicamente
function setupPage() {
    // Aggiungi Font Awesome dinamicamente se non è già presente
    if (!document.querySelector('link[href*="font-awesome"]')) {
        const fontAwesomeLink = document.createElement('link');
        fontAwesomeLink.rel = 'stylesheet';
        fontAwesomeLink.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css';
        document.head.appendChild(fontAwesomeLink);
    }

    // Aggiungi stili CSS dinamicamente
    const style = document.createElement('style');
    style.textContent = `
        .icon-container {
            display: inline-block;
            margin-left: 8px; /* Spazio a sinistra dell'icona */
            vertical-align: middle;
        }

        .icon-green {
            color: green;
            transform: rotate(0deg); /* Orizzontale */
        }

        .icon-yellow {
            color: yellow;
            transform: rotate(45deg); /* Diagonale verso l'alto */
        }

        .icon-red {
            color: red;
            transform: rotate(-45deg); /* Diagonale verso il basso */
        }
    `;
    document.head.appendChild(style);
}

// Funzione per aggiornare lo stato del giocatore basato sulla media dei voti
function updatePlayerStatus(mediaVoto) {
    // Seleziona l'elemento della media voto
    let mediaVotoElement = document.querySelector('.media-voto'); // Modifica con il selettore corretto

    if (!mediaVotoElement) {
        console.error('Elemento della media voto non trovato.');
        return;
    }

    // Crea un nuovo elemento per l'icona
    let iconElement = document.createElement('span');
    iconElement.classList.add('icon-container');

    // Rimuovere eventuali icone esistenti
    let existingIcon = mediaVotoElement.querySelector('.icon-container');
    if (existingIcon) {
        mediaVotoElement.removeChild(existingIcon);
    }

    // Determinare e applicare la classe di icona appropriata
    if (mediaVoto >= 5 && mediaVoto <= 5.5) {
        iconElement.classList.add('icon-green');
        iconElement.innerHTML = '<i class="fas fa-arrow-right"></i>'; // Orizzontale
    } else if (mediaVoto > 5.5) {
        iconElement.classList.add('icon-yellow');
        iconElement.innerHTML = '<i class="fas fa-arrow-up"></i>'; // Diagonale verso l’alto
    } else {
        iconElement.classList.add('icon-red');
        iconElement.innerHTML = '<i class="fas fa-arrow-down"></i>'; // Diagonale verso il basso
    }

    // Aggiungi l'icona accanto alla media voto
    mediaVotoElement.appendChild(iconElement);
}
// Funzioni esistenti nel tuo script
function existingFunction1() {
    // Codice esistente...
}

function existingFunction2() {
    // Codice esistente...
}

// Aggiungi Font Awesome e stili CSS dinamicamente
function setupPage() {
    // Aggiungi Font Awesome dinamicamente se non è già presente
    if (!document.querySelector('link[href*="font-awesome"]')) {
        const fontAwesomeLink = document.createElement('link');
        fontAwesomeLink.rel = 'stylesheet';
        fontAwesomeLink.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css';
        document.head.appendChild(fontAwesomeLink);
    }

    // Aggiungi stili CSS dinamicamente
    const style = document.createElement('style');
    style.textContent = `
        .icon-container {
            display: inline-block;
            margin-left: 8px; /* Spazio a sinistra dell'icona */
            vertical-align: middle;
        }

        .icon-green {
            color: green;
            transform: rotate(0deg); /* Orizzontale */
        }

        .icon-yellow {
            color: yellow;
            transform: rotate(45deg); /* Diagonale verso l'alto */
        }

        .icon-red {
            color: red;
            transform: rotate(-45deg); /* Diagonale verso il basso */
        }
    `;
    document.head.appendChild(style);
}


// Funzione per simulare il recupero dei dati del giocatore e aggiornare lo stato
function fetchPlayerDataAndUpdateStatus() {
    // Esempio di recupero dati, sostituisci con la tua logica
    let mediaVotoElement = document.querySelector('.media-voto'); // Modifica con il selettore corretto

    if (mediaVotoElement) {
        let mediaVoto = parseFloat(mediaVotoElement.textContent.trim());
        updatePlayerStatus(mediaVoto);
    } else {
        console.error('Elemento della media voto non trovato.');
    }
}

// Assicurati che il DOM sia completamente carico prima di eseguire il codice
document.addEventListener('DOMContentLoaded', function() {
    // Configura la pagina con Font Awesome e stili CSS
    setupPage();

    // Chiamate alle funzioni esistenti
    existingFunction1();
    existingFunction2();

    // ... Altre chiamate a funzioni esistenti

    // Chiamata alla funzione per aggiornare lo stato del giocatore
    fetchPlayerDataAndUpdateStatus();
});
// Funzioni esistenti nel tuo script
function existingFunction1() {
    // Codice esistente...
}

function existingFunction2() {
    // Codice esistente...
}

// Aggiungi Font Awesome e stili CSS dinamicamente
function setupPage() {
    // Aggiungi Font Awesome dinamicamente se non è già presente
    if (!document.querySelector('link[href*="font-awesome"]')) {
        const fontAwesomeLink = document.createElement('link');
        fontAwesomeLink.rel = 'stylesheet';
        fontAwesomeLink.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css';
        document.head.appendChild(fontAwesomeLink);
    }

    // Aggiungi stili CSS dinamicamente
    const style = document.createElement('style');
    style.textContent = `
        .icon-container {
            display: inline-block;
            margin-left: 8px; /* Spazio a sinistra dell'icona */
            vertical-align: middle;
        }

        .icon-green {
            color: green;
            transform: rotate(0deg); /* Orizzontale */
        }

        .icon-yellow {
            color: yellow;
            transform: rotate(45deg); /* Diagonale verso l'alto */
        }

        .icon-red {
            color: red;
            transform: rotate(-45deg); /* Diagonale verso il basso */
        }
    `;
    document.head.appendChild(style);
}

// Funzione per aggiornare lo stato del giocatore basato sulla media dei voti
function updatePlayerFormStatus(mediaVoto) {
    // Seleziona l'elemento della media voto
    let mediaVotoElement = document.querySelector('.media-voto'); // Modifica con il selettore corretto

    if (!mediaVotoElement) {
        console.error('Elemento della media voto non trovato.');
        return;
    }

    // Crea un nuovo elemento per l'icona
    let iconElement = document.createElement('span');
    iconElement.classList.add('icon-container');

    // Rimuovere eventuali icone esistenti
    let existingIcon = mediaVotoElement.querySelector('.icon-container');
    if (existingIcon) {
        mediaVotoElement.removeChild(existingIcon);
    }

    // Determinare e applicare la classe di icona appropriata
    if (mediaVoto >= 5 && mediaVoto <= 5.5) {
        iconElement.classList.add('icon-green');
        iconElement.innerHTML = '<i class="fas fa-arrow-right"></i>'; // Orizzontale
    } else if (mediaVoto > 5.5) {
        iconElement.classList.add('icon-yellow');
        iconElement.innerHTML = '<i class="fas fa-arrow-up"></i>'; // Diagonale verso l’alto
    } else {
        iconElement.classList.add('icon-red');
        iconElement.innerHTML = '<i class="fas fa-arrow-down"></i>'; // Diagonale verso il basso
    }

    // Aggiungi l'icona accanto alla media voto
    mediaVotoElement.appendChild(iconElement);
}
// Funzioni esistenti nel tuo script
function existingFunction1() {
    // Codice esistente...
}

function existingFunction2() {
    // Codice esistente...
}

// Aggiungi Font Awesome e stili CSS dinamicamente
function setupPage() {
    // Aggiungi Font Awesome dinamicamente se non è già presente
    if (!document.querySelector('link[href*="font-awesome"]')) {
        const fontAwesomeLink = document.createElement('link');
        fontAwesomeLink.rel = 'stylesheet';
        fontAwesomeLink.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css';
        document.head.appendChild(fontAwesomeLink);
    }

    // Aggiungi stili CSS dinamicamente
    const style = document.createElement('style');
    style.textContent = `
        .icon-container {
            display: inline-block;
            margin-left: 8px; /* Spazio a sinistra dell'icona */
            vertical-align: middle;
        }

        .icon-green {
            color: green;
            transform: rotate(0deg); /* Orizzontale */
        }

        .icon-yellow {
            color: yellow;
            transform: rotate(45deg); /* Diagonale verso l'alto */
        }

        .icon-red {
            color: red;
            transform: rotate(-45deg); /* Diagonale verso il basso */
        }
    `;
    document.head.appendChild(style);
}
// Funzioni esistenti nel tuo script
function existingFunction1() {
    // Codice esistente...
}

function existingFunction2() {
    // Codice esistente...
}

// Aggiungi Font Awesome e stili CSS dinamicamente
function setupPage() {
    // Aggiungi Font Awesome dinamicamente se non è già presente
    if (!document.querySelector('link[href*="font-awesome"]')) {
        const fontAwesomeLink = document.createElement('link');
        fontAwesomeLink.rel = 'stylesheet';
        fontAwesomeLink.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css';
        document.head.appendChild(fontAwesomeLink);
    }

    // Aggiungi stili CSS dinamicamente
    const style = document.createElement('style');
    style.textContent = `
        .icon-container {
            display: inline-block;
            margin-left: 8px; /* Spazio a sinistra dell'icona */
            vertical-align: middle;
        }

        .icon-green {
            color: green;
            transform: rotate(0deg); /* Orizzontale */
        }

        .icon-yellow {
            color: yellow;
            transform: rotate(45deg); /* Diagonale verso l'alto */
        }

        .icon-red {
            color: red;
            transform: rotate(-45deg); /* Diagonale verso il basso */
        }
    `;
    document.head.appendChild(style);
}
setTimeout(function() {
/* UPDATE EACH SEASON */
var youthID = 134648982;
var botID = 134307216;
var SS = new Date("11 22 2021 08:00:00 GMT"); // s70 start
var training1 = new Date("11 22 2021 23:00:00 GMT"); // first training
/* UPDATE EACH SEASON */
var wage_rate = 15.8079;
var Season = SESSION.season;

var positionNames = ["D C", "D L", "D R", "DM C", "DM L", "DM R", "M C", "M L", "M R", "OM C", "OM L", "OM R", "F", "GK"];
var positionFullNames = [
/* EN */	["Defender Center", "Defender Left", "Defender Right", "Defensive Midfielder Center", "Defensive Midfielder Left", "Defensive Midfielder Right", "Midfielder Center", "Midfielder Left", "Midfielder Right", "Offensive Midfielder Center", "Offensive Midfielder Left", "Offensive Midfielder Right", "Forward", "Goalkeeper"],
/* JP */	["ディフェンダー 中央", "ディフェンダー 左", "ディフェンダー 右", "守備的ミッドフィルダー 中央", "守備的ミッドフィルダー 左", "守備的ミッドフィルダー 右", "ミッドフィルダー 中央", "ミッドフィルダー 左", "ミッドフィルダー 右", "攻撃的ミッドフィルダー 中央", "攻撃的ミッドフィルダー 左", "攻撃的ミッドフィルダー 右", "フォワード", "ゴールキーパー"],
/* P  */	["Obrońca środkowy", "Obrońca lewy", "Obrońca prawy", "Defensywny pomocnik środkowy", "Defensywny pomocnik lewy", "Defensywny pomocnik prawy", "Pomocnik środkowy", "Pomocnik lewy", "Pomocnik prawy", "Ofensywny pomocnik środkowy", "Ofensywny pomocnik lewy", "Ofensywny pomocnik prawy", "Napastnik", "Bramkarz"],
/* D  */	["Forsvar Centralt", "Forsvar Venstre", "Forsvar Højre", "Defensiv Midtbane Centralt", "Defensiv Midtbane Venstre", "Defensiv Midtbane Højre", "Midtbane Centralt", "Midtbane Venstre", "Midtbane Højre", "Offensiv Midtbane Centralt", "Offensiv Midtbane Venstre", "Offensiv Midtbane Højre", "Angriber", "Målmand"],
/* I  */	["Difensore Centrale", "Difensore Sinistro", "Difensore Destro", "Centrocampista Difensivo Centrale", "Centrocampista Difensivo Sinistro", "Centrocampista Difensivo Destro", "Centrocampista Centrale", "Centrocampista Sinistro", "Centrocampista Destro", "Centrocampista Offensivo Centrale", "Centrocampista Offensivo Sinistro", "Centrocampista Offensivo Destro", "Attaccante", "Portiere"],
/* H  */	["Defensa Central", "Defensa Izquierdo", "Defensa Derecho", "Mediocampista Defensivo Central", "Mediocampista Defensivo Izquierdo", "Mediocampista Defensivo Derecho", "Mediocampista Central", "Mediocampista Izquierdo", "Mediocampista Derecho", "Mediocampista Ofensivo Central", "Mediocampista Ofensivo Izquierdo", "Mediocampista Ofensivo Derecho", "Delantero", "Portero"],
/* F  */	["Défenseur Central", "Défenseur Gauche", "Défenseur Droit", "Milieu défensif Central", "Milieu défensif Gauche", "Milieu défensif Droit", "Milieu Central", "Milieu Gauche", "Milieu Droit", "Milieu offensif Central", "Milieu offensif Gauche", "Milieu offensif Droit", "Attaquant", "Gardien de but"],
/* A  */	["Defender Center", "Defender Left", "Defender Right", "Defensive Midfielder Center", "Defensive Midfielder Left", "Defensive Midfielder Right", "Midfielder Center", "Midfielder Left", "Midfielder Right", "Offensive Midfielder Center", "Offensive Midfielder Left", "Offensive Midfielder Right", "Forward", "Goalkeeper"],
/* C  */	["Obrambeni Sredina", "Obrambeni Lijevo", "Obrambeni Desno", "Defenzivni vezni Sredina", "Defenzivni vezni Lijevo", "Defenzivni vezni Desno", "Vezni Sredina", "Vezni Lijevo", "Vezni Desno", "Ofenzivni vezni Sredina", "Ofenzivni vezni Lijevo", "Ofenzivni vezni Desno", "Napadač", "Golman"],
/* G  */	["Verteidiger Zentral", "Verteidiger Links", "Verteidiger Rechts", "Defensiver Mittelfeldspieler Zentral", "Defensiver Mittelfeldspieler Links", "Defensiver Mittelfeldspieler Rechts", "Mittelfeldspieler Zentral", "Mittelfeldspieler Links", "Mittelfeldspieler Rechts", "Offensiver Mittelfeldspieler Zentral", "Offensiver Mittelfeldspieler Links", "Offensiver Mittelfeldspieler Rechts", "Stürmer", "Torhüter"],
/* PO */	["Defesa Centro", "Defesa Esquerdo", "Defesa Direito", "Médio Defensivo Centro", "Médio Defensivo Esquerdo", "Médio Defensivo Direito", "Medio Centro", "Medio Esquerdo", "Medio Direito", "Medio Ofensivo Centro", "Medio Ofensivo Esquerdo", "Medio Ofensivo Direito", "Avançado", "Guarda-Redes"],
/* R  */	["Fundas Central", "Fundas Stânga", "Fundas Dreapta", "Mijlocas Defensiv Central", "Mijlocas Defensiv Stânga", "Mijlocas Defensiv Dreapta", "Mijlocas Central", "Mijlocas Stânga", "Mijlocas Dreapta", "Mijlocas Ofensiv Central", "Mijlocas Ofensiv Stânga", "Mijlocas Ofensiv Dreapta", "Atacant", "Portar"],
/* T  */	["Defans Orta", "Defans Sol", "Defans Sağ", "Defansif Ortasaha Orta", "Defansif Ortasaha Sol", "Defansif Ortasaha Sağ", "Ortasaha Orta", "Ortasaha Sol", "Ortasaha Sağ", "Ofansif Ortasaha Orta", "Ofansif Ortasaha Sol", "Ofansif Ortasaha Sağ", "Forvet", "Kaleci"],
/* RU */	["Defender Center", "Defender Left", "Defender Right", "Defensive Midfielder Center", "Defensive Midfielder Left", "Defensive Midfielder Right", "Midfielder Center", "Midfielder Left", "Midfielder Right", "Offensive Midfielder Center", "Offensive Midfielder Left", "Offensive Midfielder Right", "Forward", "Goalkeeper"],
/* CE */	["Obránce Střední", "Obránce Levý", "Obránce Pravý", "Defenzivní Záložník Střední", "Defenzivní Záložník Levý", "Defenzivní Záložník Pravý", "Záložník Střední", "Záložník Levý", "Záložník Pravý", "Ofenzivní záložník Střední", "Ofenzivní záložník Levý", "Ofenzivní záložník Pravý", "Útočník", "Gólman"],
/* HU */	["Védő , középső", "Védő , bal oldali", "Védő , jobb oldali", "Védekező Középpályás , középső", "Védekező Középpályás , bal oldali", "Védekező Középpályás , jobb oldali", "Középpályás , középső", "Középpályás , bal oldali", "Középpályás , jobb oldali", "Támadó középpályás , középső", "Támadó középpályás , bal oldali", "Támadó középpályás , jobb oldali", "Csatár", "Kapus"],
/* GE */	["მცველი ცენტრალური", "მცველი მარცხენა", "მცველი მარჯვენა", "საყრდენი ნახევარმცველი ცენტრალური", "საყრდენი ნახევარმცველი მარცხენა", "საყრდენი ნახევარმცველი მარჯვენა", "ნახევარმცველი ცენტრალური", "ნახევარმცველი მარცხენა", "ნახევარმცველი მარჯვენა", "შემტევი ნახევარმცველი ცენტრალური", "შემტევი ნახევარმცველი მარცხენა", "შემტევი ნახევარმცველი მარჯვენა", "თავდამსხმელი", "მეკარე"],
/* FI */	["Puolustaja Keski", "Puolustaja Vasen", "Puolustaja Oikea", "Puolustava Keskikenttä Keski", "Puolustava Keskikenttä Vasen", "Puolustava Keskikenttä Oikea", "Keskikenttä Keski", "Keskikenttä Vasen", "Keskikenttä Oikea", "Hyökkäävä Keskikenttä Keski", "Hyökkäävä Keskikenttä Vasen", "Hyökkäävä Keskikenttä Oikea", "Hyökkääjä", "Maalivahti"],
/* SV */	["Försvarare Central", "Försvarare Vänster", "Försvarare Höger", "Defensiv Mittfältare Central", "Defensiv Mittfältare Vänster", "Defensiv Mittfältare Höger", "Mittfältare Central", "Mittfältare Vänster", "Mittfältare Höger", "Offensiv Mittfältare Central", "Offensiv Mittfältare Vänster", "Offensiv Mittfältare Höger", "Anfallare", "Målvakt"],
/* NO */	["Forsvar Sentralt", "Forsvar Venstre", "Forsvar Høyre", "Defensiv Midtbane Sentralt", "Defensiv Midtbane Venstre", "Defensiv Midtbane Høyre", "Midtbane Sentralt", "Midtbane Venstre", "Midtbane Høyre", "Offensiv Midtbane Sentralt", "Offensiv Midtbane Venstre", "Offensiv Midtbane Høyre", "Angrep", "Keeper"],
/* SC */	["Defender Centre", "Defender Left", "Defender Richt", "Defensive Midfielder Centre", "Defensive Midfielder Left", "Defensive Midfielder Richt", "Midfielder Centre", "Midfielder Left", "Midfielder Richt", "Offensive Midfielder Centre", "Offensive Midfielder Left", "Offensive Midfielder Richt", "Forward", "Goalkeeper"],
/* VL */	["Verdediger Centraal", "Verdediger Links", "Verdediger Rechts", "Verdedigende Middenvelder Centraal", "Verdedigende Middenvelder Links", "Verdedigende Middenvelder Rechts", "Middenvelder Centraal", "Middenvelder Links", "Middenvelder Rechts", "Aanvallende Middenvelder Centraal", "Aanvallende Middenvelder Links", "Aanvallende Middenvelder Rechts", "Aanvaller", "Doelman"],
/* BR */	["Zagueiro Central", "Zagueiro Esquerdo", "Zagueiro Direito", "Volante Central", "Volante Esquerdo", "Volante Direito", "Meio-Campista Central", "Meio-Campista Esquerdo", "Meio-Campista Direito", "Meia Ofensivo Central", "Meia Ofensivo Esquerdo", "Meia Ofensivo Direito", "Atacante", "Goleiro"],
/* GR */	["Αμυντικός Κεντρικός", "Αμυντικός Αριστερός", "Αμυντικός Δεξιός", "Αμυντικός Μέσος Κεντρικός", "Αμυντικός Μέσος Αριστερός", "Αμυντικός Μέσος Δεξιός", "Μέσος Κεντρικός", "Μέσος Αριστερός", "Μέσος Δεξιός", "Επιθετικός μέσος Κεντρικός", "Επιθετικός μέσος Αριστερός", "Επιθετικός μέσος Δεξιός", "Επιθετικός", "Τερματοφύλακας"],
/* BG */	["Защитник Централен", "Защитник Ляв", "Защитник Десен", "Дефанзивен Халф Централен", "Дефанзивен Халф Ляв", "Дефанзивен Халф Десен", "Халф Централен", "Халф Ляв", "Халф Десен", "Атакуващ Халф Централен", "Атакуващ Халф Ляв", "Атакуващ Халф Десен", "Нападател"],
];

if (location.href.indexOf("/players/") != -1) {
	document.findPositionIndex = function(position) {
		var index = -1;
		for (var i=0; i< positionFullNames.length; i++) {
			for (var j=0; j< positionFullNames[i].length; j++) {
				if (position.indexOf(positionFullNames[i][j]) == 0) return j;
			}
		}
		return index;
	};

	function funFix1 (i) {
		i = (Math.round(i*10)/10).toFixed(1);
		return i;
	}

    function addCommas(nStr) {
		nStr += '';
		var x = nStr.split('.');
		var x1 = x[0];
		var x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
				x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}

	function CalcMaxPrice(age, si, retiring) {
    var Result = "-";
    if (!retiring)
    {
      var yearidx = age.search(/\d\d/);
      var year = age.substr(yearidx,2);
      age = age.slice(yearidx+2);
      var month = age.replace(/\D+/g,"");
      var factor = 192400/(Math.round(year) + Math.round(month)/12)-5200;
      if (factor < 400) factor = 400;
      if (year >= 18) Result = addCommas(Math.round(factor * si));
    }
    return Result;
	}

    function CalcBankPrice(TotalMonths, si, retiring, isGK) {
    var Result = "-";
    if (!retiring)
    {
        var year = Math.floor(TotalMonths / 12);
        var month = TotalMonths % 12;
		if (year >= 18)
        {
            var ageD = 25 / (year * 1 + (month / 12));
            Result = Math.round(si * 500 * Math.pow(ageD, 2.5));
            if (isGK) Result = Math.round(Result * 0.75);
            Result = addCommas(Result);
        }
    }
    return Result;
    }

    function CalcAgeMonths(age) {
      var yearidx = age.search(/\d\d/);
      var year = age.substr(yearidx, 2);
      age = age.slice(yearidx + 2);
      var month = age.replace(/\D+/g,"");
      return year * 12 + month * 1;
    }

    function get_information(link, callback) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", link, true);
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4) {
            callback(xhr.responseText);
        }
    };
    xhr.send(null);
    }

    var en = new Intl.NumberFormat("en-US");
    var gettr = document.getElementsByClassName("float_left info_table zebra")[0].getElementsByTagName("tr");
    var playerID = new String(location.pathname.match(/\d+/g));
    if (playerID.indexOf(",") != (-1)) {
        var pID = new String(playerID.search(/,/g));
        playerID = new String(playerID.substr(0,pID));
    }
	var AgeMonths = CalcAgeMonths(gettr[2].getElementsByTagName("td")[0].innerHTML);
    var RetireStatus = gettr[7].getElementsByTagName("td")[0].innerHTML.indexOf("retire.gif") > 0;
    var positionCell = document.getElementsByClassName("favposition long")[0].childNodes;
	var positionArray = [];
	if (positionCell.length == 1){
			positionArray[0] = positionCell[0].textContent;
	} else if (positionCell.length == 2){
			positionArray[0] = positionCell[0].textContent + positionCell[1].textContent;
	} else if (positionCell[1].className == "split"){
			positionArray[0] = positionCell[0].textContent + positionCell[3].textContent;
			positionArray[1] = positionCell[2].textContent + positionCell[3].textContent;
	} else if (positionCell[3].className == "f"){
			positionArray[0] = positionCell[0].textContent + positionCell[1].textContent;
			positionArray[1] = positionCell[3].textContent;
	} else {
			positionArray[0] = positionCell[0].textContent + positionCell[1].textContent;
			positionArray[1] = positionCell[0].textContent + positionCell[3].textContent;
	}
    for (var i = 0; i < positionArray.length; i++){
		var positionIndex = document.findPositionIndex(positionArray[i]);
    }
    if (gettr[8].getElementsByTagName("th")[0].innerHTML == global_content[254]) {
    //if (gettr[8].getElementsByTagName("th")[0].innerHTML == "Skill Index") {
        var SI = new String(gettr[8].getElementsByTagName("td")[0].innerHTML).replace(/,/g, "");
    } else {
        SI = new String(gettr[6].getElementsByTagName("td")[0].innerHTML);
        if (SI.indexOf("div") == (-1)) {
            SI = new String(gettr[6].getElementsByTagName("td")[0].innerHTML).replace(/,/g, "");
        } else {
            var divSI = new String(SI.search(/<div>/g));
            SI = new String(SI.substr(0,divSI).replace(/,/g, ""));
        }
    }
    //var wage = new String(gettr[4].getElementsByTagName("td")[0].innerText).replace(/,/g, "");
    var wage = new String(gettr[4].getElementsByTagName("span")[0].innerHTML).replace(/,/g, "");
    var today = new Date();
	var day = (today.getTime()-training1.getTime())/1000/3600/24;
	while (day > 84-16/24) day -= 84;
	var session = Math.floor(day/7)+1;									// training sessions
	var ageMax = 20.1 + session / 12;									// max new player age

	var age = gettr[2].getElementsByTagName("td")[0].innerHTML;
	var yearidx = age.search(/\d\d/);
	var year = age.substr(yearidx,2);
    var months = age.replace(/\D+/g,"");
	age = age.slice(yearidx+2);
	var month = age.replace(/\D+/g,"");
	age = year*1 + month/12;

	var check = today.getTime()-SS.getTime();
	var season = 84*24*3600*1000;
	var count = 0;

	while (check > season) {
		check -= season;
		count++;
	}

	if (document.getElementsByClassName("gk")[0] == null) var weight = 263533760000;
    else weight = 48717927500;
    if (wage == 30000 || (playerID > youthID && count == 0)) {	// youth player ID
		var TI1 = null;
	} else {
		TI1 = Math.pow(2,Math.log(weight*SI)/Math.log(Math.pow(2,7))) - Math.pow(2,Math.log(weight*wage/(wage_rate))/Math.log(Math.pow(2,7)));
		TI1 = Math.round(TI1*10);
		if (session == 0) TI1 = TI1;
		else TI1 = funFix1(TI1/session);
	}
    if (playerID > botID && age < ageMax) {		// BOT player ID
		if (wage == 30000) var TI2 = null;
		else {
			wage_rate = 23.75;
			TI2 = Math.pow(2,Math.log(weight*SI)/Math.log(Math.pow(2,7))) - Math.pow(2,Math.log(weight*wage/(wage_rate))/Math.log(Math.pow(2,7)));
			TI2 = Math.round(TI2*10);
            }
		}
    if (TI1 == null && TI2 == null) {
        var AverageTI = 0;
        var sess = parseInt(month)+1;
        var prvTI = 0;
    } else {
        if (TI2 == null) {
        AverageTI = TI1;
        prvTI = 1;
        sess = parseInt(month)+1;
            if (sess > session) sess = session;
        } else {
        AverageTI = TI2/(parseInt(month)-1);
        sess = parseInt(month)-1;
        prvTI = 0;
        }
    }

    var playerTable = document.getElementsByClassName("skill_table zebra")[0];
    var newTr = document.createElement("tr");
	var th = document.createElement("th");
	th.setAttribute("colspan", "4");
	th.setAttribute("align", "center");

    var table4 = document.createElement("table");
	var tbody = document.createElement("tbody");
	table4.setAttribute("border", "1");
	table4.setAttribute("bordercolor", "#6C9922");
    tbody.setAttribute("align", "center");
	var tr = document.createElement("tr");
    tr.style="background-color:#333333;";
    var td = document.createElement("td");
    var myTeam = SESSION["main_id"];
    var myBteam = SESSION["b_team"];
    var teamid = gettr[1].getElementsByTagName("td")[0].innerHTML.match(/\d+/);
    if (prvTI == 1 && session > 0 && (1+parseInt(month))<session) { var csp1 = 1; } else { csp1 = 2; }
    if (teamid != myTeam && teamid != myBteam) { var csp2 = 0; } else { csp2 = 1; }
    var csp = 1*csp1+1*csp2;
    td.setAttribute('colspan', ''+csp+'');
	var newdiv=document.createElement("div");
	var p=document.createElement("d");
	p.style="font-weight:bold;color:#CF0;";
	p.innerText="Trader's calculator"
	newdiv.appendChild(p);
	td.appendChild(newdiv);
	tr.appendChild(td);

    var td = document.createElement("td");
	var newdiv=document.createElement("div");
	var GoBtn=document.createElement("button");
	var t = document.createTextNode("Go");
	GoBtn.appendChild(t);
	GoBtn.style="width:80%;";
	GoBtn.className="button";
	GoBtn.onclick=DoCalcNewASI;
	newdiv.appendChild(GoBtn);
	td.appendChild(newdiv);
	tr.appendChild(td);

    var td = document.createElement("td");
	var newdiv=document.createElement("div");
    newdiv.innerHTML= "Weeks<br>";
	var NumTrainings=document.createElement("input");
	NumTrainings.name="NumTrainings";
	NumTrainings.className="embossed";
    NumTrainings.style="text-align:center;margin-bottom:5px;";
	//NumTrainings.size=2;
    NumTrainings.size=1;
	NumTrainings.maxLength=4;
	NumTrainings.value=6;
	newdiv.appendChild(NumTrainings);
	td.appendChild(newdiv);
	tr.appendChild(td);

    var td = document.createElement("td");
	var newdiv=document.createElement("div");
    newdiv.innerHTML= "<d id='TG1'>TI </d><br>";
	var NewTI=document.createElement("input");
	NewTI.name="NewTI";
	NewTI.className="embossed";
    NewTI.style="text-align:center;margin-bottom:5px;display:inline-block;";
	//NewTI.size=5;
    NewTI.size=1;
	NewTI.maxLength=4;
	NewTI.value=funFix1(AverageTI);
	newdiv.appendChild(NewTI);
    var sessDiv=document.createElement("div");
    sessDiv.style="text-transform:lowercase;font-weight:normal;margin-left:4px;margin-top: 2px;display:inline-block;";
    //var sess=1+parseInt(month);
    sessDiv.innerHTML=" x"+sess;
    newdiv.appendChild(sessDiv);
	td.appendChild(newdiv);
	tr.appendChild(td);


    if (teamid != myTeam && teamid != myBteam) {
        var td = document.createElement("td");
	    var newdiv = document.createElement("div");
        var p=document.createElement("d");
        p.id="TG2";
	    newdiv.appendChild(p);
	    td.appendChild(newdiv);
	    tr.appendChild(td);
    }

    if (prvTI == 1 && AverageTI != null && session > 0 && (1+parseInt(month))<session) {
        var td = document.createElement("td");
	    var newdiv=document.createElement("div");
        newdiv.id="PrevAge";
        td.appendChild(newdiv);
	    tr.appendChild(td);
    }

    tbody.appendChild(tr);

    var tr = document.createElement("tr");
    tr.innerHTML = "<th>Season</th><th>Age</th><th>ASI</th><th>Bank Price</th><th>Wage/Gain</th><th>Max Price</th>";
    tbody.appendChild(tr);

    var tr = document.createElement("tr");

    var td = document.createElement("td");
    var newdiv=document.createElement("div");
    var p=document.createElement("d");
    p.id="Season";
    p.innerHTML=Season+","+session
	newdiv.appendChild(p);
	td.appendChild(newdiv);
	tr.appendChild(td);

    var td = document.createElement("td");
    var newdiv=document.createElement("div");
    var p=document.createElement("d");
    p.id="CurrAge";
    p.innerHTML=year+","+months.substr(2);
	newdiv.appendChild(p);
	td.appendChild(newdiv);
	tr.appendChild(td);

    var td = document.createElement("td");
	var newdiv=document.createElement("div");
	var p=document.createElement("d");
	p.id="CurrSI";
	p.innerHTML=addCommas(SI);
	newdiv.appendChild(p);
	td.appendChild(newdiv);
	tr.appendChild(td);

    var td = document.createElement("td");
	var newdiv=document.createElement("div");
	var p=document.createElement("d");
	p.id="CurrBankPrice";
	p.innerHTML=CalcBankPrice(AgeMonths, SI, RetireStatus, positionIndex == 13);
	newdiv.appendChild(p);
	td.appendChild(newdiv);
	tr.appendChild(td);

    var td = document.createElement("td");
	var newdiv=document.createElement("div");
	var p=document.createElement("d");
    var wage = new String(gettr[4].getElementsByTagName("span")[0].innerHTML).replace(/,/g, "");
    var totWage = wage*NumTrainings.value;
	p.id="totWage";
	p.innerHTML=addCommas(totWage);
	newdiv.appendChild(p);
	td.appendChild(newdiv);
	tr.appendChild(td);

	var td = document.createElement("td");
	var newdiv=document.createElement("div");
	var p=document.createElement("d");
	p.id="CurrMaxPrice";
	p.innerHTML=CalcMaxPrice(gettr[2].getElementsByTagName("td")[0].innerHTML, SI, RetireStatus);
	newdiv.appendChild(p);
	td.appendChild(newdiv);
	tr.appendChild(td);
    tbody.appendChild(tr);

    var tr = document.createElement("tr");
    tr.id = "HiddenTR";
    tr.style.display="none";
    var td = document.createElement("td");
    var newdiv=document.createElement("div");
	var p=document.createElement("d");
    p.id="Season2";
	newdiv.appendChild(p);
	td.appendChild(newdiv);
	tr.appendChild(td);

    var td = document.createElement("td");
    var newdiv=document.createElement("div");
	var p=document.createElement("d");
    p.id="Age2";
	newdiv.appendChild(p);
	td.appendChild(newdiv);
	tr.appendChild(td);

    var td = document.createElement("td");
	var newdiv=document.createElement("div");
	var p=document.createElement("d");
	p.id="FinalSI";

    var pIdx=document.createElement("input");
	pIdx.name="PosIdx";
	pIdx.type="hidden";
	pIdx.value=positionIndex;
	newdiv.appendChild(p);
	newdiv.appendChild(pIdx);
	td.appendChild(newdiv);
	tr.appendChild(td);

	var td = document.createElement("td");
	var newdiv=document.createElement("div");
	var p=document.createElement("d");
	p.id="FinalBankPrice";

	var pIdx=document.createElement("input");
	pIdx.name="AgeNow";
	pIdx.type="hidden";
    if (RetireStatus == true) { pIdx.value="-";
    } else { pIdx.value=AgeMonths; }
	newdiv.appendChild(p);
	newdiv.appendChild(pIdx);
	td.appendChild(newdiv);
    tr.appendChild(td);

    var td = document.createElement("td");
	var newdiv=document.createElement("div");
	var p=document.createElement("d");
	p.id="bankGain";
    newdiv.appendChild(p);
	td.appendChild(newdiv);
    tr.appendChild(td);

    var td = document.createElement("td");
	var newdiv=document.createElement("div");
	var p=document.createElement("d");
	p.id="FinalMaxPrice";
    newdiv.appendChild(p);
	td.appendChild(newdiv);
    tr.appendChild(td);
    tbody.appendChild(tr);

    table4.appendChild(tbody);
    th.appendChild(table4);
    newTr.appendChild(th);
    playerTable.appendChild(newTr);

    if (teamid == myBteam) teamid = myTeam;
    var url = "https://trophymanager.com/stadium/"+teamid;
    get_information(url, function(text) {
    var AllLevels = String(text.match(/"level":\d+/gm));
    AllLevels = String(AllLevels.match(/\d+/gm));
    var levels = AllLevels.split(/,/gm);
    var TGlev = levels[11];
    var TG=document.getElementById("TG1");
    TG.innerHTML+= "(TG "+TGlev+")";
    });

    if (teamid != myTeam && teamid != myBteam) {
        var my_url = "https://trophymanager.com/stadium/"
        get_information(my_url, function(text) {
        var AllLevels = String(text.match(/"level":\d+/gm));
        AllLevels = String(AllLevels.match(/\d+/gm));
        var levels = AllLevels.split(/,/gm);
        var TGlev = levels[11];
        var TG = document.getElementById("TG1");
        var TG2 = document.getElementById("TG2");
        var tg1 = TG.textContent.match(/\d+/gm);
        var Ti = document.getElementsByName("NewTI")[0];
        var eqTI = funFix1(Ti.value/(tg1*5+50)*(TGlev*5+50));
        TG2.innerHTML += "<nobr><span style='text-transform:none;'>on my TG</span></nobr><br><input id='myTgTI' class='embossed' style='text-align:center;margin-bottom:5px;background-color:#3d5623;' size='1' value='"+eqTI+"' disabled>";
        });
    }
}
function DoCalcNewASI() {
var hiddTR = document.getElementById("HiddenTR");
hiddTR.style.display = ("table-row");
var Ti=document.getElementsByName("NewTI")[0];
var NumTr=document.getElementsByName("NumTrainings")[0];
var SI=document.getElementById("CurrSI").innerHTML.replace(/,/g, "");
var NewSeason=document.getElementById("Season2");
var NewAge=document.getElementById("Age2");
var FinTi=document.getElementById("FinalSI");
var FinalBP=document.getElementById("FinalBankPrice");
var FinalMP=document.getElementById("FinalMaxPrice");
var posIdx=document.getElementsByName("PosIdx")[0];
var AgeNow=document.getElementsByName("AgeNow")[0];
var bnkGain=document.getElementById("bankGain");
var tWage=document.getElementById("totWage");
var pAgeTI=document.getElementById("PrevAge");
var wage = new String(gettr[4].getElementsByTagName("span")[0].innerHTML).replace(/,/g, "");
if (posIdx.value != 13) {
   var AllSkills = Math.pow(SI * Math.pow(2, 9) * Math.pow(5, 4) * Math.pow(7, 7), 1/7);
   } else {
   var AllSkills = Math.pow(SI * Math.pow(2, 9) * Math.pow(5, 4) * Math.pow(7, 7), 1/7)/14*11;
   }
   AllSkills = AllSkills + (NumTr.value * Ti.value / 10);
AllSkils = funFix1(AllSkills);
if (posIdx.value != 13) {
   FinSi = Math.pow(AllSkills, 7)/(Math.pow(2, 9) * Math.pow(5, 4) * Math.pow(7, 7));
   } else {
   FinSi = Math.pow(AllSkills / 11 * 14, 7) /(Math.pow(2, 9) * Math.pow(5, 4) * Math.pow(7, 7));
   }
var Age2 = (AgeNow.value*1 + NumTr.value*1);
var year2 = String(Age2/12).substr(0, 2);
var months2 = Math.round(Age2%12);
var Ss2 = Season*12+session*1+NumTr.value*1;
var Season2 = parseInt(Ss2/12);
var Week2 = Math.round(Ss2%12);
var twg=wage*NumTr.value;
tWage.innerHTML = addCommas(twg);
NewAge.innerHTML = year2+","+months2;
NewSeason.innerHTML = Season2+","+Week2;
FinTi.innerHTML = addCommas(Math.round(FinSi));
var FBP=CalcBankPrice(AgeNow.value*1 + NumTr.value*1, FinSi, false, posIdx.value == 13);
FinalBP.innerHTML = FBP;
var totGain = (FBP.replace(/,/g, "")-twg-6*FBP.replace(/,/g, "")/100).toFixed(0);
bnkGain.innerHTML = addCommas(totGain);
FinalMP.innerHTML = CalcMaxPrice(year2+","+months2, FinSi, false);
if (prvTI == 1 && AverageTI != null && session > 0 && (1+parseInt(month))<session) {
   var pTI = funFix1((Math.floor(AverageTI*session)-Ti.value*(1+parseInt(month)))/(session-(1+parseInt(month))));
   var pAge = year-1;
   var cSess = 1+parseInt(month);
   var pSess = session-cSess;
   pAgeTI.innerHTML = pAge+"<span style='text-transform:lowercase;'> years</span> TI<br><input class='embossed' style='text-align:center;margin-bottom:5px;background-color:#3d5623;display:inline-block;' size='1' value='"+pTI+"' disabled><span style='text-transform:lowercase;font-weight:normal;'> x"+pSess+"</span>";
}
if (teamid != myTeam && teamid != myBteam) {
        var my_url = "https://trophymanager.com/stadium/"
        get_information(my_url, function(text) {
        var AllLevels = String(text.match(/"level":\d+/gm));
        AllLevels = String(AllLevels.match(/\d+/gm));
        var levels = AllLevels.split(/,/gm);
        var TGlev = levels[11];
        var TG = document.getElementById("TG1");
        var TG2 = document.getElementById("TG2");
        var tg1 = TG.textContent.match(/\d+/gm);
        var Ti = document.getElementsByName("NewTI")[0];
        var eqTInew = funFix1(Ti.value/(tg1*5+50)*(TGlev*5+50));
        var myTgTI=document.getElementById("myTgTI");
        myTgTI.value = eqTInew;
        });
    }
}
;}, 100);
///////////////////////////////////////////////////////////////////////////
// SCRIPT OPTIONS: answer "yes" or "no"
var showStars = "yes"; // show gold and silver stars instead of 19 and 20
var addREC = "yes"; // add REC potential to the report
var addSkills = "yes"; // add scout's skills to the report
var countAvailable = "yes"; // count available scouts
var countReports = "yes"; // count total reports
var countInterested = "yes"; // count interested clubs
var hideUnavailable = "yes"; // hide unavailable scouts
///////////////////////////////////////////////////////////////////////////

document.getElementById("player_scout_new").addEventListener("click", function () { ScoutSkills(); HideScouts(); });
function ScoutSkills() {
    var sheet = window.document.styleSheets[0];
    sheet.insertRule('#player_scout_new tr:hover{background:#333333;}', sheet.cssRules.length);
    var elencoScout = document.getElementById("player_scout_new").getElementsByTagName("table")[0].rows;
    var scoutSkills = document.getElementById("player_scout_new").getElementsByTagName("td");
    if (showStars == "yes") {
        for (var z = 1; z<scoutSkills.length; z++) {
            if (scoutSkills[z].innerHTML == 20) scoutSkills[z].innerHTML = "<img src='/pics/star.png' alt='20' title='20' style='vertical-align: baseline; margin-bottom:-2px;'>";
            if (scoutSkills[z].innerHTML == 19) scoutSkills[z].innerHTML = "<img src='/pics/star_silver.png' alt='19' title='19' style='vertical-align: baseline; margin-bottom:-1px;'>";
        }
    }
    var Scoutata = document.getElementById("player_scout_new").getElementsByTagName("strong");
    for (var j = 0; j<Scoutata.length; j++) {
         if (addREC == "yes") {
             var Reports = Scoutata[j].parentNode.parentNode;
             var StOro = Reports.getElementsByClassName("megastar recomendation");
             var MezStOro = Reports.getElementsByClassName("megastar recomendation_half");
             var StOroVerde = Reports.getElementsByClassName("megastar recomendation_potential");
             var StVerde = Reports.getElementsByClassName("megastar potential");
             var MezStVerde = Reports.getElementsByClassName("megastar potential_half");
             var Stelle = 1*StOro.length+1*StOroVerde.length+1*StVerde.length+0.5*MezStVerde.length+0.5*MezStOro.length;
             var PotNum = Reports.childNodes[3].innerHTML.match(/\d+/);
             Reports.childNodes[3].innerHTML = Reports.childNodes[3].innerHTML.replace(/\(\d+\)/, "("+PotNum+"/"+Stelle+"*)");
         }
         if (addSkills == "yes") {
             var nome = Scoutata[j].textContent;
             var sk1 = elencoScout[0].cells[1].textContent;
             var sk2 = elencoScout[0].cells[2].textContent;
             var sk3 = elencoScout[0].cells[3].textContent;
             var sk4 = elencoScout[0].cells[4].textContent;
             var sk5 = elencoScout[0].cells[5].textContent;
             var sk6 = elencoScout[0].cells[6].textContent;
             var sk7 = elencoScout[0].cells[7].textContent;
             for (var i = 1; i<elencoScout.length; i++) {
                 var scout = elencoScout[i].cells[0].textContent;
                 if (scout == nome) {
                     var Sen = elencoScout[i].cells[1].innerHTML;
                     var Yth = elencoScout[i].cells[2].innerHTML;
                     var Phy = elencoScout[i].cells[3].innerHTML;
                     var Tac = elencoScout[i].cells[4].innerHTML;
                     var Tec = elencoScout[i].cells[5].innerHTML;
                     var Dev = elencoScout[i].cells[6].innerHTML;
                     var Psy = elencoScout[i].cells[7].innerHTML;
                     var skill = "<span class='subtle'>"+sk1+":</span>"+Sen+"<span class='subtle'> "+sk2+":</span>"+Yth+"<span class='subtle'> "+sk3+":</span>"+Phy+"<span class='subtle'> "+sk4+":</span>"+Tac+"<span class='subtle'> "+sk5+":</span>"+Tec+"<span class='subtle'> "+sk6+":</span>"+Dev+"<span class='subtle'> "+sk7+":</span>"+Psy;
                     var $div = $("<span style='font-weight:normal;text-transform:capitalize;'><br>"+skill+"</span>").appendTo(Scoutata[j]);
                 }
             }
         }
     }
     var indisponibili = document.getElementById("player_scout_new").getElementsByClassName("button disabled");
     var rimasti = (elencoScout.length) - (indisponibili.length) -1;
     var totScout = (elencoScout.length) -1;
     var slotTot = document.getElementById("player_scout_new").getElementsByTagName("table")[0].rows[0].cells[8];
     if (countAvailable == "yes") {
         slotTot.textContent = " Tot: "+rimasti+"/"+totScout;
     }
     var totScoutate = document.getElementById("tabplayer_scout_new").getElementsByTagName("div")[0];
     if (countReports == "yes") {
         if (totScoutate.textContent.indexOf(":") == (-1)) {
             totScoutate.textContent += ": "+Scoutata.length;
             } else {
                 var numScoutate = totScoutate.textContent.match(/\d+/);
                 if (numScoutate != Scoutata.length) {
                     totScoutate.textContent = totScoutate.textContent.replace(/\d+/, Scoutata.length);
                 }
             }
     }
     if (countInterested == "yes") {
         if (document.getElementById("player_scout_new").getElementsByClassName("zebra interested_clubs")[0] != null) {
             var totInteressati = document.getElementById("player_scout_new").getElementsByClassName("zebra interested_clubs")[0].rows.length;
             var Interessati = document.getElementById("player_scout_new").getElementsByTagName("h3")[0];
             if (Interessati.textContent.indexOf(":") == (-1)) {
                 Interessati.textContent += ": "+totInteressati;
             }
         }
     }
}
function HideScouts() {
    if (hideUnavailable == "yes") {
        var indisponibili = document.getElementById("player_scout_new").getElementsByClassName("button disabled");
        for (var y = 0; y<indisponibili.length; y++) {
            var pulisci = indisponibili[y].parentNode.parentNode;
            pulisci.style.display = "none";
        }
        var tabScout = document.getElementById("player_scout_new").getElementsByTagName("table")[0];
        $(tabScout).each(function() {
        $(this).find("tr").filter(":visible").removeClass("odd");
        $(this).find("tr").filter(":visible:odd").addClass("odd");
        });
    }
}