// =================================================================================================
//
//
//
// =================================================================================================


// =================================================================================================
//
// 送信ボタン入力項目チェック
//
// =================================================================================================
jQuery(function(){
	// =============================================================================================
	//
	// 送信ボタン押下時イベント
	//
	// =============================================================================================
	jQuery("#b_sbmt").click(function(){
		// -----------------------------------------------------------------------------------------
		// 変数定義と初期化
		// -----------------------------------------------------------------------------------------
		// エラーチェック用
		var u_error_focus = 0;

		// -----------------------------------------------------------------------------------------
		// 初期化
		// -----------------------------------------------------------------------------------------
		jQuery("#r_y_error").css("display", "none");
		jQuery("#r_y_error").html("");

		jQuery("#tel_error").css("display", "none");
		jQuery("#tel_error").html("");

		jQuery("#add_error").css("display", "none");
		jQuery("#add_error").html("");

		jQuery("#cmnt_error").css("display", "none");
		jQuery("#cmnt_error").html("");

		jQuery("#mail2_error").css("display", "none");
		jQuery("#mail2_error").html("");

		jQuery("#mail_error").css("display", "none");
		jQuery("#mail_error").html("");

		jQuery("#name_error").css("display", "none");
		jQuery("#name_error").html("");

		jQuery("#purpose_error").css("display", "none");
		jQuery("#purpose_error").html("");


		// -----------------------------------------------------------------------------------------
		// ご予約の方のチェック
		// -----------------------------------------------------------------------------------------
		if ( document.contact.purpose[1].checked == true ) {
			// 予約日入力チェック

			if ( document.contact.r_m.value == "" )  {
				jQuery("#r_y_error").css("display", "block");
				jQuery("#r_y_error").html("ご予約日をご入力下さい");
				u_error_focus = 7;
			}

			if ( document.contact.r_d.value == "" )  {
				jQuery("#r_y_error").css("display", "block");
				jQuery("#r_y_error").html("ご予約日をご入力下さい");
				u_error_focus = 7;
			}

			if ( document.contact.r_t.value == "" )  {
				jQuery("#r_y_error").css("display", "block");
				jQuery("#r_y_error").html("ご予約日をご入力下さい");
				u_error_focus = 7;
			}

			if ( document.contact.r_min.value == "" )  {
				jQuery("#r_y_error").css("display", "block");
				jQuery("#r_y_error").html("ご予約日をご入力下さい");
				u_error_focus = 7;
			}

			// 電話番号入力チェック
			if ( document.contact.tel.value == "" )  {
				jQuery("#tel_error").css("display", "block");
				jQuery("#tel_error").html("電話番号をご入力下さい");
				u_error_focus = 6;
			}

			// 住所入力チェック
			if ( document.contact.add.value == "" )  {
				jQuery("#add_error").css("display", "block");
				jQuery("#add_error").html("住所をご入力下さい");
				u_error_focus = 5;
			}
		}

		if ( document.contact.purpose[0].checked == true ) {
			// お問い合わせ内容入力チェック
			if ( document.contact.cmnt.value == "" )  {
				jQuery("#cmnt_error").css("display", "block");
				jQuery("#cmnt_error").html("お問い合わせ内容をご入力下さい");
				u_error_focus = 8;
			}
		}

		// メールアドレス(確認)入力チェック
		if ( document.contact.mail2.value == "" )  {
			jQuery("#mail2_error").css("display", "block");
			jQuery("#mail2_error").html("メールアドレス(確認)を御入力下さい");
			u_error_focus = 4;
		} else {
			if ( document.contact.mail.value != document.contact.mail2.value )  {
				jQuery("#mail2_error").css("display", "block");
				jQuery("#mail2_error").html("メールアドレス(確認)のご入力が間違えています");
				u_error_focus = 4;
			}
		}

		// メールアドレス入力チェック
		if ( document.contact.mail.value == "" )  {
			jQuery("#mail_error").css("display", "block");
			jQuery("#mail_error").html("メールアドレスを御入力下さい");
			u_error_focus = 3;
		}

		// お名前入力チェック
		if ( document.contact.name.value == "" )  {
			jQuery("#name_error").css("display", "block");
			jQuery("#name_error").html("お名前を御入力下さい");
			u_error_focus = 2;
		}

		// ご希望内容チェック
		if (( document.contact.purpose[0].checked == false ) && ( document.contact.purpose[1].checked == false )) {
			jQuery("#purpose_error").css("display", "block");
			jQuery("#purpose_error").html("ご希望内容をご選択下さい");
			u_error_focus = 1;
		}

		// -----------------------------------------------------------------------------------------
		// エラー無し
		// -----------------------------------------------------------------------------------------
		if ( u_error_focus == 0 ) {
			return true;
		} else {
			// -------------------------------------------------------------------------------------
			// エラー発生時のジャンプ先
			// -------------------------------------------------------------------------------------
			window.location.hash = "#contact";
			switch(u_error_focus) {
			case 1:
				document.contact.purpose[0].focus();
				break;
			case 2:
				document.contact.name.focus();
				break;
			case 3:
				document.contact.mail.focus();
				break;
			case 4:
				document.contact.mail2.focus();
				break;
			case 8:
				document.contact.cmnt.focus();
				break;
			case 5:
				document.contact.add.focus();
				break;
			case 6:
				document.contact.tel.focus();
				break;
			case 7:
				document.contact.r_m.focus();
				break;
			}
			return false;
		}
    });
	// =============================================================================================
	//
	// 	やり直し押下時イベント
	//
	// =============================================================================================
	jQuery("#b_rst").click(function(){
		// -----------------------------------------------------------------------------------------
		// 初期化
		// -----------------------------------------------------------------------------------------
		jQuery("#r_y_error").css("display", "none");
		jQuery("#r_y_error").html("");

		jQuery("#tel_error").css("display", "none");
		jQuery("#tel_error").html("");

		jQuery("#add_error").css("display", "none");
		jQuery("#add_error").html("");

		jQuery("#cmnt_error").css("display", "none");
		jQuery("#cmnt_error").html("");

		jQuery("#mail2_error").css("display", "none");
		jQuery("#mail2_error").html("");

		jQuery("#mail_error").css("display", "none");
		jQuery("#mail_error").html("");

		jQuery("#name_error").css("display", "none");
		jQuery("#name_error").html("");

		jQuery("#purpose_error").css("display", "none");
		jQuery("#purpose_error").html("");

		window.location.hash = "#pmap";
		window.location.hash = "#contact";
		return true;
    });
});



