﻿
// author：M.Shibahara @ http://e-optimize.jp


// ----------------------------------------------------------------
// フォーカス
// ----------------------------------------------------------------
function fncblnFocus(obj) 
{ 
	obj.focus(); 
} 

// ----------------------------------------------------------------
// メッセージ１
// ----------------------------------------------------------------
function fncAlertEmpty(strMsg) 
{ 
	strM = "";
	strM = strM + "[ " + strMsg + " ] を入力してください。";
	strM = strM + "\n";
	alert( strM );
} 

function fncAlertEmptyEnglish(strMsg) 
{ 
	strM = "";
	strM = strM + "There is no \[ " + strMsg + " \] entered\.\n";
	strM = strM + "\n";
	alert( strM );
} 

// ----------------------------------------------------------------
// メッセージ２
// ----------------------------------------------------------------
function fncAlertIncre(strMsg) 
{ 
	strM = "";
	strM = strM + "[ " + strMsg + " ] を正しく入力してください。";
	strM = strM + "\n";
	alert( strM );
} 

function fncAlertIncreEnglish(strMsg) 
{ 
	strM = "";
	strM = strM + "Please enter \[ " + strMsg + " \] correctly\.\n";
	strM = strM + "\n";

	alert( strM );
} 

// ----------------------------------------------------------------
// インプットの背景色設定
// ----------------------------------------------------------------
function fncBlnInputBGColor(objWork, clrWork) 
{ 
	objWork.style.backgroundColor = clrWork;
	return true;
}

// ----------------------------------------------------------------
// 未入力チェック（空文字不可）
// ----------------------------------------------------------------
function fncBlnInputEmpty(strWork) 
{ 
	if(strWork == "")
	{ 
		return false; 
	}
	else 
	{ 
		return true;
	} 
}

// ----------------------------------------------------------------
// 全角かなチェック（ひらがな以外不可）
// ----------------------------------------------------------------
function fncBlnInputHiraKana(strWork) 
{
	if(strWork.match( /[^ぁ-ん]+/ ))
	{ 
		return false; 
	}
	else 
	{ 
		return true;
	} 
}

// ----------------------------------------------------------------
// 全角カナチェック（全角カタカナ以外不可）
// ----------------------------------------------------------------
function fncBlnInputKataKana(strWork) 
{
	if(strWork.match( /[^ァ-ン]+/ ))
	{ 
		return false; 
	}
	else 
	{ 
		return true;
	} 
}

// ----------------------------------------------------------------
// 半角文字チェック（半角文字以外不可）
// ----------------------------------------------------------------
function fncBlnInputHalf(strWork) 
{
	if(strWork.match( /[^0-9A-Za-z_\x2D.]+/ ))
	{ 
		return false; 
	}
	else 
	{ 
		return true;
	} 
}

// ----------------------------------------------------------------
// 半角数字チェック（半角数字以外不可）
// ----------------------------------------------------------------
function fncBlnInputNumber(strWork) 
{
	if(strWork.match( /[^0-9]+/ ))
	{ 
		return false; 
	}
	else 
	{ 
		return true;
	} 
}

// ----------------------------------------------------------------
// 半角英字チェック（半角英字以外不可）
// ----------------------------------------------------------------
function fncBlnInputAlpha(strWork) 
{
	if(strWork.match( /[^A-Za-z]+/ ))
	{ 
		return false; 
	}
	else 
	{ 
		return true;
	} 
}

// ----------------------------------------------------------------
// メールアドレスチェック（規定フォーマット以外不可）
// ----------------------------------------------------------------
function fncBlnInputMail(strWork) 
{ 
	if(strWork.match( /[0-9A-Za-z_\x2D.]+@[0-9A-Za-z_\x2D.]+\.[0-9A-Za-z_\x2D]+/ ) == null)
	{ 
		return false; 
	}
	else 
	{ 
		return true;
	}
}

// ----------------------------------------------------------------
// 電話番号チェック（規定フォーマット以外不可）
// ----------------------------------------------------------------
function fncBlnInputPhoneNumber(strWork) 
{ 
	if(strWork.match( /^[0-9]+\-[0-9]+\-[0-9]+$/ ) == null)
	{ 
		return false; 
	}
	else 
	{ 
		return true;
	}
} 

// ----------------------------------------------------------------
// ラジオボックス選択チェック
// ----------------------------------------------------------------
function fncStrInputCheckRadioBox(objRadio) 
{
	strWork = '';
	for ( intI = 0; intI < objRadio.length; intI++ ) 
	{ 
		if ( objRadio[intI].checked == true ) 
		{ 
			strWork = objRadio[intI].value;
			return strWork;
		} 
	} 
	return strWork;
}

// ----------------------------------------------------------------
// チェックボックス選択チェック
// ----------------------------------------------------------------
function fncStrInputCheckCheckBox(objCheck) 
{
	strWork = '';
	if ( objCheck.checked == true ) 
	{ 
		strWork = objCheck.value;;
	} 
	return strWork;
}

// ----------------------------------------------------------------
// 誕生日算出
// ----------------------------------------------------------------
function fncIntCalcBirth(intYear, intMonth, intDay) 
{ 
	objNow      = new Date();
	intNowYear  = objNow.getFullYear();
	intNowMonth = objNow.getMonth() + 1;
	intNowDay   = objNow.getDate();

	intAge = 0;
	intAge = intNowYear - intYear;

	if (intMonth < intNowMonth )
	{ 
		intAge = intAge;
	} 
	else
	{ 
		if ( intMonth > intNowMonth ) 
		{ 
			intAge = intAge - 1;
		} 
		else 
		{ 
			if ( intDay > intNowDay ) 
			{ 
				intAge = intAge - 1;
			} 
			else 
			{ 
				intAge = intAge;
			} 
		} 
	} 

	return intAge;
} 

// ----------------------------------------------------------------
// 日付の妥当性チェック
// ----------------------------------------------------------------
function fncBlnDateCheck(strY, strM, strD)
{ 
	if ( strY != '' ) 
	{ 
		if ( strM != '' ) 
		{ 
			if ( strD != '' ) 
			{ 
				intY = parseInt(strY);
				intM = parseInt(strM);
				intD = parseInt(strD);

				switch ( intM )
				{ 
					case 4:
					case 6:
					case 9:
					case 11:
						if ( intD > 30 )
						{ 
							return false;
						} 
						else 
						{ 
							return true;
						} 
						break;
					case 2:
						if (( (intY % 4 == 0) && (intY % 100 != 0) ) || (intY % 400 == 0) ) 
						{ 
							if ( intD > 29 )
							{ 
								return false;
							} 
							else 
							{ 
								return true;
							} 
						} 
						else 
						{ 
							if ( intD > 28 )
							{ 
								return false;
							} 
							else 
							{ 
								return true;
							} 
						} 
						break;
					default:
						return true;
				} 
			} 
			else 
			{ 
				return false;
			} 
		} 
		else 
		{ 
			return false;
		} 
	} 
	else 
	{ 
		if ( strM != '' ) 
		{ 
			return false;
		} 
		else 
		{ 
			if ( strD != '' ) 
			{ 
				return false;
			} 
			else 
			{ 
				return true;
			} 
		} 
	} 
} 
