function isDate(value){
      function all_digits(value){
           is_all_digits = true
           str_value = value.toString()
           if (value == ""){
              return false
           }

           for (var i = 0; i < value.length; i++) {
              single_char = str_value.charCodeAt(i) 
              if (single_char < 48 || single_char > 58){
                 is_all_digits = false
                 break;
              }
           }
           return is_all_digits
       }
      function valid_day(str_day){
          digits_ok = all_digits(str_day) 
          if (digits_ok){
              //checking for leading zeros
              first_digit = str_day.substring(0,1)
              string_length = str_day.length
              
              if (first_digit == 0 && string_length == 2){
                  str_day = str_day.substr(1,1)
              }
              digit_day = parseInt(str_day)
              
              if (digit_day > 0 && digit_day < 32){
                  return true
              }else{
                  return false
              }
          }else{
             return false
          }
      }

      function valid_month(str_month){
          digits_ok = all_digits(str_month) 
          if (digits_ok){
              digit_month = parseInt(str_month, 10)
              if (digit_month > 0 && digit_month < 13){
                  return true
              }else{
                  return false
              }
          }else{
             return false
          }
      }
      function valid_year(str_year){
          digits_ok = all_digits(str_year) 
          if (digits_ok){
              digit_year = parseInt(str_year)
              if (str_year.length == 2 || str_year.length == 4){
                   return true
              }else{
                   return false
              }
          }else{
             return false
          }
      }
str_date = value.toString()
str_length = str_date.length
is_valid = true
back_slash_count = 0 
dash_count = 0
for (var i = 0; i < str_length; i++) {
    single_char = str_date[i]
    if (single_char == '/' || single_char == '-'){
        if (single_char == '/'){
             back_slash_count = back_slash_count + 1
        }
        if (single_char == '-'){
             dash_count = dash_count + 1
        }
    }
}
if (back_slash_count == 2 && dash_count == 0 || dash_count == 2 && back_slash_count == 0){
    if (back_slash_count == 2){
         seq_numbers = str_date.split('/')
    }else{
         seq_numbers = str_date.split('-')
    }
    month_ok = valid_month(seq_numbers[0])
    day_ok = valid_day(seq_numbers[1])
    year_ok = valid_year(seq_numbers[2])
   
    if (month_ok && day_ok  && year_ok){
       is_valid = true
    } else {
       is_valid = false
    }
} else {
    is_valid = false
}

//if the date is in valid format, we need to check if its logically
//correct for month days and leap years
if (is_valid == true){
  
  int_month = parseInt(seq_numbers[0], 10)
  int_day = parseInt(seq_numbers[1], 10)
  int_year = parseInt(seq_numbers[2], 10)

  
  //gets days in month of febuary by checking the leap year 
  function GetFebuaryCount(year){
    //if it is Not a leap year it has 28 days
    if ((year%4) != 0){
      febuary_count = 28
    }else{ 
      //it IS a leap year and has 29 days
      febuary_count = 29
    }
    return febuary_count
  }
  days_in_month_list = [31,GetFebuaryCount(int_year),31,30,31,30,31,31,30,31,30,31]
  
  if (int_day <= days_in_month_list[int_month-1]){
    return true
  }else{
    return false
  }
}else{
  return is_valid
}

}

function all_digits(value){
   is_all_digits = true
   str_value = value.toString()
   if (value == ""){
      return false
   }

   for (var i = 0; i < value.length; i++) {
       single_char = str_value.charCodeAt(i) 
       if (single_char < 48 || single_char > 58){
            is_all_digits = false
          
       }
   }
   return is_all_digits
}

function isPhone(value) {
     valueStr = value.toString()
if (value.length == null || value.length == "0") return true;

//if (value.length == "0" || value.length < "8") return false;
     var countHash = 0
     for (var i = 0; i < value.length; i++) {
          var hashChar = valueStr.charAt(i)
          if (hashChar == "-") countHash = countHash + 1;
      }
          if (countHash > "2" || countHash < "1" || value.length < 7) return false;

     for (var i = 0; i < value.length; i++) {
          var oneChar = valueStr.charAt(i)
          if (oneChar != "-" && oneChar < "0" || oneChar > "9" || oneChar == " ") {
              return false
          }
     }
     return true
}

function isEmail(value) {
if (value.length == null || value.length == "0") return true;
var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (value.indexOf(".") > 2) && (value.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  var email_status = (!r1.test(value) && r2.test(value))
  if(!email_status){
          return false
     }
     return true
}

function isZip(value) {
     valueStr = value.toString()
if (value.length == null || value.length == "0"){
    return true
}
     if (value.length < "5" || value.length > "10") return false;
     var countHash = 0
     for (var i = 0; i < value.length; i++) {
  
          var hashChar = valueStr.charAt(i)
          if (hashChar == "-") countHash = countHash + 1;
      }
          if (countHash > "1") return false;

     for (var i = 0; i < value.length; i++) {
          var oneChar = valueStr.charAt(i)
          var r1 = new RegExp("[a-zA-Z0-9\\-]");          
          var zip_status = (r1.test(oneChar))
          if(!zip_status){
                return false
             }
//if (oneChar != "-" && oneChar < ("A" || "a") || oneChar > ("Z" || "z") || oneChar == " ") {
//              return false
//          }
     }
     return true
}

function is_dec_int(value){
     str_value = value.toString()
     str_size = str_value.length
     one_digit = false
     is_all_digits = true
     count = 0

     //loop through each individual character and check for validation
     for (var i=0; i < str_size; i++){
          one_char = str_value.charAt(i)
          if (one_char == "."){
             one_digit = true
             count = count + 1
          }else{
             single_char = str_value.charCodeAt(i) 
             if (single_char < 48 || single_char > 58){
                 is_all_digits = false
                 break;
             }
          }
     }
     if (count > 1 || str_size == 1 && one_digit == true || is_all_digits == false){
        return false
     }else{
        return true
     }
}
function isNull(value) {
  if (value.length == null || value.length == "0") return false;
  return true
}

function isSocialSecurity(passed_value){
  str_value = passed_value.toString()
  all_valid_data = false
  if (str_value.length == 11){
    dash_count = 0
    for (var i=0; i < str_value.length; i++){
      if (str_value.charAt(i) == "-"){
        dash_count++
      }
    }
    if (str_value.charAt(3) == "-" && str_value.charAt(6) == "-" && dash_count == 2){
      str_list = str_value.split("-")
      if (all_digits(str_list[0]) && str_list[0].length == 3 && all_digits(str_list[1]) && str_list[1].length == 2 && all_digits(str_list[2]) && str_list[2].length == 4){
        all_valid_data = true
      }
    }
  } 
  return all_valid_data
}

function isValidCustomerNo(customer_no){
  customer_no = customer_no.toString()
  all_valid = false
  for (var i=0; i < customer_no.length; i++){
     //must be 9 characters long to be valid
     if (customer_no.length == 9){
        oneChar = customer_no.charAt(4)
        if (oneChar == "-"){
           left_side = customer_no.substring(0,4)
           right_side = customer_no.substring(5,9)
           if (all_digits(left_side) && all_digits(right_side)){
              all_valid = true
           }
        }
     }
  }
  return all_valid
}
