
/**
 * @version 0.2
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/25
 * Function that checks if the String is of bigger or equal than the Min. Length
 * @param str1 the value to be checked
 * @param minSize the required min. size
 * @return true if the string contains only digits
 */
    function isMinSize(str1, minSize) {
      var trimmedString = Trim(str1);
      if (trimmedString.length >= minSize) {
          return true;
      }
      return false;
    }

/**
 * @version 0.2
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/25
 * Function that checks if the String is lesser or equal than the Max. Length
 * @param str1 the value to be checked
 * @param maxSize the required max. size
 * @return true if the string contains only digits
 */
    function isMaxSize(str1, maxSize) {
      var trimmedString = Trim(str1);
      if (trimmedString.length <= maxSize) {
          return true;
      }
      return false;
    }

/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if the String contains Numeric Digits ([0-9]) only
 * @param str1 the value to be checked
 * @return true if the string contains only digits
 */
    function isNumericDigits(str1) {
      err = 0;
      for (i=0;i<str1.length;i++){
        code = str1.charCodeAt(i);
        asciisymbol = "0123456789";
        if (asciisymbol.indexOf(str1.charAt(i)) > -1) {
            // Do Nothing
        }
        else {
          err++;
        }
      }
      if (err!=0) {
        return false;
      }
      else {
        return true;
      }
    }


/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if the String is not empty
 * @param strValue the value to be checked
 * @return true if the string is empty
 */
    function isEmpty(strValue) {
        if (Trim(strValue) == "") {
            return true;
        }
        return false;
    }

/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if the string contains 2 bytes characters only (for example: Kanji, Katakana, Hiragana but not non-hankaku-kana), do not allow the space
 * @param  str1 the String to be validated
 * @return true if the string is only 2 bytes characters.
 */
    function isKanjiOr(str1){
      err = 0;
      for (i=0;i<str1.length;i++){
        code = str1.charCodeAt(i);
        onebytechars = "ｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜｦﾝｧｨｩｪｫｯｬｭｮ､｡｢｣ﾞﾟ!\"#$%&'()-^\\=~|@[;:],./`{+*}<>?_ ";
        if (onebytechars.indexOf(str1.charAt(i)) > -1) {
          err++;
        }
        else if ((48<=code && code <=57) || (65<= code && code <=90) || (97 <= code && code <= 122)) {
          err++;
        }
        else {
        }
      }
      if (err!=0) {
        return false; // includes 1byte char
      }
      else {
        return true; // is all 2byte chars
      }
    }


/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if the String contains Hankukukana characters
 * @param str1 the string to be checked
 * @return a boolean value to indicate
 */
    function hasHankakukana(str1){
      err = 0;
      for (i=0;i<str1.length;i++){
        code = str1.charCodeAt(i);
        onebytechars = "ｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜｦﾝｧｨｩｪｫｯｬｭｮ､｡｢｣ﾞﾟ";
        if (onebytechars.indexOf(str1.charAt(i)) > -1) {
          err++;
        }
        else {
        }
      }
      if (err!=0) {
        return true; // includes hankaku-kana
      }
      else {
        return false; // is all 2byte chars or ASCII chars
      }
    }

/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if string is compossed of Hankukakana characters.
 * @param inputStr the string to be checked
 * @return true if the whole string is compossed of Hankukakana characters.
 */
    function isHankakukana(inputStr)
    {
        err = 0;
        if (inputStr == null || inputStr == "") {
            //return false; // if you want to check empty value
        }
        for (i=0;i<inputStr.length;i++){
            hankakukana = "ｱｲｳｴｵｶｷｸｹｺｻｼｽｾｿﾀﾁﾂﾃﾄﾅﾆﾇﾈﾉﾊﾋﾌﾍﾎﾏﾐﾑﾒﾓﾔﾕﾖﾗﾘﾙﾚﾛﾜｦﾝｧｨｩｪｫｯｬｭｮ､｡｢｣ﾞﾟ";
            if (hankakukana.indexOf(inputStr.charAt(i)) > -1) {
            }
            else {
                err++;
            }
        }
        if (err!=0) {
            return false;
        }
        else {
            return true;
        }
    }

/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if the String is Katakana
 * @param str1 the string to be checked
 * @return true if the string is katakana
 */
    function isKatakana(str1){
        var RE = /^[ァ-ヶ・ーヽヾ]*$/
        if(RE.test(str1) == true) {
            return true;
        }
        else {
            return false;
        }
    }

/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if the whole string is a "pure-japanese" string (checks if all the characters are 2byte characters).
 * @param str1 the string to be checked
 * @return true if the whole string is a "pure-japanese" string (checks if all the characters are 2byte characters).
 */
    function isJapanese(str1) {
        var i;
        for(i=0; i < str1.length; i++) {
            if(escape(str1.charAt(i)).length < 4) {
                return false;
            }
        }
        return true;
    }

/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if the string has a "Pound" sign
 * @param str1 the string to be checked
 * @return true if the string has a "Pound" sign
 */
    function hasPoundSign(str1){
      pound = 0;
      for (i=0;i<str1.length;i++){
        code = str1.charCodeAt(i);
        asciisymbol = "@";
        if (asciisymbol.indexOf(str1.charAt(i)) > -1) {
            pound++;
        }
      }
      if (pound == 0) { // if it didn't find the found sign
        return false;
      }
      else {
        return true;
      }
    }

/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if all characters use Ascii Characters
 * @param str1 the string to be checked
 * @return true if all characters use Ascii Characters
 */
    function isAllAsciistr(str1){
      err = 0;
      for (i=0;i<str1.length;i++){
        code = str1.charCodeAt(i);
        asciisymbol = "!\"#$%&'()-^\\=~|@[;:],./`{+*}<>?_ ";
        if (asciisymbol.indexOf(str1.charAt(i)) > -1) {
        }
        else if ((48<=code && code <=57) || (65<= code && code <=90) || (97 <= code && code <= 122)) {
        }
        else {
          err++;
        }
      }
      if (err!=0) {
        return false;
      }
      else {
        return true;
      }
    }

/**
 * @version 0.3
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if the Date is a valid date (for example, do not allow 31th February). Do not allows values below or equal the year 1900 or above or equal the year 2070
 * @param yyyy The year (in the 4-digits YYYY format)
 * @param mm The month
 * @param dd The day
 * @return true if the date is not valid
 */
    function isValidDate(yyyy, mm, dd) {
        /* Start Addition by Ricardo */
        /* Check first if the given parameters are valid numerical digits (natural values) */
        if (!isNumericDigits(yyyy)) {
            return false;
        }
        if (!isNumericDigits(mm)) {
            return false;
        }
        if (!isNumericDigits(dd)) {
            return false;
        }
        /* End Addition by Ricardo */

        if (mm < 01 || mm > 12) {
            return false;
        }

        if (yyyy > 2070 || yyyy < 1900) {
            return false;
        }

        if ((mm == 4 || mm == 6 || mm == 9 || mm == 11) && (dd < 1 || dd > 30)) {
            return false;
        }

        if ((mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) && (dd < 1 || dd > 31)) {
            return false;
        }

        if (mm == 2) {
            if(((yyyy % 400 != 0 && yyyy % 100 == 0) || yyyy % 4 != 0) && (dd < 1 || dd > 28)) {
                return false;
            }
            if ((yyyy % 400 == 0 || yyyy % 4 == 0) && (dd < 1 || dd > 29)) {
                return false;
            }
        }

        return true;
    }


/**
 * @version 0.2
 * @author Okada
 * @author <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that checks if the date is ok (for example, don't allow a Month 13).
 * @param yy the year in a 2-digit YY format
 * @param mm the month
 * @return false if the date is not valid
 */
    function isValidShortDate(yy, mm){
        if (yy < 0) {
            return false;
        }
        var yyyy = "20" + yy;
        if (mm < 01 || mm > 12) {
            return false;
        }
        return true;
    }

/**
 * @version 0.2
 * @comments <a href="mailto:ricardo@hottolink.co.jp">Ricardo Leon</a>
 * @date 2002/08/21
 * Function that trims the spaces of a String on both sides
 * @param inString the string to be trimmed
 * @return a String with the same contents but without the spaces at the ends
 */
function Trim(inString) {
  var retVal = "";
  var start = 0;
  while ((start < inString.length) && (inString.charAt(start) == ' ')) {
    ++start;
  }
  var end = inString.length;
  while ((end > 0) && (inString.charAt(end - 1) == ' ')) {
    --end;
  }
  retVal = inString.substring(start, end);
  return retVal;
}

/**
 * @version 0.1
 * @comments <a href="mailto:pravin@hottolink.co.jp">Pravin Bhirud</a>
 * @date 2003/09/24
 * Function that checks whether the inserted email is valid
 * @return true if ut is valid or false otherwise
 */

    function isValidEmail(strEmail){
        var em=strEmail;
        var x=strEmail.indexOf("@");
        var y=strEmail.indexOf(".");
        if(x<1){
            return false;
        }
        //if(y<(x+2)){
        //    return false;
        //}
        var check_text ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-%@";
        for( i = 0; i <em.length; i++) {
            if(check_text.indexOf(em.charAt(i)) ==-1){
                return false;
            }
        }
        return true;
    }

/**
 * @version 0.1
 * @author Meiko Yasukawa
 * @date 2005/07/19
 * Function that checks if the Date is a future day.
 * @param yyyy The year (in the 4-digits YYYY format)
 * @param mm The month
 * @param dd The day
 * @return true if the date is not valid
 */
    function isFutureDate(yyyy, mm, dd) {
        var inputDate = new Date(yyyy, mm-1, dd);
        var today = new Date();
        var today2 = new Date(today.getYear(), today.getMonth(), today.getDate());
        if(inputDate.getTime() - today2.getTime() > 0) {
            return true;
        }
        return false;
    }

/* End of File*/

