stats = [['Attack', 0, 14, 1, 4],['Hit Rate', 0, 50, 4, 1, 0],['Delay', 0, 10, 12, -1, 0],['Max MP', 1, 50, 1, 30, 0],['Magic Attack', 1, 50, 4, 1, 0],['Magic Defense', 1, -14, 1, 1, 0],['Capacity', 2, 620, 1, 80, 0],['Perception', 2, 0, 4, 1, 0],['Luck', 2, 0, 4, 1, 0],['Max HP', 3, 90, 1, 30, 0],['Defense', 3, -8, 1, 4, 0],['Evasion', 3, 0, 4, 1, 0]];
builds =["4114", "4123", "4132", "4141", "4213", "4222", "4231", "4312", "4321", "4411", "1414", "1423", "1432", "1441", "2413", "2422", "2431", "3412", "3421", "4411", "1144", "1243", "1342", "1441", "2143", "2242", "2341", "3142", "3241", "4141", "1144", "1234", "1324", "1414", "2134", "2224", "2314", "3124", "3214", "4114"];
function calculate_value(n) {
	if (stats[n][2] + stats[n][4] * Math.floor((4+stats_type[stats[n][1]]*(level-1))/4/stats[n][3]) < 0) {		
		return 0;
	} else {
		return stats[n][2] + stats[n][4] * Math.floor((4+stats_type[stats[n][1]]*(level-1))/4/stats[n][3]);
	}
}
function make_table(lvl, char_type) {
	level = parseInt(lvl,10);
	line = "<table border='1'><tr><td></td><td colspan='10'><center><font size='2'><strong><u>" + ["Power", "Magic", "Sense", "Charm"][char_type] +" Builds</u></strong></font></center></td></tr><tr><td><center><font size='2'><strong><u>Stats</u></strong></font></center></td>";
	for (i=char_type*10; i <= char_type*10 + 9; i++){
		line += "<td>" + builds[i] + "</td>";
	}
	line += "</tr>";
	for (var s = 0; s <= 11; s++) {
		line += "<tr><td>" + stats[s][0] + "</td>";
		for (var b = char_type*10; b <= char_type*10 + 9; b++) {
			stats_type = [parseInt(builds[b].charAt(0)), parseInt(builds[b].charAt(1)), parseInt(builds[b].charAt(2)), parseInt(builds[b].charAt(3))];
			line += "<td>" + calculate_value(s) + "</td>";
		}
	}
	document.getElementById('table').innerHTML = line + "</table>";
}
function check_level(level) {
	if (parseInt(level.value,10) < 0 || level.value == '') {
		level.value = 0;
	}
}