// 'args.js', written by Charlton D. Rose for Inquiry.Com
// 										
// Permission is granted to use and modify this script for any purpose,
// provided that this credit header is retained, unmodified, in the script.

// This function is included to overcome a bug in Netscape's implementation
// of the escape() function:
function myunescape( str ) {
  str = '' + str;
  while( true ) {
    var i = str.indexOf( '+' );
    if( i < 0 )
      break;
    str = str.substring( 0, i ) + ' ' + str.substring( i + 1, str.length );
  }
  return unescape( str );
}

// This function creates the args[] array and populates it with data
// found in the URL's search string:
function args_init() {
  args = new Array();
  keys = new Array();
  var argstring = window.location.search;
  if( argstring.charAt( 0 ) != '?')
    return;
  argstring = argstring.substring( 1, argstring.length );
  var argarray = argstring.split( '&' );
  var i;
  var singlearg;
  for( i = 0; i < argarray.length; ++i ) {
    singlearg = argarray[i].split( '=' );
    if( singlearg.length != 2 ) {
      singlearg[0] = argarray[i];
      singlearg[1] = "1";
    }
    var key = myunescape( singlearg[0] );
    var value = myunescape( singlearg[1] );
    args[key] = value;
    keys[i] = key;
  }
}

// Call the args_init() function to set up the args[] array:

args_init();

// End of 'args.js'

// Additional utilities copyright &copy; 2001, 2002 Mark Purtill.
function arg_string() {
  var temp = new Array();
  for( i=0; i < keys.length; ++i ) {
    temp[ temp.length ] = ( keys[i] + "=" + args[keys[i]] );
  }
  if( temp.length > 0 ) {
    return "?" + temp.join( "&" );
  } else {
    return "";
  }
}

function arg_string_no_seed() {
  var temp = new Array();
  for( i=0; i < keys.length; ++i ) {
    if( keys[i] != "seed" ) {
      temp[ temp.length ] = ( keys[i] + "=" + args[keys[i]] );
    }
  }
  if( temp.length > 0 ) {
    return "?" + temp.join( "&" );
  } else {
    return "";
  }
}

// The Central Randomizer 1.3 (C) 1997 by Paul Houle (paul@honeylocust.com)
// See:  http://www.honeylocust.com/javascript/randomizer.html
// Feel free to use the Central Randomizer on your page. I do ask
// that you keep the comment intact; it also would be nice if you
// were to drop a link to one of my pages.
function rnd() {
  rnd.seed = Math.abs(rnd.seed*9301+49297) % 233280;
  return rnd.seed/(233280.0);
}

// Returns a number in 0..(number-1)
function random_number( number ) {
  return Math.floor( rnd()*number );
}

// End of central randomizer

function set_seed( number ) {
  rnd.seed = number;
}

// Additional utilities copyright &copy; 2001, 2002 Mark Purtill.
function locationNoArgs () {
  var loc = window.location.href;
  var idx = loc.indexOf( '?' );
  if( idx == -1 ) {
    return loc;
  } else {
    return loc.substring( 0, idx );
  }
}

function locationDirOnly() {
  var loc = locationNoArgs();
  var idx = loc.lastIndexOf( '/' );
  if( idx == -1 ) {
    // Waa??
    return loc;
  } else {
    return loc.substring( 0, idx+1 );
  }
}

