﻿// 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\n恐れ入りますが、下記の内容をご確認ください\r\n\r\n";

	// 未入力と不正入力のチェック
	if(!f.name.value){
		error_mes += "・ご氏名をご記入下さい。\r\n";flg = true;
	}

	if(!confirm_flg){
		if(!f.sex[0].checked && !f.sex[1].checked){
			error_mes += "・性別をご選択下さい。\r\n";flg = true;
		}
	}

	if(!f.school_name.value){
		error_mes += "・学校名をご記入下さい。\r\n";flg = true;
	}

	if(!f.grade.value){
		error_mes += "・学年をご選択下さい。\r\n";flg = true;
	}

	if(f.email.value && !f.email.value.match(/^[^@]+@[^.]+\..+/)){
		error_mes += "・メールアドレスの形式に誤りがあります。\r\n";flg = true;
	}

	if(!f.comment.value){
		error_mes += "・動機をご記入下さい。\r\n";flg = true;
	}
	
	// 判定
	if(flg){
		// アラート表示して再入力を警告
		window.alert(error_mes);return false;
	}
	else{

		// 確認メッセージ
		if(confirm_flg){
			return ConfirmMsg('ご入力いただいた内容で送信します。\nよろしいですか？');
		}
		return true;
	}


}


