var donotreeval = false;
var race_troll = 'I';
var race_att_pi = 16; var race_ATT = 0;
var race_esq_pi = 16; var race_ESQ = 0;
var race_deg_pi = 16; var race_DEG = 0;
var race_vue_pi = 16; var race_VUE = 0;
var race_pv_pi  = 16; var race_PV  = 0;
var race_reg_pi = 30; var race_REG = 0;
var race_arm_pi = 30; var race_ARM = 0;
var race_dla_pi = 18;
document.anatrolliseur.LANCER_compet.value = 10;

function convertStringToInt(s) {
	i = parseInt(s);
	if (isNaN(i)) {
		return 0;
	} else {
		return i;
	}
}

function getCheckedValue(r) {
	if(!r)
		return "";
	var radioLength = r.length;
	if(radioLength == undefined)
		if(r.checked)
			return r.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(r[i].checked) {
			return r[i].value;
		}
	}
	return "";
}

function init_pi() {
	race_ATT_pi = 16;
	race_ESQ_pi = 16;
	race_DEG_pi = 16;
	race_VUE_pi = 16;
	race_PV_pi  = 16;
	race_REG_pi = 30;
	race_ARM_pi = 30;
	race_DLA_pi = 18;

	if (race_troll == 'A') {
		race_REG_pi = 22;
	} else if (race_troll == 'D') {
		race_PV_pi = 12;
	} else if (race_troll == 'K') {
		race_DEG_pi = 12;
	} else if (race_troll == 'N') {
		race_ATT_pi = 15;
		race_ESQ_pi = 15;
		race_DEG_pi = 15;
		race_VUE_pi = 15;
		race_PV_pi  = 15;
		race_REG_pi = 29;
		race_ARM_pi = 29;
		race_DLA_pi = 17;
	} else if (race_troll == 'S') {
		race_ATT_pi = 12;
	} else if (race_troll == 'T') {
		race_VUE_pi = 12;
	}
}

function init_race(troll) {
	race_troll = troll;

	for (var i = 0; i < document.getElementsByName("durakuir").length; i++) {
		document.getElementsByName("durakuir")[i].style.display = 'none';
		document.getElementsByName("durakuir")[i].style.visiblity = 'hidden';
	}
	for (var i = 0; i < document.getElementsByName("kastar").length; i++) {
		document.getElementsByName("kastar")[i].style.display = 'none';
		document.getElementsByName("kastar")[i].style.visiblity = 'hidden';
	}
	for (var i = 0; i < document.getElementsByName("skrim").length; i++) {
		document.getElementsByName("skrim")[i].style.display = 'none';
		document.getElementsByName("skrim")[i].style.visiblity = 'hidden';
	}
	for (var i = 0; i < document.getElementsByName("tomawak").length; i++) {
		document.getElementsByName("tomawak")[i].style.display = 'none';
		document.getElementsByName("tomawak")[i].style.visiblity = 'hidden';
	}
	for (var i = 0; i < document.getElementsByName("darkling").length; i++) {
		document.getElementsByName("darkling")[i].style.display = 'none';
		document.getElementsByName("darkling")[i].style.visiblity = 'hidden';
	}

	if (race_troll == 'A') {
		for (var i = 0; i < document.getElementsByName("darkling").length; i++) {
			document.getElementsByName("darkling")[i].style.display = '';
			document.getElementsByName("darkling")[i].style.visiblity = 'visible';
		}
	} 
	if (race_troll == 'D') {
		for (var i = 0; i < document.getElementsByName("durakuir").length; i++) {
			document.getElementsByName("durakuir")[i].style.display = '';
			document.getElementsByName("durakuir")[i].style.visiblity = 'visible';
		}
	}
	if (race_troll == 'K') {
		for (var i = 0; i < document.getElementsByName("kastar").length; i++) {
			document.getElementsByName("kastar")[i].style.display = '';
			document.getElementsByName("kastar")[i].style.visiblity = 'visible';
		}
	}
	if (race_troll == 'S') {
		for (var i = 0; i < document.getElementsByName("skrim").length; i++) {
			document.getElementsByName("skrim")[i].style.display = '';
			document.getElementsByName("skrim")[i].style.visiblity = 'visible';
		}
	}
	if (race_troll == 'T') {
		for (var i = 0; i < document.getElementsByName("tomawak").length; i++) {
			document.getElementsByName("tomawak")[i].style.display = '';
			document.getElementsByName("tomawak")[i].style.visiblity = 'visible';
		}
	}

	init_pi();

	document.anatrolliseur.ATT.value = 3;
	document.anatrolliseur.ATT_nb.value = 0;
	document.anatrolliseur.ATT_pi.value = 0;
	document.anatrolliseur.ATT_next.value = race_ATT_pi;

	document.anatrolliseur.ESQ.value = 3;
	document.anatrolliseur.ESQ_nb.value = 0;
	document.anatrolliseur.ESQ_pi.value = 0;
	document.anatrolliseur.ESQ_next.value = race_ESQ_pi;

	document.anatrolliseur.DEG.value = 3;
	document.anatrolliseur.DEG_nb.value = 0;
	document.anatrolliseur.DEG_pi.value = 0;
	document.anatrolliseur.DEG_next.value = race_DEG_pi;

	document.anatrolliseur.VUE.value = 3;
	document.anatrolliseur.VUE_nb.value = 0;
	document.anatrolliseur.VUE_pi.value = 0;
	document.anatrolliseur.VUE_next.value = race_VUE_pi;

	document.anatrolliseur.PV.value = 30;
	document.anatrolliseur.PV_bm.value = 0;
	document.anatrolliseur.PV_nb.value = 0;
	document.anatrolliseur.PV_pi.value = 0;
	document.anatrolliseur.PV_next.value = race_PV_pi;

	document.anatrolliseur.REG.value = 1;
	document.anatrolliseur.REG_nb.value = 0;
	document.anatrolliseur.REG_pi.value = 0;
	document.anatrolliseur.REG_next.value = race_REG_pi;

	document.anatrolliseur.ARM.value = 1;
	document.anatrolliseur.ARM_nb.value = 0;
	document.anatrolliseur.ARM_pi.value = 0;
	document.anatrolliseur.ARM_next.value = race_ARM_pi;

	document.anatrolliseur.DLAH.value = 12;
	document.anatrolliseur.DLAM.value = 0;
	document.anatrolliseur.DLA_nb.value = 0;
	document.anatrolliseur.DLA_pi.value = 0;
	document.anatrolliseur.DLA_next.value = race_DLA_pi;

	if (troll == 'A') {
		document.anatrolliseur.REG.value = 2;
	} else if (troll == 'S') {
		document.anatrolliseur.ATT.value = 4;
	} else if (troll == 'D') {
		document.anatrolliseur.PV.value = 40;
	} else if (troll == 'K') {
		document.anatrolliseur.DEG.value = 4;
	} else if (troll == 'T') {
		document.anatrolliseur.VUE.value = 4;
	}

	reeval();
	reevalpi();
}

function f(n) {
	if (n <= 0) {
		return 0;
	} else return f(n-1)+n;
}

function recarac(type) {
	eval('new_value = document.anatrolliseur.'+type+'.value');
	eval('document.anatrolliseur.'+type+'.value = race_'+type);
	eval('next_value = race_'+type);
	while (next_value < new_value) {
		carac(type,+1);
		eval('next_value = race_'+type);
	}
	while (next_value > new_value) {
		carac(type,-1);
		eval('next_value = race_'+type);
	}
}
function carac(type,val) {
	init_pi();

	if (type == 'PV') {
		eval('document.anatrolliseur.'+type+'.value = eval(document.anatrolliseur.'+type+'.value) + val*10');
	} else if (type == 'DLA') {
		dla_nb = eval(document.anatrolliseur.DLA_nb.value) + val;
		tps = 12 * 60;
		for (var i = 1; i <= dla_nb; i++) {
		  if (i <= 10)
				tps = tps - (30 - ((i - 1) * 3));
			else
				tps = tps - 2.5;
		}
		document.anatrolliseur.DLAM.value = tps - (Math.floor(tps / 60) * 60);
		document.anatrolliseur.DLAH.value = Math.floor(tps / 60);
	} else {
		eval('document.anatrolliseur.'+type+'.value = eval(document.anatrolliseur.'+type+'.value) + val');
	}
	eval('document.anatrolliseur.'+type+'_nb.value = eval(document.anatrolliseur.'+type+'_nb.value) + val');
	eval('document.anatrolliseur.'+type+'_pi.value = eval(race_'+type+'_pi) * f(eval(document.anatrolliseur.'+type+'_nb.value))');
	eval('document.anatrolliseur.'+type+'_next.value = eval(race_'+type+'_pi) * (eval(document.anatrolliseur.'+type+'_nb.value)+1)');

	reeval();
	reevalpi();
}

function distance(x) {
	return distance_f(x, 4, 5);
}

function distance_f(x, y, z) {
//alert(x+"/"+y+"/"+z);
	if (x <= y) return 1;
	else return distance_f(x, y+z, z+1)+1;
}

pascal3 = new Array(
	new Array(),
	new Array(0,1,1,1));
pascal6 = new Array(
	new Array(),
	new Array(0,1,1,1,1,1,1));

function freqx(p, n, x, d) {
	for (var i = p.length; i <= d; i++) {
		p[i] =  new Array();
		for (var j = 0; j <= i*n; j++) {
			if (j < i) p[i][j] = 0;
			else {
				p[i][j] = 0;
				for (var k = Math.max(1,j-n); k < j; k++) {
					if (p[i-1].length > k) {
						p[i][j] += p[i-1][k];
					}
				}
			}
		}
	}
	if (x >= p[d].length) return 0;
	return p[d][x];
}

function freq(f, x, d) {
	if (f == 3) {
		return freqx(pascal3, f, x, d);
	} else {
		return freqx(pascal6, f, x, d);
	}
}

moy = new Array(
	0,1,2,new Array(0),4,5,new Array(0));
function jetmoyen(d, f) {
	for (var i = moy[f].length; i <= d; i++) {
		moy[f][i] = 0;
		var sf = 0;
		for (var j = i; j <= i*f; j++) {
			var fq = freq(f, j, i);
			moy[f][i] += j * fq;
			sf += fq;
		}
		moy[f][i] = moy[f][i]/ sf;
	}
	return moy[f][d];
}
function variance(nb_des, nb_faces) {
	var jm = jetmoyen(nb_des, nb_faces);

	var s = 0;
	var sf = 0;
	for (var i = nb_des; i <= nb_des * nb_faces; i++) {
		var fq = freq(nb_faces, i, nb_des);
		s += (i - jm) * (i - jm) * fq;
		sf += fq;
	}
	return s / sf;
}

function ecarttype(nb_des, nb_faces) {
	return Math.sqrt(variance(nb_des, nb_faces));
}

function max3(niv, des_bonus) {
	if (des_bonus > niv*3) return niv*3;
	return des_bonus;
}

function Caracs(base, physique, magique) {
	this.base = base;
	this.physique = physique;
	this.magique  = magique;
	this.bm = this.physique+this.magique;
}
function reeval() {
//	if (donotreeval) return;

	race_PV  = eval(document.anatrolliseur.PV.value);
	race_VUE = eval(document.anatrolliseur.VUE.value);
	race_ATT = eval(document.anatrolliseur.ATT.value);
	race_DEG = eval(document.anatrolliseur.DEG.value);
	race_ESQ = eval(document.anatrolliseur.ESQ.value);
	race_ARM = eval(document.anatrolliseur.ARM.value);
	race_REG = eval(document.anatrolliseur.REG.value);

	PVs = new Caracs(
		eval(document.anatrolliseur.PV.value),
		0,
		eval(document.anatrolliseur.PV_bm.value)
	);

	VUE = new Caracs(
		eval(document.anatrolliseur.VUE.value),
		eval(document.anatrolliseur.VUE_bm_p.value),
		eval(document.anatrolliseur.VUE_bm_m.value)
	);

	ATT = new Caracs(
		eval(document.anatrolliseur.ATT.value),
		eval(document.anatrolliseur.ATT_bm_p.value),
		eval(document.anatrolliseur.ATT_bm_m.value)
	);

	DEG = new Caracs(
		eval(document.anatrolliseur.DEG.value),
		eval(document.anatrolliseur.DEG_bm_p.value),
		eval(document.anatrolliseur.DEG_bm_m.value)
	);

	ESQ = new Caracs(
		eval(document.anatrolliseur.ESQ.value),
		eval(document.anatrolliseur.ESQ_bm_p.value),
		eval(document.anatrolliseur.ESQ_bm_m.value)
	);

	REG = new Caracs(
		eval(document.anatrolliseur.REG.value),
		eval(document.anatrolliseur.REG_bm_p.value),
		eval(document.anatrolliseur.REG_bm_m.value)
	);

	ARM = new Caracs(
		eval(document.anatrolliseur.ARM.value),
		eval(document.anatrolliseur.ARM_bm_p.value),
		eval(document.anatrolliseur.ARM_bm_m.value)
	);

	tps = 12 * 60;
	for (i = 1; i <= eval(document.anatrolliseur.DLA_nb.value); i++) {
		if (i <= 10)
			tps = tps - (30 - ((i - 1) * 3));
		else
			tps = tps - 2.5;
	}
	if (i <= 10)
		tpsnext = tps - (30 - ((i - 1) * 3));
	else
		tpsnext = tps - 2.5;
	dladays = tpsnext * tpsnext
			/ (60 * 24 * (tps - tpsnext));

	document.anatrolliseur.DLA_estim.value = Math.round(dladays);
	dladayspi = dladays * eval(document.anatrolliseur.DLA_next.value);
	document.anatrolliseur.DLA_1.value = Math.round(dladayspi / 1);
	document.anatrolliseur.DLA_2.value = Math.round(dladayspi / 2);
	document.anatrolliseur.DLA_3.value = Math.round(dladayspi / 3);
	document.anatrolliseur.DLA_4.value = Math.round(dladayspi / 4);
	document.anatrolliseur.DLA_5.value = Math.round(dladayspi / 5);
	document.anatrolliseur.DLA_6.value = Math.round(dladayspi / 6);

	document.anatrolliseur.PV_sec.value = Math.round(250/(PVs.base+PVs.bm)*60);

	document.anatrolliseur.ATT_moy.value = Math.round(jetmoyen(ATT.base,6)*10)/10 + ATT.bm;
	document.anatrolliseur.ATT_ec.value = Math.round(ecarttype(ATT.base,6)*10)/10;

	document.anatrolliseur.ESQ_moy.value = Math.round(jetmoyen(ESQ.base,6)*10)/10 + ESQ.bm;
	document.anatrolliseur.ESQ_ec.value = Math.round(ecarttype(ESQ.base,6)*10)/10;

	document.anatrolliseur.DEG_moy.value = Math.round(jetmoyen(DEG.base,3)*10)/10 + DEG.bm;
	document.anatrolliseur.DEG_ec.value = Math.round(ecarttype(DEG.base,3)*10)/10;

	document.anatrolliseur.REG_moy.value = Math.round(jetmoyen(REG.base,3)*10)/10 + REG.bm;
	document.anatrolliseur.REG_ec.value = Math.round(ecarttype(REG.base,3)*10)/10;

	document.anatrolliseur.ARM_moy_p.value = Math.round(jetmoyen(ARM.base,3)*10)/10 + ARM.bm;
	document.anatrolliseur.ARM_ec_p.value = Math.round(ecarttype(ARM.base,3)*10)/10;

	COR = new Caracs(Math.floor(((PVs.base+PVs.bm)/10) + Math.round(jetmoyen(ARM.base,3)*10)/10 + ARM.physique), 0, 0);
	AGI = new Caracs(Math.floor(REG.base + ESQ.base), 0, 0);
	STA = new Caracs(Math.floor(REG.base + ESQ.base), 0, 0);

	document.anatrolliseur.COR.value = COR.base;
	document.anatrolliseur.AGI.value = AGI.base;

	current = new Caracs(Math.floor(2 * AGI.base / 3), ESQ.physique, ESQ.magique)
	document.anatrolliseur.STA_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.STA_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(ATT.base, ATT.physique, ATT.magique)
	document.anatrolliseur.BAL_att.value = current.base;
	document.anatrolliseur.BAL_att_bm.value = current.bm;
	document.anatrolliseur.BAL_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.BAL_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	adv_agi = eval(document.anatrolliseur.BAL_adv_REG.value)+eval(document.anatrolliseur.BAL_adv_ESQ.value)
	current = new Caracs(Math.floor(2 * adv_agi / 3), eval(document.anatrolliseur.BAL_adv_ESQ_bm.value), 0)
	document.anatrolliseur.BAL_adv_sta_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.BAL_adv_sta_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor((PVs.base+PVs.bm) / 20), 0, 0)
	document.anatrolliseur.RA.value = current.base;
	document.anatrolliseur.RA_moy.value = Math.round(jetmoyen(current.base,3)*10)/10;
	document.anatrolliseur.RA_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	current = new Caracs(Math.floor(ATT.base / 2), Math.floor(ATT.bm / 2), 0)
	document.anatrolliseur.BS_att.value = current.base;
	document.anatrolliseur.BS_att_bm.value = current.bm;
	document.anatrolliseur.BS_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.BS_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(ATT.base / 2), Math.floor(DEG.bm / 2), 0)
	document.anatrolliseur.BS_deg.value = current.base;
	document.anatrolliseur.BS_deg_bm.value = current.bm;
	document.anatrolliseur.BS_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.BS_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	document.anatrolliseur.CDM_dist.value = VUE.base + VUE.bm;

	document.anatrolliseur.PISTAGE_dist.value = 2 * (VUE.base + VUE.bm);

	current = new Caracs(Math.floor(ATT.base / 2), Math.floor(ATT.bm / 2), 0)
	document.anatrolliseur.CA_att.value = current.base;
	document.anatrolliseur.CA_att_bm.value = current.bm;
	document.anatrolliseur.CA_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.CA_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(DEG.base, DEG.physique, DEG.magique)
	document.anatrolliseur.CA_deg.value = current.base;
	document.anatrolliseur.CA_deg_bm.value = current.bm;
	document.anatrolliseur.CA_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.CA_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	current = new Caracs(Math.floor(ATT.base / 2), Math.floor(ATT.bm / 2), 0)
	document.anatrolliseur.PARER.value = current.base;
	document.anatrolliseur.PARER_bm.value = current.bm;
	document.anatrolliseur.PARER_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.PARER_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	document.anatrolliseur.LANCER_dist.value = Math.floor(2 + (VUE.base + VUE.bm) / 5);
	document.anatrolliseur.LANCER_toucher.value = Math.floor(eval(document.anatrolliseur.LANCER_compet.value)
		+ Math.min(10, (1 - eval(document.anatrolliseur.LANCER_dist.value)) * 10 + VUE.base + VUE.bm));

	current = new Caracs(ATT.base + max3(1,Math.floor(ATT.base / 2)), ATT.physique, ATT.magique);
	document.anatrolliseur.AP1_att.value = current.base;
	document.anatrolliseur.AP1_att_bm.value = current.bm;
	document.anatrolliseur.AP1_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.AP1_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(ATT.base + max3(2,Math.floor(ATT.base / 2)), ATT.physique, ATT.magique);
	document.anatrolliseur.AP2_att.value = current.base;
	document.anatrolliseur.AP2_att_bm.value = current.bm;
	document.anatrolliseur.AP2_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.AP2_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(ATT.base + max3(3,Math.floor(ATT.base / 2)), ATT.physique, ATT.magique);
	document.anatrolliseur.AP3_att.value = current.base;
	document.anatrolliseur.AP3_att_bm.value = current.bm;
	document.anatrolliseur.AP3_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.AP3_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(ATT.base + max3(4,Math.floor(ATT.base / 2)), ATT.physique, ATT.magique);
	document.anatrolliseur.AP4_att.value = current.base;
	document.anatrolliseur.AP4_att_bm.value = current.bm;
	document.anatrolliseur.AP4_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.AP4_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(ATT.base + max3(5,Math.floor(ATT.base / 2)), ATT.physique, ATT.magique);
	document.anatrolliseur.AP5_att.value = current.base;
	document.anatrolliseur.AP5_att_bm.value = current.bm;
	document.anatrolliseur.AP5_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.AP5_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(ATT.base + max3(6,Math.floor(ATT.base / 2)), ATT.physique, ATT.magique);
	document.anatrolliseur.AP6_att.value = current.base;
	document.anatrolliseur.AP6_att_bm.value = current.bm;
	document.anatrolliseur.AP6_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.AP6_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(ATT.base + max3(7,Math.floor(ATT.base / 2)), ATT.physique, ATT.magique);
	document.anatrolliseur.AP7_att.value = current.base;
	document.anatrolliseur.AP7_att_bm.value = current.bm;
	document.anatrolliseur.AP7_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.AP7_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	document.anatrolliseur.AP_deg.value = DEG.base;
	document.anatrolliseur.AP_deg_bm.value = DEG.bm;
	document.anatrolliseur.AP_deg_moy.value = Math.round(jetmoyen(DEG.base,3)*10)/10 + DEG.bm;
	document.anatrolliseur.AP_deg_ec.value = Math.round(ecarttype(DEG.base,3)*10)/10;

	current = new Caracs(Math.floor(3 * DEG.base / 2), DEG.physique, DEG.magique);
	document.anatrolliseur.AP_deg_crit.value = current.base;
	document.anatrolliseur.AP_deg_crit_bm.value = current.bm;
	document.anatrolliseur.AP_deg_crit_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.AP_deg_crit_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	document.anatrolliseur.CHARGE_att.value = ATT.base;
	document.anatrolliseur.CHARGE_att_bm.value = ATT.bm;
	document.anatrolliseur.CHARGE_att_moy.value = Math.round(jetmoyen(ATT.base,6)*10)/10 + current.bm;
	document.anatrolliseur.CHARGE_att_ec.value = Math.round(ecarttype(ATT.base,6)*10)/10;
	document.anatrolliseur.CHARGE_deg.value = DEG.base;
	document.anatrolliseur.CHARGE_deg_bm.value = DEG.bm;
	document.anatrolliseur.CHARGE_deg_moy.value = Math.round(jetmoyen(DEG.base,3)*10)/10 + DEG.bm;
	document.anatrolliseur.CHARGE_deg_ec.value = Math.round(ecarttype(DEG.base,3)*10)/10;
	document.anatrolliseur.CHARGE_dist.value = distance(REG.base + Math.floor((PVs.base+PVs.bm) / 10));

	current = new Caracs(Math.floor((VUE.base + ESQ.base)/2), 0, 0);
	document.anatrolliseur.PIEGE_deg.value = current.base;
	document.anatrolliseur.PIEGE_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10;
	document.anatrolliseur.PIEGE_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	document.anatrolliseur.CDB_att.value = ATT.base;
	document.anatrolliseur.CDB_att_bm.value = ATT.bm;
	document.anatrolliseur.CDB_att_moy.value = Math.round(jetmoyen(ATT.base,6)*10)/10 + ATT.bm;
	document.anatrolliseur.CDB_att_ec.value = Math.round(ecarttype(ATT.base,6)*10)/10;

	current = new Caracs(DEG.base + max3(1,Math.floor(DEG.base / 2)), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB1_deg.value = current.base;
	document.anatrolliseur.CDB1_deg_bm.value = current.bm;
	document.anatrolliseur.CDB1_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.CDB1_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(DEG.base / 2), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB1_deg_crit.value = currentcrit.base;
	document.anatrolliseur.CDB1_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.CDB1_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.CDB1_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(DEG.base + max3(2,Math.floor(DEG.base / 2)), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB2_deg.value = current.base;
	document.anatrolliseur.CDB2_deg_bm.value = current.bm;
	document.anatrolliseur.CDB2_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.CDB2_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(DEG.base / 2), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB2_deg_crit.value = currentcrit.base;
	document.anatrolliseur.CDB2_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.CDB2_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.CDB2_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(DEG.base + max3(3,Math.floor(DEG.base / 2)), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB3_deg.value = current.base;
	document.anatrolliseur.CDB3_deg_bm.value = current.bm;
	document.anatrolliseur.CDB3_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.CDB3_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(DEG.base / 2), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB3_deg_crit.value = currentcrit.base;
	document.anatrolliseur.CDB3_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.CDB3_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.CDB3_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(DEG.base + max3(4,Math.floor(DEG.base / 2)), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB4_deg.value = current.base;
	document.anatrolliseur.CDB4_deg_bm.value = current.bm;
	document.anatrolliseur.CDB4_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.CDB4_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(DEG.base / 2), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB4_deg_crit.value = currentcrit.base;
	document.anatrolliseur.CDB4_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.CDB4_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.CDB4_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(DEG.base + max3(5,Math.floor(DEG.base / 2)), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB5_deg.value = current.base;
	document.anatrolliseur.CDB5_deg_bm.value = current.bm;
	document.anatrolliseur.CDB5_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.CDB5_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(DEG.base / 2), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB5_deg_crit.value = currentcrit.base;
	document.anatrolliseur.CDB5_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.CDB5_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.CDB5_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(DEG.base + max3(6,Math.floor(DEG.base / 2)), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB6_deg.value = current.base;
	document.anatrolliseur.CDB6_deg_bm.value = current.bm;
	document.anatrolliseur.CDB6_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.CDB6_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(DEG.base / 2), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB6_deg_crit.value = currentcrit.base;
	document.anatrolliseur.CDB6_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.CDB6_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.CDB6_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(DEG.base + max3(7,Math.floor(DEG.base / 2)), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB7_deg.value = current.base;
	document.anatrolliseur.CDB7_deg_bm.value = current.bm;
	document.anatrolliseur.CDB7_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.CDB7_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(DEG.base / 2), DEG.physique, DEG.magique);
	document.anatrolliseur.CDB7_deg_crit.value = currentcrit.base;
	document.anatrolliseur.CDB7_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.CDB7_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.CDB7_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(ATT.base, ATT.physique, ATT.magique);
	document.anatrolliseur.RB1_att.value = current.base;
	document.anatrolliseur.RB1_att_bm.value = current.bm;
	document.anatrolliseur.RB1_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.RB1_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(DEG.base, DEG.physique, DEG.magique);
	document.anatrolliseur.RB1_deg.value = current.base;
	document.anatrolliseur.RB1_deg_bm.value = current.bm;
	document.anatrolliseur.RB1_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.RB1_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(current.base / 2), current.physique, current.magique);
	document.anatrolliseur.RB1_deg_crit.value = currentcrit.base;
	document.anatrolliseur.RB1_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.RB1_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.RB1_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(Math.floor(ATT.base*75/100), Math.floor(ATT.bm*75/100), 0);
	document.anatrolliseur.RB2_att.value = current.base;
	document.anatrolliseur.RB2_att_bm.value = current.bm;
	document.anatrolliseur.RB2_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.RB2_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(DEG.base*75/100), Math.floor(DEG.bm*75/100), 0);
	document.anatrolliseur.RB2_deg.value = current.base;
	document.anatrolliseur.RB2_deg_bm.value = current.base;
	document.anatrolliseur.RB2_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.RB2_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(current.base / 2), current.physique, current.magique);
	document.anatrolliseur.RB2_deg_crit.value = currentcrit.base;
	document.anatrolliseur.RB2_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.RB2_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.RB2_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(Math.floor(ATT.base*75/100*75/100), Math.floor(ATT.bm*75/100*75/100), 0);
	document.anatrolliseur.RB3_att.value = current.base;
	document.anatrolliseur.RB3_att_bm.value = current.bm;
	document.anatrolliseur.RB3_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.RB3_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(DEG.base*75/100*75/100), Math.floor(DEG.bm*75/100*75/100), 0);
	document.anatrolliseur.RB3_deg.value = current.base;
	document.anatrolliseur.RB3_deg_bm.value = current.bm;
	document.anatrolliseur.RB3_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.RB3_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(current.base / 2), current.physique, current.magique);
	document.anatrolliseur.RB3_deg_crit.value = currentcrit.base;
	document.anatrolliseur.RB3_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.RB3_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.RB3_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(Math.floor(ATT.base*75/100*75/100*75/100), Math.floor(ATT.bm*75/100*75/100*75/100), 0);
	document.anatrolliseur.RB4_att.value = current.base;
	document.anatrolliseur.RB4_att_bm.value = current.bm;
	document.anatrolliseur.RB4_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.RB4_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(DEG.base*75/100*75/100*75/100), Math.floor(DEG.bm*75/100*75/100*75/100), 0);
	document.anatrolliseur.RB4_deg.value = current.base;
	document.anatrolliseur.RB4_deg_bm.value = current.bm;
	document.anatrolliseur.RB4_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.RB4_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(current.base / 2), current.physique, current.magique);
	document.anatrolliseur.RB4_deg_crit.value = currentcrit.base;
	document.anatrolliseur.RB4_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.RB4_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.RB4_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(Math.floor(ATT.base*75/100*75/100*75/100*75/100), Math.floor(ATT.bm*75/100*75/100*75/100*75/100), 0);
	document.anatrolliseur.RB5_att.value = current.base;
	document.anatrolliseur.RB5_att_bm.value = current.bm;
	document.anatrolliseur.RB5_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.RB5_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(DEG.base*75/100*75/100*75/100*75/100), Math.floor(DEG.bm*75/100*75/100*75/100*75/100), 0);
	document.anatrolliseur.RB5_deg.value = current.base;
	document.anatrolliseur.RB5_deg_bm.value = current.bm;
	document.anatrolliseur.RB5_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.RB5_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(current.base / 2), current.physique, current.magique);
	document.anatrolliseur.RB5_deg_crit.value = currentcrit.base;
	document.anatrolliseur.RB5_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.RB5_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.RB5_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(Math.floor(ATT.base*75/100*75/100*75/100*75/100*75/100), Math.floor(ATT.bm*75/100*75/100*75/100*75/100*75/100), 0);
	document.anatrolliseur.RB6_att.value = current.base;
	document.anatrolliseur.RB6_att_bm.value = current.bm;
	document.anatrolliseur.RB6_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.RB6_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(DEG.base*75/100*75/100*75/100*75/100*75/100), Math.floor(DEG.bm*75/100*75/100*75/100*75/100*75/100), 0);
	document.anatrolliseur.RB6_deg.value = current.base;
	document.anatrolliseur.RB6_deg_bm.value = current.bm;
	document.anatrolliseur.RB6_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.RB6_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	currentcrit = new Caracs(current.base + Math.floor(current.base / 2), current.physique, current.magique);
	document.anatrolliseur.RB6_deg_crit.value = currentcrit.base;
	document.anatrolliseur.RB6_deg_crit_bm.value = currentcrit.bm;
	document.anatrolliseur.RB6_deg_crit_moy.value = Math.round(jetmoyen(currentcrit.base,3)*10)/10 + currentcrit.bm;
	document.anatrolliseur.RB6_deg_crit_ec.value = Math.round(ecarttype(currentcrit.base,3)*10)/10;

	current = new Caracs(ATT.base, ATT.physique, ATT.magique);
	document.anatrolliseur.FRENESIE_att.value = current.base;
	document.anatrolliseur.FRENESIE_att_bm.value = current.bm;
	document.anatrolliseur.FRENESIE_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.FRENESIE_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(DEG.base, DEG.physique, DEG.magique);
	document.anatrolliseur.FRENESIE_deg.value = current.base;
	document.anatrolliseur.FRENESIE_deg_bm.value = current.bm;
	document.anatrolliseur.FRENESIE_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.FRENESIE_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	//PreM et PuM
	att_bonus = 1;
	deg_bonus = 1;
	if (getCheckedValue(document.anatrolliseur.PreM) == 1) {
		att_bonus = att_bonus * (1+0.2);
		deg_bonus = deg_bonus * (1-0.2);
	} else if (getCheckedValue(document.anatrolliseur.PreM) == 2) {
		att_bonus = att_bonus * (1+0.2) * (1+0.2 * 0.66);
		deg_bonus = deg_bonus * (1-0.2) * (1-0.2 * 0.66);
	} else if (getCheckedValue(document.anatrolliseur.PreM) == 3) {
		att_bonus = att_bonus * (1+0.2) * (1+0.2 * 0.66) * (1+0.2 * 0.4);
		deg_bonus = deg_bonus * (1-0.2) * (1-0.2 * 0.66) * (1-0.2 * 0.4);
	} else if (getCheckedValue(document.anatrolliseur.PreM) == 4) {
		att_bonus = att_bonus * (1+0.2) * (1+0.2 * 0.66) * (1+0.2 * 0.4) * (1+0.2 * 0.25);
		deg_bonus = deg_bonus * (1-0.2) * (1-0.2 * 0.66) * (1-0.2 * 0.4) * (1-0.2 * 0.25);
	}
	if (getCheckedValue(document.anatrolliseur.PuiM) == 1) {
		deg_bonus = deg_bonus * (1+0.2);
		att_bonus = att_bonus * (1-0.2);
	} else if (getCheckedValue(document.anatrolliseur.PuiM) == 2) {
		deg_bonus = deg_bonus * (1+0.2) * (1+0.2 * 0.66);
		att_bonus = att_bonus * (1-0.2) * (1-0.2 * 0.66);
	} else if (getCheckedValue(document.anatrolliseur.PuiM) == 3) {
		deg_bonus = deg_bonus * (1+0.2) * (1+0.2 * 0.66) * (1+0.2 * 0.4);
		att_bonus = att_bonus * (1-0.2) * (1-0.2 * 0.66) * (1-0.2 * 0.4);
	} else if (getCheckedValue(document.anatrolliseur.PuiM) == 4) {
		deg_bonus = deg_bonus * (1+0.2) * (1+0.2 * 0.66) * (1+0.2 * 0.4) * (1+0.2 * 0.25);
		att_bonus = att_bonus * (1-0.2) * (1-0.2 * 0.66) * (1-0.2 * 0.4) * (1-0.2 * 0.25);
	}
	
	current = new Caracs(Math.floor(ATT.base * att_bonus), 0, ATT.magique);
	document.anatrolliseur.SDA_att.value = current.base;
	document.anatrolliseur.SDA_att_bm.value = current.bm
	document.anatrolliseur.SDA_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.SDA_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(REG.base * deg_bonus), 0, DEG.magique);
	document.anatrolliseur.SDA_deg.value = current.base;
	document.anatrolliseur.SDA_deg_bm.value = current.bm;
	document.anatrolliseur.SDA_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.SDA_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;
	document.anatrolliseur.SDA_necro.value = REG.base;

	document.anatrolliseur.HYPNO_full.value = Math.floor(3 * ESQ.base / 2);
	document.anatrolliseur.HYPNO_half.value = Math.floor(ESQ.base / 3);

	current = new Caracs(Math.floor(DEG.base * deg_bonus), 0, DEG.magique);
	document.anatrolliseur.RP_deg.value = current.base;
	document.anatrolliseur.RP_deg_bm.value = current.bm;
	document.anatrolliseur.RP_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.RP_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;
	document.anatrolliseur.RP_reg.value = DEG.base;

	current = new Caracs(Math.floor(2 * DEG.base / 3 * att_bonus), 0, ATT.magique);
	document.anatrolliseur.VAMPI_att.value = current.base;
	document.anatrolliseur.VAMPI_att_bm.value = current.bm;
	document.anatrolliseur.VAMPI_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.VAMPI_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(DEG.base * deg_bonus), 0, DEG.magique);
	document.anatrolliseur.VAMPI_deg.value = current.base;
	document.anatrolliseur.VAMPI_deg_bm.value = current.bm;
	document.anatrolliseur.VAMPI_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.VAMPI_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	PM_dist_max = distance(VUE.base + VUE.bm);
	document.anatrolliseur.PM_dist.value = PM_dist_max;
	if (eval(document.anatrolliseur.PM_proxi.value) == 99) {
		document.anatrolliseur.PM_proxi.value = 0;
	} else if (document.anatrolliseur.PM_proxi.value > document.anatrolliseur.PM_dist.value) {
		document.anatrolliseur.PM_proxi.value = PM_dist_max;
	} else if (document.anatrolliseur.PM_proxi.value < 0) {
		document.anatrolliseur.PM_proxi.value = 0
	}
	PM_proxi_bonus = document.anatrolliseur.PM_proxi.value;

	current = new Caracs(Math.floor(VUE.base * att_bonus), 0, ATT.magique);
	document.anatrolliseur.PM_att.value = current.base;
	document.anatrolliseur.PM_att_bm.value = current.bm;
	document.anatrolliseur.PM_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.PM_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(VUE.base / 2 * deg_bonus), 0, DEG.magique);
	document.anatrolliseur.PM_min_deg.value = current.base;
	document.anatrolliseur.PM_min_deg_bm.value = current.bm;
	document.anatrolliseur.PM_min_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.PM_min_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	current = new Caracs(Math.floor(VUE.base / 2 * deg_bonus + VUE.base / 2 / 2), 0, DEG.magique);
	document.anatrolliseur.PM_min_deg_crit.value = current.base;
	document.anatrolliseur.PM_min_deg_crit_bm.value = current.bm;
	document.anatrolliseur.PM_min_deg_crit_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.PM_min_deg_crit_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	current = new Caracs(Math.floor(VUE.base / 2 * deg_bonus + PM_dist_max - PM_proxi_bonus), 0, DEG.magique);
	document.anatrolliseur.PM_deg.value = current.base;
	document.anatrolliseur.PM_deg_bm.value = current.bm;
	document.anatrolliseur.PM_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.PM_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	current = new Caracs(Math.floor(VUE.base / 2 * deg_bonus + PM_dist_max - PM_proxi_bonus + VUE.base / 2 / 2), 0, DEG.magique);
	document.anatrolliseur.PM_deg_crit.value = current.base;
	document.anatrolliseur.PM_deg_crit_bm.value = current.bm;
	document.anatrolliseur.PM_deg_crit_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.PM_deg_crit_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	document.anatrolliseur.AA_dist.value = Math.floor((VUE.base + VUE.bm) / 2);

	document.anatrolliseur.AE.value = REG.base;

	document.anatrolliseur.AdA.value = 1 + Math.floor((ATT.base - 3) / 2);
	document.anatrolliseur.AdD.value = 1 + Math.floor((DEG.base - 3) / 2);
	document.anatrolliseur.AdE.value = 1 + Math.floor((ESQ.base - 3) / 2);

	document.anatrolliseur.FP.value = 1 + Math.floor((DEG.base - 3 + Math.floor((PVs.base + PVs.bm - 30) / 10)) / 2);

	document.anatrolliseur.FA.value = 1 + Math.floor(VUE.base / 5);

	document.anatrolliseur.GLUE.value = 1 + Math.floor(VUE.base / 3);

	current = new Caracs(Math.floor(ATT.base * att_bonus), 0, ATT.magique);
	document.anatrolliseur.GDS_att.value = current.base;
	document.anatrolliseur.GDS_att_bm.value = current.bm;
	document.anatrolliseur.GDS_att_moy.value = Math.round(jetmoyen(current.base,6)*10)/10 + current.bm;
	document.anatrolliseur.GDS_att_ec.value = Math.round(ecarttype(current.base,6)*10)/10;

	current = new Caracs(Math.floor(DEG.base / 2 * deg_bonus), 0, DEG.magique);
	document.anatrolliseur.GDS_deg.value = current.base;
	document.anatrolliseur.GDS_deg_bm.value = current.bm;
	document.anatrolliseur.GDS_deg_moy.value = Math.round(jetmoyen(current.base,3)*10)/10 + current.bm;
	document.anatrolliseur.GDS_deg_ec.value = Math.round(ecarttype(current.base,3)*10)/10;

	GDS_venin = 1 + Math.floor((PVs.base + PVs.bm) / 30) + Math.floor(REG.base / 3);
	document.anatrolliseur.GDS_virulence.value = GDS_venin;
	document.anatrolliseur.GDS_virulence_moy.value = Math.round(jetmoyen(GDS_venin,3)*10)/10;
	document.anatrolliseur.GDS_virulence_ec.value = Math.round(ecarttype(GDS_venin,3)*10)/10;
	document.anatrolliseur.GDS_duree.value = 1 + Math.floor(VUE.base / 5);

	EXPLO_deg = Math.floor(1 + Math.floor((DEG.base + Math.floor((PVs.base+PVs.bm) / 10)) / 2));
	document.anatrolliseur.EXPLO.value = EXPLO_deg;
	document.anatrolliseur.EXPLO_moy.value = Math.round(jetmoyen(EXPLO_deg,3)*10)/10;
	document.anatrolliseur.EXPLO_ec.value = Math.round(ecarttype(EXPLO_deg,3)*10)/10;

	document.anatrolliseur.TK.value = 1 + Math.floor((VUE.base + VUE.bm) / 2);

	dist_base = distance(eval(document.anatrolliseur.MM.value) / 5);
//	dist_base = Math.ceil((Math.sqrt(19 + 8 * eval(document.anatrolliseur.MM.value) / 5) + 3) / 2); // (racine (19+8*((MM/5)+3))-7)/2
	document.anatrolliseur.TP_h.value = Math.floor(dist_base + 20 + VUE.base);
	document.anatrolliseur.TP_v.value = Math.floor(dist_base / 3 + 3);

	document.anatrolliseur.VA.value = Math.floor(VUE.base / 2);

	// Si le sort est réussi le lanceur voit et peut cibler les Trolls et Monstres cachés situés à :
	//    * Vue entre 3 et 5 : 1 case
	//    * Vue entre 6 et 11 : 2 cases
	//    * Vue entre 12 et 21 : 3 cases
	//    * Vue entre 22 et 34 : 4 cases
	//    * Vue au delà de 34 : 5 cases 
	vlc_vue = eval(document.anatrolliseur.VUE.value);
//		+ convertStringToInt(document.anatrolliseur.VUE_bm_m.value)
//		+ convertStringToInt(document.anatrolliseur.VUE_bm_p.value);
	if (vlc_vue <= 5) vlc_dist = 1
	else if (vlc_vue <= 11) vlc_dist = 2
	else if (vlc_vue <= 21) vlc_dist = 3
	else if (vlc_vue <= 34) vlc_dist = 4
	else vlc_dist = 5;
	document.anatrolliseur.VLCsoi.value = vlc_dist;
	document.anatrolliseur.VLCcaseh.value = Math.floor((VUE.base + VUE.bm) / 2);
	document.anatrolliseur.VLCcasev.value = Math.floor(eval(document.anatrolliseur.VLCcaseh.value) / 2);

	document.anatrolliseur.VT.value = Math.floor(VUE.base / 3);
}

function reevalpi() {
	if (donotreeval) return;
	init_pi();

	var pi = 0;
	pi += eval(document.anatrolliseur.ATT_pi.value);
	pi += eval(document.anatrolliseur.ESQ_pi.value);
	pi += eval(document.anatrolliseur.DEG_pi.value);
	pi += eval(document.anatrolliseur.REG_pi.value);
	pi += eval(document.anatrolliseur.ARM_pi.value);
	pi += eval(document.anatrolliseur.VUE_pi.value);
	pi += eval(document.anatrolliseur.PV_pi.value);
	pi += eval(document.anatrolliseur.DLA_pi.value);

	for (var i = 0; i < document.anatrolliseur.comp.length; i++) {
		if (document.anatrolliseur.comp[i].checked) {
			pi += eval(document.anatrolliseur.comp[i].value);
		}
	}

	document.anatrolliseur.PI.value = pi;
	var pip = 0;
	i = 1;
	while (pip <= pi) {
		pip = (i + 2) * 5 * (i + 1) - 10;
		i++;
	}
	document.anatrolliseur.NIVEAU_pi.value = i-1;
	document.anatrolliseur.PI_max.value = 18290;
	document.anatrolliseur.PI_remain.value = eval(document.anatrolliseur.PI_max.value)-eval(document.anatrolliseur.PI_init.value)-eval(document.anatrolliseur.PI.value);
}

function niveau() {
	var pip = 0;
	var i = 1;
	while (pip <= eval(document.anatrolliseur.PI_encoded.value)) {
		pip = (i + 2) * 5 * (i + 1) - 10;
		i++;
	}
	document.anatrolliseur.NIVEAU.value = i-1;
}

var cookie_name = 'anatrolliseur_v7';
function get_anatrolliseur_cookie_value() {
	var value = 'anatrolliseur=v7|';
	value += race_troll + '|';
	value += document.anatrolliseur.DLAH.value + '|';
	value += document.anatrolliseur.DLAM.value + '|';
	value += document.anatrolliseur.PV.value + '|';
	value += document.anatrolliseur.VUE.value + '|';
	value += document.anatrolliseur.VUE_bm_p.value + '|';
	value += document.anatrolliseur.VUE_bm_m.value + '|';
	value += document.anatrolliseur.ATT.value + '|';
	value += document.anatrolliseur.ATT_bm_p.value + '|';
	value += document.anatrolliseur.ATT_bm_m.value + '|';
	value += document.anatrolliseur.ESQ.value + '|';
	value += document.anatrolliseur.ESQ_bm_p.value + '|';
	value += document.anatrolliseur.ESQ_bm_m.value + '|';
	value += document.anatrolliseur.DEG.value + '|';
	value += document.anatrolliseur.DEG_bm_p.value + '|';
	value += document.anatrolliseur.DEG_bm_m.value + '|';
	value += document.anatrolliseur.REG.value + '|';
	value += document.anatrolliseur.REG_bm_p.value + '|';
	value += document.anatrolliseur.REG_bm_m.value + '|';
	value += document.anatrolliseur.MM.value + '|';
	// comps
	for (var i = 0; i < document.anatrolliseur.comp.length; i++) {
		if (document.anatrolliseur.comp[i].checked) {
			value += '1|';
		} else {
			value += '0|';
		}
	}
	value += document.anatrolliseur.ARM_bm_p.value + '|';
	value += document.anatrolliseur.ARM_bm_m.value + '|';
	value += document.anatrolliseur.PV_bm.value + '|';
	value += document.anatrolliseur.ARM.value + '|';
	return value;
}

function set_anatrolliseur_cookie_value(value) {
	donotreeval = true;
	var fieldValues = value;
	var fieldArray  = fieldValues.split('|');

	var i = 0;
	i++; race_troll = fieldArray[i]; init_race(race_troll);
	if (race_troll == 'A') document.anatrolliseur.race[0].checked = true;
	if (race_troll == 'D') document.anatrolliseur.race[1].checked = true;
	if (race_troll == 'K') document.anatrolliseur.race[2].checked = true;
	if (race_troll == 'N') document.anatrolliseur.race[3].checked = true;
	if (race_troll == 'S') document.anatrolliseur.race[4].checked = true;
	if (race_troll == 'T') document.anatrolliseur.race[5].checked = true;
	i++; h = fieldArray[i];
	i++; m = fieldArray[i];
	while ((h != document.anatrolliseur.DLAH.value)
	    || (m != document.anatrolliseur.DLAM.value)) {
		carac('DLA',1); //recarac('DLA');
	}
	i++; document.anatrolliseur.PV.value = fieldArray[i]; recarac('PV');
	i++; document.anatrolliseur.VUE.value = fieldArray[i];
	i++; document.anatrolliseur.VUE_bm_p.value = fieldArray[i];
	i++; document.anatrolliseur.VUE_bm_m.value = fieldArray[i]; recarac('VUE');
	i++; document.anatrolliseur.ATT.value = fieldArray[i];
	i++; document.anatrolliseur.ATT_bm_p.value = fieldArray[i];
	i++; document.anatrolliseur.ATT_bm_m.value = fieldArray[i]; recarac('ATT');
	i++; document.anatrolliseur.ESQ.value = fieldArray[i];
	i++; document.anatrolliseur.ESQ_bm_p.value = fieldArray[i];
	i++; document.anatrolliseur.ESQ_bm_m.value = fieldArray[i]; recarac('ESQ');
	i++; document.anatrolliseur.DEG.value = fieldArray[i];
	i++; document.anatrolliseur.DEG_bm_p.value = fieldArray[i];
	i++; document.anatrolliseur.DEG_bm_m.value = fieldArray[i]; recarac('DEG');
	i++; document.anatrolliseur.REG.value = fieldArray[i];
	i++; document.anatrolliseur.REG_bm_p.value = fieldArray[i];
	i++; document.anatrolliseur.REG_bm_m.value = fieldArray[i]; recarac('REG');
	i++; document.anatrolliseur.MM.value = fieldArray[i];
	// comps
	for (var j = 0; j < document.anatrolliseur.comp.length; j++) {
		i++;
		if (fieldArray[i] == '1') {
			document.anatrolliseur.comp[j].checked = true;
		}
	}
	i++; document.anatrolliseur.ARM_bm_p.value = fieldArray[i];
	i++; document.anatrolliseur.ARM_bm_m.value = fieldArray[i];
	i++; document.anatrolliseur.PV_bm.value = fieldArray[i];
	i++; document.anatrolliseur.ARM.value = fieldArray[i]; recarac('ARM');

	donotreeval = false;
	reeval();
	reevalpi();
}

function save_anatrolliseur_cookie() {
	var value = get_anatrolliseur_cookie_value();
	var expires_in_x_days = 365;
	var expires = new Date();     //set new date object
	expires.setTime(expires.getTime() + (1000 * 60 * 60 * 24 * expires_in_x_days));

	document.cookie
		= cookie_name + "=" + escape(value)
		+ "; path=/"
		+ ((expires == null) ? "" : "; expires=" + expires.toGMTString());
}

function retrieve_anatrolliseur_cookie () {
	var dc = document.cookie;
	var prefix = cookie_name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	var value = unescape(dc.substring(begin + prefix.length, end));

	set_anatrolliseur_cookie_value(value);
}

retrieve_anatrolliseur_cookie();

