
function onCalc()
{
	var lv = document.form.lv.value;
	var dex = document.form.dex.value;
	var weapon = getSelectedValue(document.form.weapon);
	var job = document.form.job.selectedIndex;
	var param = 0;

	param += parseInt(getSelectedValue(document.form.haste));
	param += parseInt(getSelectedValue(document.form.gt));

	document.form.aspd.value =
		getAttackSpeed(lv, dex, weapon, job, param);
}

function getSelectedValue(obj)
{
	return obj.options[obj.selectedIndex].value;
}

function getAttackSpeed(lv, dex, weapon, job, param)
{
	var jobAspd = getJobAspd(job);

	var e = parseInt((lv / 8.0 + dex * 4.0) * weapon + jobAspd - 3.0);

	if (e > 187)
		e = 187;

	var f = getAttackSpeedPlusValue(e);
	var g = 50.0 / (200.0 - e) * 0.5 + f;
	var i = ((param * 0.001 + g)/2)*100;

	if (i < 0.0)
		return 5;
	if (i > 100.0)
		return 100.0;	

	return String(i).substr(0, 8);
}

function getAttackSpeedPlusValue(value)
{
	var table = new Array(
		0.08,
		0.16,
		0.24,
		0.32,
		0.40,
		0.48,
		0.56,
		0.64,
		0.72,
		0.80,
		0.88,
		0.96,
		1.04,
		1.12,
		1.20,
		1.30,
		1.38,
		1.50);

	var index = parseInt(value * 0.1);

	if (index < 0)
		index = 0;

	if (index >= 18)
		index = 17;

	return table[index];
}

function getJobAspd(job)
{
	var table = new Array(
		75,
		80,
		75,
		70,
		65,
		75,
		60,
		90,
		85,
		75,
		70,
		85,
		70,
		70,
		75,
		75);

	return table[job];
}

function onLoad()
{
	createJobSelector();
	createWeaponSelector();
	createHasteSelector();
	createGTSelector();
}

function createJobSelector()
{
	var obj = document.getElementById('job');

	var html = "";

	html += '<select name="job">';
	html += '<option>Vagrant</option>';
	html += '<option>Mercenary</option>';
	html += '<option>Acrobat</option>';
	html += '<option>Assist</option>';
	html += '<option>Magician</option>';
	html += '<option>=N/A=</option>';
	html += '<option>Knight</option>';
	html += '<option>Blade</option>';
	html += '<option>Jester</option>';
	html += '<option>Ranger</option>';
	html += '<option>Ringmaster</option>';
	html += '<option>Billposter</option>';
	html += '<option>Psykeeper</option>';
	html += '<option>Elementer</option>';
	html += '<option>=N/A=</option>';
	html += '<option>=N/A=</option>';
	html += '</select>';

	obj.innerHTML = html;
}

function createWeaponSelector()
{
	var obj = document.getElementById('weapon');

	var html = "";

	html += '<select name="weapon">';
	html += '<option value="0.085">Sword (One Hand)</option>';
	html += '<option value="0.035">Sword (Two Hands)</option>';
	html += '<option value="0.060">Axe (One Hand)</option>';
	html += '<option value="0.030">Axe (Two Hands)</option>';
	html += '<option value="0.050">Stick</option>';
	html += '<option value="0.070">Knuckle</option>';
	html += '<option value="0.025">Wand</option>';
	html += '<option value="0.045">Staff</option>';
	html += '<option value="0.075">Yoyo</option>';
	html += '<option value="0.070">Bow</option>';
	html += '</select>';

	obj.innerHTML = html;
}

function createHasteSelector()
{
	var obj = document.getElementById('haste');

	var html = "";

	html += '<select name="haste">';
	html += '<option value="0"  >  </option>';
	html += '<option value="100"> 1</option>';
	html += '<option value="120"> 2</option>';
	html += '<option value="140"> 3</option>';
	html += '<option value="180"> 4</option>';
	html += '<option value="200"> 5</option>';
	html += '<option value="220"> 6</option>';
	html += '<option value="240"> 7</option>';
	html += '<option value="260"> 8</option>';
	html += '<option value="280"> 9</option>';
	html += '<option value="300">10</option>';
	html += '<option value="320">11</option>';
	html += '<option value="340">12</option>';
	html += '<option value="360">13</option>';
	html += '<option value="380">14</option>';
	html += '<option value="400">15</option>';
	html += '<option value="420">16</option>';
	html += '<option value="440">17</option>';
	html += '<option value="460">18</option>';
	html += '<option value="480">19</option>';
	html += '<option value="500">20</option>';
	html += '</select>';

	obj.innerHTML = html;
}

function createGTSelector()
{
	var obj = document.getElementById('gt');

	var html = "";

	html += '<select name="gt">';
	html += '<option value="0"  >  </option>';
	html += '<option value="50" > 1</option>';
	html += '<option value="100"> 2</option>';
	html += '<option value="150"> 3</option>';
	html += '<option value="200"> 4</option>';
	html += '<option value="250"> 5</option>';
	html += '<option value="300"> 6</option>';
	html += '<option value="350"> 7</option>';
	html += '<option value="400"> 8</option>';
	html += '<option value="450"> 9</option>';
	html += '<option value="500">10</option>';
	html += '</select>';

	obj.innerHTML = html;
}
