/* Name: stringvb.js
   Desc:
   This js file adds useful VBScript like string functions to the JavaScript String object
   as member functions.
   The functions are:

     trim()      - returns a string without leading and trailing spaces
     left(arg1)  - returns the left portion of a string of length "arg1"
     right(arg1) - returns the right portion of a string of length "arg1"
     mid(arg1,[arg2]) - returns a string starting at point "arg1" of optional length "arg2"
   
   Usage:
   Include this file as a HTML script block. Then, call these functions as methods of
   your string objects.
   ex.: myStr.trim();

   Note:
   Include this file before any script in your HTML page using these methods.
   
   Author: Joe Agster
   Date: 9/6/2000
*/

function _private_trim() {
  var tmpStr, atChar;
  tmpStr = this;

  if (tmpStr.length > 0) atChar = tmpStr.charAt(0);
  while (_private_stringvb_isSpace(atChar)) {
    tmpStr = tmpStr.substring(1, tmpStr.length);
    atChar = tmpStr.charAt(0);
  }
  if (tmpStr.length > 0) atChar = tmpStr.charAt(tmpStr.length-1);
  while (_private_stringvb_isSpace(atChar)) {
    tmpStr = tmpStr.substring(0,( tmpStr.length-1));
    atChar = tmpStr.charAt(tmpStr.length-1);
  }
  return tmpStr;
}

function _private_left(inLen) {
  return this.substring(0,inLen);
}

function _private_right(inLen) {
  return this.substring((this.length-inLen),this.length);
}

function _private_mid(inStart,inLen) {
  var iEnd;
  if (!inLen)
    iEnd = this.length;
  else
    iEnd = inStart + inLen;
  return this.substring(inStart,iEnd);
}

function _private_stringvb_isSpace(inChar) {
  return (inChar == ' ' || inChar == '\t' || inChar == '\n');
}

String.prototype.trim = _private_trim;
String.prototype.left = _private_left;
String.prototype.right = _private_right;
String.prototype.mid = _private_mid;
