﻿// ------------------------------------------------------------------------------
// 【目次】
//		-- 標準機能 --
// 		unspacer(str_id)										空白文字しか入力がない場合にエラー表示。
// 		eng_spelling_check(str_id)					禁則文字しか入力がない場合にエラー表示。
// 		normal_width_input(str_id)					半角数字でない時にエラー表示。
// 		email_check(str_id)									メールアドレス正規化。
// 		move_next(str_id, next_str_id, num)	郵便番号から住所自動割当。
//		-- カスタマイズ機能 --
// 		disabled_area(str_id)								入力枠　可能・不可能モード。
// 		disabled_block(str_id)							ブロック表示・非表示モード。
// ------------------------------------------------------------------------------

// ------------------------------------------------------------------------------
// HTML側
// <input type="text" name="お名前" value="" id="onamae" onchange="unspacer('onamae')" />
// 	ポイント・・・idで指定。onchange="unspacer('id名')とする。
// ------------------------------------------------------------------------------

// ---------------------------------------------------------------
// 条件別チェック
// ---------------------------------------------------------------
function check_in(){
	//予約
	if(document.getElementById('inq01').checked){
		if(document.getElementById('tel').value == ''){
			alert("電話番号が記載されていません。");
			document.getElementById('tel').focus();
		}else if(document.getElementById('member').value == ''){
			alert("会員番号が記載されていません。");
			document.getElementById('member').focus();
		}
	//見学
	}else if(document.getElementById('inq02').checked){
		if(document.getElementById('tel').value == ''){
			alert("電話番号が記載されていません。");
			document.getElementById('tel').focus();
		}else if(document.getElementById('division').value == ''){
			alert("都道府県が選択されていません。");
			document.getElementById('division').focus();
		}else if(document.getElementById('address').value == ''){
			alert("都道府県以下の住所が記載されていません。");
			document.getElementById('address').focus();
		}
		}else if(document.getElementById('select_cal').value == ''){
			alert("第1希望日時が記載されていません。");
			document.getElementById('select_cal').focus();
		}		
	}
}





// ---------------------------------------------------------------
// 空白文字しか入力がない場合にエラー表示。
// ---------------------------------------------------------------
function unspacer(str_id) {
	// 初期設置
	var flag_space = 0;
	var flag_text = 0;
	
	var num = document.getElementById(str_id).value.length;
	var str = document.getElementById(str_id).value;
	for(var i = 0; i < num; i ++){
		if(str.charAt(i) == ' ' || str.charAt(i) == '　'){
			flag_space = 1;
		}else{
			// 空白以外が存在する場合
			flag_text = 1;
		}
	}
	// 空白だけしか記載されていない場合は抹消
	if(flag_space == 1 && flag_text == 0){
		alert("スペースしか記入されておりません。再度ご確認ください。");
		document.getElementById(str_id).value = '';
	}
}


// ---------------------------------------------------------------
// 禁則文字しか入力がない場合にエラー表示。
// 全角文字（スペース除く）・半角カタカナ以外がNG
// ---------------------------------------------------------------
function eng_spelling_check(str_id){
	// 初期設置
	var flag_ngword = 0;
	var flag_text = 0;
	
	var num = document.getElementById(str_id).value.length;
	var str = document.getElementById(str_id).value;
	var str_v;
	for(var i = 0; i < num; i ++){
		str_v = str.charAt(i);
		if(str_v.match(/[ -~|　]/g)){
			flag_ngword = 1;
		}else{
			// 半角英語以外が存在する場合
			flag_text = 1;
		}
	}
	// 半角英語だけしか記載されていない場合は抹消
	if(flag_ngword == 1 && flag_text == 0){
		alert("不正な文字列です。再度ご確認ください。");
		document.getElementById(str_id).value = '';
	}
}


// ---------------------------------------------------------------
// 半角数字でない時にエラー表示。
// ---------------------------------------------------------------
function normal_width_input(str_id) {
	c = document.getElementById(str_id).value;
	if(c.match(/[^0-9]/g)){
		document.getElementById(str_id).value = '';
		alert("半角数字で入力してください。");
	}
}


// ---------------------------------------------------------------
// メールアドレス正規化。
// ---------------------------------------------------------------
function email_check(str_id) {
	c = document.getElementById(str_id).value;
	check = /.+@.+\..+/;
	if(!c.match(check)){
		document.getElementById(str_id).value = '';
		alert("メールアドレスが正しくありません。");
	}
}


// ---------------------------------------------------------------
// 次の枠へ移動。
// ---------------------------------------------------------------
function move_next(str_id, next_str_id, num) {
  if (str_id.value.length >= num) {
    document.getElementById(next_str_id).focus();
  }
}



// ------------------------------------------------------------------------------
// disabled = true　の場合、入力POSTデータとしてすら飛びません。
// 
// HTML側
// 個人の場合はチェックを入れる
// <input type="checkbox" name="お客様分類" value="yes" id="kind" onclick="disabled_check('kind')" />
// 個人<input type="text" name="お名前" value="" id="person_name" />
// 法人<input type="text" name="お名前" value="" id="cliant_name" />
// 
// と記述しておくと、チェックが入った時とのみ、個人の方のテキストボックスが
// 記入可能になる。逆に不可視状態であれば、POSTデータすら飛ばない為、データ重複もなくなる。
// 注意：このケースの場合、初めから読み込ます必要がある為、<body onload="disabled_check('kind');">
//       と記述しておく必要がある。
// ------------------------------------------------------------------------------

// ---------------------------------------------------------------
// 入力　可能・不可能モード。
// ---------------------------------------------------------------
function disabled_area(str_id){
	var str_num = str_id.split('-');
	for(var i = 1; i <= str_num[1]; i ++){
		if( document.getElementById(str_num[0]).checked ){
			// チェックが入っている場合
			document.getElementById(str_num[0] + '-' + i ).disabled = false; // 可視
		}else{
			// チェックが入っていない場合
			document.getElementById(str_num[0] + '-' + i ).disabled = true; // 不可視
		}
	}

}




// ------------------------------------------------------------------------------
// 
// fmailカスタマイズ仕様用
// 画面切り替え処理　ブロックごと表示・非表示を切り替える
// 
// ------------------------------------------------------------------------------
function desabled_block(str_id){
	var str_num = str_id.split('-');
	if( document.getElementById(str_num[0]).checked ){
		// 初めに表示させる方
		for(var i = 1; i <= str_num[1]; i ++){
			// データ部分
			document.getElementById(str_num[0] + '-' + i).disabled = false; // 可視
			// 表示部分
			document.getElementById(str_num[0] + '-' + i).style.display = 'block'; // 可視
		}
		
		//  後から表示させる方
		for(i = 1; i <= str_num[2]; i ++){			
			// データ部分
			document.getElementById(str_num[0] + '_reverse-' + i).disabled = true; // 不可視
			// 表示部分
			document.getElementById(str_num[0] + '_reverse-' + i).style.display = 'none'; // 不可視
		}
	}else{
		// 初めに表示させる方
		for(var i = 1; i <= str_num[1]; i ++){
			// データ部分
			document.getElementById(str_num[0] + '-' + i).disabled = true; // 不可視
			// 表示部分
			document.getElementById(str_num[0] + '-' + i).style.display = 'none'; // 不可視
		}
		
		//  後から表示させる方
		for(i = 1; i <= str_num[2]; i ++){			
			// データ部分
			document.getElementById(str_num[0] + '_reverse-' + i).disabled = false; // 可視
			// 表示部分
			document.getElementById(str_num[0] + '_reverse-' + i).style.display = 'block'; // 可視
		}
	}
}
