function CheckLength(str,flg) {
     for (var i = 0; i < str.length; i++) {
         var c = str.charCodeAt(i);
         // Shift_JIS: 0x0 ～ 0x80, 0xa0 , 0xa1 ～ 0xdf , 0xfd ～ 0xff
         // Unicode : 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3
         if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
             if(!flg) return true;
         } else {
             if(flg) return true;
         }
     }
     return false;
 }

// ******************************************************************************************************************************************
// 引数で渡された文字列が半角文字かどうかチェックする
// ******************************************************************************************************************************************
function isHanCheck(str) {
	var result = str.match(/[0-9a-zA-Z_\-\.@[]:; ]*/);
	if ( str == result ) {
		return true;
	} else {
		return false;
	}
}
// ******************************************************************************************************************************************
// 引数で渡された文字列が半角英数字かどうかチェックする
// ******************************************************************************************************************************************
function isAlpNumCheck(str) {
	var result = str.match(/[0-9a-zA-Z ]*/);
	if ( str == result ) {
		return true;
	} else {
		return false;
	}
}

// ******************************************************************************************************************************************
// 引数で渡された文字列が半角数字かどうかチェックする
// ******************************************************************************************************************************************
function isNumCheck(str) {
	var result = str.match(/[0-9 ]*/);
	if ( str == result ) {
		return true;
	} else {
		return false;
	}
}

// ******************************************************************************************************************************************
// 引数で渡された文字列がメールアドレスとして有効かどうかチェックする
// ******************************************************************************************************************************************
function isMailAddrCheck(str) {
	
	return (str!=""&&str.match(/^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9_\-]+(\.[a-zA-Z0-9_\-]+)+$/)!=null)
	
}

// ******************************************************************************************************************************************
// 引数で渡された文字列のバイト数をカウントする
// 全角は２バイト　半角は１バイト
// ******************************************************************************************************************************************
function count_tLength(s)
{
	var r = 0;
	for (var i = 0; i < s.length; i++) {
		var c = s.charCodeAt(i);
		// Shift_JIS: 0x0 ～ 0x80, 0xa0  , 0xa1   ～ 0xdf  , 0xfd	～ 0xff
		// Unicode	: 0x0 ～ 0x80, 0xf8f0, 0xff61 ～ 0xff9f, 0xf8f1 ～ 0xf8f3
		if ( (c >= 0x0 && c < 0x81) || (c == 0xf8f0) || (c >= 0xff61 && c < 0xffa0) || (c >= 0xf8f1 && c < 0xf8f4)) {
			r += 1;
		} else {
			r += 2;
		}
	}
	return r;
}

// ******************************************************************************************************************************************
// 入力値が半角数字かどうかのチェック（＋、－は含まない）
// ******************************************************************************************************************************************
function IsNumericalValue( vtype, check_value )
{
	var number_string, i;
	
	if ( vtype == "date" ) {
		// 日付用
		number_string = "0123456789/"
	} else if ( vtype == "decimal" ) {
		// float用
		number_string = "0123456789."
	} else {
		// Integer用
		number_string = "0123456789"
	}
	
	if ( vtype != "date" ) {
		var tempValue = parseInt( check_value );
		if ( isNaN(tempValue) ) {
			return false;
		}
	}
	
	if ((check_value == "") || (check_value == null)) {
		return false;
	}
	//0123456789以外の文字が使われている場合
	for ( i = 0; i < check_value.length; i++ ) {
		if (number_string.indexOf(check_value.substring(i,i+1)) == -1) {
			return false;
		}
	}
	return true;
}

// ******************************************************************************************************************************************
// 入力された年月日が日付として有効かどうかをチェックする
// ******************************************************************************************************************************************
function IsValidDate( v_value )
{
	var v_yy, v_mm, v_dd;
	var strDate;
	
	strDate = v_value.split("/");
	if ( strDate.length < 3 ) {
		return false;
	}
	v_yy = parseInt( strDate[0], 10 );
	v_mm = parseInt( strDate[1], 10 );
	v_dd = parseInt( strDate[2], 10 );

	if (isNaN(v_yy) || isNaN(v_mm) || isNaN(v_dd)) {
		return(false);
	}
	
	// invalid month
	if ((v_mm < 1) || (v_mm > 12)) {
		return(false);
	}
	// invalid date
	if ((v_mm == 1) || (v_mm == 3) || (v_mm == 5) || (v_mm == 7) || (v_mm == 8) || (v_mm == 10) || (v_mm == 12)) {
		if ((v_dd < 1) || (v_dd > 31)) {
			return(false);
		}
	} else {
		if ((v_dd < 1) || (v_dd > 30)) {
			return(false);
		}
	}
	// check leap year	
	if (v_mm == 2) {
		if ((v_yy % 400 == 0) || ((v_yy % 4 == 0) && (v_yy % 100 != 0))) {
			if (v_dd > 29){return(false);}		// invalid date, leap year
		} else {
			if (v_dd > 28){return(false);}		// invalid date, not leap year
		}
	}	
	return(true);
}

// ******************************************************************************************************************************************
// パスワードの禁止文字が存在しないかどうかのチェック（< > [ ] ( ) { } + / % = \ ）
// ******************************************************************************************************************************************
function forbidPassword( check_value )
{
	// 『<』のチェック
	var check_t = "";
	check_t = check_value.match("<") ;
	if (check_t == "<") {
		return true;
	}
	
	// 『>』のチェック
	check_t = "";
	check_t = check_value.match(">") ;
	if (check_t == ">") {
		return true;
	}
	
	// 『[』のチェック
	check_t = "";
	check_t = check_value.match(/\[/i) ;
	if (check_t == "[") {
		return true;
	}
	
	// 『]』のチェック
	check_t = "";
	check_t = check_value.match(/\]/i) ;
	if (check_t == "]") {
		return true;
	}
	
	// 『(』のチェック
	check_t = "";
	check_t = check_value.match(/\(/i) ;
	if (check_t == "(") {
		return true;
	}
	
	// 『)』のチェック
	check_t = "";
	check_t = check_value.match(/\)/i) ;
	if (check_t == ")") {
		return true;
	}
	
	// 『{』のチェック
	check_t = "";
	check_t = check_value.match(/\{/i) ;
	if (check_t == "{") {
		return true;
	}
	
	// 『}』のチェック
	check_t = "";
	check_t = check_value.match(/\}/i) ;
	if (check_t == "}") {
		return true;
	}
	
	// 『+』のチェック
	check_t = "";
	check_t = check_value.match(/\+/i) ;
	if (check_t == "+") {
		return true;
	}
	
	// 『/』のチェック
	check_t = "";
	check_t = check_value.match(/\//i) ;
	if (check_t == "/") {
		return true;
	}
	
	// 『%』のチェック
	check_t = "";
	check_t = check_value.match("%") ;
	if (check_t == "%") {
		return true;
	}
	
	// 『=』のチェック
	check_t = "";
	check_t = check_value.match("=") ;
	if (check_t == "=") {
		return true;
	}
	
	// 『\』のチェック
	check_t = "";
	check_t = check_value.match(/\\/i) ;
	if (check_t == "\\") {
		return true;
	}
	
	return false;
}


