/*
----------- 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
  File Dependencies: global.js
                     manage_arrays.js
										 validate_contact.js
===================================================================''*/

/*'''---------------------------------
'' isUSPhoneNumber(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 a valid U.s. Phone Number.  Must be 10 digits.
----------------------------------'''*/ 
function isUSPhoneNumber(str) {
  if (str.length < 1)
    return false;
  else   
    return (isInteger(str) && str.length == digitsInUSPhoneNumber);
}

// isZIPCode (STRING str)
// 
// isZIPCode returns true if string str is a valid 
// U.str. ZIP code.  Must be 5 or 9 digits only.
//
// NOTE: Strip out any delimiters (spaces, hyphens, etc.)
// from stringstrbefore calling this function.  

function isZIPCode(str) {
  if (str.length < 1)
    return false;
  else  
    return (isInteger(str) && ((str.length == digitsInZIPCode1) || (str.length() == digitsInZIPCode2)))
}

// isStateCode(str)
// 
// Return true if str is a valid U.S. Postal Code 
// (abbreviation for state).
//

function isStateCode(str) {
//(str.toUpperCase(str));
  
  if (str.length != 2) 
    return false;
  else 
    return ( (USStateCodes.indexOf(str.toUpperCase(str)) != -1) && (str.indexOf(USStateCodeDelimiter) == -1) )
}

/*'''---------------------------------
'' isSSN(str)
--------------------------------------
   Created By: SySys:bh
   Compatibility: IE6
   Description: checks for a valid SSN
   Parameters:
     str: string to check
   Returns: true if string str is a valid SSN
----------------------------------'''*/ 
function isSSN(str) {
  var matchar = str.match(/^(\d{3})-?\d{2}-?\d{4}$/);
  var numDashes = str.split('-').length - 1;
  if (matchar == null || numDashes == 1) {
    return false;
  }else { 
    if (parseInt(matchar[1],10)==0) {
       return false;
    } else {
     return true;
    }
  }
}


/*'''---------------------------------
'' isEmailList(str,del)
--------------------------------------
   Created By: SySys:BH
   Last Edited By: SySys:BH
   Compatibility: IE6
   Description: checks for a valid list of emails seperated by the delmiter
   Parameters:
     str: string to check
     delmiter: delimiter between email addressses (usually semicolon or comma)
   Dependencies: manage_arrays.js:split 
                 validate_contact.js:isEmail
   Returns: true if each email in email list is valid, false if any email is bad
----------------------------------'''*/ 
function isEmailList(str,delimiter){
  var arys = new Array();
  arys = split(str,delimiter);
  for(i=0; i < arys.length; i++){
    if(!(isEmail(arys[i]))){
      return false;
    }
  }
  return true; 
}

/*'''---------------------------------
'' isEmail(str)
--------------------------------------
   Created By: SySys:CH
   Last Edited By: SySys:BH
   Compatibility: IE6
   Description: checks for a valid email address
   Parameters:
     str: string to check
   Returns: true if email is well formed 
----------------------------------'''*/ 
function isEmail(str) {   
  if (isEmpty(str)) 
    return false;
  var i = 0;
  var emailsArray = str.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
  var count1 = 0;
  var count2 = 0;
  var sLength = str.length;
  if (emailsArray != null){ 
    for (i = 0;i<=sLength;i++){
     if (str.charAt(i) == "@")
       count1++;
       count2=0; //reset period count because there can be multiple periods before the @ but only one after
     if (str.charAt(i) == ".")
       count2++;
    }
    if ((count1 > 1) || (count2 > 1))
      return false;
    else
      if (str.indexOf(' ') != -1)
        return false;
      else
        return true; 
  }else{
    return false;
  } 
}
