function spellPT(name,lvl,line,ability,info,skill,power,range,cast,area,recast,duration,type) {
	this.name = name
	this.lvl = lvl
	this.line = line
	this.ability = ability
	this.info = info
	this.skill = skill
	this.power = power
	this.range = range
	this.cast = cast
	this.area = area
	this.recast = recast
	this.duration = duration
	this.type = type
}

function linePT(name,description,ability,current) {
	this.name = name
	this.description = description
	this.ability = ability
	this.current = current
}

function abilityPT(name,lvl,id,type,train,mastery,child,mo1,mo2) {
	this.name = name
	this.lvl = lvl
	this.id = id 
	this.type = type
	this.train = train
	this.mastery = mastery
	this.child = child
}

function stylePT(id,name,lvl,special,fat,dmg,abonus,dbonus,dpenalty,opening,current,specialdesc,mo1,mo2) {
	this.id=id
	this.name=name
	this.lvl=lvl
	this.special=special
	this.fat=fat
	this.dmg=dmg
	this.abonus=abonus
	this.dbonus=dbonus
	this.dpenalty=dpenalty
	this.opening=opening
	this.specialdesc=specialdesc
}
	
function getDOMObj(obj)
{
	return document.getElementById(obj);
}

function getIE4Obj(obj)
{
	return document.all[obj];
}
 
function getNS4Obj(obj)
{}

if(document.getElementById)	myGetObject = getDOMObj
else if(document.all) myGetObject = getIE4Obj
else if(document.layers) myGetObject = getNS4Obj

if (document.layers) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove=mtrack;
mousex = 0
mousey = 0

function mtrack(e) {
	if (document.layers){
		mousex = e.pageX
		mousey = e.pageY
	}
	else {
		// mousex = event.x
		// mousey = event.y
	}
}

function calcSkill(skill, checkLimits) {
	olevel = myGetObject("LEVEL") 
	oskill = myGetObject("SKILL" + skill)
	ocost = myGetObject("COST" + skill)
	ospent = myGetObject("SPENT" + skill)
	operc = myGetObject("PERC" + skill)
	
	skillCost = 0
		for (var i = 2; i <= oskill.value; i++) {
		if (skillCost + i > parseInt(myGetObject("LEFT").value) + parseInt(ospent.innerHTML)) break;
		if (i > olevel.value) break;
		skillCost += i
	}		
	
	change = skillCost - ospent.innerHTML;
	
	ospent.innerHTML=skillCost;
	oskill.value=i-1;
	ocost.innerHTML=i;
	
	myGetObject("SPENT").value = parseInt(myGetObject("SPENT").value) + change
	myGetObject("LEFT").value = myGetObject("LEFT").value - change
	
	for (i=1; i<Abilities.length; i++) {
		if (Abilities[i].type == 3 || (Abilities[i].type == 2 && Abilities[i].lvl == 5)) showSpell(Abilities[i]) 
		if (Abilities[i].type == 5 && Abilities[i].train == 1) showStyle(Abilities[i]) 
	}			
}	

function moLine(line,id) {
	if (id > 0) {
		l1Revert = myGetObject("LINENAME" + line).innerHTML;
		l2Revert = myGetObject("LINEDESC" + line).innerHTML;
		l3Revert = myGetObject("LINEEFFECT" + line).innerHTML;
		output = "";
		if (Spells[id].type != "") output += "<b style='color:000000'>" + Spells[id].type + " </b>"
		if (Spells[id].power != "") output += "<b style='color:000000'>COST</b>&nbsp;" + Spells[id].power + " "			
		if (Spells[id].range != "") output += "<b style='color:000000'>RANGE</b>&nbsp;" + Spells[id].range + " "	
		if (Spells[id].area != "") output += "<b style='color:000000'>AREA</b>&nbsp;" + Spells[id].area + " "	
		if (Spells[id].duration != "") output += "<b style='color:000000'>DURATION</b>&nbsp;" + Spells[id].duration + " "			
		if (Spells[id].cast != "") output += "<b style='color:000000'>CASTTIME</b>&nbsp;" + Spells[id].cast + " "	
		if (Spells[id].recast != "") output += "<b style='color:000000'>RECAST</b>&nbsp;" + Spells[id].recast + " "							
		myGetObject("LINENAME" + line).innerHTML = "<b style='color:000000'>" + Spells[id].name + "</b>";
		myGetObject("LINEEFFECT" + line).innerHTML = "<span style='color:red'>" + Spells[id].info + "&nbsp;</span>";	
		myGetObject("LINEDESC" + line).innerHTML = output;		
		return "green"
	} else {
		myGetObject("LINENAME" + line).innerHTML = l1Revert;
		myGetObject("LINEDESC" + line).innerHTML = l2Revert;
		myGetObject("LINEEFFECT" + line).innerHTML = l3Revert;
		return ""
	}
}

function showStyle(ability) {
	activeid=0; lvl = ability.lvl; iline=" ";
	l = parseInt(myGetObject("SKILL" + ability.id).value)
	for (x=1; x<Styles.length; x++) {
		if (Styles[x]) {
		if (Styles[x].id == ability.id) {
			if (Styles[x].lvl > l) iline += "<span style='cursor:crosshair;' onmouseout='this.style.color=moStyle(" + ability.id + ",-1)' onmouseover='this.style.color=moStyle(" + ability.id + "," + x + ")'>" + Styles[x].lvl + "</span> "
			else {
				activeid=x;
				iline += "<span style='color:red; cursor:crosshair;' onmouseout='this.style.color=moStyle(" + ability.id + ",-2);' onmouseover='this.style.color=moStyle(" + ability.id + "," + x + ")'>" + Styles[x].lvl + "</span> "
			}
		} 
		}	
	}
	if (activeid > 0) {
		output = "<table cellspacing=0 cellpadding=0><tr bgcolor=#ffffff><td width=100%><div class='MainText'>"
		if (Styles[activeid].opening != "") output+= " <b style='color:000000'>Opening&nbsp;:&nbsp;</b>" + Styles[activeid].opening + " ";					
		output += "<b style='color:000000'>Fatigue&nbsp;:&nbsp;</b>" + Styles[activeid].fat + " "; 
		if (Styles[activeid].dmg != "") output+= " <b style='color:000000'>Damage&nbsp;:&nbsp;</b>" + Styles[activeid].dmg + " ";
		if (Styles[activeid].abonus != "") output+= " <b style='color:000000'>Attack&nbsp;:&nbsp;</b>" + Styles[activeid].abonus + " ";
		if (Styles[activeid].dpenalty != "") output+= " <b style='color:000000'>Defense&nbsp;:&nbsp;</b>" + Styles[activeid].dpenalty + " ";
		if (Styles[activeid].dbonus != "") output+= " <b style='color:000000'>Defense&nbsp;:&nbsp;</b>" + Styles[activeid].dbonus + " ";		
		if (Styles[activeid].special != "") output+= " <b style='color:000000'>Special&nbsp;:&nbsp;</b>" + Styles[activeid].special + " ";	
		if (Styles[activeid].specialdesc != "")	output+= " <b style='color:000000'> - </b>" + Styles[activeid].specialdesc + " ";
		output += "</div></td></tr></table>"
		myGetObject("STYLENAME" + ability.id).innerHTML = "<b style='color:000000'>" + Styles[activeid].name + "</b>"		
		myGetObject("STYLEDESC" + ability.id).innerHTML = output;
	}
	myGetObject("STYLE" + ability.id).innerHTML = iline
}

function moStyle(abilityid,activeid) {
	if (activeid > 0) {
		s1Revert = myGetObject("STYLENAME" + abilityid).innerHTML;
		s2Revert = myGetObject("STYLEDESC" + abilityid).innerHTML;
		output = "<table cellspacing=0 cellpadding=0><tr bgcolor=#ffffff><td width=100%><div class='MainText'>"
		if (Styles[activeid].opening != "") output+= " <b style='color:000000'>Opening&nbsp;:&nbsp;</b>" + Styles[activeid].opening + " ";					
		output += "<b style='color:000000'>Fatigue&nbsp;:&nbsp;</b>" + Styles[activeid].fat + " "; 
		if (Styles[activeid].dmg != "") output+= " <b style='color:000000'>Damage&nbsp;:&nbsp;</b>" + Styles[activeid].dmg + " ";
		if (Styles[activeid].abonus != "") output+= " <b style='color:000000'>Attack&nbsp;:&nbsp;</b>" + Styles[activeid].abonus + " ";
		if (Styles[activeid].dpenalty != "") output+= " <b style='color:000000'>Defense&nbsp;:&nbsp;</b>" + Styles[activeid].dpenalty + " ";
		if (Styles[activeid].dbonus != "") output+= " <b style='color:000000'>Defense&nbsp;:&nbsp;</b>" + Styles[activeid].dbonus + " ";		
		if (Styles[activeid].special != "") output+= " <b style='color:000000'>Special&nbsp;:&nbsp;</b>" + Styles[activeid].special + " ";	
		if (Styles[activeid].specialdesc != "")	output+= " <b style='color:000000'> - </b>" + Styles[activeid].specialdesc + " ";
		output += "</div></td></tr></table>"
		myGetObject("STYLENAME" + abilityid).innerHTML = "<b style='color:000000'>" + Styles[activeid].name + "</b>"
		myGetObject("STYLEDESC" + abilityid).innerHTML = output;
		return "green";
	} else {
		myGetObject("STYLENAME" + abilityid).innerHTML = s1Revert;
		myGetObject("STYLEDESC" + abilityid).innerHTML = s2Revert;
		if (activeid == -2) { return "red" } else {return ""};
	}
}

function showSpell(ability) {
	lvl = ability.lvl; oline = 0;
	curlinelvl = 0;	activeid = 0;
	iline = " "; l = myGetObject("LEVEL").value;
	for (x=1; x<Spells.length; x++) {
		if (Spells[x].skill == ability.id) {
			if (oline > 0 && oline != Spells[x].line) {
				if (curlinelvl != Lines[Spells[x-1].line].current || l == 1) {
					//if (lvl > l) iline = "<font color='888888'>" + iline + "</font>";
					myGetObject("LINE" + oline).innerHTML = iline;
					if (activeid != 0) {
						myGetObject("LINED" + oline).innerHTML = '&nbsp;' + Spells[activeid].info + '&nbsp;';
					} else {
						myGetObject("LINED" + oline).innerHTML = '&nbsp;';							
					}			
					Lines[Spells[x-1].line].current=curlinelvl;
				}
				iline=" "; curlinelvl=0; activeid = 0;
			}
			if (ability.type == 2 && ability.train == 1) skilllvl = parseInt(myGetObject("SKILL" + ability.id).value) 
			else skilllvl = l;
			oline = Spells[x].line
			if (Spells[x].lvl > l || lvl > l) iline += "<font style='cursor:crosshair' onmouseout='this.style.color=moLine(" + oline + ",-1);' onmouseover='this.style.color=moLine(" + oline + "," + x + ")'>" + Spells[x].lvl + " </font>"
			else {  
				if (ability.type == 3 && parseInt(myGetObject("SKILL" + ability.mastery).value) < Spells[x].lvl) iline += "<font style='cursor:crosshair' onmouseout='moLine(" + oline + ",-1)' onmouseover='moLine(" + oline + "," + x + ")'>" + Spells[x].lvl + " </font>"
				else {
					if (ability.type == 2 && ability.child == 0 && skilllvl < Spells[x].lvl) iline += "<font style='cursor:crosshair' onmouseout='moLine(" + oline + ",-1)' onmouseover='moLine(" + oline + "," + x + ")'>" + Spells[x].lvl + " </font>"
					else {
						curlinelvl=Spells[x].lvl; activeid=x;
						iline += "<font style='cursor:crosshair' color=red onmouseout='this.style.color=moLine(" + oline + ",-1)' onmouseover='this.style.color=moLine(" + oline + "," + x + ")'>" + Spells[x].lvl + " </font>"
					}					
				}	
			}
		} else if (oline > 0) break ;
	}
	if (iline != " ") {
		if (curlinelvl != Lines[Spells[x-1].line].current || l == 1) {
			//if (lvl > l) iline = "<font color='888888'>" + iline + "</font>";
			myGetObject("LINE" + oline).innerHTML = iline;
			if (activeid != 0) {
				myGetObject("LINED" + oline).innerHTML = '&nbsp;' + Spells[activeid].info  + '&nbsp;';			
			} else {
				myGetObject("LINED" + oline).innerHTML = '&nbsp;';							
			}				
			Lines[Spells[x-1].line].current=curlinelvl;
		}	
	}
}

function calcSpec(lvl) {
	intLevel = Math.floor(lvl);
	lowLevel = lvl < 5 ? lvl : 5 
	specTotal = 0;

	for (i = 2; i <= lowLevel; i++) 
		specTotal += Math.floor(i * 1);			
	for (i = 6; i <= intLevel; i++) 
		specTotal += Math.floor(i * specMult);			
	for (i = 40.5; i <= lvl; i++)
		specTotal += Math.floor(Math.floor(i) / 2 * specMult);

	p = eval('s' + pStat)
	s = eval('s' + sStat)
	t = eval('s' + tStat)	
	
	if (parseInt(lvl) > 5) {
		p[998] = parseInt(lvl) - 5
		s[998] = Math.round((parseInt(lvl)-5)/2)
		t[998] = Math.round((parseInt(lvl)-4)/3)
	} else {
		p[998]=0;s[998]=0;t[998]=0;
	}
	sRace(raceID)
	
	myGetObject("SKILL").value = Math.round(specTotal)
	myGetObject("LEFT").value = Math.round(specTotal) - parseInt(myGetObject("SPENT").value) + parseInt(myGetObject("BONUS").value);
	
	for (i=1; i<Abilities.length; i++) {
		if (Abilities[i].train == 1) {
			if (parseInt(myGetObject("SKILL" + Abilities[i].id).value) > lvl){
				diff = parseInt(myGetObject("SKILL" + Abilities[i].id).value) - lvl;
				bSkill(Abilities[i].id,diff)
			}
		}
	

	}	 
}

function sdToggle(item,value) {
	for (x=1; x<Spells.length; x++) {
		if (myGetObject("ABILITY" + item + Spells[x].ability)) {
			oTemp = myGetObject("ABILITY" + item + Spells[x].ability);
			if (value) {
				oTemp.style.position='relative'; 
				oTemp.style.visibility='visible';
			} else {
				oTemp.style.position='absolute'; 
				oTemp.style.visibility='hidden';			
			}
		}
		if (myGetObject("LINE" + item + Spells[x].line)) {
			oTemp = myGetObject("LINE" + item + Spells[x].line);
			if (value) {
				oTemp.style.position='relative'; 
				oTemp.style.visibility='visible';
			} else {
				oTemp.style.position='absolute'; 
				oTemp.style.visibility='hidden';
			}			
		}
	}
}

function bLevel(inc) {
 	l = parseFloat(myGetObject("LEVEL").value);
	l = (l <= 40 ? l : 40 + (l - 40) * 2) + inc;
	if (l < 1) l=1; 
 	if (l > 60) l=60;
 	l = l <= 40 ? l : 40 + (l - 40) / 2;
 	myGetObject("LEVEL").value = l; 
	calcSpec(l); 
}	

function bBonus(inc) {
	myGetObject("BONUS").value = parseInt(myGetObject("BONUS").value) + inc
	calcSpec(myGetObject("LEVEL").value);
}

function bSkill(skill,inc) {
	o = "SKILL" + skill;
	skillObj = myGetObject(o);
		skillObj.value = parseInt(skillObj.value) + inc;
	if (skillObj.value < 2) skillObj.value=1;
	if (skillObj.value > 50) skillObj.value=50; 
	calcSkill(skill);
}	

function bAttribute(attr,inc){
	s = eval('s' + attr)
	shift = 0;
	if (inc == -1) shift = 1;
		if (s[999] < 10 + shift) cost = 1
	if (s[999] > 9 + shift && s[999] < 15 + shift) cost=2
	if (s[999] > 14 + shift) cost=3
	base = parseInt(myGetObject("BASE").value)
	if (s[999] + inc < 0) return
	 	if (base - cost * inc < 0) return 
	s[999] += inc
		myGetObject("BASE").value = base - cost * inc
	myGetObject(attr).value = s[999] + s[raceID] + s[998]  
	if (s[999] > 0) myGetObject(attr).style.color = "firebrick"
	if (s[999] == 0) myGetObject(attr).style.color = "black"
}		
	
function sRace(id) {
	raceID = id
	myGetObject("STR").value = sSTR[id]+sSTR[999]+sSTR[998];
	myGetObject("CON").value = sCON[id]+sCON[999]+sCON[998];
	myGetObject("DEX").value = sDEX[id]+sDEX[999]+sDEX[998];
	myGetObject("QUI").value = sQUI[id]+sQUI[999]+sQUI[998];
	myGetObject("INT").value = sINT[id]+sINT[999]+sINT[998];
	myGetObject("PIE").value = sPIE[id]+sPIE[999]+sPIE[998];
	myGetObject("EMP").value = sEMP[id]+sEMP[999]+sEMP[998];
	myGetObject("CHA").value = sCHA[id]+sCHA[999]+sCHA[998];													
}

function init() {
	for (i=1; i<Abilities.length; i++) {
		if (Abilities[i].mastery > 0) {
			for (x=1; x<Abilities.length; x++) {
				if (Abilities[i].mastery == Abilities[x].id) {
					Abilities[x].child = i;
				}
			}
		}
	}
}

var sSTR = new Array()
var sCON = new Array()
var sDEX = new Array()
var sQUI = new Array()
var sINT = new Array()
var sPIE = new Array()
var sEMP = new Array()
var sCHA = new Array()
var moRevert
var raceID 

