element = new Array(0);	//‘®«”{—¦
//	UŒ‚‘¤		–³   ‰Î   “y   …   •—		//–hŒä‘¤
element[0] = new Array(  1, 1.3,   1, 0.9,   1);	//–³
element[1] = new Array(  1, 1.3,   1, 1.4, 0.7);	//‰Î
element[2] = new Array(0.9, 1.2, 0.9, 0.5, 1.3);	//“y
element[3] = new Array(  1, 0.7, 1.3, 0.9,   1);	//…
element[4] = new Array(  1, 1.6, 0.6, 0.9,   1);	//•—

//	–hŒä‘¤		  –³   ‰Î   “y   …   •—	UŒ‚‘¤
//element[0] = new Array(100, 100,  90, 100, 100);	//–³
//element[1] = new Array(130, 130, 120,  70, 160);	//‰Î
//element[2] = new Array(100, 100,  90, 130,  60);	//“y
//element[3] = new Array( 90, 140,  50,  90,  90);	//…
//element[4] = new Array(100,  70, 130, 100, 100);	//•—


//cooperation = new Array(0);	//˜AŒg”{—¦
//	–hŒä‘¤		        –³    ‰Î    “y    …    •—	//UŒ‚‘¤
//cooperation[0] = new Array(  1.3,  1.3, 1.33,  1.3,  1.3);	//–³	•s–¾
//cooperation[1] = new Array( 1.23, 1.23, 1.25, 1.43, 1.19);	//‰Î
//cooperation[2] = new Array(  1.3,  1.3, 1.33, 1.23,  1.5);	//“y
//cooperation[3] = new Array( 1.33, 1.21,  1.6, 1.33, 1.33);	//…
//cooperation[4] = new Array(  1.3, 1.43, 1.23,  1.3,  1.3);	//•—

cooperation = new Array(0);	//˜AŒg”{—¦
//	–hŒä‘¤		      –³    ‰Î    “y    …    •—	//UŒ‚‘¤
cooperation[0] = new Array(  1.3,  1.3,  4/3,  1.3,  1.3);	//–³	•s–¾
cooperation[1] = new Array(16/13,16/13, 1.25, 10/7,19/16);	//‰Î
cooperation[2] = new Array(  1.3,  1.3,  4/3,16/13,  1.5);	//“y
cooperation[3] = new Array(  4/3,17/14,  1.6,  4/3,  4/3);	//…
cooperation[4] = new Array(  1.3, 10/7,16/13,  1.3,  1.3);	//•—

edit_mob = new Array(0);

edit_mob[0]  = new Array(0,0,0,0,0,"");
edit_mob[1]  = new Array(0,0,0,0,0,"");
edit_mob[2]  = new Array(0,0,0,0,0,"");
edit_mob[3]  = new Array(0,0,0,0,0,"");
edit_mob[4]  = new Array(0,0,0,0,0,"");
edit_mob[5]  = new Array(0,0,0,0,0,"");
edit_mob[6]  = new Array(0,0,0,0,0,"");
edit_mob[7]  = new Array(0,0,0,0,0,"");
edit_mob[8]  = new Array(0,0,0,0,0,"");
edit_mob[9]  = new Array(0,0,0,0,0,"");
edit_mob[10] = new Array(0,0,0,0,0,"");
edit_mob[11] = new Array(0,0,0,0,0,"");
edit_mob[12] = new Array(0,0,0,0,0,"");
edit_mob[13] = new Array(0,0,0,0,0,"");
edit_mob[14] = new Array(0,0,0,0,0,"");
edit_mob[15] = new Array(0,0,0,0,0,"");
edit_mob[16] = new Array(0,0,0,0,0,"");
edit_mob[17] = new Array(0,0,0,0,0,"");
edit_mob[18] = new Array(0,0,0,0,0,"");
edit_mob[19] = new Array(0,0,0,0,0,"");

list = "";
edit_list = "";

function calc(){
	init();
	option_mob();
	list_out();
	edit();
}

function init(){
	pc_element = eval(document.form.pc_element.value);
	npc_element = eval(document.form.npc_element.value);

	pc_choice = eval(document.form.pc_choice.value);
	npc_choice = eval(document.form.npc_choice.value);

	pc_atk = eval(document.form.pc_atk.value);
	npc_atk = eval(document.form.npc_atk.value);
//	pc_matk = eval(document.form.pc_atk.value);
//	npc_matk = eval(document.form.npc_atk.value);
	pc_skill = eval(document.form.pc_skill.value);
	npc_skill = eval(document.form.npc_skill.value);
	pc_plus = eval(document.form.pc_plus.value);
	npc_plus = eval(document.form.npc_plus.value);

	def = 0;
	mdef = 0;

	list = "";
}

function option_mob(){
	mob[0][0] = eval(document.form.mob_element.value);
	mob[0][1] = eval(document.form.lv.value);
	mob[0][2] = eval(document.form.con.value);
	mob[0][3] = eval(document.form.wis.value);
	mob[0][4] = eval(document.form.hp.value);

	def_calc( mob[0][0], mob[0][1], mob[0][2], mob[0][3])

	document.form.def.value = Math.round(def);
	document.form.mdef.value = Math.round(mdef);

}

function def_calc( mob_element, lv, con, wis){

	//–hŒäŒvŽZ
	if (mob_element == 2) {def = lv*2.6 + con*1.75; mdef = lv*2.2 + wis*2.2}
	else                  {def = lv*2   + con*1.75; mdef = lv*2   + wis*2.2}
}

function list_out(){

	list += "<TABLE cellpadding=5><TR><TH>–¼‘O</TH><TH>‘®«</TH><TH>HP</TH><TH>PC</TH><TH>NPC</TH><TH>PC+NPC</TH><TH>˜AŒg</TH></TR>";


	for ( i=0; i<mob.length; i++){
		main_calc(mob[i][0], mob[i][1], mob[i][2], mob[i][3], mob[i][4], mob[i][5]);
	}

	list += "</TABLE>";

	document.all.list.innerHTML = list;

}

function main_calc(mob_element, lv, con, wis, life, name, flg){

	def_calc( mob_element, lv, con, wis)

	//pcUŒ‚ŒvŽZ
	var pc1 = pc_atk*1.4 + pc_skill;

	if (pc_choice == 0) {
		if (pc_atk >= def) var pc2 = def*0.98;
		if (pc_atk < def) var pc2 = pc_atk*0.98 + (def - pc_atk)*0.179;
	}
	if (pc_choice == 1) {
		if (pc_atk >= mdef) var pc2 = mdef*0.98;
		if (pc_atk < mdef) var pc2 = pc_atk*0.98 + (mdef - pc_atk)*0.179;
	}
	var pc3 = (pc1 - pc2)*element[mob_element][pc_element];

	//npcUŒ‚ŒvŽZ
	var npc1 = npc_atk*1.4 + npc_skill;

	if (npc_choice == 0) {
		if (npc_atk >= def) var npc2 = def*0.98;
		if (npc_atk < def) var npc2 = npc_atk*0.98 + (def - npc_atk)*0.179;
	}
	if (npc_choice == 1) {
		if (npc_atk >= mdef) var npc2 = mdef*0.98;
		if (npc_atk < mdef) var npc2 = npc_atk*0.98 + (mdef - npc_atk)*0.179;
	}
	var npc3 = (npc1 - npc2)*element[mob_element][npc_element];

	//ƒ}ƒCƒiƒXˆ—
	if (pc3 <= 0) pc3 = 0;
	if (npc3 <= 0) npc3 = 0;

	//˜AŒgŒvŽZ
	var cop_pc_dmg = pc3 * cooperation[pc_element][mob_element];
	var cop_npc_dmg = npc3 * cooperation[npc_element][mob_element];
	var cop_dmg = cop_pc_dmg + cop_npc_dmg;

	//ŽlŽÌŒÜ“ü
	pc3 = Math.round(pc3);
	npc3 = Math.round(npc3);
	cop_pc_dmg = Math.round(cop_pc_dmg);
	cop_npc_dmg = Math.round(cop_npc_dmg);
	cop_dmg = Math.round(cop_dmg);
	//o—Í
	var pc_dmg = pc3 + pc_plus;
	var npc_dmg = npc3 + npc_plus;
	var turn_dmg = pc3 + npc3 + pc_plus + npc_plus;
	var cop_pc_dmg = cop_pc_dmg + pc_plus;
	var cop_npc_dmg = cop_npc_dmg + npc_plus;
	var cop_dmg = cop_dmg + pc_plus + npc_plus;

	list += "<TR><TD bgcolor=lightgrey align=center>"+name+"</TD>";
	switch(mob_element){
		case 0 : list += "<TD bgcolor=white align=center>"+ele_name[mob_element]+"</TD>";break;
		case 1 : list += "<TD bgcolor=pink align=center>"+ele_name[mob_element]+"</TD>";break;
		case 2 : list += "<TD bgcolor=wheat align=center>"+ele_name[mob_element]+"</TD>";break;
		case 3 : list += "<TD bgcolor=skyblue align=center>"+ele_name[mob_element]+"</TD>";break;
		case 4 : list += "<TD bgcolor=lightgreen align=center>"+ele_name[mob_element]+"</TD>";break;
	}
	list += "<TD bgcolor=lightgrey align=right>"+life+"</TD>";
	list += "<TD bgcolor=lightgrey align=right>"+pc_dmg+"</TD>";
	list += "<TD bgcolor=lightgrey align=right>"+npc_dmg+"</TD>";
	if (turn_dmg < life) list += "<TD bgcolor=pink align=right>"+turn_dmg+"</TD>";
	if (turn_dmg >= life) list += "<TD bgcolor=skyblue align=right>"+turn_dmg+"</TD>";
	if (cop_dmg < life) list += "<TD bgcolor=pink>"+cop_dmg+"@(PC:"+cop_pc_dmg+"@NPC:"+cop_npc_dmg+")</TD>";
	if (cop_dmg >= life) {
		list += "<TD bgcolor=skyblue>"+cop_dmg+"@(PC:";
		if (life <= cop_pc_dmg) list += "<FONT color=red>"+cop_pc_dmg+"</FONT>";
			else if (life > cop_pc_dmg && life-50 < cop_pc_dmg) list += "<FONT color=yellow>"+cop_pc_dmg+"</FONT>";
			else list += cop_pc_dmg;
		list += "@NPC:";
		if (life <= cop_npc_dmg) list += "<FONT color=red>"+cop_npc_dmg+"</FONT>";
			else if (life > cop_npc_dmg && life-50 < cop_npc_dmg) list += "<FONT color=yellow>"+cop_npc_dmg+"</FONT>";
			else list += cop_npc_dmg;
		list += ")</TD></TR>";
	}
}


function minus(num) {
	if (num == 1) document.form.pc_atk.value = eval(document.form.pc_atk.value) - 1;
	if (num == 2) document.form.npc_atk.value = eval(document.form.npc_atk.value) - 1;
	calc();
}

function plus(num) {
	if (num == 1) document.form.pc_atk.value = eval(document.form.pc_atk.value) + 1;
	if (num == 2) document.form.npc_atk.value = eval(document.form.npc_atk.value) + 1;
	calc();
}



function edit() {
	for (i=1; i<edit_mob.length +1; i++) {
		edit_mob[i-1][0] = eval(document.form['mob_element'+ i].value);
		edit_mob[i-1][1] = eval(document.form['lv'+ i].value);
		edit_mob[i-1][2] = eval(document.form['con'+ i].value);
		edit_mob[i-1][3] = eval(document.form['wis'+ i].value);
		edit_mob[i-1][4] = eval(document.form['hp'+ i].value);
//		if (document.form['name'+ i].value == "") {
//			edit_mob[i-1][5] = "‘º’·";
//		} else {
			edit_mob[i-1][5] = document.form['name'+ i].value;
//		}
	}
	edit_list_out();
}

function edit_list_out() {

	list = "";

	edit_list = "<TABLE cellpadding=5><TR><TH>–¼‘O</TH><TH>‘®«</TH><TH>HP</TH><TH>PC</TH><TH>NPC</TH><TH>PC+NPC</TH><TH>˜AŒg</TH></TR>";


	for (i=0; i<edit_mob.length; i++){
		if(edit_mob[i][5] != "" && edit_mob[i][5].slice(-1) != "@") {
			main_calc(edit_mob[i][0], edit_mob[i][1], edit_mob[i][2], edit_mob[i][3], edit_mob[i][4], edit_mob[i][5], "edit");
		}
	}

	edit_list += list;

	edit_list += "</TABLE>";

	if(edit_list == "<TABLE cellpadding=5><TR><TH>–¼‘O</TH><TH>‘®«</TH><TH>HP</TH><TH>PC</TH><TH>NPC</TH><TH>PC+NPC</TH><TH>˜AŒg</TH></TR></TABLE>") edit_list += "<BR><CENTER>ŒvŽZ‘ÎÛ‚È‚µ</CENTER><BR>"

	document.all.edit_list.innerHTML = edit_list;
}

function MenuSwitch() {
	if (document.all.edit_mode.style.display == 'block') {
		edit(); 
		save_moblist();
		document.all.edit_mode.style.display = "none";
		document.all.edit_list.style.display = "block";
		document.form.edit_switch.value = "•ÒWƒ‚[ƒhŠJŽn";
	} else {
		document.all.edit_mode.style.display = "block";
		document.all.edit_list.style.display = "none";
		document.form.edit_switch.value = "•ÒWƒ‚[ƒhI—¹";
	}
}
