var races = ["Human", "half Elf", "Dwarf","Halfling","Elf","Gnome","half Orc"]
var profs = ["Barbarian", "Bard", "Cleric", "Druid", "Fighter", "Monk", "Paladin", "Ranger", "Rogue", "Sorcerer", "Wizard"];
var cacheSkills;
var cacheFeats;
var FirstTime = true;
var DICE_POOL_MIN = 68;
var LEVEL_CAP = 20;

var classExp = ["0", "1,000", "3,000", "6,000", "10,000",  "15,000", "21,000", "28,000", "36,000", "45,000", "55,000", "66,000", "78,000", "91,000", "105,000", "120,000", "136,000", "153,000", "171,000", "190,000"];

var bab = [1,.75,.75,.75,1,.75,1,1,.75,.5,.5];

featsLists = new Object();
featsLists.general = ["alertness","Ambidexterity","Armor (lt)","Armor (md)","Armor (hv)","Blind-fight","Combat casting","Combat reflexes","Dodge","Mobility","Spring attack","Endurance","Exotic Weapons Proficiency","Expertise","Improved Disarm","Improved trip","Whirlwind atack","Great fortitude","Improved critical","Improved initiative","Improved unarmed strike","Deflect arrows","Stunning fist","Iron will","Leadership","Lightning reflexes","Martial weapons proficiency","Mounted combat","Mounted archery","Trample","Ride-by attack","Spirited charge","Point blank shot","Far shot","Precise shot","Rapid shot","Shot on the run","Power attack","Cleave","Improved bull rush","Sunder","Great cleave","Quick draw","Run","Shield proficiency","Simple weapons proficiency","Skill focus","Spell focus","Spell penetration","Toughness","Track","Two weapon fighting","Improved two weapon Fighting","Weapon finesse","Weapon focus"];
featsLists.special = ["Extra turning","Spell mastery","Weapon specialization"];
featsLists.meta = ["Empower","Enlarge","Extend","Heighten","Maximize","Quicken","Silent","Still"];
featsLists.items = ["Brew Potion","Craft Magic Arms/Armor","Craft Rod","Craft Staff","Craft Wand","Craft Wonderous Item","Forge Ring","Scribe Scroll"];
featsLists.fighter =["Ambidexterity","Blind-fight","Combat Reflexes","Dodge","Mobility","Spring attack","Exotic weapon proficiency","Expertise","Improved disarm","Improved trip","Whirlwind attack","Improved critical","Improved initiative","Improved unarmed strike","Deflect arrows","Stunning fist","Mounted combat","Mounted archery","Trample","Ride-by attack","Spirited charge","Point blank shot","Far shot","Precise shot","Rapid shot","Shot on the run","Power attack","Cleave","Improved bull Rush","Sunder","Great cleave","Quick draw","Two weapon fighting","Improved two weapon fighting","Weapon finesse","Weapon focus","Weapon specialization"];
featsLists.wizard = ["Spell Mastery","Empower","Enlarge","Extend","Heighten","Maximize","Quicken","Silent","Still","Brew Potion","Craft Magic Arms/Armor","Craft Rod","Craft Staff","Craft Wand","Craft Wonderous Item","Forge Ring","Scribe Scroll"];
featsLists.idName = ["alertness","Ambidexterity","Armor (lt)","Armor (md)","Armor (hv)","Blind-fight","Combat casting","Combat reflexes","Dodge","Mobility","Spring attack","Endurance","Exotic Weapons Proficiency","Expertise","Improved Disarm","Improved trip","Whirlwind atack","Great fortitude","Improved critical","Improved initiative","Improved unarmed strike","Deflect arrows","Stunning fist","Iron will","Leadership","Lightning reflexes","Martial weapons proficiency","Mounted combat","Mounted archery","Trample","Ride-by attack","Spirited charge","Point blank shot","Far shot","Precise shot","Rapid shot","Shot on the run","Power attack","Cleave","Improved bull rush","Sunder","Great cleave","Quick draw","Run","Shield proficiency","Simple weapons proficiency","Skill focus","Spell focus","Spell penetration","Toughness","Track","Two weapon fighting","Improved two weapon Fighting","Weapon finesse","Weapon focus","Extra turning","Spell mastery","Weapon specialization","Empower","Enlarge","Extend","Heighten","Maximize","Quicken","Silent","Still","Brew Potion","Craft Magic Arms/Armor","Craft Rod","Craft Staff","Craft Wand","Craft Wonderous Item","Forge Ring","Scribe Scroll", "Toughness(+3hp)"];
featsLists.f = [1, 5, 8, 9 , 10, 13, 15,18,19,20,21,22,27,28,29,30,31,32,33,34,35,36,37,38,40,41,42,51,53,54,57];
featsLists.ID = new Array();
featsLists.gID = new Array();
featsLists.sID = new Array();
featsLists.mID = new Array();
featsLists.iID = new Array();
featsLists.wID = new Array();
featsLists.prof = new Array();
featsLists.prof[0] = [2, 3, 26, 44, 45];
featsLists.prof[1] = [2, 3, 44, 45];
featsLists.prof[2] = [2, 3, 4, 44, 45];
featsLists.prof[3] = [2, 3, 26, 44, 45];
featsLists.prof[4] = [2, 3, 4, 26, 44, 45];
featsLists.prof[5] = [12, 20, 22, 45];
featsLists.prof[6] = [2, 3, 4, 26, 44, 45];
featsLists.prof[7] = [1, 2, 3, 26, 44, 45, 50, 51];
featsLists.prof[8] = [2, 27, 44, 45];
featsLists.prof[9] = [45];
featsLists.prof[10] = [45];


for (var q = 0; q < featsLists.idName.length;q++)
{
	featsLists.ID[q] = q;
}

for (var q = 0; q < 55; q++)
{
	featsLists.gID[q] = featsLists.ID[q];
}
for (var q = 55; q < 58; q++)
{
	featsLists.sID[q-55] = featsLists.ID[q];
}
for (var q = 58; q < 64; q++)
{
	featsLists.mID[q-58] = featsLists.ID[q];
}
for (var q = 66; q < 74; q++)
{
	featsLists.iID[q-66] = featsLists.ID[q];
}
featsLists.w = [56, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73];



var hitDie = [12, 6, 8, 8, 10, 8, 10, 10, 6, 4, 4];


var skills = new Object();
skills.list = [
"alchemy",
"animal empathy",
"appraise",
"balance",
"bluff",
"climb",
"concentration",
"craft[*]",
"decipher script",
"diplomacy",
"disable device",
"disguise",
"escape artist",
"forgery",
"gather information",
"handle animal",
"heal",
"hide",
"innuendo",
"intimidate",
"intuit direction",
"jump",
"know(arcana)",
"know(religion)",
"know(nature)",
"know(other*)",
"listen",
"move silently",
"open lock",
"perform",
"pick pocket",
"profession[*]",
"read lips",
"ride",
"scry",
"search",
"sense motive",
"speak language",
"spellcraft",
"spot",
"swim",
"tumble",
"use magic device",
"use rope",
"wilderness lore"];


skills.bbn = [2,0,2,2,2,1,2,1,0,2,2,2,2,2,2,1,2,2,2,1,1,1,2,2,2,2,1,2,2,2,2,2,0,1,0,2,2,2,2,2,1,2,0,2,1];
skills.brd = [1,0,1,1,1,1,1,1,1,1,2,1,1,2,1,2,2,1,2,2,1,1,1,1,1,1,1,1,2,1,1,1,0,2,1,2,1,1,1,2,1,1,1,2,2];
skills.clr = [2,0,2,2,2,2,1,1,0,1,2,2,2,2,2,2,1,2,2,2,2,2,1,1,2,2,2,2,2,2,2,1,0,2,1,2,2,2,1,2,2,2,0,2,2];
skills.drd = [2,1,2,2,2,2,1,1,0,1,2,2,2,2,2,1,1,2,2,2,1,2,2,2,1,2,2,2,2,2,2,1,0,2,1,2,2,2,1,2,1,2,0,2,1];
skills.ftr = [2,0,2,2,2,1,2,1,0,2,2,2,2,2,2,1,2,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,0,1,0,2,2,2,2,2,1,2,0,2,2];
skills.mnk = [2,0,2,1,2,1,1,1,0,1,2,2,1,2,2,2,2,1,2,2,2,1,1,2,2,2,1,1,2,1,2,1,0,2,0,2,2,2,2,2,1,1,0,2,2];
skills.pal = [2,0,2,2,2,2,2,1,0,1,2,2,2,2,2,1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,2,1,0,1,0,2,2,2,2,2,2,2,0,2,2];
skills.rgr = [2,1,2,2,2,1,1,1,0,2,2,2,2,2,2,1,1,1,2,2,1,1,2,2,1,2,1,1,2,2,2,1,0,1,0,2,2,2,2,2,1,2,0,2,2];
skills.rog = [2,0,1,1,1,1,2,1,1,1,1,1,1,1,1,2,2,1,1,1,1,1,2,2,2,2,1,1,1,1,1,1,1,2,0,1,1,2,2,1,1,1,1,1,2];
skills.sor = [1,0,2,2,2,2,1,1,0,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,1,0,2,1,2,2,2,1,2,2,2,0,2,2];
skills.wiz = [1,0,2,2,2,2,1,1,0,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2,1,0,2,1,2,2,2,1,2,2,2,0,2,2];



var character = new Object();
character.p = new Array();
character.plevel = new Array();
character.name = "";
character.pcounter = 0;
character.level =0;
character.currentProf = "";
character.profSkills = [skills.bbn,skills.brd,skills.clr, skills.drd, skills.ftr, skills.mnk, skills.pal, skills.rgr, skills.rog, skills.sor, skills.wiz];
character.charSkills = new Array();
character.charSkillRanks = new Array();
character.skills = new Object();
character.skills.list = new Array();
character.charSkillsSubs = new Array();
character.charSkillsSubsRanks = new Array();
character.masterList = new Array();
character.listoffeats = new Array();
character.classSpecials = new Array();
character.hitpointsTotal = 0;
character.attributes = [0,0,0,0,0,0];
character.experienceTotal = 0;
character.spellsList = new Array();



var pSpec = new Object();
/* keeping this list for my sanity...
0: "Rage 1/day",
1: "Fast Movement",
2: "Keep Dex to AC when flat",
3: "Rage 2/day",
4: "Cant Be flanked",
5: "Rage 3/day",
6: "+1 Reflex save vs Traps",
7: "Damage reduction 1/-",
8: "Rage 4/day",
9: "+2 Reflex save vs Traps",
10: "Damage reduction 2/-",
11: "Greater Rage",
12: "Rage 5/day",
13: "+3 Reflex save vs Traps",
14: "Damage reduction 3/-",
15: "+4 Reflex save vs traps",
16: "Rage 6/day",
17: "Not winded from rage",
18: "Damage reduction 4/-",
19: "Bard Songs",
20: "Bardic Knowledge",
21: "Turn or Rebuke undead",
22: "Nature Sense",
23: "Animal Companion",
24: "Woodland Stride",
25: "Trackless Step",
26: "Resist Nature's Lure",
27: "Wild shape (1/day)",
28: "Wild shape (2/day)",
29: "Wild shape (3/day)",
30: "Wild shape (Large)",
31: "Venom Immunity",
32: "Wild shape (4/day)",
33: "Wild shape (Tiny)",
34: "Wild shape (Dire)",
35: "A thousand Faces",
36: "Wild shape (5/day)",
37: "Wild shape (Huge)",
38: "Timeless body",
39: "Wild shape (Elemental 1/day)",
40: "Wild shape (6/day)",
41: "Wild shape (Elemental 3/day)"
42: "Unarmed Strike", 
43: "Stunning Fist Feat",
44: "Evasion",
45: "Deflect Arrows Feat",
46: "Still Mind",
47: "Slow Fall: 20'",
48: "Purity of Body",
49: "Slow Fall: 30'",
50: "Improved Trip Feat",
51: "Wholeness of body",
52: "Leap of the clouds",
53: "Slow fall: 50'",
54: "Improved Evasion",
55: "Ki strike +1",
56: "Diamond body",
57: "Abundant step",
58: "Diamond soul",
59: "Ki strike +2",
60: "Quivering palm",
61: "Ki strike +3",
62: "Tongue of the sun and moon",
63: "Slow Fall: any distance",
64: "Empty body",
65: "Perfect self",
66: "Detect evil",
67: "Divine grace",
68: "Lay on hands",
69: "Divine Health",
70: "Aura of Courage",
71: "Smite Evil",
72: "Remove disease (1/week)",
73: "Special mount",
74: "Remove disease (2/week)",
75: "Remove disease (3/week)",
76: "Remove disease (4/week)",
77: "Remove disease (5/week)",
78: "Remove disease (6/week)",
79: "Track Feat",
80: "1st favored enemy", 
81: "2nd favored enemy", 
82: "3rd favored enemy", 
83: "4th favored enemy", 
84: "5th favored enemy",
85: "Sneak Attack +1d6",
86: "Sneak attack +2d6",
87: "Sneak Attack +3d6",
88: "Sneak attack +4d6",
89: "Sneak attack +5d6",
90: "Special ability",
91: "Sneak attack +6d6",
92: "Sneak attack +7d6",
93: "Sneak attack +8d6",
94: "Sneak attack +9d6",
95: "Sneak attack +10d6",
96: "Summon familiar",
97: "Scribe scroll feat"
*/
pSpec.list = ["Rage 1/day","Fast Movement","Dex bonus to armor class","Rage 2/day","Cant Be flanked","Rage 3/day","+1 Reflex save vs Traps","Damage reduction 1/-","Rage 4/day","+2 Reflex save vs Traps","Damage reduction 2/-","Greater Rage","Rage 5/day","+3 Reflex save vs Traps","Damage reduction 3/-","+4 Reflex save vs Traps","Rage 6/day","Not winded from rage","Damage reduction 4/-","Bard Songs","Bardic Knowledge","Turn undead","Nature Sense","Animal Companion","Woodland Stride","Trackless Step","Resist Nature's Lure","Wild shape (1/day)","Wild shape (2/day)","Wild shape (3/day)","Wild shape (Large)","Venom Immunity","Wild shape (4/day)","Wild shape (Tiny)","Wild shape (Dire)","A thousand Faces","Wild shape (5/day)","Wild shape (Huge)","Timeless body","Wild shape (Elemental 1/day)","Wild shape (6/day)","Wild shape (Elemental 3/day)","Unarmed Strike","Stunning Fist Feat","Evasion","Deflect Arrows Feat","Still Mind","Slow Fall: 20'","Purity of Body","Slow Fall: 30'","Improved Trip Feat","Wholeness of body","Leap of the clouds","Slow fall: 50'","Improved Evasion","Ki strike +1","Diamond body","Abundant step","Diamond soul","Ki strike +2","Quivering palm","Ki strike +3","Tongue of the sun and moon","Slow Fall: any distance","Empty body","Perfect self","Detect evil","Divine grace","Lay on hands","Divine Health","Aura of Courage","Smite Evil","Remove disease (1/week)","Special mount","Remove disease (2/week)","Remove disease (3/week)","Remove disease (4/week)","Remove disease (5/week)","Remove disease (6/week)","Track Feat","1st favored enemy", "2nd favored enemy", "3rd favored enemy", "4th favored enemy", "5th favored enemy","Sneak Attack +1d6","Sneak attack +2d6","Sneak Attack +3d6","Sneak attack +4d6","Sneak attack +5d6","Special ability","Sneak attack +6d6","Sneak attack +7d6","Sneak attack +8d6","Sneak attack +9d6","Sneak attack +10d6","Summon familiar","Scribe scroll feat"];
pSpec.abil = new Array();
pSpec.lvl = new Array();

//barbarian
pSpec.abil[0] = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18];
pSpec.lvl[0]  = [1,1,2,4,5,8,10,11,12,13,14,15,16,16,17,19,20,20,20];
//bard
pSpec.abil[1] = [19,20];
pSpec.lvl[1]  = [1,1];
//cleric
pSpec.abil[2] = [21];
pSpec.lvl[2]  = [1];
//druid
pSpec.abil[3] = [22,23,24,25,26,27,28,29,30,31,32,32,34,35,36,37,38,39,40,41];
pSpec.lvl[3]  = [1,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,15,16,18,18];
//fighter
pSpec.abil[4] =[""];
pSpec.lvl[4] =[0];
//monk
pSpec.abil[5] =[42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,37,60,61,62,63,64,65];
pSpec.lvl[5] = [ 1, 1, 1, 2, 3, 4, 5, 6, 6, 7, 7, 8, 9,10,11,12,13,13,15,16,17,17,18,19,20];
//paladin
pSpec.abil[6] =[66,67,68,69,70,71,72,21,73,74,75,76,77,78];
pSpec.lvl[6] =[1,1,1,1,2,2,3,3,5,6,9,12,15,18];
//ranger
pSpec.abil[7] =[79,80,81,82,83,84];
pSpec.lvl[7] =[1,1,5,10,15,20];
//rogue
pSpec.abil[8] =[85,44, 2, 86,87, 4, 88,89,90, 6,91,92,90, 9,93,90,13,94,90,95,15];
pSpec.lvl[8] =[  1, 2, 3,  3, 5, 6,  7, 9,10,11,11,13,13,14,15,16,17,17,19,19,20];
//sorceror
pSpec.abil[9] =[96];
pSpec.lvl[9] =[1];
//wizard
pSpec.abil[10] =[96,97];
pSpec.lvl[10] =[1,1];




var mods = new Array();
mods[0] =  0;
mods[1] = -5;
mods[2] = mods[3] = -4;
mods[4] = mods[5] = -3;
mods[6] = mods[7] = -2;
mods[8] = mods[9] = -1;
mods[10] = mods[11] = 0;
mods[12] = mods[13] = 1;
mods[14] = mods[15] = 2;
mods[16] = mods[17] = 3;
mods[18] = mods[19] = 4;
mods[20] = mods[21] = 5;
mods[22] = mods[23] = 6;
mods[24] = mods[25] = 7;
mods[26] = mods[27] = 8;
mods[28] = mods[29] = 9;
mods[30] = mods[31] = 10;

var baseSkills = [2,4,2,4,2,4,2,4,8,2,2];



var reflexSaves = [0,1,0,0,0,1,0,0,1,0,0];
var willSaves =   [0,1,1,1,0,1,0,0,0,1,1];
var fortSaves =   [1,0,1,1,1,1,1,1,0,0,0];

self.name = "CharacterGen";

function random() { 
  random.seed = (random.seed*random.a + random.c) % random.m; 

  return random.seed / random.m; 
}
random.m=714025; random.a=4096; random.c=150889; 
random.seed = (new Date()).getTime()%random.m;



var schools = ["Abjuration", "Conjuration", "Divination","Enchantment","Evocation","Illusion","Necromancy","Transmutation","Universal"];
var spells= new Object();
spells.Mage = new Array();
spells.mageSchool = new Array();
spells.Mage[0] = ["Resistance","Ray of Frost","Detect Poison","Daze","Flare","Light","Dancing Lights","Ghost Sound","Disrupt Undead","Mage Hand","Mending","Open/Close","Arcane Mark","Detect Magic","Prestidigitation","Read Magic"];
spells.mageSchool[0] = [0,1,2,3,4,4,5,5,6,7,7,7,8,8,8,8]
spells.Mage[1] = ["Alarm","Endure Elements","Hold Portal","Prot vs Chaos/Law/Good/Evil","Shield","Grease","Mage Armor","Mount","Obscuring Mist","Summon Monster I","Unseen Servant","Comprehend Languages","Detect Secret Doors","Detect Undead","Identify","True Strike","Charm Person","Hypnotism","Sleep","Magic Missile","Tenser's Floating Disk","Change Self","Color Spray","Nystul's Magic Aura","Nystul's Undetectable Aura","Silent Image","Ventriloquism","Cause Fear","Chill Touch","Ray of Enfeeblement","Animate Rope","Burning Hands","Enlarge","Erase","Expeditious Retreat","Feather Fall","Jump","Magic Weapon","Message","Reduce","Shock Grasp","Spider Climb"];
spells.mageSchool[1] = [0,0,0,0,0,1,1,1,1,1,1,2,2,2,2,2,3,3,3,4,4,5,5,5,5,5,5,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7];
spells.Mage[2] = ["Arcane Lock","Obscure Object","Prot vs Arrows","Resist Elements","Fog Cloud","Glitterdust","Melf's Acid Arrow","Summon Monster II","Summon Swarm","Web","Detect Thoughts","Locate Object","See Invisible","Tasha's Hideous Laughter","Darkness","Daylight","Flaming Sphere","Shatter","Blur","Continual Flame","Hypnotic Pattern","Invisibility","Leomund's Trap","Magic Mouth","Minor Image","Mirror Image","Misdirection","Ghoul Touch","Scare","Spectral Hand","Alter Self","Blindness/Deafness","Bull's Strength","Cat's Grace","Darkvision","Endurance","Knock","Levitate","Pyrotechnics","Rope Trick","Whispering Wind"];
spells.mageSchool[2] =[0,0,0,0,1,1,1,1,1,1,2,2,2,3,4,4,4,4,5,5,5,5,5,5,5,5,5,6,6,6,7,7,7,7,7,7,7,7,7,7,7];
spells.Mage[3] = ["Dispel Magic","Explosive Runes","Magic Circle vs Chaos/Law/Good/Evil","Nondetection","Prot vs Elements","Flame Arrow","Phantom Steed","Sepia Snake Sigil","Sleet Storm","Stinking Cloud","Summon Monster III","Clair Audience/Voyance","Tongues","Hold Person","Suggestion","Fireball","Gust of Wind","Leomund's Tiny Hut","Lightning Bolt","Wind Wall","Displacement","Illusory Script","Invisibilty Sphere","Major Image","Gentle Repose","Halt Undead","Vampiric Touch","Blink","Fly","Gaseous Form","Greater Magic Weapon","Haste","Keen Edge","Secret Page","Shrink Item","Slow","Water Breathing"];
spells.mageSchool[3] = [0,0,0,0,0,1,1,1,1,1,1,2,2,3,3,4,4,4,4,4,5,5,5,5,6,6,6,7,7,7,7,7,7,7,7,7,7];
spells.Mage[4] = ["Dimensional Anchor","Fire Trap","Minor Globe of Invulnerability","Remove Curse","Stoneskin","Evard's Black Tentacles","Leomund's Secure Shelter","Minor Creation","Solid Fog","Summon Monster IV","Arcane Eye","Detect Scrying","Locate Creature","Scrying","Charm Monster","Confusion","Emotion","Lesser Geas","Fire Shield","Ice Storm","Otiluke's Resilient Sphere","Shout","Wall of Fire","Wall of Ice","Hallucinatory Terrain","Illusory Wall","Improved Invisibility","Phantasmal Killer","Rainbow Pattern","Shadow Conjuration","Contagion","Enervation","Fear","Bestow Curse","Dimension Door","Polymorph Other","Polymorph Self","Rary's Mnemonic Enhancer"];
spells.mageSchool[4] = [0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,7,7,7,7,7];
spells.Mage[5] = ["Dismissal","Cloudkill","Leomund's Secret Chest","Lesser Planar Binding","Major Creation","Mordenkainen's Faithful Hound","Summon Monster V","Wall of Iron","Wall of Stone","Contact Other Plane","Prying Eyes","Rary's Telepathic Bond","Dominate Person","Feeblemind","Hold Monster","Mind Fog","Bigby's Interposing Hand","Cone of Cold","Sending","Wall of Force","Dream","False Vision","Greater Shadow Conjuration","Mirage Arcana","Nightmare","Persistant Image","Seeming","Shadow Evocation","Animate Dead","Magic Jar","Animal Growth", "Fabricate","Passwall","Stone Shape","Telekinesis","Teleport","Transmute Rock To Mud","Transmute Mud To Rock","Permanency"];
spells.mageSchool[5] = [0,1,1,1,1,1,1,1,1,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,5,5,5,5,6,6,7,7,7,7,7,7,7,7,8];
spells.Mage[6] = ["Antimagic Field","Globe of Invulnerability","Greater Dispelling","Guards and Wards","Repulsion","Acid Fog","Planar Binding","Summon Monster VI","Analyze Dweomer","Legend Lore","True Seeing","Geas/Quest","Mass Suggestion","Bigby's Forceful Hand","Chain Lightning","Contingency","Otiluke's Freezing Sphere","Greater Shadow Evocation","Mislead","Permanent Image","Programmed Image","Project Image","Shades","Veil","Circle of Death","Control Water","Control Weather","Disintegrate","Eyebite","Flesh to Stone","Mass Haste","Mordenkainen's Lucubration","Move Earth","Stone To Flesh","Tenser's Transformation"];
spells.mageSchool[6] = [0,0,0,0,0,1,1,1,2,2,2,3,3,4,4,4,4,5,5,5,5,5,5,5,6,7,7,7,7,7,7,7,7,7,7];
spells.Mage[7] = ["Banishment","Sequester","Spell Turning","Drawmij's Instant Summons","Mordenkainen's Magnificent Mansion","Phase Door","Power Word, Stun","Summon Monster VII","Greater Scrying","Vision","Insanity","Bigby's Grasping Hand","Delayed Blast Fireball","Forcecage","Mordenkainen's Sword","Prismatic Spray","Mass Invisibility","Shadow Walk","Simulacrum","Control Undead","Finger of Death","Ethereal Jaunt","Plane Shift","Reverse Gravity","Statue","Teleport Without Error","Vanish","Limited Wish"];
spells.mageSchool[7] = [0,0,0,1,1,1,1,1,2,2,3,4,4,4,4,4,5,5,5,6,6,7,7,7,7,7,7,8];
spells.Mage[8] = ["Mind Blank","Prismatic Wall","Protection vs Spells","Greater Planar Binding","Incendiary Cloud","Maze","Power Word, Blind","Summon Monster VIII","Trap The Soul","Discern Location","Antipathy","Binding","Demand","Mass Charm","Otto's Irresistable Dance","Sympathy","Bigby's Clenched Fist","Otiluke's Telekinetic Sphere","Sunburst","Screen","Clone","Horride Wilting","Etherealness","Iron Body","Polymorph Any Object","Symbol"];
spells.mageSchool[8] = [0,0,0,1,1,1,1,1,1,2,3,3,3,3,3,3,4,4,4,5,6,6,7,7,7,8];
spells.Mage[9] = ["Freedom","Imprisonment","Mordenkainen's Disjunction","Prismatic Sphere","Gate","Power Word, Kill","Summon Monster IX","Foresight","Dominate Monster","Bigby's Crushing Hand","Meteor Swarm","Weird","Astral Projection","Energy Drain","Soul Bind","Wail of The Banshee","Refuge","Shapechange","Teleportation Circle","Temporal Stasis","Time Stop ","Wish"];
spells.mageSchool[9] = [0,0,0,0,1,1,1,2,3,4,4,5,6,6,6,6,7,7,7,7,7,8];

var spellsByLevel=0;
var levelBreaks = [1,3,5,7,9,11,13,15,17];
var maxLevel = 1;
var totalLevels;
var levelName = ["", "first","second","third","fourth","fifth","sixth","seventh","eighth","ninth"];

var totalSpells = new Array();
for(var cnt=1;cnt < 10; cnt++)
{
	totalSpells[cnt] = 0;
}

var setTimer;
/**************************************************************************************
** End of global declarations // start of functions
** general functions/utilities: update, isDigit, initPage, doStep, doNext, toggleErrMsg,
** cleanFeatsList (not in use atm), 
***************************************************************************************/

function getClassName()
{
   if (navigator.appName == 'Microsoft Internet Explorer') return "className";
   else return "class";

}
function cleanFeatsList()
{
	var temp = new Array();
	temp = character.listoffeats;
	var b = temp.length;
	for(var i = 0; i < b;i++)
	{
		if(temp[i] == -1)
		{
			if(temp[i+1] != "")
			{
				temp[i] = temp[i+1];
				temp[i+1] = -1;
			}
			else
			{
				i = b;
			}
		}
	}
	temp.pop();
	temp.pop();
	character.listoffeats = temp;
}


function toggleErrMsg(msg)
{
	
	if(msg)
	{
		document.getElementById("errorMessage").innerHTML = msg;
		document.getElementById("errorMessage").style.visibility = "visible";
	}
	else
	{
		document.getElementById("errorMessage").innerHTML = "";
		document.getElementById("errorMessage").style.visibility = "hidden";
	}
}


function update()
{
	var d ="";
	
	var abilities = ["Str: ", "Dex: ", "Con: ", "Int: ", "Wis: ", "Cha: "];
	d += "Work Area Info:<br>";
	d += "data so far:<br>";
	if(character.name != "")
	{
		d+= "Name: <b>" + character.name + "</b><br/>"
	}
	d += "Race chosen: " + races[character.r] + "<br>Abilities Rolled: ("
	for (var i = 0; i < 6; i++)
	{
		d += abilities[i] + character.attributes[i] + " ";
	}
	d += ") hp: "+character.hitpointsTotal+"<br><br>class(es) chosen: ";
	
	for (var i = 0;i < character.pcounter; i++)
	{
		d+=profs[character.p[i]] +"(level " + character.plevel[i] +")"
		if(i < character.pcounter-1) d+=", ";
		else d+=".";
	}
	d += " character level " + character.level;
	
	d += "<br>Special class abilities: ";
	for(var i = (character.classSpecials.length-1);i >= 0;i--)
	{
		d+= "<i>"+ pSpec.list[character.classSpecials[i]] +"</i>; ";
	}
	d += "<br>Skills known: ";
	for (i = 0; i < character.charSkills.length;i++)
	{
		d+= skills.list[character.charSkills[i]] + "(<b>"+character.charSkillRanks[i]+"</b>)";
		if(i < character.charSkills.length-1) 
		{
			d+=", ";
		}
		else
		{
			d+= ".";		
		}

	}
	d += "<br>feats taken: "
	for (i = 0; i < character.listoffeats.length;i++)
	{
		d+=featsLists.idName[character.listoffeats[i]];
		if(i < character.listoffeats.length-1) 
		{
			d+=", ";
		}
		else
		{
			d+= ".";		
		}
	}
	
	document.getElementById("bottomSection").innerHTML = d;
}


function isDigit(c)
{
	for (var i = 0; i < 10; i++)
	{
		if (c == i) return true
	}
	return false
}

function initPage()
{
	document.getElementById("step2").disabled = true;
	document.getElementById("step3").disabled = true;
	document.getElementById("step4").disabled = true;
	document.getElementById("step5").disabled = true;
	document.getElementById("step6").disabled = true;
	document.getElementById("step7").disabled = true;
	document.getElementById("step8").disabled = true;
	
	document.getElementById("topSection").innerHTML = "<span style='font-family: arial;color: blue'>Welcome to D&DLeicht...yet another js ap that would have been better written in c++ or java. :) This is based solely on the core rules of D&D 3.0 if you are hoping for epic stuff (over level 20) or things not in the core rules forget about it. Basically its very simple. you follow each step 1 through 7 then you can choose to repeat steps 3 through 6 if you want to add more classes. Along the way you will recieve alerts and confirmation popups so enable popups if you need to. Not yet done: spells, calculated stats (saves etc), the character sheet. When this is done pressing the finish button will open a new window with a printable character sheet of the character you made.</span><br><br>Enjoy!<br>Paul Emerson Leicht, 10.05.2005<br>programmer and designer of D&DLeicht.";
	document.getElementById("bottomSection").innerHTML = "Workarea: info will go here as you make the character.";
}
function doStep(num)
{
	
	document.getElementById("step" + num).className = "menuItemClicked"
	document.getElementById("topSection").innerHTML = "";		
	switch(num)
	{
		case 1:
			getRace();
			break;
		case 2: 
			getAttributes();
			break;
		case 3:
			getProfession();
			break;
		case 4:
			getSkills();
			break;
		case 5: 
			getBonusFeats();
			break;
		case 6:
			getExtras();
			break;
		case 7:
			getCharData();
			break;
		case 8: 
			finishCharacter();
			break;
		default:
			break;
	}
}

function doNext(num)
{
	var n = num + 1;
	document.getElementById("step" + num).className = "menuItem"
	document.getElementById("step" + n).disabled = false;			
	document.getElementById("step" + num).disabled = true;			
}


/**************************************************************************************
** Races: doRace, getRace, 


***************************************************************************************/

function doRace()
{
	var g = document.getElementById("raceSelect").value;
	if (confirm("is " +races[g]+" Correct?"))
	{	
		character.r = g;
		document.getElementById("topSection").innerHTML +=  races[g]+" selected. <button id='next1' type='button' onClick='doNext(1);this.disabled=true;'>next step</button>";		
		document.getElementById("rselbut").disabled =true;
		update();
	}
}
function getRace()
{
	var d="";
	d += "<p>Please Select a race from the pulldown menu below:</p>";
	d += "<form id='aform'><select id='raceSelect' name='raceSelect' size=1>"
	for (var i = 0; i < races.length; i++)
	{
		d+="<option value='"+i+"'>"+races[i]+"</option><br>";
	}
	d += "</select><button id='rselbut' onClick='doRace()' type='button'>Pick A Race</button></form><br>";
	document.getElementById("topSection").innerHTML = d;
}

/**************************************************************************************
** Attributes: getAttributes, doAttributes, checkValue, getStats, keepStats, 
** addRaceStats,


***************************************************************************************/


function doAttributes()
{
	var die = new Array();
	var boolDice = true;
	var dietotal;
	var b = 0;
	while (boolDice)
	{
		dietotal=0;
		for (var i = 0; i < 6; i++)
		{
			die[i] = 0;
			for (var j = 0; j < 3; j++)
			{
				b = Math.ceil(random()*6);	
				die[i] +=b;
			}
			document.getElementById("att" + i).innerHTML = die[i];
			dietotal += die[i];
		}
		if(dietotal >= DICE_POOL_MIN) boolDice = false;
	}		
	
	if(confirm("Are these attributes acceptable?"))
	{
		character.attributes = die;
		document.getElementById("dicebut").disabled =true;
		document.getElementById("statsBut").disabled=true;
		document.getElementById("topSection").innerHTML +=  "Attributes accepted. <button id='next1' type='button' onClick='doNext(2);this.disabled=true;'>next step</button>";		
		update();
	}
	else 
	{
			document.getElementById("outerButton1").innerHTML = "<button type='button' id='statsBut' onClick='getStats()'>select</button>";
	}
	addRaceStats();
}

function getStats()
{
	var g = new Array();
	for(var i = 0;i< 6;i++)
	{
		g[i] = document.getElementById("att" + i).innerHTML;	
		document.getElementById("att" + i).innerHTML = "<input id='stat"+i+"' name='stat"+i+"' class='statEntry' type='text' size=3 maxlength='2' onChange='checkValue(this)'>";
	}
	document.getElementById("outerButton1").innerHTML = "<button type='button' id='statsBut' onClick='keepStats()'>Keep</button>";
}

function getAttributes()
{
	var d = "";
	d += "<span id='errMsg' style='visibility: hidden;color: #990000'></span><br><form name='form2'>";
	d += "<div>Please roll the&nbsp;&nbsp; <button id='dicebut' type='button' onClick='doAttributes();'>Dice</button> or <span id='outerButton1'><button type='button' id='statsBut' onClick='getStats()'>select</button></span> your stats.<br>Strength: <span id='att0'></span><br>Dexterity: <span id='att1'></span><br>Constitution: <span id='att2'></span><br>Intelligence: <span id='att3'></span><br>Wisdom: <span id='att4'></span><br>Charisma: <span id='att5'></span></div></form>";
	document.getElementById("topSection").innerHTML = d;
}

function checkValue(objElem)
{
	var v = objElem.value;
	document.getElementById("errMsg").style.visibility="hidden";
	if(!(isDigit(v.charAt(0))) || !(isDigit(v.charAt(1))))
	{
		objElem.value = "";
		document.getElementById("errMsg").innerHTML = "Please Enter values between 3 and 18";
		document.getElementById("errMsg").style.visibility = "visible";
	}
	else if (v > 18 || v < 3) 
	{
		objElem.value = "";
		document.getElementById("errMsg").innerHTML = "Please Enter values between 3 and 18";
		document.getElementById("errMsg").style.visibility = "visible";
	}
	
}


function keepStats()
{
	var v = new Array();
	document.getElementById("errMsg").style.visibility = "hidden";
	for (var i =0; i < 6; i++)//check for blanks
	{
		v[i] = document.getElementById("stat" + i).value;
		if ((v[i] == null) || (v[i] == "undefined") || (v[i] == " ")||(v[i]==""))
		{
			document.getElementById("errMsg").innerHTML = "Please enter a value between 3 and 18 for all stats.";
			document.getElementById("errMsg").style.visibility = "visible";
			return;
		}
	}
	
	if(confirm("Are these attributes acceptable?"))
	{
		character.attributes = v;
		update();
		document.getElementById("dicebut").disabled =true;
		document.getElementById("statsBut").disabled=true;
		document.getElementById("topSection").innerHTML +=  "Attributes accepted. <button id='next1' type='button' onClick='doNext(2);this.disabled=true;'>next step</button>";		
	}
	addRaceStats();
}

function addRaceStats()
{
	switch(character.r)
	{
	
	
		case '0'://humans (no changes)
			break;
		case '1'://half elves (no changes)
			break;
		case '2'://dwarves (+2 Con, -2 Cha)
			character.attributes[2] = Number(character.attributes[2]) + 2;
			character.attributes[5] = Number(character.attributes[5]) - 2;
			break;
		case '3'://halflings (+2 Dex, -2 Str)
			character.attributes[1] = Number(character.attributes[1]) + 2;
			character.attributes[0] = Number(character.attributes[0]) - 2;
			break;
		case '4'://elves (+2 Dex, -2 Con)
			character.attributes[1] = Number(character.attributes[1]) + 2;
			character.attributes[2] = Number(character.attributes[2]) - 2;
			break;
		case '5'://gnomes (+2 Con, -2 Str)
			character.attributes[2] = Number(character.attributes[2]) + 2;
			character.attributes[0] = Number(character.attributes[0]) - 2;
			break;
		case '6'://half orcs (+2 Str, -2 Int, -2 Cha)
			character.attributes[0] = Number(character.attributes[0]) + 2;
			character.attributes[3] = Number(character.attributes[3]) - 2;
			character.attributes[5] = Number(character.attributes[5]) - 2;
			break;
		default:
			break;	
	}
}
/**************************************************************************************
** Professional Classes: addProf, doProf, getProfession, generateCalcdStats


***************************************************************************************/
function generateCalcdStats()
{
	
	var high=0;
	var low=0;
	var save= new Array();
	var r=0,w=0,f=0;
	character.baseattackbonus = 0;
	
	for (var i=0; i < character.p.length; i++)
	{
		character.baseattackbonus += Math.floor(character.plevel[i] * bab[character.p[i]]);
		
		
		
		high = Math.floor(character.plevel[i]/2) + 2;
		low = Math.floor(character.plevel[i]/3);
		save[0] = low;
		save[1] = high;
		r += save[reflexSaves[character.p[i]]];
		f += save[fortSaves[character.p[i]]];
		w += save[willSaves[character.p[i]]];
	}
	if(character.r == 3)
	{
		r +=1;
		f+=1;
		w+=1;
	}
	r += mods[character.attributes[1]];
	f += mods[character.attributes[2]];
	w += mods[character.attributes[4]];
	if(r < 0) r= 0;
	if(f < 0) f= 0;
	if(w < 0) w= 0;
	
	character.ref=r;
	character.fort=f;
	character.will=w;
}
function addProf(num)
{
	var newpflag = true;
	for (var i = 0; i < character.pcounter; i++)
	{
		if (character.p[i] == num) //is this class one already chosen? if so add a level and clear the flag
		{
			character.plevel[i]++;
			newpflag = false;
		}
	}
	if (newpflag) 
	{
		character.p[character.pcounter] = num //otherwise add it and increment the number of professions by 1
		character.plevel[character.pcounter] = 1;
		character.pcounter++;
	}
	character.level++;
	update();
	generateCalcdStats();
}

function doProf()
{
	var p = document.getElementById("profSelect").value;
	if (confirm("Do you want to add a level of " +profs[p]+"?"))
	{	
		addProf(p);
		character.currentProf = p;
		
		document.getElementById("topSection").innerHTML +=  profs[p]+" selected. <button id='next1' type='button' onClick='doNext(3);this.disabled=true;'>next step</button>";		
		document.getElementById("pselbut").disabled =true;
	}
}

function getProfession()
{
	var d="";
	document.getElementById("step3").disabled = true;
	document.getElementById("step7").disabled = true;
	document.getElementById("step8").disabled = true;
	d += "<p>To add a new level please select a class</p>";
	d += "<form id='form3'><select id='profSelect' name='profSelect' size=1>"
	for (var i = 0; i < profs.length; i++)
	{
		d+="<option value='"+i+"'>"+profs[i]+"</option><br>";
	}
	d += "</select><button id='pselbut' onClick='doProf()' type='button'>Add a class</button></form><br>";
	document.getElementById("topSection").innerHTML = d;
	
}

/**************************************************************************************
** Skills: getSkills, doSkills, listSkills, checkForNewSkill, notOverLimit,


***************************************************************************************/
function notOverLimit(id)
{
	var maxRank = character.level + 3;
	var maxHalfRank = Math.floor(maxRank/2);
	var c = character.charSkills;
	for(var i = 0; i < c.length; i++)
	{
		if (c[i] == id)
		{
			if (character.profSkills[character.currentProf][id] == 1)
			{
				toggleErrMsg("skill: "+skills.list[c[i]]+" rank max:" + maxRank + " rank: "+ character.charSkillRanks[i]);
				if(maxRank <= character.charSkillRanks[i]) return false;
			}
			else
			{
				toggleErrMsg("skill: "+skills.list[c[i]]+" cross-class rank max:" + maxHalfRank + " rank: "+ character.charSkillRanks[i]);
				if(maxHalfRank <= character.charSkillRanks[i]) return false;
			}
		}
	}
	return true;
}

function checkForNewSkill(num)
{
	var c = character.charSkills;
	for(var i = 0;i < c.length;i++)
	{
		if (num == c[i]) return false;
	}
	return true;
}

function doSkill(num)
{
	var d = "";
	var l = "";
	toggleErrMsg();
	document.getElementById("topSection").innerHTML = cacheSkills
	if(character.skills.total >= character.profSkills[character.currentProf][num])
	{
		if (notOverLimit(num))
		{
			if (checkForNewSkill(num))
			{
				character.skills.total -= character.profSkills[character.currentProf][num];
				character.charSkillRanks[character.charSkills.length] = 1;
				character.charSkills[character.charSkills.length] = num;
			}
			else
			{
				character.skills.total -= character.profSkills[character.currentProf][num];
				for(var i = 0;i < character.charSkills.length;i++)
				{
					if (num == character.charSkills[i])
					{
						character.charSkillRanks[i]++;
					}
				}
			}
		}
		else
		{
			toggleErrMsg("You've already reached your maximum rank for " + skills.list[num] + "!");
		}
	}
	else
	{
		toggleErrMsg("You dont have enough skill points left to buy a rank in "+skills.list[num]);
	}
	d +="<div class='skillList'><b>Skills Known:";
	
	for(var i = 0; i < character.charSkills.length;i++)
	{
		d+= skills.list[character.charSkills[i]] + "(<b>"+character.charSkillRanks[i]+"</b>), ";
	}
	d+="</div>";
	document.getElementById("topSection").innerHTML = cacheSkills + d;
	document.getElementById("cp").innerHTML = character.skills.total;
	if(character.skills.total == 0)	
	{
		update();
		toggleErrMsg();
		document.getElementById("topSection").innerHTML =  "Skills Completed! <button id='next1' type='button' onClick='doNext(4);this.disabled=true;'>next step</button>";
	}
}

function listSkills()
{
	var d="";
	var j;
	
	d += "You have <span id='cp'>"+character.skills.total+"</span> skill points remaining. <span class='span0'>Skill is not available</span>&nbsp<span class='span1'>Skill is class skill</span>&nbsp<span class='span2'>Skill is cross class (costs 2)</span><br>";
	d += "<form id='form4'><table cellpadding='0' cellspacing='0' border='0' class='sList'><tr>"
	d +="<td class='skillcontainer1' valign='top'><div class='insideSkill'>";
	for (var i = 0; i < 12; i++)
	{
		if(character.profSkills[character.currentProf][i] == 0)
		{
			d+="<span id='sk"+i+"' class='span"+character.profSkills[character.currentProf][i]+"'>"+skills.list[i]+"</span><br>";
		}
		else
		{
			d+="<span onmouseover=\"this.style.backgroundColor='#999999'\" onmouseout=\"this.style.backgroundColor=''\" id='sk"+i+"' class='span"+character.profSkills[character.currentProf][i]+"' onClick=\"doSkill("+i+")\">"+skills.list[i]+"</span><br>";
		}
	}
	j = i;
	d +="</div></td><td class='skillcontainer2' valign='top'><div class='insideSkill'>";
	for (var i = j; i <j + 12; i++)
	{
		if(character.profSkills[character.currentProf][i] == 0)
		{
			d+="<span id='sk"+i+"' class='span"+character.profSkills[character.currentProf][i]+"' >"+skills.list[i]+"</span><br>";
		}
		else
		{
			d+="<span onmouseover=\"this.style.backgroundColor='#999999'\" onmouseout=\"this.style.backgroundColor=''\" id='sk"+i+"' class='span"+character.profSkills[character.currentProf][i]+"' onClick=\"doSkill("+i+")\">"+skills.list[i]+"</span><br>";
		}
	}
	j = i;
	d +="</div></td><td class='skillcontainer3' valign='top'><div class='insideSkill'>";
	for (var i = j; i <j + 12; i++)
	{
		if(character.profSkills[character.currentProf][i] == 0)
		{
			d+="<span id='sk"+i+"' class='span"+character.profSkills[character.currentProf][i]+"'>"+skills.list[i]+"</span><br>";
		}
		else
		{
			d+="<span onmouseover=\"this.style.backgroundColor='#999999'\" onmouseout=\"this.style.backgroundColor=''\" id='sk"+i+"' class='span"+character.profSkills[character.currentProf][i]+"' onClick=\"doSkill("+i+")\">"+skills.list[i]+"</span><br>";
		}
	}
	j = i;
	d +="</div></td><td class='skillcontainer4' valign='top'><div class='insideSkill'>";
	for (var i = j; i <skills.list.length; i++)
	{
		if(character.profSkills[character.currentProf][i] == 0)
		{
			d+="<span id='sk"+i+"' class='span"+character.profSkills[character.currentProf][i]+"'>"+skills.list[i]+"</span><br>";
		}
		else
		{
			d+="<span onmouseover=\"this.style.backgroundColor='#999999'\" onmouseout=\"this.style.backgroundColor=''\" id='sk"+i+"' class='span"+character.profSkills[character.currentProf][i]+"' onClick=\"doSkill("+i+")\">"+skills.list[i]+"</span><br>";
		}
	}
	d+"</div></td>";
	d += "</tr></table></form><br>";
	document.getElementById("topSection").innerHTML = d;
	cacheSkills = document.getElementById("topSection").innerHTML;
}


function getSkills()
{
	var sm = 1;
	var bonus = 0;
	update();
	document.getElementById("step4").disabled=true;
	character.skills.total = 0;
	if (character.level == 1)//is this the first character level?
	{
		sm=4;
		if (character.r == 0) //is human? add the bonus
		{
			bonus = 4;
		}
	}
	else
	{
		if (character.r == 0) //is human? add the bonus
		{
			bonus = 1;
		}
	}
	character.skills.total = ((baseSkills[character.currentProf] + mods[character.attributes[3]]));
	if (character.skills.total < 1) character.skills.total = 1;
	character.skills.total = character.skills.total * sm + bonus;
	listSkills();
}
/**************************************************************************************
** Feats: getFeats, listFeats, concatFeats, getMasterList, doFeat, preRequisite, 
** checkForFeat, checkForSkill, checkForClass, isFirstLevelFighter, doFighterBonusFeats,
** getProfFeats
***************************************************************************************/

function getProfFeats()
{
	var list = new Array();
	
	currentList = new Array();
	cL = new Array();
	
	list = character.listoffeats;
	
	for (var k = 0; k < featsLists.prof[character.currentProf].length;k++)
	{
		currentList[k] = true;
		cL[k] = featsLists.prof[character.currentProf][k];
	}

	if(list[0])
	{
		for (var i = 0; i < list.length; i++)
		{
			for(var j = 0;j < featsLists.prof[character.currentProf].length;j++)
			{
				if(list[i] == featsLists.prof[character.currentProf][j])
				{
					currentList[j] = false;
				}
			}
		}
		for (j = 0; j < currentList.length;j++)
		{
			if(currentList[j])
			{
				list[list.length] = cL[j];
			}
		}
	}
	else
	{
		list = featsLists.prof[character.currentProf];
	}
	return list;
}

function doBonusFeat(feat)
{
	var d;
	character.listoffeats[character.listoffeats.length] = feat;
	d = "Feats Selected: "
	for(var i =0; i < character.listoffeats.length;i++)
	{
		d+= featsLists.idName[character.listoffeats[i]];
	    if (i < character.listoffeats.length-1) d+=", ";
	    else d+="."
	}
	document.getElementById("topSection").innerHTML = d;
	update();
	getFeats();
}
function doWizardBonusFeats()
{
	getBonusFeatsList(featsLists.w);
}

function doFighterBonusFeats()
{
	getBonusFeatsList(featsLists.f);
}
function getBonusFeatsList(list)
{
	var masterList = new Array();
	masterList = list;
	d = "<table class='featList' cellpadding='0' cellspacing='0'><tr>";
	for (var j=0; j < masterList.length; j++)
	{
		if (j % 15 == 0) 
		{
			if (j != 0)
			{
				d+="</td>";
			}
			d += "<td class='featContainer'valign='top'>";
		}
		if(preRequisite(masterList[j])) 
		{
			
			if(!checkForFeat(masterList[j]))
			{
				d += "<span onClick=\"doBonusFeat("+masterList[j]+")\" class='fspan' onmouseover=\"this.style.backgroundColor='#FFFFFF'\" onmouseout=\"this.style.backgroundColor=''\">"+featsLists.idName[masterList[j]]+"</span><br>";
			}
			else
			{
				d+="<span class='fspanDone'>"+featsLists.idName[masterList[j]]+"</span><br>";
			}
		}
		else d+="<span class='fspanOff'>"+featsLists.idName[masterList[j]]+"</span><br>";
	}
	d += "</td></tr></table>";
	document.getElementById("topSection").innerHTML = d;
}

function getBonusFeats()
{
	for(var i = 0; i < character.p.length;i++)
	{
		if((character.currentProf == 4)&&(character.p[i] == 4)) 
		{
			if ((character.plevel[i] == 1) || (character.plevel[i]%2 == 0))
			{
				doFighterBonusFeats();
				return;
			}
		}
		if(character.currentProf == 10 && character.p[i] == 10)
		{
			if ((character.plevel[i]%5 == 0) && (character.plevel[i] > 1))
			{
				doWizardBonusFeats();
				return;
			}
		}
	}
	getFeats();
}

function checkForFeat(id)
{
	for (var i = 0; i < character.listoffeats.length; i++)
	{
		if(character.listoffeats[i] == id) return true;
	}
}
function checkForSkill(id)
{
	for (var i = 0; i < character.charSkills.length; i++)
	{
		if (character.charSkills[i] == id) return true;
	}
}
function checkForClass(prof, level)
{
	for (var i = 0; i < character.p.length;i++)
	{
		if (character.p[i] == prof)
		{
			if (character.plevel[i] > (level - 1)) return true;
		}
		
	}
}
function preRequisite(id)
{
	
	switch(id)// the insanely long switch statement :(
	{
		case 1: //ambidexterity requires dex 15+
			if (character.attributes[1] > 14) return true;
			break
		case 3: //armor proficiency medium requires armor proficiency light
			if(checkForFeat(2)) return true;
			break;
		case 4:// armor proficiency heavy requires armor proficiency medium
			if(checkForFeat(3)) return true;
			break;
		case 8: // dodge requires dex 13+
			if (character.attributes[1] > 12 )return true;
			break;
		case 9:// mobility requires dodge
			if(checkForFeat(8)) return true;
			break;
		case 10://spring attack requires mobility
			if(checkForFeat(9) && character.baseattackbonus > 3) return true;
			break;			
		case 12:// exotic weapon proficiency requires 1+ base attack bonus
			if (character.baseattackbonus > 0) return true;
			break;						
		case 13://expertise requires int 13+
			if(character.attributes[3] > 12) return true;
			break;						
		case 14://improved disarm requires expertise
			if(checkForFeat(13)) return true;
			break;						
		case 15://improved trip requires expertise
			if(checkForFeat(13)) return true;
			break;						
		case 16: // whirlwind attack requires expertise and spring attack
			if(checkForFeat(13) && checkForFeat(10)) return true;
			break;
		case 18: //improved critical requires weapon knowledge(not checked) and character.baseattackbonus 8+
			if (character.baseattackbonus > 7) return true; 
			break;
		case 21: //deflect arrows requires improved unarmed strike
			if(checkForFeat(20)) return true;
			break;
		case 22: //stunning fist requires improved unarmed strike
			if(checkForFeat(20)) return true;
			break;		
		case 24: //leadership requires level 6+ character
			if (character.level > 5) return true;
			break;
		case 27://mounted combat requires Ride Skill
			if(checkForSkill(33)) return true;
			break;
		case 28: //mounted archery requires mounted combat
			if(checkForFeat(27)) return true;
			break;
		case 29: //trample requires mounted combat
			if(checkForFeat(27)) return true;
			break;
		case 30: //ride-by attack requires mounted combat
			if(checkForFeat(27)) return true;
			break;
		case 31: //spirited charge requires ride-by attack
			if(checkForFeat(30)) return true;
			break;
		case 33: //Far Shot requires point blank shot
			if(checkForFeat(32)) return true;
			break;
		case 34: //precise shot requires point blank shot
			if(checkForFeat(32))
			break;
		case 35: //rapid shot requires Dex 13+ and point blank shot
			if(character.attributes[1] > 12 && checkForFeat(32)) return true;
			break;
		case 36: //shot on the run requires Dex 13+, mobility and point blank shot
			if(character.attributes[1] > 12 && checkForFeat(9) && checkForFeat(32)) return true;
			break;
		case 37: //power attack requires Str 13+
			if(character.attributes[0] > 12) return true;
			break;
		case 38://cleave requires power attack
			if(checkForFeat(37)) return true;
			break;
		case 39://improved bull rush requires power attack
			if(checkForFeat(37)) return true;
			break;
		case 40: //sunder requires power attack
			if(checkForFeat(37)) return true;
			break;
		case 41: //great cleave requires cleave and character.baseattackbonus 4+
			if(checkForFeat(38) && character.baseattackbonus > 3) return true;
			break;
		case 42: //quick draw requires base attack bonus 1+
			if(character.baseattackbonus > 0) return true;
			break;
		case 52: //improved two weapon fighting requires two weapon fighting, ambidexterity and character.baseattackbonus 9+
			if (checkForFeat(51) && checkForFeat(1) && character.baseattackbonus > 8)return true;
			break;
		case 53: //weapon finesse requires weapon proficiency and character.baseattackbonus 1+
			if (character.baseattackbonus > 0) return true;
			break;
		case 54: //weapon focus requires weapon proficiency and character.baseattackbonus 1+
			if (character.baseattackbonus > 0) return true;
			break;
		case 57: //weapon specialization requires fighter level 4+
			if (checkForClass(4,4)) return true;
			break;			
		case 66: //brew potion requires a spell caster class level 3+
			if(checkForClass(1,3) || checkForClass(2,3) || checkForClass(3,3) || checkForClass(9,3) || checkForClass(10,3)) return true;
			break;
		case 67: //craft magic arms & armor requires a spell caster class level 5+
			if(checkForClass(1,5) || checkForClass(2,5) || checkForClass(3,5) || checkForClass(9,5) || checkForClass(10,5)) return true;
			break;
		case 68: //craft rod requires a spell caster class level 9+
			if(checkForClass(1,9) || checkForClass(2,9) || checkForClass(3,9) || checkForClass(9,9) || checkForClass(10,9)) return true;
			break;
		case 69: //craft staff requires a spell caster class level 12+
			if(checkForClass(1,12) || checkForClass(2,12) || checkForClass(3,12) || checkForClass(9,12) || checkForClass(10,12)) return true;
			break;
		case 70: //craft wand requires a spell caster class level 5+
			if(checkForClass(1,5) || checkForClass(2,5) || checkForClass(3,5) || checkForClass(9,5) || checkForClass(10,5)) return true;
			break;
		case 71: //craft wonderous item requires a spell caster class level 3+
			if(checkForClass(1,3) || checkForClass(2,3) || checkForClass(3,3) || checkForClass(9,3) || checkForClass(10,3)) return true;
			break;
		case 72: //forge ring requires a spell caster class level 12+
			if(checkForClass(1,12) || checkForClass(2,12) || checkForClass(3,12) || checkForClass(9,12) || checkForClass(10,12)) return true;
			break;
		case 73: //scribe scroll requires a spell caster class level 12+
			if(checkForClass(1,1) || checkForClass(2,1) || checkForClass(3,1) || checkForClass(9,1) || checkForClass(10,1)) return true;
			break;
		default:
			return true;
	}
	return false;
}

function doFeat(id)
{
	document.getElementById("topSection").innerHTML = cacheFeats;
	if(character.featsCount > 0)
	{
		var d;
		character.listoffeats[character.listoffeats.length] = id;
		character.featsCount--;
		d = "Feats Selected: "
		for(var i =0; i < character.listoffeats.length;i++)
		{
		    if (i > 0) d+=", ";
			d+= featsLists.idName[character.listoffeats[i]];
		}
		if (character.featsCount == 0) 
		{
			update("<br>"+d);
			d += "<button id='next1' type='button' onClick='doNext(5);this.disabled=true;'>next step</button>"
			document.getElementById("topSection").innerHTML = d;
			
			return;
		}
		else 
		{
			document.getElementById("topSection").innerHTML = "You have <span id='featnum'>"+character.featsCount+"</span> feats remaining to choose:";
			listFeats();
			document.getElementById("topSection").innerHTML += d;
		}
	}

}

function concatFeats(list1, list2)
{
	var k, l, j=0, i=0;
	var list = new Array();
	list = list1;
	l = list.length;
	k = l + list2.length;
	for(i = l; i < k; i++)
	{
		list[i] = list2[j];
		j++
	}
	return list;
}
function getMasterList()
{
	var masterList = new Object();
	
	if (character.currentProf == 10)
	{
		masterList = concatFeats(featsLists.gID, featsLists.w);
	}
	else if (character.currentProf== 9 || (character.currentProf >= 1 && character.currentProf <= 3))
	{
		masterList = concatFeats(featsLists.gID,featsLists.iID);
		masterList = concatFeats(masterList,featsLists.mID);
		if(character.currentProf== 2)
		{
			masterList[masterList.length] = featsLists.sID[0];
		}
	}
	else if(character.currentProf == 4)
	{
		masterList = featsLists.gID.concat(featsLists.sID[2]);
	}
	else 
	{
		masterList = featsLists.gID;
	}
	character.masterList = masterList;
	//character.listoffeats = concatFeats(character.listoffeats, featsLists.prof[character.currentProf]);
	return masterList;
	
}

function listFeats()
{
	
	var d;
	var i;
	var masterList;
	
	if (FirstTime)
	{
		masterList = getMasterList();
		FirstTime = false;
	}
	else 
	{
		masterList = character.masterList;
	}
	
	d = "<table class='featList' cellpadding='0' cellspacing='0'><tr>";
	for (var j=0; j < masterList.length; j++)
	{
		if (j % 15 == 0) 
		{
			if (j != 0)
			{
				d+="</td>";
			}
			d += "<td class='featContainer'valign='top'>";
		}
		if(preRequisite(masterList[j])) 
		{
			if(!checkForFeat(masterList[j]))
			{
				d += "<span onClick=\"doFeat("+masterList[j]+")\" class='fspan' onmouseover=\"this.style.backgroundColor='#FFFFFF'\" onmouseout=\"this.style.backgroundColor=''\">"+featsLists.idName[masterList[j]]+"</span><br>";
			}
			else
			{
				d+="<span class='fspanDone'>"+featsLists.idName[masterList[j]]+"</span><br>";
			}
		}
		else d+="<span class='fspanOff'>"+featsLists.idName[masterList[j]]+"</span><br>";
	}
	d += "</td></tr></table>";
	document.getElementById("topSection").innerHTML += d;
	cacheFeats = document.getElementById("topSection").innerHTML;
}

function getFeats()
{
	var d ="";
	
	document.getElementById("step5").disabled = true;
	character.featsCount =0;
	
	//is human at first level? yes feats+1
	if (character.r == 0 && character.level == 1)
	{
		character.featsCount++;
	}
	//is 1st level? yes feats +1
	if (character.level == 1)
	{
		character.featsCount++;
	}
	//is character level%3 0? feats +1
	if ((character.level%3) == 0)
	{
		character.featsCount++;
	}
	
	character.listoffeats = getProfFeats();
	update();
	if (character.featsCount > 0)
	{
		d += "You have <span id='featnum'>"+character.featsCount+"</span> feats remaining to choose:";
		document.getElementById("topSection").innerHTML = d;
		listFeats();
	}
	else
	{
		d += "You have no feats to choose.<br>";
		document.getElementById("topSection").innerHTML = d + "Feats Completed! <button id='next1' type='button' onClick='doNext(5);this.disabled=true;'>next step</button>";
	}
}

/**************************************************************************************
** Extras: getExtras, doBonusAttribute,doHitPointsTotal, getClassSpecials, confirmBonus, 
** doSpecials,removeRedundantSpecials

***************************************************************************************/
function removeIt(arTemp, id)
{
	var it = arTemp;
	var temp;
	for(var j = 0;j < it.length;j++)
	{
		if (arTemp[id] == it[j])		
		{
			if((j+1) < it.length)
			{
				temp = it[j];
				it[j] = it[j+1];
				it[j + 1] = temp;
				
			}
			else
			{
				j = it.length;
			}
		}
	}
	it.pop();
	return it;
	
}

function checkForLesser(num)
{
	switch(num)
	{
		case 95://sneak attack +10d6
			checkForLesser(94); 
			removeIt(character.classSpecials, 94);
			break;
		case 94://sneak attack +9d6
			checkForLesser(93);
			removeIt(character.classSpecials, 93);
			break;
		case 93://sneak attack +8d6
			checkForLesser(92);
			removeIt(character.classSpecials, 92);
			break;
		case 92://sneak attack +7d6
			checkForLesser(91);
			removeIt(character.classSpecials, 91);
			break;
		case 91://sneak attack +6d6
			checkForLesser(89);
			removeIt(character.classSpecials, 89);
			break;
		case 89://sneak attack +5d6
			checkForLesser(88);
			removeIt(character.classSpecials, 88);
			break;
		case 88://sneak attack +4d6
			checkForLesser(87);
			removeIt(character.classSpecials, 87);
			break;
		case 87://sneak attack +3d6
			checkForLesser(86);
			removeIt(character.classSpecials, 86);
			break;
		case 86://sneak attack +2d6
			removeIt(character.classSpecials, 85);
			break;

		case 84: //5 enemies
			checkForLesser(83);
			removeIt(character.classSpecials, 83);
			break;
		case 83: //4 enemies
			checkForLesser(82);
			removeIt(character.classSpecials, 82);
			break;
		case 82: //3 enemies
			checkForLesser(81);
			removeIt(character.classSpecials, 81);
			break;			
		case 81: //2 enemies
			removeIt(character.classSpecials, 80);
			break;
		case 78: //remove disease 6 * per week
			checkForLesser(77);
			removeIt(character.classSpecials, 77);
			break;
		case 77: //remove disease 5 * per week
			checkForLesser(76);
			removeIt(character.classSpecials, 76);
			break;
		case 76: //remove disease 4 * per week
			checkForLesser(75);
			removeIt(character.classSpecials, 75);
			break;
		case 75: //remove disease 3 * per week
			checkForLesser(74);
			removeIt(character.classSpecials, 74);
			break;
		case 74: //remove disease 2 * per week
			removeIt(character.classSpecials, 72);
			break;
		case 63: //slowfall any
			checkForLesser(53);
			removeIt(character.classSpecials, 53);
			break;
		case 61: //ki strike +3
			checkForLesser(59);
			removeIt(character.classSpecials, 59);
			break;
		case 59: //ki strike +2
			removeIt(character.classSpecials, 55);
			break;
		case 53: //slowfall 50 feet
			checkForLesser(49);
			removeIt(character.classSpecials, 49);
			break;
		case 49: //slowfall 30 feet
			removeIt(character.classSpecials, 47);
			break;
		case 41: //wildshape: elem *3/day
			removeIt(character.classSpecials, 39);
			break;
		case 36: //wildshape: 5*/day
			checkForLesser(32);
			removeIt(character.classSpecials, 32);
			break;
		case 32: //wildshape 4*/day
			checkForLesser(29);
			removeIt(character.classSpecials, 29);
			break;
		case 29: //wildshape 3*/day
			checkForLesser(28);
			removeIt(character.classSpecials, 28);
			break;
		case 28: //wildshape 2*/day
			removeIt(character.classSpecials, 27)
			break;
		case 18: //damage reduction 4/-
			checkForLesser(14);
			removeIt(character.classSpecials, 14);
			break;
		case 16: //rage 6*/day
			checkForLesser(12);
			removeIt(character.classSpecials, 12);
			break;
		case 15: //+4 to reflex save vs traps
			checkForLesser(13);
			removeIt(character.classSpecials, 13);
			break;
			
		case 14: //damage reduction 3/-
			checkForLesser(10);
			removeIt(character.classSpecials, 10);
			break;
		case 13: //+3 to reflex save vs traps
			checkForLesser(9);
			removeIt(character.classSpecials, 9);
			break;			
		case 12: //rage 5*/day
			checkForLesser(8);
			removeIt(character.classSpecials, 8);
			break;			
		case 10: //damage reduction 2/-
			removeIt(character.classSpecials, 7);
			break;
		case 9: //+2 to reflex save vs traps
			removeIt(character.classSpecials, 6);
			break;			
		case 8: //rage 4*/day
			checkForLesser(5);
			removeIt(character.classSpecials, 5);
			break;				
		case 5: //rage 3*/day
			checkForLesser(3);
			removeIt(character.classSpecials, 3);
			break;		
		case 3: //rage 2*/day
			removeIt(character.classSpecials, 0);
			//alert("!!")
			break;		
		default:
			////alert(num + " is being worked on");
			break;
	}
}
function removeLesserSpecials()
{
	for(var i = (pSpec.list.length-1);i >= 0;i--)
	{
		for(var j = 0; j < character.classSpecials.length;j++)
		{
			if(character.classSpecials[j] == i)
			{
				checkForLesser(i);
			}
		}
	}
}

function removeRedundantSpecials()
{
	var cs = character.classSpecials;
	
	for (var i = 0; i < character.classSpecials.length;i++)
	{
		for(var j = 0; j < cs.length;j++)
		{
			if (cs[j] == cs[i] && j > i) 
			{
				cs = removeIt(cs, j);
			}
		}
	}
	character.classSpecials = cs;
	removeLesserSpecials()
}
function doSpecials()
{
	
	var level = 0;
	var notDone = true;
	var s = new Array();
	for(var j = 0;j < 11; j++)
	{
		for(var b = 0; b < character.p.length;b++)
		{
			if(character.p[b] == j)
			{
				for(var i = (pSpec.abil[j].length-1);i >= 0 ;i--)
				{
					if(character.plevel[b] >= pSpec.lvl[j][i])
					{
						s[s.length] = pSpec.abil[j][i];
					}
				}
			}
		}
	}
	character.classSpecials = s;
	update();
}
function confirmBonus(id)
{
	var attr = ["strength", "dexterity", "constitution", "intelligence", "wisdom", "charisma"];
	if(confirm("Increase " +attr[id]+"?"))
	{
		character.attributes[id]++;
		update();
		doHitPointsTotal();	
	}
}
function getClassSpecials()
{
	document.getElementById("topSection").innerHTML = "";
	
	doSpecials();
	if(character.name)
	{
		document.getElementById("step8").disabled=false;
	}
	removeRedundantSpecials();
	doNext(6);
}
function doHitPointsTotal()
{
	var hpb = 0;
	var hpm = 0;
	var hpr = 0;
	var hpbPhrase = "";
	var notHappy = true;
	for (var i = 0; i < character.listoffeats.length; i++)
	{
		if (featsLists.idName[character.listoffeats[i]] == "Toughness") 
		{
			hpb = 3;
			hpbPhrase = "and your toughness feats adds 3 points";
			character.listoffeats[i] = 74;
		}
	}
	hpm = mods[character.attributes[2]];
	while(notHappy)
	{
		hpr = Math.floor(random() *(hitDie[character.currentProf]) +1); 
		hpr += hpm; 
		if(hpr < 1) hpr = 1;
		confirmPhrase = "your hitpoints rolled this level are " + hpr +" "+ hpbPhrase + " Keep them?";
		if (confirm(confirmPhrase))
		{
			notHappy = false;
			character.hitpointsTotal += hpr + hpb;
		}
	}
	update();
	getClassSpecials();
	
}

function doBonusAttribute()
{
	document.getElementById("topSection").innerHTML  = "your stats.<br>Strength: <span id='att0'>"+character.attributes[0]+"</span><button type='button' onClick=\"confirmBonus(0)\">+</button><br>Dexterity: <span id='att1'>"+character.attributes[1]+"</span><button type='button' onClick=\"confirmBonus(1)\">+</button><br>Constitution: <span id='att2'>"+character.attributes[2]+"</span><button type='button' onClick=\"confirmBonus(2)\">+</button><br>Intelligence: <span id='att3'>"+character.attributes[3]+"</span><button type='button' onClick=\"confirmBonus(3)\">+</button><br>Wisdom: <span id='att4'>"+character.attributes[4]+"</span><button type='button' onClick=\"confirmBonus(4)\">+</button><br>Charisma: <span id='att5'>"+character.attributes[5]+"</span><button type='button' onClick=\"confirmBonus(5)\">+</button>";
}

function getExtras()
{
	if (character.level%4 ==0 && character.level > 1) 
	{
		doBonusAttribute();
	}
	else
	{
		doHitPointsTotal();
	}
	if(character.currentProf == 10 )spellChooser();
}

/**************************************************************************************
** Character Summary: getCharData, checkName,endIt


***************************************************************************************/
function endIt()
{
	document.getElementById("topSection").innerHTML = "thank you for using D&DLeicht! Please press finish to complete the program.";
	document.getElementById("step3").disabled = false;
	document.getElementById("step7").disabled = false;
	document.getElementById("step8").disabled = false;
}

function checkName(name)
{
	if(confirm("is  \"" + name +"\" correct?"))
	{
		character.name = name;
		document.getElementById("step8").disabled = false;
		if(character.level == LEVEL_CAP) endIt();
		update();
	}
}
function getCharData()
{
	toggleErrMsg();
	doNext(2);
	var d = "";
	if(character.name =="")
	{
		d += "<input type='text' size='40' maxlength='40' id='characterName' class='cName' value='"+character.name+"'></input><button type='button' onClick=\"checkName(document.getElementById('characterName').value)\">select</button>";
	}
	else
	{
		d += "<input type='text' size='40' maxlength='40' id='characterName' class='cName' value='"+character.name+"' onChange=\"document.getElementById('namebut').disabled=false\"></input><button id='namebut' disabled type='button' onClick=\"checkName(document.getElementById('characterName').value)\">select</button>";
	}
	document.getElementById("topSection").innerHTML = d;
	
	document.getElementById("step7").disabled = true;
	
	
}


/****************************************************************************************
** finish character: finishCharacter, calcTotalExp, drawCharacterSheet, makePop,
**


****************************************************************************************/
function finishCharacter()
{
	document.getElementById("step1").disabled = true;
	document.getElementById("step2").disabled = true;
	document.getElementById("step3").disabled = true;
	document.getElementById("step4").disabled = true;
	document.getElementById("step5").disabled = true;
	document.getElementById("step6").disabled = true;
	document.getElementById("step7").disabled = true;
	
	document.getElementById("step1").className = "menuItem";
	document.getElementById("step2").className = "menuItem";
	document.getElementById("step3").className = "menuItem";
	document.getElementById("step4").className = "menuItem";
	document.getElementById("step5").className = "menuItem";
	document.getElementById("step6").className = "menuItem";
	document.getElementById("step7").className = "menuItem";
	document.getElementById("step8").innerHTML = "Finished!";
	if(checkForFeat(17)) character.fort+=2;
	if(checkForFeat(23)) character.will+=2;
	if(checkForFeat(25)) character.ref +=2;
	
	character.experienceTotal=calcTotalExp();
	drawCharacterSheet();
}
function calcTotalExp()
{
	return classExp[character.level-1];
}
function drawCharacterSheet()
{
	var content = "";
	var abilities = ["Strength: ", "Dexterity: ", "Constitution: ", "Intelligence: ", "Wisdom: ", "Charisma: "];
	
	content += "<div class='sheetHeading'>D&DLeicht Character Sheet by Paul E Leicht</div>"
	c=character.name.substr(0,1).toUpperCase();
	n=character.name.substr(1, character.name.length-1);
	
	content += "<div class='charHeading'><div class='charName'>"+c+n;
	content += "</div><div class='charRace'>"+races[character.r]+"</div><div class='charClass'>";
	for(var i =0; i < character.p.length;i++)
	{
		content+= profs[character.p[i]] + "(" + character.plevel[i] +")";
		if(i < character.p.length-1) content+= ", ";
		else content +="."
	}
	content+="</div><div class='charExp'>Experience Earned: "+character.experienceTotal+"</div></div>";
	
	content+="<div class='stats'><div class='attributes'>";
	for(var i = 0; i < character.attributes.length;i++)
	{
		content += "<span class='attr'>"
		content += abilities[i] +"</span><span class='attrNum'>";
		content += character.attributes[i]+"</span>&nbsp;<span class='attrEnd'>(</span>";
		content +="<span class='attrNum'>";
		if(mods[character.attributes[i]] > 0) content += "+";
		else if (mods[character.attributes[i]] == 0) content+=" ";
		content += mods[character.attributes[i]]+"</span><span class='attrEnd'>)</span><br>";	
	}
	content+="<br></div>";
	content+="<div class='calcedStats'>"
	content+="<span class='hp'>Hit Points: </span> <span class='hpNum'>"+character.hitpointsTotal+"</span><br>"
	content+="<span class='bab'>base attack bonus: +" + character.baseattackbonus;
	if(character.baseattackbonus>5)content+="/" + (Number(character.baseattackbonus)-5);
	if(character.baseattackbonus>10)content+="/" + (Number(character.baseattackbonus)-10);
	if(character.baseattackbonus>15)content+="/" + (Number(character.baseattackbonus)-15);
	content+="</span><br><div class='saves'>saving throws:<br>";
	content+="<span class='save'>Reflex: +" + character.ref +"</span><br>";
	content+="<span class='save'>Fortitude: +" + character.fort +"</span><br>";
	content+="<span class='save'>Will: +" + character.will +"</span><br>";
	content+="</div></div>";
	content+="<div class='feats'><div class='featsinside'>Feats: ";
	for(var i=0; i < character.listoffeats.length;i++)
	{
			content+=featsLists.idName[character.listoffeats[i]];
			if (i < character.listoffeats.length-1) content+=", ";
			else content+=".";
	}
	
	content+="</div></div></div>";	
	content+="<div class='spec'><div class='specinside'>";
	content+="Special class abilities: ";
	for(var i=0;i < character.classSpecials.length;i++)
	{
		content+= pSpec.list[character.classSpecials[i]];
		if(i < character.classSpecials.length-1) content += ", ";
		else content+= ".";
	}
	content+="</div></div>";
	content+="<div class='skillslist'><div class='skillslistinside'>";
	content+="Skills: ";
	for(var i=0;i < character.charSkills.length;i++)
	{
		content+= skills.list[character.charSkills[i]] +"("; 
		content+= character.charSkillRanks[i] +")";
		if(i < character.charSkills.length-1) content += ", ";
		else content+= ".";
	}
	content+="</div></div>";
	
	makePop(content);
	
}
function makePop(content)
{
	var pop = window.open("", "charactermaker", "resize=yes, height=700 width=800");
	pop.document.open();
	var dtype = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">";
	pop.document.write(dtype);
	pop.document.write("<html><head><title>Character Maker 1.0</title><link href='dndcm.css' rel='stylesheet' type='text/css'></head><body style='width:800px;'>");
	pop.document.write(content);
	pop.document.write("</body></html>");
	pop.document.close();
	pop.focus();
}



function spellChooser()
{
	for(var i =0; i < character.p.length;i++)
	{
		if(character.p[i] == 9 || character.p[i] == 10) 
		{
		   setLevel(character.plevel[i])
		}
		
	}
}

function setLevel(lvl)
{

	if (lvl > 0)
	{
	 
		for(var u = 0; u < levelBreaks.length;u++)
		{
			if(levelBreaks[u] < lvl) 
			{
				maxLevel = u+1;
				alert(maxLevel)
			}
		}
		
	}
	else
	{
		maxLevel = 1;
	}
	totalSpells[1] = 3;
	setTimer=setTimeout("startInit()",100);

}


function startInit()
{

	var spellDisplay = document.createElement("DIV");
	spellDisplay.setAttribute("ID", "spellDisplayDiv");
	spellDisplay.setAttribute(getClassName(), "seldiv");
	document.body.appendChild(spellDisplay);
	var selSpan = document.createElement("DIV");
	selSpan.setAttribute("ID", "selectSpan");
	selSpan.setAttribute(getClassName(), "selspan");
	document.getElementById("spellDisplayDiv").appendChild(selSpan);
	setT = setTimeout("initShowSpells()", 1000);
    
}
function closePop(id)
{
	var p =	document.getElementById(id);
	p.parentNode.removeChild(p);
}

function initShowSpells()
{
	
	var t="";
	t+="<table cellspacing=0 cellpadding=0 border=1 id='gridLayout' class='tableGrid'>";
	t+="<tr><td class='gridCell' id='leftCell'>";
	t+="</td><td class='gridCell' id='centerCell'>";
	t+="</td><td class='gridCell' id='rightCell'>";
	t+="</td></tr></table>";
	document.getElementById("spellDisplayDiv").innerHTML += t;
    makeButtonBank();
	document.getElementById("x1").disabled= true;
	showSpellsLists(1);
	
}
function makeButtonBank()
{
	var d = "";
	for (var i = 1; i < 10; i++)	
	{
		d+="<button id='x"+i+"' type='button' class='butStyle'";
		if(i> maxLevel) 
		{
			
			d+="disabled ";
			d+="style='display:none;'";
		}
		d+="onFocus='if(blur()) this.blur();' onClick='showSpellsLists("+i+");disableBut("+i+")'>"+i+"</button>";
	}

	
	d = "<a style='padding:0px;position:relative;top:0px;right:95%;' href='javascript:void(0);' onclick='closePop(\"spellDisplayDiv\")'>X</a>"+d;
	document.getElementById("selectSpan").innerHTML = d;

	
}
function disableBut(num)
{
	var id = "x" + num;
	for(var i = 1;i < 10; i++)
	{
		if(i <= maxLevel) document.getElementById("x"+i).disabled = false;
		else document.getElementById("x"+i).disabled = true;
	}
	document.getElementById(id).disabled= true;
}


function checkForProtected(spellId, spellLevel)
{
	return oldSpells[spellLevel][spellId];
}
function checkForSpell(spellId, spellLevel)
{
	return s[spellLevel][spellId];
}
function toggleSpell(spellId,spellLevel)
{
	
	if (s[spellLevel][spellId] == false) 
	{
		if(totalSpells[spellLevel] >0)
		{
			s[spellLevel][spellId] = true;
			totalSpells[spellLevel]--;
		}
		else
		{
			if(confirm("you have no spells to choose, exit?")) updateSpells();
		}
	}
	else
	{
		s[spellLevel][spellId] = false;
		totalSpells[spellLevel]--;
	}
	
	showSpellsLists(spellLevel);
}

function showSpellsLists(spellLevel)
{
}

function updateSpells()
{
}