/*
----------- FundSys.net(TM) Copyright SySys(R) Corp 2002 ------------
====================================================================
  Created By: BH
  Last Edited By: BH
  Inception Date: 1/1/2002
  Last Edited Date: 1/1/2002
  Description:  None
  Required Files: global.js (whitespace)
  File Dependencies: Manage_string.js
===================================================================''*/

/*'''---------------------------------
'' replace(str, regexp, replacement)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Replaces all occurencs of the 'regexp' with 'replacement'
   Parameters:
     str: string to replace
     regexp: the sub string that you are searching for
     replacement: the value to replace all occurences of the 'regexp' with
   Returns: string with all occurences of 'regexp' replaced with 'replacement'
----------------------------------'''*/ 
function replace(str, regexp, replacement){
  //alert('str=' + str + '\nregexp=' + regexp + '\nreplacement=' + replacement);
  if(str.indexOf(regexp)>=0){
    return replace(str.replace(regexp, replacement), regexp, replacement);
  }else{
    return str;
  }  
}


/*'''---------------------------------
'' length(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: function call to retrive length of a string 
   Parameters:
     str: string to test length of
   Returns: lenght of given string 
   Notes: Better to use string object length property unless you need the length in line
----------------------------------'''*/ 
function length(str){
  return str.length;
}

/*'''---------------------------------
'' stripchasInBag(str, bag)
--------------------------------------
   Created By: SySys:LivePayment
   Compatibility: IE6
   Description: Removes all characters which appear in string bag from string str.
   Parameters:
     str: string to remove characters from
     bag: list of characters to remove
   Returns: string with bag characters removed
----------------------------------'''*/ 
function stripchasInBag(str, bag){
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is not in bag, append to returnString.
  for (i = 0; i < str.length; i++) {   
    // Check that current character isn't whitespace.
    var c = str.charAt(i);
    if (bag.indexOf(c) == -1) returnString += c;
  }
  return returnString;
}

/*'''---------------------------------
'' stripchasNotInBag(str, bag)
--------------------------------------
   Created By: SySys:LivePayment
   Compatibility: IE6
   Description: all characters which do NOT appear in string bag 
   Parameters:
     str: string to remove characters from
     bag: list of characters not to remove
   Returns: string with characters not in bag removed
----------------------------------'''*/ 
function stripchasNotInBag(str, bag){
  var i;
  var returnString = "";
  // Search through string's characters one by one.
  // If character is in bag, append to returnString.
  for (i = 0; i < str.length; i++) {   
    // Check that current character isn't whitespace.
    var c = str.charAt(i);
    if (bag.indexOf(c) != -1) returnString += c;
  }
  return returnString;
}

/*'''---------------------------------
'' stripWhitespace(str, bag)
--------------------------------------
   Created By: SySys:LivePayment
   Compatibility: IE6
   Description: Removes all whitespace characters from str. 
   Parameters:
     str: string to remove whitespace from
   Returns: str string with whitespace removed
   Dependencies: Manage_string.js:stripchasInBag
----------------------------------'''*/ 
function stripWhitespace(str) {
  return stripchasInBag (str, whitespace)
}

/*'''---------------------------------
'' LTrim(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: Removes all whitespace from begining of string
   Parameters:
     str: string to remove whitespace from
   Returns: str string with whitespace removed from front
----------------------------------'''*/ 
function LTrim(str) {
  //alert(str);
  var i = 0;
  while ((i < str.length) && chaInString (str.charAt(i), whitespace))
    i++;
  return str.substring (i, str.length);
}


/*'''---------------------------------
'' prefix(value, padCharacter, padLength)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: pads the value parameter with the padCharacter until the string is padLength.  (padding on the front)
   Parameters:
     value: original value to pad
     padCharacter: value to pad with
     padLength: length of resulting string
   Returns: value padded with the padCharacter with a length of padLength
   Note: if value is longer than padLength the string is truncated at the end
----------------------------------'''*/ 
function prefix(value, padCharacter, padLength) {
  var val = value.toString();
  if(val.length > padLength){
    return value.substring(0,padLength);
  }else{
    for(var i=val.length; i<padLength; i++){
      val+=padCharacter;
    }
    return val;
  }  
}


/*'''---------------------------------
'' suffix(value, padCharacter, padLength)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: pads the value parameter with the padCharacter until the string is padLength.  (padding on the end)
   Parameters:
     value: original value to pad
     padCharacter: value to pad with
     padLength: length of resulting string
   Returns: value padded with the padCharacter with a length of padLength
   Note: if value is longer than padLength the string is truncated at the end
----------------------------------'''*/ 
function suffix(value, padCharacter, padLength){
  var val = value.toString();
  if(val.length > padLength){
    return val.substring(0,padLength);
  }else{
    for(var i=val.length; i<padLength; i++){
      val=padCharacter+val;
    }
    return val;
  }  
}


