// $Id: tools.js,v 1.1 2003/07/02 21:59:34 bowens Exp $

// adjust the window location to prefix + where, but only if where has
// something in it
function doJumpTo(where, prefix) {
  var theval = where.options[where.selectedIndex].value;
  if (theval.length > 0)
    window.location.href = prefix + theval;
}

// This function accepts one to many incoming bill numbers,
// normalizes them, and then checks to make sure they're valid
// It returns null if there is a problemo or the normalized
// bills if everything is hunky-dorey
function validateBillNumbers(incoming) {
  var splitre = new RegExp("[ ,\n\r\t.;]+");
  var thenumbers = "0123456789";
  // split the value and validate each one
  var valre = new RegExp(
      "^(HR|HRES|HCONRES|HJRES|TD|SRES|SCONRES|SJRES|S|DSAPPS|DS|DSJRES|DSCONRES|DSRES|DHAPPS|DHR|DHJRES|DHCONRES|DHRES)[0-9]{1,4}(\\-[0-9]{1,4})?$", "i");

  // the first pass using splitre will be used to normalize the bills
  var thebills = incoming.toUpperCase().split(splitre);
  var thenewvalue = "";
  for (n = 0; n < thebills.length; n++) {
    if (n > 0) {
      // get the last char of the previous element
      lastcharprev = thebills[n - 1].substr(thebills[n-1].length - 1);
      if (thenumbers.indexOf(lastcharprev) > -1) {
        thenewvalue = thenewvalue + " ";
      }
    }
    thenewvalue = thenewvalue + thebills[n];
  }

  // the second pass validates the normalized bill numbers
  thebills = thenewvalue.split(splitre);
  thenewvalue = "";
  for (n = 0; n < thebills.length; n++) {
    if (thebills[n] == "")
      continue;
    if (!valre.test(thebills[n])) {
      alert("Error: >" + thebills[n] + "< is not a valid bill number.");
      return null;
    }
    thenewvalue = (thenewvalue.length == 0 ? thebills[n] :
        thenewvalue + " " + thebills[n]); 
  }
  return thenewvalue;
}

/**
 * Author: Mark Kennedy
 *  Removes leading and trailing whitespace from a string
 */
function trimString( s ) {
  // Check to ensure that something was passed in
  if( s ) {
    s = s.replace( /^\s*/, "" );
    s = s.replace( /\s*$/, "" );
    return s;
  } else {
    return '';
  }
}

// URL decode the provided string
function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

//remembermyhome
function remembermyhome(page) {
  alert('You have selected this page as your starting page.');
  document.location = "remembermyhome.do?page="+page;
}



