/*
----------- 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
  File Dependencies: none
===================================================================''*/

/*'''---------------------------------
'' isEmpty(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for empty string
   Parameters:
     str: string to check
   Returns: true if string empty false otherwise
----------------------------------'''*/ 
function isEmpty(str) {
  return ((str == null) || (str.length == 0))
}

/*'''---------------------------------
'' isWhitespace(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for whitespace characeters only
   Parameters:
     str: string to check
   Returns: true if string contains only whitespace characters or is empty, false otherwise
----------------------------------'''*/ 
function isWhitespace(str) {
  var i;
  // Is str empty?
  if (isEmpty(str)) return true;
    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
      for (i = 0; i < str.length; i++) {   
        // Check that current character isn't whitespace.
        var c = str.charAt(i);
          if (whitespace.indexOf(c) == -1) return false;
      }
    // All characters are whitespace.
    return true;
}

/*'''---------------------------------
'' chaInString(cha, str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for characger in a string
   Parameters:
     cha: character to check in string
     str: string to check
   Returns: true if string contains the character
   Notes: 
     WORKAROUND FUNCTION FOR NAVIGATOR 2.0.2 COMPATIBILITY.
     The below function *should* be unnecessary.  In general,
     avoid using it.  Use the standard method indexOf instead.
     However, because of an apparent bug in indexOf on 
     Navigator 2.0.2, the below loop does not work as the
     body of stripInitialWhitespace:
     while ((i < str.length) && (whitespace.indexOf(str.charAt(i)) != -1))
     i++;
     ... so we provide this workaround function chaInString
     instead.
     chaInString (character c, STRING str)
       Returns true if single character c (actually a string)
     is contained within string str.
----------------------------------'''*/ 
function chaInString (cha, str) {
  for (i = 0; i < str.length; i++) {
    if (str.charAt(i) == cha) 
      return true;
  }
  return false;
}

/*'''---------------------------------
'' isLetter(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for english letters (A .. Z, a..z).
   Parameters:
     str: string to check
   Returns: true if character is an english letter (A .. Z, a..z).
   Notes: Need i18n version to support European characters.
     could be tricky due to different character
----------------------------------'''*/ 
function isLetter (cha) {
  return ( ((cha >= "a") && (cha <= "z")) || ((cha >= "A") && (cha <= "Z")) )
}


/*'''---------------------------------
'' isDigit(cha)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for digit (0 .. 9).
   Parameters:
     cha: character to check
   Returns: true if character is a digit (0 .. 9).
----------------------------------'''*/ 
function isDigit (cha) {
  return ((cha >= "0") && (cha <= "9"))
}


/*'''---------------------------------
'' isLetterOrDigit(cha)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for an english letter (A .. Z, a..z) or digit (0 .. 9).
   Parameters:
     chr: character to check
   Returns: true if character is an english letter (A .. Z, a..z) or digit (0 .. 9).
----------------------------------'''*/ 
function isLetterOrDigit (cha) {   
  return (isLetter(cha) || isDigit(cha))
}

/*'''---------------------------------
'' isInteger(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a positive integer
   Parameters:
     str: string to check
   Returns: Returns true if all characters in string str are positive integers only.
   Notes:
     Accepts non-signed integers only. Does not accept floating point, exponential notation, etc.
     don't use parseInt because it would accept a string with trailing non-numeric characters.
   Example:
     EXAMPLE FUNCTION CALL:     RESULT:
     isInteger ("5")            true 
     isInteger ("")             false
     isInteger ("-5")           false
----------------------------------'''*/ 
function isInteger(str) {
  if (str.length < 1)
    return false
  else{
  var i;
    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < str.length; i++) {   
      // Check that current character is number.
      var c = str.charAt(i);
      if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
  }
}


/*'''---------------------------------
'' isSignedInteger(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a positive or negative integer value
   Parameters:
     str: string to check
   Returns: Returns true if a positive or negative integer is passed.
   Notes:
     first character is allowed to be + or -. Does not accept floating point, exponential notation, etc.
     don't use parseInt because it would accept a string with trailing non-numeric characters.
   Example:
     EXAMPLE FUNCTION CALL:     RESULT:
     isSignedInteger ("5")      true 
     isSignedInteger ("")       false
     isSignedInteger ("-5")     true
     isSignedInteger ("+5")     true
----------------------------------'''*/ 
function isSignedInteger(str) {
  if (str.length < 1)
   return false;
  else{
    var startPos = 0;
    // skip leading + or -
    if ((str.charAt(0) == "-") || (str.charAt(0) == "+"))
      startPos = 1;    
      return (isInteger(str.substring(startPos, str.length)));
  }
}


/*'''---------------------------------
'' isNegativeInteger(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a negative integer value
   Parameters:
     str: string to check
   Returns: Returns true if string str is an integer <= 0.
----------------------------------'''*/ 
function isNegativeInteger (str){
  return (isSignedInteger(str)  &&  (parseInt (str) <= 0) );
}


/*'''---------------------------------
'' isPositiveInteger(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a positive integer value
   Parameters:
     str: string to check
   Returns: Returns true if string str is an integer >= 0.
----------------------------------'''*/ 
function isPositiveInteger(str) {
  return ( isSignedInteger(str) && ( parseInt(str) >= 0 ) );
}


/*'''---------------------------------
'' isMoney(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a floating point value and allows a $ in front of the value
   Parameters:
     str: string to check
   Returns: True if string str is an unsigned floating point (real) number. 
   NOTES: Does not accept exponential notation. 
     It is recommened to do a replace on the $ to '' when saving database
   Dependencies: validate_string.js:isFloat
----------------------------------'''*/ 
function isMoney(str) { 
  var mny = str;
  if(mny.charAt(0)=='$'){
    mny = mny.substring(1,mny.length);
  }  
  mny = mny.replace(',','');
  return isFloat(mny);
}


/*'''---------------------------------
'' isFloat(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a floating point value
   Parameters:
     str: string to check
   Returns: True if string str is an unsigned floating point (real) number. 
   NOTES: Does not accept exponential notation.
----------------------------------'''*/ 
function isFloat(str) { 
  if (str.length < 1)
    return false;
  var i;
  var seenDecimalPoint = false;
  if (str == '.') return false;
  // Search through string's characters one by one until we find a non-numeric character. if we do, return false; if we don't, return true.
  for (i = 0; i < str.length; i++){   
    // Check that current character is number.
    var c = str.charAt(i);
    if ((c == '.') && !seenDecimalPoint) seenDecimalPoint = true;
    else if (!isDigit(c)) return false;
  }
  // All characters are numbers.
  return true;
}

/*'''---------------------------------
'' isSignedFloat(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a positive or negative float value
   Parameters:
     str: string to check
   Returns: Returns true if a positive or negative integer is passed.
   Notes:
     first character is allowed to be + or -. 
   Example:
     EXAMPLE FUNCTION CALL:     RESULT:
     isSignedInteger ("5.0")      true 
     isSignedInteger ("")       false
     isSignedInteger ("-5.0")     true
     isSignedInteger ("+5.0")     true
----------------------------------'''*/ 
function isSignedFloat(str) {
  if (str.length < 1)
   return false;
  else{
    var startPos = 0;
    // skip leading + or -
    if ((str.charAt(0) == "-") || (str.charAt(0) == "+"))
      startPos = 1;    
      return (isFloat(str.substring(startPos, str.length)));
  }
}


/*'''---------------------------------
'' isPositiveFloat(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a positive floating point value
   Parameters:
     str: string to check
   Returns: True if string str is an positive floating point (real) number. 
   NOTES: Does not accept exponential notation.
   Dependencies: validate_string.js:isFloat
----------------------------------'''*/ 
function isPositiveFloat(str) {
  var startPos = 0;    
  return (isFloat(str.substring(startPos,str.length)));
}

/*'''---------------------------------
'' isNegitiveFloat(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a negative floating point value
   Parameters:
     str: string to check
   Returns: True if string str is an negative floating point (real) number. 
   NOTES: Does not accept exponential notation.
   Dependencies: validate_string.js:isFloat
----------------------------------'''*/ 
function isNegitiveFloat(str) {
  if (str.length < 1)
    return false;
  if (str.charAt(0) == "-"){
      var startPos = 1;    
  }else{ 
    return false;    
  }
  return (isFloat(str.substring(startPos, str.length)));
}


/*'''---------------------------------
'' isAlphabetic(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a negative floating point value
   Parameters:
     str: string to check
   Returns: Returns true if string str is English letters (A .. Z, a..z) only.
----------------------------------'''*/ 
function isAlphabetic(str) {
  var i;
  if (str.length < 1)
    return false; 
    // Search through string's characters one by one
    // until we find a non-alphabetic character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < str.length; i++) {   
        // Check that current character is letter.
        var c = str.charAt(i);
        if (!isLetter(c))
        return false;
    }
    // All characters are letters.
    return true;
}


/*'''---------------------------------
'' isAlphanumeric(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a negative floating point value
   Parameters:
     str: string to check
   Returns: Returns true if string str is English letters (A .. Z, a..z) and numbers (0..9) only.
----------------------------------'''*/ 
function isAlphanumeric(str){
  if (str.length < 1)
    return false;
  var i; 
  // Search through string's characters one by one
  // until we find a non-alphanumeric character.
  // When we do, return false; if we don't, return true.
  for (i = 0; i < str.length; i++) {   
    // Check that current character is number or letter.
    var c = str.charAt(i);
    if (! (isLetter(c) || isDigit(c) ) )
      return false;
  }
  // All characters are numbers or letters.
  return true;
}


/*'''---------------------------------
'' isIntegerInRange(str, a, b)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for an integer between the given range
   Parameters:
     str: string to check
     a: begining of range
     b: end of range
   Returns: true if string str is an integer within the range of integer arguments a and b, inclusive.
----------------------------------'''*/ 
function isIntegerInRange(str, a, b) {
  if (str.length < 1) 
      return false;
  // Catch non-integer strings to avoid creating a NaN below,
  // which isn't available on JavaScript 1.0 for Windows.
  if (!isInteger(str, false)) return false;
  // Now, explicitly change the type to integer via parseInt
  // so that the comparison code below will work both on 
  // JavaScript 1.2 (which typechecks in equality comparisons)
  // and JavaScript 1.1 and before (which doesn't).
  var num = parseInt(str);
  return ((num >= a) && (num <= b));
}
