// JavaScript Document

/////////////////////////////////////
// 汎用確認メッセージ
/////////////////////////////////////
function ConfirmMsg(msg){
	return (confirm(msg))?true:false;
}

/////////////////////////////////////////////////////////////////////////////////
// 未入力及び不正入力のチェック（※Safariのバグ（エスケープ文字認識）を回避）
/////////////////////////////////////////////////////////////////////////////////
function inputChk(f,confirm_flg){

	// フラグの初期化
	var flg = false;
	var error_mes = "Error Message\r\nExcuse me,please confirm the following content.\r\n恐れ入りますが、下記の内容をご確認ください\r\n\r\n";

	// 未入力と不正入力のチェック
	if(!f.select_action.value){
		error_mes += "・Please select the inquiry contents.\r\nお問い合わせ項目をご選択ください。\r\n";flg = true;
	}

	if(!f.man.value && !f.woman.value && !f.child.value && !f.baby.value){
		if(f.select_action.value == "Pre-reservation(空室確認)"){
			error_mes += "・Please fill in the number of people.\r\n人数をご記入ください。\r\n";flg = true;
		}
	}
	if(f.man.value && f.man.value.match(/[^0-9]/) || f.woman.value && f.woman.value.match(/[^0-9]/) || f.child.value && f.child.value.match(/[^0-9]/) || f.baby.value && f.baby.value.match(/[^0-9]/)){
			error_mes += "・Please fill the valid The number of person.\r\n人数は半角数字のみでご記入してください。\r\n";flg = true;
	}

	if(!f.room.value){
		if(f.select_action.value == "Pre-reservation(空室確認)"){
			error_mes += "・Please fill in the hope for the number of rooms.\r\n部屋数の希望をご記入ください。\r\n";flg = true;
		}
	}
	if(f.room.value && f.room.value.match(/[^0-9]/)){
			error_mes += "・Please fill the valid The number of room.\r\n部屋数の希望は半角数字のみでご記入してください。\r\n";flg = true;
	}

	if(!f.in_year.value && !f.in_month.value && !f.in_day.value && !f.out_year.value && !f.out_month.value && !f.out_day.value){
		if(f.select_action.value == "Pre-reservation(空室確認)"){
			error_mes += "・Please fill in the schedule.\r\n日程をご記入ください。\r\n";flg = true;
		}
	}
	if(f.in_year.value && f.in_year.value.match(/[^0-9]/) || f.in_month.value && f.in_month.value.match(/[^0-9]/) || f.in_day.value && f.in_day.value.match(/[^0-9]/) ||
	        f.out_year.value && f.out_year.value.match(/[^0-9]/) || f.out_month.value && f.out_month.value.match(/[^0-9]/) || f.out_day.value && f.out_day.value.match(/[^0-9]/)){
			error_mes += "・Please fill the valid Schedule.\r\n日程は半角数字のみでご記入してください。\r\n";flg = true;
	}

	if(!f.around_time.value){
		if(f.select_action.value == "Pre-reservation(空室確認)"){
			error_mes += "・Please fill in the check-in schedule time.\r\nチェックイン予定時間をご記入ください。\r\n";flg = true;
		}
	}
	if(f.around_time.value && f.around_time.value.match(/[^0-9]/)){
			error_mes += "・Please fill the valid Check-in schedule time.\r\nチェックイン予定時間は半角数字のみでご記入してください。\r\n";flg = true;
	}

	if(!f.name.value){
		error_mes += "・Please fill in your name.\r\nお名前をご記入ください。\r\n";flg = true;
	}
	
	/*if(!f.sex.value){
		 if(!f.sex[0].checked && !f.sex[1].checked){
			error_mes += "・性別をご選択ください。\r\n";flg = true;
		 }
	}*/
	
	if(!f.kokuseki.value){
		error_mes += "・Please fill in your Nationality.\r\n国籍をご記入ください。\r\n";flg = true;
	}

	if(!f.email.value){
		error_mes += "・Please fill in the E-mail address.\r\nE-mailをご記入ください。\r\n";flg = true;
	}
	else if(!f.email.value.match(/^[^@]+@[^.]+\..+/)){
		error_mes += "・Please fill the valid E-mail address.\r\nE-mailの形式に誤りがあります。\r\n";flg = true;
	}
	
	if(!f.tel.value){
		if(f.select_action.value == "Pre-reservation(空室確認)"){
			error_mes += "・Please fill in Telephone number.\r\n電話番号をご記入ください。\r\n";flg = true;
		}
	}	
	if(f.tel.value && f.tel.value.match(/[^0-9]/)){
			error_mes += "・Please fill the valid Telephone number.\r\n電話番号は半角数字のみでご記入してください。\r\n";flg = true;
	}

	if(f.fax.value && f.fax.value.match(/[^0-9]/)){
			error_mes += "・Please fill the valid Fax number.\r\nFAX番号は半角数字のみでご記入してください。\r\n";flg = true;
	}

	if(!f.comment.value){
		if(f.select_action.value !== "Pre-reservation(空室確認)"){
			error_mes += "・Please fill in Question to us.\r\nお問い合わせ内容をご記入ください。\r\n";flg = true;
		}
	}

	
	// 判定
	if(flg){
		// アラート表示して再入力を警告
		window.alert(error_mes);return false;
	}
	else{

		// 確認メッセージ
		if(confirm_flg){
			return ConfirmMsg('Are you sure that you want to send this email?\r\nご入力いただいた内容で送信します。\nよろしいですか？');
		}
		return true;
	}


}

