// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// dungeon/random.js
//
// copyright (c) 2006-2010 drow <drow@bin.sh>
// all rights reserved.

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// configuration

var static_fields = ['level','infest','image_size','grid'];

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// frob form inputs

function random_dungeon (form) {
  $A(form.elements).each(function (input) {
    if (input.disabled) return;
    if (static_fields.indexOf(input.name) > -1) return;

    if (input.type == 'text') {
      if (input.name == 'seed') {
        input.value = rand(2147483647,1);
      }
    } else if (input.type.match(/^select/)) {
      if (input.options[0].text.match(/^Random/)) {
        input.selectedIndex = 0;
      } else {
        input.selectedIndex = rand(input.options.length,0);
      }
    }
  });
  layout_reaction();
  preview();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// random number

function rand (x,z) {
  return Math.floor(Math.random() * x) + z;
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// showtime

document.write('&nbsp; <input type="button" value="Random"'
  + ' onclick="random_dungeon(this.form)" />');

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


