//-------- Function ----------------------------------------------------------
// データを入力、修正する時、内容を確認するためのジャバスクリプト
// 데이터를 입력, 수정할 때 내용을 확인 하기 위한 자바스크립트
function explain_write_check(form_fid, admin_check) {
	var f = document.getElementById('form_'+form_fid);

	// 管理者ではない場合、Login可否をチェック
	// 관리자가 아닐 경우 로그인 여부를 체크
	if (admin_check != 'admin') {
		if (trim(f.user_id.value) == "") {
			alert("ログインをしてください。");
			f.user_id.value = "";
			f.user_id.focus();
			return false;
		}
	}
	
	// データを入力する時
	// 데이터를 입력할 때
	if (f.action.value == 'write' || f.action.value == 'comment_write' || f.action.value == 'history_write') {
		// 内容がない場合
		// 내용이 없는 경우
		if (trim(f.contents.value) == "") {
			alert("内容を入力してください。");
			f.contents.value = "";
			f.contents.focus();
			return false;
		} else {
			// 管理者ではない場合、不良単語チェック
			// 관리자가 아닌 경우, 불량단어 체크
			if (admin_check == '') {
				if (!validate_user_text(f.contents)) {
					return false;
				}
			}
		}
	// データを修正する時
	// 데이터를 수정할 때
	} else {
		// 内容がない場合
		// 내용이 없는 경우
		if (trim(f.contents2.value) == "") {
			alert("内容を入力してください。");
			f.contents2.value = "";
			f.contents2.focus();
			return false;
		} else {
			// 管理者ではない場合、不良単語チェック
			// 관리자가 아닌 경우, 불량단어 체크
			if (admin_check == '') {
				if (!validate_user_text(f.contents2)) {
					return false;
				}
			}
		}
	}
	f.submit();
}
//----------------------------------------------------------------------------


//-------- Function ----------------------------------------------------------
// 不良単語チェックのためのジャバスクリプト
// 불량단어 체크를 위한 자바스크립트
function validate_user_text(input) {

	var compare_text = input.value;
	
	// 不良単語のリスト
	// 불량단어 리스트
	var swear_words_arr=new Array("080","090","０８０","０９０","バカ","馬鹿","ばか");
	var swear_alert_arr=new Array;
	var swear_alert_count=0;

	for(var i=0; i<swear_words_arr.length; i++) {
		for(var j=0; j<(compare_text.length); j++) {
			if(swear_words_arr[i]==compare_text.substring(j,(j+swear_words_arr[i].length)).toLowerCase()) {
				swear_alert_arr[swear_alert_count]=compare_text.substring(j,(j+swear_words_arr[i].length));
				swear_alert_count++;
			}
		}
	}

	// チェックされた単語のリスト
	// 체크된 불량 단어 리스트
	var alert_text="";
	for(var k=1; k<=swear_alert_count; k++) {
		alert_text+="\n" + "(" + k + ")  " + swear_alert_arr[k-1];
	}
	if(swear_alert_count>0) {
		alert("不良単語がチェックされました。\n\nチェックされた不良単語は下記となります。"
				+ "\n_______________________________\n"
				+ alert_text
				+ "\n_______________________________");
		return false;
	} else {
		return true;
	}
}
//----------------------------------------------------------------------------

//-------- Function ----------------------------------------------------------
// settingに関するデータを修正出来るように Formが見えるとか見えないようにするジャバスクリプト
// setting에 관한 데이터를 수정할 수 있도록 Form이 보이거나 안보이게 하는 자바스크립트
function explain_setting(form_fid) {
	var f = document.getElementById('form_'+form_fid);

	if (document.getElementById('edit_'+form_fid).style.display == 'none') {
		document.getElementById('view_'+form_fid).style.display='none';
		document.getElementById('edit_'+form_fid).style.display='block';
	} else {
		document.getElementById('view_'+form_fid).style.display='block';
		document.getElementById('edit_'+form_fid).style.display='none';
	}
}
//----------------------------------------------------------------------------

//-------- Function ----------------------------------------------------------
// Commentが入力、修正されるように Formが見えるとか見えないようにするジャバスクリプト
// Comment가 입력,수정될 수 있도록 Form을 보이거나 안보이게 하는 자바스크립트
function explain_comment(display_ok, form_fid) {
	var f = document.getElementById('form_'+form_fid);
	f.action.value = "comment_" + display_ok;

	if (display_ok == 'write') {
		if (document.getElementById('write_'+form_fid).style.display == 'none') {
			document.getElementById('write_'+form_fid).style.display='block';
		} else {
			document.getElementById('write_'+form_fid).style.display='none';
		}
		document.getElementById('view_'+form_fid).style.display='block';
		document.getElementById('edit_'+form_fid).style.display='none';
	} else {
		if (document.getElementById('edit_'+form_fid).style.display == 'none') {
			document.getElementById('view_'+form_fid).style.display='none';
			document.getElementById('edit_'+form_fid).style.display='block';
		} else {
			document.getElementById('view_'+form_fid).style.display='block';
			document.getElementById('edit_'+form_fid).style.display='none';
		}
		document.getElementById('write_'+form_fid).style.display='none';
	}
}
//----------------------------------------------------------------------------

//-------- Function ----------------------------------------------------------
// FAQのテーブルの色を変更しながらテーブルが見えるとか見えないようにするためのジャバスクリプト
// FAQ의 테이블 색상을 변경하면서 테이블이 보이거나 안보이게 하기 위한 자바스크립트
function changeFieldColor(obj) { obj.bgColor = "#f2ebc1"; }
function returnFieldColor(obj) { obj.bgColor = "#fef7e7"; }

var old_faq;
function explain_faq(i) {
	if (old_faq==i) {
		var mode=document.getElementById('comment'+i).style.display;
		if (mode=='inline') { document.getElementById('comment'+i).style.display='none'; }
		else { document.getElementById('comment'+i).style.display='inline'; }
		document.getElementById('comment2'+i).style.backgroundColor='';
	} else {
		if (old_faq) {
			document.getElementById('comment'+old_faq).style.display='none';
			document.getElementById('comment2'+old_faq).style.backgroundColor='';
		}
		document.getElementById('comment'+i).style.display='inline';
		document.getElementById('comment2'+i).style.backgroundColor='#f2ebc1';
	}
	old_faq=i;
}
//----------------------------------------------------------------------------

//-------- Function ----------------------------------------------------------
// 決済手段が見えるとか見えないようにするためのジャバスクリプト
// 결제 수댠이 보이거나 안보이게 하기 위한 자바스크립트
var old_payment;
function explain_payment(i) {

	if (old_payment==i) {
		var mode=document.getElementById('comment'+i).style.display;
		if (mode=='inline') { document.getElementById('comment'+i).style.display='none'; }
		else { document.getElementById('comment'+i).style.display='inline'; }
	} else {
		if (old_payment == undefined) { document.getElementById('comment1').style.display='none'; }
		if (old_payment) { document.getElementById('comment'+old_payment).style.display='none'; }
		document.getElementById('comment'+i).style.display='inline';
	}
	old_payment=i;
}
//----------------------------------------------------------------------------