// Dragon Code Builder JavaScript - Version 1.26.13 - Last modified: 12/02/04
// Copyright ©2006 Timoran J. Synkral. All rights reserved.
// This product is protected under the Free Improvement License (FIL). It is neither proprietary
// nor public domain. Use is subject to the terms and conditions of the FIL, which are included
// with the product. Do not copy or redistribute this product unless it is specifically permitted
// by the FIL. No guarantees are made as to this product's usability and it is provided as-is
// without warranties express or implied. Do not use this product for critical applications such
// as life support.

// Author: Timoran J. Synkral - Timoran .at. GadgetScope.com

// Global variables

var dcver = "2.6";                        // Corresponding Dragon Code Version
var dcburl = "http://timoran.gadgetscope.com/dc2.phtml";
var dcurl = "http://www.dragoncode.org/";
var dcdurl = "http://www.dragon-realms.com/?page=decoder";
var mybodclr = "Cna";                     // Body color
var mygen = "";                           // Custom gender
var mylen = "";                           // Custom length
var mywid = "";                           // Custom width
var mywei = "";                           // Custom weight
var myage = "";                           // Custom age
var myfruit = "";                         // Custom fruit
var mynland = "";                         // Custom native land
var mymstat = "";                         // Custom mating status
var myoff = "";                           // Custom offspring
var myhsize = "";                         // Custom hoard size
var mymph = "";                           // Custom monetary philosophy
var mydiet = "";                          // Custom diet
var myreal = "";                          // Custom reality index
var myacti = "";                          // Custom activity
var myhum = "";                           // Custom humor index
var mysoc = "";                           // Custom social life
var myubi = "";                           // Custom ubiquity
var myirr = "";                           // Custom irritability
var mymag = "";                           // Custom magic ability
var mypsy = "";                           // Custom psychic power
var mytek = "";                           // Custom technology
var myhug = "";                           // Custom huggability
var myfrd = "";                           // Custom dragon friend

function verifyreset() {
  if (confirm('Are you sure you want to reset the form and start over?')) {
    clrspelist();                         // Clear species forms list
    clrapplist();                         // Clear appendage list
    clrbwlist();                          // Clear breath weapon list
    clrsklist();                          // Clear skin type list
    clrclrlist();                         // Clear color list
    mybodclr = "Cna";                     // Clear body color
    mygen = "";                           // Clear custom gender
    mylen = "";                           // Clear custom length
    mywid = "";                           // Clear custom width
    mywei = "";                           // Clear custom weight
    myage = "";                           // Clear custom age
    myfruit = "";                         // Clear custom fruit
    mynland = "";                         // Clear custom native land
    mymstat = "";                         // Clear custom mating status
    myoff = "";                           // Clear custom mating status
    myhsize = "";                         // Clear custom hoard size
    mymph = "";                           // Clear custom monetary philosophy
    mydiet = "";                          // Clear custom diet
    myreal = "";                          // Clear custom reality index
    myacti = "";                          // Clear custom activity
    myhum = "";                           // Clear custom humor index
    mysoc = "";                           // Clear custom social life
    myubi = "";                           // Clear custom ubiquity
    myirr = "";                           // Clear custom irritability
    mymag = "";                           // Clear custom magic ability
    mypsy = "";                           // Clear custom psychic power
    mytek = "";                           // Clear custom technology
    myhug = "";                           // Clear custom huggability
    myfrd = "";                           // Clear custom dragon friendship
    return true;
  }
  else {
    return false;
  }
}

function computedc() {
  var outstr;
  var dcb = document.dcbuilder;           // Shortcut to reduce code size and typing
  outstr = "DC2.";                        // Start with Dragon Code level 2 declaration
  separator = " ";                        // Separator between elements


  var spestr = "";                        // String of forms
  var speslash = false;                   // Boolean: Add slash


                                          // Collect species from list
  var splooplen = dcb.spelist.length - 1;
  if (dcb.stable.checked && dcb.spelist.options[0].value != "SPna") {
    var speseldex = dcb.spelist.selectedIndex;
    if (speseldex < 0) {
      dcb.spelist.selectedIndex = 0;
      speseldex = dcb.spelist.selectedIndex;
    }
    spestr = dcb.spelist.options[speseldex].value;
  }
  if (dcb.shapshif.checked || dcb.stable.checked) {
    spestr += "~";
  }
  if (dcb.spelist.options[0].value != "SPna") {
    for (al = 0; al <= splooplen; al++) {
      var speval = dcb.spelist.options[al].value;
      if (!dcb.stable.checked || (dcb.stable.checked && !dcb.spelist.options[al].selected)) {
        if (speslash) {
          spestr += "/";
        }
        else {
          speslash = true;
        }
        spestr += speval;
      }
    }
  }
  if (spestr) {
    outstr += spestr;
  }
  else {
    // Actually, don't put an "unknown" symbol if this is omitted.
    // The spec says to just leave a space, which will be done anyway.
  }
                                          // End species
  // ----------------------------------------------------------------
                                          // Begin gender
  var gdrin = dcb.gender.options[dcb.gender.selectedIndex].value;
  var gdrmn = dcb.genderment.options[dcb.genderment.selectedIndex].value;
  var gdrto = dcb.genderchg.options[dcb.genderchg.selectedIndex].value;
                                          // Strip out the G
  gdrin = gdrin.substring(1,gdrin.length);
                                          // Read gender and assign it
  if (gdrin != "na" || mygen) {           // This will always execute if there is free text
    outstr += separator + "G";
    if (gdrin != "na" || dcb.genderfree[0].checked) {
      if (gdrin != "na") {
        outstr += gdrin;
      }
      if (dcb.genderfree[0].checked && mygen) {
        outstr += "\"" + mygen + "\"";
      }

      if (gdrmn != "na") {
        outstr += "/" + gdrmn;
        if (dcb.genderfree[1].checked && mygen) {
          outstr += "\"" + mygen + "\"";
        }
      }
      else if (dcb.genderfree[1].checked && mygen) {
        outstr += "/" + "\"" + mygen + "\"";
      }

      if (gdrto != "na") {
        outstr += ">" + gdrto;
        if (dcb.genderfree[2].checked && mygen) {
          outstr += "\"" + mygen + "\"";
        }
      }
      else if (dcb.genderfree[2].checked && mygen) {
        outstr += ">" + "\"" + mygen + "\"";
      }
    }
  }
                                          // End gender
  // ----------------------------------------------------------------
                                          // Begin length
  var lenin = dcb.lngth.options[dcb.lngth.selectedIndex].value;
                                          // Read length and assign it
  if (lenin != "Lna" || mylen) {
    if (lenin != "Lspec" && lenin != "Lna") {
      outstr += separator + lenin;
      if (mylen) {
        outstr += "\"" + mylen + "\"";
      }
    }
    else if (lenin == "Lna") {
      outstr += separator + "L\"" + mylen + "\"";
    }
    else {
      var munit = dcb.measunit.options[dcb.measunit.selectedIndex].value;
      outstr += separator + "L";
      if (mylen) {
        outstr += "\"" + mylen + "\"";
      }
      var lennput = parseFloat(dcb.measured.value);
      if (lennput) {
        outstr += lennput + munit.substring(2,munit.length);
        var lenofarm = parseFloat(dcb.lenarm.value);
        if (lenofarm) {
          outstr += lenofarm + "a";
        }
        var lenofleg = parseFloat(dcb.lenleg.value);
        if (lenofleg) {
          outstr += lenofleg + "l";
        }
        var lenofneck = parseFloat(dcb.lenneck.value);
        if (lenofneck) {
          outstr += lenofneck + "n";
        }
        var lenoftail = parseFloat(dcb.lentail.value);
        if (lenoftail) {
          outstr += lenoftail + "t";
        }
        var lenofwing = parseFloat(dcb.lenwing.value);
        if (lenofwing) {
          outstr += lenofwing + "w";
        }
      }
    }
  }
                                          // End length
  // ----------------------------------------------------------------
                                          // Begin width
  var widin = dcb.wdth.options[dcb.wdth.selectedIndex].value;
                                          // Read width and assign it
  if (widin != "Wna") {
    outstr += separator + widin;
  }
  if (mywid) {
    if (widin == "Wna") {
      outstr += separator + "W";
    }
    outstr += "\"" + mywid + "\"";
  }

                                          // End width
  // ----------------------------------------------------------------
                                          // Begin weight
  var weiin = dcb.wght.options[dcb.wght.selectedIndex].value;
                                          // Read weight and assign it
  if (weiin != "Tna" || mywei) {
    if (weiin != "Tspec" && weiin != "Tna") {
      outstr += separator + weiin;
      if (mywei) {
        outstr += "\"" + mywei + "\"";
      }
    }
    else if (weiin == "Tna") {
      outstr += separator + "T\"" + mywei + "\"";
    }
    else {
      var wunit = dcb.weiunit.options[dcb.weiunit.selectedIndex].value;
      outstr += separator + "T" 
      if (mywei) {
        outstr += "\"" + mywei + "\"";
      }
      var weinput = parseFloat(dcb.weighed.value);
      if (weinput) {
        outstr += weinput + wunit.substring(2,wunit.length);
      }
    }
  }
                                          // End weight
  // ----------------------------------------------------------------
                                          // Begin appendages

  var appstr;                             // String of appendages
  appstr = "P";
  if (dcb.Pvar.checked) {
    appstr += "~";
  }
  if (dcb.Punk.checked) {
    appstr += "?";
  }
  if (dcb.appends.options[0].value != "Pna") {
                                          // The placeholder is not present, continue
                                          // Collect appendages from list
    var applooplen = dcb.appends.length - 1;
    for (pl = 0; pl <= applooplen; pl++) {
      var inval = dcb.appends.options[pl].value;
                                          // Strip out the P
      inval = inval.substring(1,inval.length);
      appstr += inval;
    }
  }
  if (appstr != "P") {
    outstr += separator + appstr;
  }

                                          // End appendages
  // ----------------------------------------------------------------
                                          // Begin skin

  var skstr = "";                         // String of skin types
  var skinin = dcb.bodyskintype.options[dcb.bodyskintype.selectedIndex].value;
                                          // Read skin type and assign it
  if (skinin != "Skna") {
    if (skinin == "Skspec" && dcb.bskother.value) {
      skinin = "Sk\"" + dcb.bskother.value + "\"";
    }
    else if (skinin == "Skspec") {
      skinin = "Sk?";
    }
    if (dcb.sktypes.options[0].value != "Kna") {
                                          // The placeholder is not present, continue
                                          // Collect skin types from list
      var sklooplen = dcb.sktypes.length - 1;
      for (kl = 0; kl <= sklooplen; kl++) {
        var inval = dcb.sktypes.options[kl].value;
        skstr += inval;
      }
    }

    outstr += separator + skinin;
    if (skstr) {
      outstr += skstr;
    }
  }
                                          // End skin
  // ----------------------------------------------------------------
                                          // Begin color

  var clrstr = "";                        // String of colors
  var clrin = mybodclr;
                                          // Read color and assign it
  if (clrin != "Cna" && clrin) {
    if (dcb.clrparts.options[0].value != "Cna") {
                                          // The placeholder is not present, continue
                                          // Collect colors from list
      var cllooplen = dcb.clrparts.length - 1;
      for (cl = 0; cl <= cllooplen; cl++) {
        var clval = dcb.clrparts.options[cl].value;
        clrstr += clval;
      }
    }

    outstr += separator + clrin;
    if (clrstr) {
      outstr += clrstr;
    }
  }

                                          // End color
  // ----------------------------------------------------------------
  var dcburlsec = "http://timoran.gadgetscope.com/dc2.phtml";
  // ----------------------------------------------------------------
                                          // Begin breath weapons

  var bwstr;                              // String of breath weapons
  var bwslash = false;                    // Boolean: Add slash
  bwstr = "B";

  if (!dcb.Bnone.checked) {
    if (!dcb.Bunk.checked) {
      if (!dcb.Bany.checked) {
        if (dcb.breathweps.options[0].value != "Bna") {
                                          // The placeholder is not present, continue
                                          // Collect appendages from list
          var bwlooplen = dcb.breathweps.length - 1;
          for (bl = 0; bl <= bwlooplen; bl++) {
            var inval = dcb.breathweps.options[bl].value;
                                          // Strip out the B
            inval = inval.substring(1,inval.length);
            if (bwslash) {
              bwstr += "/";
            }
            else {
              bwslash = true;
            }
            bwstr += inval;
          }
        }
      }
      else {
        bwstr = "B~";
      }
    }
    else {
      bwstr = "B?";
    }
  }
  else {
    bwstr = "B-";
  }
  if (bwstr != "B") {
    outstr += separator;
    outstr += bwstr;
  }

                                          // End breath weapons
  // ----------------------------------------------------------------
                                          // Begin age

  var agein = dcb.ages.options[dcb.ages.selectedIndex].value;
                                          // Strip out the A
  agein = agein.substring(1,agein.length);
                                          // Read age and assign it
  if (agein != "na" || myage) {
    outstr += separator + "A";
    if (agein != "na") {
      outstr += agein;
    }
    if (myage) {
      outstr += "\"" + myage + "\"";
    }
  }
                                          // End age
  // ----------------------------------------------------------------
                                          // Begin fruitiness

  var frtin = dcb.fruits.options[dcb.fruits.selectedIndex].value;
                                          // Strip out the Fr
  frtin = frtin.substring(2,frtin.length);
                                          // Read fruitiness and assign it
  if (frtin != "na" || myfruit) {
    outstr += separator + "Fr";
    if (frtin != "na") {
      outstr += frtin;
    }
    if (myfruit) {
      outstr += "\"" + myfruit + "\"";
    }
  }
                                          // End fruitiness
  // ----------------------------------------------------------------
  // Brief security check
  var pageurl = window.location.href.toLowerCase();
  if (pageurl.indexOf("timoran") < 0 && pageurl.indexOf("gadgetscope") < 0 &&
      pageurl.indexOf("http") >= 0) {
    alert("Th"+"is is not a"+"n a"+"uth"+"or"+"ized mi"+"rror. Ple"+"ase cl"+"ick O"+"K to g"+"o to the corr"+"ect si"+"te.");
    top.location.href = dcburlsec;
  }
  // ----------------------------------------------------------------
                                          // Begin native land

  var nlin = dcb.nland.options[dcb.nland.selectedIndex].value;
                                          // Strip out the N
  nlin = nlin.substring(1,nlin.length);
                                          // Read native land and assign it
  if (nlin != "na" || mynland) {
    outstr += separator + "N";
    if (nlin != "na") {
      outstr += nlin;
    }
    if (mynland) {
      outstr += "\"" + mynland + "\"";
    }
  }
                                          // End native land
  // ----------------------------------------------------------------
                                          // Begin mating status

  var mstin = dcb.mst.options[dcb.mst.selectedIndex].value;
                                          // Strip out the M
  mstin = mstin.substring(1,mstin.length);
                                          // Read mating status and assign it
  if (mstin != "na" || mymstat) {
    outstr += separator + "M";
    if (mstin != "na") {
      if (dcb.Mdist.checked) {          // Distant from mate
        outstr += " ";
      }
      outstr += mstin;
      var curmz = parseInt(dcb.mscur.value);
      if (curmz) {
        outstr += curmz;
      }
      var pastmz = parseInt(dcb.mspast.value);
      if (pastmz) {
        outstr += "|" + pastmz;
      }
      var bittmz = parseInt(dcb.msbitt.value);
      if (bittmz) {
        outstr += "*" + bittmz;
      }
      var deadmz = parseInt(dcb.msdead.value);
      if (deadmz) {
        outstr += "_" + deadmz;
      }
    }
    if (mymstat) {
      outstr += "\"" + mymstat + "\""
    }
    if (dcb.Mxx.checked) {
     outstr += "xx";
    }
    if (dcb.Mxy.checked) {
     outstr += "xy";
    }
  }
                                          // End mating status
  // ----------------------------------------------------------------
                                          // Begin offspring

  var ofsin = dcb.offspr.options[dcb.offspr.selectedIndex].value;
                                          // Strip out the O
  ofsin = ofsin.substring(1,ofsin.length);
  okidn = dcb.okidnum.value;              // Number of kids
                                          // Read offspring and assign it
  if (ofsin != "na" || myoff) {
    outstr += separator + "O";
    if (dcb.Oadopt.checked) {
      outstr += "a";
    }
    if (ofsin != "na") {
      if (ofsin == "-spec") {
        outstr += "-" + okidn;
      }
      else if (ofsin == "+spec") {
        outstr += "+" + okidn;
      }
      else {
        outstr += ofsin;
      }
    }
    if (myoff) {
      outstr += "\"" + myoff + "\"";
    }
  }
                                          // End offspring
  // ----------------------------------------------------------------
                                          // Begin hoard

  var hoain = dcb.hsize.options[dcb.hsize.selectedIndex].value;
                                          // Strip out the H
  hoain = hoain.substring(1,hoain.length);
                                          // Read hoard size and assign it
  if (hoain != "na" || myhsize) {
    outstr += separator + "H";
    if (hoain != "na") {
      outstr += hoain;
    }
    if (myhsize) {
      outstr += "\"" + myhsize + "\"";
    }
  }
                                          // End hoard
  // ----------------------------------------------------------------
                                          // Begin monetary philosophy

  var mmmin = dcb.mphil.options[dcb.mphil.selectedIndex].value;
                                          // Strip out the $
  mmmin = mmmin.substring(1,mmmin.length);
                                          // Read philosophy and assign it
  if (mmmin != "na" || mymph) {
    outstr += separator + "$";
    if (mmmin != "na") {
      outstr += mmmin;
    }
    if (mymph) {
      outstr += "\"" + mymph + "\"";
    }
  }
                                          // End monetary philosophy
  // ----------------------------------------------------------------
                                          // Begin diet

  var dietin = dcb.diet.options[dcb.diet.selectedIndex].value;
                                          // Strip out the F
  dietin = dietin.substring(1,dietin.length);
                                          // Read diet and assign it
  if (dietin != "na" || mydiet) {
    outstr += separator + "F";
    if (dietin != "na") {
      outstr += dietin;
    }
    if (mydiet) {
      outstr += "\"" + mydiet + "\""
    }
    var numfts = dcb.foodtypes.length;
    var slashfood = false;
    var numfoodused = 0;
    var actfood = "";
    for (ftl = 0; ftl <= numfts - 1; ftl++) {
      if (dcb.foodtypes.options[ftl].selected) {
        actfood = dcb.foodtypes.options[ftl].value;
        if (slashfood == true) {
          if (numfoodused <= 1 && actfood == "~") {
                                          // Don't slash this, there's only one food type
          }
          else {
            outstr += "/";
          }
          outstr += actfood;
        }
        else {
          outstr += actfood;
          slashfood = true;
        }
        numfoodused++;
      }
    }
  }
                                          // End diet
  // ----------------------------------------------------------------
                                          // Begin reality index

  var realin = dcb.reality.options[dcb.reality.selectedIndex].value;
                                          // Strip out the R
  realin = realin.substring(1,realin.length);
                                          // Read reality and assign it
  if (realin != "na" || myreal) {
    outstr += separator + "R";
    if (realin != "na") {
      outstr += realin;
    }
    if (myreal) {
      outstr += "\"" + myreal + "\"";
    }
  }
                                          // End reality index
  // ----------------------------------------------------------------
                                          // Begin activity

  var actiin = dcb.activity.options[dcb.activity.selectedIndex].value;
                                          // Strip out the Ac
  actiin = actiin.substring(2,actiin.length);
                                          // Read activity and assign it
  if (actiin != "na" || myacti) {
    outstr += separator + "Ac";
    if (actiin != "na") {
      outstr += actiin;
    }
    if (myacti) {
      outstr += "\"" + myacti + "\"";
    }
  }
                                          // End activity
  // ----------------------------------------------------------------
                                          // Begin humor index

  var humin = dcb.humor.options[dcb.humor.selectedIndex].value;
                                          // Strip out the J
  humin = humin.substring(1,humin.length);
                                          // Read reality and assign it
  if (humin != "na" || myhum) {
    outstr += separator + "J";
    if (humin != "na") {
      outstr += humin;
    }
    if (myhum) {
      outstr += "\"" + myhum + "\"";
    }
  }
                                          // End humor index
  // ----------------------------------------------------------------
                                          // Begin social life

  var socin = dcb.social.options[dcb.social.selectedIndex].value;
                                          // Strip out the S
  socin = socin.substring(1,socin.length);
                                          // Read social life and assign it
  if (socin != "na" || mysoc) {
    outstr += separator + "S";
    if (socin != "na") {
      outstr += socin;
    }
    if (mysoc) {
      outstr += "\"" + mysoc + "\"";
    }
  }
                                          // End social life
  // ----------------------------------------------------------------
                                          // Begin ubiquity

  var ubiin = dcb.ubiq.options[dcb.ubiq.selectedIndex].value;
                                          // Strip out the U
  ubiin = ubiin.substring(1,ubiin.length);
                                          // Read ubiquity and assign it
  if (ubiin != "na" || myubi) {
    outstr += separator + "U";
    if (ubiin != "na") {
      outstr += ubiin;
    }
    if (myubi) {
      outstr += "\"" + myubi + "\"";
    }
  }
                                          // End ubiquity
  // ----------------------------------------------------------------
                                          // Begin irritability

  var irrin = dcb.irrit.options[dcb.irrit.selectedIndex].value;
                                          // Strip out the I
  irrin = irrin.substring(1,irrin.length);
                                          // Read irritability and assign it
  if (irrin != "na" || myirr) {
    outstr += separator + "I";
    if (irrin != "na") {
      outstr += irrin;
      if (dcb.irrbbq.checked) {
        outstr += "#";
      }
    }
    if (myirr) {
      outstr += "\"" + myirr + "\"";
    }
  }
                                          // End irritability
  // ----------------------------------------------------------------
                                          // Begin magic ability

  var mgcin = dcb.magic.options[dcb.magic.selectedIndex].value;
  var mgcsp = dcb.magspec.value;
                                          // Strip out the V
  mgcin = mgcin.substring(1,mgcin.length);
                                          // Read magic ability and assign it
  if (mgcin != "na" || mymag) {
    outstr += separator + "V";
    if (mgcin != "na") {
      outstr += mgcin;
      if (mgcsp) {
        outstr += "[" + mgcsp + "]";
      }
    }
    if (mymag) {
      outstr += "\"" + mymag + "\"";
    }
  }
                                          // End magic ability
  // ----------------------------------------------------------------
                                          // Begin psychic power

  var psyin = dcb.psypow.options[dcb.psypow.selectedIndex].value;
  var psysp = dcb.psyspec.value;
                                          // Strip out the Q
  psyin = psyin.substring(1,psyin.length);
                                          // Read psychic power and assign it
  if (psyin != "na" || mypsy) {
    outstr += separator + "Q";
    if (psyin != "na") {
      outstr += psyin;
      if (psysp) {
        outstr += "[" + psysp + "]";
      }
    }
    if (mypsy) {
      outstr += "\"" + mypsy + "\"";
    }
  }
                                          // End psychic power
  // ----------------------------------------------------------------
                                          // Begin technology

  var tekin = dcb.tech.options[dcb.tech.selectedIndex].value;
  var teksp = dcb.tekspec.value;
                                          // Strip out the Tc
  tekin = tekin.substring(2,tekin.length);
                                          // Read technology and assign it
  if (tekin != "na" || mytek) {
    outstr += separator + "Tc";
    if (tekin != "na") {
      outstr += tekin;
      if (teksp) {
        outstr += "[" + teksp + "]";
      }
    }
    if (mytek) {
      outstr += "\"" + mytek + "\"";
    }
  }
                                          // End technology
  // ----------------------------------------------------------------
                                          // Begin huggability

  var hugin = dcb.hug.options[dcb.hug.selectedIndex].value;
                                          // Strip out the E
  hugin = hugin.substring(1,hugin.length);
                                          // Read huggability and assign it
  if (hugin != "na" || myhug) {
    outstr += separator + "E";
    if (hugin != "na") {
      outstr += hugin;
      if (dcb.hugviol.checked) {
        outstr += "#";
      }
    }
    if (myhug) {
      outstr += "\"" + myhug + "\"";
    }
  }
                                          // End huggability
  // ----------------------------------------------------------------
                                          // Begin dragon friendship

  var frdin = dcb.dfriend.options[dcb.dfriend.selectedIndex].value;
                                          // Strip out the Df
  frdin = frdin.substring(2,frdin.length);
                                          // Read DF and assign it
  if (frdin != "na" || myfrd) {
    outstr += separator + "Df";
    if (frdin != "na") {
      outstr += frdin;
    }
    if (myfrd) {
      outstr += "\"" + myfrd + "\"";
    }
  }
                                          // End dragon friendship
  // ----------------------------------------------------------------
                                          // Send the finished Dragon Code to the user
                                          // through the output text field
  var outputstr = "My Dragon Code (version "+dcver+"): "+outstr+"\n\nAbout this Dragon Code - Build your own!\n<"
  outputstr += dcburl+">";
  dcb.output.value = outputstr;
  var outhtmlstr = "My Dragon Code (version "+dcver+"): "+outstr+"<BR><BR><A HREF=\"";
  outhtmlstr += dcurl+"\">About Dragon Code</A> - <A HREF=\""+dcburl+"\">Build your own Dragon Code!</A> - <A";
  outhtmlstr += " HREF=\""+dcdurl+"\">Decoder</A>";
  dcb.outhtml.value = outhtmlstr;
}



function bar(message) {
                                          // Status bar control
  window.status = message;
  return true;
}

function custspec() {
                                          // Custom species
  var newname = prompt("Please type in the name for your species.","");
  if (newname) {
    var dcb = document.dcbuilder;
    var speclen = dcb.species.length;
    var spectoadd = new Option(newname, "sp-\"" + newname + "\"");
    dcb.species.options[speclen] = spectoadd;
    dcb.species.options[speclen].selected = true;
  }
}

function unlockmeasure() {
                                          // Jump-to for length
  var dcb = document.dcbuilder;
  if (dcb.lngth.options[dcb.lngth.selectedIndex].value == "Lspec") {
    dcb.measured.focus();
  }
}

function specmeasure() {
                                          // Set custom length
  document.dcbuilder.lngth.selectedIndex = 1;
}

function unlockweight() {
                                          // Jump-to for weight
  var dcb = document.dcbuilder;
  if (dcb.wght.options[dcb.wght.selectedIndex].value == "Tspec") {
    dcb.weighed.focus();
  }
}

function specweight() {
                                          // Set custom weight
  document.dcbuilder.wght.selectedIndex = 1;
}

  // ----------------------------------------------------------------
                                          // Begin species

function delspe() {
                                          // Delete species
  var dcb = document.dcbuilder;
  if (dcb.spelist.selectedIndex > -1) {
    if (dcb.spelist.options[dcb.spelist.selectedIndex].value != "SPna") {
      dcb.spelist.options[dcb.spelist.selectedIndex] = null;
    }
    else {
      alert("There are no forms to delete.");
    }
  }
  else {
    alert("Please select the form you want to delete.");
  }
  if (dcb.spelist.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No forms specified.", "SPna");
    dcb.spelist.options[0] = placeholder;
  }
}

function addspetolist() {
                                          // Add species
  var dcb = document.dcbuilder;
  var stringadd = "";
  var stringnice = "";                    // Used for display if short enough
  connector = "+";                        // Connector between species selections
  var spelen = (dcb.species.length - 1);  // Number of species in the list, zero-based
  var hasdragon = false;                  // Boolean: Species includes a dragon
  var hashuman = false;                   // Boolean: Species includes a human
  var hasamph = false;                    // Boolean: Species includes an amphibian
  var hasbird = false;                    // Boolean: Species includes a bird
  var hascrust = false;                   // Boolean: Species includes a crustacean
  var hasdino = false;                    // Boolean: Species includes a dinosaur
  var hasextra = false;                   // Boolean: Species includes a extraterrestrial
  var hasfish = false;                    // Boolean: Species includes a fish
  var hasins = false;                     // Boolean: Species includes a insect
  var hasleg = false;                     // Boolean: Species includes a legend
  var hasmamm = false;                    // Boolean: Species includes a mammal
  var hasmoll = false;                    // Boolean: Species includes a mollusk
  var hasmyth = false;                    // Boolean: Species includes a mythical
  var hasplant = false;                   // Boolean: Species includes a plant
  var hasrep = false;                     // Boolean: Species includes a reptile
  var hasspir = false;                    // Boolean: Species includes a spirit
  var hasund = false;                     // Boolean: Species includes an undead
  var firstdone = false;                  // Boolean: First cross-breed done,
                                          //   start adding pluses
  for (sl = 0; sl <= spelen; sl++) {
    if (dcb.species.options[sl].selected) {
                                          // Current index is selected
      var hide_pre = false;               // Hide the type prefix (simplified notation)
      var convstring = dcb.species.options[sl].value;
      var convnice = dcb.species.options[sl].text;
      var mytxt = "";                     // Free-text for current species
      if (convstring.substring(2,3) == "D") {
                                          // This is a type of dragon
        if (hasdragon) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasdragon = true;               // Use simplified notation for next dragon
        }
      }
      if (convstring.substring(2,3) == "H") {
                                          // This is a type of human
        if (hashuman) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hashuman = true;                // Use simplified notation for next human
        }
      }
      if (convstring.substring(2,3) == "A") {
                                          // This is a type of amphibian
        if (hasamph) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasamph = true;                 // Use simplified notation for next amphibian
        }
      }
      if (convstring.substring(2,3) == "B") {
                                          // This is a type of bird
        if (hasbird) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasbird = true;                 // Use simplified notation for next bird
        }
      }
      if (convstring.substring(2,3) == "C") {
                                          // This is a type of crustacean
        if (hascrust) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hascrust = true;                // Use simplified notation for next crustacean
        }
      }
      if (convstring.substring(2,3) == "S") {
                                          // This is a type of dinosaur
        if (hasdino) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasdino = true;                 // Use simplified notation for next dinosaur
        }
      }
      if (convstring.substring(2,3) == "E") {
                                          // This is a type of extraterrestrial
        if (hasextra) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasextra = true;                 // Use simplified notation for next et
        }
      }
      if (convstring.substring(2,3) == "F") {
                                          // This is a type of fish
        if (hasfish) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasfish = true;                 // Use simplified notation for next fish
        }
      }
      if (convstring.substring(2,3) == "I") {
                                          // This is a type of insect
        if (hasins) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasins = true;                  // Use simplified notation for next bird
        }
      }
      if (convstring.substring(2,3) == "L") {
                                          // This is a type of legend
        if (hasleg) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasleg = true;                  // Use simplified notation for next bird
        }
      }
      if (convstring.substring(2,3) == "M") {
                                          // This is a type of mammal
        if (hasmamm) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasmamm = true;                 // Use simplified notation for next bird
        }
      }
      if (convstring.substring(2,3) == "O") {
                                          // This is a type of mollusk
        if (hasmoll) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasmoll = true;                 // Use simplified notation for next mollusk
        }
      }
      if (convstring.substring(2,3) == "Y") {
                                          // This is a type of myth
        if (hasmyth) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasmyth = true;                 // Use simplified notation for next myth
        }
      }
      if (convstring.substring(2,3) == "P") {
                                          // This is a type of plant
        if (hasplant) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasplant = true;                // Use simplified notation for next plant
        }
      }
      if (convstring.substring(2,3) == "R") {
                                          // This is a type of reptile
        if (hasrep) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasrep = true;                  // Use simplified notation for next reptile
        }
      }
      if (convstring.substring(2,3) == "Q") {
                                          // This is a type of spirit
        if (hasspir) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasspir = true;                 // Use simplified notation for next spirit
        }
      }
      if (convstring.substring(2,3) == "U") {
                                          // This is a type of undead
        if (hasund) {
          hide_pre = true;                // Hide this prefix for simplified notation
        }
        else {
          hasund = true;                  // Use simplified notation for next undead
        }
      }
      if (convstring.substring(2,3) == "-") {
                                          // This is a custom species
        hide_pre = true;
      }
      else {
        if (dcb.askspe.checked) {
                                          // User wants to enter free-text (will not be added to custom species)
          mytxt = prompt("Please type in any free text you want to add to "+ convnice +". Leave it blank and press OK if you have nothing to add.","");
	    if (mytxt == null) {
		dcb.askspe.checked = false;
	    }
	    else if (mytxt) {
            convstring += "\"" + mytxt + "\"";
          }
        }
      }
      if (hide_pre) {                     // Hide first-letter type declaration
        var dcheckstr = convstring.substring(3,convstring.length);
        if (dcheckstr.length > 0) {
          if (firstdone) {
            stringadd += connector;
          }
          stringadd += dcheckstr;
        }
      }
      else {
        if (firstdone) {
          stringadd += connector;
        }
        stringadd += convstring.substring(2,convstring.length);
      }
      if (firstdone) {
        stringnice += " and ";
      }
      stringnice += convnice;
      firstdone = true;
    }
  }
  if (dcb.speciesaddon.value != "na" && stringadd != "") {
    var secspestring = dcb.speciesshape.options[dcb.speciesshape.selectedIndex].value;
    var secspenice = dcb.speciesshape.options[dcb.speciesshape.selectedIndex].text;
    if (dcb.speciesaddon.value == "shape") {
      stringadd += "^";
      stringnice += " - Shape: ";
    }
    if (dcb.speciesaddon.value == "form") {
      stringadd += "[";
      stringnice += " - Form: ";
    }
    stringadd += secspestring;
    stringnice += secspenice;
    if (dcb.askspe.checked) {
                                          // User wants to enter free-text
      mytxt = prompt("Please type in any free text you want to add to "+ secspenice +". Leave it blank and press OK if you have nothing to add.","");
      if (mytxt == null) {
        dcb.askspe.checked = false;
      }
      else if (mytxt) {
        stringadd += "\"" + mytxt + "\"";
      }
    }
    if (dcb.speciesaddon.value == "form") {
      stringadd += "]";
    }
  }
  if (stringnice.length > 50) {
    stringnice = stringadd;
  }
  if (stringadd != "") {
                                          // Add this form to the list
    if (dcb.spelist.options[0].value == "SPna") {
                                          // The placeholder is present, delete it
      dcb.spelist.options[0] = null;
    }
    else {
      dcb.shapshif.checked = true;        // This is not the first species to be added
    }                                     // Therefore, shapeshifter
    var spposit = dcb.spelist.length;
    var sptoadd = new Option(stringnice, stringadd);
    dcb.spelist.options[spposit] = sptoadd;
    resetspe();
  }
  else {
    alert("Please select the species you want to add.");
  }
}

function resetspe() {
                                          // Reset values after adding species
  var dcb = document.dcbuilder;
  dcb.species.selectedIndex = 0;
  dcb.species.options[0].selected = false;
  dcb.askspe.checked = false;
  dcb.speciesaddon.selectedIndex = 0;
  dcb.speciesshape.selectedIndex = 0;
}

function clrspelist() {
                                          // Clear species forms list
  var dcb = document.dcbuilder;
  var lenslist = dcb.spelist.length;
  for (spl = 1; spl <= lenslist; spl++) {
    dcb.spelist.options[0] = null;
  }
  if (dcb.spelist.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No forms specified.", "SPna");
    dcb.spelist.options[0] = placeholder;
  }
  else {
    alert("Internal error: Species forms list could not clear properly.");
  }
}


                                          // End species
  // ----------------------------------------------------------------
function ismainlengthpresent() {
                                          // Make sure a main length is present
  var dcb = document.dcbuilder;
  var lennput = parseFloat(dcb.measured.value);
  if (!lennput) {
    alert("Warning: Main length must be specified to use appendage length!");
  }
}
  // ----------------------------------------------------------------
                                          // Begin appendages

function delapp() {
                                          // Delete appendage
  var dcb = document.dcbuilder;
  if (dcb.appends.selectedIndex > -1) {
    if (dcb.appends.options[dcb.appends.selectedIndex].value != "Pna") {
      dcb.appends.options[dcb.appends.selectedIndex] = null;
    }
    else {
      alert("There are no appendages to delete.");
    }
  }
  else {
    alert("Please select the appendage you want to delete.");
  }
  if (dcb.appends.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No appendages specified.", "Pna");
    dcb.appends.options[0] = placeholder;
  }
}

function addapptolist() {
                                          // Add appendage
  var dcb = document.dcbuilder;
  var appat = dcb.apptype.options[dcb.apptype.selectedIndex].text;
  var appav = dcb.apptype.options[dcb.apptype.selectedIndex].value;
  var apptxt = dcb.appother.value;
  var appnumval = dcb.appnum.options[dcb.appnum.selectedIndex].value;
  var appsnum = parseFloat(dcb.appspecnum.value);
  if (appnumval != "PNspec" || (appsnum == dcb.appspecnum.value && appsnum != 0)) {
    if (appav == "Pwa") {
      appav = "Pw\'";
    }
    
    if (appav == "Pspec" && apptxt) {
      appav = "P\"" + apptxt + "\""
      appat = apptxt;
    }
    else if (appav == "Pspec") {
      appav = "Pna";
    }
    if (appav != "Pna") {
                                          // Add appendage modifiers
      if (dcb.Pweb.checked == true) {
                                          // Webbed
        appav = appav + "^";
      }
      if (appnumval != "PNna") {
        if (appnumval == "PNspec") {
          if (appsnum) {
            appav = appav + dcb.appspecnum.value;
            if (appat.indexOf("One") > -1) {
              appat = appat.substring(4,appat.length);
              appat += "s";
            }
            else if (appat.indexOf("Pair of") > -1) {
              appat = appat.substring(8,appat.length);
            }
            else {
              appat += "s";
            }
            if (appsnum == 1) {
              appat = appat.substring(0,appat.length - 1);
            }
            appat = appsnum + " " + appat;
          }
        }
        else {
          var appmoder = appnumval.substring(2,appnumval.length);
          appav = appav + appmoder;
          if (appmoder == "+") {
            appat = appat + " plus one";
          }
          if (appmoder == "-") {
            appat = appat + " minus one";
          }
          if (appmoder == "!") {
            if (appat.indexOf("One") > -1) {
              appat = appat.substring(4,appat.length);
              appat += "s";
            }
            else if (appat.indexOf("Pair of") > -1) {
              appat = appat.substring(8,appat.length);
            }
            else {
              appat += "s";
            }
            appat = "Many " + appat;
          }
          if (appmoder == "~") {
            if (appat.indexOf("One") > -1) {
              appat = appat.substring(4,appat.length);
              appat += "s";
            }
            if (appat.indexOf("Pair of") > -1) {
              appat = appat.substring(8,appat.length);
            }
            appat = "Variable " + appat;
          }
        }
      }
      if (dcb.Pweb.checked == true) {
        appat += " (webbed)";
      }
                                          // Add appendage to the list
      if (dcb.appends.options[0].value == "Pna") {
                                          // The placeholder is present, delete it
        dcb.appends.options[0] = null;
      }
      var appposit = dcb.appends.length;
      var apptoadd = new Option(appat, appav);
      dcb.appends.options[appposit] = apptoadd;
      resetappnums();
      dcb.appother.value = "";
    }
    else {
      alert("Please select the appendage you want to add.");
    }
  }
  else {
    alert("Please enter a real number.");
  }
}

function unlockappother() {
                                          // Jump-to for other appendage
  var dcb = document.dcbuilder;
  if (dcb.apptype.options[dcb.apptype.selectedIndex].value == "Pspec") {
    dcb.appother.focus();
  }
}

function appsetother() {
                                          // Set other type of appendage
  document.dcbuilder.apptype.selectedIndex = 11;
}

function unlockappnum() {
                                          // Jump-to for appendage number
  var dcb = document.dcbuilder;
  if (dcb.appnum.options[dcb.appnum.selectedIndex].value == "PNspec") {
    dcb.appspecnum.focus();
  }
}

function specappnum() {
                                          // Set custom appendage number
  document.dcbuilder.appnum.selectedIndex = 1;
}

function resetappnums() {
                                          // Reset values after adding appendage
  var dcb = document.dcbuilder;
  dcb.appnum.selectedIndex = 0;
  dcb.appspecnum.value = "";
  dcb.Pweb.checked = false;
}

function clrapplist() {
                                          // Clear appendage list
  var dcb = document.dcbuilder;
  var lenlist = dcb.appends.length;
  for (cpl = 1; cpl <= lenlist; cpl++) {
    dcb.appends.options[0] = null;
  }
  if (dcb.appends.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No appendages specified.", "Pna");
    dcb.appends.options[0] = placeholder;
  }
  else {
    alert("Internal error: Appendage list could not clear properly.");
  }
}

                                          // End appendages
  // ----------------------------------------------------------------
                                          // Begin skin type

function delsk() {
                                          // Delete skin type
  var dcb = document.dcbuilder;
  if (dcb.sktypes.selectedIndex > -1) {
    if (dcb.sktypes.options[dcb.sktypes.selectedIndex].value != "Kna") {
      dcb.sktypes.options[dcb.sktypes.selectedIndex] = null;
    }
    else {
      alert("There are no skin types to delete.");
    }
  }
  else {
    alert("Please select the skin type you want to delete.");
  }
  if (dcb.sktypes.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No skin types specified.", "Kna");
    dcb.sktypes.options[0] = placeholder;
  }
}

function addsktolist() {
                                          // Add skin type
  var dcb = document.dcbuilder;
  var skpat = dcb.skinplace.options[dcb.skinplace.selectedIndex].text;
  var skpav = dcb.skinplace.options[dcb.skinplace.selectedIndex].value;
  var sktat = dcb.skintype.options[dcb.skintype.selectedIndex].text;
  var sktav = dcb.skintype.options[dcb.skintype.selectedIndex].value;
  sktav = sktav.substring(2, sktav.length);

  if (sktav == "spec" && dcb.skother.value) {
    sktav = "\"" + dcb.skother.value + "\"";
    sktat = dcb.skother.value;
  }
  else if (sktav == "spec") {
    sktav = "na";
  }

  if (sktav != "na") {
    skpav = skpav.substring(2, skpav.length);
                                          // Add skin type to the list
    if (dcb.sktypes.options[0].value == "Kna") {
                                          // The placeholder is present, delete it
      dcb.sktypes.options[0] = null;
    }
    var skposit = dcb.sktypes.length;
    var sktoadd = new Option(skpat + ": " + sktat, "," + skpav + sktav);
    dcb.sktypes.options[skposit] = sktoadd;
    resetsk();
    if (dcb.bodyskintype.options[dcb.bodyskintype.selectedIndex].value == "Skna") {
      alert("Warning: A body skin type is required for this tag.");
    }
  }
  else {
    alert("Please select the skin type you want to add.");
  }
}

function resetsk() {
                                          // Reset values after adding skin type
  var dcb = document.dcbuilder;
  dcb.skintype.selectedIndex = 0;
  dcb.skother.value = "";
}

function unlockbskother() {
                                          // Jump-to for other skin type
  var dcb = document.dcbuilder;
  if (dcb.bodyskintype.options[dcb.bodyskintype.selectedIndex].value == "Skspec") {
    dcb.bskother.focus();
  }
}

function bsksetother() {
                                          // Set other type of skin
  document.dcbuilder.bodyskintype.selectedIndex = 16;
}

function unlockskother() {
                                          // Jump-to for other skin type
  var dcb = document.dcbuilder;
  if (dcb.skintype.options[dcb.skintype.selectedIndex].value == "Skspec") {
    dcb.skother.focus();
  }
}

function sksetother() {
                                          // Set other type of skin
  document.dcbuilder.skintype.selectedIndex = 16;
}

function clrsklist() {
                                          // Clear skin type list
  var dcb = document.dcbuilder;
  var lenlist = dcb.sktypes.length;
  for (cpl = 1; cpl <= lenlist; cpl++) {
    dcb.sktypes.options[0] = null;
  }
  if (dcb.sktypes.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No skin types specified.", "Kna");
    dcb.sktypes.options[0] = placeholder;
  }
  else {
    alert("Internal error: Skin type list could not clear properly.");
  }
}


                                          // End skin type
  // ----------------------------------------------------------------
                                          // Begin color

function custclr() {
                                          // Custom color
  var newname = prompt("Please type in your custom color.","");
  if (newname) {
    var dcb = document.dcbuilder;
    var clrlen = dcb.thecolor.length;
    var clrtoadd = new Option(newname, "C\"" + newname + "\"");
    dcb.thecolor.options[clrlen] = clrtoadd;
    var clr2len = dcb.seccolor.length;
    var clr2toadd = new Option(newname, "\"" + newname + "\"");
    dcb.seccolor.options[clr2len] = clr2toadd;
  }
}

function addclrtolist() {
                                          // Add appendage color
  var dcb = document.dcbuilder;
  var colplace = dcb.clrplace.options[dcb.clrplace.selectedIndex].value;
                                          // Place
  var colin = dcb.thecolor.options[dcb.thecolor.selectedIndex].value;
                                          // Color
  var lgtcolin = dcb.lgtmod.options[dcb.lgtmod.selectedIndex].value;
                                          // Lightness modifier
  var efxcolin = dcb.efxmod.options[dcb.efxmod.selectedIndex].value;
                                          // Color effects
  var sectype = dcb.extramod.options[dcb.extramod.selectedIndex].value;
                                          // Extra color
  var seclgt = dcb.seclgt.options[dcb.seclgt.selectedIndex].value;
                                          // Second color lightness
  var secclr = dcb.seccolor.options[dcb.seccolor.selectedIndex].value;
                                          // Second color lightness
  var secefx = dcb.secefx.options[dcb.secefx.selectedIndex].value;
                                          // Second color lightness
  var tcolplace = dcb.clrplace.options[dcb.clrplace.selectedIndex].text;
                                          // Place
  var tcolin = dcb.thecolor.options[dcb.thecolor.selectedIndex].text;
                                          // Color
  var tlgtcolin = dcb.lgtmod.options[dcb.lgtmod.selectedIndex].text;
                                          // Lightness modifier
  var tefxcolin = dcb.efxmod.options[dcb.efxmod.selectedIndex].text;
                                          // Color effects
  var tsectype = dcb.extramod.options[dcb.extramod.selectedIndex].text;
                                          // Extra color
  var tseclgt = dcb.seclgt.options[dcb.seclgt.selectedIndex].text;
                                          // Second color lightness
  var tsecclr = dcb.seccolor.options[dcb.seccolor.selectedIndex].text;
                                          // Second color lightness
  var tsecefx = dcb.secefx.options[dcb.secefx.selectedIndex].text;
                                          // Second color lightness

                                          // Strip out the C
  colin = colin.substring(1,colin.length);
                                          // Strip out the CP
  colplace = colplace.substring(2,colplace.length);

  if (colin != "na") {
    var clrav = "";
    var clrat = "";
    if (colplace != "na") {
      clrav += "," + colplace;
      clrat += tcolplace + ": ";
    }
    clrav += colin;
    if (lgtcolin != "na") {
      clrav += lgtcolin;
      clrat += tlgtcolin + " ";
    }
    if (efxcolin != "na") {
      clrat += tefxcolin + " ";
    }
    clrat += tcolin;
    if (efxcolin != "na") {
      if (efxcolin == "lum") {
        clrav += "'";
      }
      else {
        clrav += efxcolin;
      }
    }
    if (sectype != "na" && secclr != "na") {
      clrav += sectype;
      clrat += ": " + tsectype + " ";
      if (secclr != "colorless") {
        clrav += secclr;
      }
      if (seclgt != "na") {
        clrav += seclgt;
        clrat += tseclgt + " ";
      }
      if (secefx != "na") {
        clrav += secefx;
        clrat += tsecefx + " ";
      }
      clrat += tsecclr;
    }
    if (colplace != "na") {
                                          // Add color to the list
      if (mybodclr == "Cna") {
        alert("Warning: A body color is required for this tag.");
      }
      if (dcb.clrparts.options[0].value == "Cna") {
                                          // The placeholder is present, delete it
        dcb.clrparts.options[0] = null;
      }
      var clrposit = dcb.clrparts.length;
      var clrtoadd = new Option(clrat, clrav);
      dcb.clrparts.options[clrposit] = clrtoadd;
    }
    else {
      mybodclr = "C" + clrav;
      dcb.clrbody.value = clrat;
    }
    resetclrs();
  }
  else {
    alert("Please select the color you want to add.");
  }
}

function delclr() {
                                          // Delete color
  var dcb = document.dcbuilder;
  if (dcb.clrparts.selectedIndex > -1) {
    if (dcb.clrparts.options[dcb.clrparts.selectedIndex].value != "Cna") {
      dcb.clrparts.options[dcb.clrparts.selectedIndex] = null;
    }
    else {
      alert("There are no colors to delete.");
    }
  }
  else {
    alert("Please select the color you want to delete.");
  }
  if (dcb.clrparts.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No appendage colors specified.", "Cna");
    dcb.clrparts.options[0] = placeholder;
  }
}

function resetclrs() {
                                          // Reset colors after add
  var dcb = document.dcbuilder;
  dcb.lgtmod.selectedIndex = 2;
  dcb.thecolor.selectedIndex = 0;
  dcb.efxmod.selectedIndex = 0;
  dcb.extramod.selectedIndex = 0;
  dcb.seclgt.selectedIndex = 2;
  dcb.seccolor.selectedIndex = 0;
  dcb.secefx.selectedIndex = 0;
}

function clrbclr() {
                                          // Clear body color
  document.dcbuilder.clrbody.value = "No body color specified.";
  mybodclr = "";
}

function clrclrlist() {
                                          // Clear color list
  var dcb = document.dcbuilder;
  var lenlist = dcb.clrparts.length;
  for (cpl = 1; cpl <= lenlist; cpl++) {
    dcb.clrparts.options[0] = null;
  }
  if (dcb.clrparts.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No appendage colors specified.", "Cna");
    dcb.clrparts.options[0] = placeholder;
  }
  else {
    alert("Internal error: Color list could not clear properly.");
  }
}
                                          // End color
  // ----------------------------------------------------------------
                                          // Begin breath weapon

function unlockbwother() {
                                          // Jump-to for other breath weapon
  var dcb = document.dcbuilder;
  if (dcb.breathtype.options[dcb.breathtype.selectedIndex].value == "Bspec") {
    dcb.bwother.focus();
  }
}

function bwsetother() {
                                          // Set other type of breath weapon
  document.dcbuilder.breathtype.selectedIndex = 19;
}


function delbw() {
                                          // Delete breath weapon
  var dcb = document.dcbuilder;
  if (dcb.breathweps.selectedIndex > -1) {
    if (dcb.breathweps.options[dcb.breathweps.selectedIndex].value != "Bna") {
      dcb.breathweps.options[dcb.breathweps.selectedIndex] = null;
    }
    else {
      alert("There are no breath weapons to delete.");
    }
  }
  else {
    alert("Please select the breath weapon you want to delete.");
  }
  if (dcb.breathweps.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No breath weapons specified.", "Bna");
    dcb.breathweps.options[0] = placeholder;
  }
}

function addbwtolist() {
                                          // Add breath weapon
  var dcb = document.dcbuilder;
  var bwat = dcb.breathtype.options[dcb.breathtype.selectedIndex].text;
  var bwav = dcb.breathtype.options[dcb.breathtype.selectedIndex].value;
  var bwbeam;                             // Boolean: Beam
  var bwcloud;                            // Boolean: Cloud


  if (bwav == "Bspec" && dcb.bwother.value) {
    bwav = "B\"" + dcb.bwother.value + "\"";
    bwat = dcb.bwother.value;
  }
  else if (bwav == "Bspec") {
    bwav = "Bna";
  }
  if (bwav != "Bna") {
    if (dcb.Bbeam.checked) {
      bwbeam = true;
    }
    else {
      bwbeam = false;
    }
    if (dcb.Bcloud.checked) {
      bwcloud = true;
    }
    else {
      bwcloud = false;
    }
    if (bwbeam) {
      bwat += " beam";
      bwav += "|";
    }
    if (bwcloud) {
      bwat += " cloud";
      bwav += "#";
    }
                                          // Add breath weapon to the list
    if (dcb.breathweps.options[0].value == "Bna") {
                                          // The placeholder is present, delete it
      dcb.breathweps.options[0] = null;
    }
    var bwposit = dcb.breathweps.length;
    var bwtoadd = new Option(bwat, bwav);
    dcb.breathweps.options[bwposit] = bwtoadd;
    resetbws();
  }
  else {
    alert("Please select the breath weapon you want to add.");
  }
}

function resetbws() {
                                          // Reset breath weapons after add
  var dcb = document.dcbuilder;
  dcb.breathtype.selectedIndex = 0;
  dcb.bwother.value = "";
  dcb.Bbeam.checked = false;
  dcb.Bcloud.checked = false;
}

function clrbwlist() {
                                          // Clear breath weapon list
  var dcb = document.dcbuilder;
  var lenlist = dcb.breathweps.length;
  for (cpl = 1; cpl <= lenlist; cpl++) {
    dcb.breathweps.options[0] = null;
  }
  if (dcb.breathweps.length < 1) {
                                          // List is empty, create placeholder
    var placeholder = new Option("No breath weapons specified.", "Bna");
    dcb.breathweps.options[0] = placeholder;
  }
  else {
    alert("Internal error: Breath weapon list could not clear properly.");
  }
}

function bwrc(actcb) {
                                          // Radio-like checkboxes
  var dcb = document.dcbuilder;
  if (actcb == "none" && dcb.Bnone.checked) {
    dcb.Bunk.checked = false;
    dcb.Bany.checked = false;
  }
  if (actcb == "unk" && dcb.Bunk.checked) {
      dcb.Bnone.checked = false;
      dcb.Bany.checked = false;
  }
  if (actcb == "any" && dcb.Bany.checked) {
    dcb.Bnone.checked = false;
    dcb.Bunk.checked = false;
  }
}

function selall() {
                                          // Select all for finished DC
  var dcb = document.dcbuilder;
  dcb.output.focus()
  dcb.output.select()
}

function selallhtml() {
                                          // Select all for HTML
  var dcb = document.dcbuilder;
  dcb.outhtml.focus()
  dcb.outhtml.select()
}

function stableshif() {
                                          // Stable checkbox > shapeshifter
  var dcb = document.dcbuilder;
  dcb.shapshif.checked = true;
}

function custgen() {
                                          // Custom gender
  mygen = prompt("Please type in your gender.",mygen);
  if (mygen == null) {
    mygen = "";
  }
}

function custlen() {
                                          // Custom length
  mylen = prompt("Please type in your length.",mylen);
  if (mylen == null) {
    mylen = "";
  }
}

function custwid() {
                                          // Custom width
  mywid = prompt("Please type in your width.",mywid);
  if (mywid == null) {
    mywid = "";
  }
}

function custwei() {
                                          // Custom weight
  mywei = prompt("Please type in your width.",mywei);
  if (mywei == null) {
    mywei = "";
  }
}

function custage() {
                                          // Custom age
  myage = prompt("Please type in your age.",myage);
  if (myage == null) {
    myage = "";
  }
}

function custfruit() {
                                          // Custom fruit
  myfruit = prompt("Please type in your fruit.",myfruit);
  if (myfruit == null) {
    myfruit = "";
  }
}

function custnland() {
                                          // Custom native land
  mynland = prompt("Please type in your native land.",mynland);
  if (mynland == null) {
    mynland = "";
  }
}

function custmstat() {
                                          // Custom mating status
  mymstat = prompt("Please type in your mating status.",mymstat);
  if (mymstat == null) {
    mymstat = "";
  }
}

function msrc(actcb) {
                                          // Radio-like checkboxes
  var dcb = document.dcbuilder;
  if (actcb == "xx" && dcb.Mxx.checked) {
      dcb.Mxy.checked = false;
  }
  if (actcb == "xy" && dcb.Mxy.checked) {
    dcb.Mxx.checked = false;
  }
}

function custoff() {
                                          // Custom offspring
  myoff = prompt("Please type in your offspring.",myoff);
  if (myoff == null) {
    myoff = "";
  }
}

function specoffnum() {
                                          // Set custom offspring number
  if (document.dcbuilder.offspr.selectedIndex != 7) {
    document.dcbuilder.offspr.selectedIndex = 5;
  }
}

function unlockoffnum() {
                                          // Jump-to for offspring
  var dcb = document.dcbuilder;
  var offin = dcb.offspr.options[dcb.offspr.selectedIndex].value;
  if (offin == "O+spec" || offin == "O-spec") {
    dcb.okidnum.focus();
  }
}

function custhsize() {
                                          // Custom hoard size
  myhsize = prompt("Please type in your hoard size.",myhsize);
  if (myhsize == null) {
    myhsize = "";
  }
}

function custmph() {
                                          // Custom monetary philosophy
  mymph = prompt("Please type in your monetary philosophy.",mymph);
  if (mymph == null) {
    mymph = "";
  }
}

function custdiet() {
                                          // Custom diet
  mydiet = prompt("Please type in your diet.",mydiet);
  if (mydiet == null) {
    mydiet = "";
  }
}

function custreal() {
                                          // Custom reality index
  myreal = prompt("Please type in your reality index.",myreal);
  if (myreal == null) {
    myreal = "";
  }
}

function custacti() {
                                          // Custom activity
  myacti = prompt("Please type in your online activity.",myacti);
  if (myacti == null) {
    myacti = "";
  }
}

function custhum() {
                                          // Custom humor index
  myhum = prompt("Please type in your humor index.",myhum);
  if (myhum == null) {
    myhum = "";
  }
}

function custsoc() {
                                          // Custom social life
  mysoc = prompt("Please type in your social life.",mysoc);
  if (mysoc == null) {
    mysoc = "";
  }
}

function custubi() {
                                          // Custom ubiquity
  myubi = prompt("Please type in your ubiquity.",myubi);
  if (myubi == null) {
    myubi = "";
  }
}

function custirr() {
                                          // Custom irritability
  myirr = prompt("Please type in your irritability.",myirr);
  if (myirr == null) {
    myirr = "";
  }
}

function custmag() {
                                          // Custom magic ability
  mymag = prompt("Please type in your magic ability.",mymag);
  if (mymag == null) {
    mymag = "";
  }
}

function custpsy() {
                                          // Custom psychic power
  mypsy = prompt("Please type in your psychic power.",mypsy);
  if (mypsy == null) {
    mypsy = "";
  }
}

function custtek() {
                                          // Custom technology
  mytek = prompt("Please type in your technology.",mytek);
  if (mytek == null) {
    mytek = "";
  }
}

function custfrd() {
                                          // Custom dragon friend
  myfrd = prompt("Please type in your dragon friendship.",myfrd);
  if (myfrd == null) {
    myfrd = "";
  }
}

function custhug() {
                                          // Custom huggability
  myhug = prompt("Please type in your huggability.",myhug);
  if (myhug == null) {
    myhug = "";
  }
}

//End of Dragon Code Builder JavaScript
