/*
        This web page was created to help players produce
        3rd edition D&D characters quickly and easily. It
        accepts some basic input from the user, then displays
        a basic character sheet (in HTML). A simple, blank
        sheet can also be displayed for printing purposes.

	This page has been tested and works with Internet Explorer,
	Opera, Firefox, Mozilla and Konqueror.
	This page does not fully function Netscape.

        Please feel free to copy, alter and use
        this HTML/JavaScript code at will. However I ask
        that you document and send me any logic
        changes. Thank you. This generator is licensed under
        the GNU General Public License (GPL) version 2. 
        For more information please see 
        http://www.fsf.org/licenses/gpl.html

        Technical assistance provided by Isaac Sabean.
	Random name generator provided by David A. Wheeler.

        Version - 4.5
        Written by Jesse Smith <slicer69@hotmail.com>
        http://slicer69.tripod.com/

*/

    // this varible contains data passed to new pop-ups
    var min_feature = "scrollbars=yes, menubar=no, status=no, toolbar=no, resizable=yes";
    var display_feature = "scrollbars=yes, menubar=yes, status=no, toolbar=no, resizable=yes";

    // define an empty value
    var NONE = 0;

    // define current version
    var current_version = 4.5;

    var notes_win;
    var game_notes = "";

    // define race values
    var HUMAN = 0;
    var ELF = 1;
    var DWARF = 2;
    var HALFLING = 3;
    var HALF_ELF = 4;
    var HALF_ORC = 5;
    var GNOME = 6;

    // define class values
    var BARBARIAN = 0;
    var BARD = 1;
    var CLERIC = 2;
    var DRUID = 3;
    var FIGHTER = 4;
    var MONK = 5;
    var PALADIN = 6;
    var RANGER = 7;
    var ROGUE = 8;
    var SORCERER = 9;
    var WIZARD = 10;

    var LAWFUL_GOOD = 0;
    var NEUTRAL_GOOD = 1;
    var CHAOTIC_GOOD = 2;
    var LAWFUL_NEUTRAL = 3;
    var TRUE_NEUTRAL = 4;
    var CHAOTIC_NEUTRAL = 5;
    var LAWFUL_EVIL = 6;
    var NEUTRAL_EVIL = 7;
    var CHAOTIC_EVIL = 8;

    // gods and religions
    var BACCOB = 1;
    var CORELLON_LARENTHIAN = 2;
    var EHLONNA = 3;
    var ERYTNUL = 4;
    var FARLANGHN = 5;
    var GARL_GLITTERGOLD = 6;
    var GRUUMSH = 7;
    var HEIRONEOUS = 8;
    var HEXTOR = 9;
    var KORD = 10;
    var MORADIN = 11;
    var NERULL = 12;
    var OBAD_HAI = 13;    // Obad-Hai
    var OLIDAMMARA = 14;
    var PELOR = 15;
    var ST_CUTHBERT = 16;  // St. Cuthbert
    var VECNA = 17;
    var WEE_JAS = 18;
    var YONDALLA = 19;
    var OTHER_GOD = 20;


    // define skills
    var APPRAISE = 0;
    var BALANCE = 1;
    var BLUFF = 2;
    var CLIMB = 3;
    var CONCENTRATION = 4;
    var CRAFT = 5;
    var DECIPHER_SCRIPT = 6;
    var DIPLOMACY = 7;
    var DISABLE_DEVICE = 8;
    var DISGUISE = 9;
    var ESCAPE_ARTIST = 10;
    var FORGERY = 11;
    var GATHER_INFORMATION = 12;
    var HANDLE_ANIMAL = 13;
    var HEAL = 14;
    var HIDE_SKILL = 15;
    var INTIMIDATE = 16;
    var JUMP = 17;
    var KNOWLEDGE_ARCANA = 18;
    var KNOWLEDGE_ARCHITECTURE = 19;
    var KNOWLEDGE_DUNGEONEERING = 20;
    var KNOWLEDGE_GEOGRAPHY = 21;
    var KNOWLEDGE_HISTORY = 22;
    var KNOWLEDGE_LOCAL = 23;
    var KNOWLEDGE_NATURE = 24;
    var KNOWLEDGE_NOBILITY = 25;
    var KNOWLEDGE_RELIGION = 26;
    var KNOWLEDGE_PLANES = 27;
    var LISTEN = 28;
    var MOVE_SILENTLY = 29;
    var OPEN_LOCK = 30;
    var PERFORM = 31;
    var PROFESSION = 32;
    var RIDE = 33;
    var SEARCH = 34;
    var SENSE_MOTIVE = 35;
    var SLEIGHT_OF_HAND = 36;
    var SPEAK_LANGUAGE = 37;
    var SPELLCRAFT = 38;
    var SPOT = 39;
    var SURVIVAL = 40;
    var SWIM = 41;
    var TUMBLE = 42;
    var USE_MAGIC_DEVICE = 43;
    var USE_ROPE = 44;

    // define languages
    var ABYSSAL = 0;
    var AQUAN = 1;
    var AURAN = 2;
    var CELESTIAL = 3;
    var COMMON = 4;
    var DRACONIC = 5;
    var DRUIDIC = 6;
    var DWARVEN = 7;
    var ELVEN = 8;
    var GNOME_LANG = 9;
    var GOBLIN = 10;
    var GIANT = 11;
    var GNOLL = 12;
    var HALFLING_LANG = 13;
    var IGNAN = 14;
    var INFERNAL = 15;
    var ORC = 16;
    var SYLVAN = 17;
    var TERRAN = 18;
    var UNDERCOMMON = 19;

    var language_win;
    var language_points, max_language_points;
    var language = new Array(20);
    var language_names = new Array(20);
    language_names[0] = "Abyssal";
    language_names[1] = "Aquan";
    language_names[2] = "Auran";
    language_names[3] = "Celestial";
    language_names[4] = "Common";
    language_names[5] = "Draconic";
    language_names[6] = "Druidic";
    language_names[7] = "Dwarven";
    language_names[8] = "Elven";
    language_names[9] = "Gnome";
    language_names[10] = "Goblin";
    language_names[11] = "Giant";
    language_names[12] = "Gnoll";
    language_names[13] = "Halfling";
    language_names[14] = "Ignan";
    language_names[15] = "Infernal";
    language_names[16] = "Orc";
    language_names[17] = "Sylvan";
    language_names[18] = "Terran";
    language_names[19] = "Undercommon";



    var skill_names = new Array(44);
    skill_names[0] = "APPRAISE";
    skill_names[1] = "BALANCE";
    skill_names[2] = "BLUFF";
    skill_names[3] = "CLIMB";
    skill_names[4] = "CONCENTRATION";
    skill_names[5] = "CRAFT";
    skill_names[6] = "DECIPHER_SCRIPT";
    skill_names[7] = "DIPLOMACY";
    skill_names[8] = "DISABLE_DEVICE";
    skill_names[9] = "DISGUISE";
    skill_names[10] = "ESCAPE_ARTIST";
    skill_names[11] = "FORGERY";
    skill_names[12] = "GATHER_INFORMATION";
    skill_names[13] = "HANDLE_ANIMAL";
    skill_names[14] = "HEAL";
    skill_names[15] = "HIDE";
    skill_names[16] = "INTIMIDATE";
    skill_names[17] = "JUMP";
    skill_names[18] = "KNOWLEDGE_ARCANA";
    skill_names[19] = "KNOWLEDGE_ARCHITECTURE";
    skill_names[20] = "KNOWLEDGE_DUNGEONEERING";
    skill_names[21] = "KNOWLEDGE_GEOGRAPHY";
    skill_names[22] = "KNOWLEDGE_HISTORY";
    skill_names[23] = "KNOWLEDGE_LOCAL";
    skill_names[24] = "KNOWLEGE_NATURE";
    skill_names[25] = "KNOWLEGE_NOBILTY";
    skill_names[26] = "KNOWLEDGE_RELIGION";
    skill_names[27] = "KNOWLEDGE_PLANES";
    skill_names[28] = "LISTEN";
    skill_names[29] = "MOVE_SILENTLY";
    skill_names[30] = "OPEN_LOCK";
    skill_names[31] = "PERFORM";
    skill_names[32] = "PROFESSION";
    skill_names[33] = "RIDE";
    skill_names[34] = "SEARCH";
    skill_names[35] = "SENSE_MOTIVE";
    skill_names[36] = "SLEIGHT_OF_HAND";
    skill_names[37] = "SPEAK_LANGUAGE";
    skill_names[38] = "SPELLCRAFT";
    skill_names[39] = "SPOT";
    skill_names[40] = "SURVIVAL";
    skill_names[41] = "SWIM";
    skill_names[42] = "TUMBLE";
    skill_names[43] = "USE_MAGIC_DEVICE";
    skill_names[44] = "USE_ROPE";


    // define feat values
    var ACROBATIC = 0;
    var AGILE = 1;
    var ALERTNESS = 2;
    var ANIMAL_AFFINITY = 3;
    var ARMOR_PROFICIENCY_LIGHT = 4;
    var ARMOR_PROFICIENCY_MEDIUM = 5;
    var ARMOR_PROFICIENCY_HEAVY = 6;
    var ATHLETIC = 7;
    var AUGMENT_SUMMONING = 8;
    var BLIND_FIGHT = 9;
    var BREW_POTION = 10;
    var CLEAVE = 11;
    var COMBAT_CASTING = 12;
    var COMBAT_EXPERTISE = 13;
    var COMBAT_REFLEXES = 14;
    var CRAFT_MAGIC_ARMS_AND_ARMOR = 15;
    var CRAFT_ROD = 16;
    var CRAFT_STAFF = 17;
    var CRAFT_WAND = 18;
    var CRAFT_WONDEROUS_ITEM = 19;
    var DECEITFUL = 20;
    var DEFLECT_ARROWS = 21;
    var DEFT_HANDS = 22;
    var DIEHARD = 23;
    var DILIGENT = 24;
    var DODGE = 25;
    var EMPOWER_SPELL = 26;
    var ENDURANCE = 27;
    var ENLARGE_SPELL = 28;
    var ESCHEW_MATERIALS = 29;
    var EXOTIC_WEAPON_PROFICIENCY = 30;
    var EXTEND_SPELL = 31;
    var EXTRA_TURNING = 32;
    var FAR_SHOT = 33;
    var FORGE_RING = 34;
    var GREAT_CLEAVE = 35;
    var GREAT_FORTITUDE = 36;
    var GREATER_SPELL_FOCUS = 37;
    var GREATER_SPELL_PENETRATION = 38;
    var GREATER_TWO_WEAPON_FIGHTING = 39;
    var GREATER_WEAPON_FOCUS = 40;
    var GREATER_WEAPON_SPECIALIZATION = 41;
    var HEIGHTEN_SPELL = 42;
    var IMPROVED_BULL_RUSH = 43;
    var IMPROVED_COUNTERSPELL = 44;
    var IMPROVED_CRITICAL = 45;
    var IMPROVED_DISARM = 46;
    var IMPROVED_FEINT = 47;
    var IMPROVED_GRAPPLE = 48;
    var IMPROVED_INITIATIVE = 49;
    var IMPROVED_OVERRUN = 50;
    var IMPROVED_PRECISE_SHOT = 51;
    var IMPROVED_SHIELD_BASH = 52;
    var IMPROVED_SUNDER = 53;
    var IMPROVED_TRIP = 54;
    var IMPROVED_TURNING = 55;
    var IMPROVED_TWO_WEAPON_FIGHTING = 56;
    var IMPROVED_UNARMED_STRIKE = 57;
    var INVESTIGATOR = 58;
    var IRON_WILL = 59;
    var LEADERSHIP = 60;
    var LIGHTNING_REFLEXES = 61;
    var MAGICAL_APTITUDE = 62;
    var MANYSHOT = 63;
    var MARTIAL_WEAPON_PROFICIENCY = 64;
    var MAXIMIZE_SPELL = 65;
    var MOBILITY = 66;
    var MOUNTED_ARCHERY = 67;
    var MOUNTED_COMBAT = 68;
    var NATURAL_SPELL = 69;
    var NEGOTIATOR = 70;
    var NIMBLE_FINGERS = 71;
    var PERSUASIVE = 72;
    var POINT_BLANK_SHOT = 73;
    var POWER_ATTACK = 74;
    var PRECISE_SHOT = 75;
    var QUICK_DRAW = 76;
    var QUICKEN_SPELL = 77;
    var RAPID_RELOAD = 78;
    var RAPID_SHOT = 79;
    var RIDE_BY_ATTACK = 80;
    var RUN = 81;
    var SCRIBE_SCROLL = 82;
    var SELF_SUFFICIENT = 83;
    var SHIELD_PROFICIENCY = 84;
    var SHOT_ON_THE_RUN = 85;
    var SILENT_SPELL = 86;
    var SIMPLE_WEAPON_PROFICIENCY = 87;
    var SKILL_FOCUS = 88;
    var SNATCH_ARROWS = 89;
    var SPELL_FOCUS = 90;
    var SPELL_MASTERY = 91;
    var SPELL_PENETRATION = 92;
    var SPIRITED_CHARGE = 93;
    var SPRING_ATTACK = 94;
    var STEALTHY = 95;
    var STILL_SPELL = 96;
    var STUNNING_FIST = 97;
    var TOUGHNESS = 98;
    var TOWER_SHIELD_PROFICIENCY = 99;
    var TRACK = 100;
    var TRAMPLE = 101;
    var TWO_WEAPON_DEFENCE = 102;
    var TWO_WEAPON_FIGHTING = 103;
    var WEAPON_FINESSE = 104;
    var WEAPON_FOCUS = 105;
    var WEAPON_SPECIALIZATION = 106;
    var WHIRLWIND_ATTACK = 107;
    var WIDEN_SPELL = 108;


    // provide a list of descriptions for feats
    var feat_info = new Array(109);
    feat_info[0] = "+2 bonus to Jump and Tumble checks";
    feat_info[1] = "+2 bonus to Balance and Escape Artist checks";
    feat_info[2] = "+2 bonus to Listen and Spot checks";
    feat_info[3] = "+2 bonus to Handle Animal and Ride checks";
    feat_info[4] = "Able to use Light armor";
    feat_info[5] = "Able to use Medium armor";
    feat_info[6] = "Able to use Heavy armor";
    feat_info[7] = "+2 bonus to Climb and Swim checks";
    feat_info[8] = "Summoned creatures get +4 str and +4 con";
    feat_info[9] = "Re-roll missed chance against concealed targets";
    feat_info[10] = "Create potion of 3rd level spell or lower";
    feat_info[11] = "Attack a second targe after falling a foe";
    feat_info[12] = "+4 bonus to Concentration check in combat";
    feat_info[13] = "Trade attack bonus for greater armor class (max 5)";
    feat_info[14] = "Gain attacks of opportunity against foes";
    feat_info[15] = "Create magic weapons and armor";
    feat_info[16] = "Create a special rod";
    feat_info[17] = "Create a special staff";
    feat_info[18] = "Create a special wand";
    feat_info[19] = "Create a wonderous item";
    feat_info[20] = "+2 bonus to Disguise and Forgery checks";
    feat_info[21] = "Deflect a ranged weapon";
    feat_info[22] = "+2 bonus to Sleight of Hand and Use Rope checks";
    feat_info[23] = "Gain stable health when knocked unconscience";
    feat_info[24] = "+2 bonus to Appraise and Decipher Script checks";
    feat_info[25] = "Gain +1 to armor class in comabt against one foe";
    feat_info[26] = "Spell powers increase by 50%";
    feat_info[27] = "Gain +4 bonus to most Swim, Consitution and Fortitude checks";
    feat_info[28] = "Double the range of a spell";
    feat_info[29] = "Cast spells wihtout cheap materials";
    feat_info[30] = "No penalty when using exotic weapons";   // not erotic weapons
    feat_info[31] = "Double the length of time a spell lasts";
    feat_info[32] = "You can turn undead four more times each day";
    feat_info[33] = "Gain better abilities with long-ranged weapons";
    feat_info[34] = "Create a special ring";
    feat_info[35] = "After fallign a foe, you get to attack again multiple times";
    feat_info[36] = "+2 bonus to all Fortitude checks";
    feat_info[37] = "Make it harder to resist your spells";
    feat_info[38] = "+2 bonus when overcoming a creature's spell resistence";
    feat_info[39] = "Gain a third attack with your off-hand weapon (-10 penalty)";
    feat_info[40] = "Gain +1 to all attack rolls with a given weapon";
    feat_info[41] = "Gain +2 damage to all successful attack rolls";
    feat_info[42] = "Increase the effective level of a spell";
    feat_info[43] = "Perform bull rushes without prevoking attacks";
    feat_info[44] = "When counter-spelling, use a spell of the same school";
    feat_info[45] = "Increase the threat range of your weapon";
    feat_info[46] = "Do not pervoke attacks when disarming an opponet";
    feat_info[47] = "Use a movement turn to Buff a foe";
    feat_info[48] = "Do not pervoke attacks when grappling";
    feat_info[49] = "+4 bonus to Initiative checks";
    feat_info[50] = "Gain +4 bonus to Strength checks when over-running";
    feat_info[51] = "Your ranged attacks  can hit foes who are behind cover";
    feat_info[52] = "When bashing with your shield, you can still use the shield defensively";
    feat_info[53] = "When striking a held object, you do not provoke an attack";
    feat_info[54] = "Do not pervoke an attack when trying to trip a foe";
    feat_info[55] = "Turn undead as if you were one level higher";
    feat_info[56] = "Gain a second attack with your off-hand (-5 penalty)";
    feat_info[57] = "You are considered armed even when you have no weapon";
    feat_info[58] = "+2 bonus to Gather Information and Search checks";
    feat_info[59] = "+2 bonus to Will checks";
    feat_info[60] = "You may attract loyal followers";   // *cough* cult *cough*
    feat_info[61] = "+2 bonus to Reflex checks";
    feat_info[62] = "+2 bonus to Spellcraft and Use Magic Device checks";
    feat_info[63] = "Fire two arrows at one target within 30 feet (-4 penalty)";
    feat_info[64] = "You can use Martial weapons";
    feat_info[65] = "Spell features are all maximized";
    feat_info[66] = "Gain +4 dodge ability when leaving a square in melee";
    feat_info[67] = "Take only half penlties when shooting while mounted";
    feat_info[68] = "You can try to stay mounted if you mount is hit";
    feat_info[69] = "Cast spells while in transformed shape";
    feat_info[70] = "+2 bonus to Diplomacy and Sense Motive checks";
    feat_info[71] = "+2 bonus to Disable Device and Open Lock checks";
    feat_info[72] = "+2 bonus on Bluff and Intimidate checks";
    feat_info[73] = "+1 bonus to attack and damage rolls on foes within 30 feet";
    feat_info[74] = "Trade attack points for damage points in melee";
    feat_info[75] = "Use ranged attacks against foes who are in melee without penalty";
    feat_info[76] = "Draw a weapon as a free action";
    feat_info[77] = "Cast a quickened spell as a free action";
    feat_info[78] = "Reduce the time it takes to reload a weapon";
    feat_info[79] = "Get an extra attack with ranged weapons";
    feat_info[80] = "Attack while mounted without prevoking attacks";
    feat_info[81] = "Run at 5 times your normal speed with light load";
    feat_info[82] = "Create a scroll of a spell you know";
    feat_info[83] = "+2 bonus to Heal and Survival checks";
    feat_info[84] = "You are able to use a shield properly";
    feat_info[85] = "You can run and shoot at the same time";
    feat_info[86] = "Cast spell without speaking";
    feat_info[87] = "You are able to use simple weapons";
    feat_info[88] = "+3 bonus on selected skill";
    feat_info[89] = "Catch ranged weapons";
    feat_info[90] = "It is more difficult to resist your spells";
    feat_info[91] = "Cast selected spells without a spell book";
    feat_info[92] = "+2 bonus to your caster level when overcoming a creatures spell resistance";
    feat_info[93] = "Deal double damage with a melee weapon when charging on a mount";
    feat_info[94] = "Move both before and after a melee attack";
    feat_info[95] = "+2 bonus to Hide and Move Silently checks";
    feat_info[96] = "Cast spells without moving your hands";
    feat_info[97] = "Try to stun a foe with your fist";
    feat_info[98] = "+3 hit points";
    feat_info[99] = "You are able to use a tower shield";
    feat_info[100] = "You gain the ability to follow creatures";
    feat_info[101] = "You foe is unable to avoid your mount's run-down";
    feat_info[102] = "When fighting with two weapons, you gain +1 to armor class";
    feat_info[103] = "You find it easier to fight with two weapons";
    feat_info[104] = "With light weapons, you may use your Dexterity for melee attacks";
    feat_info[105] = "+1 bonus to all attack rolls with a selected weapon";
    feat_info[106] = "+2 bonus to all damage rolls with a selected weapon";
    feat_info[107] = "You may make one attack against each foe within reach each round";
    feat_info[108] = "Double the size of a spell";
  
    // Below are the definitions for equipment numbers. Equipment is set up
    // in three different arrays (eq_name, eq_cost and eq_bonus). So
    // eq_name[SHORT_SWORD] should be "shortsword".
    
    MAX_EQUIPMENT = 217;        // so far the max number of items

    // These define the positions of the
    // STARTing part of a category of equipment.
    var FIRST_ARMOR = 66;
    var FIRST_GEAR = 87;
    var FIRST_CLOTHES = 178;
    var FIRST_MOUNT = 190;

    // Now define equipment numbers
    // weapons
    var GAUNTLET = 0;
    var DAGGER = 1;
    var DAGGER_PUNCHING = 2;
    var GAUNTLET_SPIKED = 3;
    var MACE_LIGHT = 4;
    var SICKLE = 5;
    var CLUB = 6;
    var HALFSPEAR = 7;
    var MACE_HEAVY = 8;
    var MORNINGSTAR = 9;
    var QUARTERSTAFF = 10;
    var SHORTSPEAR = 11;
    var CROSSBOW_LIGHT = 12;
    var CROSSBOW_BOLTS = 13;
    var DART = 14;
    var SLING = 15;
    var BULLETS_SLING = 16;
    var CROSSBOW_HEAVY = 17;
    var JAVELIN = 18;
    var AXE_THROWING = 19;
    var HAMMER_LIGHT = 20;
    var HANDAXE = 21;
    var LANCE_LIGHT = 22;
    var PICK_LIGHT = 23;
    var SAP = 24;
    var SWORD_SHORT = 25;
    var BATTLEAXE = 26;
    var FLAIL_LIGHT = 27;
    var LANCE_HEAVY = 28;
    var LONGSWORD = 29;
    var PICK_HEAVY = 30;
    var RAPIER = 31;
    var SCIMITAR = 32;
    var TRIDENT = 33;
    var WARHAMMER = 34;
    var FALCHION = 35;
    var FLAIL_HEAVY = 36;
    var GLAIVE = 37;
    var GREATAXE = 38;
    var GREATCLUB = 39;
    var GREATSWORD = 40;
    var GUISARME = 41;
    var HAILBERD = 42;
    var LONGSPEAR = 43;
    var RANSEUR = 44;
    var SCYTHE = 45;
    var SHORTBOW = 46;
    var SHORTBOW_COMPOSITE = 47;
    var LONGBOW = 48;
    var LONGBOW_COMPOSITE = 49;
    var ARROWS = 50;
    var KAMAHALFLING = 51;
    var KUKRI_HALFLING = 52;
    var NUNCHAKU_HALFLING = 53;
    var SIANGHAM_HALFLING = 54;
    var KAMA = 55;
    var NUNCHAKU = 56;
    var SIANGHAM = 57;
    var SWORD_BASTARD = 58;
    var WARAXE_DWARVEN = 59;
    var HAMMER_GNOME = 60;
    var AXE_ORC = 61;
    var CHAIN_SPIKED = 62;
    var FLAIL_DIRE = 63;
    var SWORD_TWO_BLADED = 64;
    var URGROSH_DWARVEN = 65;

    // armor
    var PADDED = 66;
    var LEATHER = 67;
    var STUDDED_LEATHER = 68;
    var CHAIN_SHIRT = 69;
    var HIDE_ARMOR = 70;
    var SCALE_MAIL = 71;
    var CHAINMAIL = 72;
    var BREASTPLATE = 73;
    var SPLINT_MAIL = 74;
    var BANDED_MAIL = 75;
    var HALF_PLATE = 76;
    var FULL_PLATE = 77;
    var BUCKLER = 78;
    var SHIELD_SMALL_WOODEN = 79;
    var SHIELD_SMALL_STEEL = 80;
    var SHIELD_LARGE_WOODEN = 81;
    var SHIELD_LARGE_STEEL = 82;
    var SHIELD_TOWER = 83;
    var ARMOR_SPIKES = 84;
    var GAUNTLET_LOCKED = 85;
    var SHIELD_SPIKES = 86;
    
    // gear and tools
    var BACKPACK = 87;
    var BARREL = 88;
    var BASKET = 89;
    var BEDROLL = 90;
    var BELL = 91;
    var BLANKET = 92;
    var BLOCK_TACKLE = 93;
    var BOTTLE = 94;
    var BUCKET = 95;
    var CALTROPS = 96;
    var CANDLE = 97;
    var CANVAS = 98;
    var CASE = 99;
    var CHAIN = 100;
    var CHALK = 101;
    var CHEST = 102;
    var CROWBAR = 103;
    var FIREWOOD = 104;
    var FISHHOOK = 105;
    var FISHING_NET = 106;
    var FLASK = 107;
    var FLINT_STEEL = 108;
    var GRAPPLING_HOOK = 109;
    var HAMMER = 110;
    var INK = 111;
    var INKPEN = 112;
    var JUG = 113;
    var LADDER = 114;
    var LAMP = 115;
    var LANTERN_BULLSEYE = 116;
    var LANTERN_HOODED = 117;
    var LOCK = 118;
    var MANACLES = 119;
    var MIRROR = 120;             // FOR YOUR VAIN ADVENTURER
    var MUG = 121;
    var OIL = 122;
    var PAPER = 123;
    var PARCHMENT = 124;
    var PICK = 125;
    var PICTHER = 126;
    var PITON = 127;
    var POLE = 128;
    var POT = 129;              // NOT THAT KIND OF POT
    var POUCH = 130;
    var RAM = 131;
    var RATIONS = 132;
    var ROPE = 133;
    var SACK = 134;
    var SEALING_WAX = 135;
    var NEEDLE = 136;
    var SIGNAL_WHISTLE = 137;
    var SIGNET_RING = 138;
    var SLEDGE = 139;
    var SOAP = 140;
    var SPADE = 141;
    var SPYGLASS = 142;
    var TENT = 143;
    var TORCH = 144;
    var VIAL = 145;
    var WATERSKIN = 146;
    var WHETSTONE = 147;

    // I'm leaving out mounts and other special item for now.
    // If there is demand I'll put them in later.

    // Demand or no, here are the other pieces of equipment:
    // Special substances and items
    var ACID_FLASK = 148;
    var ALCHEMIST_FIRE = 149;
    var ANTITOXIN = 150;
    var EVERBURNING_TORCH = 151;
    var HOLY_WATER = 152;
    var SMOKESTICK = 153;
    var SUNROD = 154;
    var TANGLEFOOD_BAG = 155;
    var THUNDERSTONE = 156;
    var TINDERTWIG = 157;

    // tools (wonder why I'm not on the list...)
    var ALCHEMIST_LAB = 158;
    var ARTISAN_TOOLS = 159;
    var ARTISAN_TOOLS_MASTERWORK = 160;
    var CLIMBER_KIT = 161;
    var DISGUISE_KIT = 162;
    var HEALER_KIT = 163;
    var HOLLY_MISTLETOE = 164;
    var HOLY_SYMBOL_WOOD = 165;
    var HOLY_SYMBOL_SILVER = 166;
    var HOURGLASS = 167;
    var MAGNIFYING_GLASS = 168;
    var MUSIC_INSTRUMENT = 169;
    var MUSIC_INSTRUMENT_MASTERWORK = 170;
    var SCALE_MERCHANT = 171;
    var SPELL_COMPONENT_POUCH = 172;
    var SPELL_BOOK = 173;
    var THIEF_TOOLS = 174;
    var THIEF_TOOLS_MASTERWORK = 175;
    var TOOL_MASTERWORK = 176;
    var WATER_CLOCK = 177;

    // Clothes for the non-streaking adventurer
    var ARTISAN_OUTFIT = 178;
    var CLERIC_VESTMENTS = 179;
    var COLD_WEATHER_OUTFIT = 180;
    var COURTIER_OUTFIT = 181;
    var ENTERTAINER_OUTFIT = 182;
    var EXPLORER_OUTFIT = 183;
    var MONK_OUTFIT = 184;
    var NOBLE_OUTFIT = 185;
    var PEASANT_OUTFIT = 186;
    var ROYAL_OUTFIT = 187;
    var SCHOLAR_OUTFIT = 188;
    var TRAVELER_OUTFIT = 189;

    // skip food and lodging, we can't carry most of those
    // mounts, horses, dogs, ponies
    var BIT_BRIDLE = 190;
    var DOG_GUARD = 191;
    var DOG_RIDING = 192;
    var DONKEY = 193;
    var FEED_PER_DAY = 194;
    var HORSE_HEAVY = 195;     // aren't they all?
    var HORSE_LIGHT = 196;
    var PONY = 197;
    var WARHORSE_HEAVY = 198;
    var WARHORSE_LIGHT = 199;
    var WARPONY = 200;         // hahaha
    var MILITARY_SADDLE = 201;
    var PACK_SADDLE = 202;
    var RIDING_SADDLE = 203;
    var MILITARY_SADDLE_EXOTIC = 204;
    var PACK_SADDLE_EXOTIC = 205;
    var RIDING_SADDLE_EXOTIC = 206;
    var SADDLE_BAGS = 207;
   
    // travel stuff
    var CARRIAGE = 208;
    var CART = 209;
    var GALLEY = 210;
    var KEELBOAT = 211;
    var LONGSHIP = 212;
    var ROWBOAT = 213;
    var SAILING_SHIP = 214;
    var SLED = 215;
    var WAGON = 216;
    var WARSHIP = 217;
 

    // define character values
    var race = HUMAN;
    var race_name = "Human";

    var starting_class = BARBARIAN;
    var starting_class_name = "Barbarian";

    // levels in each class (there are 11 classes)
    var class_levels = new Array(1,0,0,0,0,0,0,0,0,0,0);

    var alignment = LAWFUL_GOOD;
    var alignment_name = "Lawful Good";
    var alignment_conflict;

    var religion = NONE;
    var religion_name = "None";

    var total_level = 1;
    var max_bonus_ability = 0, bonus_ability = 0;

    var armour_bonus = 0;
    
    var strength, strength_mod;
    var dexterity, dex_mod;
    // intelligence is also a flag to show if we have rolled ability scores
    var intelligence = 0, int_mod;
    var constitution, con_mod;
    var wisdom, wis_mod;
    var charisma, chr_mod;

    // define min values for abilities
    var min_str, min_dex, min_con, min_int, min_wis, min_chr;

    // define player extras
    var base_attack_bonus;
    var reflex_save, will_save, fortitude_save;
    var hit_points;
    var experience_points = 0;
    var money;

    // define equipment varibles
    var MASTERWORK_EQUIPMENT = 87;
    var eq_name = new Array(MAX_EQUIPMENT);     // eqipment name
    var eq_cost = new Array(MAX_EQUIPMENT);     // gold to purchase the eq
    var eq_bonus = new Array(MAX_EQUIPMENT);    // ac or attack the eq gives
    var eq_have = new Array(MAX_EQUIPMENT);      // eqipment the char has
    var eq_masterwork = new Array(MASTERWORK_EQUIPMENT);    // whether weapons and armor are masterwork.
    var user_equipment_list = new Array();
    var max_user_equipment = 0;
    var shield_index = -1, armour_index = -1;

    // let's not forget the cost of masterwork stuff
    var MASTERWORK_WEAPON = 300.0;
    var MASTERWORK_ARMOR = 150.0;
    var MASTERWORK_BOLT = 60.0;
    var MASTERWORK_ARROW = 120.0;

    // the following are the offsets of the bolt and arrows in equipment
    var BOLT_WEAPON = 13;
    var ARROW_WEAPON = 50;



    // Define known skills. There are 45 skills currently.
    var skills = new Array(45);
    // how many poitns do we have to spend
    var max_skill_points, skill_points;

    // define which feats have been selected (true/false)
    var feats = new Array(108);
    // total number of feats which can be selected
    var feat_points;
    
    // number of feats for being a fighter, wizard or monk
    var fighter_feats, wizard_feats;
    var monk_bonus_feats = new Array(3);
    // true for two weapon fighting, false for archery
    var ranger_combat_style = true;

    // array of feat names
    var feat_names = new Array(108);

    feat_names[0] = "ACROBATIC";
    feat_names[1] = "AGILE";
    feat_names[2] = "ALERTNESS";
    feat_names[3] = "ANIMAL_AFFINITY";
    feat_names[4] = "ARMOR_PROFICIENCY_LIGHT";
    feat_names[5] = "ARMOR_PROFICIENCY_MEDIUM";
    feat_names[6] = "ARMOR_PROFICIENCY_HEAVY";
    feat_names[7] = "ATHLETIC";
    feat_names[8] = "AUGMENT_SUMMONING";
    feat_names[9] = "BLIND_FIGHT";
    feat_names[10] = "BREW_POTION";
    feat_names[11] = "CLEAVE";
    feat_names[12] = "COMBAT_CASTING";
    feat_names[13] = "COMBAT_EXPERTISE";
    feat_names[14] = "COMBAT_REFLEXES";
    feat_names[15] = "CRAFT_MAGIC_ARMS_AND_ARMOR";
    feat_names[16] = "CRAFT_ROD";
    feat_names[17] = "CRAFT_STAFF";
    feat_names[18] = "CARFT_WAND";
    feat_names[19] = "CRAFT_WONDEROUS_ITEM";
    feat_names[20] = "DECEITFUL";
    feat_names[21] = "DEFLECT_ARROWS";
    feat_names[22] = "DEFT_HANDS";
    feat_names[23] = "DIEHARD";
    feat_names[24] = "DILIGENT";
    feat_names[25] = "DODGE";
    feat_names[26] = "EMPOWER_SPELL";
    feat_names[27] = "ENDURANCE";
    feat_names[28] = "ENLARGE_SPELL";
    feat_names[29] = "ESCHEW_MATERIALS";
    feat_names[30] = "EXOTIC_WEAPON_PROFICIENCY";
    feat_names[31] = "EXTEND_SPELL";
    feat_names[32] = "EXTRA_TURNING";
    feat_names[33] = "FAR_SHOT";
    feat_names[34] = "FORGE_RING";
    feat_names[35] = "GREAT_CLEAVE";
    feat_names[36] = "GREAT_FORTITUDE";
    feat_names[37] = "GREATER_SPELL_FOCUS";
    feat_names[38] = "GREATER_SPELL_PENETRATION";
    feat_names[39] = "GREATER_TWO_WEAPON_FIGHTING";
    feat_names[40] = "GREATER_WEAPON_FOCUS";
    feat_names[41] = "GREATER_WEAPON_SPECIALIZATION";
    feat_names[42] = "HEIGHTEN_SPELL";
    feat_names[43] = "IMPROVED_BULL_RUSH";
    feat_names[44] = "IMPROVED_COUNTERSPELL";
    feat_names[45] = "IMPROVED_CRITICAL";
    feat_names[46] = "IMPROVED_DISARM";
    feat_names[47] = "IMPROVED_FEINT";
    feat_names[48] = "IMPROVED_GRAPPLE";
    feat_names[49] = "IMPROVED_INITIATIVE";
    feat_names[50] = "IMPROVED_OVERRUN";
    feat_names[51] = "IMPROVED_PRECISE_SHOT";
    feat_names[52] = "IMPROVED_SHIELD_BASH";
    feat_names[53] = "IMPROVED_SUNDER";
    feat_names[54] = "IMPROVED_TRIP";
    feat_names[55] = "IMPROVED_TURNING";
    feat_names[56] = "IMPROVED_TWO_WEAPON_FIGHTING";
    feat_names[57] = "IMPROVED_UNARMED_STRIKE";
    feat_names[58] = "INVESTIGATOR";
    feat_names[59] = "IRON_WILL";
    feat_names[60] = "LEADERSHIP";
    feat_names[61] = "LIGHTNING_REFLEXES";
    feat_names[62] = "MAGICAL_APTITUDE";
    feat_names[63] = "MANYSHOT";
    feat_names[64] = "MARTIAL_WEAPON_PROFICIENCY";
    feat_names[65] = "MAXIMIZE_SPELL";
    feat_names[66] = "MOBILITY";
    feat_names[67] = "MOUNTED_ARCHERY";
    feat_names[68] = "MOUNTED_COMBAT";
    feat_names[69] = "NATURAL_SPELL";
    feat_names[70] = "NEGOTIATOR";
    feat_names[71] = "NIMBLE_FINGERS";
    feat_names[72] = "PERSUASIVE";
    feat_names[73] = "POINT_BLANK_SHOT";
    feat_names[74] = "POWER_ATTACK";
    feat_names[75] = "PRECISE_SHOT";
    feat_names[76] = "QUICK_DRAW";
    feat_names[77] = "QUICKEN_SPELL";
    feat_names[78] = "RAPID_RELOAD";
    feat_names[79] = "RAPID_SHOT";
    feat_names[80] = "RIDE_BY_ATTACK";
    feat_names[81] = "RUN";
    feat_names[82] = "SCRIBE_SCROLL";
    feat_names[83] = "SELF_SUFFICIENT";
    feat_names[84] = "SHIELD_PROFICIENCY";
    feat_names[85] = "SHOT_ON_THE_RUN";
    feat_names[86] = "SILENT_SPELL";
    feat_names[87] = "SIMPLE_WEAPON_PROFICIENCY";
    feat_names[88] = "SKILL_FOCUS";
    feat_names[89] = "SNATCH_ARROWS";
    feat_names[90] = "SPELL_FOCUS";
    feat_names[91] = "SPELL_MASTERY";
    feat_names[92] = "SPELL_PENETRATION";
    feat_names[93] = "SPIRITED_CHARGE";
    feat_names[94] = "SPRING_ATTACK";
    feat_names[95] = "STEALTHY";
    feat_names[96] = "STILL_SPELL";
    feat_names[97] = "STUNNING_FIST";
    feat_names[98] = "TOUGHNESS";
    feat_names[99] = "TOWER_SHIELD_PROFICIENCY";
    feat_names[100] = "TRACK";
    feat_names[101] = "TRAMPLE";
    feat_names[102] = "TWO_WEAPON_DEFENCE";
    feat_names[103] = "TWO_WEAPON_FIGHTING";
    feat_names[104] = "WEAPON_FINESSE";
    feat_names[105] = "WEAPON_FOCUS";
    feat_names[106] = "WEAPON_SPECIALIZATION";
    feat_names[107] = "WHIRLWIND_ATTACK";
    feat_names[108] = "WIDEN_SPELL";
 
    // define the values for equipment (there are quite a few)
    // starting with the weapons
    eq_name[0] = "Gauntlet"; eq_cost[0] = 2.0; eq_bonus[0] = " ";
    eq_name[1] = "Dagger"; eq_cost[1] = 2.0; eq_bonus[1] = "1d4";
    eq_name[2] = "Dagger, punching"; eq_cost[2] = 2.0; eq_bonus[2] = "1d4";
    eq_name[3] = "Gauntlet, spiked"; eq_cost[3] = 5.0; eq_bonus[3] = "1d4";
    eq_name[4] = "Mace, light"; eq_cost[4] = 5.0; eq_bonus[4] = "1d6";
    eq_name[5] = "Sickle"; eq_cost[5] = 6.0; eq_bonus[5] = "1d6";
    eq_name[6] = "Club"; eq_cost[6] = 0.0; eq_bonus[6] = "1d6";
    eq_name[7] = "Halfspear"; eq_cost[7] = 1.0; eq_bonus[7] = "1d6";
    eq_name[8] = "Mace, heavy"; eq_cost[8] = 12.0; eq_bonus[8] = "1d8";
    eq_name[9] = "Morningstar"; eq_cost[9] = 8.0; eq_bonus[9] = "1d8";
    eq_name[10] = "Quarterstaff"; eq_cost[10] = 0.0; eq_bonus[10] = "1d6";
    eq_name[11] = "Shortspear"; eq_cost[11] = 2.0; eq_bonus[11] = "1d8";
    eq_name[12] = "Crossbow, light"; eq_cost[12] = 35.0; eq_bonus[12] = "1d8";
    eq_name[13] = "Bolts (10)"; eq_cost[13] = 1.0; eq_bonus[13] = " ";
    eq_name[14] = "Dart"; eq_cost[14] = 0.5; eq_bonus[14] = "1d4";
    eq_name[15] = "Sling"; eq_cost[15] = 0.0; eq_bonus[15] = "1d4";
    eq_name[16] = "Bullets, sling"; eq_cost[16] = 0.1;  eq_bonus[16] = " ";
    eq_name[17] = "Crossbow, heavy"; eq_cost[17] = 50.0; eq_bonus[17] = "1d10";
    eq_name[18] = "Javelin"; eq_cost[18] = 1.0; eq_bonus[18] = "1d6";
    // random easter egg -- Hi!
    eq_name[19] = "Axe, throwing"; eq_cost[19] = 8.0; eq_bonus[19] = "1d6";
    eq_name[20] = "Hammer, light"; eq_cost[20] = 1.0; eq_bonus[20] = "1d4";
    eq_name[21] = "Handaxe"; eq_cost[21] = 6.0; eq_bonus[21] = "1d6";
    eq_name[22] = "Lance, light"; eq_cost[22] = 6.0; eq_bonus[22] = "1d6";
    eq_name[23] = "Pick, light"; eq_cost[23] = 4.0; eq_bonus[23] = "1d4";
    eq_name[24] = "Sap"; eq_cost[24] = 1.0; eq_bonus[24] = "1d6";
    eq_name[25] = "Sword, short"; eq_cost[25] = 10.0; eq_bonus[25] = "1d6";
    eq_name[26] = "Battleaxe"; eq_cost[26] = 10.0; eq_bonus[26] = "1d8";
    eq_name[27] = "Flail, light"; eq_cost[27] = 8.0; eq_bonus[27] = "1d8";
    eq_name[28] = "Lance, heavy"; eq_cost[28] = 10.0; eq_bonus[28] = "1d8";
    eq_name[29] = "Longsword"; eq_cost[29] = 15.0; eq_bonus[29] = "1d8";
    eq_name[30] = "Pick, heavy"; eq_cost[30] = 8.0; eq_bonus[30] = "1d6";
    eq_name[31] = "Rapier"; eq_cost[31] = 20.0; eq_bonus[31] = "1d6";
    eq_name[32] = "Scimitar"; eq_cost[32] = 15.0; eq_bonus[32] = "1d6";
    eq_name[33] = "Trident"; eq_cost[33] = 15.0; eq_bonus[33] = "1d8";
    eq_name[34] = "Warhammer"; eq_cost[34] = 12.0; eq_bonus[34] = "1d8";
    eq_name[35] = "Falchion"; eq_cost[35] = 75.0; eq_bonus[35] = "2d4";
    eq_name[36] = "Flail, heavy"; eq_cost[36] = 15.0; eq_bonus[36] = "1d10";
    eq_name[37] = "Glaive"; eq_cost[37] = 8.0; eq_bonus[37] = "1d10";
    eq_name[38] = "Greataxe"; eq_cost[38] = 20.0; eq_bonus[38] = "1d12";
    eq_name[39] = "Greatclub"; eq_cost[39] = 5.0; eq_bonus[39] = "1d10";
    eq_name[40] = "Greatsword"; eq_cost[40] = 50.0; eq_bonus[40] = "2d6";
    eq_name[41] = "Guisarme"; eq_cost[41] = 9.0; eq_bonus[41] = "2d4";
    eq_name[42] = "Halberd"; eq_cost[42] = 10.0; eq_bonus[42] = "1d10";
    eq_name[43] = "Longspear"; eq_cost[43] = 5.0; eq_bonus[43] = "1d8";
    eq_name[44] = "Ranseur"; eq_cost[44] = 10.0; eq_bonus[44] = "2d4";
    eq_name[45] = "Scythe"; eq_cost[45] = 18.0; eq_bonus[45] = "2d4";
    eq_name[46] = "Shortbow"; eq_cost[46] = 30.0; eq_bonus[46] = "1d6";
    eq_name[47] = "Shortbow, composite"; eq_cost[47] = 75.0; eq_bonus[47] = "1d6";
    eq_name[48] = "Longbow"; eq_cost[48] = 75.0; eq_bonus[48] = "1d8";
    eq_name[49] = "Longbow, composite"; eq_cost[49] = 100.0; eq_bonus[49] = "1d8";
    eq_name[50] = "Arrows (20)"; eq_cost[50] = 1.0; eq_bonus[50] = " ";
    eq_name[51] = "Kama, halfling"; eq_cost[51] = 2.0; eq_bonus[51] = "1d4";
    eq_name[52] = "Kukri"; eq_cost[52] = 8.0; eq_bonus[52] = "1d4";
    eq_name[53] = "Nunchaku, halfling"; eq_cost[53] = 2.0; eq_bonus[53] = "1d4";
    eq_name[54] = "Siangham, halfling"; eq_cost[54] = 2.0; eq_bonus[54] = "1d4";
    eq_name[55] = "Kama"; eq_cost[55] = 2.0; eq_bonus[55] = "1d6";
    eq_name[56] = "Nunchaku"; eq_cost[56] = 2.0; eq_bonus[56] = "1d6";
    eq_name[57] = "Siangham"; eq_cost[57] = 3.0; eq_bonus[57] = "1d6";
    eq_name[58] = "Sword, bastard"; eq_cost[58] = 35.0; eq_bonus[58] = "1d10";
    eq_name[59] = "Waraxe, dwarven"; eq_cost[59] = 30.0; eq_bonus[59] = "1d10";
    eq_name[60] = "Hammer, gnome hooked"; eq_cost[60] = 20.0; eq_bonus[60] = "1d6";
    eq_name[61] = "Axe, orc double"; eq_cost[61] = 60.0; eq_bonus[61] = "1d8";
    eq_name[62] = "Chain, spiked"; eq_cost[62] = 25.0; eq_bonus[62] = "2d4";
    eq_name[63] = "Flail, dire"; eq_cost[63] = 90.0; eq_bonus[63] = "1d8";
    eq_name[64] = "Sword, two-bladed"; eq_cost[64] = 100.0; eq_bonus[64] = "1d8";
    eq_name[65] = "Urgrosh, dwarven"; eq_cost[65] = 50.0; eq_bonus[65] = "1d8";

    // now for the armor (always wear protection...unless you're a monk)
    eq_name[66] = "Padded armor"; eq_cost[66] = 5.0; eq_bonus[66] = "+1";
    eq_name[67] = "Leather"; eq_cost[67] = 10.0; eq_bonus[67] = "+2";
    eq_name[68] = "Studded leather"; eq_cost[68] = 25.0; eq_bonus[68] = "+3";
    eq_name[69] = "Chain shirt"; eq_cost[69] = 100.0; eq_bonus[69] = "+4";
    eq_name[70] = "Hide"; eq_cost[70] = 15.0; eq_bonus[70] = "+3";
    eq_name[71] = "Scale Mail"; eq_cost[71] = 50.0; eq_bonus[71] = "+4";
    eq_name[72] = "Chainmail"; eq_cost[72] = 150.0; eq_bonus[72] = "+5";
    eq_name[73] = "Breastplate"; eq_cost[73] = 200.0; eq_bonus[73] = "+5";
    eq_name[74] = "Splint mail"; eq_cost[74] = 200.0; eq_bonus[74] = "+6";
    eq_name[75] = "Banded mail"; eq_cost[75] = 250.0; eq_bonus[75] = "+6";
    eq_name[76] = "Half-plate"; eq_cost[76] = 600.0; eq_bonus[76] = "+7";
    eq_name[77] = "Full plate"; eq_cost[77] = 1500.0; eq_bonus[77] = "+8";
    eq_name[78] = "Buckler"; eq_cost[78] = 15.0; eq_bonus[78] = "+1";
    eq_name[79] = "Shield, small, wood"; eq_cost[79] = 3.0; eq_bonus[79] = "+1";
    eq_name[80] = "Shield, small, steel"; eq_cost[80] = 9.0; eq_bonus[80] = "+1";
    eq_name[81] = "Shield, large, wood"; eq_cost[81] = 7.0; eq_bonus[81] = "+2";
    eq_name[82] = "Shield, large, steel"; eq_cost[82] = 20.0; eq_bonus[82] = "+2";
    eq_name[83] = "Shield, tower"; eq_cost[83] = 30.0; eq_bonus[83] = " ";
    eq_name[84] = "Armor spikes"; eq_cost[84] = 50.0; eq_bonus[84] = " ";
    eq_name[85] = "Gauntlet, locked"; eq_cost[85] = 8.0; eq_bonus[85] = " ";
    eq_name[86] = "Shield spikes"; eq_cost[86] = 10.0; eq_bonus[86] = " ";
    // On to the misc equipment
    eq_name[87] = "Backpack"; eq_cost[87] = 2.0; eq_bonus[87] = "2lb";
    eq_name[88] = "Barrel"; eq_cost[88] = 2.0; eq_bonus[88] = "30lb";
    eq_name[89] = "Basket"; eq_cost[89] = 0.4; eq_bonus[89] = "1lb";
    eq_name[90] = "Bedroll"; eq_cost[90] = 0.1; eq_bonus[90] = "5lb";
    eq_name[91] = "Bell"; eq_cost[91] = 1.0; eq_bonus[91] = " ";
    eq_name[92] = "Blanket"; eq_cost[92] = 0.5; eq_bonus[92] = "3lb";
    eq_name[93] = "Block n Tackle"; eq_cost[93] = 5.0; eq_bonus[93] = "5lb";
    eq_name[94] = "Bottle"; eq_cost[94] = 2.0; eq_bonus[94] = " ";
    eq_name[95] = "Bucket"; eq_cost[95] = 0.5; eq_bonus[95] = "2lb";
    eq_name[96] = "Caltrops"; eq_cost[96] = 1.0; eq_bonus[96] = "2lb";
    eq_name[97] = "Candle (10)"; eq_cost[97] = 0.1; eq_bonus[97] = " ";
    eq_name[98] = "Canvas"; eq_cost[98] = 0.1; eq_bonus[98] = "1lb";
    eq_name[99] = "Case"; eq_cost[99] = 1.0; eq_bonus[99] = " ";
    eq_name[100] = "Chain (10ft)"; eq_cost[100] = 30.0; eq_bonus[100] = "2lb";
    eq_name[101] = "Chalk (10)"; eq_cost[101] = 0.1; eq_bonus[101] = " ";
    eq_name[102] = "Chest"; eq_cost[102] = 2.0; eq_bonus[102] = "25lb";
    eq_name[103] = "Crowbar"; eq_cost[103] = 2.0; eq_bonus[103] = "5lb";
    eq_name[104] = "Firewood (10 days)"; eq_cost[104] = 0.1; eq_bonus[104] = "200lb";
    eq_name[105] = "Fishhook"; eq_cost[105] = 0.1; eq_bonus[105] = " ";
    eq_name[106] = "Fishing net"; eq_cost[106] = 4.0; eq_bonus[106] = "5lb";
    eq_name[107] = "Flask (3)"; eq_cost[107] = 0.1; eq_bonus[107] = " ";
    eq_name[108] = "Flint/steel"; eq_cost[108] = 1.0; eq_bonus[108] = " ";
    eq_name[109] = "Grappling hook"; eq_cost[109] = 1.0; eq_bonus[109] = "4lb";
    eq_name[110] = "Hammer"; eq_cost[110] = 0.5; eq_bonus[110] = "2lb";
    eq_name[111] = "Ink"; eq_cost[111] = 8.0; eq_bonus[111] = " ";
    eq_name[112] = "Inkpen"; eq_cost[112] = 0.1; eq_bonus[112] = " ";
    eq_name[113] = "Jug (3)"; eq_cost[113] = 0.1; eq_bonus[113] = "27lb";
    eq_name[114] = "Ladder (20ft)"; eq_cost[114] = 0.1; eq_bonus[114] = "40lb";
    eq_name[115] = "Lamp"; eq_cost[115] = 0.1; eq_bonus[115] = "1lb";
    eq_name[116] = "Lantern, bullseye"; eq_cost[116] = 12.0; eq_bonus[116] = "3lb";
    eq_name[117] = "Lantern, hooded"; eq_cost[117] = 7.0; eq_bonus[117] = "2lb";
    eq_name[118] = "Lock"; eq_cost[118] = 40.0; eq_bonus[118] = "1lb";
    eq_name[119] = "Manacles"; eq_cost[119] = 15.0; eq_bonus[119] = "2lb";
    eq_name[120] = "Mirror"; eq_cost[120] = 10.0; eq_bonus[120] = " ";
    eq_name[121] = "Mug"; eq_cost[121] = 0.0; eq_bonus[121] = "1lb";
    eq_name[122] = "Oil"; eq_cost[122] = 0.1; eq_bonus[122] = "1lb";
    eq_name[123] = "Paper"; eq_cost[123] = 0.4; eq_bonus[123] = " ";
    eq_name[124] = "Parchment"; eq_cost[124] = 0.2; eq_bonus[124] = " ";
    eq_name[125] = "Pick, miner's"; eq_cost[125] = 3.0; eq_bonus[125] = "10lb";
    eq_name[126] = "Pitcher, clay"; eq_cost[126] = 0.0; eq_bonus[126] = "5lb";
    eq_name[127] = "Piton"; eq_cost[127] = 0.1; eq_bonus[127] = " ";
    eq_name[128] = "Pole (10ft)"; eq_cost[128] = 0.2; eq_bonus[128] = "8lb";
    eq_name[129] = "Pot, iron"; eq_cost[129] = 0.5; eq_bonus[129] = "10lb";
    eq_name[130] = "Pouch, belt"; eq_cost[130] = 1.0; eq_bonus[130] = "3lb";
    eq_name[131] = "Ram"; eq_cost[131] = 10.0; eq_bonus[131] = "20lb";
    eq_name[132] = "Rations"; eq_cost[132] = 0.5; eq_bonus[132] = "1lb";
    eq_name[133] = "Rope (50ft)"; eq_cost[133] = 1.0; eq_bonus[133] = "5lb";
    eq_name[134] = "Sack"; eq_cost[134] = 0.1; eq_bonus[134] = " ";
    eq_name[135] = "Sealing wax"; eq_cost[135] = 1.0; eq_bonus[135] = "1lb";
    eq_name[136] = "Sewing needle"; eq_cost[136] = 0.5; eq_bonus[136] = " ";
    eq_name[137] = "Signal whistle"; eq_cost[137] = 0.8; eq_bonus[137] = " ";
    eq_name[138] = "Signet ring"; eq_cost[138] = 5.0; eq_bonus[138] = " ";
    eq_name[139] = "Sledge"; eq_cost[139] = 1.0; eq_bonus[139] = "10lb";
    eq_name[140] = "Soap"; eq_cost[140] = 0.5; eq_bonus[140] = "1lb";
    eq_name[141] = "Spade"; eq_cost[141] = 2.0; eq_bonus[141] = "8lb";
    eq_name[142] = "Spyglass"; eq_cost[142] = 1000.0; eq_bonus[142] = "1lb";
    eq_name[143] = "Tent"; eq_cost[143] = 10.0; eq_bonus[143] = "20lb";
    eq_name[144] = "Torch"; eq_cost[144] = 0.0; eq_bonus[144] = "1lb";
    eq_name[145] = "Vial"; eq_cost[145] = 1.0; eq_bonus[145] = " ";
    eq_name[146] = "Waterskin"; eq_cost[146] = 1.0; eq_bonus[146] = "4lb";
    eq_name[147] = "Whetstone"; eq_cost[147] = 0.0; eq_bonus[147] = "1lb";

    // special substances and items
    eq_name[148] = "Acid flask"; eq_cost[148] = 10.0; eq_bonus[148] = "1lb";
    eq_name[149] = "Alchemist's fire"; eq_cost[149] = 20.0; eq_bonus[149] = "1lb";
    eq_name[150] = "Antitoxin"; eq_cost[150] = 50.0; eq_bonus[150] = " ";
    eq_name[151] = "Everburning torch"; eq_cost[151] = 110.0; eq_bonus[151] = "1lb";
    eq_name[152] = "Holy water"; eq_cost[152] = 25.0; eq_bonus[152] = "1lb";
    eq_name[153] = "Smokestick"; eq_cost[153] = 20.0; eq_bonus[153] = "1lb";
    eq_name[154] = "Sunrod"; eq_cost[154] = 2.0; eq_bonus[154] = "1lb";
    eq_name[155] = "Tranglefoot bag"; eq_cost[155] = 50.0; eq_bonus[155] = "4lb";
    eq_name[156] = "Thunderstone"; eq_cost[156] = 30.0; eq_bonus[156] = "1lb";
    eq_name[157] = "Tindertwig"; eq_cost[157] = 1.0; eq_bonus[157] = " ";
  
    // tools and kits
    eq_name[158] = "Alchemist's Lab"; eq_cost[158] = 500.0; eq_bonus[158] = "40lb";
    eq_name[159] = "Artisan's tools"; eq_cost[159] = 5.0; eq_bonus[159] = "5lb";
    eq_name[160] = "Artisan's tools, masterwork"; eq_cost[160] = 55.0; eq_bonus[160] = "5lb";
    eq_name[161] = "Climber's kit"; eq_cost[161] = 80.0; eq_bonus[161] = "5lb";
    eq_name[162] = "Disguise kit"; eq_cost[162] = 50.0; eq_bonus[162] = "8lb";
    eq_name[163] = "Healer's kit"; eq_cost[163] = 50.0; eq_bonus[163] = "1lb";
    eq_name[164] = "Holly and Mistletoe"; eq_cost[164] = 0.0; eq_bonus[164] = " ";
    eq_name[165] = "Holy Symbol, wood"; eq_cost[165] = 1.0; eq_bonus[165] = " ";
    eq_name[166] = "Holy Symbol, silver"; eq_cost[166] = 25.0; eq_bonus[166] = "1lb";
    eq_name[167] = "Hourglass"; eq_cost[167] = 25.0; eq_bonus[167] = "1lb";
    eq_name[168] = "Magnifying glass"; eq_cost[168] = 100.0; eq_bonus[168] = " ";
    eq_name[169] = "Musical instrument"; eq_cost[169] = 5.0; eq_bonus[169] = "3lb";
    eq_name[170] = "Musical instrument, masterwork"; eq_cost[170] = 100.0; eq_bonus[170] = "3lb";
    eq_name[171] = "Merchant scale"; eq_cost[171] = 2.0; eq_bonus[171] = "1lb";
    eq_name[172] = "Spell component pouch"; eq_cost[172] = 5.0; eq_bonus[172] = "2lb";
    eq_name[173] = "Spell book"; eq_cost[173] = 15.0; eq_bonus[173] = "3lb";
    eq_name[174] = "Thieves' tools"; eq_cost[174] = 30.0; eq_bonus[174] = "1lb";
    eq_name[175] = "Thieves' tools, masterwork"; eq_cost[175] = 100.0; eq_bonus[175] = "2lb";
    eq_name[176] = "Tool, masterwork"; eq_cost[176] = 50.0; eq_bonus[176] = "1lb";
    eq_name[177] = "Water clock"; eq_cost[177] = 1000.0; eq_bonus[177] = "200lb";

    // clothes for the cold hero
    eq_name[178] = "Artisan's outfit"; eq_cost[178] = 1.0; eq_bonus[178] = "4lb";
    eq_name[179] = "Cleric's vestments"; eq_cost[179] = 5.0; eq_bonus[179] = "6lb";
    eq_name[180] = "Cold weather outfit"; eq_cost[180] = 8.0; eq_bonus[180] = "7lb";
    eq_name[181] = "Coutier's outfit"; eq_cost[181] = 30.0; eq_bonus[181] = "6lb";
    eq_name[182] = "Entertainer's outfit"; eq_cost[182] = 3.0; eq_bonus[182] = "4lb";
    eq_name[183] = "Explorer's outfit"; eq_cost[183] = 10.0; eq_bonus[183] = "8lb";
    eq_name[184] = "Monk's outfit"; eq_cost[184] = 5.0; eq_bonus[184] = "2lb";
    eq_name[185] = "Noble's outfit"; eq_cost[185] = 75.0; eq_bonus[185] = "10lb";
    eq_name[186] = "Peasant's outfit"; eq_cost[186] = 0.1; eq_bonus[186] = "2lb";
    eq_name[187] = "Royal outfit"; eq_cost[187] = 200.0; eq_bonus[187] = "15lb";
    eq_name[188] = "Scholar's outfit"; eq_cost[188] = 5.0; eq_bonus[188] = "6lb";
    eq_name[189] = "Traveler's outfit"; eq_cost[189] = 1.0; eq_bonus[189] = "5lb";

    // mounts and mounts' equipment
    eq_name[190] = "Bit and Bridle"; eq_cost[190] = 2.0; eq_bonus[190] = "1lb";
    eq_name[191] = "Guard dog"; eq_cost[191] = 25.0; eq_bonus[191] = " ";
    eq_name[192] = "Riding dog"; eq_cost[192] = 150.0; eq_bonus[192] = " ";
    eq_name[193] = "Donkey"; eq_cost[193] = 8.0; eq_bonus[193] = " ";
    eq_name[194] = "Feed per day"; eq_cost[194] = 0.1; eq_bonus[194] = "10lb";
    eq_name[195] = "Horse, heavy"; eq_cost[195] = 200.0; eq_bonus[195] = " ";
    eq_name[196] = "Horse, light"; eq_cost[196] = 75.0; eq_bonus[196] = " ";
    eq_name[197] = "Pony"; eq_cost[197] = 30.0; eq_bonus[197] = " ";
    eq_name[198] = "Warhorse, heavy"; eq_cost[198] = 400.0; eq_bonus[198] = " ";
    eq_name[199] = "Warhorse, light"; eq_cost[199] = 150.0; eq_bonus[199] = " ";
    eq_name[200] = "Warpony"; eq_cost[200] = 100.0; eq_bonus[200] = " ";
    // whew, 200 down, a bunch more to go
    eq_name[201] = "Military saddle"; eq_cost[201] = 20.0; eq_bonus[201] = "30lb";
    eq_name[202] = "Pack saddle"; eq_cost[202] = 5.0; eq_bonus[202] = "15lb";
    eq_name[203] = "Riding saddle"; eq_cost[203] = 10.0; eq_bonus[203] = "25lb";
    eq_name[204] = "Exotic military saddle"; eq_cost[204] = 60.0; eq_bonus[204] = "40lb";
    eq_name[205] = "Exotic pack saddle"; eq_cost[205] = 15.0; eq_bonus[205] = "20lb";
    eq_name[206] = "Exotic riding saddle"; eq_cost[206] = 30.0; eq_bonus[206] = "30lb";
    eq_name[207] = "Saddlebags"; eq_cost[207] = 4.0; eq_bonus[207] = "8lb";

    // transport
    eq_name[208] = "Carriage"; eq_cost[208] = 100.0; eq_bonus[208] = "600lb";
    eq_name[209] = "Cart"; eq_cost[209] = 15.0; eq_bonus[209] = "200lb";
    eq_name[210] = "Galley"; eq_cost[210] = 30000.0; eq_bonus[210] = " ";
    eq_name[211] = "Keelboat"; eq_cost[211] = 3000.0; eq_bonus[211] = " ";
    eq_name[212] = "Longship"; eq_cost[212] = 10000.0; eq_bonus[212] = " ";
    eq_name[213] = "Rowboat"; eq_cost[213] = 50.0; eq_bonus[213] = "100lb";
    eq_name[214] = "Sailing ship"; eq_cost[214] = 10000.0; eq_bonus[214] = " ";
    eq_name[215] = "Sled"; eq_cost[215] = 20.0; eq_bonus[215] = "300lb";
    eq_name[216] = "Wagon"; eq_cost[216] = 35.0; eq_bonus[216] = "400lb";
    eq_name[217] = "Warship"; eq_cost[217] = 25000.0; eq_bonus[217] = " ";


    // spells
    // These varibles determine the character's specialization and
    // which domains he/she will give up. This is for wizards only.
    var special_spell_domain = "none";
    var restricted_spell_domain = new Array(2);
    restricted_spell_domain[0] = "none";
    restricted_spell_domain[1] = "none";

    // This array holds the number of spells the character can get
    // per each wizard level.
    var num_wizard_spells = new Array(10);
    // This array shows how many spells, per level, the character has selected.
    var wizard_spells = new Array(10);

    // This array holds the number of sorcerer spells
    // the character can get per level
    var num_sorcerer_spells = new Array(10);
    // This array shows how many spells, per level, the character has selected
    var sorcerer_spells = new Array(10);

    // The below section outlines definitions for sorcerer/wizard spells
    // define an array with 10 spell levels and allow for 50 spells per level.
    var wizard_spell_name = new Array(10);
    // define an array for each spell, which will hold the spell's domain
    var wizard_spell_domain = new Array(10);

    // define varibles for bard spells
    var num_bard_spells = new Array(7);   // bard spells we can learn
    var bard_spells = new Array(7);       // bard spells we know
    var bard_spell_name = new Array(7);   // names of bard spells

    // use the "count" varible to create the second dimension for each multi
    // dimensional array.
    var count;     // just a counter 
    for (count = 0; count < 10; count++)
    {
        wizard_spells[count] = new Array(50);       // wizard spells the char has
        sorcerer_spells[count] = new Array(50);     // sorcerer spells the char has
        wizard_spell_name[count] = new Array(50);   // list of spells by name
        wizard_spell_domain[count] = new Array(50); // list of spells by domain
    }

    for (count = 0; count < 7; count++)
    {
        bard_spells[count] = new Array(40);   // spells we know
        bard_spell_name[count] = new Array(40);     // names of bard spells
    }

    // bard spell names are defined below the wizard/sorcerer list

    // we now get to the fun part of giving each wizard/sorcerer spell
    // a name and domain
    wizard_spell_name[0][0] = "Resistance"; wizard_spell_domain[0][0] = "Abjur";
    wizard_spell_name[0][1] = "Acid Splash"; wizard_spell_domain[0][1] = "Conj";
    wizard_spell_name[0][2] = "Detect Poison"; wizard_spell_domain[0][2] = "Div";
    wizard_spell_name[0][3] = "Read Magic"; wizard_spell_domain[0][3] = "Div";
    wizard_spell_name[0][4] = "Daze"; wizard_spell_domain[0][4] = "Ench";
    wizard_spell_name[0][5] = "Dancing Lights"; wizard_spell_domain[0][5] = "Evoc";
    wizard_spell_name[0][6] = "Flare"; wizard_spell_domain[0][6] = "Evoc";
    wizard_spell_name[0][7] = "Light"; wizard_spell_domain[0][7] = "Evoc";
    wizard_spell_name[0][8] = "Ray of Frost"; wizard_spell_domain[0][8] = "Evoc";
    wizard_spell_name[0][9] = "Ghost Sound"; wizard_spell_domain[0][9] = "Illus";
    wizard_spell_name[0][10] = "Disrupt Undead"; wizard_spell_domain[0][10] = "Necro";
    wizard_spell_name[0][11] = "Touch Fatigue"; wizard_spell_domain[0][11] = "Necro";
    wizard_spell_name[0][12] = "Mage Hand"; wizard_spell_domain[0][12] = "Trans";
    wizard_spell_name[0][13] = "Mending"; wizard_spell_domain[0][13] = "Trans";
    wizard_spell_name[0][14] = "Message"; wizard_spell_domain[0][14] = "Trans";
    wizard_spell_name[0][15] = "Open/Close"; wizard_spell_domain[0][15] = "Trans";
    wizard_spell_name[0][16] = "Acrane Mark"; wizard_spell_domain[0][16] = "Univ";
    wizard_spell_name[0][17] = "Prestidigitation"; wizard_spell_domain[0][17] = "Univ";
    wizard_spell_name[0][18] = "Detect Magic"; wizard_spell_domain[0][18] = "Div";
    wizard_spell_name[0][19] = " "; wizard_spell_domain[0][19] = "NA";


    wizard_spell_name[1][0] = "Alarm"; wizard_spell_domain[1][0] = "Abjur";
    wizard_spell_name[1][1] = "Endure Elements"; wizard_spell_domain[1][1] = "Abjur";
    wizard_spell_name[1][2] = "Hold Portal"; wizard_spell_domain[1][2] = "Abjur";
    wizard_spell_name[1][3] = "Protection from (Alignment)"; wizard_spell_domain[1][3] = "Abjur";
    wizard_spell_name[1][4] = "Shield"; wizard_spell_domain[1][4] = "Abjur";
    wizard_spell_name[1][5] = "Grease"; wizard_spell_domain[1][5] = "Conj";
    wizard_spell_name[1][6] = "Mage Armor"; wizard_spell_domain[1][6] = "Conj";
    wizard_spell_name[1][7] = "Mount"; wizard_spell_domain[1][7] = "Conj";
    wizard_spell_name[1][8] = "Obscuring Mist"; wizard_spell_domain[1][8] = "Conj";
    wizard_spell_name[1][9] = "Summon Monster I"; wizard_spell_domain[1][9] = "Conj";
    wizard_spell_name[1][10] = "Unseen Servant"; wizard_spell_domain[1][10] = "Conj";
    wizard_spell_name[1][11] = "Comprehend Languages"; wizard_spell_domain[1][11] = "Div";
    wizard_spell_name[1][12] = "Detect Secret doors"; wizard_spell_domain[1][12] = "Div";
    wizard_spell_name[1][13] = "Detect Undead"; wizard_spell_domain[1][13] = "Div";
    wizard_spell_name[1][14] = "Identify"; wizard_spell_domain[1][14] = "Div";
    wizard_spell_name[1][15] = "True Strike"; wizard_spell_domain[1][15] = "Div";
    wizard_spell_name[1][16] = "Charm Person"; wizard_spell_domain[1][16] = "Ench";
    wizard_spell_name[1][17] = "Hypnotism"; wizard_spell_domain[1][17] = "Ench";
    wizard_spell_name[1][18] = "Sleep"; wizard_spell_domain[1][18] = "Ench";
    wizard_spell_name[1][19] = "Burning Hands"; wizard_spell_domain[1][19] = "Evoc";
    wizard_spell_name[1][20] = "Magic Missle"; wizard_spell_domain[1][20] = "Evoc";
    wizard_spell_name[1][21] = "Shocking Grasp"; wizard_spell_domain[1][21] = "Evoc";
    wizard_spell_name[1][22] = "Tenser's Floating Disk"; wizard_spell_domain[1][22] = "Evoc";
    wizard_spell_name[1][23] = "Color Srpay"; wizard_spell_domain[1][23] = "Illus";
    wizard_spell_name[1][24] = "Disguise Self"; wizard_spell_domain[1][24] = "Illus";
    wizard_spell_name[1][25] = "Nystul's Magic Aura"; wizard_spell_domain[1][25] = "Illus";
    wizard_spell_name[1][26] = "Silent Image"; wizard_spell_domain[1][26] = "Illus";
    wizard_spell_name[1][27] = "Ventriloquism"; wizard_spell_domain[1][27] = "Illus";
    wizard_spell_name[1][28] = "Cause Fear"; wizard_spell_domain[1][28] = "Necro";
    wizard_spell_name[1][29] = "Chill Touch"; wizard_spell_domain[1][29] = "Necro";
    wizard_spell_name[1][30] = "Ray of Enfeeblement"; wizard_spell_domain[1][30] = "Necro";
    wizard_spell_name[1][31] = "Animate Rope"; wizard_spell_domain[1][31] = "Trans";
    wizard_spell_name[1][32] = "Enlarge Person"; wizard_spell_domain[1][32] = "Trans";
    wizard_spell_name[1][33] = "Erase"; wizard_spell_domain[1][33] = "Trans";
    wizard_spell_name[1][34] = "Expeditious Retreat"; wizard_spell_domain[1][34] = "Trans";
    wizard_spell_name[1][35] = "Feather Fall"; wizard_spell_domain[1][35] = "Trans";
    wizard_spell_name[1][36] = "Jump"; wizard_spell_domain[1][36] = "Trans";
    wizard_spell_name[1][37] = "Magic Weapon"; wizard_spell_domain[1][37] = "Trans";
    wizard_spell_name[1][38] = "Reduce Person"; wizard_spell_domain[1][38] = "Trans";
    wizard_spell_name[1][39] = " "; wizard_spell_domain[1][39] = "NA";

    wizard_spell_name[2][0] = "Arcane Lock"; wizard_spell_domain[2][0] = "Abjur";
    wizard_spell_name[2][1] = "Obscure Object"; wizard_spell_domain[2][1] = "Abjur";
    wizard_spell_name[2][2] = "Protection from Arrows"; wizard_spell_domain[2][2] = "Abjur";
    wizard_spell_name[2][3] = "Resist Energy"; wizard_spell_domain[2][3] = "Abjur";
    wizard_spell_name[2][4] = "Fog Cloud"; wizard_spell_domain[2][4] = "Conj";
    wizard_spell_name[2][5] = "Glitterdust"; wizard_spell_domain[2][5] = "Conj";
    wizard_spell_name[2][6] = "Melf's Acid Arrow"; wizard_spell_domain[2][6] = "Conj";
    wizard_spell_name[2][7] = "Summon Monster II"; wizard_spell_domain[2][7] = "Conj";
    wizard_spell_name[2][8] = "Summon Swarm"; wizard_spell_domain[2][8] = "Conj";
    wizard_spell_name[2][9] = "Web"; wizard_spell_domain[2][9] = "Conj";
    wizard_spell_name[2][10] = "Detect Thoughts"; wizard_spell_domain[2][10] = "Div";
    wizard_spell_name[2][11] = "Locate Object"; wizard_spell_domain[2][11] = "Div";
    wizard_spell_name[2][12] = "See Inivisility"; wizard_spell_domain[2][12] = "Div";
    wizard_spell_name[2][13] = "Daze Monster"; wizard_spell_domain[2][13] = "Ench";
    wizard_spell_name[2][14] = "Tasha's Hideous Laughter"; wizard_spell_domain[2][14] = "Ench";
    wizard_spell_name[2][15] = "Touch of Idiocy"; wizard_spell_domain[2][15] = "Ench";
    wizard_spell_name[2][16] = "Continual Flame"; wizard_spell_domain[2][16] = "Evoc";
    wizard_spell_name[2][17] = "Darkness"; wizard_spell_domain[2][17] = "Evoc";
    wizard_spell_name[2][18] = "Flaming Sphere"; wizard_spell_domain[2][18] = "Evoc";
    wizard_spell_name[2][19] = "Gust of Wind"; wizard_spell_domain[2][19] = "Evoc";
    wizard_spell_name[2][20] = "Scorching Ray"; wizard_spell_domain[2][20] = "Evoc";
    wizard_spell_name[2][21] = "Shatter"; wizard_spell_domain[2][21] = "Evoc";
    wizard_spell_name[2][22] = "Blur"; wizard_spell_domain[2][22] = "Illus";
    wizard_spell_name[2][23] = "Hypnotic Pattern"; wizard_spell_domain[2][23] = "Illus";
    wizard_spell_name[2][24] = "Invisibility"; wizard_spell_domain[2][24] = "Illus";
    wizard_spell_name[2][25] = "Leomund's Trap"; wizard_spell_domain[2][25] = "Illus";
    wizard_spell_name[2][26] = "Magic Mouth"; wizard_spell_domain[2][26] = "Illus";
    wizard_spell_name[2][27] = "Minor Image"; wizard_spell_domain[2][27] = "Illus";
    wizard_spell_name[2][28] = "Mirror Image"; wizard_spell_domain[2][28] = "Illus";
    wizard_spell_name[2][29] = "Misdirection"; wizard_spell_domain[2][29] = "Illus";
    wizard_spell_name[2][30] = "Blindness/Deafness"; wizard_spell_domain[2][30] = "Necro";
    wizard_spell_name[2][31] = "Command Undead"; wizard_spell_domain[2][31] = "Necro";
    wizard_spell_name[2][32] = "False Life"; wizard_spell_domain[2][32] = "Necro";
    wizard_spell_name[2][33] = "Ghoul Touch"; wizard_spell_domain[2][33] = "Necro";
    wizard_spell_name[2][34] = "Scare"; wizard_spell_domain[2][34] = "Necro";
    wizard_spell_name[2][35] = "Spectral Hand"; wizard_spell_domain[2][35] = "Necro";
    wizard_spell_name[2][36] = "Alter Self"; wizard_spell_domain[2][36] = "Trans";
    wizard_spell_name[2][37] = "Bear's Enduance"; wizard_spell_domain[2][37] = "Trans";
    wizard_spell_name[2][38] = "Bull's Strength"; wizard_spell_domain[2][38] = "Trans";
    wizard_spell_name[2][39] = "Cat's Grace"; wizard_spell_domain[2][39] = "Trans";
    wizard_spell_name[2][40] = "Darkvision"; wizard_spell_domain[2][40] = "Trans";
    wizard_spell_name[2][41] = "Eagle's Splendor"; wizard_spell_domain[2][41] = "Trans";
    wizard_spell_name[2][42] = "Fox's Cunning"; wizard_spell_domain[2][42] = "Trans";
    wizard_spell_name[2][43] = "Knock"; wizard_spell_domain[2][43] = "Trans";
    wizard_spell_name[2][44] = "Levitate"; wizard_spell_domain[2][44] = "Trans";
    wizard_spell_name[2][45] = "Owl's Wisdom"; wizard_spell_domain[2][45] = "Trans";
    wizard_spell_name[2][46] = "Pyrotechnics"; wizard_spell_domain[2][46] = "Trans";
    wizard_spell_name[2][47] = "Rope Trick"; wizard_spell_domain[2][47] = "Trans";
    wizard_spell_name[2][48] = "Spider Climb"; wizard_spell_domain[2][48] = "Trans";
    wizard_spell_name[2][49] = "Whispering Wind"; wizard_spell_domain[2][49] = "Trans";
    wizard_spell_name[2][50] = " "; wizard_spell_domain[2][50] = "NA";

    wizard_spell_name[3][0] = "Dispel Magic"; wizard_spell_domain[3][0] = "Abjur";
    wizard_spell_name[3][1] = "Explosive Runes"; wizard_spell_domain[3][1] = "Abjur";
    wizard_spell_name[3][2] = "Magic Circle Against (alignment)"; wizard_spell_domain[3][2] = "Abjur";
    wizard_spell_name[3][3] = "Nondetection"; wizard_spell_domain[3][3] = "Abjur";
    wizard_spell_name[3][4] = "Protection from Energy"; wizard_spell_domain[3][4] = "Abjur";
    wizard_spell_name[3][5] = "Phantom Steed"; wizard_spell_domain[3][5] = "Conj";
    wizard_spell_name[3][6] = "Sepia Snake Sigial"; wizard_spell_domain[3][6] = "Conj";
    wizard_spell_name[3][7] = "Sleet Storm"; wizard_spell_domain[3][7] = "Conj";
    wizard_spell_name[3][8] = "Stinking Cloud"; wizard_spell_domain[3][8] = "Conj";
    wizard_spell_name[3][9] = "Summon Monster III"; wizard_spell_domain[3][9] = "Conj";
    wizard_spell_name[3][10] = "Arcane Sight"; wizard_spell_domain[3][10] = "Div";
    wizard_spell_name[3][11] = "Clairaudiance/Clairvoyance"; wizard_spell_domain[3][11] = "Div";
    wizard_spell_name[3][12] = "Tongues"; wizard_spell_domain[3][12] = "Div";
    wizard_spell_name[3][13] = "Deep Slumber"; wizard_spell_domain[3][13] = "Ench";
    wizard_spell_name[3][14] = "Heroism"; wizard_spell_domain[3][14] = "Ench";
    wizard_spell_name[3][15] = "Hold Person"; wizard_spell_domain[3][15] = "Ench";
    wizard_spell_name[3][16] = "Rage"; wizard_spell_domain[3][16] = "Ench";
    wizard_spell_name[3][17] = "Suggstion"; wizard_spell_domain[3][17] = "Ench";
    wizard_spell_name[3][18] = "Daylight"; wizard_spell_domain[3][18] = "Evoc";
    wizard_spell_name[3][19] = "Fireball"; wizard_spell_domain[3][19] = "Evoc";
    wizard_spell_name[3][20] = "Leomund's Tiny Hut"; wizard_spell_domain[3][20] = "Evoc";
    wizard_spell_name[3][21] = "Lightning Bolt"; wizard_spell_domain[3][21] = "Evoc";
    wizard_spell_name[3][22] = "Wind Wall"; wizard_spell_domain[3][22] = "Evoc";
    wizard_spell_name[3][23] = "Displacement"; wizard_spell_domain[3][23] = "Illus";
    wizard_spell_name[3][24] = "Illusory Script"; wizard_spell_domain[3][24] = "Illus";
    wizard_spell_name[3][25] = "Ivisibility Sphere"; wizard_spell_domain[3][25] = "Illus";
    wizard_spell_name[3][26] = "Major Image"; wizard_spell_domain[3][26] = "Illus";
    wizard_spell_name[3][27] = "Gentle Repose"; wizard_spell_domain[3][27] = "Necro";
    wizard_spell_name[3][28] = "Halt Undead"; wizard_spell_domain[3][28] = "Necro";
    wizard_spell_name[3][29] = "Ray of Exhaustion"; wizard_spell_domain[3][29] = "Necro";
    wizard_spell_name[3][30] = "Vampiric Touch"; wizard_spell_domain[3][30] = "Necro";
    wizard_spell_name[3][31] = "Blink"; wizard_spell_domain[3][31] = "Trans";
    wizard_spell_name[3][32] = "Flame Arrow"; wizard_spell_domain[3][32] = "Trans";
    wizard_spell_name[3][33] = "Fly"; wizard_spell_domain[3][33] = "Trans";
    wizard_spell_name[3][34] = "Gaseous Form"; wizard_spell_domain[3][34] = "Trans";
    wizard_spell_name[3][35] = "Haste"; wizard_spell_domain[3][35] = "Trans";
    wizard_spell_name[3][36] = "Keen Edge"; wizard_spell_domain[3][36] = "Trans";
    wizard_spell_name[3][37] = "Magic Weapon, Greater"; wizard_spell_domain[3][37] = "Trans";
    wizard_spell_name[3][38] = "Secret Page"; wizard_spell_domain[3][38] = "Trans";
    wizard_spell_name[3][39] = "Shrink Item"; wizard_spell_domain[3][39] = "Trans";
    wizard_spell_name[3][40] = "Slow"; wizard_spell_domain[3][40] = "Trans";
    wizard_spell_name[3][41] = "Water Breathing"; wizard_spell_domain[3][41] = "Trans";
    wizard_spell_name[3][42] = " "; wizard_spell_domain[3][42] = "NA";
    
    wizard_spell_name[4][0] = "Dimensional Anchor"; wizard_spell_domain[4][0] = "Abjur";
    wizard_spell_name[4][1] = "Fire Trap"; wizard_spell_domain[4][1] = "Abjur";
    wizard_spell_name[4][2] = "Globe of Invulnerability, Lesser"; wizard_spell_domain[4][2] = "Abjur";
    wizard_spell_name[4][3] = "Remove Curse"; wizard_spell_domain[4][3] = "Abjur";
    wizard_spell_name[4][4] = "Stoneskin"; wizard_spell_domain[4][4] = "Abjur";
    wizard_spell_name[4][5] = "Dimensional Door"; wizard_spell_domain[4][5] = "Conj";
    wizard_spell_name[4][6] = "Evard's Black Tentacles"; wizard_spell_domain[4][6] = "Conj";
    wizard_spell_name[4][7] = "Leomund's Secure Shelter"; wizard_spell_domain[4][7] = "Conj";
    wizard_spell_name[4][8] = "Minor Creation"; wizard_spell_domain[4][8] = "Conj";
    wizard_spell_name[4][9] = "Solid Fog"; wizard_spell_domain[4][9] = "Conj";
    wizard_spell_name[4][10] = "Summon Monster IV"; wizard_spell_domain[4][10] = "Conj";
    wizard_spell_name[4][11] = "Arcane Eye"; wizard_spell_domain[4][11] = "Div";
    wizard_spell_name[4][12] = "Detect Scrying"; wizard_spell_domain[4][12] = "Div";
    wizard_spell_name[4][13] = "Locate Creature"; wizard_spell_domain[4][13] = "Div";
    wizard_spell_name[4][14] = "Scrying"; wizard_spell_domain[4][14] = "Div";
    wizard_spell_name[4][15] = "Charm Monster"; wizard_spell_domain[4][15] = "Ench";
    wizard_spell_name[4][16] = "Confusion"; wizard_spell_domain[4][16] = "Ench";
    wizard_spell_name[4][17] = "Crushing Dispair"; wizard_spell_domain[4][17] = "Ench";
    wizard_spell_name[4][18] = "Geas, Lesser"; wizard_spell_domain[4][18] = "Ench";
    wizard_spell_name[4][19] = "Fire Shield"; wizard_spell_domain[4][19] = "Evoc";
    wizard_spell_name[4][20] = "Ice Storm"; wizard_spell_domain[4][20] = "Evoc";
    wizard_spell_name[4][21] = "Otiluke's Resilient Sphere"; wizard_spell_domain[4][21] = "Evoc";
    wizard_spell_name[4][22] = "Shout"; wizard_spell_domain[4][22] = "Evoc";
    wizard_spell_name[4][23] = "Wall of Fire"; wizard_spell_domain[4][23] = "Evoc";
    wizard_spell_name[4][24] = "Wall of Ice"; wizard_spell_domain[4][24] = "Evoc";
    wizard_spell_name[4][25] = "Hallucinary Terrian"; wizard_spell_domain[4][25] = "Illus";
    wizard_spell_name[4][26] = "Illusory Wall"; wizard_spell_domain[4][26] = "Illus";
    wizard_spell_name[4][27] = "Ivisibility, Greater"; wizard_spell_domain[4][27] = "Illus";
    wizard_spell_name[4][28] = "Phantasmal Killer"; wizard_spell_domain[4][28] = "Illus";
    wizard_spell_name[4][29] = "Rainbow Pattern"; wizard_spell_domain[4][29] = "Illus";
    wizard_spell_name[4][30] = "Shadow Conjuration"; wizard_spell_domain[4][30] = "Illus";
    wizard_spell_name[4][31] = "Animate Dead"; wizard_spell_domain[4][31] = "Necro";
    wizard_spell_name[4][32] = "Bestow Curse"; wizard_spell_domain[4][32] = "Necro";
    wizard_spell_name[4][33] = "Contagion"; wizard_spell_domain[4][33] = "Necro";
    wizard_spell_name[4][34] = "Enervation"; wizard_spell_domain[4][34] = "Necro";
    wizard_spell_name[4][35] = "Fear"; wizard_spell_domain[4][35] = "Necro";
    wizard_spell_name[4][36] = "Enlarge Person, Mass"; wizard_spell_domain[4][36] = "Trans";
    wizard_spell_name[4][37] = "Polymorph"; wizard_spell_domain[4][37] = "Trans";
    wizard_spell_name[4][38] = "Rary's Mnemonic Enchancer"; wizard_spell_domain[4][38] = "Trans";
    wizard_spell_name[4][39] = "Reduce Person, Mass"; wizard_spell_domain[4][39] = "Trans";
    wizard_spell_name[4][40] = "Stone Shape"; wizard_spell_domain[4][40] = "Trans";
    wizard_spell_name[4][41] = " "; wizard_spell_domain[4][41] = "NA";
    
    wizard_spell_name[5][0] = "Break Enchantment"; wizard_spell_domain[5][0] = "Abjur";
    wizard_spell_name[5][1] = "Dismissal"; wizard_spell_domain[5][1] = "Abjur";
    wizard_spell_name[5][2] = "Mordenkainen's Private Sanctum"; wizard_spell_domain[5][2] = "Abjur";
    wizard_spell_name[5][3] = "Cloudkill"; wizard_spell_domain[5][3] = "Conj";
    wizard_spell_name[5][4] = "Leomund's Secret Chest"; wizard_spell_domain[5][4] = "Conj";
    wizard_spell_name[5][5] = "Major Creation"; wizard_spell_domain[5][5] = "Conj";
    wizard_spell_name[5][6] = "Mordenkainen's Faithful Hound"; wizard_spell_domain[5][6] = "Conj";
    wizard_spell_name[5][7] = "Planar Binding, Lesser"; wizard_spell_domain[5][7] = "Conj";
    wizard_spell_name[5][8] = "Summon Monster V"; wizard_spell_domain[5][8] = "Conj";
    wizard_spell_name[5][9] = "Telport"; wizard_spell_domain[5][9] = "Conj";
    wizard_spell_name[5][10] = "Wall of Stone"; wizard_spell_domain[5][10] = "Conj";
    wizard_spell_name[5][11] = "Contact other Plane"; wizard_spell_domain[5][11] = "Div";
    wizard_spell_name[5][12] = "Prying Eyes"; wizard_spell_domain[5][12] = "Div";
    wizard_spell_name[5][13] = "Rary's Telepathic Bond"; wizard_spell_domain[5][13] = "Div";
    wizard_spell_name[5][14] = "Dominate Person"; wizard_spell_domain[5][14] = "Ench";
    wizard_spell_name[5][15] = "Feeblemind"; wizard_spell_domain[5][15] = "Ench";
    wizard_spell_name[5][16] = "Hold Monster"; wizard_spell_domain[5][16] = "Ench";
    wizard_spell_name[5][17] = "Mind Fog"; wizard_spell_domain[5][17] = "Ench";
    wizard_spell_name[5][18] = "Symbol of Sleep"; wizard_spell_domain[5][18] = "Ench";
    wizard_spell_name[5][19] = "Bigby's Interposing Hand"; wizard_spell_domain[5][19] = "Evoc";
    wizard_spell_name[5][20] = "Cone of Cold"; wizard_spell_domain[5][20] = "Evoc";
    wizard_spell_name[5][21] = "Sending"; wizard_spell_domain[5][21] = "Evoc";
    wizard_spell_name[5][22] = "Wall of Force"; wizard_spell_domain[5][22] = "Evoc";
    wizard_spell_name[5][23] = "Dream"; wizard_spell_domain[5][23] = "Illus";
    wizard_spell_name[5][24] = "False Vision"; wizard_spell_domain[5][24] = "Illus";
    wizard_spell_name[5][25] = "Mirage Arcana"; wizard_spell_domain[5][25] = "Illus";
    wizard_spell_name[5][26] = "Nightmare"; wizard_spell_domain[5][26] = "Illus";
    wizard_spell_name[5][27] = "Persistent Image"; wizard_spell_domain[5][27] = "Illus";
    wizard_spell_name[5][28] = "Seeming"; wizard_spell_domain[5][28] = "Illus";
    wizard_spell_name[5][29] = "Shadow Evocation"; wizard_spell_domain[5][29] = "Illus";
    wizard_spell_name[5][30] = "Blight"; wizard_spell_domain[5][30] = "Necro";
    wizard_spell_name[5][31] = "Magic Jar"; wizard_spell_domain[5][31] = "Necro";
    wizard_spell_name[5][32] = "Symbol of Pain"; wizard_spell_domain[5][32] = "Necro";
    wizard_spell_name[5][33] = "Waves of Fatigue"; wizard_spell_domain[5][33] = "Necro";
    wizard_spell_name[5][34] = "Animal Growth"; wizard_spell_domain[5][34] = "Trans";
    wizard_spell_name[5][35] = "Baleful Polymorph"; wizard_spell_domain[5][35] = "Trans";
    wizard_spell_name[5][36] = "Fabricate"; wizard_spell_domain[5][36] = "Trans";
    wizard_spell_name[5][37] = "Overland Flight"; wizard_spell_domain[5][37] = "Trans";
    wizard_spell_name[5][38] = "Passwall"; wizard_spell_domain[5][38] = "Trans";
    wizard_spell_name[5][39] = "Telekinesis"; wizard_spell_domain[5][39] = "Trans";
    wizard_spell_name[5][40] = "Transmute Mud to Rock"; wizard_spell_domain[5][40] = "Trans";
    wizard_spell_name[5][41] = "Transmute Rock to Mud"; wizard_spell_domain[5][41] = "Trans";
    wizard_spell_name[5][42] = "Permanency"; wizard_spell_domain[5][42] = "Trans";
    wizard_spell_name[5][43] = " "; wizard_spell_domain[5][43] = "NA";
    
    wizard_spell_name[6][0] = "Antimagic Field"; wizard_spell_domain[6][0] = "Abjur";
    wizard_spell_name[6][1] = "Dispel Magic, Greater"; wizard_spell_domain[6][1] = "Abjur";
    wizard_spell_name[6][2] = "Globe of Invulnerability"; wizard_spell_domain[6][2] = "Abjur";
    wizard_spell_name[6][3] = "Guards and Wards"; wizard_spell_domain[6][3] = "Abjur";
    wizard_spell_name[6][4] = "Repulsion"; wizard_spell_domain[6][4] = "Abjur";
    wizard_spell_name[6][5] = "Acid Fog"; wizard_spell_domain[6][5] = "Conj";
    wizard_spell_name[6][6] = "Planar Binding"; wizard_spell_domain[6][6] = "Conj";
    wizard_spell_name[6][7] = "Summon Monster VI"; wizard_spell_domain[6][7] = "Conj";
    wizard_spell_name[6][8] = "Wall of Iron"; wizard_spell_domain[6][8] = "Conj";
    wizard_spell_name[6][9] = "Analyze Dweomer"; wizard_spell_domain[6][9] = "Div";
    wizard_spell_name[6][10] = "Legend Lore"; wizard_spell_domain[6][10] = "Div";
    wizard_spell_name[6][11] = "True Seeing"; wizard_spell_domain[6][11] = "Div";
    wizard_spell_name[6][12] = "Geas/Quest"; wizard_spell_domain[6][12] = "Ench";
    wizard_spell_name[6][13] = "Heroism, Greater"; wizard_spell_domain[6][13] = "Ench";
    wizard_spell_name[6][14] = "Suggestion, Mass"; wizard_spell_domain[6][14] = "Ench";
    wizard_spell_name[6][15] = "Symbol of Persuasion"; wizard_spell_domain[6][15] = "Ench";
    wizard_spell_name[6][16] = "Bigby's Forceful Hand"; wizard_spell_domain[6][16] = "Evoc";
    wizard_spell_name[6][17] = "Chain Lightning"; wizard_spell_domain[6][17] = "Evoc";
    wizard_spell_name[6][18] = "Contingency"; wizard_spell_domain[6][18] = "Evoc";
    wizard_spell_name[6][19] = "Otiluke's Freezing Sphere"; wizard_spell_domain[6][19] = "Evoc";
    wizard_spell_name[6][20] = "Mislead"; wizard_spell_domain[6][20] = "Illus";
    wizard_spell_name[6][21] = "Permanet Image"; wizard_spell_domain[6][21] = "Illus";
    wizard_spell_name[6][22] = "Programmed Image"; wizard_spell_domain[6][22] = "Illus";
    wizard_spell_name[6][23] = "Shadow Walk"; wizard_spell_domain[6][23] = "Illus";
    wizard_spell_name[6][24] = "Veil"; wizard_spell_domain[6][24] = "Illus";
    wizard_spell_name[6][25] = "Circle of Death"; wizard_spell_domain[6][25] = "Necro";
    wizard_spell_name[6][26] = "Create Undead"; wizard_spell_domain[6][26] = "Necro";
    wizard_spell_name[6][27] = "Eyebite"; wizard_spell_domain[6][27] = "Necro";
    wizard_spell_name[6][28] = "Symbol of Fear"; wizard_spell_domain[6][28] = "Necro";
    wizard_spell_name[6][29] = "Undeath to Death"; wizard_spell_domain[6][29] = "Necro";
    wizard_spell_name[6][30] = "Bear's Endurance, Mass"; wizard_spell_domain[6][30] = "Trans";
    wizard_spell_name[6][31] = "Bull's Strength, Mass"; wizard_spell_domain[6][31] = "Trans";
    wizard_spell_name[6][32] = "Cat's Grace, Mass"; wizard_spell_domain[6][32] = "Trans";
    wizard_spell_name[6][33] = "Control Weather"; wizard_spell_domain[6][33] = "Trans";
    wizard_spell_name[6][34] = "Disintegrate"; wizard_spell_domain[6][34] = "Trans";
    wizard_spell_name[6][35] = "Eagle's Splendor, Mass"; wizard_spell_domain[6][35] = "Trans";
    wizard_spell_name[6][36] = "Flesh to Stone"; wizard_spell_domain[6][36] = "Trans";
    wizard_spell_name[6][37] = "Fox's Cunning, Mass"; wizard_spell_domain[6][37] = "Trans";
    wizard_spell_name[6][38] = "Mordenkainen's Lucubration"; wizard_spell_domain[6][38] = "Trans";
    wizard_spell_name[6][39] = "Move Earth"; wizard_spell_domain[6][39] = "Trans";
    wizard_spell_name[6][40] = "Owl's Wisdom, Mass"; wizard_spell_domain[6][40] = "Trans";
    wizard_spell_name[6][41] = "Stone to Flesh"; wizard_spell_domain[6][41] = "Trans";
    wizard_spell_name[6][42] = "Tenser's Transformation"; wizard_spell_domain[6][42] = "Trans";
    wizard_spell_name[6][43] = " "; wizard_spell_domain[6][43] = "NA";
   
    // this is a pointless easter egg -- Hi! 
    wizard_spell_name[7][0] = "Banishment"; wizard_spell_domain[7][0] = "Abjur";
    wizard_spell_name[7][1] = "Sequester"; wizard_spell_domain[7][1] = "Abjur";
    wizard_spell_name[7][2] = "Spell Turning"; wizard_spell_domain[7][2] = "Abjur";
    wizard_spell_name[7][3] = "Drawmij's Instant Summons"; wizard_spell_domain[7][3] = "Conj";
    wizard_spell_name[7][4] = "Mordenkainen's Magnificent Mansion"; wizard_spell_domain[7][4] = "Conj";
    wizard_spell_name[7][5] = "Phase Door"; wizard_spell_domain[7][5] = "Conj";
    wizard_spell_name[7][6] = "Plane Shift"; wizard_spell_domain[7][6] = "Conj";
    wizard_spell_name[7][7] = "Summon Monster VII"; wizard_spell_domain[7][7] = "Conj";
    wizard_spell_name[7][8] = "Teleport, Greater"; wizard_spell_domain[7][8] = "Conj";
    wizard_spell_name[7][9] = "Telport Object"; wizard_spell_domain[7][9] = "Conj";
    wizard_spell_name[7][10] = "Arcane Sight, Greater"; wizard_spell_domain[7][10] = "Div";
    wizard_spell_name[7][11] = "Scrying, Greater"; wizard_spell_domain[7][11] = "Div";
    wizard_spell_name[7][12] = "Vision"; wizard_spell_domain[7][12] = "Div";
    wizard_spell_name[7][13] = "Hold Person, Mass"; wizard_spell_domain[7][13] = "Ench";
    wizard_spell_name[7][14] = "Insanity"; wizard_spell_domain[7][14] = "Ench";
    wizard_spell_name[7][15] = "Power Word Blind"; wizard_spell_domain[7][15] = "Ench";
    wizard_spell_name[7][16] = "Symbol of Stunning"; wizard_spell_domain[7][16] = "Ench";
    wizard_spell_name[7][17] = "Bigby's Grasping Hand"; wizard_spell_domain[7][17] = "Evoc";
    wizard_spell_name[7][18] = "Delayed Blast Fireball"; wizard_spell_domain[7][18] = "Evoc";
    wizard_spell_name[7][19] = "Forcecage"; wizard_spell_domain[7][19] = "Evoc";
    wizard_spell_name[7][20] = "Mordenkainen's Sword"; wizard_spell_domain[7][20] = "Evoc";
    wizard_spell_name[7][21] = "Prismatic Spray"; wizard_spell_domain[7][21] = "Evoc";
    wizard_spell_name[7][22] = "Ivisibility, Mass"; wizard_spell_domain[7][22] = "Illus";
    wizard_spell_name[7][23] = "Project Image"; wizard_spell_domain[7][23] = "Illus";
    wizard_spell_name[7][24] = "Shadow Conjration, Greater"; wizard_spell_domain[7][24] = "Illus";
    wizard_spell_name[7][25] = "Simulacrum"; wizard_spell_domain[7][25] = "Illus";
    wizard_spell_name[7][26] = "Control Undead"; wizard_spell_domain[7][26] = "Necro";
    wizard_spell_name[7][27] = "Finger of Death"; wizard_spell_domain[7][27] = "Necro";
    wizard_spell_name[7][28] = "Symbol of Weakness"; wizard_spell_domain[7][28] = "Necro";
    wizard_spell_name[7][29] = "Waves of Exhaustion"; wizard_spell_domain[7][29] = "Necro";
    wizard_spell_name[7][30] = "Control Weather"; wizard_spell_domain[7][30] = "Trans";
    wizard_spell_name[7][31] = "Ethereal Jaunt"; wizard_spell_domain[7][31] = "Trans";
    wizard_spell_name[7][32] = "Reverse Gravity"; wizard_spell_domain[7][32] = "Trans";
    wizard_spell_name[7][33] = "Statue"; wizard_spell_domain[7][33] = "Trans";
    wizard_spell_name[7][34] = "Limited Wish"; wizard_spell_domain[7][34] = "Univ";
    wizard_spell_name[7][35] = " "; wizard_spell_domain[7][35] = "NA";

    wizard_spell_name[8][0] = "Dimsensional Lock"; wizard_spell_domain[8][0] = "Abjur";
    wizard_spell_name[8][1] = "Mind Blank"; wizard_spell_domain[8][1] = "Abjur";
    wizard_spell_name[8][2] = "Prismatic Wall"; wizard_spell_domain[8][2] = "Abjur";
    wizard_spell_name[8][3] = "Protection from spells"; wizard_spell_domain[8][3] = "Abjur";
    wizard_spell_name[8][4] = "Incendiary Cloud"; wizard_spell_domain[8][4] = "Conj";
    wizard_spell_name[8][5] = "Maze"; wizard_spell_domain[8][5] = "Conj";
    wizard_spell_name[8][6] = "Planar Binding, Greater"; wizard_spell_domain[8][6] = "Conj";
    wizard_spell_name[8][7] = "Summon Monster VIII"; wizard_spell_domain[8][7] = "Conj";
    wizard_spell_name[8][8] = "Trap the Soul"; wizard_spell_domain[8][8] = "Conj";
    wizard_spell_name[8][9] = "Discern Location"; wizard_spell_domain[8][9] = "Div";
    wizard_spell_name[8][10] = "Moment of Prescience"; wizard_spell_domain[8][10] = "Div";
    wizard_spell_name[8][11] = "Prying Eyes, Greater"; wizard_spell_domain[8][11] = "Div";
    wizard_spell_name[8][12] = "Antipathy"; wizard_spell_domain[8][12] = "Ench";
    wizard_spell_name[8][13] = "Binding"; wizard_spell_domain[8][13] = "Ench";
    wizard_spell_name[8][14] = "Charm Monster, Mass"; wizard_spell_domain[8][14] = "Ench";
    wizard_spell_name[8][15] = "Demand"; wizard_spell_domain[8][15] = "Ench";
    wizard_spell_name[8][16] = "Otto's Irresistable Dance"; wizard_spell_domain[8][16] = "Ench";
    wizard_spell_name[8][17] = "Power Word Stun"; wizard_spell_domain[8][17] = "Ench";
    wizard_spell_name[8][18] = "Symbol of Insanity"; wizard_spell_domain[8][18] = "Ench";
    wizard_spell_name[8][19] = "Sympathy"; wizard_spell_domain[8][19] = "Ench";
    wizard_spell_name[8][20] = "Bigby's Clenched Fist"; wizard_spell_domain[8][20] = "Evoc";
    wizard_spell_name[8][21] = "Otiluke's Telekinetic Sphere"; wizard_spell_domain[8][21] = "Evoc";
    wizard_spell_name[8][22] = "Polar Ray"; wizard_spell_domain[8][22] = "Evoc";
    wizard_spell_name[8][23] = "Shout, Greater"; wizard_spell_domain[8][23] = "Evoc";
    wizard_spell_name[8][24] = "Sunburst"; wizard_spell_domain[8][24] = "Evoc";
    wizard_spell_name[8][25] = "Scintillating Pattern"; wizard_spell_domain[8][25] = "Illus";
    wizard_spell_name[8][26] = "Screen"; wizard_spell_domain[8][26] = "Illus";
    wizard_spell_name[8][27] = "Shadow Evocation, Greater"; wizard_spell_domain[8][27] = "Illus";
    wizard_spell_name[8][28] = "Clone"; wizard_spell_domain[8][28] = "Necro";
    wizard_spell_name[8][29] = "Creater Greater Undead"; wizard_spell_domain[8][29] = "Necro";
    wizard_spell_name[8][30] = "Horrid Wilting"; wizard_spell_domain[8][30] = "Necro";
    wizard_spell_name[8][31] = "Symbol of Death"; wizard_spell_domain[8][31] = "Necro";
    wizard_spell_name[8][32] = "Iron Body"; wizard_spell_domain[8][32] = "Trans";
    wizard_spell_name[8][33] = "Polymorph any Object"; wizard_spell_domain[8][33] = "Trans";
    wizard_spell_name[8][34] = "Temporal Stasis"; wizard_spell_domain[8][34] = "Trans";
    wizard_spell_name[8][35] = " "; wizard_spell_domain[8][35] = "NA";

    wizard_spell_name[9][0] = "Freedom"; wizard_spell_domain[9][0] = "Abjur";
    wizard_spell_name[9][1] = "Imprisonment"; wizard_spell_domain[9][1] = "Abjur";
    wizard_spell_name[9][2] = "Mordenkainen's Disjunction"; wizard_spell_domain[9][2] = "Abjur";
    wizard_spell_name[9][3] = "Prismatic Sphere"; wizard_spell_domain[9][3] = "Abjur";
    wizard_spell_name[9][4] = "Gate"; wizard_spell_domain[9][4] = "Conj";
    wizard_spell_name[9][5] = "Refuge"; wizard_spell_domain[9][5] = "Conj";
    wizard_spell_name[9][6] = "Summon Monster IX"; wizard_spell_domain[9][6] = "Conj";
    wizard_spell_name[9][7] = "Teleportation Circle"; wizard_spell_domain[9][7] = "Conj";
    wizard_spell_name[9][8] = "Foresight"; wizard_spell_domain[9][8] = "Div";
    wizard_spell_name[9][9] = "Dominate Monster"; wizard_spell_domain[9][9] = "Ench";
    wizard_spell_name[9][10] = "Hold Monster, Mass"; wizard_spell_domain[9][10] = "Ench";
    wizard_spell_name[9][11] = "Power Word Kill"; wizard_spell_domain[9][11] = "Ench";
    wizard_spell_name[9][12] = "Bigby's Crushing Hand"; wizard_spell_domain[9][12] = "Evoc";
    wizard_spell_name[9][13] = "Meteor Swarm"; wizard_spell_domain[9][13] = "Evoc";
    wizard_spell_name[9][14] = "Shades"; wizard_spell_domain[9][14] = "Illus";
    wizard_spell_name[9][15] = "Weird"; wizard_spell_domain[9][15] = "Illus";
    wizard_spell_name[9][16] = "Asteral Projection"; wizard_spell_domain[9][16] = "Necro";
    wizard_spell_name[9][17] = "Energy Drain"; wizard_spell_domain[9][17] = "Necro";
    wizard_spell_name[9][18] = "Soul Bind"; wizard_spell_domain[9][18] = "Necro";
    wizard_spell_name[9][19] = "Wail of the Banshee"; wizard_spell_domain[9][19] = "Necro";
    wizard_spell_name[9][20] = "Etherealness"; wizard_spell_domain[9][20] = "Trans";
    wizard_spell_name[9][21] = "Shapechange"; wizard_spell_domain[9][21] = "Trans";
    wizard_spell_name[9][22] = "Time Stop"; wizard_spell_domain[9][22] = "Trans";
    wizard_spell_name[9][23] = "Wish"; wizard_spell_domain[9][23] = "Univ";
    wizard_spell_name[9][24] = " "; wizard_spell_domain[9][24] = "NA";

    // okay, that is the end of the sorcerer/wizard spells

    // now define the bard spell names
    bard_spell_name[0][0] = "Dancing Lights"; bard_spell_name[0][1] = "Daze";
    bard_spell_name[0][2] = "Detect Magic"; bard_spell_name[0][3] = "Flare";
    bard_spell_name[0][4] = "Ghost Sound"; bard_spell_name[0][5] = "Know Direction";
    bard_spell_name[0][6] = "Light"; bard_spell_name[0][7] = "Lullaby";
    bard_spell_name[0][8] = "Mage Hand"; bard_spell_name[0][9] = "Mending";
    bard_spell_name[0][10] = "Message"; bard_spell_name[0][11] = "Open/Close";
    bard_spell_name[0][12] = "Prestidigitation"; bard_spell_name[0][13] = "Read Magic";
    bard_spell_name[0][14] = "Resistance"; bard_spell_name[0][15] = "Summon Instrument";
    bard_spell_name[0][16] = " ";

    bard_spell_name[1][0] = "Alarm"; bard_spell_name[1][1] = "Animate Rope";
    bard_spell_name[1][2] = "Cause Fear"; bard_spell_name[1][3] = "Charm Person";
    bard_spell_name[1][4] = "Comprehend Languages"; bard_spell_name[1][5] = "Cure Light Wounds";
    bard_spell_name[1][6] = "Detect Secret Doors"; bard_spell_name[1][7] = "Disguise Self";
    bard_spell_name[1][8] = "Erase"; bard_spell_name[1][9] = "Expeditious Retreat";
    bard_spell_name[1][10] = "Feather Fall"; bard_spell_name[1][11] = "Grease";
    bard_spell_name[1][12] = "Hypnotism"; bard_spell_name[1][13] = "Identify";
    bard_spell_name[1][14] = "Lesser Confusion"; bard_spell_name[1][15] = "Magic Mouth";
    bard_spell_name[1][16] = "Nystul's Magic Aura"; bard_spell_name[1][17] = "Obscure Object";
    bard_spell_name[1][18] = "Remove Fear"; bard_spell_name[1][19] = "Silent Image";
    bard_spell_name[1][20] = "Sleep"; bard_spell_name[1][21] = "Summon Monster I";
    bard_spell_name[1][22] = "Tasha's Hideous Laughter"; bard_spell_name[1][23] = "Undetectable Alignment";
    bard_spell_name[1][24] = "Unseen Servent"; bard_spell_name[1][25] = "Ventriloquism";
    bard_spell_name[1][26] = " "; 

    bard_spell_name[2][0] = "Alter Self"; bard_spell_name[2][1] = "Animal Messenger";
    bard_spell_name[2][2] = "Animal Trance"; bard_spell_name[2][3] = "Blindness/Deafness";
    bard_spell_name[2][4] = "Blur"; bard_spell_name[2][5] = "Calm Emotions";
    bard_spell_name[2][6] = "Cat's Grace"; bard_spell_name[2][7] = "Cure Moderate Wounds";
    bard_spell_name[2][8] = "Darkness"; bard_spell_name[2][9] = "Daze Monster";
    bard_spell_name[2][10] = "Delay Poison"; bard_spell_name[2][11] = "Detect Thoughts";
    bard_spell_name[2][12] = "Eagle's Splendor"; bard_spell_name[2][13] = "Enthrall";
    bard_spell_name[2][14] = "Fox's Cunning"; bard_spell_name[2][15] = "Glitterdust";
    bard_spell_name[2][16] = "Heroism"; bard_spell_name[2][17] = "Hold Person";
    bard_spell_name[2][18] = "Hypnotic Pattern"; bard_spell_name[2][19] = "Invisiblity";
    bard_spell_name[2][20] = "Locate Object"; bard_spell_name[2][21] = "Minor Image";
    bard_spell_name[2][22] = "Mirror Image"; bard_spell_name[2][23] = "Misdirection";
    bard_spell_name[2][24] = "Pyrotechnics"; bard_spell_name[2][25] = "Rage";
    bard_spell_name[2][26] = "Scare"; bard_spell_name[2][27] = "Shatter";
    bard_spell_name[2][28] = "Silence"; bard_spell_name[2][29] = "Sound Burst";
    bard_spell_name[2][30] = "Suggestion"; bard_spell_name[2][31] = "Summon Monster II";
    bard_spell_name[2][32] = "Summon Swarm"; bard_spell_name[2][33] = "Tongues";
    bard_spell_name[2][34] = "Whispering Wind"; bard_spell_name[2][35] = " ";

    bard_spell_name[3][0] = "Blink"; bard_spell_name[3][1] = "Charm Monster";
    bard_spell_name[3][2] = "Clairaudience/Clairvoyance"; bard_spell_name[3][3] = "Confusion";
    bard_spell_name[3][4] = "Crushing Dispair"; bard_spell_name[3][5] = "Cure Serious Wounds";
    bard_spell_name[3][6] = "Daylight"; bard_spell_name[3][7] = "Deep Slumber";
    bard_spell_name[3][8] = "Dispel Magic"; bard_spell_name[3][9] = "Displacement";
    bard_spell_name[3][10] = "Fear"; bard_spell_name[3][11] = "Gaseous Form";
    bard_spell_name[3][12] = "Geas, Lesser"; bard_spell_name[3][13] = "Glibness";
    bard_spell_name[3][14] = "Good Hope"; bard_spell_name[3][15] = "Haste";
    bard_spell_name[3][16] = "Illusory Script"; bard_spell_name[3][17] = "Invisiblity Sphere";
    bard_spell_name[3][18] = "Leomund's Tiny Hut"; bard_spell_name[3][19] = "Major Image";
    bard_spell_name[3][20] = "Phantom Steed"; bard_spell_name[3][21] = "Remove Curse";
    bard_spell_name[3][22] = "Scrying"; bard_spell_name[3][23] = "Sculpt Sound";
    bard_spell_name[3][24] = "Secret Page"; bard_spell_name[3][25] = "See Invisibility";
    bard_spell_name[3][26] = "Sepia Snake Sigil"; bard_spell_name[3][27] = "Slow";
    bard_spell_name[3][28] = "Speak with Animals"; bard_spell_name[3][29] = "Summon Monster III";
    bard_spell_name[3][30] = " ";


    bard_spell_name[4][0] = "Break Enchantment"; bard_spell_name[4][1] = "Cure Critical Wounds";
    bard_spell_name[4][2] = "Detect Scrying"; bard_spell_name[4][3] = "Dimension Door";
    bard_spell_name[4][4] = "Dominate Person"; bard_spell_name[4][5] = "Freedom of Movement";
    bard_spell_name[4][6] = "Hallucinatory Terrain"; bard_spell_name[4][7] = "Hold Monster";
    bard_spell_name[4][8] = "Invisiblity, Greater"; bard_spell_name[4][9] = "Legend Lore";
    bard_spell_name[4][10] = "Leomund's Secure Shelter"; bard_spell_name[4][11] = "Locate Creature";
    bard_spell_name[4][12] = "Modify Memory"; bard_spell_name[4][13] = "Neutralize Poison";
    bard_spell_name[4][14] = "Rainbow Pattern"; bard_spell_name[4][15] = "Repel Vermin";
    bard_spell_name[4][16] = "Shadow Conjuration"; bard_spell_name[4][17] = "Shout";
    bard_spell_name[4][18] = "Speak with Plants"; bard_spell_name[4][19] = "Summon Monster IV";
    bard_spell_name[4][20] = "Zone of Silence"; bard_spell_name[4][21] = " ";

    bard_spell_name[5][0] = "Cure Light Wounds, Mass"; bard_spell_name[5][1] = "Dispel Magic, Greater";
    bard_spell_name[5][2] = "Dream"; bard_spell_name[5][3] = "False Vision";
    bard_spell_name[5][4] = "Heroism, Greater"; bard_spell_name[5][5] = "Mind Fog";
    bard_spell_name[5][6] = "Mirage Arcana"; bard_spell_name[5][7] = "Mislead";
    bard_spell_name[5][8] = "Nightmare"; bard_spell_name[5][9] = "Persistent Image";
    bard_spell_name[5][10] = "Seeming"; bard_spell_name[5][11] = "Shadow Evocation";
    bard_spell_name[5][12] = "Shadow Walk"; bard_spell_name[5][13] = "Song of Discord";
    bard_spell_name[5][14] = "Suggestion, Mass"; bard_spell_name[5][15] = "Summon Monster V";
    bard_spell_name[5][16] = " ";

    bard_spell_name[6][0] = "Analyze Dweomer"; bard_spell_name[6][1] = "Animate Objects";
    bard_spell_name[6][2] = "Cat's Grace, Mass"; bard_spell_name[6][3] = "Charm Monster, Mass";
    bard_spell_name[6][4] = "Cure Moderate Wounds, Mass"; bard_spell_name[6][5] = "Eagle's Splendor, Mass";
    bard_spell_name[6][6] = "Eyebite"; bard_spell_name[6][7] = "Find the Path";
    bard_spell_name[6][8] = "Fox's Cunning, Mass"; bard_spell_name[6][9] = "Geas/Quest";
    bard_spell_name[6][10] = "Hero's Feast"; bard_spell_name[6][11] = "Otto's Irresistible Dance";
    bard_spell_name[6][12] = "Permanent Image"; bard_spell_name[6][13] = "Programmed Image";
    bard_spell_name[6][14] = "Project Image"; bard_spell_name[6][15] = "Scrying, Greater";
    bard_spell_name[6][16] = "Shout, Greater"; bard_spell_name[6][17] = "Summon Monster VI";
    bard_spell_name[6][18] = "Sympathetic Vibration"; bard_spell_name[6][19] = "Veil";
    bard_spell_name[6][20] = " ";

    // end of bard spells



    // the handle to the skills window
    var newwin;
    // window which displays feats
    var featwin;

    // window to display character sheet
    var displaywin;
  
    // windows to display equipment
    var eq_win;

    // window that allows ability scores to be swapped
    var swapwin;

    // window to allow user to enter ability scores
    var ability_win;

    // window to select spells
    var spell_win;

    // window to select monk and ranger bonus feats
    var bonus_feat_win;

    // window to handle saving data
    var save_win;
    // window to level up 1 level
    var level_up_win;
    // window for setting up equipment
    var equip_win;

    // This function opens a window displaying
    // information about this web page.
    function Show_About()
    {
        // open new window
        var New_Win = open('', 'About', min_feature);

        New_Win.document.write('<center>');

        New_Win.document.write('This web page was created to help players produce<br>');
        New_Win.document.write('3rd edition D&D characters quickly and easily. It<br>');
        New_Win.document.write('accepts some basic input from the user, then displays<br>');
        New_Win.document.write('a basic character sheet (in HTML). A simple, blank<br>');
        New_Win.document.write('sheet can also be displayed for printing purposes.<br><br>');

        New_Win.document.write('This page has been tested and works with Internet Explorer,<br>');
        New_Win.document.write('Opera, Firefox, Mozilla, Safari,  and Konqueror<br><br>');

        New_Win.document.write('Please feel free to copy, change and use<br>');
        New_Win.document.write('this HTML code at will (in accordance with the GPL v2). However I ask<br>');
        New_Win.document.write('that you document and send me any logic<br>');
        New_Win.document.write('changes. Please see the <a href="readme.txt">README file</a> for more details. Thank you.<br><br>');

        New_Win.document.write('All information used to create this character<br>');
        New_Win.document.write("generator was taken from the Player's Hand Book<br>");
        New_Win.document.write("and the Dungeon Master's Guide<br>");
        New_Win.document.write('authored by <a href="http://wizards.com/">Wizards of the Coast Inc.</a><br>');
        New_Win.document.write('<br>');
        New_Win.document.write('Technical assistance provided by Isaac Sabean.<br>');
        New_Win.document.write('Random Name generation was coded by David Wheeler, please see ');
        New_Win.document.write('<a href="http://www.dwheeler.com/totro.html">http://www.dwheeler.com/totro.html</a> ');
        New_Win.document.write('for more information and the original code.<br><br>');

        New_Win.document.write('Version -- 4.5<br>');
        New_Win.document.write('Written by Jesse Smith -- slicer69@hotmail.com<br>');
        New_Win.document.write('<a href="http://slicer69.tripod.com/">http://slicer69.tripod.com/</a><br><br>');

        New_Win.document.write('<form>');
        New_Win.document.write('  <input type=button value="Close" onClick="window.close()">');
        New_Win.document.write('</form>');

        New_Win.document.write('</center>');

        New_Win.document.close();
        New_Win.focus();
    }


    // This function loads the FAQ page. The FAQ page should be found
    // in the current directory.
    function Show_FAQs(dnd_path)
    {
       var New_Win = open(dnd_path+'/faqs.html', 'FAQs', min_feature);

       New_Win.document.close();
       New_Win.focus();
    }



    // This function takes a string and returns the
    // lower case version (without under scores).
    // The string "A_FEAT_NAME" will change to "a feat name"
    function Proper_Case(line)
    {
       var myline = new String(line);
       var reg_expression = /_/g;

       myline = myline.replace(reg_expression, ' ');
       myline = myline.toLowerCase();
       return myline;
    }


    // This function resets all ability scores to 0.
    // The score displays in the main window are all
    // blanked. This is to keep people from rolling
    // scores, then changing their race, class, etc.
    // Bonus ability poitns are also reset.
    function Clear_Ability_Scores()
    {
       // if scores haven't been rolled, skip this code
       if (intelligence == 0)
          return;

       strength = str_mod = 0;
       dexterity = dex_mod = 0;
       constitution = con_mod = 0;
       intelligence = int_mod = 0;
       wisdom = wis_mod = 0;
       charisma = chr_mod = 0;
       max_bonus_ability = bonus_ability = 0;

       document.main.strength.value = "";
       document.main.str_mod.value = "";
       document.main.dexterity.value = "";
       document.main.dex_mod.value = "";
       document.main.constitution.value = "";
       document.main.con_mod.value = "";
       document.main.intelligence.value = "";
       document.main.int_mod.value = "";
       document.main.wisdom.value = "";
       document.main.wis_mod.value = "";
       document.main.charisma.value = "";
       document.main.chr_mod.value = "";
       document.main.bonus_ability.value = "";
    }

    


    // This function clears the skills, feats, eq_have and language
    // arrays. This gives us a clean slate to work with after rolling
    // ability scores.
    function Clear_Skills_Feats_Equipment_Language()
    {
        var count;

        for (count = 0; count <= USE_ROPE; count++)
            skills[count] = 0;

        for (count = 0; count <= WIDEN_SPELL; count++)
            feats[count] = 0;

        // clear monk specific feats
        for (count = 0; count < 3; count++)
           monk_bonus_feats[count] = 0;

        for (count = 0; count <= MAX_EQUIPMENT; count++)
            eq_have[count] = 0;

        // I know this is ugly, but I do not have a set amount of armor and weapons
        for (count = 0; count <= 86; count++)
           eq_masterwork[count] = 0;

        for (count = 0; count <= UNDERCOMMON; count++)
            language[count] = 0;
    }



    // This function returns the characters total
    // base attack bonus. The value is stored in "base_attack_bonus".
    // (Wonder how I came up with that name?)
    function Get_Base_Attack_Bonus()
    {
       var num;

       // search through all classes, adding the
       // base attack bonuses for each class
       base_attack_bonus = 0;
       // halflings and gnomes get a +1 to base attack bonus due to their size
       if ( (race == HALFLING) || (race == GNOME) )
         base_attack_bonus += 1;

       for (num = 0; num <= WIZARD; num++)
       {
          if (class_levels[num])
          {
            switch (num)
            {
               case BARBARIAN:
               case FIGHTER:
               case PALADIN:
               case RANGER:
                      base_attack_bonus += class_levels[num];
                      break;

               case BARD:
               case CLERIC:
               case DRUID:
               case MONK:
               case ROGUE:
                      if (class_levels[num] < 5)
                         base_attack_bonus += class_levels[num] - 1;
                      else if (class_levels[num] < 9)
                         base_attack_bonus += class_levels[num] - 2;
                      else if (class_levels[num] < 13)
                         base_attack_bonus += class_levels[num] - 3;
                      else if (class_levels[num] < 17)
                         base_attack_bonus += class_levels[num] - 4;
                      else
                         base_attack_bonus += class_levels[num] - 5;
                      break;

               case SORCERER:
               case WIZARD:
                      base_attack_bonus += Math.floor(class_levels[num] / 2);
                      break;

            }     // end of switch
          }       // end of if character has this class
       }    // end of for loop
    }       // end of Get_Back_Attack_Bonus()



    // This function retrieves class saving throws. These
    // include fortitude, reflex and will saves.

    // Note: This function is upgraded to DnD 3.5
    function Get_Saving_Throw()
    {
        var count;

        fortitude_save = 0;
        reflex_save = 0;
        will_save = 0;
        for (count = 0; count <= WIZARD; count++)
        {
           if (class_levels[count])
           {
              switch (count)
              {
                case BARBARIAN:
                case FIGHTER:
                case PALADIN:
                               fortitude_save += Math.floor(class_levels[count] / 2) + 2;
                               reflex_save += Math.floor(class_levels[count] / 3);
                               will_save += Math.floor(class_levels[count] / 3);
                               break;
                case BARD:
                               fortitude_save += Math.floor(class_levels[count] / 3);
                               reflex_save += Math.floor( class_levels[count] / 2) + 2;
                               will_save += Math.floor( class_levels[count] / 2) + 2;
                               break;
               case CLERIC:
               case DRUID:
                               fortitude_save += Math.floor( class_levels[count] / 2) + 2;
                               reflex_save += Math.floor(class_levels[count] / 3);
                               will_save += Math.floor(class_levels[count] / 2) + 2;
                               break;
               case MONK:
                               fortitude_save += Math.floor(class_levels[count] / 2) + 2;
                               reflex_save += Math.floor(class_levels[count] / 2) + 2;
                               will_save += Math.floor(class_levels[count] / 2) + 2;
                               break;
               case RANGER:
                               fortitude_save += Math.floor(class_levels[count] / 2) + 2;
                               reflex_save += Math.floor(class_levels[count] / 2) + 2;
                               will_save += Math.floor(class_levels[count] / 3);
                               break;
               case ROGUE:
                               fortitude_save += Math.floor(class_levels[count] / 3);
                               reflex_save += Math.floor(class_levels[count] / 2) + 2;
                               will_save += Math.floor(class_levels[count] / 3);
                               break;
               case SORCERER:
               case WIZARD: 
                               fortitude_save += Math.floor(class_levels[count] / 3);
                               reflex_save += Math.floor(class_levels[count] / 3);
                               will_save += Math.floor(class_levels[count] / 2) + 2;
                               break;
                
              }   // end of switch
           }      // end of have this class
        }    // end of for loop
    }     // end of get saving throw


    // This function returns a number from an "num"
    // sided dice.
    function Roll_Die(num)
    {
       var rand_number;

       // get random number
       rand_number = Math.round( ( Math.random() * num) );

       // the below line was changed to make there be an even
       // chance of rolling a min or max number.
       // previously, there was a great chance of rolling 1 than a "num"
       // if (rand_number < 1) rand_number = 1;
       if (rand_number < 1) rand_number = num;

       if (rand_number > num) rand_number = num;

       return rand_number;
    }


    // This function calculates the number of
    // hit points the character will have.
    // The value is stored in the varible "hit_points".

    // Note: This function has been upgrades to DnD 3.5
    function Calc_Hit_Points()
    {
       var class_count, sum;
       var count, dice_size;

       hit_points = 0;
       armour_bonus = 0;

       for (class_count = 0; class_count <= WIZARD; class_count++)
       {
          // check if character has this class
          if (class_levels[class_count])
          {
          // get the dice size
          switch (class_count)
          {
             case BARBARIAN:    // d12
                       dice_size = 12;
                       break;
             case BARD:         // d6
             case ROGUE:
                       dice_size = 6;
                       break;

             case CLERIC:       // d8
             case DRUID:
             case MONK:
             case RANGER:
                       dice_size = 8;
                       break;

             case FIGHTER:      // d10
             case PALADIN:
                       dice_size = 10;
                       break;

             case SORCERER:     // d4
             case WIZARD:
                       dice_size = 4;
                       break;
             
          }      // end of switch


          // this this is the starting class, then take the full
          // hit dice for the first level
          if (class_count == starting_class)
          {
             sum = dice_size + con_mod;
             if (sum < 1) sum = 1;
             hit_points += sum;
             for (count = 1; count < class_levels[class_count]; count++)
             {
                sum = Roll_Die(dice_size) + con_mod;
                if (sum < 1) sum = 1;
                hit_points += sum;
             }  
          }

          // otherwise, if this class is not the starting class, just
          // roll the dice for hit points
          else
          {
            for (count = 0; count < class_levels[class_count]; count++)
            {
               sum = Roll_Die(dice_size) + con_mod;
               if (sum < 1) sum = 1;
               hit_points += sum;
            }
          }

          // This has been fixed above
          // make sure we get at least one hit point
          // if (sum < 1)
          //   sum = 1;

          // hit_points += sum;
          }       // end of if character has this class

       }     // end of for loop

       // Elves get -2 to con, removing one hit point per level
       if (race == ELF)
         hit_points -= total_level;

       // Dwarves and Gnomes get +2 to con, adding a hit point per level
       if ( (race == DWARF) || (race == GNOME) )
         hit_points += total_level;

       if (hit_points < 1)
         hit_points = 1;

    }


    // This function calculated the starting amount of gold
    // that a character has. This based of the Player's Hand Book
    // page 95 (Equipment).
    // Note: Changed this function so it follows different rules.
    //       First level characters follow the rules on page
    //       96 of the PHB. However, second level characters
    //       and higher, get (3 ^ total_level) * 100 gold.
    //       I believe this is in the DMG, not sure which page.
    // NOTE: Changed function again. Formula was *very* wrong for
    //       players over 2ed level. I am now using the chart on
    //       page 135 of the Dungeon Master's Guide.
    //       Players now get a lot less money.
    function Calc_Money()
    {
        var class_count;
        var cash;
        var dice_rolls, roll_count;

        if (total_level == 1)
        {
         money = 0.0;
        for (class_count = 0; class_count <= WIZARD; class_count++)
        {
           if (class_levels[class_count])
           {
              switch (class_count)
              {
                 case BARBARIAN:
                 case BARD:
                         dice_rolls = 4; break;

                 case CLERIC:
                 case MONK:
                 case ROGUE:
                         dice_rolls = 5; break;

                 case DRUID: dice_rolls = 2; break;
                
                 case FIGHTER:
                 case PALADIN:
                 case RANGER: dice_rolls = 6; break;
            
                 case SORCERER:
                 case WIZARD: dice_rolls = 3; break;
               
              }    // end of switch
              
              cash = 0;
              for (roll_count = 0; roll_count < dice_rolls; roll_count++)
                 cash += Roll_Die(4);

              if (class_count == MONK)
                money += cash * class_levels[class_count];
              else
                money += (cash * 10) * class_levels[class_count];

           }      // end of have this class 
        }        // end of for loop
        }        // end of just first level char

        else      // second level or higher
        {
           switch (total_level)
           {
             case 2: money = 900; break;
             case 3: money = 2700; break;
             case 4: money = 5400; break;
             case 5: money = 9000; break;
             case 6: money = 13000; break;
             case 7: money = 19000; break;
             case 8: money = 27000; break;
             case 9: money = 36000; break;
             case 10: money = 49000; break;
             case 11: money = 66000; break;
             case 12: money = 88000; break;
             case 13: money = 110000; break;
             case 14: money = 150000; break;
             case 15: money = 200000; break;
             case 16: money = 260000; break;
             case 17: money = 340000; break;
             case 18: money = 440000; break;
             case 19: money = 580000; break;
             case 20: money = 760000; break;
           }   // end of switch
        }   
        

    }      // end of Calc_Money function


    // This function sets the character's experience points.
    // The value is stored in "experience_points".
    // Taken from page 22 of the Player's Hand Book.
    function Get_Experience_Points()
    {
       var num;

       experience_points = 0;
       for (num = 1; num < total_level; num++)
         experience_points += num * 1000;

    }


    // Get race from the race box
    function Set_Race()
    {
       race = document.main.race.options.selectedIndex;

       switch (race)
       {
          case HUMAN: race_name = "Human"; break;
          case ELF: race_name = "Elf"; break;
          case DWARF: race_name = "Dwarf"; break;
          case HALFLING: race_name = "Halfling"; break;
          case HALF_ELF: race_name = "Half Elf"; break;
          case HALF_ORC: race_name = "Half Orc"; break;
          case GNOME: race_name = "Gnome"; break;
       }     // switch race

       Clear_Ability_Scores();
    }


    // Get class from class box
    function Set_Starting_Class()
    {
       starting_class = document.main.starting_class.options.selectedIndex;

       // clear all other classes as this is usually done first
       document.main.barbarian_class.checked = false;
       document.main.bard_class.checked = false;
       document.main.cleric_class.checked = false;
       document.main.druid_class.checked = false;
       document.main.fighter_class.checked = false;
       document.main.monk_class.checked = false;
       document.main.paladin_class.checked = false;
       document.main.ranger_class.checked = false;
       document.main.rogue_class.checked = false;
       document.main.sorcerer_class.checked = false;
       document.main.wizard_class.checked = false;
               
       switch (starting_class)
       {
         case BARBARIAN: starting_class_name = "Barbarian";
                         document.main.barbarian_class.checked = true;
                         break;
         case BARD: starting_class_name = "Bard";
                    document.main.bard_class.checked = true;
                    break;
         case CLERIC: starting_class_name = "Cleric";
                      document.main.cleric_class.checked = true;
                      break;
         case DRUID: starting_class_name = "Druid";
                     document.main.druid_class.checked = true;
                     break;
         case FIGHTER: starting_class_name = "Fighter";
                       document.main.fighter_class.checked = true;
                       break;
         case MONK: starting_class_name = "Monk";
                    document.main.monk_class.checked = true;
                    break;
         case PALADIN: starting_class_name = "Paladin";
                       document.main.paladin_class.checked = true;
                       break;
         case RANGER: starting_class_name = "Ranger";
                      document.main.ranger_class.checked = true;
                      break;
         case ROGUE: starting_class_name = "Rogue";
                     document.main.rogue_class.checked = true;
                     break;
         case SORCERER: starting_class_name = "Sorcerer";
                        document.main.sorcerer_class.checked = true;
                        break;
         case WIZARD: starting_class_name = "Wizard";
                      document.main.wizard_class.checked = true;
                      break;

       }   // end of switch

       Set_Class();
    }


    // This function sets the number of levels in each class.
    function Set_Class()
    {
       if (document.main.barbarian_class.checked)
         class_levels[BARBARIAN] = document.main.barbarian_level.selectedIndex + 1;
       else
         class_levels[BARBARIAN] = 0;

       if (document.main.bard_class.checked)
         class_levels[BARD] = document.main.bard_level.selectedIndex + 1;
       else
         class_levels[BARD] = 0;

       if (document.main.cleric_class.checked)
         class_levels[CLERIC] = document.main.cleric_level.selectedIndex + 1;
       else
         class_levels[CLERIC] = 0;

       if (document.main.druid_class.checked)
         class_levels[DRUID] = document.main.druid_level.selectedIndex + 1;
       else
         class_levels[DRUID] = 0;

       if (document.main.fighter_class.checked)
         class_levels[FIGHTER] = document.main.fighter_level.selectedIndex + 1;
       else
         class_levels[FIGHTER] = 0;

       if (document.main.monk_class.checked)
         class_levels[MONK] = document.main.monk_level.selectedIndex + 1;
       else
         class_levels[MONK] = 0;

       if (document.main.paladin_class.checked)
         class_levels[PALADIN] = document.main.paladin_level.selectedIndex + 1;
       else
         class_levels[PALADIN] = 0;

       if (document.main.ranger_class.checked)
         class_levels[RANGER] = document.main.ranger_level.selectedIndex + 1;
       else
         class_levels[RANGER] = 0;

       if (document.main.rogue_class.checked)
         class_levels[ROGUE] = document.main.rogue_level.selectedIndex + 1;
       else
         class_levels[ROGUE] = 0;

       if (document.main.sorcerer_class.checked)
         class_levels[SORCERER] = document.main.sorcerer_level.selectedIndex + 1;
       else
         class_levels[SORCERER] = 0;

       if (document.main.wizard_class.checked)
         class_levels[WIZARD] = document.main.wizard_level.selectedIndex + 1;
       else
         class_levels[WIZARD] = 0;

       Set_Total_Level();
       Clear_Ability_Scores();
    }


    // Get the alignment from the select box and
    // set the alignment_name varible.
    function Set_Alignment()
    {
       alignment = document.main.alignment.selectedIndex;
       
       switch(alignment)
       {
         case LAWFUL_GOOD: alignment_name = "Lawful Good"; break;
         case NEUTRAL_GOOD: alignment_name = "Neutral Good"; break;
         case CHAOTIC_GOOD: alignment_name = "Choatic Good"; break;
         case LAWFUL_NEUTRAL: alignment_name = "Lawful Neutral"; break;
         case TRUE_NEUTRAL: alignment_name = "True Neutral"; break;
         case CHAOTIC_NEUTRAL: alignment_name = "Choatic Neutral"; break;
         case LAWFUL_EVIL: alignment_name = "Lawful Evil"; break;
         case NEUTRAL_EVIL: alignment_name = "Neutral Evil"; break;
         case CHAOTIC_EVIL: alignment_name = "Chaoic Evil"; break;

       }    // end of switch alignment

       Clear_Ability_Scores();
    }


    // This function sets the varibles for the
    // characters religion.
    // Page 106 of the PHB.
    function Set_Religion()
    {
       religion = document.main.religion.selectedIndex;
       switch (religion)
       {
          case NONE: religion_name = "None"; break;
          case BACCOB: religion_name = "Boccob"; break;
          case CORELLON_LARENTHIAN: religion_name = "Corellon Larethian"; break;
          case EHLONNA: religion_name = "Ehlonna"; break;
          case ERYTNUL: religion_name = "Erythnul"; break;
          case FARLANGHN: religion_name = "Fharlanghn"; break;
          case GARL_GLITTERGOLD: religion_name = "Garl Glittergold"; break;
          case GRUUMSH: religion_name = "Gruumsh"; break;
          case HEIRONEOUS: religion_name = "Heironeous"; break;
          case HEXTOR: religion_name = "Hextor"; break;
          case KORD: religion_name = "Kord"; break;
          case MORADIN: religion_name = "Moradin"; break;
          case NERULL: religion_name = "Nerull"; break;
          case OBAD_HAI: religion_name = "Obad-Hai"; break;
          case OLIDAMMARA: religion_name = "Olidammara"; break;
          case PELOR: religion_name = "Pelor"; break;
          case ST_CUTHBERT: religion_name = "St. Cuthbert"; break;
          case VECNA: religion_name = "Vecna"; break;
          case WEE_JAS: religion_name = "Wee Jas"; break;
          case YONDALLA: religion_name = "Yondalla"; break;
          case OTHER_GOD: religion_name = "Other";
                   document.main.religion_name.focus();
                   break;
       }   // end of switch
    }




    // Set the starting level for the character.
    function Set_Total_Level()
    {
       var count;

       total_level = 0;
       for (count = 0; count <= WIZARD; count++)
       {
          total_level += class_levels[count];
       }
       document.main.total_level.value = total_level;
    }


    // This function checks to make sure the select class
    // can be used with the given alignment. Due to
    // multi-class problems, this only works when characters
    // have one class only. If all is well betweem the
    // class and alignment, this function returns true,
    // otherwise false is returned.
    function Check_Alignment()
    {
       var class_found = 0;
       var count;

       // make sure we have just one class
       for (count = 0; count <= WIZARD; count++)
       {
           if (class_levels[count]) class_found++;
       }
       if (class_found > 1)
          return true;
             
       // Barbarians and Bards cannot be lawful 
       if ( (class_levels[BARBARIAN]) || (class_levels[BARD]) )
       {
          if ( (alignment == LAWFUL_GOOD) || 
             (alignment == LAWFUL_NEUTRAL) ||
             (alignment == LAWFUL_EVIL) )
             return false;
          else
             return true;
       }
   
       // Clerics should match their god, but keeping track
       // of all the alignments and one-steps seems like
       // overkill. Leaving this for the DM now...
 
       // Druids must be neutral
       if (class_levels[DRUID])
       {
         if ( (alignment == NEUTRAL_GOOD) ||
              (alignment == CHAOTIC_NEUTRAL) ||
              (alignment == TRUE_NEUTRAL) ||
              (alignment == LAWFUL_NEUTRAL) ||
              (alignment == NEUTRAL_EVIL) )
            return true;
         else
            return false;
       }

       // monks are always lawful
       if (class_levels[MONK])
       {
          if ( (alignment == LAWFUL_GOOD) ||
               (alignment == LAWFUL_NEUTRAL) ||
               (alignment == LAWFUL_EVIL) )
             return true;
          else
             return false;
        }

       // paladins are always lawful good
       if (class_levels[PALADIN])
       {
          if (alignment == LAWFUL_GOOD)
             return true;
          else
             return false;
       }

       return true;
    }    // end of Check_Alignment()



    // This function resets all of the spell data to zeros.
    // With this done, it then initalizes all of the spells-known
    // varibles.
    function Init_Wizard_Spells()
    {
      var index, spell_index;
      var temp;

      for (index = 0; index < 10; index++)
      {
         num_wizard_spells[index] = 0;   // number of spells per level we can know
         for (spell_index = 0; spell_index < 50; spell_index++)
         {
              wizard_spells[index][spell_index] = 0;    // erase spells that we have
         }
      }
 
      // if the character is not a wizard, stop here
      if (! class_levels[WIZARD])
        return;

      // if the wizard has a low intelligence, they cannot cast spells
      if (intelligence < 10)
        return;

      // a wizard knows all 0-level spells
      // Note: Except for 0-level spells in their prohibated schools
      for (spell_index = 0; spell_index < 50; spell_index++)
      {
        if ( (wizard_spell_domain[0][spell_index] != restricted_spell_domain[0]) &&
             (wizard_spell_domain[0][spell_index] != restricted_spell_domain[1]) )
          wizard_spells[0][spell_index] = 1;
        else
          wizard_spells[0][spell_index] = 0;
      }

      // set the number of wizard spells we can get, per level
      // remember that wizards get all 0-level spells
      // which, in this case, means they can learn no 0-level spells
      for (index = class_levels[WIZARD]; index > 1; index--)
      {
         temp = Math.round(index / 2.0);
         if ( temp > 9) temp = 9;
         num_wizard_spells[ temp ] += 2;
      }

      // a wizard starts with any three first level spells
      num_wizard_spells[1] += 3;
      // if the wizard has a intelligence of 12+, she gets a bonus spell
      if (intelligence > 11)
         num_wizard_spells[1] += 1;

    }   // end of init wizard spells



    // This function gives us the number of sorcerer spells
    // a character may learn at each level.
    function Gain_Sorcerer_Spells()
    {
       // if the character is not a sorcerer, bail out now
       if (! class_levels[SORCERER])
         return;

       // set how many spells the sorcerer can learn per level
       switch (class_levels[SORCERER])
       {
         case 1: num_sorcerer_spells[0] = 4; num_sorcerer_spells[1] = 2;
                 break;
         case 2: num_sorcerer_spells[0] = 5; num_sorcerer_spells[1] = 2;
                 break;
         case 3: num_sorcerer_spells[0] = 5; num_sorcerer_spells[1] = 3;
                 break;
         case 4: num_sorcerer_spells[0] = 6; num_sorcerer_spells[1] = 3;
                 num_sorcerer_spells[2] = 1; break;
         case 5: num_sorcerer_spells[0] = 6; num_sorcerer_spells[1] = 4;
                 num_sorcerer_spells[2] = 2; break;
         case 6: num_sorcerer_spells[0] = 7; num_sorcerer_spells[1] = 4;
                 num_sorcerer_spells[2] = 2; num_sorcerer_spells[3] = 1;
                 break;
         case 7: num_sorcerer_spells[0] = 7; num_sorcerer_spells[1] = 5;
                 num_sorcerer_spells[2] = 3; num_sorcerer_spells[3] = 2;
                 break;
         case 8: num_sorcerer_spells[0] = 8; num_sorcerer_spells[1] = 5;
                 num_sorcerer_spells[2] = 3; num_sorcerer_spells[3] = 2;
                 num_sorcerer_spells[4] = 1; break;
         case 9: num_sorcerer_spells[0] = 8; num_sorcerer_spells[1] = 5;
                 num_sorcerer_spells[2] = 4; num_sorcerer_spells[3] = 3;
                 num_sorcerer_spells[4] = 2; break;
         case 10: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 4; num_sorcerer_spells[3] = 3;
                  num_sorcerer_spells[4] = 2; num_sorcerer_spells[5] = 1;
                  break;
         case 11: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 3; num_sorcerer_spells[5] = 2;
                  break;
         case 12: num_sorcerer_spells[0] = 0; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 3; num_sorcerer_spells[5] = 2;
                  num_sorcerer_spells[6] = 1; break;
         case 13: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 4; num_sorcerer_spells[5] = 3;
                  num_sorcerer_spells[6] = 2; break;
         case 14: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 4; num_sorcerer_spells[5] = 3;
                  num_sorcerer_spells[6] = 2; num_sorcerer_spells[7] = 1;
                  break;
         case 15: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 4; num_sorcerer_spells[5] = 4;
                  num_sorcerer_spells[6] = 3; num_sorcerer_spells[7] = 2;
                  break;
         case 16: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 4; num_sorcerer_spells[5] = 4;
                  num_sorcerer_spells[6] = 3; num_sorcerer_spells[7] = 2;
                  num_sorcerer_spells[8] = 1; break;
         case 17: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 4; num_sorcerer_spells[5] = 4;
                  num_sorcerer_spells[6] = 3; num_sorcerer_spells[7] = 3;
                  num_sorcerer_spells[8] = 2; break;
         case 18: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 4; num_sorcerer_spells[5] = 4;
                  num_sorcerer_spells[6] = 3; num_sorcerer_spells[7] = 3;
                  num_sorcerer_spells[8] = 2; num_sorcerer_spells[9] = 1;
                  break;
         case 19: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 4; num_sorcerer_spells[5] = 4;
                  num_sorcerer_spells[6] = 3; num_sorcerer_spells[7] = 3;
                  num_sorcerer_spells[8] = 3; num_sorcerer_spells[9] = 2;
                  break;
         case 20: num_sorcerer_spells[0] = 9; num_sorcerer_spells[1] = 5;
                  num_sorcerer_spells[2] = 5; num_sorcerer_spells[3] = 4;
                  num_sorcerer_spells[4] = 4; num_sorcerer_spells[5] = 4;
                  num_sorcerer_spells[6] = 3; num_sorcerer_spells[7] = 3;
                  num_sorcerer_spells[8] = 3; num_sorcerer_spells[9] = 3;
                  break;

       }  // end of switch

    }       // end of Gain Sorcerer Spells



    // This function initiates all of the sorcerer's spells.
    // We clear all of the known spells. Then give the
    // possible number of learned spells.
    function Init_Sorcerer_Spells()
    {
       var index, spell_index;

       // clear all known spells 
       for (index = 0; index < 10; index++)
       {
         num_sorcerer_spells[index] = 0;    // spells we can learn
         for (spell_index = 0; spell_index < 50; spell_index++)
         {
           sorcerer_spells[index][spell_index] = 0; // spells we know
         }
       }

       // if the character is not a sorcerer, bail out now
       if (! class_levels[SORCERER])
         return;

       Gain_Sorcerer_Spells();

    }   // end of Init_Sorcerer_Spells()


    // This function gets the number of spells a bard
    // may larn at each level.
    function Gain_Bard_Spells()
    {
       if (! class_levels[BARD] )
          return;

       switch ( class_levels[BARD] )
       {
         case 1: num_bard_spells[0] = 4; break;
         case 2: num_bard_spells[0] = 5; num_bard_spells[1] = 2;
                 break;
         case 3: num_bard_spells[0] = 6; num_bard_spells[1] = 3;
                 break;
         case 4: num_bard_spells[0] = 6; num_bard_spells[1] = 3;
                 num_bard_spells[2] = 2; break;
         case 5:
         case 6: num_bard_spells[0] = 6; num_bard_spells[1] = 4;
                 num_bard_spells[2] = 3; break;
         case 7: num_bard_spells[0] = 6; num_bard_spells[1] = 4;
                 num_bard_spells[2] = 4; num_bard_spells[3] = 2;
                 break;
         case 8:
         case 9: num_bard_spells[0] = 6; num_bard_spells[1] = 4;
                 num_bard_spells[2] = 4; num_bard_spells[3] = 3;
                 break;
         case 10: num_bard_spells[0] = 6; num_bard_spells[1] = 4;
                  num_bard_spells[2] = 4; num_bard_spells[3] = 4;
                  num_bard_spells[4] = 2; break;
         case 11:
         case 12: num_bard_spells[0] = 6; num_bard_spells[1] = 4;
                  num_bard_spells[2] = 4; num_bard_spells[3] = 4;
                  num_bard_spells[4] = 3; break;
         case 13: num_bard_spells[0] = 6; num_bard_spells[1] = 4;
                  num_bard_spells[2] = 4; num_bard_spells[3] = 4;
                  num_bard_spells[4] = 4; num_bard_spells[5] = 2;
                  break;
         case 14:
         case 15: num_bard_spells[0] = 6; num_bard_spells[1] = 4;
                  num_bard_spells[2] = 4; num_bard_spells[3] = 4;
                  num_bard_spells[4] = 4; num_bard_spells[5] = 3;
                  break;
         case 16: num_bard_spells[0] = 6; num_bard_spells[1] = 5;
                  num_bard_spells[2] = 4; num_bard_spells[3] = 4;
                  num_bard_spells[4] = 4; num_bard_spells[5] = 4;
                  num_bard_spells[6] = 2; break;
         case 17: num_bard_spells[0] = 6; num_bard_spells[1] = 5;
                  num_bard_spells[2] = 5; num_bard_spells[3] = 4;
                  num_bard_spells[4] = 4; num_bard_spells[5] = 4;
                  num_bard_spells[6] = 3; break;
         case 18: num_bard_spells[0] = 6; num_bard_spells[1] = 5;
                  num_bard_spells[2] = 5; num_bard_spells[3] = 5;
                  num_bard_spells[4] = 4; num_bard_spells[5] = 4;
                  num_bard_spells[6] = 3; break;
         case 19: num_bard_spells[0] = 6; num_bard_spells[1] = 5;
                  num_bard_spells[2] = 5; num_bard_spells[3] = 5;
                  num_bard_spells[4] = 5; num_bard_spells[5] = 4;
                  num_bard_spells[6] = 4; break;
         case 20: num_bard_spells[0] = 6; num_bard_spells[1] = 5;
                  num_bard_spells[2] = 5; num_bard_spells[3] = 5;
                  num_bard_spells[4] = 5; num_bard_spells[5] = 5;
                  num_bard_spells[6] = 4; break;

       }   // end of switch

    }      // end of Gain Bard Spells



    // This function sets all of the Bard spells known to 0.
    // It also sets the number of bard spells we can learn.
    function Init_Bard_Spells()
    {
       var spell_level, spell_index;

       // reset all of the bard spells we can learn and have
       for (spell_level = 0; spell_level < 7; spell_level++)
       {
          num_bard_spells[spell_level] = 0;
          for (spell_index = 0; spell_index < 40; spell_index++)
          {
             bard_spells[spell_level][spell_index] = 0;
          }
       }

       // if the character is not a bard, stop now
       if (! class_levels[BARD])
         return;

       // now we get potiental to learn spells
       Gain_Bard_Spells();

    }   // end of Init_Bard_Spells()



    // This function calls the functions for initating spells.
    // Just to keep things modular
    function Init_Spells()
    {
       Init_Wizard_Spells();
       Init_Sorcerer_Spells();
       Init_Bard_Spells();
    }


    
    // Roll a single ability score.
    function Roll_Ability()
    {
       var count;
       var sum, rand_number;
       var min_roll = 99;       // the lowest die rolled

       sum = 0;
       // Note: I changed it from three rolls to four rolls,
       // dropping the lowest roll, since most people do stats this way.
       for (count = 0; count < 4; count++)
       {
         // get random number
         rand_number = Roll_Die(6);
         if (rand_number < min_roll)
            min_roll = rand_number;
         sum += rand_number;
       }
    
       // drop lowest roll
       sum -= min_roll;
       return sum;
     }

   
    // Roll ability scores
    function Roll_Scores()
    {
       var temp_level;

       // Before we roll ability scores, make sure there
       // is at least one class selected "total_level > 1" and
       // the starting class is one of the classes selected.
       if (total_level < 1)
       {
          alert ('Please select at least one character class first.');
          return;
       }

       if (class_levels[starting_class] < 1)
       {
          alert('You must take at least one level in your starting class.');
          return;
       }

       alignment_conflict = false;
       if (! Check_Alignment() )
       {
           // alert('There are alignment restrictions for this class.');
           switch ( starting_class )
           {
              case BARBARIAN:
                   alert('Barbarians cannot have a lawful alignment.');
                   break;
              case BARD:
                   alert('Bards cannot have a lawful alignment.');
                   break;
              case DRUID:
                   alert('Druids must be of a neutral alignment.');
                   break;
              case MONK:
                   alert('Monks must have a lawful alignment.');
                   break;
              case PALADIN:
                   alert('Paladins must have an alignment of lawful good.');
                   break;
           
           }
           alignment_conflict = true;
           // return;
       }

       strength = Roll_Ability();
       str_mod = Math.round( (strength - 11) / 2 );
       document.main.strength.value = strength;
       document.main.str_mod.value = str_mod;

       dexterity = Roll_Ability();
       dex_mod = Math.round( (dexterity - 11) / 2 );
       document.main.dexterity.value = dexterity;
       document.main.dex_mod.value = dex_mod;

       constitution = Roll_Ability();
       con_mod = Math.round( (constitution - 11) / 2 );
       document.main.constitution.value = constitution;
       document.main.con_mod.value = con_mod;

       intelligence = Roll_Ability();
       if ( (race == HALF_ORC) && (intelligence < 5) ) intelligence = 5;
       else if (intelligence < 3) intelligence = 3;
     
       int_mod = Math.round( (intelligence - 11) / 2 );
       document.main.intelligence.value = intelligence;
       document.main.int_mod.value = int_mod;

       wisdom = Roll_Ability();
       wis_mod = Math.round( (wisdom - 11) / 2 );
       document.main.wisdom.value = wisdom;
       document.main.wis_mod.value = wis_mod;

       charisma = Roll_Ability();
       chr_mod = Math.round( (charisma - 11) / 2 );
       document.main.charisma.value = charisma;
       document.main.chr_mod.value = chr_mod;

       temp_level = total_level;
       while ( (temp_level % 4) != 0)
         temp_level--;

       bonus_ability = temp_level / 4;
       max_bonus_ability = bonus_ability;
       document.main.bonus_ability.value = bonus_ability;

       // set min values
       min_str = strength;
       min_dex = dexterity;
       min_con = constitution;
       min_int = intelligence;
       min_wis = wisdom;
       min_chr = charisma;

       Calc_Hit_Points();
       Get_Base_Attack_Bonus();
       Get_Saving_Throw();
       Get_Experience_Points();
       Calc_Money();
       Clear_Skills_Feats_Equipment_Language();
       Calc_Language_Points();
       Calc_Skill_Points();
       Calc_Feat_Points();
       Init_Spells();
    }


    // This function retrieves the ability scores from the
    // ability_win window. It also performs all of the functions
    // performed by the Roll_Scores() function. The
    // ability_win is closed.
    function Set_Ability_Scores()
    {
       var temp_level;

       // get ability scores from the window
       strength = ability_win.document.ability.strength.value;
       strength = strength - 1; strength += 1;
       dexterity = ability_win.document.ability.dexterity.value;
       dexterity = dexterity - 1; dexterity += 1;
       constitution = ability_win.document.ability.constitution.value;
       constitution = constitution - 1; constitution += 1;
       intelligence = ability_win.document.ability.intelligence.value;
       intelligence = intelligence - 1; intelligence += 1;
       wisdom = ability_win.document.ability.wisdom.value;
       wisdom = wisdom - 1; wisdom += 1;
       charisma = ability_win.document.ability.charisma.value;
       charisma = charisma - 1; charisma += 1;

       // close ability window
       ability_win.close();

       // calc mods
       str_mod = Math.round( (strength - 11) / 2 );
       dex_mod = Math.round( (dexterity - 11) / 2 );
       con_mod = Math.round( (constitution - 11) / 2 );
       int_mod = Math.round( (intelligence - 11) / 2 );
       wis_mod = Math.round( (wisdom - 11) / 2 );
       chr_mod = Math.round( (charisma - 11) / 2 );

       // put scores and mods in the main window
       document.main.strength.value = strength;
       document.main.str_mod.value = str_mod;
       document.main.dexterity.value = dexterity;
       document.main.dex_mod.value = dex_mod;
       document.main.constitution.value = constitution;
       document.main.con_mod.value = con_mod;
       document.main.intelligence.value = intelligence;
       document.main.int_mod.value = int_mod;
       document.main.wisdom.value = wisdom;
       document.main.wis_mod.value = wis_mod;
       document.main.charisma.value = charisma;
       document.main.chr_mod.value = chr_mod;
   
       // figure out how many bonus ability points we get
       temp_level = total_level;
       while ( (temp_level % 4) != 0)
         temp_level--;

       bonus_ability = temp_level / 4;
       max_bonus_ability = bonus_ability;
       document.main.bonus_ability.value = bonus_ability;

       // set min values
       min_str = strength;
       min_dex = dexterity;
       min_con = constitution;
       min_int = intelligence;
       min_wis = wisdom;
       min_chr = charisma;

       Calc_Hit_Points();
       Get_Base_Attack_Bonus();
       Get_Saving_Throw();
       Get_Experience_Points();
       Calc_Money();
       Clear_Skills_Feats_Equipment_Language();
       Calc_Language_Points();
       Calc_Skill_Points();
       Calc_Feat_Points();
    }
   
 

    // This function opens a window which allows the user to
    // enter his/her own ability scores.
    // Closing this window causes the ability scores to be
    // entered on the main page.
    function Enter_Ability_Scores()
    {

       // Before we roll ability scores, make sure there
       // is at least one class selected "total_level > 1" and
       // the starting class is one of the classes selected.
       if (total_level < 1)
       {
          alert ('Please select at least one character class first.');
          return;
       }
                                                                                                                             
       if (class_levels[starting_class] < 1)
       {
          alert('You must take at least one level in your starting class.');
          return;
       }
                                                                                                                             
       if (! Check_Alignment() )
       {
           alert('There are alignment restrictions for this class.');
           return;
       }

       ability_win = open('', 'Ability', min_feature);

       ability_win.document.writeln('<center>');
       ability_win.document.writeln('Enter your desired ability scores below.<br><br>');
       ability_win.document.writeln('<form name=ability>');
       ability_win.document.writeln('<table>');
       ability_win.document.writeln(' <tr>');
       ability_win.document.writeln('  <td>Strength:</td>');
       ability_win.document.writeln('  <td><input type=text size=2 name=strength></td>');
       ability_win.document.writeln(' </tr>');
       ability_win.document.writeln(' <tr>');
       ability_win.document.writeln('  <td>Dexterity:</td>');
       ability_win.document.writeln('  <td><input type=text size=2 name=dexterity></td>');
       ability_win.document.writeln(' </tr>');
       ability_win.document.writeln(' <tr>');
       ability_win.document.writeln('   <td>Constitution:</td>');
       ability_win.document.writeln('   <td><input type=text size=2 name=constitution></td>');
       ability_win.document.writeln(' </tr>');
       ability_win.document.writeln(' <tr>');
       ability_win.document.writeln('   <td>Intelligence:</td>');
       ability_win.document.writeln('   <td><input type=text size=2 name=intelligence></td>');
       ability_win.document.writeln(' </tr>');
       ability_win.document.writeln(' <tr>');
       ability_win.document.writeln('  <td>Wisdom:</td>');
       ability_win.document.writeln('  <td><input type=text size=2 name=wisdom></td>');
       ability_win.document.writeln(' </tr>');
       ability_win.document.writeln(' <tr>');
       ability_win.document.writeln('  <td>Charisma:</td>');
       ability_win.document.writeln('  <td><input type=text size=2 name=charisma></td>');
       ability_win.document.writeln(' </tr>');
    
       ability_win.document.writeln('</table>');
       ability_win.document.writeln('<input type=button value="Close" onClick="window.opener.Set_Ability_Scores()">');
       ability_win.document.writeln('</form>');
       ability_win.document.writeln('</center>');

       // if we have already rolled ability scores, then
       // place the current scores in the window
       if (intelligence > 0)
       {
          ability_win.document.ability.strength.value = strength;
          ability_win.document.ability.dexterity.value = dexterity;
          ability_win.document.ability.constitution.value = constitution;
          ability_win.document.ability.intelligence.value = intelligence;
          ability_win.document.ability.wisdom.value = wisdom;
          ability_win.document.ability.charisma.value = charisma;
       }

       ability_win.document.close();
       ability_win.focus();
    }


    function Ability_Down(num)
    {
       var changed = false;
       
       // make sure we do not get too many bonus points back
       if (bonus_ability >= max_bonus_ability)
          return;

       switch (num)
       {
         case 1:
                 if (strength > min_str)
                 {
                   strength--;
                   str_mod = Math.round( (strength - 11) / 2 );
                   document.main.strength.value = strength;
                   document.main.str_mod.value = str_mod;
                   changed = true;
                 }
                 break;

         case 2:
                 if (dexterity > min_dex)
                 {
                   dexterity--;
                   dex_mod = Math.round( (dexterity - 11) / 2 );
                   document.main.dexterity.value = dexterity;
                   document.main.dex_mod.value = dex_mod;
                   changed = true;
                 }
                 break;

         case 3:
                 if (constitution > min_con)
                 {
                   constitution--;
                   con_mod = Math.round( (constitution - 11) / 2 );
                   document.main.constitution.value = constitution;
                   document.main.con_mod.value = con_mod;
                   changed = true;
                 }
                 break;

         case 4:
                 if (intelligence > min_int)
                 {
                   intelligence--;
                   int_mod = Math.round( (intelligence - 11) / 2 );
                   document.main.intelligence.value = intelligence;
                   document.main.int_mod.value = int_mod;
                   changed = true;
                 }
                 break;

         case 5:
                 if (wisdom > min_wis)
                 {
                   wisdom--;
                   wis_mod = Math.round( (wisdom - 11) / 2 );
                   document.main.wisdom.value = wisdom;
                   document.main.wis_mod.value = wis_mod;
                   changed = true;
                 }
                 break;

         case 6:
                 if (charisma > min_chr)
                 {
                   charisma--;
                   chr_mod = Math.round( (charisma - 11) / 2 );
                   document.main.charisma.value = charisma;
                   document.main.chr_mod.value = chr_mod;
                   changed = true;
                 }
                 break;

       }     // end of switch

       if (changed)
       {
         bonus_ability++;
         document.main.bonus_ability.value = bonus_ability;
       }
    }


    function Ability_Up(num)
    {
       // make sure we don't get too many bonus points
       if (bonus_ability <= 0)
          return;

       switch (num)
       {
         case 1: strength++;
                 str_mod = Math.round( (strength - 11) / 2 );
                 document.main.strength.value = strength;
                 document.main.str_mod.value = str_mod;
                 break;

         case 2: dexterity++;
                 dex_mod = Math.round( (dexterity - 11) / 2 );
                 document.main.dexterity.value = dexterity;
                 document.main.dex_mod.value = dex_mod;
                 break;

         case 3: constitution++;
                 con_mod = Math.round( (constitution - 11) / 2 );
                 document.main.constitution.value = constitution;
                 document.main.con_mod.value = con_mod;
                 break;

         case 4: intelligence++;
                 int_mod = Math.round( (intelligence - 11) / 2 );
                 document.main.intelligence.value = intelligence;
                 document.main.int_mod.value = int_mod;
                 break;

         case 5: wisdom++;
                 wis_mod = Math.round( (wisdom - 11) / 2 );
                 document.main.wisdom.value = wisdom;
                 document.main.wis_mod.value = wis_mod;
                 break;

         case 6: charisma++;
                 chr_mod = Math.round( (charisma - 11) / 2 );
                 document.main.charisma.value = charisma;
                 document.main.chr_mod.value = chr_mod;
                 break;

       }     // end of switch

       bonus_ability--;
       document.main.bonus_ability.value = bonus_ability;
    }

    // Calculate the total number of skill
    // points the character has starting off.

    // Note: This function is upgraded to v3.5.
    function Calc_Skill_Points()
    {
      var count;
      var temp_int_mod;    // temporary intelligence modifier

      temp_int_mod = int_mod;
      // if the character is a half-orc, it gets a -2 to intelligence
      if (race == HALF_ORC)
        temp_int_mod -= 1;

      skill_points = 0;

      // don nott forget to set all skill ranks to zero
      // This is now done when Ability Scores are rolled.
      // for (count = 0; count <= USE_ROPE; count++)
      //   skills[count] = 0;

      // get skill points for each class
      for (count = 0; count <= WIZARD; count++)
      {
         // check if player has this class
         if (class_levels[count] > 0)
         {
            // if this is starting class, use special formula
            if (count == starting_class)
            {
               switch (count)
               {
                 case BARBARIAN: 
                 case DRUID:
                 case MONK:
                             skill_points += (4 + temp_int_mod) * 4;
                             skill_points += (4 + temp_int_mod) * (class_levels[count] - 1);
                             break;

                 case BARD:
                 case RANGER:
                             skill_points += (6 + temp_int_mod) * 4;
                             skill_points += (6 + temp_int_mod) * (class_levels[count] - 1);
                             break;

                 case CLERIC:
                 case FIGHTER:
                 case PALADIN:
                 case SORCERER:
                 case WIZARD:
                            skill_points += (2 + temp_int_mod) * 4;
                            skill_points += (2 + temp_int_mod) * (class_levels[count] - 1);
                            break;

                 case ROGUE:
                            skill_points += (8 + temp_int_mod) * 4;
                            skill_points += (8 + temp_int_mod) * (class_levels[count] - 1);
                            break;

               }  // end of switch
            }     // end of if starting_class

            // not the starting class, use basic formula
            else
            {
              switch (count)
              {
                 case BARBARIAN:
                 case DRUID:
                 case MONK:
                        skill_points += (4 + temp_int_mod) * class_levels[count];
                        break;

                 case BARD:
                 case RANGER:
                        skill_points += (6 + temp_int_mod) * class_levels[count];
                             break;

                 case CLERIC:
                 case FIGHTER:
                 case PALADIN:
                 case SORCERER:
                 case WIZARD:
                        skill_points += (2 + temp_int_mod) * class_levels[count];
                        break;

                 case ROGUE:
                        skill_points += (8 + temp_int_mod) * class_levels[count];
                        break;

              }     // end of switch
            }      // end of else
           }       // end of if character has this class

          }        // end of for loop

          // if the character is human, give extra points for first level
          if (race == HUMAN)
             skill_points += 4;

          // if the level is above one and the chracter is human add points
          if ( (total_level > 1) && (race == HUMAN) )
             skill_points += (total_level - 1);

          // you must start with at least 4 skill points (page 62 of the PHB)
          if (skill_points < 4)
             skill_points = 4;
          
          max_skill_points = skill_points;
    }              // end of calc_skill_points()



    // This function determines if the skill selected is a
    // native or cross-class skill.

    // Note: This function has been upgraded to DnD v3.5
    function Get_Skill_Value(skill_number)
    {
       var points;

       switch (skill_number)
       {
         case APPRAISE:
                      if ( (class_levels[BARD]) || (class_levels[ROGUE]) )
                         points = 1;
                      else
                         points = 2;
                      break;

         case BALANCE:
                     if ( (class_levels[BARD]) || (class_levels[MONK]) ||
                          (class_levels[ROGUE]) )
                        points = 1;
                     else
                        points = 2;
                     break;

         case BLUFF:
                   if ( (class_levels[BARD]) || (class_levels[ROGUE]) ||
                        (class_levels[SORCERER]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case CLIMB:
                   if ( (class_levels[BARBARIAN]) || (class_levels[BARD]) ||
                        (class_levels[FIGHTER]) || (class_levels[MONK]) ||
                        (class_levels[RANGER]) || (class_levels[ROGUE]) )
                      points = 1;
                   else
                      points = 2;
                   break;

         case CONCENTRATION:
                   if ( (class_levels[BARD]) || (class_levels[CLERIC]) ||
                        (class_levels[DRUID]) || (class_levels[MONK]) ||
                        (class_levels[PALADIN]) || (class_levels[RANGER]) ||
                        (class_levels[SORCERER]) || (class_levels[WIZARD]) )
                        points = 1;
                   else
                      points = 2;
                   break;

         case CRAFT:
                   points = 1;
                   break;

         case DECIPHER_SCRIPT:
                    if ( (class_levels[BARD]) || (class_levels[ROGUE]) ||
                         (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case DIPLOMACY:
                     if ( (class_levels[BARD]) || (class_levels[CLERIC]) ||
                          (class_levels[DRUID]) || (class_levels[MONK]) ||
                          (class_levels[PALADIN]) || (class_levels[ROGUE]) )
                        points = 1;
                     else
                        points = 2;
                     break;

         case DISABLE_DEVICE:
                     if (class_levels[ROGUE])
                        points = 1;
                     else
                        points = 2;
                     break;

         case DISGUISE:
                     if ( (class_levels[BARD]) || (class_levels[ROGUE]) )
                       points = 1;
                     else
                       points = 2;
                     break;

         case ESCAPE_ARTIST:
                     if ( (class_levels[BARD]) || (class_levels[MONK]) ||
                          (class_levels[ROGUE]) )
                        points = 1;
                     else
                        points = 2;
                     break;

         case FORGERY:
                     if (class_levels[ROGUE])
                        points = 1;
                     else
                        points = 2;
                     break;

         case GATHER_INFORMATION:
                     if ( (class_levels[BARD]) || (class_levels[ROGUE]) )
                       points = 1;
                     else
                       points = 2;
                     break;

         case HANDLE_ANIMAL:
                     if ( (class_levels[BARBARIAN]) || (class_levels[DRUID]) ||
                          (class_levels[FIGHTER]) || (class_levels[PALADIN]) ||
                          (class_levels[RANGER]) )
                        points = 1;
                     else
                        points = 2;
                     break;

         case HEAL:
                     if ( (class_levels[CLERIC]) || (class_levels[DRUID]) ||
                          (class_levels[PALADIN]) || (class_levels[RANGER]) )
                          points = 1;
                     else
                        points = 2;
                     break;

         case HIDE_SKILL:
                     if ( (class_levels[BARD]) || (class_levels[MONK]) ||
                          (class_levels[RANGER]) || (class_levels[ROGUE]) )
                          points = 1;
                     else
                       points = 2;
                     break;

         case INTIMIDATE:
                     if ( (class_levels[BARBARIAN]) || (class_levels[FIGHTER]) ||
                        (class_levels[ROGUE]) )
                       points = 1;
                     else
                       points = 2;
                     break;


         case JUMP:
                    if ( (class_levels[BARBARIAN]) || (class_levels[BARD]) ||
                         (class_levels[FIGHTER]) || (class_levels[MONK]) ||
                         (class_levels[RANGER]) || (class_levels[ROGUE]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case KNOWLEDGE_ARCANA:
                    if ( (class_levels[BARD]) || (class_levels[CLERIC]) ||
                         (class_levels[MONK]) || (class_levels[SORCERER]) ||
                         (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case KNOWLEDGE_ARCHITECTURE:
                    if ( (class_levels[BARD]) || (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case KNOWLEDGE_DUNGEONEERING:
                    if ( (class_levels[BARD]) || (class_levels[RANGER]) ||
                         (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case KNOWLEDGE_GEOGRAPHY:
                    if ( (class_levels[BARD]) || (class_levels[RANGER]) ||
                         (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case KNOWLEDGE_HISTORY:
                    if ( (class_levels[BARD]) || (class_levels[CLERIC]) ||
                         (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case KNOWLEDGE_LOCAL:
                    if ( (class_levels[BARD]) || (class_levels[ROGUE]) ||
                         (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case KNOWLEDGE_RELIGION:
                    if ( (class_levels[BARD]) || (class_levels[CLERIC]) ||
                         (class_levels[MONK]) || 
                         (class_levels[PALADIN]) || (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case KNOWLEDGE_NATURE:
                    if ( (class_levels[BARD]) || (class_levels[DRUID]) ||
                         (class_levels[RANGER]) || (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;

         case KNOWLEDGE_NOBILITY:
                    if ( (class_levels[BARD]) || (class_levels[PALADIN]) ||
                         (class_levels[WIZARD]) )
                      points = 1;
                    else
                      points = 2;
                    break;

         case KNOWLEDGE_PLANES:
                    if ( (class_levels[BARD]) || (class_levels[CLERIC]) ||
                         (class_levels[WIZARD]) )
                       points = 1;
                    else
                       points = 2;
                    break;


         case LISTEN:
                   if ( (class_levels[BARBARIAN]) || (class_levels[BARD]) ||
                        (class_levels[DRUID]) || 
                        (class_levels[MONK]) || (class_levels[RANGER]) ||
                        (class_levels[ROGUE]) )
                      points = 1;
                   else
                      points = 2;
                   break;

         case MOVE_SILENTLY:
                   if ( (class_levels[BARD]) || (class_levels[MONK]) ||
                        (class_levels[RANGER]) || (class_levels[ROGUE]) )
                      points = 1;
                   else
                      points = 2;
                   break;

         case OPEN_LOCK:
                   if (class_levels[ROGUE])
                     points = 1;
                   else
                     points = 2;
                   break;

         case PERFORM:
                   if ( (class_levels[BARD]) || (class_levels[MONK]) ||
                        (class_levels[ROGUE]) )
                      points = 1;
                   else
                      points = 2;
                   break;

         case PROFESSION:
                  if ( (class_levels[BARD]) || (class_levels[CLERIC]) ||
                       (class_levels[DRUID]) || (class_levels[MONK]) ||
                       (class_levels[PALADIN]) || (class_levels[RANGER]) ||
                       (class_levels[ROGUE]) || (class_levels[SORCERER]) ||
                       (class_levels[WIZARD]) )
                     points = 1;
                  else
                    points = 2;
                  break;

         case RIDE:
                  if ( (class_levels[BARBARIAN]) || (class_levels[FIGHTER]) ||
                       (class_levels[DRUID]) ||
                       (class_levels[PALADIN]) || (class_levels[RANGER]) )
                     points = 1;
                  else
                     points = 2;
                  break;

         case SEARCH:
                  if ( (class_levels[RANGER]) || (class_levels[ROGUE]) )
                     points = 1;
                  else
                     points = 2;
                  break;

         case SENSE_MOTIVE:
                  if ( (class_levels[BARD]) || (class_levels[ROGUE]) ||
                       (class_levels[MONK]) || (class_levels[PALADIN]) )
                     points = 1;
                  else
                     points = 2;
                  break;

         case SLEIGHT_OF_HAND:
                  if ( (class_levels[BARD]) || (class_levels[ROGUE]) )
                     points = 1;
                  else
                     points = 2;
                  break;

         case SPEAK_LANGUAGE:
                  if (class_levels[BARD])
                    points = 1;
                  else
                    points = 2;
                  break;

         case SPELLCRAFT:
                  if ( (class_levels[BARD]) || (class_levels[CLERIC]) ||
                       (class_levels[DRUID]) || (class_levels[SORCERER]) ||
                       (class_levels[WIZARD]) )
                     points = 1;
                  else
                     points = 2;
                  break;

         case SPOT:
                 if ( (class_levels[RANGER]) || (class_levels[ROGUE]) ||
                      (class_levels[DRUID]) || (class_levels[MONK]) )
                   points = 1;
                 else
                   points = 2;
                 break;

         case SURVIVAL:
                 if ( (class_levels[BARBARIAN]) || (class_levels[DRUID]) ||
                      (class_levels[RANGER]) )
                    points = 1;
                 else
                    points = 2;
                 break;

         case SWIM:
                 if ( (class_levels[BARBARIAN]) || (class_levels[BARD]) ||
                      (class_levels[DRUID]) || (class_levels[FIGHTER]) ||
                      (class_levels[MONK]) || (class_levels[RANGER]) ||
                      (class_levels[ROGUE]) )
                    points = 1;
                 else
                    points = 2;
                 break;

         case TUMBLE:
                 if ( (class_levels[BARD]) || (class_levels[MONK]) ||
                      (class_levels[ROGUE]) )
                    points = 1;
                 else
                    points = 2;
                 break;

         case USE_MAGIC_DEVICE:
                 if ( (class_levels[BARD]) || (class_levels[ROGUE]) )
                    points = 1;
                 else
                    points = 2;
                 break;

         case USE_ROPE:
                 if ( (class_levels[RANGER]) || (class_levels[ROGUE]) )
                    points = 1;
                 else
                    points = 2;
                 break;

           }  // end of switch

        return points;
                  
    }       // end of get_skill_value()




    
    // This function displays the ranks a character has
    // in each skill inside the "skill" window.
    function Display_Skill_Points()
    {
       var index;
       var element_index;

       element_index = 2;
       for (index = 0; index <= USE_ROPE; index++)
       {
          newwin.document.forms[0].elements[element_index].value = skills[index];
          element_index += 3;
       }
    }
    


    // Increase a skill, reducing the skills points.
    function Skill_Up(skill_number)
    {
       var points;

       points = Get_Skill_Value(skill_number);
       // if we already have max ranks in this skill (level + 3)
       // then don not increase skill
       if ( skills[skill_number] >= (total_level + 3) )
       {
          newwin.alert('You have the maximum number of ranks in this skill.');
          return;
       }
       // put a skill cap on cross-class skills too ( total_level + 3 ) / 2
       if ( (points == 2) && ( skills[skill_number] >= ( (total_level + 3) /2) ) )
       {
           newwin.alert('You have the maximum number of ranks in this skill.');
           return;
       }

       if (points <= skill_points)
       {
          skill_points -= points;
          skills[skill_number]++;
          newwin.document.skills.sp1.value = skill_points;
          newwin.document.skills.sp2.value = skill_points;
          Display_Skill_Points();
       }
       else
          alert('You do not have enough skill points.');


    }

    // Decrease a skill, add points back to "skill_points".
    function Skill_Down(skill_number)
    {
       var points;

       // make sure rank does not become less than 0
       if (skills[skill_number] == 0)
         return;

       // if this skill was given because of a selected
       // feat, then we cannot let it drop below "2"
       switch ( skill_number )
       {
        case JUMP:
        case TUMBLE:
              if ( (skills[skill_number] < 3) && (feats[ACROBATIC]) )
                return;
              break;

        case BALANCE:
        case ESCAPE_ARTIST:
             if ( (skills[skill_number] < 3) && (feats[AGILE]) )
               return;
             break;
        
        case LISTEN:
        case SPOT:
             if ( (skills[skill_number] < 3) && (feats[ALERTNESS]) )
                return;
             break;
 
        case HANDLE_ANIMAL:
        case RIDE:
             if ( (skills[skill_number] < 3) && (feats[ANIMAL_AFFINITY]) )
                return;
             break;

        case CLIMB:
        case SWIM:
             if ( (skills[skill_number] < 3) && (feats[ATHLETIC]) )
                return;
             break;

        case DISGUISE:
        case FORGERY:
             if ( (skills[skill_number] < 3) && (feats[DECEITFUL]) )
                return;
             break;

        case SLEIGHT_OF_HAND:
        case USE_ROPE:
             if ( (skills[skill_number] < 3) && (feats[DEFT_HANDS]) )
                return;
             break;

        case APPRAISE:
        case DECIPHER_SCRIPT:
             if ( (skills[skill_number] < 3) && (feats[DILIGENT]) )
                return;
             break;

        case GATHER_INFORMATION:
        case SEARCH:
             if ( (skills[skill_number] < 3) && (feats[INVESTIGATOR]) )
                return;
             break;

        case SPELLCRAFT:
        case USE_MAGIC_DEVICE:
             if ( (skills[skill_number] < 3) && (feats[MAGICAL_APTITUDE]) )
                return;
             break;

        case DIPLOMACY:
        case SENSE_MOTIVE:
             if ( (skills[skill_number] < 3) && (feats[NEGOTIATOR]) )
                return;
             break;

        case DISABLE_DEVICE:
        case OPEN_LOCK:
             if ( (skills[skill_number] < 3) && (feats[NIMBLE_FINGERS]) )
                return;
             break;

        case BLUFF:
        case INTIMIDATE:
             if ( (skills[skill_number] < 3) && (feats[PERSUASIVE]) )
                return;
             break;

        case HEAL:
        case SURVIVAL:
             if ( (skills[skill_number] < 3) && (feats[SELF_SUFFICIENT]) )
                return;
             break;

        case HIDE_SKILL:
        case MOVE_SILENTLY:
             if ( (skills[skill_number] < 3) && (feats[STEALTHY]) )
                return;
             break;
       }    // end of switch (make sure skills were not granted by feats

       points = Get_Skill_Value(skill_number);
       if ( (points + skill_points) <= max_skill_points)
       {
          skill_points += points;
          skills[skill_number]--;
          newwin.document.skills.sp1.value = skill_points;
          newwin.document.skills.sp2.value = skill_points;
          Display_Skill_Points();
       }
    }



    // This function opens a window which allows the
    // user to select which skills he/she wants.

    function Get_Skills()
    {
       var skill_value;

       if (intelligence == 0)
       {
          alert('Please roll ability scores first.');
          return;
       }

       // Do this is roll ability scores
       // Calc_Skill_Points();

       newwin = open('', 'Skills', min_feature);

       newwin.document.write('<center>');
       newwin.document.write('Please select your skills from the list below.');

       newwin.document.write('<form name=skills>');
       newwin.document.write('<table>');

       newwin.document.write('<tr>');
         newwin.document.write('<td>Skill points:</td>');
         newwin.document.write('<td align=center><input type=text name=sp1 size=2></td>');
       newwin.document.write('</tr>');

       newwin.document.write('<tr>');
       newwin.document.write('<td><br></td>');
       newwin.document.write('<td></td>');
       newwin.document.write('</tr>');

       for (count = 0; count <= USE_ROPE; count++)
       {
         newwin.document.write('<tr>');
         newwin.document.write('<td>');
         // try colour coding skills (native or cross-class)
           skill_value = Get_Skill_Value(count);
           if (skill_value == 1)
              newwin.document.write('<font color=green>');
           else
              newwin.document.write('<font color=blue>');
           // newwin.document.write( Proper_Case(skill_names[count]), ':');
           // add text for trained or untrained
           newwin.document.write( Proper_Case(skill_names[count]), ' ');
           switch (count)
           {
              case APPRAISE:
              case BALANCE:
              case BLUFF:
              case CLIMB:
              case CONCENTRATION:
              case CRAFT:
              case DIPLOMACY:
              case DISGUISE:
              case ESCAPE_ARTIST:
              case FORGERY:
              case GATHER_INFORMATION:
              case HEAL:
              case HIDE_SKILL:
              case INTIMIDATE:
              case JUMP:
              case LISTEN:
              case MOVE_SILENTLY:
              case PERFORM:
              case RIDE:
              case SEARCH:
              case SENSE_MOTIVE:
              case SPOT:
              case SURVIVAL:
              case SWIM:
              case USE_ROPE:
                   newwin.document.write(' (UT) :');
                   break;
              default:
                   newwin.document.write(' (T) :');
                   break;
           }      // end of switch

           newwin.document.write('</font>');
         newwin.document.write('</td>');
         newwin.document.write('<td>');
           newwin.document.write('<input type=button value="<" onClick="window.opener.Skill_Down(', count, ')">');
           newwin.document.write('<input type=text name=', skill_names[count], ' size=2>');
           newwin.document.write('<input type=button value=">" onClick="window.opener.Skill_Up(', count, ')">');
         newwin.document.write('</td>');
         newwin.document.write('</tr>');

       }       // end of for loop

       newwin.document.write('<tr>');
       newwin.document.write('<td><br></td>');
       newwin.document.write('<td></td>');
       newwin.document.write('</tr>');

       newwin.document.write('<tr>');
         newwin.document.write('<td>Skill points:</td>');
         newwin.document.write('<td align=center><input type=text name=sp2 size=2></td>');
       newwin.document.write('</tr>');

       newwin.document.write('</table>');
         newwin.document.write('<input type=button name=close_skills value="Close" onClick="window.close()">');
       newwin.document.write('</form>');
       newwin.document.write('</center>');

       newwin.document.close();
       newwin.document.skills.sp1.value = skill_points;
       newwin.document.skills.sp2.value = skill_points;
       newwin.focus();
       skill_window = newwin;
       Display_Skill_Points();

    }


    // This function checks to see which feats the character gets automatically
    // via his/her class. The feats the character gets (because of class)
    // are stored in the "feats" array.
    // This function is called from Calc_Feat_Points()
    function Get_Class_Feats()
    {
       if (class_levels[BARBARIAN])
       {
          feats[SIMPLE_WEAPON_PROFICIENCY] = 1;
          feats[MARTIAL_WEAPON_PROFICIENCY] = 1;
          feats[ARMOR_PROFICIENCY_LIGHT] = 1;
          feats[ARMOR_PROFICIENCY_MEDIUM] = 1;
          feats[SHIELD_PROFICIENCY] = 1;
       }
       if (class_levels[BARD])
       {
          feats[SIMPLE_WEAPON_PROFICIENCY] = 1;
          feats[ARMOR_PROFICIENCY_LIGHT] = 1;
          feats[SHIELD_PROFICIENCY] = 1;
       }
       if (class_levels[CLERIC])
       {
          feats[SIMPLE_WEAPON_PROFICIENCY] = 1;
          feats[ARMOR_PROFICIENCY_LIGHT] = 1;
          feats[ARMOR_PROFICIENCY_MEDIUM] = 1;
          feats[ARMOR_PROFICIENCY_HEAVY] = 1;
          feats[SHIELD_PROFICIENCY] = 1;
       }
       
       // Hey everyone. Thanks for reading my code!
       
       if (class_levels[DRUID])
       {
          feats[ARMOR_PROFICIENCY_LIGHT] = 1;
          feats[ARMOR_PROFICIENCY_MEDIUM] = 1;
          feats[SHIELD_PROFICIENCY] = 1;
       }
       if (class_levels[FIGHTER])
       {
          feats[SIMPLE_WEAPON_PROFICIENCY] = 1;
          feats[MARTIAL_WEAPON_PROFICIENCY] = 1;
          feats[ARMOR_PROFICIENCY_LIGHT] = 1;
          feats[ARMOR_PROFICIENCY_MEDIUM] = 1;
          feats[ARMOR_PROFICIENCY_HEAVY] = 1;
          feats[SHIELD_PROFICIENCY] = 1;
          feats[TOWER_SHIELD_PROFICIENCY] = 1;
       } 
       // Seems that monks do not get any starting feats
       // see page 40 of the Players Hand Book
       if (class_levels[PALADIN])
       {
          feats[SIMPLE_WEAPON_PROFICIENCY] = 1;
          feats[MARTIAL_WEAPON_PROFICIENCY] = 1;
          feats[ARMOR_PROFICIENCY_LIGHT] = 1;
          feats[ARMOR_PROFICIENCY_MEDIUM] = 1;
          feats[ARMOR_PROFICIENCY_HEAVY] = 1;
          feats[SHIELD_PROFICIENCY] = 1;
       }
       if (class_levels[RANGER])
       {
         feats[SIMPLE_WEAPON_PROFICIENCY] = 1;
         feats[MARTIAL_WEAPON_PROFICIENCY] = 1;
         feats[ARMOR_PROFICIENCY_LIGHT] = 1;
         feats[SHIELD_PROFICIENCY] = 1;
         // ranger gains Endurance at 3rd level
         if ( class_levels[RANGER] >= 3 )
            feats[ENDURANCE] = 1;
       }
       if (class_levels[ROGUE])
       {
         feats[SIMPLE_WEAPON_PROFICIENCY] = 1;
         feats[ARMOR_PROFICIENCY_LIGHT] = 1;
       }
       if (class_levels[SORCERER])
         feats[SIMPLE_WEAPON_PROFICIENCY] = 1;
       // wizards do not get any bonus feats
       // page 56 of the Players Hand Book 

    }   // end of Get_Glass_Feats

   

    // This function calculates the number of feats the character
    // will start with. The number will be stored in
    // "feat_points".
    function Calc_Feat_Points()
    {
       var count;

       // set all feat scores to zero
       // This is now done when we Roll Ability Scores.
       //for (count = 0; count <= WIDEN_SPELL; count++)
       //   feats[count] = 0;

       fighter_feats = wizard_feats = 0;

       // for the first level, we get a feat
       feat_points = 1;

       // for being human we can get another feat
       if (race == HUMAN)
         feat_points += 1;

       // we get an extra feat every third level
       feat_points += Math.floor (total_level / 3 );

       // fighters get an extra feat on ever even level
       // fighters also get a bonus feat at first level
       if (class_levels[FIGHTER])
       {
         fighter_feats += 1;
         fighter_feats += Math.floor( class_levels[FIGHTER] / 2 );
       }

       // wizards get bonus feats every 5 levels
       if (class_levels[WIZARD])
         wizard_feats += Math.floor(class_levels[WIZARD] / 5);


       // get automatic class feats
       Get_Class_Feats();
    }

    // This function displays the ranks in each feat
    // in the feats window.
    function Display_Feat_Points()
    {
       var index;
       var element_index = 2;

       if ( class_levels[FIGHTER] ) element_index++;
       if ( class_levels[WIZARD] )  element_index++;

       for (index = 0; index <= WIDEN_SPELL; index++)
       {
          featwin.document.forms[0].elements[element_index].value = feats[index];
          element_index += 3;
       }   // end of for loop

       // show remaining feat points
       featwin.document.feats.feat_points1.value = feat_points;
       featwin.document.feats.feat_points2.value = feat_points;

       // show remaining fighter feats
       if ( class_levels[FIGHTER] )
       {
          featwin.document.feats.fighter_feats1.value = fighter_feats;
          featwin.document.feats.fighter_feats2.value = fighter_feats;
       }
       // show wizard feats
       if ( class_levels[WIZARD] )
       {
          featwin.document.feats.wizard_feats1.value = wizard_feats;
          featwin.document.feats.wizard_feats2.value = wizard_feats;
       }
    }     // end of display_feat_points()


    // This function displays the feats window
    // and allows the user to select which feats he/she
    // has.
    function Get_Feats()
    {
        var index;

       if (intelligence == 0)
       {
          alert('Please roll ability scores first.');
          return;
       }

        featwin = open('', 'Skills', min_feature);
        // Do this when we roll ability scores
        // Calc_Feat_Points();

        featwin.document.writeln('<center>');
        featwin.document.writeln('Please select your feats from the list below.<br>');
        featwin.document.writeln('<br>');
        featwin.document.writeln('<form name=feats>');
        featwin.document.writeln('<table>');

        featwin.document.writeln('<tr>');
        featwin.document.writeln('<td align=right><b>Feat points:</b><br>');
        if ( class_levels[FIGHTER] )
          featwin.document.writeln('<b>Fighter Feats:</b><br>');
        if ( class_levels[WIZARD] )
          featwin.document.writeln('<b>Wizard Feats:</b><br>');
        featwin.document.writeln('</td><td align=center><input type=text name=feat_points1 size=2><br>');
        if ( class_levels[FIGHTER] )
          featwin.document.writeln('<input type=text name=fighter_feats1 size=2><br>');
        if ( class_levels[WIZARD] )
          featwin.document.writeln('<input type=text name=wizard_feats1 size=2><br>');
        featwin.document.writeln('</td></tr>');

        if ( (class_levels[WIZARD]) || (class_levels[FIGHTER]) )
           featwin.document.writeln('<tr><td><br><br></td></tr>');


        for (index = 0; index <= WIDEN_SPELL; index++)
        {
           featwin.document.writeln('<tr>');
           featwin.document.writeln('<td align=right>');
           if ( Is_Fighter_Bonus_Feat( index ) )
              featwin.document.writeln('<font size=-1>(Fighter Bonus Feat)</font>&nbsp;&nbsp;&nbsp;&nbsp; ');
           if ( Is_Wizard_Bonus_Feat( index ) )
              featwin.document.writeln('<font size=-1>(Wizard Bonus Feat)</font>&nbsp;&nbsp;&nbsp;&nbsp; ');
           featwin.document.writeln('</td>');
           featwin.document.writeln('<td>');
           featwin.document.writeln('<b title="', feat_info[index], '.">' , Proper_Case( feat_names[index] ), '</b>:' );
           featwin.document.writeln('</td>');
           featwin.document.writeln('<td align=center>');
           featwin.document.writeln('<input type=button value="<" onClick="window.opener.Feat_Down(', index, ')">');
           featwin.document.writeln('<input type=text name=', feat_names[index], ' size=2>');
           featwin.document.writeln('<input type=button value=">" onClick="window.opener.Feat_Up(', index, ')">');
           featwin.document.writeln('</td>');
           featwin.document.writeln('</tr>');

        }     // end of for loop

        if ( (class_levels[WIZARD]) || (class_levels[FIGHTER]) )
           featwin.document.writeln('<tr><td><br><br></td></tr>');

        featwin.document.writeln('<tr>');
        featwin.document.writeln('<td align=right><b>Feat points:</b><br>');
        if ( class_levels[FIGHTER] )
          featwin.document.writeln('<b>Fighter Feats:</b><br>');
        if ( class_levels[WIZARD] )
          featwin.document.writeln('<b>Wizard Feats:</b><br>');
        featwin.document.writeln('</td><td align=center><input type=text name=feat_points2 size=2><br>');
        if ( class_levels[FIGHTER] )
          featwin.document.writeln('<input type=text name=fighter_feats2 size=2><br>');
        if ( class_levels[WIZARD] )
          featwin.document.writeln('<input type=text name=wizard_feats2 size=2><br>');
        featwin.document.writeln('</td></tr>');

        featwin.document.writeln('</table>');
        featwin.document.writeln('<br>');
        featwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
        featwin.document.writeln('</form>');
        featwin.document.writeln('</center>');


        featwin.document.close();
        featwin.focus();
        Display_Feat_Points();
    }




    // This function checks that the character has all of
    // the requirements for a given feat.
    // Note: This function is now updated to v3.5
    function Feat_Open(feat_index)
    {
       var ok = true;
       var temp_dex, temp_str, temp_int;

       // adjust for race ability scores
       if ( (race == ELF) || (race == HALFLING) )
          temp_dex = dexterity + 2;
       else temp_dex = dexterity;

       if (race == HALF_ORC)
          temp_str = strength + 2;
       else if ( (race == GNOME) || (race == HALFLING) )
          temp_str = strength - 2;
       else temp_strength = strength;

       if (race == HALF_ORC)
         temp_int = intelligence - 2;
       else temp_int = intelligence;
 
       if (temp_int < 3) temp_int = 3;


       switch (feat_index)
       {
          case ARMOR_PROFICIENCY_MEDIUM:
                     if (!feats[ARMOR_PROFICIENCY_LIGHT])
                       ok = false;
                     break;

          case ARMOR_PROFICIENCY_HEAVY:
                     if (!feats[ARMOR_PROFICIENCY_MEDIUM])
                        ok = false;
                     break;

          case AUGMENT_SUMMONING:
                     if (!feats[SPELL_FOCUS])
                        ok = false;
                     break;

          case BREW_POTION:
          // spell caster level >= 3
                     if ( (class_levels[BARD] < 3) && (class_levels[CLERIC] < 3) &&
                          (class_levels[DRUID] < 3) && (class_levels[PALADIN] < 3) &&
                          (class_levels[RANGER] < 3) && (class_levels[SORCERER] < 3) &&
                          (class_levels[WIZARD] < 3) )
                        ok = false;
                        break;

          case CLEAVE:
                   if ( (temp_str < 13) || (!feats[POWER_ATTACK]) )
                      ok = false;
                   break;

          case COMBAT_EXPERTISE:
                   if (temp_int < 13)
                      ok = false;
                   break;

          case CRAFT_MAGIC_ARMS_AND_ARMOR:
          // spell caster level >= 5
                     if ( (class_levels[BARD] < 5) && (class_levels[CLERIC] < 5) &&
                          (class_levels[DRUID] < 5) && (class_levels[PALADIN] < 5) &&
                          (class_levels[RANGER] < 5) && (class_levels[SORCERER] < 5) &&
                          (class_levels[WIZARD] < 5) )
                        ok = false;
                        break;

          case CRAFT_ROD:
          // spell caster level >= 9
                     if ( (class_levels[BARD] < 9) && (class_levels[CLERIC] < 9) &&
                          (class_levels[DRUID] < 9) && (class_levels[PALADIN] < 9) &&
                          (class_levels[RANGER] < 9) && (class_levels[SORCERER] < 9) &&
                          (class_levels[WIZARD] < 9) )
                        ok = false;
                        break;

          case CRAFT_STAFF:
          // spell caster level >= 12
                     if ( (class_levels[BARD] < 12) && (class_levels[CLERIC] < 12) &&
                          (class_levels[DRUID] < 12) && (class_levels[PALADIN] < 12) &&
                          (class_levels[RANGER] < 12) && (class_levels[SORCERER] < 12) &&
                          (class_levels[WIZARD] < 12) )
                        ok = false;
                        break;

          case CRAFT_WAND:
          // spell caster level >= 5
                     if ( (class_levels[BARD] < 5) && (class_levels[CLERIC] < 5) &&
                          (class_levels[DRUID] < 5) && (class_levels[PALADIN] < 5) &&
                          (class_levels[RANGER] < 5) && (class_levels[SORCERER] < 5) &&
                          (class_levels[WIZARD] < 5) )
                        ok = false;
                        break;

          case CRAFT_WONDEROUS_ITEM:
          // spell caster level >= 3
                     if ( (class_levels[BARD] < 3) && (class_levels[CLERIC] < 3) &&
                          (class_levels[DRUID] < 3) && (class_levels[PALADIN] < 3) &&
                          (class_levels[RANGER] < 3) && (class_levels[SORCERER] < 3) &&
                          (class_levels[WIZARD] < 3) )
                        ok = false;
                        break;

          case DEFLECT_ARROWS:
                    if ( (temp_dex < 13) || (feats[IMPROVED_UNARMED_STRIKE] < 1) )
                       ok = false;
                    break;

          case DIEHARD:
                    if (!feats[ENDURANCE])
                       ok = false;
                    break;

          case DODGE:
                    if (temp_dex < 13)
                      ok = false;
                    break;

          case EXOTIC_WEAPON_PROFICIENCY:
                    if (base_attack_bonus < 1)
                      ok = false;
                    break;


          case EXTRA_TURNING:
                   if ( (!class_levels[CLERIC]) && (!class_levels[PALADIN]) )
                      ok = false;
                   break;

          case FAR_SHOT:
                   if (feats[POINT_BLANK_SHOT] < 1)
                     ok = false;
                   break;

          case FORGE_RING:
          // spell caster level >= 12
                     if ( (class_levels[BARD] < 12) && (class_levels[CLERIC] < 12) &&
                          (class_levels[DRUID] < 12) && (class_levels[PALADIN] < 12) &&
                          (class_levels[RANGER] < 12) && (class_levels[SORCERER] < 12) &&
                          (class_levels[WIZARD] < 12) )
                        ok = false;
                        break;

          case GREAT_CLEAVE:
                   if (temp_str < 13)
                      ok = false;
 
                   if ( (feats[POWER_ATTACK] < 1) || (feats[CLEAVE] < 1) || 
                        (base_attack_bonus < 4) )
                      ok = false;
                   break;

          case GREATER_SPELL_PENETRATION:
                 if (!feats[SPELL_PENETRATION])
                    ok = false;
                 break;

          case GREATER_TWO_WEAPON_FIGHTING:
                 if (temp_dex < 19)
                    ok = false;

                 if ( (!feats[IMPROVED_TWO_WEAPON_FIGHTING]) ||
                      (!feats[TWO_WEPAON_FIGHTING]) || (base_attack_bonus < 11) )
                    ok = false;

                 if ( ( class_levels[RANGER] >= 2 ) && ( ranger_combat_style ) )
                 {
                     if ( ( feats[IMPROVED_TWO_WEAPON_FIGHTING] ) &&
                          ( base_attack_bonus >= 11 ) &&
                          ( temp_dex >= 19) )
                        ok = true;
                 }
                 break;

          case GREATER_WEAPON_FOCUS:
                 if (!feats[WEAPON_FOCUS])
                    ok = false;
                 break;

          case GREATER_WEAPON_SPECIALIZATION:
                 if ( (!feats[GREATER_WEAPON_FOCUS]) || (!feats[WEAPON_FOCUS]) ||
                      (!feats[WEAPON_SPECIALIZATION]) || (class_levels[FIGHTER] < 12) )
                    ok = false;
                 break;

          case IMPROVED_BULL_RUSH:
                 if (temp_str < 13)
                    ok = false;

                 if (feats[POWER_ATTACK] < 1)
                    ok = false;
                 break;

          case IMPROVED_CRITICAL:
               if (base_attack_bonus < 8)
                 ok = false;
               break;


          // these feats have same prerequisites
          case IMPROVED_DISARM:
          case IMPROVED_FEINT:
          case IMPROVED_TRIP:
               if (temp_int < 13)
                  ok = false;

               if (feats[COMBAT_EXPERTISE] < 1)
                  ok = false;
               break;
 
          case IMPROVED_GRAPPLE:
              if (temp_dex < 13)
                 ok = false;

              if (!feats[IMPROVED_UNARMED_STRIKE])
                 ok = false;
              break;

          case IMPROVED_OVERRUN:
              if (temp_str < 13)
                 ok = false;

              if (!feats[POWER_ATTACK])
                 ok = false;
              break;

          case IMPROVED_PRECISE_SHOT:
              if (temp_dex < 19)
                ok = false;

              if ( (!feats[POINT_BLANK_SHOT]) ||
                   (!feats[PRECISE_SHOT]) || (base_attack_bonus < 11) )
                 ok = false;
              break;

          case IMPROVED_SHIELD_BASH:
             if (!feats[SHIELD_PROFICIENCY])
                  ok = false;
             break;

          case IMPROVED_SUNDER:
              if (temp_str < 13)
                 ok = false;

              if (!feats[POWER_ATTACK])
                 ok = false;
              break;

          case IMPROVED_TWO_WEAPON_FIGHTING:
              if ( (! feats[TWO_WEAPON_FIGHTING]) ||
                   (temp_dex < 17) || (base_attack_bonus < 6) )
                 ok = false;

              if ( (class_levels[RANGER] >= 2) && (ranger_combat_style) &&
                   (temp_dex >= 17) && (base_attack_bonus >= 6) )
                 ok = true;

              break;

          case LEADERSHIP:
                 if (total_level < 6)
                    ok = false;
                 break;

          case MANYSHOT:
                 if ( (temp_dex < 17) || (!feats[POINT_BLANK_SHOT]) ||
                      (!feats[RAPID_SHOT]) || (base_attack_bonus < 6) )
                    ok = false;

                 if ( (class_levels[RANGER] >= 2) && (! ranger_combat_style) )
                 {
                    if ( (temp_dex >= 17) && ( feats[POINT_BLANK_SHOT] ) &&
                         (base_attack_bonus >= 6) )
                       ok = true;
                 }
                      
                 break;

          case MOBILITY:
              if ( (temp_dex < 13) || (feats[DODGE] < 1) )
                 ok = false;
              break;

          case MOUNTED_ARCHERY:
              if ( (skills[RIDE] < 1) || (feats[MOUNTED_COMBAT] < 1) )
                 ok = false;
              break;

          case MOUNTED_COMBAT:
               if (skills[RIDE] < 1)
                  ok = false;
               break;

          case NATURAL_SPELL:
               if (wisdom < 13)
                  ok = false;
               break;

          case POWER_ATTACK:
               if (temp_str < 13)
                 ok = false;
               break;

          case PRECISE_SHOT:
               if (feats[POINT_BLANK_SHOT] < 1)
                 ok = false;
               break;

          case QUICK_DRAW:
               if (base_attack_bonus < 1)
                 ok = false;
               break;

          case RAPID_SHOT:
               if ( (temp_dex < 13) || (! feats[POINT_BLANK_SHOT]) )
                 ok = false;
               break;

          case RIDE_BY_ATTACK:
               if ( (skills[RIDE] < 1) || (!feats[MOUNTED_COMBAT]) )
                  ok = false;
               break;

          case SCRIBE_SCROLL:
          // spell caster level >= 1
                     if ( (class_levels[BARD] < 1) && (class_levels[CLERIC] < 1) &&
                          (class_levels[DRUID] < 1) && (class_levels[PALADIN] < 1) &&
                          (class_levels[RANGER] < 1) && (class_levels[SORCERER] < 1) &&
                          (class_levels[WIZARD] < 1) )
                        ok = false;
                        break;

          case SHOT_ON_THE_RUN:
              if ( (feats[POINT_BLANK_SHOT] < 1) || (temp_dex < 13) ||
                   (feats[DODGE] < 1) || (feats[MOBILITY]) || 
                   (base_attack_bonus < 4) )
                 ok = false;
              break;

          case SNATCH_ARROWS:
              if ( (temp_dex < 15) || (!feats[DEFLECT_ARROWS]) ||
                   (!feats[IMPROVED_UNARMED_STRIKE]) )
                 ok = false;
              break;

          case SPELL_MASTERY:
          // must be a wizard
              if (class_levels[WIZARD] < 1)
                 ok = false;
              break;

          case SPIRITED_CHARGE:
               if ( (skill[RIDE] < 1) || (feats[MOUNTED_COMBAT] < 1) ||
                    (feats[RIDE_BY_ATTACK] < 1) )
                  ok = false;
               break;

          case SPRING_ATTACK:
                if (temp_dex < 13)
                   ok = false;
            
                if ( (feats[DODGE] < 1) ||
                     (feats[MOBILITY] < 1) || (base_attack_bonus < 4) )
                  ok = false;
                break;

          case STUNNING_FIST:
                if (temp_dex < 13)
                  ok = false;

                if ( (wisdom < 13) || (feats[IMPROVED_UNARMED_STRIKE] < 1) ||
                     (base_attack_bonus < 8) )
                   ok = false;
                break;

          case TOWER_SHIELD_PROFICIENCY:
               if (!feats[SHIELD_PROFICIENCY])
                  ok = false;
               break;

          case TRAMPLE:
                if ( (skills[RIDE] < 1) || (feats[MOUNTED_COMBAT] < 1) )
                   ok = false;
                break;
  
          case TWO_WEAPON_DEFENCE:
                if (temp_dex < 15)
                   ok = false;

                if (!feats[TWO_WEAPON_FIGHTING])
                   ok = false;

                if ( (temp_dex >= 15) && ( ranger_combat_style ) && ( class_levels[RANGER] >= 2) )
                   ok = true;
                break;

          case TWO_WEAPON_FIGHTING:
                if (temp_dex < 15)
                   ok = false;
                break;

          // both these feats have the same requirements
          case WEAPON_FINESSE:
          case WEAPON_FOCUS:
                if (base_attack_bonus < 1)
                  ok = false;
                break;

          case WEAPON_SPECIALIZATION:
                if ( (!feats[WEAPON_FOCUS]) || (class_levels[FIGHTER] < 4) )
                  ok = false;
                break;

          case WHIRLWIND_ATTACK:
               if (temp_int < 13)
                  ok = false;

               if (temp_dex < 13)
                  ok = false;

               if ( (feats[COMBAT_EXPERTISE] < 1) || (feats[DODGE] < 1) ||
                    (feats[MOBILITY] < 1) || (feats[SPRING_ATTACK] < 1) ||
                    (base_attack_bonus < 4) )
                  ok = false;
               break;
                                  
       }    // end of switch
       return ok;
    }       // end of Feat_Open()



    // This function returns a string with a line of text
    // which explains which pre-requisets are needed
    // to gain the given feat.
    // Chances are this feat will never be called
    // for a feat without pre-reques, but if it is
    // it shall return "You may not gain this feat."
    // as the default message.
    function Get_Feat_Requirements( feat_num )
    {
       var t = "This feat requires:\n";

       switch ( feat_num )
       {
          case ARMOR_PROFICIENCY_MEDIUM: t += "Light Armor Proficiency"; break;
          case ARMOR_PROFICIENCY_HEAVY: t += "Light and Medium Armor Proficiency"; break;
          case AUGMENT_SUMMONING: t += "Spell Focus"; break;
          case BREW_POTION: t += "Three spell caster levels."; break;
          case CLEAVE: t += "Power Attack and a Strength of 13."; break;
          case COMBAT_EXPERTISE: t += "An Intelligence of 13."; break;
          case CRAFT_MAGIC_ARMS_AND_ARMOR: "Five spell caster levels."; break;
          case CRAFT_ROD: t += "Nine spell caster levels."; break;
          case CRAFT_STAFF: t += "Twelve spell caster levels."; break;
          case CRAFT_WAND: t += "Nine spell caster levels."; break;
          case CRAFT_WONDEROUS_ITEM: t += "Three spell caster levels."; break;
          case DEFLECT_ARROWS: t += "Improved Unarmed Strike and a Dexterity of 13."; break;
          case DIEHARD: t += "Endurance"; break;
          case DODGE: t += "Dexterity of 13."; break;
          case EXOTIC_WEAPON_PROFICIENCY: t += "Base Attack Bonus of +1"; break;
          case EXTRA_TURNING: t += "Levels in Cleric or Paladin."; break;
          case FAR_SHOT: t += "Point Blank Shot"; break;
          case FORGE_RING: t += "Twelve spell caster levels."; break;
          case GREAT_CLEAVE: t += "Cleave, Power Attack, Strength of 13 and Base Attack Bonus of +4."; break;
          case GREATER_SPELL_PENETRATION: t += "Spell Penetration"; break;
          case GREATER_TWO_WEAPON_FIGHTING: t += "Improved Two-Weapon Fighting, Two-Weapon Fighting, " +
                                           "Dexterity of 19 and Base Attack Bonus of +11."; break;
          case GREATER_WEAPON_FOCUS: t += "Weapon Proficiency, Weapon Focus and eight levels of Fighter."; break;
          case GREATER_WEAPON_SPECIALIZATION: t += "Weapon Proficiency, Greater Weapon Focus, Weapon Focus, " +
                                              "Weapon Specialization and twelve levels of Fighter."; break;
          case IMPROVED_BULL_RUSH: t += "Power Attack and Strength of 13."; break;
          case IMPROVED_CRITICAL: t += "Weapon Proficiency and Base Attack Bonus of +8."; break;
          case IMPROVED_DISARM: t += "Combat Expertise and an Intelligence of 13"; break;
          case IMPROVED_FEINT: t += "Combat Expertise and an Intelligence of 13."; break;
          case IMPROVED_GRAPPLE: t += "Improved Unarmed Strike and Dexterity of 13."; break;
          case IMPROVED_OVERRUN: t += "Power Attack and Strength of 13."; break;
          case IMPROVED_PRECISE_SHOT: t += "Point Blank Shot, Precise Shot, Dexterity of 19 and " +
                                           "Base Attack Bonus of +11."; break;

          case IMPROVED_SUNDER: t += "Power Attack and Strength of 13."; break;
          case IMPROVED_TRIP: t += "Combat Expertise and an Intelligence of 13."; break;
          case IMPROVED_TURNING: t += "A level of Cleric or Paladin."; break;
          case IMPROVED_TWO_WEAPON_FIGHTING: t += "Two-Weapon Fighting, Dexterity of 17 and " +
                                             "a Base Attack Bonus of +6."; break;
          case LEADERSHIP: t += "A total of six class levels."; break;
          case MANYSHOT: t += "Point Blank Shot, Rapid Shot, Dexterity of 17 and a Base Attack Bonus of +6."; break;
          case MOBILITY: t += "Dodge and a Dexterity of 13."; break;
          case MOUNTED_ARCHERY: t += "Mounted Combat and a rank in the Ride skill."; break;
          case MOUNTED_COMBAT: t += "One rank in the Ride skill."; break;
          case NATURAL_SPELL: t += "Wisdom of 13."; break;
          case POWER_ATTACK: t += "Strength of 13."; break;
          case PRECISE_SHOT: t += "Point Blank Shot"; break;
          case QUICK_DRAW: t += "Base Attack Bonus of +1"; break;
          case RAPID_SHOT: t += "Point Blank Shot and Dexterity of 13."; break;
          case RIDE_BY_ATTACK: t += "Mounted Combat and a rank in the Ride skill."; break;
          case SCRIBE_SCROLL: t += "A level in a spell casting class."; break;          
          case SHOT_ON_THE_RUN: t += "Dodge, Mobility, Point Blank Shot, Dexterity of 13 and " +
                                     "a Base Attack Bonus of +4."; break;
          case SNATCH_ARROWS: t += "Deflect Arrows, Imporved Unarmed Strike and a Dexterity of 15."; break;
          case SPELL_MASTERY: t += "A level in the Wizard class."; break;
          case SPIRITED_CHARGE: t += "Mounted Combat, Ride-By Attack and a rank in the Ride skill."; break;
          case SPRING_ATTACK: t += "Dodge, Mobility, Dexterity of 13 and a Base Attack Bonus of +4."; break;
          case STUNNING_FIST: t += "Improved Unarmed Attack, Dexterity of 13, Wisdom of 13 and " +
                                   "a Base Attack Bonus of +8."; break;
          case TOWER_SHIELD_PROFICIENCY: t += "Shield Proficiency"; break;
          case TRAMPLE: t += "Mounted Combat and a rank in the Ride skill."; break;
          case TWO_WEAPON_DEFENCE: t += "Two-Weapon Fighting and a Dexterity of 15."; break;
          case TWO_WEAPON_FIGHTING: t += "Dexterity of 15."; break;
          case WEAPON_FINESSE: t += "Base Attack Bonus of +1."; break;
          case WEAPON_FOCUS: t += "Base Attack Bonus of +1."; break;
          case WEAPON_SPECIALIZATION: t += "Weapon Focus and four levels in the Fighter class."; break;
          case WHIRLWIND_ATTACK: t += "Combat Expertise, Dodge, Mobility, Spring Attack, " +
                                      "Dexterity of 13, Intelligence of 13 and a Base Attack Bonus of +4."; break;

          default: "You do not have all the requirments for this feat."; break;
       }  // end of switch

       return t;       
    }  // end of Get_Feat_Requirements





    // This function removes a rank from a feat.
    // If the feat was a pre-requicet, then the supported
    // feats are also removed.
    function Feat_Down(feat_index)
    {
       var count;
       var is_fighter_feat, is_wizard_feat;
       var max_fighter_feats, max_wizard_feats;

       is_fighter_feat = Is_Fighter_Bonus_Feat(feat_index);
       is_wizard_feat = Is_Wizard_Bonus_Feat(feat_index);

       if ( class_levels[FIGHTER] )
          max_fighter_feats = Math.floor(class_levels[FIGHTER] / 2) + 1;
       else
          max_fighter_feats = 0;

       if ( class_levels[WIZARD] )
          max_wizard_feats = Math.floor( class_levels[WIZARD] / 5 );
       else
          max_wizard_feats = 0;

       if ( feats[feat_index] < 1)
         return;
       
       // if this feat is a class feat (feat that is
       // picked automatically) then we cannot
       // remove it 

       // the below section can be skipped, if
       // we have more than one point in this feat

       if (feats[feat_index] < 2)
       {
       switch (feat_index)
       {
         case ARMOR_PROFICIENCY_LIGHT:
                if ( (class_levels[BARBARIAN]) || (class_levels[BARD]) ||
                     (class_levels[CLERIC]) || (class_levels[DRUID]) ||
                     (class_levels[FIGHTER]) || (class_levels[PALADIN]) ||
                     (class_levels[RANGER]) || (class_levels[ROGUE]) )
                {
                   Display_Feat_Points();
                   return;
                }
                break;

         case ARMOR_PROFICIENCY_MEDIUM:
                if ( (class_levels[BARBARIAN]) || (class_levels[CLERIC]) ||
                     (class_levels[DRUID]) || (class_levels[FIGHTER]) ||
                     (class_levels[PALADIN]) )
                {
                   Display_Feat_Points();
                   return;
                }
                break;

         case ARMOR_PROFICIENCY_HEAVY:
                if ( (class_levels[CLERIC]) || (class_levels[FIGHTER]) || 
                     (class_levels[PALADIN]) )
                {
                  Display_Feat_Points();
                  return;
                }
                break;

         case ENDURANCE:
                if (class_levels[RANGER] >= 3) 
                {
                   Display_Feat_Points();
                   return;
                }
                break;

         case SHIELD_PROFICIENCY:
                if ( (class_levels[BARBARIAN]) || (class_levels[BARD]) ||
                     (class_levels[CLERIC]) || (class_levels[DRUID]) ||
                     (class_levels[FIGHTER]) || (class_levels[PALADIN]) ||
                     (class_levels[RANGER]) )
                {
                   Display_Feat_Points();
                   return;
                }
                break;

         case TOWER_SHIELD_PROFICIENCY:
                if (class_levels[FIGHTER])
                {
                  Display_Feat_Points();
                  return;
                }
                break;

         case SIMPLE_WEAPON_PROFICIENCY:
                if ( (class_levels[BARBARIAN]) || (class_levels[BARD]) ||
                     (class_levels[CLERIC]) || (class_levels[FIGHTER]) ||
                     (class_levels[PALADIN]) || (class_levels[RANGER]) ||
                     (class_levels[ROGUE]) || (class_leveles[SORCERER]) )
                {
                   Disaply_Feat_Points();
                   return;
                }
                break;

         case MARTIAL_WEAPON_PROFICIENCY:
                if ( (class_levels[BARBARIAN]) || (class_levels[FIGHTER]) ||
                     (class_levels[PALADIN]) || (class_levels[RANGER]) )
                {
                    Display_Feat_Points();
                    return;
                }
                break;
       }   // end of switch feat_index       
       }   // end of if we have more than one point in this feat

       // these lines actually remove the feat from our list 
       feats[feat_index] -= 1;

       // check to see if this should be marked as a fighter feat
       if ( (is_fighter_feat) && (fighter_feats < max_fighter_feats) && (class_levels[FIGHTER]) )
         fighter_feats += 1;

       // check to see if this should be marked as a wizard feat
       else if ( (is_wizard_feat) && (wizard_feats < max_wizard_feats) )
         wizard_feats += 1;

       else
         feat_points += 1;

      
       // remove the effects that feats have 
       switch ( feat_index )
       {
          case ACROBATIC:  skills[JUMP] -= 2; skills[TUMBLE] -= 2; break;
          case AGILE: skills[BALANCE] -= 2; skills[ESCAPE_ARTIST] -= 2; break;
          case ALERTNESS: skills[LISTEN] -= 2; skills[SPOT] -= 2; break;
          case ANIMAL_AFFINITY: skills[HANDLE_ANIMAL] -= 2; skills[RIDE] -= 2; break;
          case ATHLETIC: skills[CLIMB] -= 2; skills[SWIM] -= 2; break;
          case DECEITFUL: skills[DISGUISE] -= 2; skills[FORGERY] -= 2; break;
          case DEFT_HANDS: skills[SLEIGHT_OF_HAND] -= 2; skills[USE_ROPE] -= 2; break;
          case DILIGENT: skills[APPRAISE] -= 2; skills[DECIPHER_SCRIPT] -= 2; break;
          case GREAT_FORTITUDE: fortitude_save -= 2; break;
          case INVESTIGATOR: skills[GATHER_INFORMATION] -= 2; skills[SEARCH] -= 2; break;
          case IRON_WILL: will_save -= 2; break;
          case LIGHTNING_REFLEXES: reflex_save -= 2; break;
          case MAGICAL_APTITUDE: skills[SPELLCRAFT] -= 2; skills[USE_MAGIC_DEVICE] -= 2; break;
          case NEGOTIATOR: skills[DIPLOMACY] -= 2; skills[SENSE_MOTIVE] -= 2; break;
          case NIMBLE_FINGERS: skills[DISABLE_DIVICE] -= 2; skills[OPEN_LOCK] -= 2; break;
          case PERSUASIVE: skills[BLUFF] -= 2; skills[INTIMIDATE] -= 2; break;
          case SELF_SUFFICIENT: skills[HEAL] -= 2; skills[SURVIVAL] -= 2; break;
          case STEALTHY: skills[HIDE_SKILL] -= 2; skills[MOVE_SILENTLY] -= 2; break;
          case TOUGHNESS: hit_points -= 3; break;
       }   // end of feat effects


       // remove any feats that use the removed feat.
       for (count = 0; count <= WIDEN_SPELL; count++)
       {
          // check if we have this feat
          if (feats[count] > 0)
          {
            // should we be able to keep this feat?
            ok = Feat_Open(count);
            if (!ok)
            {
               feat_points += feats[count];
               feats[count] = 0;
            }     // end of don't keep feat
         }        // end of currently have this feat
       }       // end of for loop

       Display_Feat_Points();
    }


    
    // This function adds a rank to a feat.
    function Feat_Up(feat_index)
    {
       var ok;
       var fighter_bonus_feat;
       var wizard_bonus_feat;

       // check to see if this is a fighter bonus feat
       fighter_bonus_feat = Is_Fighter_Bonus_Feat(feat_index);
       wizard_bonus_feat = Is_Wizard_Bonus_Feat(feat_index);
       
       // if it is a FBF, then we can use regular or bonus feats
       if ( (fighter_bonus_feat) && (feat_points < 1) && (fighter_feats < 1) )
       {
          alert('You have no more fighter feat points.');
          return;
       }

       else if ( (wizard_bonus_feat) && (feat_points < 1) && (wizard_feats < 1) )
       {
          alert('You have no more wizard feat points.');
          return;
       }

       else if ( (feat_points < 1) && (! fighter_bonus_feat) && (! wizard_bonus_feat) )
       {
         alert('You have no more regular feat points.');
         return;
       }

       // make sure we have all requirements
       ok = Feat_Open(feat_index);
       if (ok)
       {
          feats[feat_index] += 1;
          // if this was a FBF then try to use fighter feats first
          if ( (fighter_bonus_feat) && (fighter_feats) )
            fighter_feats -= 1;
          else if ( (wizard_bonus_feat) && (wizard_feats) )
            wizard_feats -= 1;
          else    // otherwise, use regular feat points
            feat_points -= 1;

          Display_Feat_Points();
 
          // add in feat effects
          switch ( feat_index )
          {
          case ACROBATIC:  skills[JUMP] += 2; skills[TUMBLE] += 2; break;
          case AGILE: skills[BALANCE] += 2; skills[ESCAPE_ARTIST] += 2; break;
          case ALERTNESS: skills[LISTEN] += 2; skills[SPOT] += 2; break;
          case ANIMAL_AFFINITY: skills[HANDLE_ANIMAL] += 2; skills[RIDE] += 2; break;
          case ATHLETIC: skills[CLIMB] += 2; skills[SWIM] += 2; break;
          case DECEITFUL: skills[DISGUISE] += 2; skills[FORGERY] += 2; break;
          case DEFT_HANDS: skills[SLEIGHT_OF_HAND] += 2; skills[USE_ROPE] += 2; break;
          case DILIGENT: skills[APPRAISE] += 2; skills[DECIPHER_SCRIPT] += 2; break;
          case GREAT_FORTITUDE: fortitude_save += 2; break;
          case INVESTIGATOR: skills[GATHER_INFORMATION] += 2; skills[SEARCH] += 2; break;
          case IRON_WILL: will_save += 2; break;
          case LIGHTNING_REFLEXES: reflex_save += 2; break;
          case MAGICAL_APTITUDE: skills[SPELLCRAFT] += 2; skills[USE_MAGIC_DEVICE] += 2; break;
          case NEGOTIATOR: skills[DIPLOMACY] += 2; skills[SENSE_MOTIVE] += 2; break;
          case NIMBLE_FINGERS: skills[DISABLE_DIVICE] += 2; skills[OPEN_LOCK] += 2; break;
          case PERSUASIVE: skills[BLUFF] += 2; skills[INTIMIDATE] += 2; break;
          case SELF_SUFFICIENT: skills[HEAL] += 2; skills[SURVIVAL] += 2; break;
          case STEALTHY: skills[HIDE_SKILL] += 2; skills[MOVE_SILENTLY] += 2; break;
          case TOUGHNESS: hit_points += 3; break;
          }   // end of feat effects

       }   // end of if we can get the feat
    
       // we cannot get the feat, let the user know
       else
       {
         // alert('You do not have the requirements for this feat.');
         alert ( Get_Feat_Requirements( feat_index ) );
       }
      
    }     // end of feat_up()



    // This function determins whether the selected feat, "feat_num",
    // can be used as a fighter bonus feat. The function returns
    // true for fighter bonus feats and false for all other feats.
    function Is_Fighter_Bonus_Feat(feat_num)
    {
       var return_value = false;

       switch (feat_num)
       {
          case BLIND_FIGHT:
          case COMBAT_EXPERTISE:
          case IMPROVED_DISARM:
          case IMPROVED_FEINT:
          case IMPROVED_TRIP:
          case WHIRLWIND_ATTACK:
          case COMBAT_REFLEXES:
          case DODGE:
          case MOBILITY:
          case SPRING_ATTACK:
          case EXOTIC_WEAPON_PROFICIENCY:
          case IMPROVED_CRITICAL:
          case IMPROVED_INITIATIVE:
          case IMPROVED_UNARMED_STRIKE:
          case IMPROVED_GRAPPLE:
          case DEFLECT_ARROWS:
          case SNATCH_ARROWS:
          case STUNNING_FIST:
          case MOUNTED_COMBAT:
          case MOUNTED_ARCHERY:
          case RIDE_BY_ATTACK:
          case SPIRITED_CHARGE:
          case TRAMPLE:
          case POINT_BLANK_SHOT:
          case FAR_SHOT:
          case PRECISE_SHOT:
          case RAPID_SHOT:
          case MANYSHOT:
          case SHOT_ON_THE_RUN:
          case IMPROVED_PRECISE_SHOT:
          case POWER_ATTACK:
          case CLEAVE:
          case GREAT_CLEAVE:
          case IMPROVED_BULL_RUSH:
          case IMPROVED_OVERRUN:
          case IMPROVED_SUNDER:
          case QUICK_DRAW:
          case RAPID_RELOAD:
          case IMPROVED_SHIELD_BASH:
          case TWO_WEAPON_FIGHTING:
          case TWO_WEAPON_DEFENCE:
          case IMPROVED_TWO_WEAPON_FIGHTING:
          case GREATER_TWO_WEAPON_FIGHTING:
          case WEAPON_FINESSE:
          case WEAPON_FOCUS:
          case WEAPON_SPECIALIZATION:
          case GREATER_WEAPON_FOCUS:
          case GREATER_WEAPON_SPECIALIZATION:
               return_value = true;
       }

       return return_value;
    }    // end of is bonus fighter feat



    // This function determines if the feat passed in
    // is a feat which can be selected as a Wizard bonus feat.
    // If the feat is a wizard feat, then true is returned,
    // otherwise the function returns false.
    function Is_Wizard_Bonus_Feat( feat_num )
    {
       var return_value = false;

       switch ( feat_num )
       {
          case SPELL_MASTERY:
          case BREW_POTION:
          case CRAFT_MAGIC_ARMS_AND_ARMOR:
          case CRAFT_ROD:
          case CRAFT_STAFF:
          case CRAFT_WAND:
          case CRAFT_WONDEROUS_ITEM:
          case FORGE_RING:
          case SCRIBE_SCROLL:
          case EMPOWER_SPELL:
          case ENLARGE_SPELL:
          case HEIGHTEN_SPELL:
          case MAXIMIZE_SPELL:
          case QUICKEN_SPELL:
          case SILENT_SPELL:
          case STILL_SPELL:
          case WIDEN_SPELL:
               return_value = true;
       }

       return return_value;
    }     // end of is wizard bonus feat



    // This function sets which bonus feat(s) the
    // monk has selected.
    // Results are stored in an array of monk_bonus_feats
    function Select_Monk_Feats(level, choice)
    {
       monk_bonus_feats[level] = choice;
    }


    // This function selects the Ranger fighting style.
    // The ranger_combat_style variable is set to
    // true for two weapon fighting or false for archery.
    function Select_Ranger_Style( two_weapon )
    {
       ranger_combat_style = two_weapon;
    }


    // This function displays the Bonus Feats page.
    // From this page, a character may select Monk
    // and Ranger bonus feats.
    function Get_Bonus_Feats()
    {
       var count;

       if (intelligence == 0)
       {
          alert('Please roll ability scores first.');
          return;
       }

       // Monks and Rangers are the only bonus feat classes
       if ( (! class_levels[MONK]) && ( class_levels[RANGER] < 2) )
       {
         alert('Your class/level receives no bonus feats.');
         return;
       }

       bonus_feat_win = open('', 'Bonus_Feats', min_feature);
       bonus_feat_win.document.writeln('<center><form name=bonus>');
       bonus_feat_win.document.writeln('<table>');
       // optional monk feats first
       if ( class_levels[MONK] )
       {
         bonus_feat_win.document.writeln('<tr>');
         bonus_feat_win.document.writeln('<td><b>Monk Bonus Feats</b></td>');
         bonus_feat_win.document.writeln('<td></td>');
         bonus_feat_win.document.writeln('</tr>');
         bonus_feat_win.document.writeln('<tr>');
  bonus_feat_win.document.writeln('<td><input type=radio name=monk1 onClick="window.opener.Select_Monk_Feats(0, window.opener.IMPROVED_GRAPPLE)"> ');
         bonus_feat_win.document.writeln('Improved Grapple</td>');
  bonus_feat_win.document.writeln('<td><input type=radio name=monk1 onClick="window.opener.Select_Monk_Feats(0, window.opener.STUNNING_FIST)"> ');
         bonus_feat_win.document.writeln('Stunning Fist</td>');
         bonus_feat_win.document.writeln('</tr>');
         if ( class_levels[MONK] >= 2)
         {
            bonus_feat_win.document.writeln('<tr>');
  bonus_feat_win.document.writeln('<td><input type=radio name=monk2 onClick="window.opener.Select_Monk_Feats(1, window.opener.COMBAT_REFLEXES)"> ');
            bonus_feat_win.document.writeln('Combat Reflexes</td>');
  bonus_feat_win.document.writeln('<td><input type=radio name=monk2 onClick="window.opener.Select_Monk_Feats(1, window.opener.DEFLECT_ARROWS)"> ');
            bonus_feat_win.document.writeln('Deflect Arrows</td>');
            bonus_feat_win.document.writeln('</tr>');
         }

         if ( class_levels[MONK] >= 6)
         {
            bonus_feat_win.document.writeln('<tr>');
  bonus_feat_win.document.writeln('<td><input type=radio name=monk6 onClick="window.opener.Select_Monk_Feats(2, window.opener.IMPROVED_DISARM)"> ');
            bonus_feat_win.document.writeln('Improved Disarm</td>');
  bonus_feat_win.document.writeln('<td><input type=radio name=monk6 onClick="window.opener.Select_Monk_Feats(2, window.opener.IMPROVED_TRIP)"> ');
            bonus_feat_win.document.writeln('Improved Trip</td>');
            bonus_feat_win.document.writeln('</tr>');
         }
         bonus_feat_win.document.writeln('<tr><td><br></td><td></td></tr>');
       }

       if ( class_levels[RANGER] >= 2 )
       {
         bonus_feat_win.document.writeln('<tr>');
         bonus_feat_win.document.writeln('<td><b>Ranger Combat Style</b></td><td></td>');
         bonus_feat_win.document.writeln('</tr>');
         bonus_feat_win.document.writeln('<tr>');
   bonus_feat_win.document.writeln('<td><input type=radio name=ranger onClick="window.opener.Select_Ranger_Style(true)">');
         bonus_feat_win.document.writeln('Two Weapon Fighting</td>');
   bonus_feat_win.document.writeln('<td><input type=radio name=ranger onClick="window.opener.Select_Ranger_Style(false)">');
         bonus_feat_win.document.writeln('Archery</td>');
         bonus_feat_win.document.writeln('<tr><td><br></td><td></td></tr>');
       }
       bonus_feat_win.document.writeln('</table>');
       bonus_feat_win.document.writeln('<br><br><input type=button value="Close" onClick="window.close()">');
       bonus_feat_win.document.writeln('</form></center>');

       bonus_feat_win.document.close();
       bonus_feat_win.focus();
    }




    // This function displays which languages the character
    // has and the number of language points remaining.
    function Display_Languages()
    {
       var count;
       var element_index = 1;

       for (count = 0; count <= UNDERCOMMON; count++)
       {
         language_win.document.forms[0].elements[element_index].checked = language[count];
         element_index++;
       }
       language_win.document.language.language_points1.value = language_points;
       language_win.document.language.language_points2.value = language_points;
    }

    // This function calculates the number of languages
    // the character gets.
    function Calc_Language_Points()
    {
       language_points = int_mod;
       // half-orcs get a -2 to intelligence
       if (race == HALF_ORC)
         language_points -= 1;

       language[COMMON] = true;
       switch (race)
       {
         case HALF_ELF:
         case ELF: language[ELVEN] = true; break;
         case DWARF: language[DWARVEN] = true; break;
         case HALFLING: language[HALFLING_LANG] = true; break;
         case GNOME: language[GNOME_LANG] = true; break;
         case HALF_ORC: language[ORC] = true; break;
       }

       // Druids get Druidic (Players Hand Book, page 35)
       if ( class_levels[DRUID] )
          language[DRUIDIC] = true;

       if (language_points < 0)
         language_points = 0;

       max_language_points = language_points;
       // Display_Languages();

    }      // end of Calc_Language_Points()


    // This function allows the player to select languages for
    // his/her character. A new window is opened with
    // a list of languages and check boxes.
    function Get_Languages()
    {
       var count;

       if (intelligence == 0)
       {
         alert('Please roll ability scores first.');
         return;
       }

       // This is now done when we roll ability scores.
       // for (count = 0; count <= UNDERCOMMON; count++)
       //   language[count] = false;
              
       language_win = open('', 'Language', min_feature);

       language_win.document.writeln('<center>');
       language_win.document.writeln('<form name=language>');
       language_win.document.writeln('<table>');

       language_win.document.writeln('<tr>');
       language_win.document.writeln('<td align=right>Language Points:</td>');
       language_win.document.writeln('<td align=center><input type=text name="language_points1" size=2></td>');
       language_win.document.writeln('</tr>');
       language_win.document.writeln('<tr><td><br><br></td></tr>');

       for (count = 0; count <= UNDERCOMMON; count++)
       {
         language_win.document.writeln('<tr>');
         language_win.document.writeln('<td align=right>', language_names[count], ':</td>');
         language_win.document.writeln('<td align=center>');
         language_win.document.writeln('  <input type=checkbox name="', language_names[count], '" onClick="window.opener.Select_Language(', count, ')">');
         language_win.document.writeln('</td>');
         language_win.document.writeln('</tr>');

       }        // end of for loop

       language_win.document.writeln('<tr><td><br><br></td></tr>');       
       language_win.document.writeln('<tr>');
       language_win.document.writeln('<td align=right>Language Points:</td>');
       language_win.document.writeln('<td align=center><input type=text name="language_points2" size=2></td>');
       language_win.document.writeln('</tr>');

       language_win.document.writeln('</table>');
       language_win.document.writeln('<input type=button value="Close" onClick="window.close()">');
       language_win.document.writeln('</form>');
       language_win.document.writeln('</center>');

       language_win.document.close();
       language_win.focus();

       // Do this in roll abilty scores function
       // Calc_Language_Points();

       Display_Languages();

    }  // end of Get_Languages()



    // This function detects whether a character has
    // a given language naturals. For example, all
    // dwarves get dwarven, all elves get elven, etc.
    function Natural_Language(the_language)
    {
         if (the_language == COMMON) return true;
         if ( (the_language == ELVEN) && (race == ELF) ) return true;
         if ( (the_language == ELVEN) && (race == HALF_ELF) ) return true;
         if ( (the_language == DWARVEN) && (race == DWARF) ) return true;
         if ( (the_language == HALFLING_LANG) && (race == HALFLING) ) return true;
         if ( (the_language == DRUIDIC) && (class_levels[DRUID]) ) return true;
         if ( (the_language == GNOME_LANG) && (race == GNOME) ) return true;
         if ( (the_language == ORC) && (race == HALF_ORC) ) return true;
         
         return false;
    }
    


    // This function allows the user to select/unselect languages
    // for his/her character. Checks are performed to insure
    // the character's race/class can get the choosen language.
    // Tired of seeing "/"'s yet?
    function Select_Language(language_number)
    {
       var ok = false;

       // first check to see if we are un-selecting a language
       if ( language[language_number] )
       {
          if ( Natural_Language(language_number) )
          {
             alert('You have this language naturally.');
             Display_Languages();
             return;
          }

          if (language_points < max_language_points)
          {
            language_points += 1;
            language[language_number] = false;
            language_win.document.forms[0].elements[language_number + 1].checked = language[language_number];
          }
          else
            alert('You are unable to unlearn that language.');

          Display_Languages();
          return;
       }

       // try to select a language
       else
       {
          // see if we have any language points left
          if (language_points < 1)
          {
            language_win.document.forms[0].elements[language_number + 1].checked = language[language_number];
            Display_Languages();
            return;
          }

          // make sure we are allowed to have this language
          switch (language_number)
          {
            case ABYSSAL:
            case CELESTIAL:
            case INFERNAL:
                  if ( (class_levels[CLERIC]) || (race == HUMAN) ||
                       (race == HALF_ELF) || (race == HALF_ORC) )
                    ok = true;
                  break;

            case AQUAN:
                 if ( (race == HUMAN) || (race == HALF_ELF) )
                    ok = true;
                 break;

            case COMMON: ok = true; break;

            case DRACONIC:
                 if ( (class_levels[WIZARD]) || (race == HUMAN) ||
                      (race == ELF) || (race == GNOME) ||
                      (race == HALF_ELF) )
                   ok = true;
                 break;

            case DRUIDIC:
                   if (class_levels[DRUID])
                     ok = true;
                   break;

            case DWARVEN:
                 if ( (race == HUMAN) || (race == DWARF) ||
                      (race == GNOME) || (race == HALF_ELF) ||
                      (race == HALFLING) )
                   ok = true;
                 break;

            case ELVEN:
                 if ( (race == ELF) || (race == HALF_ELF) ||
                      (race == GNOME) || (race == HALFLING) ||
                      (race == HUMAN) )   // see page 12 of PHB 
                   ok = true;
                 break;

            case GNOME_LANG:
                 if ( (race == GNOME) || (race == HUMAN) ||
                      (race == DWARF) || (race == ELF) ||
                      (race == HALF_ELF) || (race == HALFLING) )
                   ok = true;
                 break;

            case GOBLIN:
                 if ( (race == HUMAN) || (race == DWARF) ||
                      (race == ELF) || (race == GNOME) ||
                      (race == HALF_ELF) || (race == HALFLING) ||
                      (race == HALF_ORC) )
                   ok = true;
                 break;

            case GIANT:
                 if ( (race == HUMAN) || (race == DWARF) ||
                      (race == GNOME) || (race == HALF_ELF) ||
                      (race == HALF_ORC) )
                   ok = true;
                 break;

            case GNOLL:
                 if ( (race == HUMAN) || (race == ELF) ||
                      (race == HALF_ELF) || (race == HALF_ORC) )
                   ok = true;
                 break;

            case HALFLING_LANG:
                 if ( (race == HUMAN) || (race == HALFLING) ||
                      (race == HALF_ELF) )
                   ok = true;
                 break;

            case IGNAN:
                 if ( (race == HUMAN) || (race == HALF_ELF) )
                   ok = true;
                 break;

            case ORC:
                 if ( (race == HUMAN) || (race == HALF_ORC) ||
                      (race == DWARF) || (race == ELF) ||
                      (race == GNOME) || (race == HALF_ELF) ||
                      (race == HALFLING) )
                   ok = true;
                 break;

            case SYLVAN:
                 if ( (race == HUMAN) || (race == ELF) ||
                      (race == HALF_ELF) || (class_levels[DRUID])  )
                   ok = true;
                 break;

            case TERRAN:
                 if ( (race == HUMAN) || (race == DWARF) ||
                      (race == HALF_ELF) )
                   ok = true;
                 break;

            case UNDERCOMMON:
                 if ( (race == HUMAN) || (race == DWARF) ||
                      (race == HALF_ELF) )
                   ok = true;
                 break;

          }
       }         // end of else

       if (ok)
       {
          language[language_number] = true;
          language_points--;
       }
       language_win.document.forms[0].elements[language_number + 1].checked = language[language_number];
       Display_Languages();
    }          // end of Select_Language()


    // This function attempts to remove an item of equipment from
    // the character's inventory. The price of the object is added
    // to the character's "money".
    function Eq_Down(item_num)
    {
        // make sure she has the item
        if ( eq_have[item_num] )
        {
           money += eq_cost[item_num];
           eq_have[item_num] -= 1;
        }
        
        // update screen
        if (item_num < MASTERWORK_EQUIPMENT)
           eq_win.document.forms[0].elements[(item_num*6) + 3].value = eq_have[item_num];
        else
           eq_win.document.forms[0].elements[(MASTERWORK_EQUIPMENT-1) * 6 + (item_num - (MASTERWORK_EQUIPMENT-1)) * 3 + 6].value = eq_have[item_num];
       
        eq_win.document.equipment.eq1.value = money;
        eq_win.document.equipment.eq2.value = money;

        // see if we have to take off shield or armour
        if (item_num == armour_index)
        {
           armour_bonus = 0;
           armour_index = -1;
        }
        if (index == shield_index)
        {
           armour_bonus = 0;
           armour_index = -1;
        }

    }


    // This function adds an equipment item to the character's inventory.
    // The money for the item is removed from "money".
    function Eq_Up(item_num)
    {
        var item_cost = 0;

        item_cost += eq_cost[item_num];

        // make sure we can afford this item
        if ( item_cost <= money )
        {
            money -= item_cost;
            eq_have[item_num] += 1;
        }
        else
        {
           alert('You can not afford this item.');
           return;
        }

        // update the equipment screen
        if (item_num < MASTERWORK_EQUIPMENT)
           eq_win.document.forms[0].elements[item_num*6 + 3].value = eq_have[item_num];
        else
           eq_win.document.forms[0].elements[(MASTERWORK_EQUIPMENT-1) * 6 + (item_num - (MASTERWORK_EQUIPMENT-1)) * 3 + 6].value = eq_have[item_num];

        eq_win.document.equipment.eq1.value = money;
        eq_win.document.equipment.eq2.value = money;
    }


    // This function sets the value of the "money" based
    // off of the contents of the eq1 in the equipment window.
    function Set_Money()
    {
        var temp_money;

        temp_money = eq_win.document.equipment.eq1.value;
        temp_money -= 1; temp_money += 1;
        money = temp_money;
    }





    // This function attempts to purchase a masterwork item for the player.
    // First the function checks to see if the player has enough money.
    function Masterwork_Up( item_num )
    {
        var box_offset;
        var total_cost;
       
       // figure out which type of item it is
       if ( item_num == BOLT_WEAPON )
           total_cost = MASTERWORK_BOLT; 
       else if ( item_num == ARROW_WEAPON )
           total_cost = MASTERWORK_ARROW;
       else if ( item_num < 66)
           total_cost = MASTERWORK_WEAPON;
       else
           total_cost = MASTERWORK_ARMOR;

       total_cost += eq_cost[item_num];
       
       // do we have enough money
       if (total_cost > money)
       {
          alert('You do not have enough funds to buy this item.');
          return;
       }

       // buy masterwork item
       money -= total_cost;
       eq_masterwork[item_num] += 1;
       box_offset = 6 * item_num + 6
       eq_win.document.forms[0].elements[box_offset].value = eq_masterwork[item_num];
       eq_win.document.equipment.eq1.value = money;
       eq_win.document.equipment.eq2.value = money;

    }   // end of buy masterwork



    // This function checks to see if we have a masterwork item.
    // If we do, then we sell the item and get our money back.
    function Masterwork_Down( item_num )
    {
       var total_cost;
       var box_offset;

       // first check to see if we have the item in question
       if (! eq_masterwork[item_num] )
           return;

       // we have the item, find the price
       if ( item_num == BOLT_WEAPON )
           total_cost = MASTERWORK_BOLT;
       else if ( item_num == ARROW_WEAPON )
           total_cost = MASTERWORK_ARROW;
       else if ( item_num < 66)
           total_cost = MASTERWORK_WEAPON;
       else
           total_cost = MASTERWORK_ARMOR;

       total_cost += eq_cost[item_num];
 
       // get rid of the item and get our money
       eq_masterwork[item_num] -= 1;
       money += total_cost;
       
       // update equipment window
       box_offset = 6 * item_num + 6
       eq_win.document.forms[0].elements[box_offset].value = eq_masterwork[item_num];
       eq_win.document.equipment.eq1.value = money;
       eq_win.document.equipment.eq2.value = money;

    }   // end of selling masterwork items



    // maintain a global list of user defined EQ
    function Check_User_EQ()
    {
        var count, max;

        max_user_equipment = eq_win.document.equipment.user_eq.length;
        for (count = 0; count < max_user_equipment; count++)
            user_equipment_list[count] = eq_win.document.equipment.user_eq.options[count].value;
    }

    // This function takes an item from the user entry box and adds it to the list
    // of equipment at the bottom of the equipment page.
    function Add_User_EQ()
    {
        var item_text;
        var new_option;

        item_text = eq_win.document.equipment.new_item.value;
        // it should be something longer tan 3 chars
        if ( item_text.length < 3 )
           return;

       new_option = new Option(item_text, item_text);
       eq_win.document.equipment.user_eq.add(new_option);
       eq_win.document.equipment.new_item.value = "";
       Check_User_EQ();
    }


    // This function removes an items from the user equipment list
    function Remove_User_EQ()
    {
         var index;
         
         index = eq_win.document.equipment.user_eq.selectedIndex;
         if (index < 0)
            return;

         eq_win.document.equipment.user_eq.options[index] = null;
         Check_User_EQ();
    }



    // This function allows the user to select his/her equipment. Since we do not need
    // to know what the equipment is used for, the only restriction will be money.
    // This sheet tracks money in amounts of gold in the "money" varible.
    function Get_Equipment()
    {
       var count;    // a basic counter
       var new_option;

       if (intelligence == 0)
       {
          alert('Please roll ability scores first.');
          return;
       }

       // make sure the hero has no equipment
       // This is now done when we roll ability scores.
       // for (count = 0; count <= MAX_EQUIPMENT; count++)
       //   eq_have[count] = 0;

       eq_win = open('', 'Equipment', min_feature); 
       eq_win.document.writeln('<center>');
       eq_win.document.writeln('<form name=equipment>');
       eq_win.document.writeln('Money: <input type=text name=eq1 size=5> ');
       eq_win.document.writeln('<input type=button value="Set Money to This Value" onClick="window.opener.Set_Money()">');
       eq_win.document.writeln('<br>');
       eq_win.document.writeln('<table>');
       eq_win.document.writeln('<tr>');
       eq_win.document.writeln('<td><b>Name</b></td>');
       eq_win.document.writeln('<td><center><b>Cost</b></center</td>');
       eq_win.document.writeln('<td><center><b>Attribute</b></center></td>');
       eq_win.document.writeln('<td><center><b>Amount</b></center></td>');
       eq_win.document.writeln('<td><center><b>Masterwork</b></center></td>');
       eq_win.document.writeln('</tr>');
       for (count = 0; count <= MAX_EQUIPMENT; count++)
       {
          // put in headers for categories
          if ( (count == 0) || (count == FIRST_ARMOR) || (count == FIRST_GEAR) ||
               (count == FIRST_CLOTHES) || (count == FIRST_MOUNT) )
          {
               eq_win.document.writeln('<tr>');
               eq_win.document.writeln('<td></td><br><td>');
               switch ( count )
               {
                  case 0: eq_win.document.writeln('<br><b>Weapons</b><br>'); break;
                  case FIRST_ARMOR: eq_win.document.writeln('<br><b>Armor</b><br>'); break;
                  case FIRST_GEAR: eq_win.document.writeln('<br><b>Gear and Tools</b><br>'); break;
                  case FIRST_CLOTHES: eq_win.document.writeln('<br><b>Clothes</b><br>'); break;
                  case FIRST_MOUNT: eq_win.document.writeln('<br><b>Mounts and Travel</b><br>'); break;
               }

               eq_win.document.writeln('<br></td><td></td>');
               eq_win.document.writeln('</tr>');              
          }
          
          eq_win.document.writeln('<tr>');
          eq_win.document.writeln('<td>', eq_name[count], '</td>');
          eq_win.document.writeln('<td><center>', eq_cost[count], '</center></td>');
          eq_win.document.writeln('<td><center>', eq_bonus[count], '</center></td>');
          eq_win.document.writeln('<td><center><input type=button value="<" onClick="window.opener.Eq_Down(', count, ')">');
          eq_win.document.writeln('<input type=text size=3 value="0">');
          eq_win.document.writeln('<input type=button value=">" onClick="window.opener.Eq_Up(', count, ')"></td>');

          eq_win.document.writeln('<td>');
          // add masterwork selection 
          if (count < MASTERWORK_EQUIPMENT)
          {
             eq_win.document.writeln('<center>');
             eq_win.document.writeln('<input type=button value="<" onClick="window.opener.Masterwork_Down(', count, ')">');
             eq_win.document.writeln('<input type=text size=3 value=0>');
             eq_win.document.writeln('<input type=button value=">" onClick="window.opener.Masterwork_Up(', count, ')">');
             eq_win.document.writeln('</center>');
          }
          eq_win.document.writeln('</td>');
          
          eq_win.document.writeln('</tr>');
          // display number of items we have
          if (count < MASTERWORK_EQUIPMENT)
          {
             eq_win.document.forms[0].elements[count * 6 + 3].value = eq_have[count];
             eq_win.document.forms[0].elements[count * 6 + 6].value = eq_masterwork[count];
          }
          else
             eq_win.document.forms[0].elements[(MASTERWORK_EQUIPMENT-1) * 6 + (count - (MASTERWORK_EQUIPMENT-1)) * 3 + 6].value = eq_have[count];
       }     // end of for loop

       eq_win.document.writeln('</table><br>');
       eq_win.document.writeln('Money: <input type=text name=eq2 size=5><br>');

       // allow items to be added manually
       eq_win.document.writeln('<br><br>');
       eq_win.document.writeln('Other Equipment:<br>'); 
       eq_win.document.writeln('<select name=user_eq size=5>');
       eq_win.document.writeln('</select><br><br>');
       eq_win.document.writeln('Item: <input type=text size=50 name=new_item> ');
       eq_win.document.writeln('<input type=button value="Add" onClick="window.opener.Add_User_EQ()"> ');
       eq_win.document.writeln('<input type=button value="Remove" onClick="window.opener.Remove_User_EQ()"><br>');

       eq_win.document.writeln('<br><br>'); 
       eq_win.document.writeln('<input type=button value="Close" onClick="window.close()"><br>');
       eq_win.document.writeln('</form>');
       eq_win.document.writeln('</center>');
      
       eq_win.document.equipment.eq1.value = money;
       eq_win.document.equipment.eq2.value = money;

       for (count = 0; count < max_user_equipment; count++)
       {
           new_option = new Option(user_equipment_list[count], user_equipment_list[count]);
           eq_win.document.equipment.user_eq.add(new_option);
       }

       eq_win.document.close();
       eq_win.focus();
    }    // end of get equipment


    // This function is used to swap abilities between the swap_value
    // text box and the clicked ability box. The window that sends these
    // function calls is called "swapwin".
    // Each ability score name is given a number. For example, strength is
    // 1, dexterity is 2.
    function Swap_Ability(score_num)
    {
       var temp;
       var score;

       temp = swapwin.document.swap.swap_value.value;
       temp = temp - 1; temp = temp + 1;  // make sure it is a number
       switch (score_num)
       {
          case 1: // strength
                  score = strength;
                  strength = temp;
                  str_mod = Math.floor( (strength - 10) / 2);
                  break;

          case 2: // dexterity
                  score = dexterity;
                  dexterity = temp;
                  dex_mod = Math.floor( (dexterity - 10) / 2);
                  break;

          case 3: // constitution
                  score = constitution;
                  constitution = temp;
                  con_mod = Math.floor( (constitution - 10) / 2);
                  break;

          case 4: // intelligence
                  score = intelligence;
                  intelligence = temp;
                  int_mod = Math.floor( (intelligence - 10) / 2);
                  break;

          case 5: // wisdom
                  score = wisdom;
                  wisdom = temp;
                  wis_mod = Math.floor( (wisdom - 10) / 2);
                  break;

          case 6: // charisma
                  score = charisma;
                  charisma = temp;
                  chr_mod = Math.floor( (charisma - 10) / 2);
                  break;
       }  // end of switch

       // update swap window
       swapwin.document.swap.swap_value.value = score;
       swapwin.document.swap.strength.value = strength;
       swapwin.document.swap.dexterity.value = dexterity;
       swapwin.document.swap.constitution.value = constitution;
       swapwin.document.swap.intelligence.value = intelligence;
       swapwin.document.swap.wisdom.value = wisdom;
       swapwin.document.swap.charisma.value = charisma;

       // make sure skills, feats and such are reset when ability scores change
       Calc_Hit_Points();
       Get_Base_Attack_Bonus();
       Get_Saving_Throw();
       Get_Experience_Points();
       Calc_Money();
       Clear_Skills_Feats_Equipment_Language();
       Calc_Language_Points();
       Calc_Skill_Points();
       Calc_Feat_Points();
       Init_Spells();

    }



    // This function updates the main window with the swapped ability
    // scores. It also closes the swap ability score window "swapwin".
    function Swap_Update()
    {
       document.main.strength.value = strength;
       document.main.str_mod.value = str_mod;
       document.main.dexterity.value = dexterity;
       document.main.dex_mod.value = dex_mod;
       document.main.constitution.value = constitution;
       document.main.con_mod.value = con_mod;
       document.main.intelligence.value = intelligence;
       document.main.int_mod.value = int_mod;
       document.main.wisdom.value = wisdom;
       document.main.wis_mod.value = wis_mod;
       document.main.charisma.value = charisma;
       document.main.chr_mod.value = chr_mod;
      
       swapwin.close();
   }



    // This function pops up a window that allows the user
    // to swap ability scores around. The values displayed
    // in the boxes will be taken directly from the main
    // window's ability scores.
    function Show_Swap()
    {
        if (intelligence == 0)
        {
           alert('Please roll ability scores first.');
           return;
        }

        swapwin = open('', 'Swap', min_feature);
       
        swapwin.document.writeln('<center>');
        swapwin.document.writeln('Swap ability scores<br><br>'); 
        swapwin.document.writeln('<form name=swap>');
        swapwin.document.writeln('<table>');
        swapwin.document.writeln('<tr><td>Stength:</td>');
        swapwin.document.writeln('<td><input type=text size=2 name=strength></td>');
        swapwin.document.writeln('<td><input type=button value="Swap" onClick="window.opener.Swap_Ability(1)"></td>');
        swapwin.document.writeln('</tr>');
        swapwin.document.writeln('<tr><td>Dexterity:</td>');
        swapwin.document.writeln('<td><input type=text size=2 name=dexterity></td>');
        swapwin.document.writeln('<td><input type=button value="Swap" onClick="window.opener.Swap_Ability(2)"></td>');
        swapwin.document.writeln('</tr>');
        swapwin.document.writeln('<tr><td>Constitution:</td>');
        swapwin.document.writeln('<td><input type=text size=2 name=constitution></td>');
        swapwin.document.writeln('<td><input type=button value="Swap" onClick="window.opener.Swap_Ability(3)"></td>');
        swapwin.document.writeln('</tr>');
        swapwin.document.writeln('<tr><td>Intelligence:</td>');
        swapwin.document.writeln('<td><input type=text size=2 name=intelligence></td>');
        swapwin.document.writeln('<td><input type=button value="Swap" onClick="window.opener.Swap_Ability(4)"></td>');
        swapwin.document.writeln('</tr>');
        swapwin.document.writeln('<tr><td>Wisdom:</td>');
        swapwin.document.writeln('<td><input type=text size=2 name=wisdom></td>');
        swapwin.document.writeln('<td><input type=button value="Swap" onClick="window.opener.Swap_Ability(5)"></td>');
        swapwin.document.writeln('</tr>');
        swapwin.document.writeln('<tr><td>Charisma:</td>');
        swapwin.document.writeln('<td><input type=text size=2 name=charisma></td>');
        swapwin.document.writeln('<td><input type=button value="Swap" onClick="window.opener.Swap_Ability(6)"></td>');
        swapwin.document.writeln('</tr>');
        swapwin.document.writeln('<tr><td></td></tr>');
        swapwin.document.writeln('<tr><td>Swap Value:</td>');
        swapwin.document.writeln('<td><input type=text name=swap_value size=2></td>');
        swapwin.document.writeln('</td></tr>');
        swapwin.document.writeln('</table>');
        swapwin.document.writeln('<input type=button value="Close" onClick="window.opener.Swap_Update()">');
        swapwin.document.writeln('</form>');
        swapwin.document.writeln('</center>');

        // fill text boxes with current ability scores
        swapwin.document.swap.strength.value = strength;
        swapwin.document.swap.dexterity.value = dexterity;
        swapwin.document.swap.constitution.value = constitution;
        swapwin.document.swap.intelligence.value = intelligence;
        swapwin.document.swap.wisdom.value = wisdom;
        swapwin.document.swap.charisma.value = charisma;

        swapwin.document.close();
        swapwin.focus();
    }


    // This function sets the School of Specialization for
    // wizards.
    function Select_Special()
    { 
       var lvl_count, spell_count;

       switch (spell_win.document.spells.special.selectedIndex)
       {
         case 0: special_spell_domain = "none"; break;
         case 1: special_spell_domain = "Abjur"; break;
         case 2: special_spell_domain = "Conj"; break;
         case 3: special_spell_domain = "Div"; break;
         case 4: special_spell_domain = "Ench"; break;
         case 5: special_spell_domain = "Illus"; break;
         case 6: special_spell_domain = "Evoc"; break;
         case 7: special_spell_domain = "Necro"; break;
         case 8: special_spell_domain = "Trans"; break;
       }    // end of switch
 
       // make sure prohibted schools aren't used if specialization
       // is "none"
       if (special_spell_domain == "none")
       {
          restricted_spell_domain[0] = "none";
          restricted_spell_domain[1] = "none";
          spell_win.document.spells.prohibited.selectedIndex = 0;
          spell_win.document.spells.prohibited2.selectedIndex = 0;
       }
     
       // if a special school is selected, then make sure
       // prohibited schools are forced
       else
       {
          restricted_spell_domain[0] = "Abjur";
          spell_win.document.spells.prohibited.selectedIndex = 1;
          if (special_spell_domain != "Div")
          {
             restricted_spell_domain[1] = "Conj";
             spell_win.document.spells.prohibited2.selectedIndex = 2;
          }
       }

       // Since there has been a change, reset all wizard spells
       Init_Wizard_Spells();
       Display_Wizard_Spells();

    }       //end of Select_Special()


    // This function sets the first or second prohibited school
    // for wizards. The argument passed to this function
    // indicated if the school is the first or second (0 or 1).
    function Select_Prohibited( pro_num )
    {
      var mycheck;

      // this check determins if we are dealing with
      // the first or second prohibited school
      if (pro_num == 0)
         mycheck = spell_win.document.spells.prohibited.selectedIndex;
      else
         mycheck = spell_win.document.spells.prohibited2.selectedIndex;

      switch (mycheck)
      {
        case 0: restricted_spell_domain[pro_num] = "none"; break;
        case 1: restricted_spell_domain[pro_num] = "Abjur"; break;
        case 2: restricted_spell_domain[pro_num] = "Conj"; break;
        case 3: restricted_spell_domain[pro_num] = "Ench"; break;
        case 4: restricted_spell_domain[pro_num] = "Evoc"; break;
        case 5: restricted_spell_domain[pro_num] = "Illus"; break;
        case 6: restricted_spell_domain[pro_num] = "Necro"; break;
        case 7: restricted_spell_domain[pro_num] = "Trans"; break;
      }    // end of switch

      // now I am going to be a smart arse....
           
      // if the second prohibited school is "none" then
      // the specialized school is set to "Div"
      if ( (restricted_spell_domain[1] == "none") && (pro_num == 1) )
      {
         special_spell_domain = "Div";
         spell_win.document.spells.special.selectedIndex = 3;
      }
      // if the first prohibted school is set to "none" then
      // the specialized school is set to "none"
      else if ( (restricted_spell_domain[0] == "none") && (pro_num == 0) )
      {
         special_spell_domain = "none";
         spell_win.document.spells.special.selectedIndex = 0;
         restricted_spell_domain[1] = "none";
         spell_win.document.spells.prohibited2.selectedIndex = 0;
      }

      // if both restricted domains are the same and not "none"
      // then the special school is set to "Div"
      else if ( (restricted_spell_domain[0] != "none") && 
                (restricted_spell_domain[0] == restricted_spell_domain[1]) )
      {
         special_spell_domain = "Div";
         spell_win.document.spells.special.selectedIndex = 3;
      }
      
       // Since there has been a change, reset all wizard spells
       Init_Wizard_Spells();
       Display_Wizard_Spells();

    }      // end of Select_Prohibited()


    // When the user tries to select a spell, this function is
    // called. The spell level and index is passed to this
    // function. We then check to make sure the character can
    // get this spell....or unselect this spell.
    // The known wizard spells is then updated along with the
    // number of spells the character can know.
    function Select_Wizard_Spell(spell_level, spell_index)
    {
        var count;
        var found;

        // if we already have this spell, then unlearn it
        if (wizard_spells[spell_level][spell_index])
        {
           // remove the spell from the known list
           wizard_spells[spell_level][spell_index] = 0;
           // add a spell of that level that we can learn now
           num_wizard_spells[spell_level]++;
           Display_Wizard_Spells();
           return;
        }

        // Now we can assume that we are trying to get this spell

        // if the wizard is dumb, he/she cannot learn
        // the spell (intelligence >= 10 + spell_level)
        if ( (spell_level + 10) > intelligence)
        {
           alert('You need a higher intelligence score to get this spell.');
           Display_Wizard_Spells();
           return;
        }

        // make sure we can have a spell of this level
        count = spell_level;
        found = false;
        while ( (!found) && (count < 10) )
        {
           if (num_wizard_spells[count]) found = true;
           else count++;
        }
        if (!found)
        {
          alert('You cannot select a spell of this level.');
          Display_Wizard_Spells();
          return;
        }

        // now make sure that we are not selecting a prohibited school
        if ( (wizard_spell_domain[spell_level][spell_index] == restricted_spell_domain[0]) ||
             (wizard_spell_domain[spell_level][spell_index] == restricted_spell_domain[1]) )
        {
          alert('Learning a spell in this domain is prohibited.');
          Display_Wizard_Spells();
          return;
        }

        // it seems that we can learn this spell
        // remove a spell from the can-learn list and add it to
        // the spells known
        num_wizard_spells[count]--;
        wizard_spells[spell_level][spell_index] = 1;
        Display_Wizard_Spells();

    }   // end of Select_Wizard_Spell()


    // This function toggles the proper check boxes in the spell window.
    function Display_Wizard_Spells()
    {
       var check_index;
       var spell_level, spell_index;
      
       // check_index = 3;   // first check box on the form
       check_index = 4;      // first spell_per_level box
       for (spell_level = 1; spell_level < 10; spell_level++)
       {
          spell_win.document.spells.elements[check_index].value = num_wizard_spells[spell_level];
          check_index++;
          spell_index = 0;
          while (wizard_spell_name[spell_level][spell_index] != " ")
          {
             if (wizard_spells[spell_level][spell_index] > 0)
                spell_win.document.spells.elements[check_index].checked = true;
             else
                spell_win.document.spells.elements[check_index].checked = false;

             spell_index++;
             check_index++;
          }
       }    // end of for loop
    }   // end of Display_Wizard_Spells()




    // I feel like I'm repeating myself here.....

    // This function toggles the check boxes on the spells
    // page to show which sorcerer spells we currently have.
    function Display_Sorcerer_Spells()
    {
       var check_index;
       var spell_level, spell_index;

       check_index = 0;
       for (spell_level = 0; spell_level < 10; spell_level++)
       {
          spell_win.document.sorcerer.elements[check_index].value = num_sorcerer_spells[spell_level];
          check_index++;
          spell_index = 0;
          while (wizard_spell_name[spell_level][spell_index] != " ")
          {
             if (sorcerer_spells[spell_level][spell_index] > 0)
                spell_win.document.sorcerer.elements[check_index].checked = true;
             else
                spell_win.document.sorcerer.elements[check_index].checked = false;
             
            spell_index++;
            check_index++;
          }   //  end of while loop
      }        // end of for loop
    }      // end of Display_Sorcerer_Spells
 
  
    // This function toggels the proper check boxrs on or off 
    // to show which bard spell we have.
    function Display_Bard_Spells()
    {
       var check_index;
       var spell_level, spell_index;

       check_index = 0;
       for (spell_level = 0; spell_level < 7; spell_level++)
       {
          spell_win.document.bard.elements[check_index].value = num_bard_spells[spell_level];
          check_index++;
          spell_index = 0;
          while (bard_spell_name[spell_level][spell_index] != " ")
          {
             if (bard_spells[spell_level][spell_index] > 0)
               spell_win.document.bard.elements[check_index].checked = true;
             else
               spell_win.document.bard.elements[check_index].checked = false;
             
             spell_index++;
             check_index++;
         }   // end of while
       }     // end of for loop
    }        // end of Display_Bard_Spells()




    // This function is called when the user tries to select/unselect a sorcerer spell.
    // The function removes the selection, or determines if we can learn this
    // spell. It then updates the spells known and potential spells. Finally,
    // the Display_Sorcerer_Spells() is called.
    function Select_Sorcerer_Spell( spell_level, spell_index )
    {
       // first see if we are dealing with a wizard-only arcane spell
       if ( ( (spell_level == 4) && (spell_index == 38) ) ||
            ( (spell_level == 6) && (spell_index == 38) ) )
       {
          alert('This is a wizard-only spell.');
          Display_Sorcerer_Spells();
          return;
       }

       // check to see if we already have this spell
       if (sorcerer_spells[spell_level][spell_index])
       {
          // remove this spell from the ones we know
          sorcerer_spells[spell_level][spell_index] = 0;
          // add to the spells we can learn
          num_sorcerer_spells[spell_level]++;
          // update the display
          Display_Sorcerer_Spells();
          return;
       }
   
       // now we can assume that we are trying to learn this spell
       
       // check to make sure the sorcerer's charisma is high enough
       if ( (spell_level + 10) > charisma)
       {
          alert('Your charisma is not high enough to learn this spell.');
          Display_Sorcerer_Spells();
          return;
       }

       // make sure we can learn a spell of this level
       if (num_sorcerer_spells[spell_level] < 1)
       {
           alert('You cannot learn a spell of this level.');
           Display_Sorcerer_Spells();
           return;
       }

       // we are free to learn this spell
       num_sorcerer_spells[spell_level]--;
       sorcerer_spells[spell_level][spell_index] = 1;
       Display_Sorcerer_Spells(); 

    }   // end of Select_Sorcerer_Spell()


    // This function allows the user to select/unselect a bard spell.
    // The function unsleects any spell that we have and
    // will check before granting bew spells.
    // Afterward, Display_Bard_Spells() is called.
    function Select_Bard_Spell(spell_level, spell_index)
    {
       // first see if we are unselecting this spell
       if (bard_spells[spell_level][spell_index] > 0)
       {
          // add spell to ones we can learn
          num_bard_spells[spell_level]++;
          bard_spells[spell_level][spell_index] = 0;
          Display_Bard_Spells();
          return;
       }

       // assume we are trying to get this spell
       // make sure we have enough charisma
       if ( (spell_level + 10) > charisma )
       {
          alert('You do not have enough charisma to learn this spell.');
          Display_Bard_Spells();
          return;
       }

       // make sure we can learn spells of this level
       if ( num_bard_spells[spell_level] < 1)
       {
          alert('You cannot learn a spell of this level.');
          Display_Bard_Spells();
          return;
       }

       // seems we can learn this spell
       num_bard_spells[spell_level]--;
       bard_spells[spell_level][spell_index] = 1;
       Display_Bard_Spells();

    }     // end of Select_Bard_Spell()



    // This function is called to reset wizard spells and domains.
    function Reset_Wizard_Spells()
    {
        Init_Wizard_Spells();
        Display_Wizard_Spells();
      
        special_spell_domain = "none";
        spell_win.document.spells.special.selectedIndex = 0; 
        restricted_spell_domain[0] = "none";
        restricted_spell_domain[1] = "none";
        spell_win.document.spells.prohibited.selectedIndex = 0;
        spell_win.document.spells.prohibited2.selectedIndex = 0;

    }

 

    // This function displays the window to allow the user
    // to select his/her character's spells. All the aviable spells
    // for their class are displayed.
    function Get_Spells()
    {
        var lvl, index;

        // if the character is not a spell caster, don't
        // bother opening the window
        if ( (!class_levels[BARD]) && (!class_levels[CLERIC]) &&
             (!class_levels[DRUID]) && (!class_levels[PALADIN]) &&
             (!class_levels[RANGER]) && (!class_levels[SORCERER]) &&
             (!class_levels[WIZARD]) )
        {
           alert('Your class(es) cannot cast spells.');
           return;
        }

        // if the character is not a bard, sorcerer or wizard 
        // then their spell selection is automatic
        if ( (!class_levels[BARD]) && (!class_levels[SORCERER]) &&
             (!class_levels[WIZARD]) )
        {
            alert('You class(es) spells will be automatically selected.');
            return;
        }


        // make sure the character has already rolled ability scores.
        if (intelligence == 0)
        {
            alert('Please roll aility scores first.');
            return;
        }


        spell_win = open('', 'Spells', min_feature);
        
        spell_win.document.writeln('<center>');

        // only display if we are a bard
        if ( class_levels[BARD] )
        {
        spell_win.document.writeln('<form name=bard>');
        spell_win.document.writeln('<table>');
        spell_win.document.writeln('<tr><td><b>Bard Spells</b></td>');
        spell_win.document.writeln('<td></td></tr>');
                                                                                                                             
        // display all of the bard spells
        for (lvl = 0; lvl < 7; lvl++)
        {
           spell_win.document.writeln('<tr><td><br>Level: ', lvl, '</td>');
           spell_win.document.writeln('<td><br>Spells to learn: <input type=text size=3></td></tr>');
           index = 0;
           while (bard_spell_name[lvl][index] != " ")
           {
             spell_win.document.writeln(' <tr>');
             spell_win.document.writeln('   <td>', bard_spell_name[lvl][index], '</td>');
             spell_win.document.writeln('   <td><input type=checkbox onClick="window.opener.Select_Bard_Spell(', lvl, ',', index, ')"></td>');
             spell_win.document.writeln(' </tr>');
             index++;
           }
        }   // end of for loop
                                                                                                                             
        spell_win.document.writeln('</table>');
        spell_win.document.writeln('</form>');
        }   // end of if bard

                     
        if ( class_levels[SORCERER] )
        {                                                                                        
        spell_win.document.writeln('<br><br>');

        spell_win.document.writeln('<form name=sorcerer>');
        spell_win.document.writeln('<table>');
        spell_win.document.writeln('<tr><td><b>Sorcerer Spells</b></td>');
        spell_win.document.writeln('<td></td></tr>');
        
        // display all of the sorcerer spells
        for (lvl = 0; lvl < 10; lvl++)
        {
           spell_win.document.writeln('<tr><td><br>Level: ', lvl, '</td>');
           spell_win.document.writeln('<td><br>Spells to learn: <input type=text size=3></td></tr>');
           index = 0;
           while (wizard_spell_name[lvl][index] != " ")
           {
             spell_win.document.writeln(' <tr>');
             spell_win.document.writeln('   <td>', wizard_spell_name[lvl][index], '</td>');
             spell_win.document.writeln('   <td><input type=checkbox onClick="window.opener.Select_Sorcerer_Spell(', lvl, ', ', index, ')"></td>'); 
             spell_win.document.writeln(' </tr>');
             index++;
           }
        }   // end of for loop

        spell_win.document.writeln('</table>'); 
        spell_win.document.writeln('</form>');
        }   // end of if sorcerer

        if ( class_levels[WIZARD] )
        {
        spell_win.document.writeln('<br><br>');

        spell_win.document.writeln('<form name=spells>');
        spell_win.document.writeln('<table>');
        // display wizard/sorcerer spells
        spell_win.document.writeln('<tr><td><b>Wizard Spells</b></td>');
        spell_win.document.writeln('<td><input type=button value="Reset Wizard Spells" onClick="window.opener.Reset_Wizard_Spells()"></td>');
        spell_win.document.writeln('<td></td></tr>');

        // display table for selecting specialization
        spell_win.document.writeln('<tr><td>');
        spell_win.document.writeln('School of Specialization: </td>');
        spell_win.document.writeln('<td align=right><select name=special onChange="window.opener.Select_Special()">');
        spell_win.document.writeln('<option>None</option>');
        spell_win.document.writeln('<option>Aburation</option><option>Conjuration</option>');
        spell_win.document.writeln('<option>Divination</option><option>Enchantment</option>');
        spell_win.document.writeln('<option>Evocation</option><option>Illusion</option>');
        spell_win.document.writeln('<option>Necromancy</option><option>Transmutation</option>');
        spell_win.document.writeln('</select></td><td></td></tr>');
        spell_win.document.writeln('<tr><td>Prohibited School: </td>');
        spell_win.document.writeln('<td align=right><select name=prohibited onChange="window.opener.Select_Prohibited(0)">');
        spell_win.document.writeln('<option>None</option>');
        spell_win.document.writeln('<option>Aburation</option><option>Conjuration</option>');
        spell_win.document.writeln('<option>Enchantment</option>');
        spell_win.document.writeln('<option>Evocation</option><option>Illusion</option>');
        spell_win.document.writeln('<option>Necromancy</option><option>Transmutation</option>');
        spell_win.document.writeln('</select></td><td></td></tr>');
        spell_win.document.writeln('<tr><td>Second Prohibited School: </td>');
       spell_win.document.writeln('<td align=right><select name=prohibited2 onChange="window.opener.Select_Prohibited(1)">');
        spell_win.document.writeln('<option>None</option>');
        spell_win.document.writeln('<option>Aburation</option><option>Conjuration</option>');
        spell_win.document.writeln('<option>Enchantment</option>');
        spell_win.document.writeln('<option>Evocation</option><option>Illusion</option>');
        spell_win.document.writeln('<option>Necromancy</option><option>Transmutation</option>');
        spell_win.document.writeln('</select></td><td></td></tr>');


        for (lvl = 1; lvl < 10; lvl++)
        {
          spell_win.document.writeln('<tr><td><br>Level: ', lvl, '</td>');
          spell_win.document.writeln('<td><br>Spells to learn: <input type=text size=3></td><td></td></tr>');
          index = 0;
          while (wizard_spell_name[lvl][index] != " ")
          {
            spell_win.document.writeln(' <tr>');
            spell_win.document.writeln('   <td>', wizard_spell_name[lvl][index], '</td>');
            spell_win.document.writeln('   <td>', wizard_spell_domain[lvl][index], '</td>');
            spell_win.document.writeln('   <td><input type=checkbox onClick="window.opener.Select_Wizard_Spell(', lvl, ', ', index, ')"></td>');
            spell_win.document.writeln(' </tr>');
            index++;
          }
        }   // end of for loop
        spell_win.document.writeln('</table>');

        }   // end of wizard
        spell_win.document.writeln('<input type=button value=Close onClick="window.close()">');
        spell_win.document.writeln('</form>');


        spell_win.document.writeln('</center>');
   
        if ( class_levels[BARD] ) Display_Bard_Spells();
        if ( class_levels[SORCERER] ) Display_Sorcerer_Spells();
        if ( class_levels[WIZARD] ) Display_Wizard_Spells();

        spell_win.document.close();
        spell_win.focus();
    }     // end of Get_Spells()


    // This function goes through all of the character's classes and makes a list
    // of the special class abilities those classes have. A string is created
    // with a newline seperated list of the class abilties. This string
    // is returned to the calling function.

    // Note: The commented out specials are ones that are already achieved at a lower
    //       level. No sense in repeating them.
    // Note: This function is updated to v3.5
    function Get_Class_Special()
    {
       var s = "";

       switch (class_levels[BARBARIAN])
       {
         case 20: s += "Mighty rage<br>";
         case 19: // s += "Damage reduction<br>";
         case 18: // s += "Trap sense<br>";
         case 17: s += "Tireless rage<br>";
         case 16: // s += "Damage reduction<br>";
         case 15: // s += "Trap sense<br>";
         case 14: s += "Indomitable will<br>";
         case 13: // s += "Damage reduction<br>";
         case 12: // s += "Rage, trap sense<br>";
         case 11: s += "Greater rage<br>";
         case 10: // s += "Damage reduction<br>";
         case 9: // s += "Trap sense<br>";
         case 8: // s += "Rage<br>";
         case 7: s += "Damage reduction<br>";
         case 6: // s += "Trap sense<br>";
         case 5: s += "Improved uncanny dodge<br>";
         case 4: // s += "Rage<br>";
         case 3: s += "Trap sense<br>";
         case 2: s += "Uncanny dodge<br>";
         case 1: s += "Fast movement, illiteracy, rage<br>";
        }  // end of Barbarian

        switch (class_levels[BARD])
        {
           case 20: // s += "Inspire courage<br>";
           case 19:
           case 18: s += "Mass suggestion<br>";
           case 17:
           case 16:
           case 15: s += "Inspire heroics<br>";
           case 14: // s += "Inspire courage<br>";
           case 13:
           case 12: s += "Song of Freedom<br>";
           case 11:
           case 10:
           case 9: s += "Inspire greatness<br>";
           case 8: // s += "Inspire courage<br>";
           case 7:
           case 6: s += "Suggestion<br>";
           case 5:
           case 4:
           case 3: s += "Inspire competence<br>";
           case 2:
           case 1: s += "Bardic music, bardic knowledge<br>countersong, fascinate<br>inspire courage<br>";
        }  // end of bard

        // if you're a cleric at all, then you can turn undead
        if (class_levels[CLERIC])
          s += "Turn undead<br>";

        switch (class_levels[DRUID])
        {
           case 20: // s += "Wild shape<br>";
           case 19:
           case 18: // s += "Wild shape<br>";
           case 17:
           case 16: // s += "Wild shape<br>";
           case 15: s += "Timeless body<br>";
           case 14: // s += "Wild shape<br>";
           case 13: s += "A thousand faces<br>";
           case 12: // s += "Wild shape<br>";
           case 11: // s += "Wild shape<br>";
           case 10: // s += "Wild shape<br>";
           case 9: s += "Venom immunity<br>"; 
           case 8: // s += "Wild shape<br>";
           case 7: // s += "Wild shape<br>";
           case 6: // s += "Wild shape<br>";
           case 5: s += "Wild shape<br>";
           case 4: s += "Resist nature's lure<br>";
           case 3: s += "Trackless step<br>";
           case 2: s += "Woodland stride<br>";
           case 1: s += "Animal companion<br>nature sense, wild empathy<br>";
        }   // end of druid

        // there are no specials for fighters (they get bonus feats)

        // monks are sexy
        switch (class_levels[MONK])
        {
           case 20: s += "Perfect self<br>"; 
           case 19: s += "Empty body<br>";
           case 18: // s += "Slow fall<br>";
           case 17: s += "Timeless body, tongue of sun and moon<br>";
           case 16: // s += "Ki strike<br>";
           case 15: s += "Quivering palm<br>";
           case 14: // s += "Slow fall<br>";
           case 13: s += "Diamond soul<br>";
           case 12: s += "Abundant step<br>";
           case 11: s += "Diamond body, greater flurry<br>";
           case 10: // s += "Ki strike<br>";
           case 9: s += "Improved evasion<br>";
           case 8: // s += Slow fall<br>";
           case 7: s += "Wholeness of body<br>";
           case 6: // s += "Slow fall<br>";
           case 5: s += "Purity of body<br>";
           case 4: s += "Ki strike<br>";
           case 3: s += "Still mind<br>";
           case 2: s += "Evasion<br>";
           case 1: s += "Flurry of blows, unarmed strike<br>";
        } // end of monk

        switch (class_levels[PALADIN])
        {
          case 20: // s += "Smite evil<br>";
          case 19:
          case 18: // s += "Remove disease<br>";
          case 17:
          case 16:
          case 15: // s += "Smite evil<br>";
          case 14:
          case 13:
          case 12: // s += "Remove disease<br>";
          case 11: 
          case 10: // s += "Smite evil<br>";
          case 9: // s += "Remove disease<br>";
          case 8: 
          case 7:
          case 6: s += "Remove disease<br>";
          case 5: s += "Special mount<br>";
          case 4: s += "Turn undead<br>";
          case 3: s += "Aura of courage, divine health<br>";
          case 2: s += "Divine grace, lay on hands<br>";
          case 1: s += "Aura of good<br>detect evil, smite evil<br>";
        }   // end of paladin

        // took out combat style, since the feats are now included in the display
        switch (class_levels[RANGER])
        {
           case 20: // s += "Favored enemy<br>";
           case 19:
           case 18:
           case 17: s += "Hide in plain sight<br>";
           case 16:
           case 15: // s += "Favored enemy<br>";
           case 14:
           case 13: s += "Camouflage<br>";
           case 12:
           case 11: // s += "Combat style mastery<br>";
           case 10: // s += "Favored enemy<br>";
           case 9: s += "Evasion<br>";
           case 8: s += "Swift tracker<br>";
           case 7: s += "Woodland stride<br>";
           case 6: // s += "Improved combat style<br>";
           case 5: // s += "Favored enemy<br>";
           case 4: s += "Animal companion<br>";
           case 3: // ( Moved to Get_Class_Feats() ) s += "Endurance<br>";
           case 2: // s += "Combat style<br>";
           case 1: s += "Favored enemy<br>Track, wild empathy<br>";
        }    // end of ranger

        // you don't see them, but they see you
        switch (class_levels[ROGUE])
        {
           case 20:
           case 19: // s += "Sneak attack<br>";
           case 18: // s += "Trap sense<br>";
           case 17: // s += "Sneak attack<br>";
           case 16: // s += "Special ability<br>";
           case 15: // s += "Sneak attack<br>";
           case 14:
           case 13: // s += "Sneak attack<br>";
           case 12: // s += "Trap sense<br>";
           case 11: // s += "Sneak attack<br>";
           case 10: s += "Special ability<br>";
           case 9: // s += "Sneak attack<br>";
           case 8: s += "Improved uncanny dodge<br>";
           case 7: // s += "Sneak attack<br>";
           case 6: // s += "Trap sense<br>";
           case 5: // s += "Sneak attack<br>";
           case 4: s += "Uncanny dodge<br>";
           case 3: s += "Trap sense<br>";
           case 2: s += "Evasion<br>";
           case 1: s += "Sneak attack<br>Trapfinding<br>";
        }    // end of the sneakies

        // sorcerers get just one special
        if (class_levels[SORCERER])
           s += "Summon familiar<br>";

        // wizards get two specials, both at first level
        if (class_levels[WIZARD])
           s += "Summon familiar<br>Scribe scroll<br>";
 
        return s;
    }   // end of Get_Class_Special()



    // This function figures out how much of an armor
    // bonus the character gets from equipment.
    function Calc_Armour_Bonus()
    {
        var shield_value = 0, armour_value = 0;
        //   making these global for checks -- var shield_index, armour_index;
        var my_option;

        armour_bonus = 0;

        my_option = equip_win.document.equip.elements.shield;
        shield_index = my_option.options[ my_option.selectedIndex ].value;

        my_option = equip_win.document.equip.elements.armor;
        armour_index = my_option.options[ my_option.selectedIndex ].value;

        if (shield_index >= 0)
        {
             shield_value = eq_bonus[shield_index];
             shield_value -= 0;
        }
        if (armour_index >= 0)
        {
             armour_value = eq_bonus[armour_index];
             armour_value -= 0;
        }

        armour_bonus = shield_value + armour_value;
    }


    // This function allows the user to pick out armor
    // for the character. Right now, armor and shields
    // are availible.
    function Equip_Char()
    {
        var item;
        var index;
        var selector;

        if (intelligence == 0)
        {
            alert('Please roll stats and select equipment first.');
            return;
        }

        equip_win = open('', 'Equip', min_feature);
    
        equip_win.document.writeln('<center><b>Equip Character</b><br>');
        equip_win.document.writeln('<br><br>');
        equip_win.document.writeln('<form name=equip>');
        equip_win.document.writeln('<table>');
        equip_win.document.writeln('<tr>');
        equip_win.document.writeln('<td>Armor</td>');
        equip_win.document.writeln('<td><select name=armor onChange="window.opener.Calc_Armour_Bonus()"></select></td>');
        equip_win.document.writeln('</tr>');
        equip_win.document.writeln('<tr>');
        equip_win.document.writeln('<td>Shield</td>');
        equip_win.document.writeln('<td><select name=shield onChange="window.opener.Calc_Armour_Bonus()"></select></td>');
        equip_win.document.writeln('</tr>');
        equip_win.document.writeln('</table>');
        equip_win.document.writeln('<br><input type=button value="Close" onClick="window.close()"><br>');
        equip_win.document.writeln('</form>');
        equip_win.document.writeln('</center>');

        // make dynamic list of armor we have
        selector = equip_win.document.equip.elements.armor;
        item = new Option("Select Armor", -1, true, true);
        selector.options[ selector.options.length] = item;
        for (index = 66; index <= 77; index++)
        {
           if ( ( eq_have[index] ) || ( eq_masterwork[index] ) )
           {
              item = new Option(eq_name[index], index, false, false);
              selector.options[ selector.options.length] = item;
           }
        }

        // make dynamic list of shields we have
        selector = equip_win.document.equip.elements.shield;
        item = new Option("Select shield", -1, true, true);
        selector.options[ selector.options.length] = item;
        for (index = 78; index <= 83; index++)
        {
           if ( ( eq_have[index] ) || ( eq_masterwork[index] ) )
           {
              item = new Option(eq_name[index], index, false, false);
              selector.options[ selector.options.length] = item;
           }
        }
        armour_bonus = 0;

    }


    // this function returns the amount of bonus
    // a paladin gets for saving throws.
    // Starting at second level, a paladin gets a
    // saving throw bonus equal to her charisma modifer.
    // Players Hand Book (page 44)
    function Get_Paladin_Saving_Bonus()
    {
        var save_bonus = 0;

        // must be level 2 in paladin class or above
        if ( class_levels[PALADIN] < 2)
           return 0;

        save_bonus = chr_mod;
        // factor in race
        if ( (race == DWARF) || (race == ORC) )
           save_bonus--;

        if (save_bonus < 0)
           save_bonus = 0;
        return save_bonus;
    }


 
    // This function displays an empty character sheet.
    // The window handle is saved in "displaywin".
    // Names are put in the fields so that other functions
    // may enter data later.
    function Display_Empty_Sheet()
    {
       displaywin = open('', 'Language', display_feature);

       displaywin.document.writeln('<form name=display>');
       displaywin.document.writeln('<table>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Character:</td>');
       displaywin.document.writeln('  <td><input type=text name=character size=30></td>');
       displaywin.document.writeln('  <td>Player:</td>');
       displaywin.document.writeln('  <td><input type=text name=player size=30></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Classes:</td>');
       displaywin.document.writeln('  <td><input type=text name=classes size=45></td>');
       displaywin.document.writeln('  <td>Level:</td>');
       displaywin.document.writeln('  <td><input type=text name=level size=2></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Race:</td>');
       displaywin.document.writeln('  <td><input type=text name=race size=10></td>');
       displaywin.document.writeln('  <td>Alignment:</td>');
       displaywin.document.writeln('  <td><input type=text name=alignment size=20></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Religion:</td>');
       displaywin.document.writeln('  <td><input type=text name=religion size=20></td>');
       displaywin.document.writeln('  <td>Experience:</td>');
       displaywin.document.writeln('  <td><input type=text name=experience size=10></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Hit Points:</td>');
       displaywin.document.writeln('  <td><input type=text name=hit_points size=5></td>');
       displaywin.document.writeln('  <td>Base Attack Bonus:</td>');
       displaywin.document.writeln('  <td><input type=text name=base_attack_bonus size=5></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr><td><br></td><td></td></tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Strength:</td>');
       displaywin.document.writeln('  <td><input type=text name=strength size=2>');
       displaywin.document.writeln('  <input type=text name=str_mod size=2></td>');
       displaywin.document.writeln('  <td>Fortitude:</td>');
       displaywin.document.writeln('  <td><input type=text name=fortitude size=2> + ');
       displaywin.document.writeln('      <input type=text name=fortitude_mod size=2> = ');
       displaywin.document.writeln('      <input type=text name=fortitude_total size=2></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Dexterity:</td>');
       displaywin.document.writeln('  <td><input type=text name=dexterity size=2>');
       displaywin.document.writeln('  <input type=text name=dex_mod size=2></td>');
       displaywin.document.writeln('  <td>Reflex:</td>');
       displaywin.document.writeln('  <td><input type=text name=reflex size=2> + ');
       displaywin.document.writeln('      <input type=text name=reflex_mod size=2> = ');
       displaywin.document.writeln('      <input type=text name=reflex_total size=2></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Constitution:</td>');
       displaywin.document.writeln('  <td><input type=text name=constitution size=2>');
       displaywin.document.writeln('  <input type=text name=con_mod size=2></td>');
       displaywin.document.writeln('  <td>Will:</td>');
       displaywin.document.writeln('  <td><input type=text name=will size=2> + ');
       displaywin.document.writeln('      <input type=text name=will_mod size=2> = ');
       displaywin.document.writeln('      <input type=text name=will_total size=2></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Intelligence:</td>');
       displaywin.document.writeln('  <td><input type=text name=intelligence size=2>');
       displaywin.document.writeln('  <input type=text name=int_mod size=2></td>');
       displaywin.document.writeln('  <td>Initiative:</td>');
       displaywin.document.writeln('  <td><input type=text name=initiative size=2> + ');
       displaywin.document.writeln('      <input type=text name=initiative_mod size=2> = ');
       displaywin.document.writeln('      <input type=text name=initiative_total size=2></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Wisdom:</td>');
       displaywin.document.writeln('  <td><input type=text name=wisdom size=2>');
       displaywin.document.writeln('  <input type=text name=wis_mod size=2></td>');
       displaywin.document.writeln('  <td>Melee:</td>');
       displaywin.document.writeln('  <td><input type=text name=melee size=2> + ');
       displaywin.document.writeln('      <input type=text name=melee_mod size=2> + ');
       displaywin.document.writeln('      <input type=text name=melee_extra size=2> = ');
       displaywin.document.writeln('      <input type=text name=melee_total size=2></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('  <td>Charisma:</td>');
       displaywin.document.writeln('  <td><input type=text name=charisma size=2>');
       displaywin.document.writeln('  <input type=text name=chr_mod size=2></td>');
       displaywin.document.writeln('  <td>Ranged:</td>');
       displaywin.document.writeln('  <td><input type=text name=ranged size=2> + ');
       displaywin.document.writeln('      <input type=text name=ranged_mod size=2> + ');
       displaywin.document.writeln('      <input type=text name=ranged_extra size=2> = ');
       displaywin.document.writeln('      <input type=text name=ranged_total size=2></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('<tr><td><br></td><td></td></tr>');

       displaywin.document.writeln('<tr>');
       displaywin.document.writeln('<td>Money:</td>');
       displaywin.document.writeln('<td>pp - <input type=text name=pp size=5> ');
       displaywin.document.writeln('gp - <input type=text name=gold size=5> ');
       displaywin.document.writeln('sp - ');
       displaywin.document.writeln('<input type=text name=silver size=2> ');
       displaywin.document.writeln('</td>');
       displaywin.document.writeln('<td>Armor Class: </td>');
       displaywin.document.writeln('<td><input type=text name=armor_class size=3> + 10 + ');
       displaywin.document.writeln('    <input type=text name=armor_class_bonus size=3> = ');
       displaywin.document.writeln('    <input type=text name=armor_class_total size=2></td>');
       displaywin.document.writeln('</tr>');
       displaywin.document.writeln('</table>');

       displaywin.document.writeln('</form>');
       
       // you're cut off
       // displaywin.document.close();
       displaywin.focus();
    }     // end of Display_Empty_Sheet()


    // This function displays the character sheet with all
    // of the character's data.
    // This is it, baby! This is what we've been waiting for!
    function Display_Character()
    {
       var count;
       var t = "";
       var have_skill;
       var spell_count;
       var halfling_save = 0;
       var total, skill_mod;
       var paladin_saving_bonus = 0;
       var racial_bonus = 0;

       // if we don't have a character yet, then don't display
       // the sheet.
       if (intelligence == 0)
       {
          alert('Please create a character first.');
          return;
       }

       Display_Empty_Sheet();    // have to start somewhere

       displaywin.document.display.character.value = document.main.character_name.value;
       displaywin.document.display.player.value = document.main.player_name.value;
       displaywin.document.display.race.value = race_name;
       // display classes with levels
       for (count = 0; count <= WIZARD; count++)
       {
          if (class_levels[count])
          {
             switch (count)
             {
                case BARBARIAN: t = t + "Bar "; break;
                case BARD: t = t + "Brd "; break;
                case CLERIC: t = t + "Clr "; break;
                case DRUID: t = t + "Dru "; break;
                case FIGHTER: t = t + "Fig "; break;
                case MONK: t = t + "Mnk "; break;
                case PALADIN: t = t + "Pal "; break;
                case RANGER: t = t + "Ran "; break;
                case ROGUE: t = t + "Rog "; break;
                case SORCERER: t = t + "Sor "; break;
                case WIZARD: t = t + "Wiz "; break;
             }
             t = t + class_levels[count] + " ";
          }
       }
       displaywin.document.display.classes.value = t;
       displaywin.document.display.level.value = total_level;
       displaywin.document.display.race.value = race_name;
       displaywin.document.display.alignment.value = alignment_name;
       if (religion == OTHER_GOD)
         displaywin.document.display.religion.value = displaywin.opener.document.main.religion_name.value;
       else
         displaywin.document.display.religion.value = religion_name;

       displaywin.document.display.experience.value = experience_points;
       displaywin.document.display.hit_points.value = hit_points;
       displaywin.document.display.base_attack_bonus.value = base_attack_bonus;

       // Halflings get +1 to all saving throws (page 20 PHB)
       if (race == HALFLING)
          halfling_save = 1;

       paladin_saving_bonus = Get_Paladin_Saving_Bonus();

       displaywin.document.display.fortitude.value = fortitude_save + halfling_save + paladin_saving_bonus;
       displaywin.document.display.reflex.value = reflex_save + halfling_save + paladin_saving_bonus;
       displaywin.document.display.will.value = will_save + halfling_save + paladin_saving_bonus;
       // factor in racial bonus
       if ( (race == DWARF) || (race == GNOME) )
          displaywin.document.display.fortitude_mod.value = con_mod + 1;
       else if (race == ELF)
          displaywin.document.display.fortitude_mod.value = con_mod - 1;
       else
          displaywin.document.display.fortitude_mod.value = con_mod;

       // racial difference for dex
       if ( (race == ELF) || (race == HALFLING) )
          displaywin.document.display.reflex_mod.value = dex_mod + 1;
       else
         displaywin.document.display.reflex_mod.value = dex_mod;

       displaywin.document.display.will_mod.value = wis_mod;

       displaywin.document.display.fortitude_total.value = (displaywin.document.display.fortitude.value - 0) + (displaywin.document.display.fortitude_mod.value - 0);
       displaywin.document.display.reflex_total.value = (displaywin.document.display.reflex.value - 0) + (displaywin.document.display.reflex_mod.value - 0);
       displaywin.document.display.will_total.value = (displaywin.document.display.will.value - 0) + (displaywin.document.display.will_mod.value - 0);

       // make a guess at initiative, melee and ranged bonuses
       if (feats[IMPROVED_INITIATIVE])
          displaywin.document.display.initiative_mod.value = 4;

       // remember racial difference for dex
       if ( (race == ELF) || (race == HALFLING) )
         displaywin.document.display.initiative.value = dex_mod + 1;
       else
         displaywin.document.display.initiative.value = dex_mod;

       displaywin.document.display.initiative_total.value = (displaywin.document.display.initiative.value - 0) + (displaywin.document.display.initiative_mod.value - 0);
 
       displaywin.document.display.melee.value = base_attack_bonus;

       // factor in racial strength differences
       if ( (race == GNOME) || (race == HALFLING) )
         displaywin.document.display.melee_mod.value = str_mod - 1;
       else if (race == HALF_ORC)
         displaywin.document.display.melee_mod.value = str_mod + 1;
       else
         displaywin.document.display.melee_mod.value = str_mod;

       displaywin.document.display.ranged.value = base_attack_bonus;
       // factor in dex modifier for races
       if ( (race == ELF) || (race == HALFLING) )
          displaywin.document.display.ranged_mod.value = dex_mod + 1;
       else
          displaywin.document.display.ranged_mod.value = dex_mod;

       displaywin.document.display.melee_total.value = (displaywin.document.display.melee.value - 0) + (displaywin.document.display.melee_mod.value - 0) + (displaywin.document.display.melee_extra.value - 0);
       displaywin.document.display.ranged_total.value = (displaywin.document.display.ranged.value - 0) + (displaywin.document.display.ranged_mod.value - 0) + (displaywin.document.display.ranged_extra.value - 0);

       // remember to alter scores for races
       if ( (race == GNOME) || (race == HALFLING) )
       {
          displaywin.document.display.strength.value = strength - 2;
          displaywin.document.display.str_mod.value = str_mod - 1;
       }
       else if (race == HALF_ORC)
       {
          displaywin.document.display.strength.value = strength + 2;
          displaywin.document.display.str_mod.value = str_mod + 1;
       }
       else
       {  
         displaywin.document.display.strength.value = strength;
         displaywin.document.display.str_mod.value = str_mod;
       }

       if ( (race == ELF) || (race == HALFLING) )
       {
          displaywin.document.display.dexterity.value = dexterity + 2;
          displaywin.document.display.dex_mod.value = dex_mod + 1;
       } 
       else
       {
          displaywin.document.display.dexterity.value = dexterity;
          displaywin.document.display.dex_mod.value = dex_mod;
       }
      
       if (race == HALF_ORC)
       {
          if ( (intelligence - 2) >= 3)
            displaywin.document.display.intelligence.value = intelligence - 2;
          else
            displaywin.document.display.intelligence.value = 3;
          displaywin.document.display.int_mod.value = int_mod - 1;
       }
       else
       {
          displaywin.document.display.intelligence.value = intelligence;
          displaywin.document.display.int_mod.value = int_mod;
       }
 
       if ( (race == DWARF) || (race == GNOME) )
       {
          displaywin.document.display.constitution.value = constitution + 2;
          displaywin.document.display.con_mod.value = con_mod + 1;
       }
       else if (race == ELF)
       {
          displaywin.document.display.constitution.value = constitution - 2;
          displaywin.document.display.con_mod.value = con_mod - 1;
       }
       else
       {
         displaywin.document.display.constitution.value = constitution;
         displaywin.document.display.con_mod.value = con_mod;
       }

       displaywin.document.display.wisdom.value = wisdom;
       displaywin.document.display.wis_mod.value = wis_mod;
       if ( (race == DWARF) || (race == HALF_ORC) )
       {
          displaywin.document.display.charisma.value = charisma - 2;
          displaywin.document.display.chr_mod.value = chr_mod - 1;
       }
       else
       {
         displaywin.document.display.charisma.value = charisma;
         displaywin.document.display.chr_mod.value = chr_mod;
       }

       if (money > 100.0)
       {
         displaywin.document.display.silver.value = Math.floor( (money - Math.floor(money)) * 10 );
         displaywin.document.display.pp.value = Math.floor( (money / 10) / 10);
         // displaywin.document.display.gold.value = Math.floor( money - (money / 10) );
         displaywin.document.display.gold.value = Math.floor( money - (displaywin.document.display.pp.value * 10) );
       }
       else
       {
         displaywin.document.display.gold.value = Math.floor(money);
         displaywin.document.display.silver.value = Math.floor( (money - Math.floor(money)) * 10 );
       }

       // dexterity is the big thing for armor class
       // Make sure race adjustment (for dex) gets added
       if (race == ELF)         // elves get a +1 due to added dex
          displaywin.document.display.armor_class.value = dex_mod + 1;
       else if (race == GNOME)    // gnomes get a +1 bonus from size
          displaywin.document.display.armor_class.value = dex_mod + 1;
       else if (race == HALFLING)   // halflings get two bonuses +1 for size and +1 for dex
          displaywin.document.display.armor_class.value = dex_mod + 2;
       else
          displaywin.document.display.armor_class.value = dex_mod;

       // If the character is/was a monk, she gets a wisdom bonus to armor.
       if ( (class_levels[MONK]) && (wisdom > 9) )
         displaywin.document.display.armor_class_bonus.value = wis_mod;
       else
         displaywin.document.display.armor_class_bonus.value = 0;

       // Monks also get class AC bonus.
       // but only if unencumbered by armour
       if ( (class_levels[MONK]) && (armour_bonus == 0) )
       {
          count = displaywin.document.display.armor_class_bonus.value - 0;
          displaywin.document.display.armor_class_bonus.value = count + Math.floor( class_levels[MONK] / 5 ); 
       }
       else   // not a monk
          displaywin.document.display.armor_class_bonus.value = armour_bonus;

       // total armor class up...
       displaywin.document.display.armor_class_total.value = (displaywin.document.display.armor_class.value - 0) + (displaywin.document.display.armor_class_bonus.value - 0) + 10;

       displaywin.document.writeln('<table width=100%>');
       // put out skills
       displaywin.document.writeln('<tr>');
       t = "";
       for (count = 0; count <= USE_ROPE; count++)
       {
             have_skill = false;
             if ( (count == SEARCH) || (count == SPOT) || (count == LISTEN) )
             {
                if (race == ELF)
                {
                   t = t + Proper_Case(skill_names[count]) + " " + (skills[count] + 2);
                   have_skill = true;
                }
                else if (race == HALF_ELF)
                {
                   t = t + Proper_Case(skill_names[count]) + " " + (skills[count] + 1);
                   have_skill = true;
                }
                else if (skills[count] > 0)
                {
                   t = t + Proper_Case(skill_names[count]) + " " + skills[count];
                   have_skill = true;
                }
             }
             else if ( (count == HIDE_SKILL) && ( (race == GNOME)  || (race == HALFLING) ) )
             {
                t = t + Proper_Case(skill_names[count]) + " " + (skills[count] + 4);
                have_skill = true;
             }

             else if ( (count == LISTEN) && (race == GNOME) )
             {
                t = t + Proper_Case(skill_names[count]) + " " + (skills[count] + 2);
                have_skill = true;
             }

             
             else if ( (count == CLIMB) || (count == MOVE_SILENTLY) || 
                     (count == JUMP) || (count == LISTEN) )
             {
                  if ( race == HALFLING )
                  {
                    t = t + Proper_Case(skill_names[count]) + " " + (skills[count] + 2);
                    have_skill = true;
                  }
                  else if ( skills[count] )
                  {
                     t = t + Proper_Case(skill_names[count]) + " " + skills[count];
                     have_skill = true;
                  }
             }
             

             else if (skills[count])
             {
               t = t + Proper_Case(skill_names[count]) + " " + skills[count];
               have_skill = true;
             }

             if (have_skill)
                t = t + " + ";

             // display which ability effects the skill
             if (have_skill)
             {
             switch (count)
             {
                case APPRAISE:
                case CRAFT:
                case DECIPHER_SCRIPT:
                case DISABLE_DEVICE:
                case FORGERY:
                case KNOWLEDGE_ARCANA:
                case KNOWLEDGE_ARCHITECTURE:
                case KNOWLEDGE_DUNGEONEERING:
                case KNOWLEDGE_GEOGRAPHY:
                case KNOWLEDGE_HISTORY:
                case KNOWLEDGE_LOCAL:
                case KNOWLEDGE_NATURE:
                case KNOWLEDGE_NOBILITY:
                case KNOWLEDGE_RELIGION:
                case KNOWLEDGE_PLANES:
                case SEARCH:
                case SPELLCRAFT:
                     // t = t + " int";
                     skill_mod = int_mod;
                     if (race == HALF_ORC) skill_mod--;
                     if (count == SEARCH)
                     {
                        if (race == ELF)
                           racial_bonus = 2;
                        else if (race == HALF_ELF)
                           racial_bonus = 1;
                     }
                     t = t + " " + skill_mod + " = " + (skills[count] + skill_mod + racial_bonus);
                     racial_bonus = 0;
                     break;
                case BALANCE:
                case ESCAPE_ARTIST:
                case HIDE_SKILL:
                case MOVE_SILENTLY:
                case OPEN_LOCK:
                case RIDE:
                case SLEIGHT_OF_HAND:
                case TUMBLE:
                case USE_ROPE:
                     // t = t + " dex";
                     skill_mod = dex_mod;
                     if ( (race == ELF) || (race == HALFLING) )
                        dex_mod++;
                     t = t + " " + skill_mod + " = " + (skills[count] + skill_mod);
                     break;
                case BLUFF:
                case DIPLOMACY:
                case DISGUISE:
                case GATHER_INFORMATION:
                case HANDLE_ANIMAL:
                case INTIMIDATE:
                case PERFORM:
                case USE_MAGIC_DEVICE:
                     // t = t + " chr";
                     skill_mod = chr_mod;
                     if ((race == DWARF) || (race == HALF_ORC))
                         skill_mod--;
                     t = t + " " + skill_mod + " = " + (skills[count] + skill_mod);
                     break;
                case CLIMB:
                case JUMP:
                case SWIM:
                     // t = t + " str";
                     skill_mod = str_mod;
                     if ( (race == GNOME) || (race == HALFLING) )
                        skill_mod--;
                     else if (race == HALF_ORC)
                        skill_mod++;
                     t = t + " " + skill_mod + " = " + (skills[count] + skill_mod);
                     break;
                case CONCENTRATION:
                     // t = t + " con";
                     skill_mod = con_mod;
                     if ( (race == DWARF) || (race == GNOME) )
                        skill_mod++;
                     else if (race == ELF)
                        skill_mod--;
                     t = t + " " + skill_mod + " = " + (skills[count] + skill_mod);
                     break;
                case HEAL:
                case LISTEN:
                case PROFESSION:
                case SENSE_MOTIVE:
                case SPOT:
                case SURVIVAL:
                     // t = t + " wis";
                     skill_mod = wis_mod;
                     if ( (count == SPOT) || (count == LISTEN) )
                     {
                          if (race == ELF)
                            racial_bonus = 2;
                          else if (race == HALF_ELF)
                            racial_bonus = 1;
                     }
                     t = t + " " + skill_mod + " = " + (skills[count] + skill_mod + racial_bonus);
                     racial_bonus = 0;
                     break;
                // default:
                //     t = t + "<br>";
                     break;
             }   // end of switch
             t = t + "<br>";
/*
             // Display if the skill is trained or untrained
             switch (count)
             {
              case APPRAISE:
              case BALANCE:
              case BLUFF:
              case CLIMB:
              case CONCENTRATION:
              case CRAFT:
              case DIPLOMACY:
              case DISGUISE:
              case ESCAPE_ARTIST:
              case FORGERY:
              case GATHER_INFORMATION:
              case HEAL:
              case HIDE_SKILL:
              case INTIMIDATE:
              case JUMP:
              case LISTEN:
              case MOVE_SILENTLY:
              case PERFORM:
              case RIDE:
              case SEARCH:
              case SENSE_MOTIVE:
              case SPOT:
              case SURVIVAL:
              case SWIM:
              case USE_ROPE:
                   t = t + " (UT)<br>";
                   break;
              default:
                   t = t + " (T)<br>";
                   break;
           }      // end of switch
*/
             }   // end of if we have this skill
       }   // end of for loop for skills

       if (race == ELF)
         t = t + "Immune to sleep<br>";
       displaywin.document.writeln('<td><b>Skills:</b><br><br>');
       displaywin.document.writeln(t);
       displaywin.document.writeln('<br><br></td>');

       // put out equipment
       displaywin.document.writeln('<td><b>Equipment:</b><br><br>');
       t = "";
       for (count = 0; count <= MAX_EQUIPMENT; count++)
       {
           if (eq_have[count])
               t = t + eq_name[count] + " " + eq_bonus[count] + " (" + eq_have[count] + ")<br>";
           if (eq_masterwork[count])
               t = t + "Masterwork, " + eq_name[count] + " " + eq_bonus[count] + " (" + eq_masterwork[count] + ")<br>";
       }
       displaywin.document.writeln(t);
       displaywin.document.writeln('<br>');
       for (count = 0; count < max_user_equipment; count++)
           displaywin.document.writeln(user_equipment_list[count], '<br>');
       displaywin.document.writeln('<br><br></td></tr>');

       // display feats and special characteristics
       displaywin.document.writeln('<tr><td><b>Feats/Specials:</b><br><br>');
       t = "";
       if (alignment_conflict)
          t = t + "*May be alignment conflict*<br>";

       for (count = 0; count <= WIDEN_SPELL; count++)
       {
          if (feats[count])
          {
            t = t + Proper_Case(feat_names[count]) + "<br>";
          }
       }
       // get feats/abilities specific to a class
       t = t + Get_Class_Special();
       // also get bonus monk feats
       if ( class_levels[MONK] )
       {
         for (count = 0; count < 3; count++)
         {
            // if we have a monk bonus feat and it has not already been listed, print it
            if ( ( monk_bonus_feats[count] ) && (! feats[ monk_bonus_feats[count] ] ) )
               t = t + Proper_Case(feat_names[ monk_bonus_feats[count] ]) + "<br>";
         }
       }   // end of monk bonus feats

       // check for Ranger combat style
       if ( class_levels[RANGER] >= 11 )
       {
          if ( (ranger_combat_style) && (! feats[GREATER_TWO_WEAPON_FIGHTING]) )
            t = t + Proper_Case(feat_names[GREATER_TWO_WEAPON_FIGHTING]) + "<br>";
          else if ( (! ranger_combat_style) && (! feats[IMPROVED_PRECISE_SHOT]) )
            t = t + Proper_Case(feat_names[IMPROVED_PRECISE_SHOT]) + "<br>";
       }
       if ( class_levels[RANGER] >= 6 )
       {
         if ( (ranger_combat_style) && (! feats[IMPROVED_TWO_WEAPON_FIGHTING]) )
           t = t + Proper_Case(feat_names[IMPROVED_TWO_WEAPON_FIGHTING]) + "<br>";
         else if ( (! ranger_combat_style) && (! feats[MANYSHOT]) )
           t = t + Proper_Case(feat_names[MANYSHOT]) + "<br>";
       }
       if ( class_levels[RANGER] >= 2 )
       {
         if ( (ranger_combat_style) && (! feats[TWO_WEAPON_FIGHTING]) )
           t = t + Proper_Case(feat_names[TWO_WEAPON_FIGHTING]) + "<br>";
         else if ( (! ranger_combat_style) && (! feats[RAPID_SHOT]) )
           t = t + Proper_Case(feat_names[RAPID_SHOT]) + "<br>";
       }

       displaywin.document.writeln(t);
       displaywin.document.writeln('<br><br></td>');
      
       // display known languages
       t = "";
       for (count = 0; count <= UNDERCOMMON; count++)
       {
           if (language[count])
           {
              t = t + language_names[count] + "<br>";
           }
       }
       displaywin.document.writeln('<td><b>Languages:</b><br><br>');
       displaywin.document.writeln(t);
       displaywin.document.writeln('<br><br></td></tr>');

       // display arcane spells for Bards, Sorcerers and Wizards
       displaywin.document.writeln('<tr><td>');
       if (class_levels[SORCERER])
       {
          t = "<b>Sorcerer Spells</b><br><br>";
          for (count = 0; count < 10; count++)
          {
            spell_count = 0;
            while (wizard_spell_name[count][spell_count] != " ")
            {
               if (sorcerer_spells[count][spell_count])
                  t = t + " " + wizard_spell_name[count][spell_count] + " -- " + count + "<br>";
               spell_count++;
            }
          }
          displaywin.document.writeln(t, '<br><br>');
       }

       if (class_levels[WIZARD])
       {
          t = "<b>Wizard Spells</b><br><br>";
          for (count = 0; count < 10; count++)
          {
            spell_count = 0;
            while (wizard_spell_name[count][spell_count] != " ")
            {
               if (wizard_spells[count][spell_count])
                  t = t + " " + wizard_spell_name[count][spell_count] + " -- " + wizard_spell_domain[count][spell_count] + " -- " + count + "<br>";
               spell_count++;
            }
          }
          displaywin.document.writeln(t);
       }
 
       displaywin.document.writeln('<br><br></td>');

        // display bard spells
        displaywin.document.writeln('<td>');
        if (class_levels[BARD])
        {
           t = "<b>Bard Spells</b><br><br>";
           for (count = 0; count < 7; count++)
           {
              spell_count = 0;
              while (bard_spell_name[count][spell_count] != " ")
              {
                 if (bard_spells[count][spell_count])
                   t = t + " " + bard_spell_name[count][spell_count] + " -- " + count + "<br>";
                 spell_count++;
              }
           }
           displaywin.document.writeln(t);
        }
        displaywin.document.writeln('<br><br></td></tr>');
        displaywin.document.writeln('</table>');
        displaywin.document.close();

    }    // end of display character


    // This function loads the version.htm page on the main web site.
    // It then checks for the current version number on that
    // page. This function then displays a message showing
    // whether there is an update availble.
    function Check_Update()
    {
       var New_Win = open('http://slicer69.tripod.com/dnd/version.htm', 'Update', min_feature);
       var new_version;

       new_version = New_Win.document.version.number.value;
       new_version -= 0.0; new_version += 0.0;

       New_Win.close();

       if (current_version < new_version)
         alert('There is a new version available at http://slicer69.tripod.com/dnd/dnd.htm');
       else if (current_version > new_version)
         alert('Your version is more up to date than the offical release.');
       else
         alert('You have the latest offical version of this character generator.');

       
    }   // end of Check_Update


    // This function opens a new window with a textbox and
    // prints out character information.
    // The info is displayed in the format
    // [field] [data][newline]
    function Save_Character(dnd_path, id)
    {
       var t;
       var count;
       var level_count;

       // check to make sure we have a character
       if (intelligence == 0)
       {
          alert('Please create a character first.');
          return;
       }

       save_win = open('', 'Save', min_feature);
       save_win.document.writeln('<font size=+1>');
       save_win.document.writeln('Save Character<br><br>');
       save_win.document.writeln('</font>');
       save_win.document.writeln('To save your character, please click on the button ');
       save_win.document.writeln('button below marked <i>Save to File</i>. If this does ');
       save_win.document.writeln('not work, or if you do not have an Internet connection, ');
       save_win.document.writeln('then you can highlight the ');
       save_win.document.writeln('entire text in the window below.');
       save_win.document.writeln('Right click in the window and select "Copy".');
       save_win.document.writeln('Then Paste the text into a text editor of your choice.');
       save_win.document.writeln('<br><br>');
       save_win.document.writeln('<form name="save" method="post" action="'+dnd_path+'/dnd_character_generator.savefile.php?id='+id+'">');
       save_win.document.writeln('<input type=submit value="Save to File"><br><br>');
       save_win.document.writeln('<textarea rows=25 cols=80 name=data></textarea>');
       save_win.document.writeln('<br><br>');
       save_win.document.writeln('<input type=button value="Close" onClick="window.close()">');
       save_win.document.writeln('</form>');

       t = "";
       
       // put basic info into the string
       t += "Player " + save_win.opener.document.main.player_name.value + "\n";
       t += "Name " + save_win.opener.document.main.character_name.value + "\n";
       t += "Race " + save_win.opener.race_name + "\n";
       t += "RaceNum " + save_win.opener.race + "\n";
       t += "StartingClass " + starting_class + "\n";

       for (count = 0; count <= WIZARD; count++)
       {
         switch ( count )
         {
           case BARBARIAN: t += "Barbarian "; break;
           case BARD: t += "Bard "; break;
           case CLERIC: t += "Cleric "; break;
           case DRUID: t += "Druid "; break;
           case FIGHTER: t += "Fighter "; break;
           case MONK: t += "Monk "; break;
           case PALADIN: t += "Paladin "; break;
           case RANGER: t += "Ranger "; break;
           case ROGUE: t += "Rogue "; break;
           case SORCERER: t += "Sorcerer "; break;
           case WIZARD: t += "Wizard "; break;
         }      // end of switch

         t += class_levels[count] + "\n";
       }     // end of for loop, classes

       t += "Alignment " + save_win.opener.alignment + "\n";
       t += "Religion " + save_win.opener.religion + "\n";

       // put ability scores in the string
       t += "Strength " + strength + " " + min_str + "\n";
       t += "Dexterity " + dexterity + " " + min_dex + "\n";
       t += "Constitution " + constitution + " " + min_con + "\n";
       t += "Intelligence " + intelligence + " " + min_int + "\n";
       t += "Wisdom " + wisdom + " " + min_wis + "\n";
       t += "Charisma " + charisma + " " + min_chr + "\n";
       
       t += "Money " + money + "\n";
       t += "BaseAttackBonus " + base_attack_bonus + "\n";
       t += "FortitudeSave " + fortitude_save + "\n";
       t += "WillSave " + will_save + "\n";
       t += "ReflexSave " + reflex_save + "\n";
       t += "HitPoints " + hit_points + "\n";
       t += "ArmourBonus " + armour_bonus + "\n";
       t += "ArmourIndex " + armour_index + "\n";
       t += "ShieldIndex " + shield_index + "\n";

       // put skills in the string
       for (count = 0; count <= USE_ROPE; count++)
       {
          if ( skills[count] )
            t += "Skill " + count + " " + skills[count] + "\n";
       }   // end of skill for loop

   
       // put feats in the string
       for (count = 0; count <= WIDEN_SPELL; count++)
       {
          if ( feats[count] )
            t += "Feat " + count + " " + feats[count] + "\n";
       }    // end of feats for loop

       // put equipment in the string
       for (count = 0; count <= MAX_EQUIPMENT; count++)
       {
          if ( eq_masterwork[count] )
            t += "EQ " + count + " " + eq_masterwork[count] + " MASTERWORK\n";

          if ( eq_have[count] )
            t += "EQ " + count + " " + eq_have[count] + "\n"; 
       }   // end of equipment for loop

       // put user defined equipment in the string
       for (count = 0; count < max_user_equipment; count++)
       {
          if (user_equipment_list[count])
              t += "USEREQ " + count + " " + user_equipment_list[count] + "\n";
       }

       // put languages in the string
       for (count = 0; count <= UNDERCOMMON; count++)
       {
          if ( language[count] )
            t += "Language " + count + "\n";

       }  // end of languages for loop

       // put bard spells in the string
       for ( level_count = 0; level_count < 7; level_count++)
       {
          count = 0;
          while ( bard_spell_name[level_count][count] != " " )
          {
            if ( bard_spells[level_count][count] )
              t += "Spell Bard " + level_count + " " + count + "\n";

            count++;
          }
       }    // end of bard spells for loop

       // put sorcerer spells in the string
       for ( level_count = 0; level_count < 10; level_count++)
       {
         count = 0;
         while ( wizard_spell_name[level_count][count] != " " )
         {
           if ( sorcerer_spells[level_count][count] )
              t += "Spell Sorcerer " + level_count + " " + count + "\n";
           count++;
         }
       }

       // put wizard spells in the string
       for ( level_count = 0; level_count < 10; level_count++)
       {
          count = 0;
          while ( wizard_spell_name[level_count][count] != " " )
          {
             if ( wizard_spells[level_count][count] )
               t += "Spell Wizard " + level_count + " " + count + "\n";
             count++;
          }
       }

       // if we are a wizard, put in special and restricted domains
       if ( class_levels[WIZARD] )
       {
         t += "SpecialDomain " + special_spell_domain + "\n";
         t += "RestrictedDomain1 " + restricted_spell_domain[0] + "\n";
         t += "RestrictedDomain2 " + restricted_spell_domain[1] + "\n";
       }

       // check for ranger of level 2 or up
       if ( class_levels[RANGER] > 1)
         t += "RangerStyle " + ranger_combat_style + "\n";

       // check for monk specials
       if ( class_levels[MONK] )
       {
         t += "MonkSpecial1 " + monk_bonus_feats[0] + "\n";
         t += "MonkSpecial2 " + monk_bonus_feats[1] + "\n";
         t += "MonkSpecial3 " + monk_bonus_feats[2] + "\n";
       }

       t += "NOTES \n";
       t += game_notes;

       save_win.document.save.data.value = t;
       save_win.document.close();
       save_win.focus();
    }   // end of save character


    // This function gets an argument from a passed string.
    function Get_Argument(line, arg_number)
    {
       var found = false;
       var index = 0;
       var num_spaces = 0;

       while ( (! found) && (index < line.length) )
       {
          if ( line.charAt(index) == ' ' )
            num_spaces++;

          index++;

          if (num_spaces == arg_number)
             found = true;
       }

       if (! found)
         return '';

       start_arg = index;
       // search from here to end of arg
       while ( (index < line.length) && ( line.charAt(index) != ' ' ) && (line.charAt(index) != '\n') )
          index++;

       return line.substring(start_arg, index);
       
    }     // end of Get Argument


    // This function takes the character data from a text box in
    // the "save_win" window. It interprets the data and
    // loads the character into the character generator.
    function Load_Character()
    {
        var t;         // all the data
        var line;  // one line of data
        var cmd, arg1, arg2, arg3;           // arguments of data on a line
        var last_index, index;     // position in the data
        var post_notes = false;

        // initalize everything
        game_notes = "";
        Clear_Skills_Feats_Equipment_Language();
        skill_points = 0;
        feat_points = 0;
        fighter_feats = wizard_feats = 0;
        language_points = 0;
        for (index = 0; index < 10; index++)
        {
           num_wizard_spells[index] = 0;
           num_sorcerer_spells[index] = 0;
           for (last_index = 0; last_index < 50; last_index++)
           {
              sorcerer_spells[index][last_index] = 0;
              wizard_spells[index][last_index] = 0;
           }
        }
        for (index = 0; index < 7; index++)
        {
           num_bard_spells[index] = 0;
           for (last_index = 0; last_index < 40; last_index++)
           {
              bard_spells[index][last_index] = 0;
              last_index++;
           }
        }

        // get data from the text box
        t = save_win.document.load.data.value;
        index = 0;
        last_index = 0;

        while ( index < t.length )
        {
          // load a line from the data
          while ( (index < t.length) && ( t.charAt(index) != '\n' ) && ( t.charAt(index) != '\r') )
            index++;

          line = t.substring(last_index, index);
          index++;
          last_index = index;

          if (post_notes)
             game_notes += line + '\n';
          {
          // check the line for key words
          cmd = line.substring(0, line.indexOf(' ') );
          if ( cmd == "Player" )
             document.main.player_name.value = line.substring(7);
          else if ( cmd == "Name" )
             document.main.character_name.value = line.substring(5);
          else if ( cmd == "Race" )
             document.main.race_name = Get_Argument(line, 1);
          else if ( cmd == "RaceNum")
             race = Get_Argument(line, 1) - 0;
          else if ( cmd == "StartingClass")
             starting_class = Get_Argument(line, 1) - 0;
          else if ( cmd == "Barbarian" )
            class_levels[BARBARIAN] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Bard" )
            class_levels[BARD] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Cleric" )
            class_levels[CLERIC] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Druid" )
            class_levels[DRUID] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Fighter" )
            class_levels[FIGHTER] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Monk" )
            class_levels[MONK] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Paladin" )
            class_levels[PALADIN] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Ranger" )
            class_levels[RANGER] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Rogue" )
            class_levels[ROGUE] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Sorcerer" )
            class_levels[SORCERER] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Wizard" )
            class_levels[WIZARD] = Get_Argument(line, 1) - 0;
          else if ( cmd == "Alignment")
            alignment = Get_Argument(line, 1) - 0;
          else if ( cmd == "Religion")
            religion = Get_Argument(line, 1) - 0;

          else if ( cmd == "Strength")
          {
            strength = Get_Argument(line, 1) - 0;
            min_str = Get_Argument(line, 2) - 0;
          }
          else if ( cmd == "Dexterity")
          {
            dexterity = Get_Argument(line, 1) - 0;
            min_dex = Get_Argument(line, 2) - 0;
          }
          else if ( cmd == "Constitution")
          {
            constitution = Get_Argument(line, 1) - 0;
            min_con = Get_Argument(line, 2) - 0;
          }
          else if ( cmd == "Intelligence")
          {
             intelligence = Get_Argument(line, 1) - 0;
             min_int = Get_Argument(line, 2) - 0;
          }
          else if ( cmd == "Wisdom")
          {
             wisdom = Get_Argument(line, 1) - 0;
             min_wis = Get_Argument(line, 2) - 0;
          }
          else if ( cmd == "Charisma")
          {
             charisma = Get_Argument(line, 1) - 0;
             min_chr = Get_Argument(line, 2) - 0;
          }
          else if ( cmd == "Money")
            money = Get_Argument(line, 1) - 0;
          else if ( cmd == "BaseAttackBonus")
            base_attack_bonus = Get_Argument(line, 1) - 0;
          else if ( cmd == "FortitudeSave")
            fortitude_save = Get_Argument(line, 1) - 0;
          else if ( cmd == "WillSave")
            will_save = Get_Argument(line, 1) - 0;
          else if ( cmd == "ReflexSave")
            reflex_save = Get_Argument(line, 1) - 0;
          else if ( cmd == "HitPoints")
            hit_points = Get_Argument(line, 1) - 0;
          else if ( cmd == "ArmourBonus")
            armour_bonus = Get_Argument(line, 1) - 0;
          else if ( cmd == "ArmourIndex")
            armour_index = Get_Argument(line, 1) - 0;
          else if ( cmd == "ShieldIndex")
            shield_index = Get_Argument(line, 1) - 0;
          else if ( cmd == "Skill")
          {
             arg1 = Get_Argument(line, 1) - 0;
             arg2 = Get_Argument(line, 2) - 0;
             skills[arg1] = arg2;
          }
          else if ( cmd == "Feat")
          {
            arg1 = Get_Argument(line, 1) - 0;
            arg2 = Get_Argument(line, 2) - 0;
            feats[arg1] = arg2;
          }
          else if ( cmd == "EQ")
          {
            arg1 = Get_Argument(line, 1) - 0;
            arg2 = Get_Argument(line, 2) - 0;
            arg3 = Get_Argument(line, 3);
            if (arg3 == "MASTERWORK")
               eq_masterwork[arg1] = arg2;
            else
               eq_have[arg1] = arg2;
          }
          else if ( cmd == "USEREQ")
          {
              arg1 = Get_Argument(line, 1) - 0;
              arg2 = Get_Argument(line, 2);
              if (max_user_equipment < (arg1 + 1) )
                 max_user_equipment = arg1 + 1;
              user_equipment_list[arg1] = arg2;
          }
          else if ( cmd == "Language")
          {
             arg1 = Get_Argument(line, 1) - 0;
             language[arg1] = true;
          }
          else if ( cmd == "Spell")
          {
             arg1 = Get_Argument(line, 1);       // class
             arg2 = Get_Argument(line, 2) - 0;   // level
             arg3 = Get_Argument(line, 3) - 0;   // spell number
             if ( arg1 == "Bard" )
               bard_spells[arg2][arg3] = true;
             else if ( arg1 == "Sorcerer" )
               sorcerer_spells[arg2][arg3] = true;
             else if ( arg1 == "Wizard" )
               wizard_spells[arg2][arg3] = true;
          }   // end of spell
          else if ( cmd == "SpecialDomain")
             special_spell_domain = Get_Argument(line, 1) - 0;
          else if ( cmd == "RestrictedDomain1")
             restricted_spell_domain[0] = Get_Argument(line, 1) - 0;
          else if ( cmd == "RestrictedDomain2")
             restricted_spell_domain[1] = Get_Argument(line, 1) - 0;
          else if ( cmd == "RangerStyle")
             ranger_combat_style = Get_Argument(line, 1) - 0;
          else if ( cmd == "MonkSpecial1")
             monk_bonus_feats[0] = Get_Argument(line, 1) - 0;
          else if ( cmd == "MonkSpecial2")
             monk_bonus_feats[1] = Get_Argument(line, 1) - 0;
          else if ( cmd == "MonkSpecial3")
             monk_bonus_feats[2] = Get_Argument(line, 1) - 0;
          else if ( cmd == "NOTES")
             post_notes = true;
          }      // before the notes marker
        }   // end of while not end of data


        str_mod = Math.round( (strength - 11) / 2 );
        dex_mod = Math.round( (dexterity - 11) / 2 );
        con_mod = Math.round( (constitution - 11) / 2 );
        int_mod = Math.round( (intelligence - 11) / 2 );
        wis_mod = Math.round( (wisdom - 11) / 2 );
        chr_mod = Math.round( (charisma - 11) / 2 );
        
        // fill in the fields on the main page
        document.main.strength.value = strength;
        document.main.str_mod.value = str_mod;
        document.main.dexterity.value = dexterity;
        document.main.dex_mod.value = dex_mod;
        document.main.constitution.value = constitution;
        document.main.con_mod.value = con_mod;
        document.main.intelligence.value = intelligence;
        document.main.int_mod.value = int_mod;
        document.main.wisdom.value = wisdom;
        document.main.wis_mod.value = wis_mod;
        document.main.charisma.value = charisma;
        document.main.chr_mod.value = chr_mod;

        document.main.bonus_ability.value = 0;
        // display classes properly
        Set_Total_Level();

        document.main.total_level.value = total_level;
        document.main.barbarian_class.checked = (class_levels[BARBARIAN] > 0);
        document.main.barbarian_level.selectedIndex = class_levels[BARBARIAN] ? class_levels[BARBARIAN] - 1 : 0;
        document.main.bard_class.checked = (class_levels[BARD] > 0);
        document.main.bard_level.selectedIndex = class_levels[BARD] ? class_levels[BARD] - 1 : 0;
        document.main.cleric_class.checked = (class_levels[CLERIC] > 0);
        document.main.cleric_level.selectedIndex = class_levels[CLERIC] ? class_levels[CLERIC] - 1 : 0;
        document.main.druid_class.checked = (class_levels[DRUID] > 0);
        document.main.druid_level.selectedIndex = class_levels[DRUID] ? class_levels[DRUID] - 1 : 0;
        document.main.fighter_class.checked = (class_levels[FIGHTER] > 0);
        document.main.fighter_level.selectedIndex = class_levels[FIGHTER] ? class_levels[FIGHTER] - 1 : 0;
        document.main.monk_class.checked = (class_levels[MONK] > 0);
        document.main.monk_level.selectedIndex = class_levels[MONK] ? class_levels[MONK] - 1 : 0;
        document.main.paladin_class.checked = (class_levels[PALADIN] > 0);
        document.main.paladin_level.selectedIndex = class_levels[PALADIN] ? class_levels[PALADIN] - 1 : 0;
        document.main.ranger_class.checked = (class_levels[RANGER] > 0);
        document.main.ranger_level.selectedIndex = class_levels[RANGER] ? class_levels[RANGER] - 1 : 0;
        document.main.rogue_class.checked = (class_levels[ROGUE] > 0);
        document.main.rogue_level.selectedIndex = class_levels[ROGUE] ? class_levels[ROGUE] - 1 : 0;
        document.main.sorcerer_class.checked = (class_levels[SORCERER] > 0);
        document.main.sorcerer_level.selectedIndex = class_levels[SORCERER] ? class_levels[SORCERER] - 1 : 0;
        document.main.wizard_class.checked = (class_levels[WIZARD] > 0);
        document.main.wizard_level.selectedIndex = class_levels[WIZARD] ? class_levels[WIZARD] - 1 : 0;

        // let's get alignment and religion in there too
        document.main.alignment.selectedIndex = alignment;
        document.main.religion.selectedIndex = religion;
        Set_Religion();
        document.main.starting_class.selectedIndex = starting_class;
        // update race
        document.main.race.selectedIndex = race;
        // make sure race is correct on character sheet'
        switch (race)
        {
           case HUMAN: race_name = "Human"; break;
           case ELF: race_name = "Elf"; break;
           case DWARF: race_name = "Dwarf"; break;
           case HALFLING: race_name = "Halfling"; break;
           case HALF_ELF: race_name = "Half Elf"; break;
           case HALF_ORC: race_name = "Half Orc"; break;
           case GNOME: race_name = "Gnome"; break;
        }     // switch race


        // ugly hack to get alignment name
        // I am doing this because Set_Alignment() resets ability scores.
        switch(alignment)
        {
         case LAWFUL_GOOD: alignment_name = "Lawful Good"; break;
         case NEUTRAL_GOOD: alignment_name = "Neutral Good"; break;
         case CHAOTIC_GOOD: alignment_name = "Choatic Good"; break;
         case LAWFUL_NEUTRAL: alignment_name = "Lawful Neutral"; break;
         case TRUE_NEUTRAL: alignment_name = "True Neutral"; break;
         case CHAOTIC_NEUTRAL: alignment_name = "Choatic Neutral"; break;
         case LAWFUL_EVIL: alignment_name = "Lawful Evil"; break;
         case NEUTRAL_EVIL: alignment_name = "Neutral Evil"; break;
         case CHAOTIC_EVIL: alignment_name = "Chaoic Evil"; break;

        }    // end of switch alignment


        save_win.close();
    }  // end of load character function



    // This function levels up a character. The class to be gained is
    // stored in level_up_win.document.level_up.new_class.selected
    // Long enough for you?
    // This function gives the character the extra skill points, feat points,
    // base attack bonus, saving throws,
    // spell points, hit points, bonus ability points, and experience.
    function Level_Up()
    {
       var new_class;       // so we do not always have to refer to that long variable
       var temp;            // a temp variable
       var new_skill_points;   // new skill points a character gains
       var spell_level, spell_num;

       new_class = level_up_win.document.level_up.new_class.selectedIndex;

       // check to see if this class is already at 20
       if ( class_levels[new_class] >= 20 )
       {
           alert('You already have the maximum number of levels in this class.');
           return;
       }

       // assign the new class to the character
       class_levels[new_class] += 1;
       Set_Total_Level();

       // see if we should get an extra ability score point
       if (! (total_level % 4))
       {
          bonus_ability += 1;
          max_bonus_ability += 1;
          document.main.bonus_ability.value = bonus_ability;

       }

       // Because the character gains skill points
       // and hit points at this time, we shall prevent
       // an un-gaining of ability scores.
       min_str = strength;
       min_dex = dexterity;
       min_con = constitution;
       min_wis = wisdom;
       min_int = intelligence;
       min_chr = charisma;

       Get_Experience_Points();

       // check for a new feat point
       if (! (total_level % 3))
          feat_points++;

       // fighters and wizards also get bonus feats
       if ( (new_class == WIZARD) && (! (class_levels[WIZARD] % 5)) )
          wizard_feats++;

       else if ( (new_class == FIGHTER) && (! (class_levels[FIGHTER] % 2) ) )
          fighter_feats++;
       else if ( ( new_class == FIGHTER ) && ( class_levels[FIGHTER] == 1 ) )
          fighter_feats++;

       // give bards, sorcerers and wizards their new spells

       // bards
       if ( (new_class == BARD) && ( class_levels[BARD] > 1) ) // old bard
       {
       // get all the spells we can learn at this level
       for (spell_level = 0; spell_level < 7; spell_level++)
         num_bard_spells[spell_level] = 0;

       Gain_Bard_Spells();

       // remove spells we have learned from the ones we can learn
       for (spell_level = 0; spell_level < 7; spell_level++)
       {
          temp = 0;
          for (spell_num = 0; spell_num < 40; spell_num++)
          {
             if ( bard_spells[spell_level][spell_num] )
               temp++;
          }
          num_bard_spells[spell_level] -= temp;
       }
       }   // end of bard
       else if ( (new_class == BARD) && (class_levels[BARD] == 1) ) // new bard
          Init_Bard_Spells();


       // sorcerers
       if ( (new_class == SORCERER) && ( class_levels[SORCERER] > 1) ) // old sorcerer
       {
       // get all the spells we can learn
       for (spell_level = 0; spell_level < 10; spell_level++)
         num_sorcerer_spells[spell_level] = 0;

       Gain_Sorcerer_Spells();

       // remove spells we have learned from the ones we can learn
       for (spell_level = 0; spell_level < 10; spell_level++)
       {
          temp = 0;
          for (spell_num = 0; spell_num < 50; spell_num++)
          {
             if ( sorcerer_spells[spell_level][spell_num] )
               temp++;
          }
          num_sorcerer_spells[spell_level] -= temp;
       }
       }   // end of sorcerer
       else if ( ( new_class == SORCERER ) && ( class_levels[SORCERER] == 1 ) ) // new sorcerer
         Init_Sorcerer_Spells();



       // wizards
       if ( ( new_class == WIZARD ) && ( class_levels[WIZARD] > 1) )  // already a wizard
       {
         temp = Math.round( class_levels[WIZARD] / 2.0 );
         if (temp > 9) temp = 9;
         num_wizard_spells[ temp ] += 2;
       }
       else if ( ( new_class == WIZARD ) && ( class_levels[WIZARD] == 1) ) // new wizard
          Init_Wizard_Spells();


       // assign new skill points
       temp = int_mod;
       // orcs have a lower intelligence
       if ( race == HALF_ORC ) temp -= 1;
       new_skill_points = 0;
       switch ( new_class )
       {
          case BARBARIAN: new_skill_points += 4 + temp; break;
          case BARD: new_skill_points += 6 + temp; break;
          case CLERIC: new_skill_points += 2 + temp; break;
          case DRUID: new_skill_points += 4 + temp; break;
          case FIGHTER: new_skill_points += 2 + temp; break;
          case MONK: new_skill_points += 4 + temp; break;
          case PALADIN: new_skill_points += 2 + temp; break;
          case RANGER: new_skill_points += 6 + temp; break;
          case ROGUE: new_skill_points += 8 + temp; break;
          case SORCERER: new_skill_points += 2 + temp; break;
          case WIZARD: new_skill_points += 2 + temp; break;
       }    // end of switch for skill points

       if (new_skill_points < 1) new_skill_points = 1;
       if (race == HUMAN) new_skill_points++;
       skill_points += new_skill_points;
       max_skill_points += new_skill_points;

       // get hit points for new class
       temp = 0;
       switch ( new_class )
       {
         case BARBARIAN: temp += Roll_Die(12); break;
         case BARD: temp += Roll_Die(6); break;
         case CLERIC: temp += Roll_Die(8); break;
         case DRUID: temp += Roll_Die(8); break;
         case FIGHTER: temp += Roll_Die(10); break;
         case MONK: temp += Roll_Die(8); break;
         case PALADIN: temp += Roll_Die(10); break;
         case RANGER: temp += Roll_Die(8); break;
         case ROGUE: temp += Roll_Die(6); break;
         case SORCERER: temp += Roll_Die(4); break;
         case WIZARD: temp += Roll_Die(4); break;
       }

       temp += con_mod;
       // racial mods
       if (race == DWARF) temp += 1;
       else if (race == ELF) temp -=1;
       else if (race == GNOME) temp += 1;

       if (temp < 1) temp = 1;
       hit_points += temp;

       // get base attack bonus and saving throws
       Get_Base_Attack_Bonus();
       Get_Saving_Throw();

       // mark in check box on the main page
       // all of the classes we have
       // also update number of levels in this
       // class on main page
       switch ( new_class )
       {
          case BARBARIAN: document.main.barbarian_class.checked = true;
                          document.main.barbarian_level.selectedIndex = class_levels[BARBARIAN] - 1;
                          break;
          case BARD:      document.main.bard_class.checked = true;
                          document.main.bard_level.selectedIndex = class_levels[BARD] - 1;
                          break;
          case CLERIC:    document.main.cleric_class.checked = true;
                          document.main.cleric_level.selectedIndex = class_levels[CLERIC] - 1;
                          break;
          case DRUID:     document.main.druid_class.checked = true;
                          document.main.druid_level.selectedIndex = class_levels[DRUID] - 1;
                          break;
          case FIGHTER:   document.main.fighter_class.checked = true;
                          document.main.fighter_level.selectedIndex = class_levels[FIGHTER] - 1;
                          break;
          case MONK:      document.main.monk_class.checked = true;
                          document.main.monk_level.selectedIndex = class_levels[MONK] - 1;
                          break;
          case PALADIN:   document.main.paladin_class.checked = true;
                          document.main.paladin_level.selectedIndex = class_levels[PALADIN] - 1;
                          break;
          case RANGER:    document.main.ranger_class.checked = true;
                          document.main.ranger_level.selectedIndex = class_levels[RANGER] - 1;
                          break;
          case ROGUE:     document.main.rogue_class.checked = true;
                          document.main.rogue_level.selectedIndex = class_levels[ROGUE] - 1;
                          break;
          case SORCERER:  document.main.sorcerer_class.checked = true;
                          document.main.sorcerer_class.selectedIndex = class_levels[SORCERER] - 1;
                          break;
          case WIZARD:    document.main.wizard_class.checked = true;
                          document.main.wizard_class.selectedIndex = class_levels[WIZARD] - 1;
                          break;
       }



       level_up_win.close();
    }    // end of the Level Up function





    // This function displays the level up window.
    function Display_Level_Up()
    {

        if ( intelligence == 0)
        {
           alert('Please create a character first.');
           return;
        }

        level_up_win = open('', 'Level_Up', min_feature);

        level_up_win.document.writeln('<center>');
        level_up_win.document.writeln('<font size=+1>');
        level_up_win.document.writeln('Level Up<br><br>');
        level_up_win.document.writeln('</font>');
        level_up_win.document.writeln('Please select the class in which you would like to gain a level.<br><br>');
        level_up_win.document.writeln('<form name=level_up>');
        level_up_win.document.writeln('Class: ');
        level_up_win.document.writeln('<select name=new_class>');
        level_up_win.document.writeln('<option>Barbarian</option>');
        level_up_win.document.writeln('<option>Bard</option>');
        level_up_win.document.writeln('<option>Cleric</option>');
        level_up_win.document.writeln('<option>Druid</option>');
        level_up_win.document.writeln('<option>Fighter</option>');
        level_up_win.document.writeln('<option>Monk</option>');
        level_up_win.document.writeln('<option>Paladin</option>');
        level_up_win.document.writeln('<option>Ranger</option>');
        level_up_win.document.writeln('<option>Rogue</option>');
        level_up_win.document.writeln('<option>Sorcerer</option>');
        level_up_win.document.writeln('<option>Wizard</option>');
        level_up_win.document.writeln('</select>');
        level_up_win.document.writeln('<br><br>');
        level_up_win.document.writeln('<input type=button value="Level Up" onClick="window.opener.Level_Up()">');
        level_up_win.document.writeln('<input type=button value="Close" onClick="window.close()">');
        level_up_win.document.writeln('</form>');
        level_up_win.document.writeln('</center>');

        level_up_win.document.close();
        level_up_win.focus();
    }



   
    // This function creates a window and displays a text
    // box, along with instructions on how to load character data.
    function Display_Load_Character()
    {
       save_win = open('', 'Load', min_feature);
       save_win.document.writeln('<font size=+1>');
       save_win.document.writeln('Load Character<br><br>');
       save_win.document.writeln('</font>');
       save_win.document.writeln('To load a previously created character, copy/paste the ');
       save_win.document.writeln('character data into the text box below. then click <b>Load</b>.');
       save_win.document.writeln('<br><br>');
       save_win.document.writeln('<form name=load>');
       save_win.document.writeln('<textarea name=data rows=25 cols=80></textarea>');
       save_win.document.writeln('<br><br>');
       save_win.document.writeln('<input type=button value="Load" onClick="window.opener.Load_Character()"> ');
       save_win.document.writeln('<input type=button value="Close" onClick="window.close()">');
       save_win.document.writeln('</form>');

       save_win.document.close();
       save_win.focus();
    }     // end of Display_Load_Character




    // This function takes the data stored in the notes windows (notes_win)
    // and puts in a global variable called "game_notes".
    function Set_Notes()
    {
       game_notes = notes_win.document.note_form.note.value;
       notes_win.close();
    }


    // This function opens a new windows which will let the user
    // make random notes about the game.
    function Display_Notes()
    {
       notes_win = open('', 'Notes', min_feature);
       notes_win.document.writeln('Here you can make notes about your game.<br>');
       notes_win.document.writeln('For example, the names of important people,');
       notes_win.document.writeln('places to go or other reminders.<br><br>');
       notes_win.document.writeln('<form name=note_form>');
       notes_win.document.writeln('<textarea name=note rows=30 cols=60></textarea>');
       notes_win.document.writeln('<br><br>');
       notes_win.document.writeln('<input type=button value="Save" onclick="window.opener.Set_Notes()"> ');
       notes_win.document.writeln('<input type=button value="Cancel" onclick="window.close()">');
       notes_win.document.writeln('</form>');
       notes_win.document.note_form.note.value = game_notes;
    }

    // Thus begins the help windows. They are in order
    // of appearance on the main window.
    // In the case of duplicate help buttins, the first
    // determines the order.
    function Display_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('The Display Empty Sheet button opens ');
       newwin.document.writeln('a new window with a blank character sheet.');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('The Display Character button also opens a ');
       newwin.document.writeln('new window with a character sheet. However, ');
       newwin.document.writeln('the Display Character button fills in the ');
       newwin.document.writeln('character sheet with your character ');
       newwin.document.writeln('stats, scores and equipment.<br><br>');
      
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }

    function Name_Help()
    {
        newwin = open('', 'Help', min_feature);
        newwin.document.writeln('<center>');
        newwin.document.writeln('Your Name is your character name while in ');
        newwin.document.writeln('the DnD game. Clicking on the ');
        newwin.document.writeln('Random Name button causes the generator to suggest ');
        newwin.document.writeln('a name for your character.<br>');
        newwin.document.writeln('On the other hand, your ');
        newwin.document.writeln('Player Name is your actual name in real life.');
        newwin.document.writeln('<br><br>');
        newwin.document.writeln('<form>');
        newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
        newwin.document.writeln('</form>');
        newwin.document.writeln('</center>');
    }

    function Race_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('Your race determines what species you are. ');
       newwin.document.writeln('You can select from any of the standard DnD ');
       newwin.document.writeln('races. Each one has certain advantages and ');
       newwin.document.writeln('draw backs. For example, Humans are a good ');
       newwin.document.writeln('over-all character. Elves are usually quick ');
       newwin.document.writeln('but not so tough. Dwarves and Gnomes are ');
       newwin.document.writeln('small and sturdy. Orcs are strong, but usually' );
       newwin.document.writeln('considered dumb. Halflings are small and weak, but ');
       newwin.document.writeln('small and hard to find. Your race will play a role ');
       newwin.document.writeln('in how you are viewed by others in the DnD world.');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Starting_Class_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('Your starting class determines what sort of ');
       newwin.document.writeln('proffesion or life you lead when you start the ');
       newwin.document.writeln('game. Each class has strengths and weaknesses to ');
       newwin.document.writeln('to consider. Barbarians, fighters, monks and ');
       newwin.document.writeln('paladins are good melee fighters. Rangers, rogues ');
       newwin.document.writeln('and sorcerers and wizards are better at long ');
       newwin.document.writeln('ranges. Clerics are good spell casters and healers ');
       newwin.document.writeln('bards are good charmers. Druids are at home in the ');
       newwin.document.writeln('wild, but do not always work well in cities.<br><br>'); 
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Class_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('When you gain a level of experience, you have ');
       newwin.document.writeln('the option of branching out to different classes ');
       newwin.document.writeln('or life styles. Each class has its advantages ');
       newwin.document.writeln('and disadvantages. Some quests start at this ');
       newwin.document.writeln('more advanced stage of development. If you wish ');
       newwin.document.writeln('to be more diverse at the beginning of the quest ');
       newwin.document.writeln('you may wish to select more than one class here. ');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('Here, you can select which classes you have and ');
       newwin.document.writeln('how many levels (experience) you have in each. ');
       newwin.document.writeln('At the bottom of the chart is a Total Level ');
       newwin.document.writeln('counter to show your over all level. Your ');
       newwin.document.writeln('Dungeon Master will usually tell you at which over-all');
       newwin.document.writeln('level you will start.<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }



    function Alignment_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('Your alignment determines how your character ');
       newwin.document.writeln('acts. That is, if you are good, indifferent or ');
       newwin.document.writeln('bad. Your alignment is usually a general guide ');
       newwin.document.writeln('line in how you react to given situations. ');
       newwin.document.writeln('For example, a good character usually will not ');
       newwin.document.writeln('steal or kill without a good reason. An evil ');
       newwin.document.writeln('character is out for self gain or the gain of ');
       newwin.document.writeln('another evil creature. Neutral people are often ');
       newwin.document.writeln('indifferent to the causes of others, enjoying ');
       newwin.document.writeln('their own freedom.<br>');
       newwin.document.writeln('Lawful alignments try to follow the rules, ');
       newwin.document.writeln('pay their taxes and keep their word. Choatic ');
       newwin.document.writeln('characters are less predictable and do what ');
       newwin.document.writeln('they wish at the time.<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }



    function Religion_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('Your religion usually plays a minor role in your ');
       newwin.document.writeln('quest. Unless, you are a paladin or cleric.');
       newwin.document.writeln('You can usually select any religion you wish, ');
       newwin.document.writeln('however, the god of your choice should be of ');
       newwin.document.writeln('a simular alignment as your character. Especially ');
       newwin.document.writeln('in the case of clerics and paladins. For example: ');
       newwin.document.writeln('Pelor is a good god (god of the sun). Evil players ');
       newwin.document.writeln('are unlikely to worship him. Also, non-elves are ');
       newwin.document.writeln('not likely to worship Corellon Larethian, the god ');
       newwin.document.writeln('of the elves.<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }



    function Ability_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('Your ability scores are randomly determined, ');
       newwin.document.writeln('usually by dice rolls. In this case, the ');
       newwin.document.writeln('generator rolls the scores for you.');
       newwin.document.writeln('If you wish, you can roll your stats with real dice and ');
       newwin.document.writeln('manually enter the scores by clicking "Manually enter Ability Scores".'); 
       newwin.document.writeln('<br>Each score ');
       newwin.document.writeln('will be in the range of 3 (really poor) to ');
       newwin.document.writeln('18 (very good), with 10 being average.');
       newwin.document.writeln('Each ability score shows how good (or bad) you ');
       newwin.document.writeln('are in a given field. Strength determines your ');
       newwin.document.writeln('muscluar ability, dexterity is your speed and ');
       newwin.document.writeln('hand-eye cordination. Constitution is how tough ');
       newwin.document.writeln('you are. Your intelligence determines how well ');
       newwin.document.writeln('you learn new things. Wisdom is an indicater of ');
       newwin.document.writeln('how aware you are of the given situation and ');
       newwin.document.writeln('charisma determines how well you interact with ');
       newwin.document.writeln('others.<br><br>');
       newwin.document.writeln('Your ability modifier is an indication of where ');
       newwin.document.writeln('you stand compared to an average person. A minus ');
       newwin.document.writeln('score is below average and a positive score is ');
       newwin.document.writeln('above the norm.<br>');
       newwin.document.writeln('You can swap any ability score with any other by ');
       newwin.document.writeln('clicking the "Swap Ability Scores" button. This will ');
       newwin.document.writeln('bring up a new window. In this window, you can select ');
       newwin.document.writeln('which of your rolled scores will be assigned to which ');
       newwin.document.writeln('abilities.<br><br>');
       newwin.document.writeln('The arrows on either side of the ability score boxes ');
       newwin.document.writeln('are used to added bonus ability score points. Any character ');
       newwin.document.writeln('of level 4 or above receives one or more extra ability points. ');
       newwin.document.writeln('These extra points can be added to any of the six ability scores. ');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Bonus_Ability_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('For every four levels of experience you gain, you ');
       newwin.document.writeln('get a bonus ability point. This point can be added ');
       newwin.document.writeln('to any of the six ability scores.<br>');
       newwin.document.writeln('If you are generating a character who has a total ');
       newwin.document.writeln('level of four or more, you will have the option of ');
       newwin.document.writeln('placing one or more bonus ability points. These ');
       newwin.document.writeln('points can be added (or subtracted) from the ');
       newwin.document.writeln('ability score table using the arrows next to ');
       newwin.document.writeln('the score boxes above.<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Skill_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('Your skills are talents you have picked up in ');
       newwin.document.writeln('the course of your adventuring days. Selecting ');
       newwin.document.writeln('skills allows you to perform tasks or become ');
       newwin.document.writeln('better at certain actions. Each class has ');
       newwin.document.writeln('traits that make them better at some skills and ');
       newwin.document.writeln('worse at others. For example, rogues have a ');
       newwin.document.writeln('wide varity of skills to draw on, while a ');
       newwin.document.writeln('fighter focuses on a narrower range of skills.');
       newwin.document.writeln('<br>');
       newwin.document.writeln('There are two types of skills you can select. ');
       newwin.document.writeln('These are your native class skills (<font color=green>green</font>), the ones that ');
       newwin.document.writeln('you can learn easily. The second is called ');
       newwin.document.writeln('cross-class skills (<font color=blue>blue</font>), which are harder to learn and ');
       newwin.document.writeln('require two skill points for each new rank (or ');
       newwin.document.writeln('advancement) in the skill.<br>');
       newwin.document.writeln('Skills are futher broken into Trained and Untrained ');
       newwin.document.writeln('categories. An untrained skill is one that anyone can use ');
       newwin.document.writeln('even without skill ranks. A trained skill, to be used, requires ');
       newwin.document.writeln('at least one skill rank. Trained skills are marked with (T) ');
       newwin.document.writeln('and untrained skills with an (UT).<br>');
       newwin.document.writeln('A character has a max number of skill points that he/she ');
       newwin.document.writeln('may put into a skill. You may put up to three skill ranks ');
       newwin.document.writeln('plus your total level into native skills. Cross skills can ');
       newwin.document.writeln('have half this number.<br>');
       newwin.document.writeln('Because some feats add skill bonuses on top of the ranks, it ');
       newwin.document.writeln('is a good idea to select your skills before selecting feats.<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Feat_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('A feat is a special ability that your character ');
       newwin.document.writeln('can perform. These are usually powerful or ');
       newwin.document.writeln('special acts. Each player starts out with one ');
       newwin.document.writeln('feat point and some classes/races get more. ');
       newwin.document.writeln('Many feats require that you have a high ');
       newwin.document.writeln('ability score or another previously taken feat.');
       newwin.document.writeln('You gain at least one new feat point for every ');
       newwin.document.writeln('three levels of experience.<br><br>');
       newwin.document.writeln('Fighters get their own special set of feats. The number ');
       newwin.document.writeln('of Fighter Feats you get are displayed on the Feats page.');
       newwin.document.writeln('Feats that a Fighter may pick using these extra feats are marked ');
       newwin.document.writeln('with a "(Fighter Bonus Feat)" tag.<br>');
       newwin.document.writeln('Wizards also get their own special feats, ');
       newwin.document.writeln('which can be selected using wizard bonus ');
       newwin.document.writeln('feats. These feats are marked with a "(Wizard Bonus Feat)" lable.');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Bonus_Feat_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('Some classes receive extra feat points, which can be ');
       newwin.document.writeln('used to purchase any number of feats. Other classes ');
       newwin.document.writeln('are granted special feat points which may be used only to ');
       newwin.document.writeln('choose between two feats. Monks and Rangers both have choices ');
       newwin.document.writeln('to make (feat wise) which will determine their speciality in combat. ');
       newwin.document.writeln('The Bonus Feat window will allow you to make these choices for your ');
       newwin.document.writeln('Monk or Ranger.');

       newwin.document.writeln('<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Equipment_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('Your equipment is a collection of items, weapons ');
       newwin.document.writeln('and armor you are taking with you on your ');
       newwin.document.writeln('adventure. Most equipment has a cost, displayed ');
       newwin.document.writeln('in the equipment window in gold coins.');
       newwin.document.writeln('Most equipment also has a special characteristic ');
       newwin.document.writeln('which is also listed. For example, a longsword ');
       newwin.document.writeln('will hit a target, doing the damage of one 8 sided ');
       newwin.document.writeln('die roll. So its bonus trait is a d8.<br>');
       newwin.document.writeln('Armor bonuses are the amount of protection ');
       newwin.document.writeln('given in combat, showing how hard it is to hit ');
       newwin.document.writeln('you in combat.<br>');
       newwin.document.writeln('Other equipment is given a weight, which may ');
       newwin.document.writeln('become important if you wish to carry 20 barrels.');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('You can now set the amount of money your character has ');
       newwin.document.writeln('by entering the amount in the Money box, then clicking ');
       newwin.document.writeln('the "Set Money to This Value" button.<br>');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('You may now select masterwork weapons and armor.');
       newwin.document.writeln('This is done by clicking the forward and back arrows under ');
       newwin.document.writeln('the Masterwork section of the Equipment window. This applies to weapons ');
       newwin.document.writeln('and armor only.<br> Masterwork weapons cost an extra 300 gold and armor costs ');
       newwin.document.writeln('an extra 150 gold per item. Bolts and arrows are an extra ');
       newwin.document.writeln('6 gold per bolt/arrow.<br>');
       newwin.document.writeln('You can buy any mixture of regular and masterwork items.<br>');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Language_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('The languages you can select are based on a ');
       newwin.document.writeln('number of your characteristics. Your intelligence ');
       newwin.document.writeln('determines how many languges you can learn at ');
       newwin.document.writeln('the start of the game. Your race and class will ');
       newwin.document.writeln('determine which languages you can learn. ');
       newwin.document.writeln('For example, only druids may learn druidic. ');
       newwin.document.writeln('You should probably always have common and one ');
       newwin.document.writeln('other language, such as elven, dwarven or orc.<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }

    function Spell_Help()
    {
        newwin = open('', 'Help', min_feature);
        newwin.document.writeln('<center>');
        newwin.document.writeln('If you are an arcane spell caster, such as a bard, a ');
        newwin.document.writeln('sorcerer or a wizard, you may select your spells from ');
        newwin.document.writeln('the "Select Spells" window.<br>');
        newwin.document.writeln('Bards and sorcerer spells are listed at the top of the ');
        newwin.document.writeln('window. Clicking on the check box next to the spell will ');
        newwin.document.writeln('select that spell. Clicking the box again will remove that ');
        newwin.document.writeln('spell from the one you can cast. If you do not have all of ');
        newwin.document.writeln('the prerequistes for the spell, the spell will not be selected.');
        newwin.document.writeln('<br><br>');
        newwin.document.writeln('Wizards may choose a school in which to specialize. This is ');
        newwin.document.writeln('done by choosing a special school and another school (or schools) ');
        newwin.document.writeln('to give up. A wizard may not learn spells from a prohibited school.');
        newwin.document.writeln('Wizard spells are displayed at the bottom of the spell selection page.');
        newwin.document.writeln("<br>Changing a wizard's specialization resets his/her spell list.");
        newwin.document.writeln('<br><br>');
        newwin.document.writeln('<form>');
        newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
        newwin.document.writeln('</form>');
        newwin.document.writeln('</center>');
    }


    function Save_Load_Help()
    {
        newwin = open('', 'Help', min_feature);
        newwin.document.writeln('<center>');
        newwin.document.writeln('Since JavaScript does not allow data to be saved directly to ');
        newwin.document.writeln('the hard drive (for security reasons); this is my work around for ');
        newwin.document.writeln('saving characters for later use.<br><br>');
        newwin.document.writeln('Once you have finished creating a character, click on the ');
        newwin.document.writeln('<b>Save Character</b> button. This will open a new window, with ');
        newwin.document.writeln('a text box. Your character data will be displayed in the text box. ');
        newwin.document.writeln('Highlight the text/data with your mouse and copy/paste the data into ');
        newwin.document.writeln('a text editor. This can be any text editor. Then save the file. ');
        newwin.document.writeln('<br><br>');
        newwin.document.writeln('To get your character back, open the text file you previously saved. ');
        newwin.document.writeln('In the Character Generator, click the <b>Load Character</b> button. ');
        newwin.document.writeln('Copy/Paste the text/data from the file into the text box in the Load ');
        newwin.document.writeln('Character window of the character generator. Lastly, click the ');
        newwin.document.writeln('<b>Load</b> button in the character generator.');
        newwin.document.writeln('<br><br>');
        newwin.document.writeln('Please note that your character should be <b>finished</b> before ');
        newwin.document.writeln('you save your character. You will not be able to add new skills, feats ');
        newwin.document.writeln('or spells when you re-load.');
        newwin.document.writeln('<br><br>');
        newwin.document.writeln('<form>');
        newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
        newwin.document.writeln('</form>');
        newwin.document.writeln('</center>');
    }


    function Level_Up_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('The Character Generator allows you to save and load your ');
       newwin.document.writeln('characters. It now also allows you to level up a character ');
       newwin.document.writeln('that has already been created.');
       newwin.document.writeln('This allows you to make changes to your character using the ');
       newwin.document.writeln('frame work already in place.<br><br>');
       newwin.document.writeln('Click the <b>Level Up</b> button on the main page. This will ');
       newwin.document.writeln('open a new window. Select the class in which you would like to ');
       newwin.document.writeln('gain a level. Then click the <b>Level Up</b> button in the ');
       newwin.document.writeln('new window. Your new skill points, feats, ability points, base ');
       newwin.document.writeln('attack bonus, hit points and saving throws will be calculated ');
       newwin.document.writeln('automatically.');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Notes_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('It is often helpful to keep various notes about the ');
       newwin.document.writeln('current game world in which your character lives. ');
       newwin.document.writeln('To help with this, you can click on the <b>Extra Notes</b> ');
       newwin.document.writeln('button and add any notes you like. These notes will be ');
       newwin.document.writeln('saved and can be viewed again at any time by clicking on ');
       newwin.document.writeln('the <b>Extra Notes</b> button again.');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');
    }


    function Equip_Help()
    {
       newwin = open('', 'Help', min_feature);
       newwin.document.writeln('<center>');
       newwin.document.writeln('The armor your character will wear is more than just ');
       newwin.document.writeln('a fashion statement. It is a form of protection. Use ');
       newwin.document.writeln('the <b>Equip Character</b> button to select what ');
       newwin.document.writeln('armor or shields your character will use.');
       newwin.document.writeln('<br><br>');
       newwin.document.writeln('<form>');
       newwin.document.writeln('<input type=button value="Close" onClick="window.close()">');
       newwin.document.writeln('</form>');
       newwin.document.writeln('</center>');

    }


// Random name generator by David A. Wheeler

// List of possible vowels; duplicates increase the likelihood of selection:
var vowels = new Array(
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"a", "e", "i", "o", "u",
"ae", "ai", "ao", "au", "aa",
"ea", "eo", "eu", "ee",
"ia", "io", "iu", "ii",
"oa", "oe", "oi", "ou", "oo",
"eau",
"'",
"y"  // Occasionally, 'Y' will be duplicated as a vowel and a consonant.
     // That's so rare that we won't worry about it.
)

// List of possible consonants.
// The second parameter indicates if the consonant can occur
// at the beginning or ending of a name. It's a binary value xy,
// where x is the beginning, y is the ending, and 0=no, 1=yes.
// Consonants can always appear in the "middle".  Thus:
//    0 : Neither beginning or ending (vowels must surround it)
//    1 : Ending, not beginning
//    2 : Beginning, not ending
//    3 : Beginning and ending (i.e. it can be anywhere)
// Be careful when editing this - if you forget a comma, you'll get
// mysterious errors and "undefine" results in names, since Javascript
// doesn't have good error-catching facilities.

var consonants = new Array(
["b", 3],  ["c", 3],  ["d", 3],  ["f", 3],  ["g", 3],  ["h", 3], 
["j", 3],  ["k", 3],  ["l", 3],  ["m", 3],  ["n", 3],  ["p", 3], 
["qu", 2],  ["r", 3], ["s", 3],  ["t", 3],  ["v", 3],  ["w", 3],
["x", 3],  ["y", 3],  ["z", 3], 
// Blends, sorted by second character:
["sc", 3],
["ch", 3],  ["gh", 3],  ["ph", 3], ["sh", 3],  ["th", 3], ["wh", 2],
["ck", 1],  ["nk", 1],  ["rk", 1], ["sk", 3],  ["wk", 0],
["cl", 2],  ["fl", 2],  ["gl", 2], ["kl", 2],  ["ll", 2], ["pl", 2], ["sl", 2],
["br", 2],  ["cr", 2],  ["dr", 2],  ["fr", 2],  ["gr", 2],  ["kr", 2], 
["pr", 2],  ["sr", 2],  ["tr", 2],
["ss", 1],
["st", 3],  ["str", 2],
// Repeat some entries to make them more common.
["b", 3],  ["c", 3],  ["d", 3],  ["f", 3],  ["g", 3],  ["h", 3], 
["j", 3],  ["k", 3],  ["l", 3],  ["m", 3],  ["n", 3],  ["p", 3], 
["r", 3], ["s", 3],  ["t", 3],  ["v", 3],  ["w", 3],
["b", 3],  ["c", 3],  ["d", 3],  ["f", 3],  ["g", 3],  ["h", 3], 
["j", 3],  ["k", 3],  ["l", 3],  ["m", 3],  ["n", 3],  ["p", 3], 
["r", 3], ["s", 3],  ["t", 3],  ["v", 3],  ["w", 3],
["br", 2],  ["dr", 2],  ["fr", 2],  ["gr", 2],  ["kr", 2]
)


// Return a random value between minvalue and maxvalue, inclusive,
// with equal probability.

function rolldie(minvalue, maxvalue) {
var result;
while (1) {
 result = Math.floor(Math.random() * (maxvalue-minvalue+1)+minvalue);
 if ((result >= minvalue) && (result <= maxvalue)) { return result;}
}
}

// Create a random name.  It must have at least between minsyl and maxsyl
// number of syllables (inclusive).

function RandomName(minsyl, maxsyl) {
var data = "";
var genname = "";         // this accumulates the generated name.
var leng = rolldie(minsyl, maxsyl); // Compute number of syllables in the name
var isvowel = rolldie(0, 1); // randomly start with vowel or consonant
for (var i = 1; i <= leng; i++) { // syllable . Start is 1 (not 0)
 if (isvowel) {
   data = vowels[rolldie(0, vowels.length - 1)];
   // Don't allow ' at beginning or end of name; change it to "e".
   if ( (data == "'") && ((i == 1) || (i == leng))) { data = "e";};
   genname += data;
 } else {
   do {
     data = consonants[rolldie(0, consonants.length - 1)];
     // Check if this consonant can occur in this syllable.
     if ( i == 1) { // first syllable.
       if (data[1] & 2) {break;}
     } else if (i == leng) { // last syllable.
       if (data[1] & 1) {break;}
     } else {break;}; // Middle syllable, any consonant allowed.
   } while (1)
   genname += data[0];
 }
 isvowel = 1 - isvowel; // Alternate between vowels and consonants.
}
// Initial caps:
genname = (genname.slice(0,1)).toUpperCase() + genname.slice(1);
return genname;
}


// This function calls David's RandomName(). This is just a wrapper which gets
// the new name and places the value onto the character sheet.
// Jesse <slicer69@hotmail.com>
function Get_RandomName()
{
    var first_name = "";
    var last_name = "";
    first_name = RandomName(2, 4);
    last_name = RandomName(2, 4);
    document.main.character_name.value = first_name + " " + last_name;
}



