var c_slot = 1;
var el_counter = 0;
var colors = ["","attention-r","attention-y","attention-g"];
var mod_upgrade = [[0,0,0],[7,2,3],[6,3,5],[5,5,8],[4,7,14]];

function dostuff(newcss) { document.getElementsByTagName("link")[0].href = "../shared/" + newcss; }
function showcookie(inf) { document.getElementById("notice_cookie").innerHTML = inf; }
function output(out) { document.getElementById("notice").innerHTML = out; }
function zeros(x) {
	var retar = [];
	for (var i = 0; i < x; i++) retar[i] = 0;
	return retar;
}
function setcolorvalue(field,val,low,mid,high) {
	if (isNaN(val)) {
		alert(val + " is not a number usable in field " + field);
		val = 0;
	}
	field = document.getElementById(field);
	field.innerHTML = Math.floor(val) + "%";
	field.className = (val < 0) ? colors[low] : (val < 100) ? colors[mid] : (val > 100) ? colors[high] : "";
}
function setStat(statname, amount) {
	var field = document.getElementById(statname);
	var stat = + field.value + amount;
	if (stat > 99 || stat < 1) return;
	field.value = stat;
	calc();
}
function decimal(valued,digits) {

	if (isNaN(valued)) return "N/A";

	var mult = Math.pow(10,digits);
	digits = - digits;

	if (digits < 0) {

		if (valued < Math.pow(10,digits) / 2) return '0,' + '0000'.slice(digits);

		var a = "" + Math.round(valued * mult);
		var b = a.length + digits - 1;
		if (b < 0) a = '0000'.slice(b) + a;

		return a.slice(0,digits) + "." + a.slice(digits);

	} else {

		return Math.round(valued * mult) / mult;
	}
}
function Enemy(eRow) {
	this.id = eRow[0];
	this.name = eRow[1];
	this.sname = eRow[2];
	this.level = eRow[3];
	this.hp = eRow[4];
	this.str = eRow[5];
	this.agi = eRow[6];
	this.vit = eRow[7];
	this.intel = eRow[8];
	this.dex = eRow[9];
	this.luk = eRow[10];
	this.def = eRow[11];
	this.mdef = eRow[12];
	this.atkmin = eRow[13];
	this.atkmax = this.atkmin + eRow[14];
	this.atk = (this.atkmin + this.atkmax) / 2;
	this.bexp = eRow[15];
	this.jexp = eRow[16];
	this.race = eRow[17];
	this.element = eRow[18];
	this.elem = this.element % 10;
	this.elemlvl = Math.floor(this.element / 20);
	this.size = eRow[19];
	this.range = eRow[20];
	this.basehit = this.level + this.dex;
	this.baseflee = this.level + this.agi;

	this.calcEnemy = function() {
		document.getElementById('enemy_id').value = this.id;

		this.str = eRow[5];
		this.agi = eRow[6];
		this.vitmin = this.vit;
		this.vitmax = this.vit + Math.max(Math.pow(Math.floor(this.vit/20),2)-1,0);
		this.intel = eRow[8];
		this.dex = eRow[9];
		this.luk = eRow[10];
		this.def = eRow[11];
		this.mdef = eRow[12];
		this.atkmin = eRow[13];
		this.atkmax = this.atkmin + eRow[14];
		this.element = eRow[18];
		this.elem = this.element % 10;
		this.elemlvl = Math.floor(this.element / 20);

		var e_qua = document.getElementById("e_qua").checked;
		var e_poi = document.getElementById("e_poi").checked;
		var e_bli = document.getElementById("e_bli").checked;
		var e_cur = document.getElementById("e_cur").checked;
		var e_ble = + document.getElementById("e_ble").value;
		var e_agiu = + document.getElementById("e_agiu").value;
		var e_pro = + document.getElementById("e_pro").value;
		//var e_sig = + document.getElementById("e_sig").value;
		var e_sta = + document.getElementById("e_sta").value;

		var rname = name_race[this.race].toLowerCase();
		var ename = name_elem[this.elem].toLowerCase();

		if (e_agiu) {
			this.agi += 2 + e_agiu;
		}
		if (e_ble) {
			if (ename == "undead" || rname == "demon") {
				this.str *= 0.5;
				this.dex *= 0.5;
				this.intel *= 0.5;
			} else {
				this.str += e_ble;
				this.dex += e_ble;
				this.intel += e_ble;
			}
		}
		if (e_qua) {
			this.dex *= 0.5;
			this.agi *= 0.5;
		}
		if (e_poi) {
			this.def *= 0.75;
			this.vitmin *= 0.75;
			this.vitmax *= 0.75;
		}
		this.hit = this.level + this.dex;
		this.flee = this.level + this.agi;
		if (e_bli) {
			this.hit *= 0.75;
			this.flee *= 0.75;
		}
		if (e_cur || e_pro && ename != "undead") {
			var atkmod = 1;
			if (e_cur) {
				this.luk = 0;
				atkmod -= 0.25;
			}
			if (e_pro) {
				this.def *= 1 - 0.06 * e_pro;
				this.vitmin *= 0.95 - 0.05 * e_pro;
				this.vitmax *= 0.95 - 0.05 * e_pro;
				atkmod += 0.02 + 0.03 * e_pro;
			}
			this.atkmin *= atkmod;
			this.atkmax *= atkmod;
		}
		switch (e_sta) {
			case 1 :
				this.def *= 0.5;
				this.mdef *= 1.25;
				this.elem = 1;
				this.elemlvl = 1;
				break;
			case 2 :
				this.def *= 0.5;
				this.mdef *= 1.25;
				this.elem = 2;
				this.elemlvl = 1;
				break;
		}

		for (var i in this) {
			if (!isNaN(this[i])) this[i] = Math.floor(this[i]);
		}

		this.racename = name_race[this.race].toLowerCase();
		this.elemname = name_elem[this.elem].toLowerCase();
		this.sizename = name_size[this.size].toLowerCase();

		document.getElementById("enemy_lv").innerHTML = this.level;
		document.getElementById("enemy_hp").innerHTML = this.hp;
		document.getElementById("enemy_atk").innerHTML = this.atkmin + ' ~ ' + this.atkmax;
		document.getElementById("enemy_def").innerHTML = this.def;
		document.getElementById("enemy_mdef").innerHTML = this.mdef;
		document.getElementById("enemy_size").innerHTML = this.sizename;
		document.getElementById("enemy_elem").innerHTML = this.elemname + " " + this.elemlvl;
		document.getElementById("enemy_race").innerHTML = this.racename;
		document.getElementById("enemy_str").innerHTML = this.str;
		document.getElementById("enemy_agi").innerHTML = this.agi;
		document.getElementById("enemy_vit").innerHTML = this.vit;
		document.getElementById("enemy_int").innerHTML = this.intel;
		document.getElementById("enemy_dex").innerHTML = this.dex;
		document.getElementById("enemy_luk").innerHTML = this.luk;
		document.getElementById("enemy_bexp").innerHTML = this.bexp;
		document.getElementById("enemy_jexp").innerHTML = this.jexp;
	}
}
function sortmonster() {
	sorta = document.getElementById('enemy_sort0').value;
	sortb = document.getElementById('enemy_sort1').value;
	sortc = document.getElementById('enemy_sort2').value;

	var selectedenemy = document.getElementById('enemy_id').value;

	enemies.sort(enemysortfunca);

	a = '';
	a += '<select id="enemy_sel" onchange="calc();">';
	for (var i = 0; i < enemies.length; i++) {
		a += '<option value="' + i + '"' + (enemies[i].id == selectedenemy ? ' selected' : '') + '>' + enemies[i].name + '</option>';
	}
	a += '</select>';
	document.getElementById('i_enemy').innerHTML = a;
}
function enemysortfunca(a,b) {
	return (a[sorta] < b[sorta]) ? -1 : (a[sorta] > b[sorta] ? 1 : enemysortfuncb(a,b));
}
function enemysortfuncb(a,b) {
	return (a[sortb] < b[sortb]) ? -1 : (a[sortb] > b[sortb] ? 1 : enemysortfuncc(a,b));
}
function enemysortfuncc(a,b) {
	return (a[sortc] < b[sortc]) ? -1 : (a[sortc] > b[sortc] ? 1 : 0);
}

// COOKIES HERE

function saveCookie() {
	var cookieInfo = cookieName + makeCookie();
	if (c_slot == "text") {
		document.getElementById("cookie_text").value = escape(cookieInfo);
	} else {
		var date = new Date();
		date.setTime(date.getTime() + 1000*60*60*24*30);
		document.cookie = cookieName + "_slot" + c_slot + "=" + escape(cookieInfo) + "; expires=" + date.toGMTString();
	}
}
function concatCookie(param_field,param_type) {
	var eref = document.getElementById(param_field);
	if (!eref) {
		alert("Couldn't find element " + param_field + " of type " + param_type + ". Ignoring it.");
		return "";
	}
	switch (param_type) {
		case 0 :
			return "-" + eref.value + param_field;
		case 1 :
			return "-" + (eref.checked ? 1 : 0) + param_field;
		case 2 :
			if (eref.nodeName == "SELECT") {
				return "-" + eref.value + param_field;
			} else {
				return "-" + (eref.checked ? 1 : 0) + param_field;
			}
	}
}
function changeCookie(param_slot) { c_slot = param_slot; }
function clearCookie(cookiename) {
	if (!cookiename) cookiename = cookieName + "_slot" + c_slot;
	var expires = new Date(0);
	document.cookie = cookiename + "= ; expires=" + expires.toGMTString() + ";";
}
function loadCookie() {
	var loadedCookie = null;
	if (c_slot == "text") {
		loadedCookie = document.getElementById("cookie_text").value;
		if (loadedCookie.match(/[ ]/)) {
			loadedCookie = loadedCookie.replace(/ /g,'');
			document.getElementById("cookie_text").value = loadedCookie;
			alert("Cookie contained spaces, probably because of copy-pasting in a format with linebreaks.\nSpaces have been removed, you should keep the updated cookie text.");
		}
		if (loadedCookie.match(/[^a-zA-Z0-9_-]/)) {
			alert("Cookie contains illegal characters. It cannot be used.");
			return;
		}
	} else {
		if (!document.cookie) {
			alert("No cookies found.");
			return;
		}
		var loadedCookie = locateCookie(cookieName + "_slot" + c_slot);
		if (!loadedCookie) {
			alert("Empty character slot");
			return;
		}
	}
	loadedCookie = unescape(loadedCookie);
	var data = loadedCookie.split("-");
	var tmp = data[0];
	if (tmp != cookieName) {
		alert("Bad cookie format. Either the cookie has been tampered with, or it's not from this calculator.");
		return;
	}
	for (var i = 1, len = data.length, tmp2; i < len; i++) {
		tmp = data[i];
		tmp2 = "" + tmp.match(/^\d+/);
		tmp = tmp.slice(tmp2.length);
		if (document.getElementById(tmp)) {
			setField(tmp,tmp2);
			switch (tmp) {
				case 'job_sel' : setJob(); break;
				case 'enemy_id' : sortmonster(); break;
				default : break;
			}
		} else {
			alert("The field " + tmp + " does not exist.\nMost likely the cookie is a bit old, and could use a new saving.\nIf you tried a text cookie, it could be corrupted or tampered with.");
		}
	}
	calc();
}
function locateCookie(key) {
	var loadedCookie = null;
	var wantedCookie = key + "=";
	var wantedLen = wantedCookie.length;
	var cookieList = document.cookie.split(/; */);
	for (var i = 0, checkCookie, len = cookieList.length ; i < len; i++) {
		checkCookie = cookieList[i];
		if (checkCookie.substring(0,wantedLen) == wantedCookie) {
			loadedCookie = checkCookie.substring(wantedLen);
		}
	}
	return loadedCookie;
}
function setField(param_field,param_value) {
	var pfield = document.getElementById(param_field);
	if (pfield.nodeName == "INPUT" && pfield.type == "checkbox") {
		pfield.checked = (param_value == "0") ? false : true;
	} else {
		pfield.value = param_value;
		if (!pfield.value && pfield.value !== 0) {
			pfield.value = 0;
			alert("The item " + param_value + " in field " + param_field + " does not exist.\nMost likely the cookie is a bit old, and could use a new saving.\nIf you tried a text cookie, it could be corrupted or tampered with.");
		}
	}
}
function verifyCookies(age) {
	var cookies = document.cookie;
	var ageCookie = locateCookie("generation");
	if (!cookies) {
		switch(el_counter) {
			case 0 : alert("No cookies found, attempting to set generation cookie.\nThis message will appear every visit if you do not have FULL cookies ENABLED."); break;
			case 1 : alert("Setting generation cookie failed, trying again."); break;
			default : alert("Looks like your browser isn't accepting cookies.\nIt could also be that you have too many old cookies stored.\nIf you think this is the case, remove the old cookie, or contact me."); return; break;
		}
		setGeneration(age.slice(2));
		el_counter++;
		verifyCookies(age);
	} else if (ageCookie == age.slice(2)) {
		setGeneration(age);
		alert("Generation cookie set successfully.\nIf you get this message more than once,\nyou probably only have session cookies enabled.\nThe calc needs full cookies.");
	} else if (ageCookie != age) {
		showcookie(cookies);
		cookies = cookies.split(";");
		for (var i = 0; i < cookies.length; i++) {
			clearCookie(cookies[i].split("=")[0]);
		}
		setGeneration(age);
		alert("Old cookies detected and cleared.\nIf you believe this to be an error, a copy can be found below the cookie control panel.");
	}
}
function setGeneration(age) {
		var date = new Date();
		date.setTime(date.getTime() + 1000*60*60*24*365);
		document.cookie = "generation=" + age + "; expires=" + date.toGMTString();
}

function getBonusCards(in_cards, ar_bonus, enemyid, enemyrace, equiprefine, bstat) {
	// equiprefine[i] - 1:shield 2:h/u 3:h/m 4:h/l 5:armor 6:garm 7:foot 8,9:access 
	// 0: unique 1: +race 2: -race 3: +elem 4: -elem 5: +size 6: -size 7: atkdef 8: hpsp 9: stat 10: skill
	// [7][5] - crit dmg +% 	[0][7] - exp +%		[7][6] - damange from monster +%

//combo vars
var crab_combo = 0;
var peco_combo = 0;
var dark_combo = 0;	
var paper_combo = 0;	
var harpy_combo = 0;	
var merman_combo = 0;	
var dragonfly_combo = 0;
var vagabond_combo = 0;
var peach_combo = 0;
var raggler_combo = 0;
var mastering_combo = 0;
var vocal_combo = 0;
var hyegun_combo = 0;
var succubus_combo = 0;
var clocktower_combo = 0;
var mummy_combo = 0;
var eclipse_combo = 0;
var injustice_combo = 0;
var quve_combo = 0;
var cramp_combo = 0;
var toad_combo = 0;
var hyegun_combo = 0;
var assaulter_combo = 0;

	var card;

	for (var i in in_cards) {
		card = in_cards[i];
		if (card[3] < 10) ar_bonus[card[3]][card[4]] += card[5];
		else ar_bonus[card[3]][card[4]] = true;
		switch (card[1]) {
			case "c_steelchonchon" :
				ar_bonus[4][4] += 10;
				break;
			case "c_whisper" :
				ar_bonus[4][8] -= 50;
				break;
			case "c_rocker" :
				vocal_combo ++;
			case "c_desertwolf" :
			case "c_skelworker" :
			case "c_minorous" :
				ar_bonus[7][0] += 5;
				break;
			case "c_verit" :
				ar_bonus[8][1] += 8;
				break;
			case "c_ghostring" :
				ar_bonus[8][2] -= 25;
				break;
			case "c_sohee" :
				ar_bonus[8][3] += 3;
				break;
			case "c_picky" :
			case "c_kobold" :
			case "c_hornet" :
				ar_bonus[9][0]++;
				break;
			case "c_yoyo" :
			case "c_matyr" :
			case "c_ftb" :
			case "c_chonchon" :
				ar_bonus[9][1]++;
				dragonfly_combo ++;
				break;
			case "c_evildruid" :
				ar_bonus[9][3]++;
			case "c_swordfish" :
			case "c_sandman" :
			case "c_pasana" :
			case "c_dokebi" :
			case "c_argiope" :
			case "c_munak" :
				ar_bonus[9][6]++;
				hyegun_combo += 2;
				break;
			case "c_poring" :
				ar_bonus[9][5] += 2;
				mastering_combo ++;
				break;
			case "c_drops" :
				ar_bonus[9][8] += 3;
				break;
			case "c_marse" :
			case "c_hode" :
			case "c_jakk" :
			case "c_dustiness" :
			case "c_myst" :
			case "c_isis" :
			case "c_marionette" :
			case "c_orczombie" :
				ar_bonus[9][9] += 5;
				break;
			case "c_lunatic" :
				eclipse_combo ++;
				ar_bonus[9][11] += 10;
			case "c_baphojr" :
				ar_bonus[9][10] += 10;
				break;
			case "c_wolf" :
				ar_bonus[9][10] += 10;
				vagabond_combo ++;
				break;
			case "c_fabre" :
			case "c_superpicky" :
				ar_bonus[9][12] += 100;
				break;
			case "c_andrelarva" :
				ar_bonus[9][13] += 10;
				break;
			case "c_rodafrog" :
				ar_bonus[9][13] += 50;
				toad_combo ++;
				break;
			case "c_assaulter" :
				if (enemyrace == 7) ar_bonus[9][10] += 70;
				assaulter_combo ++;
				break;
			case "c_bloodymurderer" :
				if (enemyrace == 4) ar_bonus[9][10] += 70;
				break;
			case "c_cruiser" :
				if (enemyrace == 2) ar_bonus[9][10] += 70;
				break;
			case "c_dullahan" :
				if (enemyrace == 9) ar_bonus[9][10] += 70;
				break;
			case "c_goblinarcher" :
				if (enemyrace == 1) ar_bonus[9][10] += 70;
				break;
			case "c_goblinsteamrider" :
				if (enemyrace == 0) ar_bonus[9][10] += 70;
				break;
			case "c_koboldarcher" :
				if (enemyrace == 3) ar_bonus[9][10] += 70;
				break;
			case "c_panzergoblin" :
				if (enemyrace == 6) ar_bonus[9][10] += 70;
				break;
			case "c_rotarzairo" :
				if (enemyrace == 5) ar_bonus[9][10] += 70;
				break;
			case "c_apocalipse" :
				if (equiprefine[5] > 8) ar_bonus[9][12] += 800;
				break;
			case "c_carat" :
				if (equiprefine[2] > 8) ar_bonus[9][13] += 150;
				break;
			case "c_firelock" :
				if (equiprefine[7] > 8) {
					ar_bonus[8][0] += 10;
					ar_bonus[8][1] += 10;
					}
				break;
			case "c_gibbet" :
				if (equiprefine[i] < 6) ar_bonus[9][7] += 5;
				break;
			case "c_goat" :
				if (equiprefine[5] < 6) {
					ar_bonus[9][6] += 2;
					ar_bonus[9][7] += 5;
					}
				break;
			case "c_kapha" :
				if (equiprefine[6] < 6) ar_bonus[9][7] += 8;
				break;
			case "c_megalith" :
				if (equiprefine[7] < 6) ar_bonus[9][7] += 7;
				break;
			case "c_ninetail" :
				if (equiprefine[6] > 8) ar_bonus[9][9] += 20;
				break;
			case "c_sting" :
				if (equiprefine[1] > 8) ar_bonus[9][7] += 5;
				break;
			case "c_arclouze" :
				if (equiprefine[1] < 6){ 
					ar_bonus[9][6] += 2;
					ar_bonus[9][7] += 3;
					}
				break;
			case "c_ammut" :
				if (enemyrace = 7){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_ancientworm" :
				if (enemyrace = 6){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_christmascookie" :
				if (enemyrace = 8){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_explosion" :
				if (enemyrace = 9){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_gajomart" :
				if (enemyrace = 3){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_gullinbursti" :
				if (enemyrace = 5){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_ironfist" :
				if (enemyrace = 0){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_minidemon" :
				if (enemyrace = 2){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_skelgeneral" :
				if (enemyrace = 4){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_zombieprisoner" :
				if (enemyrace = 1){ 
					ar_bonus[0][7] += 10;
					ar_bonus[7][6] += 20;
					}
				break;
			case "c_crab" :
				if (enemyid == 195){ 
					ar_bonus[7][7] += 30;
					}
				crab_combo++;
				break;
			case "c_aster" :
				if (enemyid == 194){ 
					ar_bonus[7][7] += 30;
					}
				crab_combo += 2;
				break;
			case "c_shellfish" :
				if (enemyid == 196){ 
					ar_bonus[7][7] += 30;
					}
				crab_combo += 4;
				break;
			case "c_goblinleader" :
				if (enemyid == 41 || enemyid == 42 || enemyid == 43 || enemyid == 44 || enemyid == 45 || enemyid == 198 || enemyid == 270 || enemyid == 187 || enemyid == 202 || enemyid == 321){ 
					ar_bonus[7][7] += 30;
					}
				break;
			case "c_koboldleader" :
				if (enemyid == 35 || enemyid == 36 || enemyid == 37 || enemyid == 201 || enemyid == 274){ 
					ar_bonus[7][7] += 30;
					}
				break;
			case "c_lavagolem" :
				if (enemyid == 40 || enemyid == 312 || enemyid == 219 || enemyid == 351){ 
					ar_bonus[7][7] += 30;
					}
				break;
			case "c_orclady" :
				if (enemyid == 163 || enemyid == 167 || enemyid == 199 || enemyid == 23 || enemyid == 22 || enemyid == 25 || enemyid == 69){ 
					ar_bonus[7][7] += 30;
					}
				break;
			case "c_grandpeco" :
				peco_combo ++;
				break;
			case "c_pecopeco" :
				peco_combo += 2;
				break;
			case "c_gryphon" :
				ar_bonus[9][10] += 7;
				ar_bonus[9][9] += 2;
				break;
			case "c_darklord" :
				dark_combo ++;
				break;
			case "c_darkillusion" :
				dark_combo ++;
				ar_bonus[8][0] -= 10;
				ar_bonus[8][1] -= 10;
				ar_bonus[7][2] += 10;
				break;
			case "c_thepaper" :
				paper_combo ++;
				ar_bonus[7][5] += 20;
				break;
			case "c_wanderer" :
				paper_combo += 2;
				break;
			case "c_wildrose" :
				paper_combo += 4;
				break;
			case "c_shinobi" :
				paper_combo += 8;
				break;
			case "c_dancingdragon" :
				paper_combo += 16;
				ar_bonus[9][10] += 30;
				break;
			case "c_deviling" :
				ar_bonus[4][0] += 50;
				ar_bonus[4][1] -= 50;
				ar_bonus[4][2] -= 50;
				ar_bonus[4][3] -= 50;
				ar_bonus[4][4] -= 50;
				ar_bonus[4][5] -= 50;
				ar_bonus[4][6] -= 50;
				ar_bonus[4][7] -= 50;
				ar_bonus[4][8] -= 50;
				ar_bonus[4][9] -= 50;
				break;
			case "c_harpy" :
				harpy_combo ++;
				break;
			case "c_noxious" :
				ar_bonus[4][0] += 10;		
				if (equiprefine[6] < 5) ar_bonus[4][0] += 15;
				break;
			case "c_orcbaby" :
				if (equiprefine[6] < 9) {
							ar_bonus[4][0] += 10;
							ar_bonus[9][9] += 10;
							} else {
							ar_bonus[4][0] += 5;
							ar_bonus[9][9] += 5;
							}
				break;
			case "c_parasite" :
				ar_bonus[4][0] += 5;		
				ar_bonus[9][6] ++;
				harpy_combo += 2;	
				break;
			case "c_permeter" :
				ar_bonus[4][7] += 15;		
				ar_bonus[4][9] += 15;
				assaulter_combo += 8;	
				break;
			case "c_dragontail" :
				ar_bonus[9][1] += 1;		
				ar_bonus[9][9] += 10;
				merman_combo ++;	
				break;
			case "c_dragonfly" :
				dragonfly_combo ++;	
				break;
			case "c_vagabondwolf" :
				vagabond_combo += 4;	
				break;
			case "c_rideword" :
				peach_combo += 4;	
				break;
			case "c_raggler" :
				ar_bonus[9][0] += 1;		
				ar_bonus[9][2] += 1;
				raggler_combo ++;	
				break;
			case "c_loliruri" :
				harpy_combo += 4;
				break;
			case "c_mastering" :
				mastering_combo += 4;
				break;
			case "c_merman" :
				ar_bonus[8][2] += 10;		
				ar_bonus[8][3] += 10;
				merman_combo += 2;
				break;
			case "c_mystcase" :
				raggler_combo += 2;	
				break;
			case "c_mysteltainn" :
				ar_bonus[9][6] ++;	
				break;
			case "c_miyabidoll" :
				harpy_combo += 8;
				break;
			case "c_vocal" :
				vocal_combo ++;
				break;
			case "c_bongun" :
				hyegun_combo +=4;
				if (enemyid == 126) ar_bonus[7][6] += 100; 
				break;
			case "c_enchantedpeachtree" :
				peach_combo += 16;
				break;
			case "c_succubus" :
				succubus_combo ++;
				ar_bonus[9][12] += 1000;
				ar_bonus[8][2] -= 20;
				ar_bonus[9][2] -= 3;	
				break;
			case "c_solider" :
				assaulter_combo += 4;
				ar_bonus[9][6] += 2;
				ar_bonus[9][7] += 2;
				break;
			case "c_stoneshooter" :
				ar_bonus[9][8] += 10;
				ar_bonus[7][0] += 10;
				break;
			case "c_ctmanager" :
				ar_bonus[7][2] += 5;
				clocktower_combo ++;
				break;
			case "c_babyleopard" :
				raggler_combo += 4;
				break;
			case "c_anolian" :
				merman_combo += 4;
				break;
			case "c_amonra" :
				ar_bonus[9][0] ++;
				ar_bonus[9][1] ++;
				ar_bonus[9][2] ++;
				ar_bonus[9][3] ++;
				ar_bonus[9][4] ++;
				ar_bonus[9][5] ++;
				break;
			case "c_arcangeling" :
				if (bstat[5] > 76){
						ar_bonus[8][2] += 100;
						ar_bonus[8][3] += 100;
						}
				break;
			case "c_alarm" :
				ar_bonus[9][2] ++;
				clocktower_combo ++;
				break;
			case "c_ancientmummy" :
				mummy_combo += 4;
				break;
			case "c_mummy" :
				mummy_combo ++;
				break;
			case "c_executioner" :
				ar_bonus[6][2] += 25;
				break;
			case "c_alligator" :
				merman_combo += 16;
				break;
			case "c_tirfing" :
				ar_bonus[6][1] += 25;
				break;
			case "c_evilnymph" :
				ar_bonus[9][3] ++;
				harpy_combo += 16;
				break;
			case "c_woodengolem" :
				ar_bonus[8][2] += 30;
				break;
			case "c_eclipse" :
				eclipse_combo += 4;
				break;
			case "c_injustice" :
				injustice_combo ++;
				break;
			case "c_incubus" :
				succubus_combo += 4;
				ar_bonus[9][13] += 150;
				ar_bonus[8][3] -= 20;
				ar_bonus[9][3] -= 3;	
				break;
			case "c_zherlthsh" :
				injustice_combo += 4;
				break;
			case "c_geographer" :
				peach_combo += 2;
				break;
			case "c_zipperbear" :
				raggler_combo += 8;
				break;
			case "c_choco" :
				ar_bonus[9][11] += 50;
				break;
			case "c_cookie" :
				peach_combo += 8;
				break;
			case "c_quve" :
				quve_combo += 2;
				break;
			case "c_lude" :
				quve_combo ++;
				break;
			case "c_cramp" :
				cramp_combo ++;
				break;
			case "c_tarou" :
				cramp_combo +=2;
				break;
			case "c_clock" :
				clocktower_combo ++;
				break;
			case "c_taogunka" :
				ar_bonus[9][6] -= 50;
				ar_bonus[9][7] -= 50;
				ar_bonus[8][0] += 100;
				break;
			case "c_giantwhisper" :
				if (bstat[0] > 79) ar_bonus[7][0] += 20;
				if (bstat[2] > 79) ar_bonus[8][0] += 3;
				if (bstat[5] > 79) ar_bonus[9][10] += 30;
				break;
			case "c_toad" :
				toad_combo ++;
				break;
			case "c_seal" :
				ar_bonus[9][8] += 10;
				peach_combo ++;
				break;
			case "c_punk" :
				clocktower_combo ++;
				break;
			case "c_hylozoist" :
				raggler_combo += 16;
				break;
			case "c_bloodybutterfly" :
				ar_bonus[7][2] -= 30;
				harpy_combo += 32;
				break;
			case "c_hyegun" :
				ar_bonus[9][10] += 10;
				hyegun_combo ++;
				break;
			case "c_heater" :
				assaulter_combo += 2;
				break;
			case "c_freezer" :
				assaulter_combo += 16;
				break;
		}

	// equiprefine[i] - 1:shield 2:h/u 3:h/m 4:h/l 5:armor 6:garm 7:foot 8,9:access 
	// 0: unique 1: +race 2: -race 3: +elem 4: -elem 5: +size 6: -size 7: atkdef 8: hpsp 9: stat 10: skill
	// [7][5] - crit dmg +% 	[0][7] - exp +%		[7][6] - damange from monster +%	[7][7] - atk vs monster +% 	[9][14] - perfhit +%	[7][8] - longrangedef +%

if (crab_combo == 7){ 
		ar_bonus[3][1] += 30;
		crab_combo = 0;
		}
if (peco_combo == 3){ 
		ar_bonus[9][2] += 3;
		ar_bonus[9][6] += 3;
		crab_combo = 0;
		}
if (dark_combo == 2){ 
		ar_bonus[8][0] += 20;
		ar_bonus[8][1] += 20;
		ar_bonus[7][2] += 10;
		dark_combo = 0;
		}
if (paper_combo == 31){ 
		ar_bonus[9][0] += 5;
		ar_bonus[9][1] += 5;
		paper_combo = 0;
		}
if (harpy_combo > 62){ 
		ar_bonus[9][12] += 500;
		ar_bonus[9][6] += 5;
		ar_bonus[9][7] += 5;
		harpy_combo = 0;
		}
if (dragonfly_combo == 2){ 
		ar_bonus[9][9] += 18;
		dragonfly_combo = 0;
		}
if (vagabond_combo > 4){ 
		ar_bonus[9][9] += 18;
		vagabond_combo = 0;
		}
if (raggler_combo > 30){ 
		ar_bonus[9][5] += 10;
		raggler_combo = 0;
		}
if (mastering_combo > 4){ 
		ar_bonus[9][9] += 18;
		mastering_combo = 0;
		}
if (merman_combo > 30){ 
//to do: +20% to long range phys atk
		ar_bonus[9][14] += 20;	
		ar_bonus[9][1] += 5;
		ar_bonus[9][4] += 3;
		merman_combo = 0;
		}
if (vocal_combo == 2){ 
		ar_bonus[9][9] += 18;
		vocal_combo = 0;
		}
if (peach_combo > 30){ 
		ar_bonus[9][2] += 10;
		ar_bonus[7][2] += 10;
		peach_combo = 0;
		}
if (succubus_combo > 4){ 
		ar_bonus[8][2] += 30;
		ar_bonus[9][2] += 4;
		ar_bonus[8][3] += 30;
		ar_bonus[9][3] += 4;		
		succubus_combo = 0;
		}
if (clocktower_combo == 4){ 
		ar_bonus[9][6] += 3;
		ar_bonus[9][7] += 3;	
		clocktower_combo = 0;
		}
if (mummy_combo > 4){ 
		ar_bonus[9][14] += 20;		
		mummy_combo = 0;
		}
if (eclipse_combo > 4){ 
		ar_bonus[9][9] += 18;
		eclipse_combo = 0;
		}
if (injustice_combo > 4){ 
		ar_bonus[9][5] += 3;
		ar_bonus[7][0] += 20;
		injustice_combo = 0;
		}
if (quve_combo == 3){ 
		ar_bonus[9][12] += 300;
		ar_bonus[9][13] += 60;
		quve_combo = 0;
		}
if (cramp_combo == 3){ 
		ar_bonus[9][0] += 3;
		cramp_combo = 0;
		}
if (toad_combo == 2){ 
		ar_bonus[9][9] += 18;
		toad_combo = 0;
		}
if (hyegun_combo > 6){ 
		ar_bonus[9][0] ++;
		ar_bonus[9][1] ++;
		ar_bonus[9][2] ++;
		ar_bonus[9][3] ++;
		ar_bonus[9][4] ++;
		ar_bonus[9][5] ++;
		hyegun_combo = 0;
		}
if (assaulter_combo > 30){ 
		ar_bonus[9][0] += 10;
		ar_bonus[8][0] += 20;
		ar_bonus[8][2] += 50;
		assaulter_combo = 0;
		}

	}

	if (ar_bonus[0][3]) {
		var num = 7 * ar_bonus[0][3];
		ar_bonus[1][2] += num;
		ar_bonus[1][3] += num;
		ar_bonus[1][4] += num;
		ar_bonus[1][7] += num;
	}

}

function getBonusItems(in_items, ar_bonus, ar_sta_bonus) {

	// 0: unique 1: +race 2: -race 3: +elem 4: -elem 5: +size 6: -size 7: atkdef 8: hpsp 9: stat 10: skill

//combo counter variables
var undershirt_combo = 0;
var shackle_combo = 0;
var friggs_combo = 0;
var morpheus_combo = 0;
var morrigane_combo = 0;
var goibne_combo = 0;
var stonebuckler_combo = 0;

	for (var i in in_items) {
		thing = in_items[i];
		if (thing[2] != 9 || thing[3] > 5) {
			ar_bonus[thing[2]][thing[3]] += thing[4];
		} else {
			ar_sta_bonus[thing[3]] += thing[4];
			if (thing[3] == 2) ar_bonus[9][12] += thing[4];
			if (thing[3] == 3) ar_bonus[9][13] += thing[4];
		}
		switch (thing[1]) {
		case "robeofcast" :
			ar_bonus[7][2] += 3;
			break;
		case "valkyriesshield" :
			ar_bonus[4][1] += 20;
			ar_bonus[4][3] += 20;
			ar_bonus[4][7] += 20;
			ar_bonus[4][9] += 20;
			friggs_combo ++;
			break;
		case "armorofvolcano" :
			ar_bonus[7][1] = 3;
			break;
		case "armorofocean" :
			ar_bonus[7][1] = 1;
			break;
		case "armoroftyphoon" :
			ar_bonus[7][1] = 4;
			break;
		case "armorofearth" :
			ar_bonus[7][1] = 2;
			break;
		case "goibnesarmor" :
			goibne_combo ++;	
			break;
		case "valkyriesarmor" :
			ar_bonus[9][0] += 1;
			ar_bonus[9][1] += 1;
			ar_bonus[9][2] += 1;
			ar_bonus[9][3] += 1;
			ar_bonus[9][4] += 1;
			ar_bonus[9][5] += 1;
			break;
		case "sleipnir" :
			ar_bonus[8][0] += 20;
			ar_bonus[8][1] += 20;
			ar_bonus[8][3] += 15;
			break;
		case "vidarsboots" :
			ar_bonus[8][0] += 9;
			ar_bonus[8][1] += 9;
			break;
		case "goibnesgreaves" :
			ar_bonus[8][0] += 5;
			ar_bonus[8][1] += 5;
			goibne_combo ++;
			break;
		case "skeletonmanteau" :
			ar_bonus[9][0] += 2;
			ar_bonus[9][1] -= 4;
			ar_bonus[9][2] -= 3;
			ar_bonus[9][3] -= 3;
			ar_bonus[9][4] += 2;
			ar_bonus[9][5] += 2;
			break;
		case "falconmuffler" :
			ar_bonus[9][9] += 15;
			ar_bonus[9][11] += 50;
			break;
		case "morriganesmanteau" :
			ar_bonus[9][5] += 2;
			ar_bonus[9][11] += 80;
			morrigane_combo +=8;
			break;
		case "goibnesspaulders" :
			ar_bonus[7][8] = 10;
			goibne_combo ++;
			break;
		case "sacredincense" :
			ar_bonus[9][0] += 1;
			ar_bonus[9][5] += 1;
			break;
		case "occultincense" :
			ar_bonus[9][1] += 1;
			ar_bonus[9][2] += 1;
			break;
		case "kafraring" :
			ar_bonus[9][0] += 2;
			ar_bonus[9][1] -= 4;
			ar_bonus[9][3] -= 3;
			ar_bonus[9][5] += 2;
			break;
		case "thesign" :
			ar_bonus[7][0] += 5;
			ar_bonus[7][4] += 5;
			break;
		case "morpheussring" :
			ar_bonus[9][3] += 1;
			ar_bonus[8][1] += 5;
			morpheus_combo ++;
			break;
		case "morpheussbracelet" :
			ar_bonus[9][3] += 1;
			ar_bonus[8][1] += 5;
			morpheus_combo += 2;
			break;
		case "morriganesbelt" :
			ar_bonus[7][0] += 5;
			ar_bonus[9][10] += 30;
			morrigane_combo += 4;
			break;
		case "morriganespendant" :
			ar_bonus[9][0] += 2;
			ar_bonus[9][10] += 30;
			morrigane_combo += 2;
			break;
		case "shinobisash" :
			ar_bonus[9][0] += 1;
			ar_bonus[9][1] += 1;
			ar_bonus[9][12] += 300;
			break;
		case "shackleball" :
			shackle_combo ++;
			break;
		case "ballnchain" :
			shackle_combo ++;
			break;
		case "gauntletofhit" :
			ar_bonus[9][0] += 1;
			ar_bonus[9][8] += 15;
			break;
		case "belcarf" :
			ar_bonus[9][3] += 1;
			ar_bonus[9][4] += 2;
			break;
		case "glovesofarcher" :
			ar_bonus[9][4] += 1;
			ar_bonus[9][8] += 5;
			ar_bonus[9][10] += 50;
			break;
		case "undershirt" :
			undershirt_combo ++;
			break;
		case "pantie" :
			undershirt_combo ++;
			break;
		case "kitsunemask" :
			ar_bonus[9][1] += 1;
			ar_bonus[9][5] += 1;
			break;
		case "crownofmistress" :
			ar_bonus[9][3] += 2;
			ar_bonus[9][13] += 100;
			break;
		case "helmetoforchero" :
			ar_bonus[9][0] += 2;
			ar_bonus[9][2] += 1;
			break;
		case "tigermask" :
			ar_bonus[9][0] += 3;
			ar_bonus[9][12] += 100;
			break;
		case "nekomimi" :
			ar_bonus[9][5] += 2;
			ar_bonus[1][5] += 5;
			break;
		case "salesbanner" :
			ar_bonus[9][0] += 1;
			ar_bonus[9][1] += 1;
			ar_bonus[9][5] += 1;
			break;
		case "sunflowerhairpin" :
			ar_bonus[9][1] += 2;
			ar_bonus[9][10] += 50;
			break;
		case "2ndanniversarycakehat" :
			ar_bonus[9][4] += 1;
			ar_bonus[9][13] += 80;
			break;
		case "zherlthshmask" :
			ar_bonus[2][7] += 5;
			ar_bonus[1][7] += 5;
			break;
		case "friggscirclet" :
			ar_bonus[9][3] += 2;
			ar_bonus[9][13] += 50;	
			friggs_combo ++ ;
			break;
		case "odinsblessing" :
			friggs_combo ++ ;
			stonebuckler_combo ++;
			break;
		case "morpheusshood" :
			ar_bonus[9][3] += 2;
			ar_bonus[7][2] -= 25;	
			friggs_combo ++ ;
			morpheus_combo += 4;
			break;
		case "morpheussshawl" :
			morpheus_combo += 8;
			break;
		case "morriganeshelm" :
			ar_bonus[9][5] += 2;
			ar_bonus[7][0] += 3;
			morrigane_combo ++;
			break;
		case "goibneshelm" :
			goibne_combo ++;
			break;
		case "birdnest" :
			ar_bonus[2][2] += 10;
			break;
		case "angelinghat" :
			ar_bonus[2][7] += 10;
			break;
		case "alicedoll" :
			ar_bonus[9][0] += 1;
			ar_bonus[1][7] += 10;
			break;
		case "lotus" :
			ar_bonus[9][3] += 1;
			ar_bonus[9][4] += 1;
			break;
		case "kawaiiribbon" :
			ar_bonus[2][1] += 5;
			ar_bonus[2][6] += 5;
			break;
		case "elephanthat" :
			ar_bonus[2][2] += 7;
			break;
		case "stonebuckler" :
			stonebuckler_combo ++;
			break;
		case "magniscap" :
			stonebuckler_combo ++;
			break;
		default:
			break;
		}	

//combo checks
if (undershirt_combo == 2) {
			ar_bonus[9][1] += 5;
			ar_bonus[9][9] += 10;
			undershirt_combo = 0;
			}
if (shackle_combo == 2) {
			ar_bonus[7][0] += 100;
			shackle_combo = 0;
			}
if (friggs_combo == 3) {
			ar_bonus[9][6] += 2;
			ar_bonus[9][7] += 25;
			friggs_combo = 0;
			}
if (morpheus_combo == 15) {
			ar_bonus[9][3] += 5;
			ar_bonus[9][7] += 11;
			ar_bonus[9][13] += 20;
			morpheus_combo = 0;
			}
if (morrigane_combo == 15) {
			ar_bonus[9][0] += 2;
			ar_bonus[9][5] += 9;
			ar_bonus[7][0] += 18;
			ar_bonus[9][10] += 13;	
			ar_bonus[9][11] += 13;			
			morrigane_combo = 0;
			}
if (goibne_combo == 4) {
			ar_bonus[9][2] += 5;
			ar_bonus[8][0] += 15;
			ar_bonus[8][1] += 5;
			ar_bonus[9][6] += 5;	
			ar_bonus[9][7] += 15;
			ar_bonus[4][1] += 10;		
			ar_bonus[4][2] += 10;
			ar_bonus[4][3] += 10;
			ar_bonus[4][4] += 10;	
			goibne_combo = 0;
			}
if (stonebuckler_combo == 3) {
			ar_bonus[9][0] += 3;
			ar_bonus[9][6] += 5;
			ar_bonus[9][7] += 5;
			stonebuckler_combo = 0;
			}
				
	}

}

function getBonusWeapon(in_weapon, ar_bonus, ar_sta_bonus, enemyrace) {

	switch (in_weapon[1]) {
		case "assassindagger" :
			ar_bonus[8][0] += 20;
			ar_bonus[8][1] += 15;
			break;
		case "crescentscythe" :
			ar_bonus[9][8] += 10;
			break;
		case "firebrand" :
			//var p_hs;
			break;
		case "fortunesword" :
			ar_bonus[9][11] += 200;
			break;
		case "gungnir" :
			//guided attack
			break;
		case "icefalchion" :
			//var p_hs;
			break;
		case "infiltrator" :
			ar_bonus[9][6] += 3;
			ar_bonus[9][9] += 5;
			ar_bonus[9][11] += 20;
			break;
		case "pollaxe" :
			ar_sta_bonus[0]++;
			ar_sta_bonus[4]++;
			break;
		case "katzbalger" :
			ar_sta_bonus[2] += 5;
			break;
		case "lightepsilon" :
			ar_bonus[1][6] += 3;
			break;
		case "muramasa" :
			ar_bonus[7][3] += 8;
			break;
		case "chemetiwhip" :
			ar_bonus[9][9] += 10;
			ar_bonus[9][10] += 50;
			ar_bonus[9][11] += 20;
			break;
		case "weederknife" :
			ar_bonus[1][3] += 15;
			ar_bonus[2][3] += 15;
			break;
		case "combatknife" :
			ar_bonus[1][7] += 10;
			ar_bonus[2][7] -= 10;
			break;
		case "kitchenknife" :
			ar_bonus[9][10] += 30;
			ar_bonus[1][7] += 3;
			break;
		case "bazerald" :
			ar_bonus[9][3] += 5;
			ar_bonus[7][4] += 10;
			break;
		case "exorciser" :
			ar_bonus[2][6] += 5;
			ar_bonus[2][7] -= 10;
			break;
		case "sucsamad" :
			ar_bonus[3][2] += 10;
			ar_bonus[3][4] += 10;
			break;
		case "princessknife" :
			ar_bonus[9][0] += 1;
			ar_bonus[9][1] += 1;
			ar_bonus[9][2] += 1;
			ar_bonus[9][3] += 1;
			ar_bonus[9][4] += 1;
			ar_bonus[9][5] += 1;
			break;
		case "wizardrystaff" :
			ar_bonus[9][3] += 6;
			ar_bonus[9][4] += 2;
			ar_bonus[7][4] += 15;
			break;
		case "hardcoverbook" :
			ar_bonus[9][0] += 3;
			ar_bonus[9][4] += 2;
			break;
		case "survivorsroddex" :
			ar_bonus[9][4] += 3;
			ar_bonus[9][12] += 400;
			break;
		case "survivorsrodint" :
			ar_bonus[9][3] += 3;
			ar_bonus[9][12] += 400;
			break;
		case "kamaitachi" :
			ar_bonus[9][10] += 30;
			ar_bonus[7][3] += 3;
			break;
		case "murasame" :
			if (enemyrace == 7) ar_bonus[9][10] += 100;
			break;
		case "butcher" :
			if (enemyrace == 2) ar_bonus[9][10] += 50;
			break;
//		case "fuumashurikenbeneki" :
//			ar_bonus[9][1] -= 1;
//			ar_bonus[9][4] -= 2;
			break;
		default :
			break;
	}

}	// 0: unique 1: +race 2: -race 3: +elem 4: -elem 5: +size 6: -size 7: atkdef 8: hpsp 9: stat 10: skill

function getBonusHat(in_hat, ar_bonus, ar_sta_bonus) {

	switch (in_hat[1]) {
		case "grandcirclet" :
			ar_sta_bonus[5]++;
		case "evilwing" :
		case "deviruchihat" :
			ar_sta_bonus[0]++;
			break;

		case "angelwing" :
			ar_sta_bonus[1]++;
		case "angelhelm" :
		case "gemmedcrown" :
		case "kitsunemask" :
			ar_sta_bonus[5]++;
			break;

		case "magicianhat" :
			ar_bonus[9][13] += 50;
		case "moneylosersgrief" :
			ar_sta_bonus[4]++;
			break;

		case "orcherohelm" :
			ar_sta_bonus[0] += 2;
			break;
		case "solargodhelm" :
			ar_sta_bonus[0] += 3;
			break;
		case "crownofmistress" :
			ar_bonus[9][13] += 100;
			break;
		case "magehat" :
			ar_bonus[9][13] += 150;
			break;
		default :
			break;
	}

}

var xupdate_share = 20050206;